kaufmann_ex v0.3.2-beta KaufmannEx.TestSupport.MockBus

Helper module for testing event flows.

Cannot be run Async, relies on sending messages to self()

For every given_event/2 and then_event/2.

  • Validates events against schemas registered with Schema registry
  • Injects generic Meta payload into given_event

    then_event/2 asserts that the given event is emitted and verifies or returned the payload

    If you have a custom metadata schema or specific metadata handling, set a module exporting event_metadata/2 in app_env :kaufmann_ex, :metadata_mod

    ### Example Usage

  defmodule EvenHandlerTests
    use KaufmannEx.TestSupport.MockBus

    test "event emission" do
      given_event(:"TestCommand", %{new_key: "test"})

      then_event(:"Testevent", %{new_key: "test"})

      then_no_event
    end
  end

Link to this section Summary

Functions

Assert a named event is encodable by its specified schema

Dispatches event to the default subscriber

Asserts an event has been emitted, returns the payload

Asserts an event will be emitted to the bus

Asserts no more events will be emitted

Assert an event will not be emitted

Link to this section Functions

Link to this function assert_matches_schema(event_name, payload, meta)
assert_matches_schema(atom(), any(), map()) :: boolean()

Assert a named event is encodable by its specified schema

Link to this function encoded_event(event_name, payload, callback_id \\ nil)
Link to this function given_event(event_name, payload, callback_id \\ nil)
given_event(atom(), any(), binary() | nil) :: :ok

Dispatches event to the default subscriber.

Schema must be defined & payload must be valid/enocodable

Link to this function produce(topic, event_name, payload, context)
Link to this function then_event(event_name)
then_event(atom()) :: %{meta: map(), payload: any()}

Asserts an event has been emitted, returns the payload

Returned payload will include meta metadata

Link to this function then_event(event_name, expected_payload)
then_event(atom(), any()) :: boolean()

Asserts an event will be emitted to the bus

Will test emitted payload from event matches payload Asserts payload matches argument

Link to this function then_no_event()
then_no_event() :: boolean()

Asserts no more events will be emitted

Link to this function then_no_event(message_name)
then_no_event(atom()) :: boolean()

Assert an event will not be emitted