From 5a1c59542cce16cfc86c42d4c8af2e1faa6ad673 Mon Sep 17 00:00:00 2001 From: BigSimmo <87357024+BigSimmo@users.noreply.github.com> Date: Sun, 16 Aug 2026 19:57:15 +0800 Subject: [PATCH] test(ingest): add registry service facets contract test --- tests/registry-service-facets.test.ts | 67 +++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 tests/registry-service-facets.test.ts diff --git a/tests/registry-service-facets.test.ts b/tests/registry-service-facets.test.ts new file mode 100644 index 0000000000..3d7991cf3c --- /dev/null +++ b/tests/registry-service-facets.test.ts @@ -0,0 +1,67 @@ +import { describe, expect, it } from "vitest"; + +import { defaultServiceRecords } from "@/lib/registry-fixtures"; +import { recordToRow, rowToServiceRecord, type RegistryRecordRow } from "@/lib/registry-records"; +import { serviceCatalogTags, serviceFacetDimensions } from "@/lib/service-facets"; +import type { ServiceRecord } from "@/lib/services"; + +const ownerId = "11111111-1111-4111-8111-111111111111"; +const tagDimensions = [...serviceFacetDimensions, "substance_flags"] as const; + +function roundTrip(record: ServiceRecord): ServiceRecord { + const row = recordToRow(record, ownerId, "service"); + return rowToServiceRecord(row as RegistryRecordRow); +} + +describe("registry service facet payloads", () => { + it("preserves all six tag dimensions for the 219 default service records", () => { + const records = defaultServiceRecords(); + + expect(records).toHaveLength(219); + for (const record of records) { + const row = recordToRow(record, ownerId, "service"); + const restored = rowToServiceRecord(row as RegistryRecordRow); + + expect(row.catalog_payload).toEqual(record.catalogPayload); + for (const dimension of tagDimensions) { + expect(serviceCatalogTags(restored)[dimension]).toEqual(serviceCatalogTags(record)[dimension]); + } + } + }); + + it("degrades absent and malformed payloads to only their valid string-array values", () => { + const absent = roundTrip({ slug: "absent", title: "Absent payload" }); + const malformedTags = roundTrip({ + slug: "malformed-tags", + title: "Malformed tags", + catalogPayload: { tags: "not-an-object" }, + }); + const partiallyMalformed = roundTrip({ + slug: "partially-malformed", + title: "Partially malformed tags", + catalogPayload: { + tags: { + catchments: [" Metro-wide ", "", 7, null], + age_groups: "youth", + setting_flags: null, + acuity_flags: { value: "high" }, + substance_flags: [false, " aod "], + housing_flags: [null, " home_based "], + }, + }, + }); + + for (const record of [absent, malformedTags]) { + const tags = serviceCatalogTags(record); + for (const dimension of tagDimensions) expect(tags[dimension]).toEqual([]); + } + expect(serviceCatalogTags(partiallyMalformed)).toEqual({ + catchments: ["Metro-wide"], + age_groups: [], + setting_flags: [], + acuity_flags: [], + substance_flags: ["aod"], + housing_flags: ["home_based"], + }); + }); +});