6eaf3c8c92
* feat(workspaces): drop createdByUserId from the dataschema * feat(workspaces): repositories WIP * merge * protect against removing last admin in workspace * quick impl and stub tests * add tests * services * unit tests for role services * feat(workspaces): authorize project creation if workspace specified * feat(workspaces): emit project created event * feat(workspaces): assign roles on project create in workspace * feat(workspaces): update project roles when user added to workspace * feat(workspaces): stencil gql resolvers * fix(workspaces): lol lmao * fix(workspaces): perform automatic project role update in service function * fix(workspaces): also delete roles * fix(workspaces): broke tests again oops * fix(workspaces): update `onProjectCreated` listener to use new repo method * fix(workspaces): use service function in event listener * fix(workspaces): get workspace projects via existing stream repo functions * fix(workspaces): roles mapping in domain, use enum * feat(workspaces): stencil gql api and resolvers * fix(workspaces): repair type reference in tests * fix(workspaces): consolidate files, use different existing stream-getter * fix(workspaces): more specific error * fix(workspaces): roles and scopes * fix(workspaces): yield per page * fix(workspaces): some test dry * fix(workspaces): superdry * fix(workspaces): add scopes * fix(workspaces): classic * feat(workspaces): create workspace mutation * feat(workspaces): I'm sure everything will be fine * fix(workspaces): yep * fix(workspaces): successful gql e2e test * feat(workspaces): update workspace resolver * chore(workspaces): update resolver test * feat(workspaces): some retrieval resolvers * chore(workspaces): tests for query resolvers * fix(chore): revert temp test command change * fix(workspaces): test structure and gql types * fix(workspaces): validate user authz to perform some operations * fix(workspaces): use existing test infrastructure * fix(workspaces): stop `isPublic` check if authorizing a workspace resource * fix(workspaces): better test hygiene --------- Co-authored-by: Gergő Jedlicska <gergo@jedlicska.com>
139 lines
4.1 KiB
TypeScript
139 lines
4.1 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 { AllScopes, Roles } from '@speckle/shared'
|
|
import {
|
|
CreateWorkspaceDocument,
|
|
GetActiveUserWorkspacesDocument,
|
|
GetWorkspaceDocument,
|
|
UpdateWorkspaceDocument
|
|
} from '@/test/graphql/generated/graphql'
|
|
import { Workspace } from '@/modules/workspacesCore/domain/types'
|
|
|
|
describe('workspaces module gql operations', () => {
|
|
let apollo: TestApolloServer
|
|
|
|
const testUser: BasicTestUser = {
|
|
id: '',
|
|
name: 'John Speckle',
|
|
email: 'john-speckle@example.org',
|
|
role: Roles.Server.Admin
|
|
}
|
|
|
|
before(async () => {
|
|
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)
|
|
})
|
|
})
|
|
})
|
|
})
|