/** The body contract: what it names, and what it refuses. */ import { expect, test } from "bun:test"; import { bodyProblems, meProblems } from "./body.ts"; const good = { id: "a", name: "A", x: 1, y: 2, angle: 0, alive: true, hp: 100, mate: false }; test("a well-formed body has no problems, and each missing or mistyped field is named", () => { expect(bodyProblems(good)).toEqual([]); const { alive: _, ...noAlive } = good; expect(bodyProblems({ ...noAlive, down: false })).toEqual(["body.alive should be a boolean, is undefined"]); expect(bodyProblems({ ...good, x: NaN })).toHaveLength(1); expect(bodyProblems(null)).toEqual(["body is not an object"]); expect(meProblems({ id: "a" })).toContain("me.ammo should be a number, is undefined"); }); test("`side` may be left out, but when it is sent it is a string", () => { expect(bodyProblems({ ...good, side: "north" })).toEqual([]); expect(bodyProblems({ ...good, side: 3 })).toEqual(["body.side should be a string, is 3"]); });