import { describe, expect, it } from "vitest"; import { planFeature, type InstalledFacts } from "../../scripts/create-feature.ts"; import { GENERATED_FEATURE_ID } from "../../scripts/lib/generated-feature.ts"; import { LISTED_SAMPLE_PROBE_FEATURE_ID, MANUAL_EXAMPLE_FEATURE_ID, MANUAL_PROBE_FEATURE_ID, SCAFFOLD_PROBE_FEATURE_ID, SCAFFOLD_WRITE_PROBE_FEATURE_ID, TEMPLATE_PROBE_PREFIX, renameFeatureText, } from "../../scripts/lib/template-probe-features.ts"; /** * 1112/08-02. The template's own tests add a feature to a copy of the * repository, and that copy holds the product's features. create:feature * refuses an id a feature there has, or one with the same prefix, so a * template test that used the manual's example (`invoice-feature`) or a plain * business word (`order-feature`) failed FE-GATE-005 and FE-GATE-008 in a * product that had built a feature by that name. */ const PROBE_IDS = Object.freeze([ GENERATED_FEATURE_ID, MANUAL_PROBE_FEATURE_ID, LISTED_SAMPLE_PROBE_FEATURE_ID, SCAFFOLD_PROBE_FEATURE_ID, SCAFFOLD_WRITE_PROBE_FEATURE_ID, ]); const TOPIC_SUFFIX = "abcdefghjkmnpqrstvwxyz0123"; /** A product that built features by the names a business app would pick. */ const PRODUCT: InstalledFacts = Object.freeze({ appIds: ["template-app"], featureIds: [ "invoice-feature", "order-feature", "orders-feature", "scaffold-feature", "listed-sample-feature", "invoice", "order", ], contexts: [ { id: "invoice-context", routePath: "invoices/*" }, { id: "order-context", routePath: "orders/*" }, ], contextDirectories: ["invoice-context", "order-context"], routes: [ { routeId: "INVOICE_LIST", path: "/invoices", chunkId: "route-invoice-list", navigationOrder: 50 }, { routeId: "ORDER_LIST", path: "/orders", chunkId: "route-order-list", navigationOrder: 60 }, ], topics: [], messageKeys: ["invoice.list.title", "order.list.title"], }); /** The template as it ships: no feature. */ const TEMPLATE: InstalledFacts = Object.freeze({ appIds: ["template-app"], featureIds: [], contexts: [], contextDirectories: [], routes: [], topics: [], messageKeys: [], }); describe("feature ids the template's tests create in a copy", () => { it("all begin with the reserved probe prefix", () => { for (const id of PROBE_IDS) expect(id.startsWith(TEMPLATE_PROBE_PREFIX), id).toBe(true); expect(new Set(PROBE_IDS).size).toBe(PROBE_IDS.length); }); it("are accepted in a product that built features by business names", () => { for (const id of PROBE_IDS) { expect(() => planFeature({ id, write: "KEYED" }, PRODUCT, () => TOPIC_SUFFIX), id).not.toThrow(); } }); }); describe("renameFeatureText", () => { it("moves every spelling of the manual's example to the probe's", () => { const text = [ "src/features/invoice-feature/presentation/use-invoice-list-filters.ts", "INVOICE_LIST INVOICE_CREATE_EFFECT InvoiceProblem useInvoiceListFilters", "invoiceListSearchSchema invoice.list.title /invoices invoice-create-v1", ].join("\n"); expect(renameFeatureText(text, MANUAL_EXAMPLE_FEATURE_ID, MANUAL_PROBE_FEATURE_ID)).toBe( [ "src/features/typecheck-probe-invoice-feature/presentation/use-typecheck-probe-invoice-list-filters.ts", "TYPECHECK_PROBE_INVOICE_LIST TYPECHECK_PROBE_INVOICE_CREATE_EFFECT TypecheckProbeInvoiceProblem useTypecheckProbeInvoiceListFilters", "typecheckProbeInvoiceListSearchSchema typecheckProbeInvoice.list.title /typecheckProbeInvoices typecheck-probe-invoice-create-v1", ].join("\n"), ); }); it("gives the names create:feature writes for the probe", () => { const manual = planFeature({ id: MANUAL_EXAMPLE_FEATURE_ID, write: "NEVER" }, TEMPLATE, () => TOPIC_SUFFIX); const probe = planFeature({ id: MANUAL_PROBE_FEATURE_ID, write: "NEVER" }, TEMPLATE, () => TOPIC_SUFFIX); expect( [...manual.files.keys()].map((file) => renameFeatureText(file, MANUAL_EXAMPLE_FEATURE_ID, MANUAL_PROBE_FEATURE_ID), ), ).toEqual([...probe.files.keys()]); }); });