35 lines
1.5 KiB
TypeScript
35 lines
1.5 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
|
|
import { generatedStreetNames, validateGeneratedStreets } from "./geodata";
|
|
|
|
describe("demo-pro geodata validation", () => {
|
|
it("builds the exact deterministic street catalog used by the generator", () => {
|
|
const names = generatedStreetNames();
|
|
expect(names).toHaveLength(60);
|
|
expect(new Set(names).size).toBe(names.length);
|
|
});
|
|
|
|
it("detects collisions against paginated official street responses", async () => {
|
|
const collision = generatedStreetNames()[3]!;
|
|
const fetchMock = vi.fn(async (url: string | URL | Request) => {
|
|
const offset = Number(new URL(String(url)).searchParams.get("offset"));
|
|
const features =
|
|
offset === 0
|
|
? Array.from({ length: 500 }, (_, index) => ({ properties: { text: `Unrelated Street ${index}` } }))
|
|
: [{ properties: { text: collision } }];
|
|
return new Response(JSON.stringify({ numberMatched: 501, features }), { status: 200 });
|
|
});
|
|
const report = await validateGeneratedStreets(fetchMock as typeof fetch);
|
|
expect(report.collisions).toEqual([collision]);
|
|
expect(fetchMock).toHaveBeenCalledTimes(2);
|
|
});
|
|
|
|
it("fails closed on an incomplete successful pagination response", async () => {
|
|
const fetchMock = vi.fn(
|
|
async () => new Response(JSON.stringify({ numberMatched: 501, features: [{ properties: { text: "Only one" } }] }), { status: 200 })
|
|
);
|
|
|
|
await expect(validateGeneratedStreets(fetchMock as typeof fetch)).rejects.toThrow("incomplete");
|
|
});
|
|
});
|