I’m vibing/steering a rather large test file.
open Vitest
open TodoEvent
module Fixtures = {
let mockUser: User.t = {
id: UserId.fromString("user-test-1"),
first_name: "Test",
last_name: "User",
token: "test-token-123",
email: "test@example.com",
has_valid_password: true,
}
}
describe("TodoAPI.EventExchangeEndpoint.read", () => {
testAsync("parses TodoListCreated", async _t => {
let listId = TodoList.Identifier.fromString("list-a")
let lastKnownEvents: EventSourcing.API.lastKnownEvents<TodoEventLog.EventIdentifier.t> = dict{}
let payload: TodoAPI.EventExchangeEndpoint.EventlessPayload.t = {
lastKnownEvents: lastKnownEvents,
}
let payloadMap = TodoList.Identifier.Map.fromArray([(listId, payload)])
let eventJson = JSON.Object(
dict{
"TAG": JSON.String("TodoListCreated"),
"list_id": JSON.String("list-a"),
"owner_id": JSON.String("owner-1"),
"name": JSON.String("Test List"),
"description": JSON.String("Test description"),
},
)
let recordJson = JSON.Object(
dict{
"id": JSON.String("event-1"),
"created_by": JSON.String(Fixtures.mockUser.id->UserId.toString),
"created_by_profile": JSON.Null,
"aggregate_id": JSON.String("list-a"),
"event": eventJson,
"vector_clock": JSON.Object(dict{"node-1": JSON.Number(1.0)}),
"node_id": JSON.String("node-1"),
"vessel_id": JSON.Null,
},
)
let responseJson = JSON.Object(
dict{
"request": JSON.String("READ"),
"payload": JSON.Object(
dict{
"list-a": JSON.Object(
dict{
"events": JSON.Array([recordJson]),
"last_known_events": JSON.Object(dict{}),
},
),
},
),
},
)
let mock: ApiRequest.t => _ = async request =>
switch request {
| {
method: Post,
url,
headers: dict{"Authorization": "Token test-token-123"},
body: Json(JSON.Object(dict{
"request": JSON.String("READ"),
"payload": JSON.Object(dict{
"list-a": JSON.Object(dict{"last_known_events": JSON.Object(dict{})}),
}),
})),
} if url->String.includes("/todo/events") =>
Some(Ok(responseJson))
| _ => None
}
await ApiRequest.withRequestMocker(
mock,
async () => {
let result = await TodoAPI.EventExchangeEndpoint.read(
~user=Fixtures.mockUser,
~payload=payloadMap,
)
switch result {
| Ok(map) =>
switch map->TodoList.Identifier.Map.get(listId) {
| Some({events: [{event: TodoListCreated(_)}]}) => ()
| Some(_) | None => Assert.unreachable(~message="Expected TodoListCreated", ())
}
| Error(e) =>
Assert.unreachable(
~message=`Expected Ok, got Error: ${e
->Exn.asJsExn
->Option.flatMap(Exn.message)
->Option.getOr("?")}`,
(),
)
}
},
)
})
})
The compiler crashes with:
>> Fatal error: Parmatch.all_record_args
Fatal error: exception Misc.Fatal_error
❌ Failed to Compile. See Errors Above
I’m trying to find a shorter, self-contained reproduction…