211922b6a6
* 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>
105 lines
4.1 KiB
TypeScript
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
|
|
})
|
|
})
|
|
})
|