Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/apps/web/app/services/billing/commercial-plan-names.i18n.test.ts
T

57 lines
2.1 KiB
TypeScript

import fs from "node:fs";
import path from "node:path";
import { hiveGridBasePlans } from "@hivegrid/entitlements";
import { describe, expect, it } from "vitest";
type CommercialPlanLocale = {
pricing?: {
products?: Record<string, { title?: string }>;
};
settings?: {
subscription?: {
seats?: {
package?: Record<string, string>;
};
checkout?: {
plans?: {
packages?: Record<string, { title?: string }>;
};
};
};
};
};
const repositoryRoot = process.cwd();
const expectedNames = Object.fromEntries(hiveGridBasePlans.map((plan) => [plan.seatPackageId, plan.publicName]));
const expectedLegacyPricingNames = Object.fromEntries(hiveGridBasePlans.map((plan, index) => [`plan${index + 1}`, plan.publicName]));
function readLocale(locale: "de" | "en"): CommercialPlanLocale {
return JSON.parse(fs.readFileSync(path.join(repositoryRoot, `apps/web/public/locales/${locale}/translations.json`), "utf8")) as CommercialPlanLocale;
}
describe("commercial billing plan names", () => {
it.each(["de", "en"] as const)("%s keeps seat usage and checkout labels aligned with the commercial catalog", (locale) => {
const translations = readLocale(locale);
const subscription = translations.settings?.subscription;
const seatPackageNames = subscription?.seats?.package;
const checkoutPackageNames = Object.fromEntries(
Object.entries(subscription?.checkout?.plans?.packages ?? {}).map(([packageId, copy]) => [packageId, copy.title])
);
const legacyPricingNames = Object.fromEntries(Object.entries(translations.pricing?.products ?? {}).map(([planId, copy]) => [planId, copy.title]));
expect(seatPackageNames).toEqual(expectedNames);
expect(checkoutPackageNames).toEqual(expectedNames);
expect(legacyPricingNames).toEqual(expectedLegacyPricingNames);
});
it("keeps the stable middle-tier provider mapping customer-facing as Swarm", () => {
const middleTier = hiveGridBasePlans.find((plan) => plan.technicalCode === "pro");
expect(middleTier).toMatchObject({
technicalCode: "pro",
seatPackageId: "team",
publicName: "Swarm",
});
});
});