Files
speckle-server/packages/server/modules/workspaces/tests/unit/utils/roles.spec.ts
T
Chuck Driesler bbd5146e5a fix(workspaces): add pagination to workspace team members (#2644)
* fix(workspaces): a suggestion of paginated teams

* fix(workspaces): workspace team pagination (?)

* fix(workspaces): pagination based on acl createdAt

* fix(workspaces): fix some roles-related tests

* fix(workspaces): improve query and tests

* fix(workspaces): collaborators query without incorrect groupBy

* fix(workspaces): add default values to migration

* Fixed queries and fragments

* Merged main

* Remove comment

* chore(workspaces): update WorkspaceCollaboratorCollection mocks

* chore(workspaces): fix role test

* chore(workspaces); ope

* fix(workspaces): move workspace acl timestamps to separate table

* Merge?

* fix(workspaces) drop that table

* fix(workspaces): cursor

* fix(workspaceInvites): undo merge borkage

* fix(workspaces): rework workspace member pagination

* fix(workspaces): fix test

* fix(workspaces): test test

* fix(workspaces): literally garbage

---------

Co-authored-by: Mike Tasset <mike.tasset@gmail.com>
Co-authored-by: Gergő Jedlicska <gergo@jedlicska.com>
2024-08-29 21:17:37 +02:00

85 lines
2.2 KiB
TypeScript

import { WorkspaceAcl } from '@/modules/workspacesCore/domain/types'
import { expect } from 'chai'
import { Roles } from '@speckle/shared'
import { isUserLastWorkspaceAdmin } from '@/modules/workspaces/helpers/roles'
describe('given a workspace with several admins', () => {
const workspaceRoles: Omit<WorkspaceAcl, 'createdAt'>[] = [
{
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: Omit<WorkspaceAcl, 'createdAt'>[] = [
{
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: Omit<WorkspaceAcl, 'createdAt'>[] = [
{
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
})
})
})