73 lines
3.4 KiB
TypeScript
73 lines
3.4 KiB
TypeScript
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
const routeRoot = path.resolve(process.cwd(), "apps/web/app/routes/admin/entities");
|
|
const tenantRouteRoot = path.resolve(process.cwd(), "apps/web/app/routes/app.$tenant/settings/entities");
|
|
const propertyHelperPath = path.resolve(process.cwd(), "apps/web/app/utils/helpers/PropertyHelper.ts");
|
|
|
|
function readRoute(relativePath: string) {
|
|
return fs.readFileSync(path.join(routeRoot, relativePath), "utf8");
|
|
}
|
|
|
|
describe("admin entity property route scoping", () => {
|
|
it("scopes property detail reads and mutations to the current entity", () => {
|
|
const source = readRoute("$entity/properties/$id.tsx");
|
|
|
|
expect(source).toContain("getScopedProperty");
|
|
expect(source).toContain("updateScopedProperty");
|
|
expect(source).toContain("updateScopedPropertyOptions");
|
|
expect(source).toContain("updateScopedPropertyAttributes");
|
|
expect(source).toContain("deleteScopedProperty");
|
|
expect(source).toContain("entityId: entity.id");
|
|
expect(source).not.toMatch(/\bgetProperty\(/);
|
|
expect(source).not.toMatch(/\bupdateProperty\(/);
|
|
expect(source).not.toMatch(/\bupdatePropertyOptions\(/);
|
|
expect(source).not.toMatch(/\bupdatePropertyAttributes\(/);
|
|
expect(source).not.toMatch(/\bdeleteProperty\(/);
|
|
});
|
|
|
|
it("scopes property list actions to the current entity", () => {
|
|
const source = readRoute("$entity/properties.tsx");
|
|
|
|
expect(source).toContain("getScopedProperty");
|
|
expect(source).toContain("updateScopedProperty");
|
|
expect(source).toContain("updateScopedPropertyOrder");
|
|
expect(source).toContain("deleteScopedProperty");
|
|
expect(source).toContain("allowedPropertyIds");
|
|
expect(source).toContain("entityId: entity.id");
|
|
expect(source).not.toMatch(/\bgetProperty\(/);
|
|
expect(source).not.toMatch(/\bupdateProperty\(/);
|
|
expect(source).not.toMatch(/\bupdatePropertyOrder\(/);
|
|
expect(source).not.toMatch(/\bdeleteProperty\(/);
|
|
});
|
|
|
|
it("keeps property validation errors behind semantic translation keys", () => {
|
|
const source = [
|
|
readRoute("$entity/properties/new.tsx"),
|
|
readRoute("$entity/properties/$id.tsx"),
|
|
fs.readFileSync(path.join(tenantRouteRoot, "$entity/new.tsx"), "utf8"),
|
|
fs.readFileSync(path.join(tenantRouteRoot, "$entity/$id.tsx"), "utf8"),
|
|
fs.readFileSync(propertyHelperPath, "utf8"),
|
|
].join("\n");
|
|
|
|
expect(source).toContain("models.property.errors.existingName");
|
|
expect(source).toContain("models.property.errors.existingTitle");
|
|
expect(source).toContain("models.property.errors.nameNoSpaces");
|
|
expect(source).toContain("models.property.errors.nameNoHyphen");
|
|
expect(source).toContain("models.property.errors.reservedName");
|
|
expect(source).not.toContain('throw Error("Property names cannot contain spaces")');
|
|
expect(source).not.toContain('throw Error("Property names cannot contain: -")');
|
|
expect(source).not.toContain('" is a reserved property name"');
|
|
});
|
|
|
|
it("keeps tenant entity feature gate errors behind semantic translation keys", () => {
|
|
const source = [fs.readFileSync(path.join(tenantRouteRoot, "index.tsx"), "utf8"), fs.readFileSync(path.join(tenantRouteRoot, "$entity.tsx"), "utf8")].join(
|
|
"\n"
|
|
);
|
|
|
|
expect(source).toContain("settings.entities.errors.tenantEntityCustomizationNotEnabled");
|
|
expect(source).not.toContain('throw Error("Entity customization is not enabled")');
|
|
});
|
|
});
|