import test from "node:test"; import assert from "node:assert/strict"; import { PeopleRepository } from "../static/js/cmap/model/people-repository.js"; test("PeopleRepository keeps people API routes behind its public methods", async () => { const calls = []; const api = async (path, options = {}) => { calls.push({ path, options }); if (!options.method) return { people: [{ id: 1, name: "Ada", active: true }] }; return { id: 1, name: "Ada", active: true }; }; const repository = new PeopleRepository(api); const people = await repository.all(); const created = await repository.create("Ada"); await repository.update(created, false); assert.equal(people[0].name, "Ada"); assert.deepEqual(calls.map((call) => call.path), [ "/api/people", "/api/people", "/api/people/1" ]); assert.deepEqual(JSON.parse(calls[1].options.body), { name: "Ada" }); assert.deepEqual(JSON.parse(calls[2].options.body), { name: "Ada", active: false }); }); test("PeopleRepository normalizes a missing people collection to an empty list", async () => { const repository = new PeopleRepository(async () => ({})); assert.deepEqual(await repository.all(), []); });