Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

projector.pinned.test.ts

77 lines2.1 KB

1import {
2 CommandId,
3 EventId,
4 ProjectId,
5 ThreadId,
6 type OrchestrationEvent,
7} from "@t3tools/contracts";
8import { expect, it } from "@effect/vitest";
9import * as Effect from "effect/Effect";
10​
11import { createEmptyReadModel, projectEvent } from "./projector.ts";
12​
13function makeEvent(input: {
14 readonly sequence: number;
15 readonly type: OrchestrationEvent["type"];
16 readonly payload: unknown;
17}): OrchestrationEvent {
18 return {
19 sequence: input.sequence,
20 eventId: EventId.make(`event-${input.sequence}`),
21 type: input.type,
22 aggregateKind: "thread",
23 aggregateId: ThreadId.make("thread-1"),
24 occurredAt: "2026-01-01T00:00:00.000Z",
25 commandId: CommandId.make(`command-${input.sequence}`),
26 causationEventId: null,
27 correlationId: null,
28 metadata: {},
29 payload: input.payload as never,
30 } as OrchestrationEvent;
32​
33it.effect("projects pin lifecycle events", () =>
34 Effect.gen(function* () {
35 const now = "2026-01-01T00:00:00.000Z";
36 const created = yield* projectEvent(
37 createEmptyReadModel(now),
38 makeEvent({
39 sequence: 1,
40 type: "thread.created",
41 payload: {
42 threadId: ThreadId.make("thread-1"),
43 projectId: ProjectId.make("project-1"),
44 title: "Thread",
45 modelSelection: { provider: "codex", model: "gpt-5.4" },
46 runtimeMode: "full-access",
47 interactionMode: "default",
48 branch: null,
49 worktreePath: null,
50 createdAt: now,
51 updatedAt: now,
52 },
53 }),
54 );
55 expect(created.threads[0]?.pinnedAt ?? null).toBeNull();
56​
57 const pinned = yield* projectEvent(
58 created,
59 makeEvent({
60 sequence: 2,
61 type: "thread.pinned",
62 payload: { threadId: ThreadId.make("thread-1"), pinnedAt: now, updatedAt: now },
63 }),
64 );
65 expect(pinned.threads[0]?.pinnedAt).toBe(now);
66​
67 const unpinned = yield* projectEvent(
68 pinned,
69 makeEvent({
70 sequence: 3,
71 type: "thread.unpinned",
72 payload: { threadId: ThreadId.make("thread-1"), updatedAt: now },
73 }),
74 );
75 expect(unpinned.threads[0]?.pinnedAt).toBeNull();
76 }),
77);