GH-2808: fix some logging issues with share board. (#2827)

* fix some logging issues

* fix unit test

* more test fixes

* unit test
This commit is contained in:
Scott Bishel 2022-04-18 08:57:42 -06:00 committed by GitHub
parent 37259afda4
commit 21667aa8d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 13 deletions

View file

@ -1545,7 +1545,7 @@ func (a *API) handleGetSharing(w http.ResponseWriter, r *http.Request) {
return
}
if sharing == nil {
a.errorResponse(w, r.URL.Path, http.StatusNotFound, "", nil)
jsonStringResponse(w, http.StatusOK, "{}")
return
}

View file

@ -1,7 +1,6 @@
package integrationtests
import (
"net/http"
"testing"
"github.com/mattermost/focalboard/server/model"
@ -43,8 +42,10 @@ func TestSharing(t *testing.T) {
require.Nil(t, s)
sharing, resp := th.Client.GetSharing(boardID)
th.CheckNotFound(resp)
require.Nil(t, sharing)
require.NoError(t, resp.Error)
require.NotNil(t, sharing)
require.False(t, sharing.Enabled)
require.Empty(t, sharing.ID)
})
t.Run("POST sharing, config = false", func(t *testing.T) {
@ -62,10 +63,12 @@ func TestSharing(t *testing.T) {
t.Run("GET sharing", func(t *testing.T) {
sharing, resp := th.Client.GetSharing(boardID)
// Expect not found error
require.Error(t, resp.Error)
require.Equal(t, resp.StatusCode, http.StatusNotFound)
require.Nil(t, sharing)
// Expect empty sharing object
require.NoError(t, resp.Error)
require.NotNil(t, sharing)
require.False(t, sharing.Enabled)
require.Empty(t, sharing.ID)
require.Empty(t, sharing.Token)
})
})

View file

@ -180,7 +180,12 @@ describe('src/components/shareBoard/shareBoard', () => {
})
test('should match snapshot', async () => {
mockedOctoClient.getSharing.mockResolvedValue(undefined)
const sharing:ISharing = {
id: '',
enabled: false,
token: '',
}
mockedOctoClient.getSharing.mockResolvedValue(sharing)
let container
await act(async () => {
const result = render(
@ -356,7 +361,12 @@ describe('src/components/shareBoard/shareBoard', () => {
expect(container).toMatchSnapshot()
})
test('return shareBoardComponent and click Switch without sharing', async () => {
mockedOctoClient.getSharing.mockResolvedValue(undefined)
const sharing:ISharing = {
id: '',
enabled: false,
token: '',
}
mockedOctoClient.getSharing.mockResolvedValue(sharing)
mockedUtils.createGuid.mockReturnValue('aToken')
let container: Element | undefined
await act(async () => {

View file

@ -36,6 +36,8 @@ import SearchIcon from '../../widgets/icons/search'
import BoardPermissionGate from '../permissions/boardPermissionGate'
import {useHasPermissions} from '../../hooks/permissions'
import TeamPermissionsRow from './teamPermissionsRow'
import UserPermissionsRow from './userPermissionsRow'
@ -105,10 +107,14 @@ export default function ShareBoardDialog(props: Props): JSX.Element {
const intl = useIntl()
const match = useRouteMatch<{teamId?: string, boardId: string, viewId: string}>()
const hasSharePermissions = useHasPermissions(board.teamId, boardId, [Permission.ShareBoard])
const loadData = async () => {
const newSharing = await client.getSharing(boardId)
setSharing(newSharing)
setWasCopiedPublic(false)
if( hasSharePermissions ){
const newSharing = await client.getSharing(boardId)
setSharing(newSharing)
setWasCopiedPublic(false)
}
}
const createSharingInfo = () => {