69 lines
2.3 KiB
TypeScript
69 lines
2.3 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { readRepoFile } from "~/utils/testing/repoPaths";
|
|
|
|
type BoundarySurface = {
|
|
path: string;
|
|
packageImports: string[];
|
|
forbiddenImports: string[];
|
|
};
|
|
|
|
const rowApiBoundarySurfaces: BoundarySurface[] = [
|
|
{
|
|
path: "apps/web/app/utils/api/.server/RowsApi.ts",
|
|
packageImports: [
|
|
"@toolctrl/db/rows.server",
|
|
"buildLegacyRowPropertyFiltersWhere",
|
|
"buildLegacyRowQueryWhere",
|
|
"changeLegacyRowOrder",
|
|
"countLegacyRows",
|
|
"createRowWithValues",
|
|
"hardDeleteRowById",
|
|
"getLegacyRow",
|
|
"getLegacyRowById",
|
|
"listLegacyRows",
|
|
"updateRowWithValues",
|
|
],
|
|
forbiddenImports: ["~/utils/db.server", "~/utils/db/entities/rows.db.server", "../../db/entities/rows.db.server"],
|
|
},
|
|
{
|
|
path: "apps/web/app/utils/api/.server/RowRelationshipsApi.ts",
|
|
packageImports: [
|
|
"@toolctrl/db/relationships.server",
|
|
"createLegacyRowRelationship",
|
|
"deleteLegacyRowRelationship",
|
|
"deleteLegacyRowRelationshipById",
|
|
"findLegacyEntityRelationship",
|
|
"findLegacyRowRelationshipById",
|
|
],
|
|
forbiddenImports: ["~/utils/db.server", "~/utils/db/entities/rowRelationships.db.server", "../../db/entities/rowRelationships.db.server"],
|
|
},
|
|
];
|
|
|
|
function readSource(relativePath: string) {
|
|
return readRepoFile(relativePath);
|
|
}
|
|
|
|
function importFrom(importPath: string) {
|
|
return [`from \"${importPath}\"`, `from '${importPath}'`];
|
|
}
|
|
|
|
describe("row API package boundary imports", () => {
|
|
it.each(rowApiBoundarySurfaces)("imports migrated row persistence helpers from package boundaries in $path", ({ path: relativePath, packageImports }) => {
|
|
const source = readSource(relativePath);
|
|
|
|
for (const packageImport of packageImports) {
|
|
expect(source, `${relativePath} should import ${packageImport}`).toContain(packageImport);
|
|
}
|
|
});
|
|
|
|
it.each(rowApiBoundarySurfaces)("does not reintroduce app-local row persistence imports in $path", ({ path: relativePath, forbiddenImports }) => {
|
|
const source = readSource(relativePath);
|
|
|
|
for (const forbiddenImport of forbiddenImports) {
|
|
for (const importStatement of importFrom(forbiddenImport)) {
|
|
expect(source, `${relativePath} should not import ${forbiddenImport}`).not.toContain(importStatement);
|
|
}
|
|
}
|
|
});
|
|
});
|