Files
speckle-server/packages/server/modules/gatekeeper/tests/unit/featureAuthorization.spec.ts
T
Gergő Jedlicska f501cc4ad5 gergo/web 2888 workspace project cancreate (#4294)
* WIP can create project

* WIP can create project more work

* complete body, stencil tests

* feat(shared): move workspace plan types into shared

* test progress wip

* feat(shared): add more logic to canCreateWorkspaceProject

* a few more tests, as a treat

* chore(authz): round out tests

* fixed loaders, new GQL checks, dataLoaders in auth loaders

* fix(authz): get workspace limits loader

* chore(authz): update loaders

* frontend fixed up to snuff

* fix(authz): fix workspace plans for tests

* fix(authz): classic

* fix(authz): 0 counts

---------

Co-authored-by: Chuck Driesler <chuck@speckle.systems>
Co-authored-by: Kristaps Fabians Geikins <fabis94@live.com>
2025-04-01 16:38:20 +01:00

49 lines
1.9 KiB
TypeScript

import { canWorkspaceAccessFeatureFactory } from '@/modules/gatekeeper/services/featureAuthorization'
import { WorkspacePlan } from '@speckle/shared'
import { expect } from 'chai'
import cryptoRandomString from 'crypto-random-string'
describe('featureAuthorization @gatekeeper', () => {
describe('canWorkspaceAccessFeatureFactory creates a function, that', () => {
it('throws an error if workspace is not on a workspacePlan', async () => {
const canWorkspaceAccessFeature = canWorkspaceAccessFeatureFactory({
getWorkspacePlan: async () => null
})
const canAccess = await canWorkspaceAccessFeature({
workspaceId: cryptoRandomString({ length: 10 }),
workspaceFeature: 'domainBasedSecurityPolicies'
})
expect(canAccess).to.be.false
})
;(
[
['starter', 'expired', 'oidcSso', false],
['starter', 'valid', 'oidcSso', false],
['starter', 'valid', 'workspaceDataRegionSpecificity', false],
['plus', 'valid', 'workspaceDataRegionSpecificity', false],
['plus', 'canceled', 'oidcSso', false],
['plus', 'valid', 'oidcSso', true],
['business', 'valid', 'workspaceDataRegionSpecificity', true]
] as const
).forEach(([plan, status, workspaceFeature, expectedResult]) => {
it(`returns ${expectedResult} for ${plan} @ ${status} for ${workspaceFeature}`, async () => {
const workspaceId = cryptoRandomString({ length: 10 })
const canWorkspaceAccessFeature = canWorkspaceAccessFeatureFactory({
getWorkspacePlan: async () =>
({
name: plan,
status,
workspaceId
} as WorkspacePlan)
})
const result = await canWorkspaceAccessFeature({
workspaceId,
workspaceFeature
})
expect(result).to.equal(expectedResult)
})
})
})
})