evoq_test_assertions (evoq v1.14.1)

View Source

Test assertion helpers for evoq.

Provides macros and functions for testing CQRS/ES applications.

Usage

  -include_lib("evoq/include/evoq_test.hrl").
 
  my_test() ->
      Command = #evoq_command{...},
      ?assert_command_succeeds(Command),
      ?assert_events_produced([<<"OrderCreated">>]).

Summary

Functions

Assert aggregate state matches expected.

Assert that a command dispatch fails.

Assert that a command dispatch fails with options.

Assert that a command fails with a specific error.

Assert that a command dispatch succeeds.

Assert that a command dispatch succeeds with options.

Assert that commands were dispatched by a PM. Note: This requires capturing commands during test execution.

Assert that a specific event type was produced.

Assert that specific event types were produced.

Assert that no events were produced.

Assert read model contains expected value.

Assert read model is empty.

Assert that a telemetry event was emitted.

Collect telemetry events during a function execution.

Get aggregate state for testing.

Functions

assert_aggregate_state(AggregateType, AggregateId, Predicate)

-spec assert_aggregate_state(atom(), binary(), fun((term()) -> boolean())) -> ok.

Assert aggregate state matches expected.

assert_command_fails(Evoq_command)

-spec assert_command_fails(#evoq_command{command_id :: binary() | undefined,
                                         command_type :: atom() | undefined,
                                         aggregate_type :: atom() | undefined,
                                         aggregate_id :: binary() | undefined,
                                         payload :: map(),
                                         metadata :: map(),
                                         causation_id :: binary() | undefined,
                                         correlation_id :: binary() | undefined,
                                         idempotency_key :: binary() | undefined}) ->
                              {error, term()}.

Assert that a command dispatch fails.

assert_command_fails(Evoq_command, Opts)

-spec assert_command_fails(#evoq_command{command_id :: binary() | undefined,
                                         command_type :: atom() | undefined,
                                         aggregate_type :: atom() | undefined,
                                         aggregate_id :: binary() | undefined,
                                         payload :: map(),
                                         metadata :: map(),
                                         causation_id :: binary() | undefined,
                                         correlation_id :: binary() | undefined,
                                         idempotency_key :: binary() | undefined},
                           map()) ->
                              {error, term()}.

Assert that a command dispatch fails with options.

assert_command_fails_with(Evoq_command, ExpectedError)

-spec assert_command_fails_with(#evoq_command{command_id :: binary() | undefined,
                                              command_type :: atom() | undefined,
                                              aggregate_type :: atom() | undefined,
                                              aggregate_id :: binary() | undefined,
                                              payload :: map(),
                                              metadata :: map(),
                                              causation_id :: binary() | undefined,
                                              correlation_id :: binary() | undefined,
                                              idempotency_key :: binary() | undefined},
                                term()) ->
                                   ok.

Assert that a command fails with a specific error.

assert_command_succeeds(Evoq_command)

-spec assert_command_succeeds(#evoq_command{command_id :: binary() | undefined,
                                            command_type :: atom() | undefined,
                                            aggregate_type :: atom() | undefined,
                                            aggregate_id :: binary() | undefined,
                                            payload :: map(),
                                            metadata :: map(),
                                            causation_id :: binary() | undefined,
                                            correlation_id :: binary() | undefined,
                                            idempotency_key :: binary() | undefined}) ->
                                 {ok, non_neg_integer(), [map()]}.

Assert that a command dispatch succeeds.

assert_command_succeeds(Evoq_command, Opts)

-spec assert_command_succeeds(#evoq_command{command_id :: binary() | undefined,
                                            command_type :: atom() | undefined,
                                            aggregate_type :: atom() | undefined,
                                            aggregate_id :: binary() | undefined,
                                            payload :: map(),
                                            metadata :: map(),
                                            causation_id :: binary() | undefined,
                                            correlation_id :: binary() | undefined,
                                            idempotency_key :: binary() | undefined},
                              map()) ->
                                 {ok, non_neg_integer(), [map()]}.

Assert that a command dispatch succeeds with options.

assert_commands_dispatched(ExpectedTypes, DispatchedCommands)

-spec assert_commands_dispatched([atom()], [term()]) -> ok.

Assert that commands were dispatched by a PM. Note: This requires capturing commands during test execution.

assert_compensation_triggered(ExpectedType, CompensatingCommands)

-spec assert_compensation_triggered(atom(),
                                    [#evoq_command{command_id :: binary() | undefined,
                                                   command_type :: atom() | undefined,
                                                   aggregate_type :: atom() | undefined,
                                                   aggregate_id :: binary() | undefined,
                                                   payload :: map(),
                                                   metadata :: map(),
                                                   causation_id :: binary() | undefined,
                                                   correlation_id :: binary() | undefined,
                                                   idempotency_key :: binary() | undefined}]) ->
                                       ok.

Assert compensation was triggered.

assert_event_produced(EventType, Events)

-spec assert_event_produced(binary(), [map()]) -> map().

Assert that a specific event type was produced.

assert_events_produced(ExpectedTypes, Events)

-spec assert_events_produced([binary()], [map()]) -> ok.

Assert that specific event types were produced.

assert_no_events_produced(Events)

-spec assert_no_events_produced([map()]) -> ok.

Assert that no events were produced.

assert_read_model_contains(ReadModel, Key, ExpectedValue)

-spec assert_read_model_contains(evoq_read_model:read_model(), term(), term()) -> ok.

Assert read model contains expected value.

assert_read_model_empty(ReadModel)

-spec assert_read_model_empty(evoq_read_model:read_model()) -> ok.

Assert read model is empty.

assert_telemetry_emitted(EventName, CollectedEvents)

-spec assert_telemetry_emitted([atom()], [map()]) -> ok.

Assert that a telemetry event was emitted.

collect_telemetry(EventName, Fun)

-spec collect_telemetry([atom()], fun(() -> term())) -> {term(), [map()]}.

Collect telemetry events during a function execution.

get_aggregate_state(AggregateType, AggregateId)

-spec get_aggregate_state(atom(), binary()) -> {ok, term()} | {error, term()}.

Get aggregate state for testing.