added a ton of tests for new plan, immediate and scheduled switch

This commit is contained in:
John Yeo
2026-02-02 14:48:30 +00:00
parent fa893306bf
commit 78f1d131e5
157 changed files with 18692 additions and 1634 deletions

View File

@@ -0,0 +1,29 @@
import type { FeatureOptions } from "@models/cusProductModels/cusProductModels";
import type { EntitlementWithFeature } from "@models/productModels/entModels/entModels";
import type { Price } from "@models/productModels/priceModels/priceModels";
import { priceUtils } from "@utils/productUtils/priceUtils/index";
import { Decimal } from "decimal.js";
export const featureOptionsToV2StripeQuantity = ({
featureOptions,
price,
entitlement,
}: {
featureOptions?: FeatureOptions;
price: Price;
entitlement: EntitlementWithFeature;
}) => {
const packsExcludingAllowance =
featureOptions?.upcoming_quantity ?? featureOptions?.quantity;
const allowanceInPacks = priceUtils.convert.toAllowanceInPacks({
price,
entitlement,
});
// 1. If no packs, return allowance
if (!packsExcludingAllowance) return allowanceInPacks;
// 2. Otherwise, return the total quantity
return new Decimal(packsExcludingAllowance).add(allowanceInPacks).toNumber();
};