65 lines
2.0 KiB
TypeScript
65 lines
2.0 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { readFileSync } from "node:fs";
|
|
|
|
type MigratedAnalyticsRoute = {
|
|
path: string;
|
|
packageImports: string[];
|
|
};
|
|
|
|
const migratedAnalyticsRoutes: MigratedAnalyticsRoute[] = [
|
|
{
|
|
path: "overview.tsx",
|
|
packageImports: ["getAnalyticsOverview"],
|
|
},
|
|
{
|
|
path: "visitors.tsx",
|
|
packageImports: ["getAnalyticsVisitorList"],
|
|
},
|
|
{
|
|
path: "events.tsx",
|
|
packageImports: ["getAnalyticsEventFilterOptions", "getAnalyticsEventList"],
|
|
},
|
|
{
|
|
path: "page-views.tsx",
|
|
packageImports: ["getAnalyticsPageViewFilterOptions", "getAnalyticsPageViewList"],
|
|
},
|
|
{
|
|
path: "settings.tsx",
|
|
packageImports: ["deleteAllAnalyticsData", "getOrCreateAnalyticsSettings", "removeAnalyticsIgnoredPage", "updateAnalyticsSettingsPreferences"],
|
|
},
|
|
];
|
|
|
|
const forbiddenAnalyticsBoundaryImports = [
|
|
"~/utils/db.server",
|
|
"~/utils/helpers/.server/AnalyticsService",
|
|
"~/utils/db/users.db.server",
|
|
"~/modules/featureFlags/db/featureFlags.db.server",
|
|
];
|
|
|
|
function readRouteSource(path: string) {
|
|
return readFileSync(new URL(path, import.meta.url), "utf8");
|
|
}
|
|
|
|
describe("migrated admin analytics route DB boundary imports", () => {
|
|
it("uses the package-owned analytics server helpers in every migrated route", () => {
|
|
for (const route of migratedAnalyticsRoutes) {
|
|
const source = readRouteSource(route.path);
|
|
|
|
expect(source, `${route.path} should import the analytics package boundary`).toContain("@toolctrl/db/analytics.server");
|
|
for (const packageImport of route.packageImports) {
|
|
expect(source, `${route.path} should import ${packageImport}`).toContain(packageImport);
|
|
}
|
|
}
|
|
});
|
|
|
|
it("does not reintroduce app-local analytics DB imports in migrated routes", () => {
|
|
for (const route of migratedAnalyticsRoutes) {
|
|
const source = readRouteSource(route.path);
|
|
|
|
for (const forbiddenImport of forbiddenAnalyticsBoundaryImports) {
|
|
expect(source, `${route.path} should not import ${forbiddenImport}`).not.toContain(forbiddenImport);
|
|
}
|
|
}
|
|
});
|
|
});
|