feat: update aggregate implementation

This commit is contained in:
2025-08-11 13:34:28 +02:00
parent 9dddc4e79f
commit cc8c558db6
37 changed files with 361 additions and 511 deletions

View File

@@ -1,24 +1,26 @@
import { assertEquals } from "@std/assert";
import { it } from "@std/testing/bdd";
import type { EventStoreFactory } from "../mocks/events.ts";
import { User } from "../mocks/aggregates.ts";
import type { Events } from "../mocks/events.ts";
import { describe } from "../utilities/describe.ts";
export default describe<EventStoreFactory>(".makeAggregateReducer", (getEventStore) => {
export default describe<Events>(".makeAggregateReducer", (getEventStore) => {
it("should reduce a user", async () => {
const { store } = await getEventStore();
const userA = await store
.aggregate("user")
.create({ given: "John", family: "Doe" }, "john.doe@fixture.none")
const userA = await store.aggregate
.from(User)
.setGivenName("Jane")
.setFamilyName("Doe")
.setEmail("john.doe@fixture.none", "auditor")
.save();
await userA.snapshot();
await userA.setFamilyName("Smith").setEmail("jane.smith@fixture.none", "system").save();
const userB = await store.aggregate("user").getById(userA.id);
const userB = await store.aggregate.getByStream(User, userA.id);
if (userB === undefined) {
throw new Error("Expected user to exist");
}