/** * Starting a chat is the person's reviewed act: a start that creates a room * commits only from a `ChatStart` on `ChatStartSurface`, since the room's * `about` record names that action as its writer's. A start sent without it, * or from another surface, creates no room, and its run commits nothing, so no * outcome is recorded either. A refused run logs its refusal, which is why * console warnings are allowed. */ import { type AddIntegrity, assert, type Cell, pattern, TESTS, Writable, } from "commonfabric"; import type { SharedSpaceCatalogStorage } from "../system/shared-space-catalog.ts"; import { FabriChatManagerCore } from "./manager.tsx"; import { CHAT_SEND_ACTION, CHAT_SEND_SURFACE, CHAT_START_ACTION, CHAT_START_SURFACE, type ChatIndexEntry, type ChatManagerNotice, type ChatProfile, type ChatRequestOutcome, } from "./schemas.tsx"; type ManagerArg = Parameters[0]; /** An empty shared-space catalog, as a manager lists its rooms from. */ const emptyCatalog = () => Writable.of({ entries: {}, offers: {} }); // A stand-in for this user's `#profile`, labeled, as a Fabric profile is, // because a room's participants link only a document that carries a label. type TestProfile = AddIntegrity< ChatProfile, readonly ["fabrichat-test-profile"] >; // A stand-in for a principal, a base58btc key as a principal's is. const BOB = "did:key:z6MkBob"; const startGesture = { surface: CHAT_START_SURFACE, action: CHAT_START_ACTION }; const sendGesture = { surface: CHAT_SEND_SURFACE, action: CHAT_SEND_ACTION }; const statusOf = ( requests: Cell>, id: string, ): string => requests.get()?.[id]?.status ?? "none"; export default pattern(() => { const requests = Writable.of>({}); const notices = Writable.of([]); const manager = FabriChatManagerCore({ myProfile: Writable.of({ name: "Tester" }), sharedSpaceCatalog: emptyCatalog(), direct: Writable.of>({}), requests, outgoingNotices: notices, } as ManagerArg); return { [TESTS]: [ // Without a gesture. { action: manager.openDirect, event: { requestId: "d-1", counterpart: BOB }, }, { action: manager.createGroup, event: { requestId: "g-1", title: "Team", members: [BOB] }, }, // From another reviewed surface. { action: manager.createGroup, event: { requestId: "g-2", title: "Team", members: [BOB] }, trustedUi: sendGesture, }, { assertion: assert(() => manager.rooms.length === 0 && notices.get().length === 0 && statusOf(requests, "d-1") === "none" && statusOf(requests, "g-1") === "none" && statusOf(requests, "g-2") === "none" ), }, // From its own. { action: manager.openDirect, event: { requestId: "d-2", counterpart: BOB }, trustedUi: startGesture, }, { action: manager.createGroup, event: { requestId: "g-3", title: "Team", members: [BOB] }, trustedUi: startGesture, }, { assertion: assert(() => manager.rooms.length === 2 && notices.get().length === 2 && statusOf(requests, "d-2") === "done" && statusOf(requests, "g-3") === "done" ), }, ], allowConsoleWarnings: true, }; });