fix(workspaces): backend validation on workspace settings fields (#2584)
* fix(workspaces): backend validation on workspace settings fields * chore(workspaces): move authz to resolver level
This commit is contained in:
@@ -20,6 +20,10 @@ import {
|
||||
import { Workspace } from '@/modules/workspacesCore/domain/types'
|
||||
import { beforeEachContext } from '@/test/hooks'
|
||||
import { AllScopes } from '@/modules/core/helpers/mainConstants'
|
||||
import {
|
||||
BasicTestWorkspace,
|
||||
createTestWorkspace
|
||||
} from '@/modules/workspaces/tests/helpers/creation'
|
||||
|
||||
describe('Workspaces GQL CRUD', () => {
|
||||
let apollo: TestApolloServer
|
||||
@@ -114,27 +118,65 @@ describe('Workspaces GQL CRUD', () => {
|
||||
})
|
||||
|
||||
describe('mutation workspaceMutations.update', () => {
|
||||
it('should update a workspace', async () => {
|
||||
const createRes = await apollo.execute(CreateWorkspaceDocument, {
|
||||
input: { name: cryptoRandomString({ length: 6 }) }
|
||||
})
|
||||
const workspace: BasicTestWorkspace = {
|
||||
id: '',
|
||||
ownerId: '',
|
||||
name: cryptoRandomString({ length: 6 }),
|
||||
description: cryptoRandomString({ length: 12 })
|
||||
}
|
||||
|
||||
beforeEach(async () => {
|
||||
await createTestWorkspace(workspace, testUser)
|
||||
})
|
||||
|
||||
it('should update a workspace', async () => {
|
||||
const workspaceName = cryptoRandomString({ length: 6 })
|
||||
|
||||
await apollo.execute(UpdateWorkspaceDocument, {
|
||||
const updateRes = await apollo.execute(UpdateWorkspaceDocument, {
|
||||
input: {
|
||||
id: createRes.data!.workspaceMutations.create.id,
|
||||
id: workspace.id,
|
||||
name: workspaceName
|
||||
}
|
||||
})
|
||||
|
||||
const getRes = await apollo.execute(GetWorkspaceDocument, {
|
||||
workspaceId: createRes.data!.workspaceMutations.create.id
|
||||
const { data } = await apollo.execute(GetWorkspaceDocument, {
|
||||
workspaceId: workspace.id
|
||||
})
|
||||
|
||||
expect(createRes).to.not.haveGraphQLErrors()
|
||||
expect(getRes).to.not.haveGraphQLErrors()
|
||||
expect(getRes.data?.workspace.name).to.equal(workspaceName)
|
||||
expect(updateRes).to.not.haveGraphQLErrors()
|
||||
expect(data?.workspace.name).to.equal(workspaceName)
|
||||
})
|
||||
|
||||
it('should not allow workspace name to be empty', async () => {
|
||||
const updateRes = await apollo.execute(UpdateWorkspaceDocument, {
|
||||
input: {
|
||||
id: workspace.id,
|
||||
name: ''
|
||||
}
|
||||
})
|
||||
|
||||
const { data } = await apollo.execute(GetWorkspaceDocument, {
|
||||
workspaceId: workspace.id
|
||||
})
|
||||
|
||||
expect(updateRes).to.not.haveGraphQLErrors()
|
||||
expect(data?.workspace.name).to.equal(workspace.name)
|
||||
})
|
||||
|
||||
it('should allow workspace description to be empty', async () => {
|
||||
const updateRes = await apollo.execute(UpdateWorkspaceDocument, {
|
||||
input: {
|
||||
id: workspace.id,
|
||||
description: ''
|
||||
}
|
||||
})
|
||||
|
||||
const { data } = await apollo.execute(GetWorkspaceDocument, {
|
||||
workspaceId: workspace.id
|
||||
})
|
||||
|
||||
expect(updateRes).to.not.haveGraphQLErrors()
|
||||
expect(data?.workspace.description).to.equal('')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user