# `Chronicle.Testing.Assertions`
[🔗](https://github.com/Cratis/Chronicle.Elixir/blob/main/lib/chronicle/testing/assertions.ex#L4)

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")

# `assert_appended`

```elixir
@spec assert_appended(
  atom(),
  struct() | module() | (struct() -&gt; 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`

```elixir
@spec assert_concurrency_violation(term()) :: true
```

Asserts that `result` is a concurrency-violation rejection.

# `assert_constraint_violation`

```elixir
@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`

```elixir
@spec refute_appended(
  atom(),
  struct() | module() | (struct() -&gt; boolean()),
  keyword()
) :: false
```

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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
