ExUnit support that runs the real Arc pipelines against Chronicle's in-memory kernel.
defmodule MyApp.RegisterAuthorTest do
use Arc.Test.Case,
application: MyApp.Arc,
event_types: [MyApp.Authors.AuthorRegistered]
test "registers an author", %{arc: arc} do
result = Arc.Test.execute(arc, %MyApp.Authors.RegisterAuthor{id: "...", name: "Ada"})
Arc.Test.assert_success(result)
Arc.Test.assert_appended(arc, MyApp.Authors.AuthorRegistered, event_source_id: "...")
end
endValidation, authorization, binding and the Chronicle append all run for real; nothing is
mocked. Reactors and reducers run synchronously after each append, as in Chronicle.Testing.
Each test gets its own kernel, so async: true is safe.
Summary
Functions
Asserts an event was appended. See Chronicle.Testing.Assertions.assert_appended/3.
Asserts the caller was not authorized.
Asserts the result was rejected by validation, optionally for a member.
Asserts the command succeeded: authorized, valid and without exceptions.
Points application at a Chronicle test client for the duration of the test, so code that reaches
the application's own configuration (the HTTP host, LiveView) uses it. Restores the previous
configuration when the test exits. Not safe with async: true: configuration is global.
Executes a command. Accepts the options of Arc.execute/3.
An authenticated principal.
Executes a query. Accepts the options of Arc.query/5.
Asserts no matching event was appended.
Builds a scenario for application using a Chronicle test client.
Waits until Chronicle's in-memory observers have processed every appended event.
Functions
@spec assert_appended( Arc.Test.Scenario.t(), struct() | module() | (struct() -> boolean()), keyword() ) :: true
Asserts an event was appended. See Chronicle.Testing.Assertions.assert_appended/3.
@spec assert_forbidden(Arc.CommandResult.t() | Arc.QueryResult.t()) :: true
Asserts the caller was not authorized.
@spec assert_invalid(Arc.CommandResult.t() | Arc.QueryResult.t(), atom() | nil) :: true
Asserts the result was rejected by validation, optionally for a member.
@spec assert_success(Arc.CommandResult.t() | Arc.QueryResult.t()) :: true
Asserts the command succeeded: authorized, valid and without exceptions.
Points application at a Chronicle test client for the duration of the test, so code that reaches
the application's own configuration (the HTTP host, LiveView) uses it. Restores the previous
configuration when the test exits. Not safe with async: true: configuration is global.
@spec execute(Arc.Test.Scenario.t(), struct() | {module(), map()}, keyword()) :: Arc.CommandResult.t()
Executes a command. Accepts the options of Arc.execute/3.
@spec principal(String.t(), [String.t()]) :: Arc.Principal.t()
An authenticated principal.
@spec query(Arc.Test.Scenario.t(), module(), atom(), map(), keyword()) :: Arc.QueryResult.t()
Executes a query. Accepts the options of Arc.query/5.
@spec refute_appended( Arc.Test.Scenario.t(), struct() | module() | (struct() -> boolean()), keyword() ) :: false
Asserts no matching event was appended.
Builds a scenario for application using a Chronicle test client.
@spec wait_for_observers(Arc.Test.Scenario.t()) :: :ok
Waits until Chronicle's in-memory observers have processed every appended event.