Accrue.Test.EventAssertions (accrue v0.3.1)

Copy Markdown View Source

ExUnit-style assertions for Accrue's append-only event ledger.

Usage

use Accrue.Test.EventAssertions
# or
import Accrue.Test.EventAssertions

assert_event_recorded(
  type: "subscription.created",
  subject: subscription,
  subject_type: "Subscription",
  subject_id: subscription.id,
  actor_type: "system",
  data: %{"status" => "active"},
  matches: fn event -> event.schema_version == 1 end
)

Matching

  • :type matches event.type
  • :subject derives subject_type and subject_id from a struct or map with :id
  • :subject_type, :subject_id, and :actor_type match the event fields directly
  • :data subset-matches only the provided keys
  • :matches runs a 1-arity predicate against %Accrue.Events.Event{}

Assertions query the test process' database sandbox state. Failure messages include the matcher and observed event type/subject summaries, but avoid dumping raw event payload data.

Summary

Functions

Asserts that an event matching matcher was recorded.

Asserts that an event matching subject and matchers was recorded.

Asserts that no event matching matcher was recorded.

Refutes that an event matching matcher was recorded.

Refutes that an event matching subject and matchers was recorded.

Functions

assert_event_recorded(matcher)

(macro)

Asserts that an event matching matcher was recorded.

assert_event_recorded(subject, matchers)

(macro)

Asserts that an event matching subject and matchers was recorded.

assert_no_events_recorded(matcher \\ [])

(macro)

Asserts that no event matching matcher was recorded.

refute_event_recorded(matcher)

(macro)

Refutes that an event matching matcher was recorded.

refute_event_recorded(subject, matchers)

(macro)

Refutes that an event matching subject and matchers was recorded.