← back to Homesonspec
collectors/highland-homes-fl/src/selftest.test.ts
25 lines
import { readFileSync, readdirSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
import { describe, expect, it } from "vitest";
import { validatePayload } from "@homesonspec/schemas";
import { highlandHomesFlAdapter, parseHome, statusFromAvailability } from "./index";
const FX=join(dirname(fileURLToPath(import.meta.url)),"..","fixtures","homes");
const urls=Object.fromEntries(readFileSync(join(FX,"_urls.tsv"),"utf8").trim().split(/\r?\n/).map(x=>x.split("\t")));
const files=readdirSync(FX).filter(x=>x.endsWith(".html")).sort();
const page=(url:string,html:string)=>({url,retrievedAt:new Date().toISOString(),contentType:"text/html",body:Buffer.from(html),contentHash:"test"});
describe("highland-homes-fl collision-safe fixture E2E",()=>{
it("parses eight distinct authoritative Florida inventory homes",()=>{
const homes=files.map(f=>parseHome(readFileSync(join(FX,f),"utf8"),urls[f]!));
expect(homes).toHaveLength(8); expect(homes.every(Boolean)).toBe(true);
const h=homes.filter(Boolean) as NonNullable<(typeof homes)[number]>[];
expect(new Set(h.map(x=>x.street)).size).toBe(8); expect(new Set(h.map(x=>x.id)).size).toBe(8);
for(const x of h){ expect(x.state).toBe("FL"); expect(x.zip).toMatch(/^3\d{4}$/); expect(x.price).toBeGreaterThan(200000); expect(x.beds).toBeGreaterThan(0); expect(x.baths).toBeGreaterThan(0); expect(x.sqft).toBeGreaterThan(1000); expect(x.garages).toBeGreaterThan(0); expect(x.status).toBe("MOVE_IN_READY"); }
});
it("emits schema-valid community+home records with Florida slug",()=>{
for(const f of files){ const html=readFileSync(join(FX,f),"utf8"); const out=highlandHomesFlAdapter.extract(page(urls[f]!,html)); expect(out.errors).toEqual([]); expect(out.records.map(x=>x.entityType)).toEqual(["community","inventory_home"]); for(const r of out.records){ expect(r.canonicalHints.builderSlug).toBe("highland-homes-fl"); expect(validatePayload(r).ok).toBe(true); } }
});
it("rejects Texas collision and non-detail pages",()=>{ const html=readFileSync(join(FX,files[0]!),"utf8"); expect(parseHome(html.replace('"addressRegion":"FL"','"addressRegion":"TX"'),urls[files[0]!]!)).toBeNull(); expect(parseHome("<html></html>","fixture://none")).toBeNull(); });
it("maps only explicit availability and never guesses",()=>{ expect(statusFromAvailability("https://schema.org/InStock")).toBe("MOVE_IN_READY"); expect(statusFromAvailability("Under Construction")).toBe("UNDER_CONSTRUCTION"); expect(statusFromAvailability("Coming Soon")).toBe("PLANNED"); expect(statusFromAvailability("Pending sale")).toBeNull(); });
});