6982023dca
* feat(gatekeeper): add per workspace feature flags * feat(workspaces): add admin api for granting and removing access to workspace features * fix(workspaces): use the correct constant name * fix(workspaces): more test type fixes * fix(shared): fix tests and types * fix(workspaces): properly use exhaustive switch statement * fix(workspaces): add new workspace plan feature to switch * fix(workspaces): use regular integer, its fine for now... * fix(workspaces): feature flag retention post checkout * fix(gatekeeper): fix upsert plan tests
69 lines
1.8 KiB
TypeScript
69 lines
1.8 KiB
TypeScript
import { WorkspaceFeatureFlags, type WorkspacePlan } from '@speckle/shared'
|
|
import cryptoRandomString from 'crypto-random-string'
|
|
import { assign } from 'lodash-es'
|
|
import type {
|
|
SubscriptionData,
|
|
SubscriptionProduct,
|
|
WorkspaceSubscription
|
|
} from '@/modules/gatekeeper/domain/billing'
|
|
|
|
export const buildTestWorkspacePlan = (
|
|
overrides?: Partial<WorkspacePlan>
|
|
): WorkspacePlan =>
|
|
assign(
|
|
{
|
|
workspaceId: cryptoRandomString({ length: 10 }),
|
|
createdAt: new Date(),
|
|
updatedAt: new Date(),
|
|
name: 'free',
|
|
status: 'valid',
|
|
featureFlags: WorkspaceFeatureFlags.none
|
|
},
|
|
overrides
|
|
)
|
|
|
|
export const buildTestWorkspaceSubscription = (
|
|
overrides?: Partial<WorkspaceSubscription>
|
|
): WorkspaceSubscription =>
|
|
assign(
|
|
{
|
|
workspaceId: cryptoRandomString({ length: 10 }),
|
|
createdAt: new Date(),
|
|
updatedAt: new Date(),
|
|
currentBillingCycleEnd: new Date(),
|
|
billingInterval: 'monthly',
|
|
updateIntent: {},
|
|
currency: 'usd',
|
|
subscriptionData: buildTestSubscriptionData()
|
|
},
|
|
overrides
|
|
)
|
|
|
|
export const buildTestSubscriptionData = (
|
|
overrides?: Partial<SubscriptionData>
|
|
): SubscriptionData =>
|
|
assign(
|
|
{
|
|
subscriptionId: cryptoRandomString({ length: 10 }),
|
|
customerId: cryptoRandomString({ length: 10 }),
|
|
cancelAt: new Date(),
|
|
status: 'active',
|
|
products: [],
|
|
currentPeriodEnd: new Date()
|
|
},
|
|
overrides
|
|
)
|
|
|
|
export const buildTestSubscriptionProduct = (
|
|
overrides?: Partial<SubscriptionProduct>
|
|
): SubscriptionProduct =>
|
|
assign(
|
|
{
|
|
productId: cryptoRandomString({ length: 10 }),
|
|
subscriptionItemId: cryptoRandomString({ length: 10 }),
|
|
priceId: cryptoRandomString({ length: 10 }),
|
|
quantity: 1
|
|
},
|
|
overrides
|
|
)
|