chore(gatekeeper): fix test

This commit is contained in:
Alessandro Magionami
2025-03-07 16:38:36 +01:00
parent dd461b2fb4
commit 1eb7331733
8 changed files with 14 additions and 34 deletions
@@ -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}`
@@ -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<Products, { productId: string; monthly: string; yearly: string }>,
'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<
@@ -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
})
@@ -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()
+2 -6
View File
@@ -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'),
@@ -21,8 +21,7 @@ describe('Workspace plan prices', () => {
let expectedPlans = [
...Object.values(PaidWorkspacePlans),
WorkspaceGuestSeatType,
'viewer'
WorkspaceGuestSeatType
].filter(
(p) =>
FF_WORKSPACES_NEW_PLANS_ENABLED ||
@@ -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: () => {
@@ -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