refactoring of cmaps, widgets, etc.

This commit is contained in:
2026-09-02 16:06:26 +02:00
parent 38f255c1a4
commit f0562a06cc
52 changed files with 3626 additions and 2642 deletions
+32
View File
@@ -0,0 +1,32 @@
import test from "node:test";
import assert from "node:assert/strict";
import { PeopleRepository } from "../static/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(), []);
});