The board's scenarios as tests: given, then decide or read, then
expect.
import Datumo.Scenario
# a write slice
given([%LotOpened{lot_id: "L-1"}])
|> decide(Decider, %CloseLot{lot_id: "L-1"})
|> expect({:ok, [%LotClosed{lot_id: "L-1"}]})
# a read slice
given([%PlotRegistered{plot_id: "P-1", name: "La Vega"}])
|> read(ReadModel, "P-1")
|> expect(%{name: "La Vega"})Why not fold the given by hand
In production a decision only sees what its query/1 reads. Folding the
given straight into apply_event/2 skips that read, so a query that forgets
a type, asks for the wrong tag or misses a follow-up passes every test and
silently never fires. Here the given is the store:
given/1stores each event the wayDatumo.Decideappends it: throughDatumo.Event.to_event/1, so its tags are the production ones, and through JSON, soapply_event/2gets the same string-keyed data it gets from FACT.decide/3andread/3run the production loop (Datumo.Decide.fold/3,Datumo.StateView.view/3) reading that store withDatumo.Reader.selects?/2, the same matchDatumo.Readerapplies.expect/2matches the result against a pattern. When it fails and somegivenevents were never read, it says which: a scenario may include an event on purpose to show it's ignored, so being unread is a hint, not a failure by itself.
The given
An event struct — the normal case. An event no code writes any more (it's
still in the store) or that comes from outside has no struct: give it as the
shape FACT appends, %{type: "…", data: %{…}, tags: ["…"]}, plus id: "…"
when the fold keys on the event id.
Summary
Functions
Runs a write slice's decision against the given.
Asserts the result matches pattern (a struct or map pattern matches the keys
it names). Returns the result.
Stores the scenario's given events, in order.
Computes a read slice's view from the given.
Functions
Runs a write slice's decision against the given.
Asserts the result matches pattern (a struct or map pattern matches the keys
it names). Returns the result.
Stores the scenario's given events, in order.
Computes a read slice's view from the given.