Chronicle.Testing.Assertions (cratis_chronicle v3.16.1)

Copy Markdown View Source

ExUnit assertions for events appended to a Chronicle.Testing.start_supervised_client/1 client, and for the structured rejections Chronicle.EventSequences.EventLog returns.

import Chronicle.Testing.Assertions

:ok = Chronicle.EventSequences.EventLog.append("account-1", %AccountOpened{}, client: client)
assert_appended(client, %AccountOpened{}, event_source_id: "account-1")

{:error, _} = Chronicle.EventSequences.EventLog.append("account-1", %AccountOpened{}, client: client)
assert_constraint_violation(result, "UniqueAccount")

Summary

Functions

Asserts that at least one appended event matches matcher.

Asserts that result is a concurrency-violation rejection.

Asserts that result (as returned by Chronicle.EventSequences.EventLog.append/3 and friends) is a constraint-violation rejection, optionally for the named constraint.

Asserts that no appended event matches matcher. See assert_appended/3 for the accepted matcher shapes and options.

Functions

assert_appended(client, matcher, opts \\ [])

@spec assert_appended(
  atom(),
  struct() | module() | (struct() -> boolean()),
  keyword()
) :: true

Asserts that at least one appended event matches matcher.

matcher is an exact event struct (compared with ==), an event type module (matches any event of that type), or a 1-arity function predicate.

Options

  • :event_source_id — only consider events appended for this event source
  • :count — assert exactly this many matches, instead of "at least one"

assert_concurrency_violation(result)

@spec assert_concurrency_violation(term()) :: true

Asserts that result is a concurrency-violation rejection.

assert_constraint_violation(result, constraint_name \\ nil)

@spec assert_constraint_violation(term(), String.t() | nil) :: true

Asserts that result (as returned by Chronicle.EventSequences.EventLog.append/3 and friends) is a constraint-violation rejection, optionally for the named constraint.

refute_appended(client, matcher, opts \\ [])

@spec refute_appended(
  atom(),
  struct() | module() | (struct() -> boolean()),
  keyword()
) :: false

Asserts that no appended event matches matcher. See assert_appended/3 for the accepted matcher shapes and options.