View Source OnePiece.Commanded.TestSupport.CommandHandlerCase (OnePiece.Commanded v0.24.0)
This module helps with test cases for testing aggregate states, and command handlers.
Options
aggregate: The aggregate module to use in the command handler case. If not provided, then you must provide ahandleroption.handler: The command handler module to use in the command handler case. If theaggregateoption is not provided, then theHandler.Aggregatemodule will be used as the aggregate module. Read more about transaction script command handler atOnePiece.Commanded.CommandRouter.register_transaction_script/2.
Usage
After import the test support file, you should be able to have the module in your test files.
defmodule MyAggregateTest do
use OnePiece.Commanded.TestSupport.CommandHandlerCase,
handler: MyCommandHandler,
async: true
describe "my aggregate" do
test "should do something" do
assert_events(
[%InitialEvent{}],
%DoSomething{},
[%SomethingHappened{}]
)
end
test "the state" do
assert_state(
[%InitialEvent{}],
%DoSomething{},
%MyAggregate{}
)
end
test "the error" do
assert_error(
[%InitialEvent{}],
%DoSomething{},
:already_exists
)
end
end
end