From 1eb7331733dbb53dbf2f3fa4de2c40c1108e8713 Mon Sep 17 00:00:00 2001 From: Alessandro Magionami Date: Fri, 7 Mar 2025 16:38:36 +0100 Subject: [PATCH] chore(gatekeeper): fix test --- .../gatekeeper/clients/checkout/createCheckoutSession.ts | 9 --------- packages/server/modules/gatekeeper/domain/billing.ts | 6 ++---- .../gatekeeper/services/checkout/startCheckoutSession.ts | 9 ++++----- packages/server/modules/gatekeeper/services/prices.ts | 5 ++++- packages/server/modules/gatekeeper/stripe.ts | 8 ++------ .../modules/gatekeeper/tests/intergration/prices.spec.ts | 3 +-- .../modules/gatekeeper/tests/unit/subscriptions.spec.ts | 6 ------ packages/server/modules/gatekeeperCore/domain/billing.ts | 2 +- 8 files changed, 14 insertions(+), 34 deletions(-) diff --git a/packages/server/modules/gatekeeper/clients/checkout/createCheckoutSession.ts b/packages/server/modules/gatekeeper/clients/checkout/createCheckoutSession.ts index af95208c7..cd32e8f2a 100644 --- a/packages/server/modules/gatekeeper/clients/checkout/createCheckoutSession.ts +++ b/packages/server/modules/gatekeeper/clients/checkout/createCheckoutSession.ts @@ -86,7 +86,6 @@ export const createCheckoutSessionFactoryNew = }): CreateCheckoutSession => async ({ editorsCount, - viewersCount, workspacePlan, billingInterval, workspaceSlug, @@ -98,14 +97,6 @@ export const createCheckoutSessionFactoryNew = const costLineItems: Stripe.Checkout.SessionCreateParams.LineItem[] = [ { price, quantity: editorsCount } ] - if (viewersCount > 0) - costLineItems.push({ - price: getWorkspacePlanPrice({ - workspacePlan: 'viewer', - billingInterval - }), - quantity: viewersCount - }) const cancel_url = isCreateFlow ? `${frontendOrigin}/workspaces/create?workspaceId=${workspaceId}&payment_status=canceled&session_id={CHECKOUT_SESSION_ID}` diff --git a/packages/server/modules/gatekeeper/domain/billing.ts b/packages/server/modules/gatekeeper/domain/billing.ts index 219038218..b09febc80 100644 --- a/packages/server/modules/gatekeeper/domain/billing.ts +++ b/packages/server/modules/gatekeeper/domain/billing.ts @@ -81,7 +81,6 @@ export type CreateCheckoutSession = (args: { workspaceId: string workspaceSlug: string editorsCount: number - viewersCount: number workspacePlan: PaidWorkspacePlans billingInterval: WorkspacePlanBillingIntervals isCreateFlow: boolean @@ -168,15 +167,14 @@ export type GetWorkspacePlanProductId = (args: { workspacePlan: WorkspacePricingProducts }) => string -type Products = 'guest' | 'starter' | 'plus' | 'business' | 'viewer' | 'team' | 'pro' +type Products = 'guest' | 'starter' | 'plus' | 'business' | 'team' | 'pro' export type GetWorkspacePlanProductAndPriceIds = () => Omit< Record, - 'viewer' | 'team' | 'pro' + 'team' | 'pro' > & { team?: { productId: string; monthly: string } pro?: { productId: string; monthly: string; yearly: string } - viewer?: { productId: string; monthly: string; yearly: string } } export type SubscriptionDataInput = OverrideProperties< diff --git a/packages/server/modules/gatekeeper/services/checkout/startCheckoutSession.ts b/packages/server/modules/gatekeeper/services/checkout/startCheckoutSession.ts index f99455427..a728459b8 100644 --- a/packages/server/modules/gatekeeper/services/checkout/startCheckoutSession.ts +++ b/packages/server/modules/gatekeeper/services/checkout/startCheckoutSession.ts @@ -255,17 +255,16 @@ export const startCheckoutSessionFactoryNew = } } - const [editorsCount, viewersCount] = await Promise.all([ - countSeatsByTypeInWorkspace({ workspaceId, type: 'editor' }), - countSeatsByTypeInWorkspace({ workspaceId, type: 'viewer' }) - ]) + const editorsCount = await countSeatsByTypeInWorkspace({ + workspaceId, + type: 'editor' + }) const checkoutSession = await createCheckoutSession({ workspaceId, workspaceSlug, billingInterval, workspacePlan, - viewersCount, editorsCount, isCreateFlow }) diff --git a/packages/server/modules/gatekeeper/services/prices.ts b/packages/server/modules/gatekeeper/services/prices.ts index ee3b10e50..43fe95714 100644 --- a/packages/server/modules/gatekeeper/services/prices.ts +++ b/packages/server/modules/gatekeeper/services/prices.ts @@ -49,10 +49,13 @@ export const getFreshWorkspacePlanProductPricesFactory = if ('yearly' in planIds) { const { yearly } = planIds const yearlyPrice = productPrices.find((p) => p.id === yearly) - if (!yearlyPrice) + if (!yearlyPrice) { + console.log({ plan }) + console.log({ yearlyPrice }) throw new MisconfiguredEnvironmentError( `Price ${yearly} not found for plan ${plan}` ) + } yearlyStruct = { amount: yearlyPrice.unitAmount / 100, currency: yearlyPrice.currency.toUpperCase() diff --git a/packages/server/modules/gatekeeper/stripe.ts b/packages/server/modules/gatekeeper/stripe.ts index 76ec6f617..25d2de5ad 100644 --- a/packages/server/modules/gatekeeper/stripe.ts +++ b/packages/server/modules/gatekeeper/stripe.ts @@ -48,14 +48,10 @@ export const getWorkspacePlanProductAndPriceIds: GetWorkspacePlanProductAndPrice // new ...(FF_WORKSPACES_NEW_PLANS_ENABLED ? { - viewer: { - productId: getStringFromEnv('WORKSPACE_PRO_SEAT_STRIPE_PRODUCT_ID'), - monthly: getStringFromEnv('WORKSPACE_MONTHLY_PRO_SEAT_STRIPE_PRICE_ID'), - yearly: getStringFromEnv('WORKSPACE_YEARLY_PRO_SEAT_STRIPE_PRICE_ID') - }, team: { productId: getStringFromEnv('WORKSPACE_TEAM_SEAT_STRIPE_PRODUCT_ID'), - monthly: getStringFromEnv('WORKSPACE_MONTHLY_TEAM_SEAT_STRIPE_PRICE_ID') + monthly: getStringFromEnv('WORKSPACE_MONTHLY_TEAM_SEAT_STRIPE_PRICE_ID'), + yearly: getStringFromEnv('WORKSPACE_YEARLY_TEAM_SEAT_STRIPE_PRICE_ID') }, pro: { productId: getStringFromEnv('WORKSPACE_PRO_SEAT_STRIPE_PRODUCT_ID'), diff --git a/packages/server/modules/gatekeeper/tests/intergration/prices.spec.ts b/packages/server/modules/gatekeeper/tests/intergration/prices.spec.ts index 461fc3234..59da23a29 100644 --- a/packages/server/modules/gatekeeper/tests/intergration/prices.spec.ts +++ b/packages/server/modules/gatekeeper/tests/intergration/prices.spec.ts @@ -21,8 +21,7 @@ describe('Workspace plan prices', () => { let expectedPlans = [ ...Object.values(PaidWorkspacePlans), - WorkspaceGuestSeatType, - 'viewer' + WorkspaceGuestSeatType ].filter( (p) => FF_WORKSPACES_NEW_PLANS_ENABLED || diff --git a/packages/server/modules/gatekeeper/tests/unit/subscriptions.spec.ts b/packages/server/modules/gatekeeper/tests/unit/subscriptions.spec.ts index ad536dbe7..f9eb9b3d1 100644 --- a/packages/server/modules/gatekeeper/tests/unit/subscriptions.spec.ts +++ b/packages/server/modules/gatekeeper/tests/unit/subscriptions.spec.ts @@ -451,7 +451,6 @@ describe('subscriptions @gatekeeper', () => { case 'plus': case 'team': case 'pro': - case 'viewer': expect.fail() case 'guest': return priceId @@ -517,7 +516,6 @@ describe('subscriptions @gatekeeper', () => { case 'guest': case 'team': case 'pro': - case 'viewer': expect.fail() case 'starter': return priceId @@ -596,7 +594,6 @@ describe('subscriptions @gatekeeper', () => { case 'guest': case 'team': case 'pro': - case 'viewer': expect.fail() case 'starter': return priceId @@ -670,7 +667,6 @@ describe('subscriptions @gatekeeper', () => { case 'guest': case 'team': case 'pro': - case 'viewer': expect.fail() case 'starter': return priceId @@ -1426,8 +1422,6 @@ describe('subscriptions @gatekeeper', () => { return 'teamProduct' case 'pro': return 'proProduct' - case 'viewer': - return 'viewerProduct' } }, getWorkspacePlanPriceId: () => { diff --git a/packages/server/modules/gatekeeperCore/domain/billing.ts b/packages/server/modules/gatekeeperCore/domain/billing.ts index edb1197a1..402fe3c9b 100644 --- a/packages/server/modules/gatekeeperCore/domain/billing.ts +++ b/packages/server/modules/gatekeeperCore/domain/billing.ts @@ -13,7 +13,7 @@ import { OverrideProperties, SetOptional } from 'type-fest' /** * This includes the pricing plans (Stripe products) a customer can sub to */ -export type WorkspacePricingProducts = PaidWorkspacePlans | 'guest' | 'viewer' +export type WorkspacePricingProducts = PaidWorkspacePlans | 'guest' type BaseWorkspacePlan = { workspaceId: string