View Source OnePiece.Commanded.TestSupport.CommandHandlerCase (OnePiece.Commanded v0.22.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 a handler option.
  • handler: The command handler module to use in the command handler case. If the aggregate option is not provided, then the Handler.Aggregate module will be used as the aggregate module. Read more about transaction script command handler at OnePiece.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

Summary

Functions

assert_error(initial_events, command, expected_error, aggregate_module, command_handler_module)

assert_events(initial_events, command, expected_events, aggregate_module, command_handler_module)

assert_state(initial_events, command, expected_state, aggregate_module, command_handler_module)