← back to Homesonspec

collectors/ashton-woods/src/index.test.ts

80 lines

import { readFileSync } from "node:fs";
import { join } from "node:path";
import { describe, expect, it } from "vitest";
import { ashtonWoodsAdapter, parseHome } from "./index";

const FIXTURE = readFileSync(
  join(import.meta.dirname, "..", "fixtures", "austin-321-possumhaw-lane.html"),
  "utf8",
);
const PAGE_URL =
  "https://www.ashtonwoods.com/austin/the-cottages-at-la-cima/the-cottages-at-la-cima-canyon/321-possumhaw-lane";

describe("ashton-woods adapter", () => {
  it("has the registry-matching key", () => {
    expect(ashtonWoodsAdapter.key).toBe("ashton-woods-site");
  });

  it("parses the QMI JSON-LD into a fully-populated home", () => {
    const h = parseHome(FIXTURE);
    expect(h).toBeTruthy();
    expect(h!.street).toBe("321 Possumhaw Lane");
    expect(h!.city).toBe("San Marcos");
    expect(h!.state).toBe("TX");
    expect(h!.zip).toBe("78666");
    expect(h!.community).toBe("The Cottages at La Cima");
    expect(h!.price).toBe(369636);
    expect(h!.sqft).toBe(2260);
    expect(h!.available).toBe(true);
  });

  it("derives beds/baths(full+half)/stories/garage from AmenityFeature", () => {
    const h = parseHome(FIXTURE)!;
    expect(h.beds).toBe(4);
    expect(h.bathsTotal).toBe(3.5); // "3 Baths | 1 Half Baths"
    expect(h.stories).toBe(2);
    expect(h.garages).toBe(2);
  });

  it("captures per-home geo + sales phone", () => {
    const h = parseHome(FIXTURE)!;
    expect(h.lat).toBeCloseTo(29.888184, 4);
    expect(h.lon).toBeCloseTo(-98.002232, 4);
    expect(h.phone).toBe("+1-512-648-5624");
  });

  it("extract() emits one community + one inventory_home with valid shape", () => {
    const out = ashtonWoodsAdapter.extract({
      url: PAGE_URL,
      retrievedAt: new Date().toISOString(),
      contentType: "text/html",
      body: Buffer.from(FIXTURE, "utf8"),
      contentHash: "test",
    });
    expect(out.errors).toHaveLength(0);
    const homes = out.records.filter((r) => r.entityType === "inventory_home");
    const comms = out.records.filter((r) => r.entityType === "community");
    expect(homes).toHaveLength(1);
    expect(comms).toHaveLength(1);
    const f = homes[0]!.fields;
    expect((f.price as { value: number }).value).toBe(369636);
    expect((f.sqft as { value: number }).value).toBe(2260);
    expect((f.lat as { value: number }).value).toBeCloseTo(29.888184, 4);
    expect((f.constructionStatus as { value: string }).value).toBe("MOVE_IN_READY");
    // facts-only: no images
    expect((f.images as { value: string[] }).value).toEqual([]);
  });

  it("returns no records for non-home HTML", () => {
    const out = ashtonWoodsAdapter.extract({
      url: "https://www.ashtonwoods.com/austin",
      retrievedAt: new Date().toISOString(),
      contentType: "text/html",
      body: Buffer.from("<html><body>no ld+json here</body></html>", "utf8"),
      contentHash: "test",
    });
    expect(out.errors).toHaveLength(0);
    expect(out.records).toHaveLength(0);
  });
});