ede566eed9
* prep for new resources algo * typescriptifying stuff * minor types fix * migrate to resources col * repo & creation updated, WIP processing/retrieval * WIP invite processing * finished finalization refactor * project invite management * transformed all invites services * fixed up projects & core serverinvites resolvers * test fixes * WIP workspace create GQL & test * basic invite creation test works * a buncha working tests * more tests * cancelation tests * minor invite use refactor * invite retrieval tasks * invite use() works as expected * filtering out broken invites * enabled invite retrieval by token irregardless of who is it for * minor adjustments * tests fix * test config improvements * test env adjustment * extra test case * making resource access limits harder to ignore * linter fixes * eventBus type cleanup * better generic names * refactored serverinvites resource migration * fix(server): better error message in project invite edge case
142 lines
4.2 KiB
TypeScript
142 lines
4.2 KiB
TypeScript
import { expect } from 'chai'
|
|
import cryptoRandomString from 'crypto-random-string'
|
|
import {
|
|
createTestContext,
|
|
testApolloServer,
|
|
TestApolloServer
|
|
} from '@/test/graphqlHelper'
|
|
import {
|
|
BasicTestUser,
|
|
createAuthTokenForUser,
|
|
createTestUser
|
|
} from '@/test/authHelper'
|
|
import { Roles } from '@speckle/shared'
|
|
import {
|
|
CreateWorkspaceDocument,
|
|
GetActiveUserWorkspacesDocument,
|
|
GetWorkspaceDocument,
|
|
UpdateWorkspaceDocument
|
|
} from '@/test/graphql/generated/graphql'
|
|
import { Workspace } from '@/modules/workspacesCore/domain/types'
|
|
import { beforeEachContext } from '@/test/hooks'
|
|
import { AllScopes } from '@/modules/core/helpers/mainConstants'
|
|
|
|
describe('Workspaces GQL CRUD', () => {
|
|
let apollo: TestApolloServer
|
|
|
|
const testUser: BasicTestUser = {
|
|
id: '',
|
|
name: 'John Speckle',
|
|
email: 'john-speckle@example.org',
|
|
role: Roles.Server.Admin
|
|
}
|
|
|
|
before(async () => {
|
|
await beforeEachContext()
|
|
await createTestUser(testUser)
|
|
const token = await createAuthTokenForUser(testUser.id, AllScopes)
|
|
apollo = await testApolloServer({
|
|
context: createTestContext({
|
|
auth: true,
|
|
userId: testUser.id,
|
|
token,
|
|
role: testUser.role,
|
|
scopes: AllScopes
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('retrieval operations', () => {
|
|
const workspaceIds: string[] = []
|
|
|
|
before(async () => {
|
|
const workspaces: Pick<Workspace, 'name'>[] = [
|
|
{ name: 'Workspace A' },
|
|
{ name: 'Workspace B' }
|
|
]
|
|
|
|
const results = await Promise.all(
|
|
workspaces.map((workspace) =>
|
|
apollo.execute(CreateWorkspaceDocument, { input: workspace })
|
|
)
|
|
)
|
|
|
|
for (const result of results) {
|
|
workspaceIds.push(result.data!.workspaceMutations.create.id)
|
|
}
|
|
})
|
|
|
|
describe('query workspace', () => {
|
|
it('should return a workspace that exists', async () => {
|
|
const res = await apollo.execute(GetWorkspaceDocument, {
|
|
workspaceId: workspaceIds[0]
|
|
})
|
|
|
|
expect(res).to.not.haveGraphQLErrors()
|
|
expect(res.data?.workspace).to.exist
|
|
})
|
|
|
|
it('throw a not found error if the workspace does not exist', async () => {
|
|
const res = await apollo.execute(GetWorkspaceDocument, {
|
|
workspaceId: cryptoRandomString({ length: 6 })
|
|
})
|
|
expect(res).to.haveGraphQLErrors('not found')
|
|
})
|
|
})
|
|
|
|
describe('query activeUser.workspaces', () => {
|
|
it('should return all workspaces for a user', async () => {
|
|
const res = await apollo.execute(GetActiveUserWorkspacesDocument, {})
|
|
|
|
expect(res).to.not.haveGraphQLErrors()
|
|
expect(res.data?.activeUser?.workspaces?.items?.length).to.above(1)
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('management operations', () => {
|
|
describe('mutation workspaceMutations.create', () => {
|
|
it('should create a workspace', async () => {
|
|
const workspaceName = cryptoRandomString({ length: 6 })
|
|
|
|
const createRes = await apollo.execute(CreateWorkspaceDocument, {
|
|
input: { name: workspaceName }
|
|
})
|
|
const getRes = await apollo.execute(GetWorkspaceDocument, {
|
|
workspaceId: createRes.data!.workspaceMutations.create.id
|
|
})
|
|
|
|
expect(createRes).to.not.haveGraphQLErrors()
|
|
expect(getRes).to.not.haveGraphQLErrors()
|
|
expect(getRes.data?.workspace).to.exist
|
|
expect(getRes.data?.workspace?.name).to.equal(workspaceName)
|
|
})
|
|
})
|
|
|
|
describe('mutation workspaceMutations.update', () => {
|
|
it('should update a workspace', async () => {
|
|
const createRes = await apollo.execute(CreateWorkspaceDocument, {
|
|
input: { name: cryptoRandomString({ length: 6 }) }
|
|
})
|
|
|
|
const workspaceName = cryptoRandomString({ length: 6 })
|
|
|
|
await apollo.execute(UpdateWorkspaceDocument, {
|
|
input: {
|
|
id: createRes.data!.workspaceMutations.create.id,
|
|
name: workspaceName
|
|
}
|
|
})
|
|
|
|
const getRes = await apollo.execute(GetWorkspaceDocument, {
|
|
workspaceId: createRes.data!.workspaceMutations.create.id
|
|
})
|
|
|
|
expect(createRes).to.not.haveGraphQLErrors()
|
|
expect(getRes).to.not.haveGraphQLErrors()
|
|
expect(getRes.data?.workspace.name).to.equal(workspaceName)
|
|
})
|
|
})
|
|
})
|
|
})
|