66eb539aa0
* 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 * 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 * fix(workspaces): repair type reference in tests * fix(workspaces): consolidate files, use different existing stream-getter * fix(workspaces): more specific error * fix(workspaces): yield per page * fix(workspaces): some test dry * fix(workspaces): superdry * fix(workspaces): classic --------- Co-authored-by: Gergő Jedlicska <gergo@jedlicska.com>
78 lines
2.5 KiB
TypeScript
78 lines
2.5 KiB
TypeScript
import { StreamRecord } from '@/modules/core/helpers/types'
|
|
import { queryAllWorkspaceProjectsFactory } from '@/modules/workspaces/services/projects'
|
|
import { expect } from 'chai'
|
|
import cryptoRandomString from 'crypto-random-string'
|
|
|
|
describe('Project retrieval services', () => {
|
|
describe('queryAllWorkspaceProjectFactory returns a generator, that', () => {
|
|
it('returns all streams for a workspace', async () => {
|
|
const workspaceId = cryptoRandomString({ length: 10 })
|
|
|
|
const foundProjects: StreamRecord[] = []
|
|
const storedProjects: StreamRecord[] = [{ workspaceId } as StreamRecord]
|
|
|
|
const queryAllWorkspaceProjectsGenerator = queryAllWorkspaceProjectsFactory({
|
|
getStreams: async () => {
|
|
return {
|
|
streams: storedProjects,
|
|
totalCount: storedProjects.length,
|
|
cursorDate: null
|
|
}
|
|
}
|
|
})
|
|
|
|
for await (const projectsPage of queryAllWorkspaceProjectsGenerator(
|
|
workspaceId
|
|
)) {
|
|
foundProjects.push(...projectsPage)
|
|
}
|
|
|
|
expect(foundProjects.length).to.equal(1)
|
|
})
|
|
it('returns all streams for a workspace if the query requires multiple pages of results', async () => {
|
|
const workspaceId = cryptoRandomString({ length: 10 })
|
|
|
|
const foundProjects: StreamRecord[] = []
|
|
const storedProjects: StreamRecord[] = [
|
|
{ workspaceId } as StreamRecord,
|
|
{ workspaceId } as StreamRecord
|
|
]
|
|
|
|
const queryAllWorkspaceProjectsGenerator = queryAllWorkspaceProjectsFactory({
|
|
getStreams: async ({ cursor }) => {
|
|
return cursor
|
|
? { streams: [storedProjects[1]], totalCount: 1, cursorDate: null }
|
|
: { streams: [storedProjects[0]], totalCount: 1, cursorDate: new Date() }
|
|
}
|
|
})
|
|
|
|
for await (const projectsPage of queryAllWorkspaceProjectsGenerator(
|
|
workspaceId
|
|
)) {
|
|
foundProjects.push(...projectsPage)
|
|
}
|
|
|
|
expect(foundProjects.length).to.equal(2)
|
|
})
|
|
it('exits if no results are found', async () => {
|
|
const workspaceId = cryptoRandomString({ length: 10 })
|
|
|
|
const foundProjects: StreamRecord[] = []
|
|
|
|
const queryAllWorkspaceProjectsGenerator = queryAllWorkspaceProjectsFactory({
|
|
getStreams: async () => {
|
|
return { streams: [], totalCount: 0, cursorDate: null }
|
|
}
|
|
})
|
|
|
|
for await (const projectsPage of queryAllWorkspaceProjectsGenerator(
|
|
workspaceId
|
|
)) {
|
|
foundProjects.push(...projectsPage)
|
|
}
|
|
|
|
expect(foundProjects.length).to.equal(0)
|
|
})
|
|
})
|
|
})
|