Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/packages/entitlements/src/commercial-catalog.test.ts
T

200 lines
7.9 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
calculateStorageAddOnGrossMarginAfterEgressBasisPoints,
calculateStorageAddOnGrossMarginBasisPoints,
billingCadences,
calculateBillingCatalogPrice,
calculateHiveGridGrossAmountCents,
calculateHiveGridVatAmountCents,
getBillingCatalogPlan,
getBillingCatalogStorageAddOn,
getBillingCatalogVariant,
getBillingCatalogVariantForSelection,
hiveGridBasePlans,
hiveGridBillingCatalogVersion,
hiveGridPurchasableStorageAddOns,
hiveGridStorageAddOns,
hiveGridVat,
storageAddOnEgressCoverageCycles,
serializeHiveGridBillingCatalog,
} from "./commercial-catalog.js";
describe("HiveGrid commercial billing catalog", () => {
it("maps the stable technical codes to Core, Swarm and Colony", () => {
expect(hiveGridBasePlans.map(({ technicalCode, publicName }) => ({ technicalCode, publicName }))).toEqual([
{ technicalCode: "starter", publicName: "Core" },
{ technicalCode: "pro", publicName: "Swarm" },
{ technicalCode: "business", publicName: "Colony" },
]);
});
it("models annual pricing as a monthly rate with a 12-month commitment and free payment-method choice", () => {
expect(getBillingCatalogPlan("starter")).toMatchObject({
includedSeats: { office: 2, field: 5 },
includedStorageGb: 100,
storagePerAdditionalSeatGb: 10,
variants: [
{
code: "starter",
cadence: "monthly",
lagoInterval: "monthly",
contractMonths: 1,
requiredPaymentMethod: "any",
baseAmountCents: 19_900,
extraSeatAmountCents: { office: 5_900, field: 2_500 },
},
{
code: "starter_annual_sepa",
cadence: "annual_sepa",
lagoInterval: "monthly",
contractMonths: 12,
requiredPaymentMethod: "any",
baseAmountCents: 17_900,
extraSeatAmountCents: { office: 5_310, field: 2_250 },
},
],
});
expect(getBillingCatalogVariantForSelection("pro", billingCadences.annualSepa)).toMatchObject({
code: "pro_annual_sepa",
baseAmountCents: 44_900,
extraSeatAmountCents: { office: 3_510, field: 1_710 },
});
expect(getBillingCatalogVariant("business_annual_sepa")).toMatchObject({
baseAmountCents: 89_900,
extraSeatAmountCents: { office: 3_150, field: 1_350 },
});
});
it("gives larger plans a larger shared pool and more storage per additional license", () => {
expect(
hiveGridBasePlans.map(({ technicalCode, includedStorageGb, storagePerAdditionalSeatGb }) => ({
technicalCode,
includedStorageGb,
storagePerAdditionalSeatGb,
}))
).toEqual([
{ technicalCode: "starter", includedStorageGb: 100, storagePerAdditionalSeatGb: 10 },
{ technicalCode: "pro", includedStorageGb: 500, storagePerAdditionalSeatGb: 20 },
{ technicalCode: "business", includedStorageGb: 2_000, storagePerAdditionalSeatGb: 40 },
]);
});
it("defines the fixed recurring storage packages without usage metering", () => {
expect(hiveGridStorageAddOns).toEqual([
expect.objectContaining({ code: "storage_100gb", includedStorageGb: 100, amountCents: 125, purchasable: false, lagoInterval: "monthly" }),
expect.objectContaining({ code: "storage_500gb", includedStorageGb: 500, amountCents: 699, purchasable: true, lagoInterval: "monthly" }),
expect.objectContaining({ code: "storage_1tb", includedStorageGb: 1_000, amountCents: 1_299, purchasable: true, lagoInterval: "monthly" }),
expect.objectContaining({ code: "storage_5tb", includedStorageGb: 5_000, amountCents: 6_099, purchasable: true, lagoInterval: "monthly" }),
]);
expect(hiveGridPurchasableStorageAddOns.map(({ code, amountCents }) => ({ code, amountCents }))).toEqual([
{ code: "storage_500gb", amountCents: 699 },
{ code: "storage_1tb", amountCents: 1_299 },
{ code: "storage_5tb", amountCents: 6_099 },
]);
expect(getBillingCatalogStorageAddOn("storage_1tb")?.publicName).toBe("Cloud-Speicher Plus · 1 TB");
expect(hiveGridStorageAddOns.map(calculateStorageAddOnGrossMarginBasisPoints)).toEqual([4_623, 5_192, 4_826, 4_490]);
expect(
hiveGridPurchasableStorageAddOns.map((addOn) =>
calculateStorageAddOnGrossMarginAfterEgressBasisPoints(addOn, storageAddOnEgressCoverageCycles)
)
).toEqual([1_352, 693, 88]);
expect(
hiveGridPurchasableStorageAddOns.every(
(addOn) => calculateStorageAddOnGrossMarginAfterEgressBasisPoints(addOn, storageAddOnEgressCoverageCycles) > 0
)
).toBe(true);
expect(calculateStorageAddOnGrossMarginAfterEgressBasisPoints(hiveGridPurchasableStorageAddOns.at(-1)!, 6)).toBeLessThan(0);
expect(() => calculateStorageAddOnGrossMarginAfterEgressBasisPoints(hiveGridPurchasableStorageAddOns[0]!, -1)).toThrow(
/egress cycles/u
);
});
it("calculates role-specific extras and fixed storage packages from the same catalog", () => {
expect(
calculateBillingCatalogPrice({
planCode: "starter",
cadence: billingCadences.monthly,
officeSeatQuantity: 4,
fieldSeatQuantity: 8,
storageAddOnCodes: ["storage_500gb"],
})
).toMatchObject({
variantCode: "starter",
extraOfficeSeatQuantity: 2,
extraFieldSeatQuantity: 3,
baseAmountCents: 19_900,
officeSeatAmountCents: 11_800,
fieldSeatAmountCents: 7_500,
storageAmountCents: 699,
recurringNetAmountCents: 39_899,
vatRateBasisPoints: 1_900,
vatAmountCents: 7_581,
recurringGrossAmountCents: 47_480,
});
expect(
calculateBillingCatalogPrice({
planCode: "starter",
cadence: billingCadences.annualSepa,
officeSeatQuantity: 4,
fieldSeatQuantity: 8,
storageAddOnCodes: ["storage_500gb"],
})
).toMatchObject({
recurringNetAmountCents: 35_969,
vatAmountCents: 6_834,
recurringGrossAmountCents: 42_803,
});
});
it("fails closed for unknown, duplicate or invalid selection values", () => {
expect(() =>
calculateBillingCatalogPrice({
planCode: "unknown",
cadence: billingCadences.monthly,
officeSeatQuantity: 1,
fieldSeatQuantity: 1,
})
).toThrow(/Unknown billing plan/);
expect(() =>
calculateBillingCatalogPrice({
planCode: "starter",
cadence: billingCadences.monthly,
officeSeatQuantity: 2,
fieldSeatQuantity: 5,
storageAddOnCodes: ["storage_100gb", "storage_100gb"],
})
).toThrow(/unique/);
});
it("pins the German VAT contract and emits a deterministic manifest", () => {
expect(hiveGridVat).toEqual({
code: "de-vat-19",
name: "Deutsche Umsatzsteuer 19 %",
countryCode: "DE",
rateBasisPoints: 1_900,
appliedToAmount: "exclusive",
});
expect(hiveGridBillingCatalogVersion).toBe("2026-08-03.3");
expect(serializeHiveGridBillingCatalog()).toBe(serializeHiveGridBillingCatalog());
expect(JSON.parse(serializeHiveGridBillingCatalog())).toMatchObject({
version: "2026-08-03.3",
basePlans: [{ publicName: "Core" }, { publicName: "Swarm" }, { publicName: "Colony" }],
});
});
it("calculates gross product amounts with the same pinned German VAT rounding contract", () => {
expect(calculateHiveGridVatAmountCents(5_900)).toBe(1_121);
expect(calculateHiveGridGrossAmountCents(5_900)).toBe(7_021);
expect(calculateHiveGridGrossAmountCents(1_999)).toBe(2_379);
expect(calculateHiveGridGrossAmountCents(29_999)).toBe(35_699);
expect(() => calculateHiveGridGrossAmountCents(-1)).toThrow(/non-negative safe integer/u);
});
it("returns undefined for unknown public catalog references", () => {
expect(getBillingCatalogPlan("enterprise")).toBeUndefined();
expect(getBillingCatalogVariant("enterprise")).toBeUndefined();
expect(getBillingCatalogStorageAddOn("storage_50tb")).toBeUndefined();
});
});