Files
speckle-server/packages/server/modules/workspaces/tests/unit/utils/roles.spec.ts
T
Chuck Driesler 66eb539aa0 feat(workspaces): assign project roles for workspace projects (#2499)
* 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>
2024-07-20 00:03:27 +01:00

57 lines
2.0 KiB
TypeScript

import { isUserLastWorkspaceAdmin } from '@/modules/workspaces/utils/roles'
import { WorkspaceAcl } from '@/modules/workspacesCore/domain/types'
import { expect } from 'chai'
import { Roles } from '@speckle/shared'
describe('given a workspace with several admins', () => {
const workspaceRoles: WorkspaceAcl[] = [
{ workspaceId: 'workspace-id', userId: 'non-admin', role: Roles.Workspace.Member },
{ workspaceId: 'workspace-id', userId: 'admin-a', role: Roles.Workspace.Admin },
{ workspaceId: 'workspace-id', userId: 'admin-b', role: Roles.Workspace.Admin }
]
describe('when testing a non-admin user', () => {
it('should return false', () => {
expect(isUserLastWorkspaceAdmin(workspaceRoles, 'non-admin')).to.be.false
})
})
describe('when testing an admin user', () => {
it('should return false', () => {
expect(isUserLastWorkspaceAdmin(workspaceRoles, 'admin-a')).to.be.false
})
})
})
describe('given a workspace with one admin', () => {
const workspaceRoles: WorkspaceAcl[] = [
{ workspaceId: 'workspace-id', userId: 'non-admin', role: Roles.Workspace.Member },
{ workspaceId: 'workspace-id', userId: 'admin', role: Roles.Workspace.Admin }
]
describe('when testing a non-admin user', () => {
it('should return false', () => {
expect(isUserLastWorkspaceAdmin(workspaceRoles, 'non-admin')).to.be.false
})
})
describe('when testing an admin user', () => {
it('should return true', () => {
expect(isUserLastWorkspaceAdmin(workspaceRoles, 'admin')).to.be.true
})
})
})
describe('given a workspace', () => {
const workspaceRoles: WorkspaceAcl[] = [
{ workspaceId: 'workspace-id', userId: 'non-admin', role: Roles.Workspace.Member },
{ workspaceId: 'workspace-id', userId: 'admin', role: Roles.Workspace.Admin }
]
describe('when testing a non-workspace user', () => {
it('should return false', () => {
expect(isUserLastWorkspaceAdmin(workspaceRoles, 'random-id')).to.be.false
})
})
})