Files
speckle-server/packages/server/modules/gatekeeper/tests/unit/featureAuthorization.spec.ts
T
Gergő Jedlicska f210d9b749 gergo/web 2109 project region based db connection selector (#3434)
* feat(projects): add project regions, default to null

* feat(multiregion): add projectRegion Db client lookup logic

* feat(multiregion): add project region repositories and caching

* feat(multiRegion): db initialization and get project db client

* feat(docker-compose): add second db for regions testing

* feat(multiRegion): initialize region with pubs and subs working

* fix(multiRegion): get region client even if it was registered in another pod

* feat(workspaces): create workspace resolver split

* feat: update server region metadata

* feat(projects): rewrite project creation

* feat(multiRegion): getRegionDb

* fix(workspaces): get projects now can retur null

* feat(multiRegion): make local multi region DB-s work

* feat: set d efault workspace region

* CR changes

* tests

* feat(multiRegion): bind region properly

* fe update

* test fixes

* feat(multiRegion): automatically create aiven extras plugin

* ci(postgres): use published postgres with aiven extras

* fix(multiRegion): roll back the aiven extras migration, there is a better way

* tests fix

* fix(billing): we do not need to add a seat, if the workspace is on a plan, but has no sub

---------

Co-authored-by: Kristaps Fabians Geikins <fabis94@live.com>
2024-11-06 17:29:08 +01:00

49 lines
1.9 KiB
TypeScript

import { WorkspacePlan } from '@/modules/gatekeeper/domain/billing'
import { canWorkspaceAccessFeatureFactory } from '@/modules/gatekeeper/services/featureAuthorization'
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
})
;(
[
['team', 'expired', 'oidcSso', false],
['team', 'valid', 'oidcSso', false],
['team', 'valid', 'workspaceDataRegionSpecificity', false],
['pro', 'valid', 'workspaceDataRegionSpecificity', false],
['pro', 'canceled', 'oidcSso', false],
['pro', '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)
})
})
})
})