61 lines
2.0 KiB
TypeScript
61 lines
2.0 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { readRepoFile } from "~/utils/testing/repoPaths";
|
|
|
|
const dataLoaderPaths = [
|
|
{
|
|
path: "apps/web/app/utils/data/.server/rootData.ts",
|
|
blockedImports: ["~/utils/db/users.db.server", "~/utils/db/tenants.db.server"],
|
|
},
|
|
{
|
|
path: "apps/web/app/utils/data/.server/appData.ts",
|
|
blockedImports: ["~/utils/db/users.db.server"],
|
|
},
|
|
{
|
|
path: "apps/web/app/utils/data/.server/adminData.ts",
|
|
blockedImports: ["~/utils/db/tenants.db.server"],
|
|
},
|
|
];
|
|
|
|
const tenantSelectionRoutePaths = [
|
|
"apps/web/app/routes/app.tsx",
|
|
"apps/web/app/routes/login.tsx",
|
|
];
|
|
|
|
function readLoader(relativePath: string) {
|
|
return readRepoFile(relativePath);
|
|
}
|
|
|
|
describe("auth boundary imports for shared data loaders", () => {
|
|
it.each(dataLoaderPaths)("imports migrated auth/user/tenant reads from @toolctrl/db in $path", ({ path: relativePath }) => {
|
|
const source = readLoader(relativePath);
|
|
|
|
expect(source).toContain("@toolctrl/db/auth-boundary.server");
|
|
});
|
|
|
|
it.each(dataLoaderPaths)("does not import migrated app DB wrappers in $path", ({ path: relativePath, blockedImports }) => {
|
|
const source = readLoader(relativePath);
|
|
|
|
for (const importPath of blockedImports) {
|
|
expect(source).not.toContain(`from "${importPath}"`);
|
|
expect(source).not.toContain(`from '${importPath}'`);
|
|
}
|
|
});
|
|
});
|
|
|
|
describe("auth boundary imports for tenant selection routes", () => {
|
|
it.each(tenantSelectionRoutePaths)("imports migrated auth/user/tenant reads from @toolctrl/db in %s", (relativePath) => {
|
|
const source = readLoader(relativePath);
|
|
|
|
expect(source).toContain("@toolctrl/db/auth-boundary.server");
|
|
});
|
|
|
|
it.each(tenantSelectionRoutePaths)("does not import migrated app DB wrappers in %s", (relativePath) => {
|
|
const source = readLoader(relativePath);
|
|
|
|
for (const importPath of ["~/utils/db/users.db.server", "~/utils/db/tenants.db.server"]) {
|
|
expect(source).not.toContain(`from "${importPath}"`);
|
|
expect(source).not.toContain(`from '${importPath}'`);
|
|
}
|
|
});
|
|
});
|