Cotton code
28 lines · 1.9 KB · TypeScriptRaw
/** * ROUTES-AUDIT 6, its definitions part (coordinator, 23 Nov 2026): GET /v1/definitions needs no credential, and its * `business` named a personal database's owner number. A database id appears in stream links, so it gave the number. * Now the number is said only to a caller the database knows: a device of its own, an owner token, the admin. */import { describe, expect, it } from "vitest";import { ADMIN, http, OWNER_PHONE, personalObject } from "./personal.ts";type Defs = { business: { owner_phone: string | null; database_id: string | null } };describe("a personal database's definitions", () => {  it("answer a caller it does not know as a database that does not exist, and name its owner's number to one it knows", async () => {    const slug = "audit-definitions";    const { credential } = await personalObject(slug);    // With no credential, or a made-up one, the answer is word for word a missing database's (slug aside): it never says the database is there.    const missing = await http<Record<string, unknown>>("audit-definitions-missing", "GET", "/v1/definitions");    const same = (r: { status: number; body: unknown }, as: string) => [r.status, JSON.stringify(r.body).replaceAll(as, "<slug>")];    for (const headers of [undefined, { authorization: "Bearer ctd_nobody_x" }]) {      const stranger = await http<Record<string, unknown>>(slug, "GET", "/v1/definitions", undefined, headers);      expect(same(stranger, slug)).toEqual(same(missing, "audit-definitions-missing"));      expect(JSON.stringify(stranger.body)).not.toContain(OWNER_PHONE);    }    // Its own phone and the admin are told, as before.    expect((await http<Defs>(slug, "GET", "/v1/definitions", undefined, { authorization: `Bearer ${credential}` })).body.business.owner_phone).toBe(OWNER_PHONE);    expect((await http<Defs>(slug, "GET", "/v1/definitions", undefined, ADMIN)).body.business.owner_phone).toBe(OWNER_PHONE);  });});