event.test.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { describe, expect, test } from "bun:test"
  2. import { Schema } from "effect"
  3. import { Event } from "../src/event"
  4. describe("public event schemas", () => {
  5. test("definition is pure", () => {
  6. const definitions = Event.inventory()
  7. Event.define({ type: "test.pure", schema: { value: Schema.String } })
  8. expect(definitions).toEqual([])
  9. })
  10. test("latest selection is independent of declaration order", () => {
  11. const historical = Event.define({
  12. type: "test.versioned",
  13. durable: { aggregate: "id", version: 1 },
  14. schema: { id: Schema.String },
  15. })
  16. const current = Event.define({
  17. type: "test.versioned",
  18. durable: { aggregate: "id", version: 2 },
  19. schema: { id: Schema.String, value: Schema.String },
  20. })
  21. expect(Event.latest([historical, current]).get(current.type)).toBe(current)
  22. expect(Event.latest([current, historical]).get(current.type)).toBe(current)
  23. })
  24. test("durable definitions are indexed by type and version", () => {
  25. const definition = Event.define({
  26. type: "test.durable",
  27. durable: { aggregate: "id", version: 1 },
  28. schema: { id: Schema.String },
  29. })
  30. expect(Event.durable([definition]).get("test.durable.1")).toBe(definition)
  31. })
  32. })