mirror of
https://github.com/Hestia-Homes/assessment-model.git
synced 2026-07-27 22:45:03 +00:00
Slice 2. Same shape as slice 1: resolveBuiltForm + builtFormOverrideJoin / resolvedBuiltFormSql, wired into getProperties SELECT, the filter colMap, and the count query's join set (builtForm added to EPC_JOIN_FILTER_FIELDS). BUILT_FORM_OPTIONS gains Unknown (Not Recorded now matches only an explicit override of that literal). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
194 lines
5.7 KiB
TypeScript
194 lines
5.7 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { resolveBuiltForm, resolvePropertyType } from "./descriptorResolution";
|
|
|
|
describe("resolvePropertyType", () => {
|
|
it("prefers a landlord override over the EPC-derived value", () => {
|
|
expect(
|
|
resolvePropertyType({
|
|
override: "Maisonette",
|
|
isNewApproach: true,
|
|
lodgedPropertyType: "2", // EPC code for Flat
|
|
lodgedDwellingType: null,
|
|
predictedPropertyType: null,
|
|
predictedDwellingType: null,
|
|
legacyPropertyType: null,
|
|
}),
|
|
).toBe("Maisonette");
|
|
});
|
|
|
|
it("maps an RdSAP property-type code to its label when there is no override", () => {
|
|
expect(
|
|
resolvePropertyType({
|
|
override: null,
|
|
isNewApproach: true,
|
|
lodgedPropertyType: "0", // RdSAP code for House
|
|
lodgedDwellingType: null,
|
|
predictedPropertyType: null,
|
|
predictedDwellingType: null,
|
|
legacyPropertyType: null,
|
|
}),
|
|
).toBe("House");
|
|
});
|
|
|
|
it("falls back to the predicted EPC when there is no lodged value", () => {
|
|
expect(
|
|
resolvePropertyType({
|
|
override: null,
|
|
isNewApproach: true,
|
|
lodgedPropertyType: null,
|
|
lodgedDwellingType: null,
|
|
predictedPropertyType: "2", // RdSAP code for Flat
|
|
predictedDwellingType: null,
|
|
legacyPropertyType: null,
|
|
}),
|
|
).toBe("Flat");
|
|
});
|
|
|
|
it("prefers the lodged EPC over the predicted EPC when both exist", () => {
|
|
expect(
|
|
resolvePropertyType({
|
|
override: null,
|
|
isNewApproach: true,
|
|
lodgedPropertyType: "0", // House
|
|
lodgedDwellingType: null,
|
|
predictedPropertyType: "2", // Flat
|
|
predictedDwellingType: null,
|
|
legacyPropertyType: null,
|
|
}),
|
|
).toBe("House");
|
|
});
|
|
|
|
it("falls back to dwelling_type when the lodged property_type is absent", () => {
|
|
expect(
|
|
resolvePropertyType({
|
|
override: null,
|
|
isNewApproach: true,
|
|
lodgedPropertyType: null,
|
|
lodgedDwellingType: "Flat",
|
|
predictedPropertyType: null,
|
|
predictedDwellingType: null,
|
|
legacyPropertyType: null,
|
|
}),
|
|
).toBe("Flat");
|
|
});
|
|
|
|
it("reads the legacy property-row value for a legacy property", () => {
|
|
expect(
|
|
resolvePropertyType({
|
|
override: null,
|
|
isNewApproach: false,
|
|
lodgedPropertyType: "0", // must be ignored for legacy
|
|
lodgedDwellingType: null,
|
|
predictedPropertyType: null,
|
|
predictedDwellingType: null,
|
|
legacyPropertyType: "Bungalow",
|
|
}),
|
|
).toBe("Bungalow");
|
|
});
|
|
|
|
it("never reads the EPC graph nor the legacy row across the cutoff (new-approach ignores the legacy row)", () => {
|
|
expect(
|
|
resolvePropertyType({
|
|
override: null,
|
|
isNewApproach: true,
|
|
lodgedPropertyType: null,
|
|
lodgedDwellingType: null,
|
|
predictedPropertyType: null,
|
|
predictedDwellingType: null,
|
|
legacyPropertyType: "Bungalow", // legacy row must NOT surface for a new-approach property
|
|
}),
|
|
).toBe("Unknown");
|
|
});
|
|
|
|
// Spec locks for decisions taken in ADR-0012 — an override always wins (even an
|
|
// explicit "Unknown"), and an unrecognised RdSAP code is passed through as-is.
|
|
it("lets an explicit 'Unknown' override win over a known EPC value", () => {
|
|
expect(
|
|
resolvePropertyType({
|
|
override: "Unknown",
|
|
isNewApproach: true,
|
|
lodgedPropertyType: "0", // EPC knows "House" — the override still wins
|
|
lodgedDwellingType: null,
|
|
predictedPropertyType: null,
|
|
predictedDwellingType: null,
|
|
legacyPropertyType: null,
|
|
}),
|
|
).toBe("Unknown");
|
|
});
|
|
|
|
it("passes an unrecognised RdSAP code through unchanged", () => {
|
|
expect(
|
|
resolvePropertyType({
|
|
override: null,
|
|
isNewApproach: true,
|
|
lodgedPropertyType: "9", // not in PROPERTY_TYPE_LABELS
|
|
lodgedDwellingType: null,
|
|
predictedPropertyType: null,
|
|
predictedDwellingType: null,
|
|
legacyPropertyType: null,
|
|
}),
|
|
).toBe("9");
|
|
});
|
|
});
|
|
|
|
describe("resolveBuiltForm", () => {
|
|
it("prefers a landlord override over the EPC-derived value", () => {
|
|
expect(
|
|
resolveBuiltForm({
|
|
override: "Detached",
|
|
isNewApproach: true,
|
|
lodgedBuiltForm: "4", // EPC code for Mid-Terrace
|
|
predictedBuiltForm: null,
|
|
legacyBuiltForm: null,
|
|
}),
|
|
).toBe("Detached");
|
|
});
|
|
|
|
it("maps an RdSAP built-form code to its label when there is no override", () => {
|
|
expect(
|
|
resolveBuiltForm({
|
|
override: null,
|
|
isNewApproach: true,
|
|
lodgedBuiltForm: "2", // RdSAP code for Semi-Detached
|
|
predictedBuiltForm: null,
|
|
legacyBuiltForm: null,
|
|
}),
|
|
).toBe("Semi-Detached");
|
|
});
|
|
|
|
it("falls back to the predicted EPC when there is no lodged value", () => {
|
|
expect(
|
|
resolveBuiltForm({
|
|
override: null,
|
|
isNewApproach: true,
|
|
lodgedBuiltForm: null,
|
|
predictedBuiltForm: "1", // Detached
|
|
legacyBuiltForm: null,
|
|
}),
|
|
).toBe("Detached");
|
|
});
|
|
|
|
it("reads the legacy property-row value for a legacy property", () => {
|
|
expect(
|
|
resolveBuiltForm({
|
|
override: null,
|
|
isNewApproach: false,
|
|
lodgedBuiltForm: "1", // must be ignored for legacy
|
|
predictedBuiltForm: null,
|
|
legacyBuiltForm: "End-Terrace",
|
|
}),
|
|
).toBe("End-Terrace");
|
|
});
|
|
|
|
it("resolves to 'Unknown' when nothing is available (never null)", () => {
|
|
expect(
|
|
resolveBuiltForm({
|
|
override: null,
|
|
isNewApproach: true,
|
|
lodgedBuiltForm: null,
|
|
predictedBuiltForm: null,
|
|
legacyBuiltForm: "Detached", // legacy row must NOT surface for new-approach
|
|
}),
|
|
).toBe("Unknown");
|
|
});
|
|
});
|