diff --git a/packages/shared/src/workspaces/helpers/plans.spec.ts b/packages/shared/src/workspaces/helpers/plans.spec.ts index 3e318b1bc..306bbbdda 100644 --- a/packages/shared/src/workspaces/helpers/plans.spec.ts +++ b/packages/shared/src/workspaces/helpers/plans.spec.ts @@ -1,28 +1,93 @@ import { describe, expect, it } from 'vitest' -import { isNewWorkspacePlan, WorkspacePlans } from './plans.js' +import { + doesPlanIncludeUnlimitedProjectsAddon, + isNewWorkspacePlan, + isSelfServeAvailablePlan, + WorkspacePlans +} from './plans.js' -describe('isNewWorkspacePlan', () => { - const planCases: { - [P in WorkspacePlans]: boolean - } = { - business: false, - businessInvoiced: false, - plus: false, - plusInvoiced: false, - starter: false, - starterInvoiced: false, - free: true, - academia: true, - unlimited: true, - pro: true, - proUnlimited: true, - proUnlimitedInvoiced: true, - team: true, - teamUnlimited: true, - teamUnlimitedInvoiced: true - } - it.each(Object.entries(planCases))('plan %s is new type -> %s', (plan, isNew) => { - const result = isNewWorkspacePlan(plan as WorkspacePlans) - expect(result).toStrictEqual(isNew) +describe('plan helpers', () => { + describe('isNewWorkspacePlan', () => { + const planCases: { + [P in WorkspacePlans]: boolean + } = { + business: false, + businessInvoiced: false, + plus: false, + plusInvoiced: false, + starter: false, + starterInvoiced: false, + free: true, + academia: true, + unlimited: true, + pro: true, + proUnlimited: true, + proUnlimitedInvoiced: true, + team: true, + teamUnlimited: true, + teamUnlimitedInvoiced: true + } + it.each(Object.entries(planCases))('plan %s is new type -> %s', (plan, isNew) => { + const result = isNewWorkspacePlan(plan as WorkspacePlans) + expect(result).toStrictEqual(isNew) + }) + }) + + describe('doesPlanIncludeUnlimitedProjectsAddon', () => { + const planCases: { + [P in WorkspacePlans]: boolean + } = { + business: false, + businessInvoiced: false, + plus: false, + plusInvoiced: false, + starter: false, + starterInvoiced: false, + free: false, + academia: false, + unlimited: false, + pro: false, + proUnlimited: true, + proUnlimitedInvoiced: false, + team: false, + teamUnlimited: true, + teamUnlimitedInvoiced: false + } + it.each(Object.entries(planCases))( + 'plan %s include the paid unlimited projects addon -> %s', + (plan, isNew) => { + const result = doesPlanIncludeUnlimitedProjectsAddon(plan as WorkspacePlans) + expect(result).toStrictEqual(isNew) + } + ) + }) + + describe('isSelfServeAvailablePlan', () => { + const planCases: { + [P in WorkspacePlans]: boolean + } = { + business: false, + businessInvoiced: false, + plus: false, + plusInvoiced: false, + starter: false, + starterInvoiced: false, + free: true, + academia: false, + unlimited: false, + pro: true, + proUnlimited: true, + proUnlimitedInvoiced: false, + team: true, + teamUnlimited: true, + teamUnlimitedInvoiced: false + } + it.each(Object.entries(planCases))( + 'is plan %s available self served -> %s', + (plan, isNew) => { + const result = isSelfServeAvailablePlan(plan as WorkspacePlans) + expect(result).toStrictEqual(isNew) + } + ) }) }) diff --git a/packages/shared/src/workspaces/helpers/plans.ts b/packages/shared/src/workspaces/helpers/plans.ts index 1eb16ec3c..42f09a458 100644 --- a/packages/shared/src/workspaces/helpers/plans.ts +++ b/packages/shared/src/workspaces/helpers/plans.ts @@ -94,6 +94,58 @@ export const isNewWorkspacePlan = ( } } +export const doesPlanIncludeUnlimitedProjectsAddon = ( + plan: WorkspacePlans +): boolean => { + switch (plan) { + case 'teamUnlimited': + case 'proUnlimited': + return true + case 'free': + case 'team': + case 'pro': + case 'starter': + case 'plus': + case 'business': + case 'starterInvoiced': + case 'plusInvoiced': + case 'businessInvoiced': + case 'teamUnlimitedInvoiced': + case 'proUnlimitedInvoiced': + case 'unlimited': + case 'academia': + return false + + default: + throwUncoveredError(plan) + } +} + +export const isSelfServeAvailablePlan = (plan: WorkspacePlans): boolean => { + switch (plan) { + case 'free': + case 'team': + case 'teamUnlimited': + case 'pro': + case 'proUnlimited': + return true + case 'starter': + case 'plus': + case 'business': + case 'starterInvoiced': + case 'plusInvoiced': + case 'businessInvoiced': + case 'teamUnlimitedInvoiced': + case 'proUnlimitedInvoiced': + case 'unlimited': + case 'academia': + return false + + default: + throwUncoveredError(plan) + } +} + /** * BILLING INTERVALS */