-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
How to test a process manager produces the correct commands and state?
Use the process manager's handle/2 and apply/2 functions directly by reducing a list of one or more domain events. The resultant list of commands and process manager state can then be asserted on.
events = [%Event1{}, %Event2{}]
initial_state = %MyProcessManager{}
{commands, state} =
Enum.reduce(events, {[], initial_state}, fn event, {commands, state} ->
new_commands = MyProcessManager.handle(state, event)
new_state = MyProcessManager.apply(state, event)
{commands ++ new_commands, new_state}
end)
assert match?([%Command1{}, %Command2{}], commands)
assert match?(%MyProcessManager{key: value}, state)This type of test can be run using async: true and will be very quick to execute as it does no IO.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels