Files
co-lite/solvway-admin-portal/app/lib/referenceTables.test.ts
T
ngqileandClaude Opus 5.5 5ee51d1913 chore: copy kept Tastefully modules and portals into Co-Lite
Backend modules from tastefully 8bd93d15: core-libs, core-session,
api-gateway, mobile-api, services-auth, services-system,
services-counter, services-member, services-log, services-email.
solvway-admin-portal from babyboo f64d096ea, solvway-customer-portal
from tastefully 8bd93d15. Copied as tracked files only.

Literal secrets replaced with environment placeholders:
- services-email: SMTP_PASSWORD, MAILGUN_API_KEY, SENDGRID_API_KEY,
  MAILJET_API_KEY, MAILJET_SECRET_KEY (optional, empty default)
- services-system: JUMIO_TOKEN, JUMIO_SECRET (optional)
- services-auth: USER_AUTH_API_SECRET (required); commented JWT secret removed
- core-libs: JWT_TOKEN default removed (required), XXL_JOB_TOKEN default
  removed, ipgeolocation key read from IPGEOLOCATION_API_KEY
- services-system EkycAppConfig: commented Jumio credentials removed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
2026-11-26 15:55:45 +08:00

91 lines
3.9 KiB
TypeScript

import { describe, it, expect } from "vitest";
import { REFERENCE_TABLES } from "./referenceTables";
import { DEFAULT_MESSAGES } from "./i18n/defaultMessages";
// Column registry lock (spec "admin-portal-reference-ui", requirement "One Generic Grid
// Renders Each Table's Registry Columns"): the /reference grid renders EXACTLY the columns
// the picked table's registry declares — preferredLanguage shows no message_tag column,
// nationality adds iso_code, marritalStatus adds a spouse_required (Y/N) select.
function fieldNames(key: string): string[] {
const spec = REFERENCE_TABLES.find((t) => t.key === key);
if (!spec) throw new Error(`no registry entry for ${key}`);
return spec.columns.map((c) => c.field);
}
describe("REFERENCE_TABLES column registry", () => {
it("covers exactly the five allow-listed tables, each keyed by code", () => {
expect(REFERENCE_TABLES.map((t) => t.key)).toEqual([
"nationality",
"marritalStatus",
"race",
"preferredLanguage",
"salutation",
]);
for (const t of REFERENCE_TABLES) {
expect(t.keyField).toBe("code");
expect(t.label.length).toBeGreaterThan(0);
}
});
it("nationality: code, name, message_tag and iso_code", () => {
expect(fieldNames("nationality")).toEqual(["code", "name", "messageTag", "isoCode"]);
});
it("marritalStatus: code, name, message_tag and a spouse_required Y/N select", () => {
const spec = REFERENCE_TABLES.find((t) => t.key === "marritalStatus")!;
expect(fieldNames("marritalStatus")).toEqual(["code", "name", "messageTag", "spouseRequired"]);
const spouse = spec.columns.find((c) => c.field === "spouseRequired")!;
expect(spouse.options?.map((o) => o.value)).toEqual(["Y", "N"]);
expect(spouse.editable).toBe(true);
});
it("preferredLanguage has NO message_tag column (the table has no such column)", () => {
expect(fieldNames("preferredLanguage")).toEqual(["code", "name"]);
});
it("race: code, name and message_tag only", () => {
expect(fieldNames("race")).toEqual(["code", "name", "messageTag"]);
});
it("salutation: code, name and message_tag only", () => {
expect(fieldNames("salutation")).toEqual(["code", "name", "messageTag"]);
});
it("code and name are required and editable on every table; message_tag/iso_code are not", () => {
for (const t of REFERENCE_TABLES) {
const code = t.columns.find((c) => c.field === "code")!;
const name = t.columns.find((c) => c.field === "name")!;
expect(code.required).toBe(true);
expect(code.editable).toBe(true);
expect(name.required).toBe(true);
expect(name.editable).toBe(true);
for (const c of t.columns) {
if (c.field === "messageTag" || c.field === "isoCode") {
expect(c.required ?? false).toBe(false);
}
}
}
});
});
// Copy lock (spec "portal-copy-i18n", A7): table, column and option labels hold message codes,
// translated with t() where they render, so admins can edit and translate them in /messages.
describe("REFERENCE_TABLES labels are message codes", () => {
it("labels every table, column and option with a code that has an English default", () => {
for (const t of REFERENCE_TABLES) {
const labels = [t.label, ...t.columns.flatMap((c) => [c.label, ...(c.options ?? []).map((o) => o.label)])];
for (const label of labels) expect(Object.hasOwn(DEFAULT_MESSAGES, label), label).toBe(true);
}
});
it("names a row with CatName, not the person-name code", () => {
for (const t of REFERENCE_TABLES) expect(t.columns.find((c) => c.field === "name")?.label).toBe("CatName");
});
it("labels the spouse-required options with the shared yes/no codes", () => {
const spouse = REFERENCE_TABLES.find((t) => t.key === "marritalStatus")!.columns.find((c) => c.field === "spouseRequired")!;
expect(spouse.options?.map((o) => o.label)).toEqual(["Yes", "No"]);
});
});