Files
speckle-server/packages/server/modules/gatekeeper/tests/unit/readOnly.spec.ts
T
Kristaps Fabians Geikins 211922b6a6 chore: get rid of all old workspace plan code (#4624)
* first batch of changes

* tests fix

* FE fixed

* renaming constants

* test fixes

* moar test fixes

* another test fix

* reenable app rover check

---------

Co-authored-by: Gergő Jedlicska <gergo@jedlicska.com>
2025-04-30 19:18:32 +02:00

105 lines
4.1 KiB
TypeScript

import { GetWorkspacePlan } from '@/modules/gatekeeper/domain/billing'
import { GetWorkspacePlanByProjectId } from '@/modules/gatekeeper/domain/operations'
import {
isProjectReadOnlyFactory,
isWorkspaceReadOnlyFactory
} from '@/modules/gatekeeper/services/readOnly'
import { expect } from 'chai'
describe('@gatekeeper readOnly', () => {
describe('isWorkspaceReadOnlyFactory returns a function that', () => {
it('returns true if workspace plan status is paymentFailed', async () => {
const getWorkspacePlan: GetWorkspacePlan = () =>
({ status: 'paymentFailed' } as unknown as ReturnType<GetWorkspacePlan>)
const isWorkspaceReadOnly = isWorkspaceReadOnlyFactory({ getWorkspacePlan })
expect(await isWorkspaceReadOnly({ workspaceId: '' })).to.be.false
})
it('returns true if workspace plan status is canceled', async () => {
const getWorkspacePlan: GetWorkspacePlan = () =>
({ status: 'canceled' } as unknown as ReturnType<GetWorkspacePlan>)
const isWorkspaceReadOnly = isWorkspaceReadOnlyFactory({ getWorkspacePlan })
expect(await isWorkspaceReadOnly({ workspaceId: '' })).to.be.true
})
it('returns false if workspace plan status is valid', async () => {
const getWorkspacePlan: GetWorkspacePlan = () =>
({ status: 'valid' } as unknown as ReturnType<GetWorkspacePlan>)
const isWorkspaceReadOnly = isWorkspaceReadOnlyFactory({ getWorkspacePlan })
expect(await isWorkspaceReadOnly({ workspaceId: '' })).to.be.false
})
it('returns false if workspace plan status is cancelationScheduled', async () => {
const getWorkspacePlan: GetWorkspacePlan = () =>
({ status: 'cancelationScheduled' } as unknown as ReturnType<GetWorkspacePlan>)
const isWorkspaceReadOnly = isWorkspaceReadOnlyFactory({ getWorkspacePlan })
expect(await isWorkspaceReadOnly({ workspaceId: '' })).to.be.false
})
})
describe('isProjectReadOnlyFactory returns a function that', () => {
it('returns false if project is not in a workspace', async () => {
const getWorkspacePlanByProjectId: GetWorkspacePlanByProjectId = async () => null
const isProjectReadOnly = isProjectReadOnlyFactory({
getWorkspacePlanByProjectId
})
expect(await isProjectReadOnly({ projectId: '' })).to.be.false
})
it('returns true if workspace plan status is paymentFailed', async () => {
const getWorkspacePlanByProjectId: GetWorkspacePlanByProjectId = async () =>
({
status: 'paymentFailed'
} as unknown as ReturnType<GetWorkspacePlanByProjectId>)
const isProjectReadOnly = isProjectReadOnlyFactory({
getWorkspacePlanByProjectId
})
expect(await isProjectReadOnly({ projectId: '' })).to.be.false
})
it('returns true if workspace plan status is canceled', async () => {
const getWorkspacePlanByProjectId: GetWorkspacePlanByProjectId = async () =>
({
status: 'canceled'
} as unknown as ReturnType<GetWorkspacePlanByProjectId>)
const isProjectReadOnly = isProjectReadOnlyFactory({
getWorkspacePlanByProjectId
})
expect(await isProjectReadOnly({ projectId: '' })).to.be.true
})
it('returns false if workspace plan status is valid', async () => {
const getWorkspacePlanByProjectId: GetWorkspacePlanByProjectId = async () =>
({
status: 'valid'
} as unknown as ReturnType<GetWorkspacePlanByProjectId>)
const isProjectReadOnly = isProjectReadOnlyFactory({
getWorkspacePlanByProjectId
})
expect(await isProjectReadOnly({ projectId: '' })).to.be.false
})
it('returns false if workspace plan status is cancelationScheduled', async () => {
const getWorkspacePlanByProjectId: GetWorkspacePlanByProjectId = async () =>
({
status: 'cancelationScheduled'
} as unknown as ReturnType<GetWorkspacePlanByProjectId>)
const isProjectReadOnly = isProjectReadOnlyFactory({
getWorkspacePlanByProjectId
})
expect(await isProjectReadOnly({ projectId: '' })).to.be.false
})
})
})