| 1 | import { describe, expect, it } from "@effect/vitest"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as Schema from "effect/Schema"; |
| 4 | |
| 5 | import { ApplicationProjectEvent } from "./applicationEvent.ts"; |
| 6 | |
| 7 | const decodeApplicationProjectEvent = Schema.decodeUnknownEffect(ApplicationProjectEvent); |
| 8 | |
| 9 | describe("application project events", () => { |
| 10 | it.effect("decodes project events without the legacy thread event contract", () => |
| 11 | Effect.gen(function* () { |
| 12 | const event = yield* decodeApplicationProjectEvent({ |
| 13 | sequence: 12, |
| 14 | eventId: "event-project-12", |
| 15 | aggregateKind: "project", |
| 16 | aggregateId: "project-1", |
| 17 | occurredAt: "2026-06-24T12:00:00.000Z", |
| 18 | commandId: "command-project-12", |
| 19 | causationEventId: null, |
| 20 | correlationId: "command-project-12", |
| 21 | metadata: {}, |
| 22 | type: "project.created", |
| 23 | payload: { |
| 24 | projectId: "project-1", |
| 25 | title: "Project", |
| 26 | workspaceRoot: "/tmp/project", |
| 27 | defaultModelSelection: null, |
| 28 | scripts: [], |
| 29 | createdAt: "2026-06-24T12:00:00.000Z", |
| 30 | updatedAt: "2026-06-24T12:00:00.000Z", |
| 31 | }, |
| 32 | }); |
| 33 | |
| 34 | expect(event.type).toBe("project.created"); |
| 35 | expect(event.payload.projectId).toBe("project-1"); |
| 36 | }), |
| 37 | ); |
| 38 | |
| 39 | it.effect("rejects a project event carrying a thread aggregate", () => |
| 40 | Effect.gen(function* () { |
| 41 | const result = yield* Effect.result( |
| 42 | decodeApplicationProjectEvent({ |
| 43 | sequence: 12, |
| 44 | eventId: "event-project-12", |
| 45 | aggregateKind: "thread", |
| 46 | aggregateId: "project-1", |
| 47 | occurredAt: "2026-06-24T12:00:00.000Z", |
| 48 | commandId: null, |
| 49 | causationEventId: null, |
| 50 | correlationId: null, |
| 51 | metadata: {}, |
| 52 | type: "project.deleted", |
| 53 | payload: { |
| 54 | projectId: "project-1", |
| 55 | deletedAt: "2026-06-24T12:00:00.000Z", |
| 56 | }, |
| 57 | }), |
| 58 | ); |
| 59 | |
| 60 | expect(result._tag).toBe("Failure"); |
| 61 | }), |
| 62 | ); |
| 63 | }); |