Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/packages/db/src/subscriptions-boundary.test.ts
T
2026-07-08 16:15:37 +02:00

75 lines
2.9 KiB
TypeScript

import { readFileSync } from "node:fs";
import { resolve } from "node:path";
import { describe, expect, it } from "vitest";
const repoRoot = resolve(__dirname, "../../..");
function readRepoFile(path: string) {
return readFileSync(resolve(repoRoot, path), "utf8");
}
const migratedWrappers = [
"apps/web/app/utils/db/subscriptionProducts.db.server.ts",
"apps/web/app/utils/db/tenantSubscriptions.db.server.ts",
"apps/web/app/utils/db/subscriptions/tenantSubscriptionProducts.db.server.ts",
];
const directBillingPrismaModels = [
"subscriptionProduct",
"subscriptionPrice",
"subscriptionFeature",
"subscriptionUsageBasedPrice",
"subscriptionUsageBasedTier",
"tenantSubscription",
"tenantSubscriptionProduct",
"tenantSubscriptionProductPrice",
"tenantSubscriptionUsageRecord",
"checkoutSessionStatus",
];
describe("subscription app boundary", () => {
it.each(migratedWrappers)("keeps %s behind @hivegrid/db/subscriptions.server", (path) => {
const source = readRepoFile(path);
expect(source).toContain("@hivegrid/db/subscriptions.server");
expect(source).not.toContain("~/utils/db.server");
expect(source).not.toContain("../../db.server");
expect(source).not.toContain("../db.server");
expect(source).not.toMatch(/\bdb\.[a-zA-Z]/);
});
it("keeps subscriptionService subscription billing persistence behind the package boundary", () => {
const source = readRepoFile("apps/web/app/utils/services/.server/subscriptionService.ts");
expect(source).toContain("@hivegrid/db/subscriptions.server");
expect(source).toContain("../../db.server");
expect(source).toContain("clearCacheKey");
expect(source).toContain("cancelTenantSubscription");
expect(source).toContain("EventsService.create");
for (const model of directBillingPrismaModels) {
expect(source).not.toMatch(new RegExp(`\\bdb\\.${model}\\b`));
}
});
it("keeps tenant subscription settings writes behind cache-clearing web wrappers", () => {
const source = readRepoFile("apps/web/app/routes/app.$tenant/settings/subscription.tsx");
const directPackageImport = source.match(/import\s+\{([^}]+)\}\s+from\s+["']@hivegrid\/db\/subscriptions\.server["']/s);
const importedNames = directPackageImport?.[1] ?? "";
expect(importedNames).not.toMatch(/\bcreateTenantSubscription\b/);
expect(importedNames).not.toMatch(/\bupdateTenantSubscriptionCustomerId\b/);
expect(source).toContain("~/utils/db/tenantSubscriptions.db.server");
});
it("keeps the legacy subscribe route free of in-app checkout writes and plan UI", () => {
const source = readRepoFile("apps/web/app/routes/subscribe.$tenant.tsx");
expect(source).not.toContain("@hivegrid/db/subscriptions.server");
expect(source).not.toContain("~/utils/db/tenantSubscriptions.db.server");
expect(source).not.toContain("createCheckoutSession");
expect(source).not.toContain("createBillingCustomer");
expect(source).not.toContain("PlansGrouped");
});
});