bf80347abf
* feat(workspaces): delete workspace emit event * feat(workspaces): move workspace group metrics to the backend * Removed FE mixpanel group update * Remove fragment * test(gatekeeper): add unittest to new gatekeeper service --------- Co-authored-by: Mike Tasset <mike.tasset@gmail.com>
49 lines
1.9 KiB
TypeScript
49 lines
1.9 KiB
TypeScript
import { canWorkspaceAccessFeatureFactory } from '@/modules/gatekeeper/services/featureAuthorization'
|
|
import { WorkspacePlan } from '@/modules/gatekeeperCore/domain/billing'
|
|
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)
|
|
})
|
|
})
|
|
})
|
|
})
|