Test helpers for a Decree.Decision, for an application to import.
use ExUnit.Case
import Decree.Decision.Assertions
test "a claimed email refuses a second claim" do
assert_refuses(ClaimEmail, [%EmailClaimed{digest: "d"}], %ClaimEmailCommand{digest: "d"},
:email_taken
)
end
test "a free email is claimed" do
assert_decides(ClaimEmail, [], command, %EmailClaimed{digest: "d"})
endThey run Decree.Decision.evolve/2, Decree.Decision.admit/2 and
Decree.Decision.decide/2 with no store: the given events stand for what the reads
would answer, decrypted where the decision lists them, so they never read time or a
database. What only a store can answer, such
as a retry or a command match, needs a dispatch. So do a batch's scope and fact checks, which
run on prepared tags, and what a dispatch reduces: on a decision that lists its fold, a reason
here is the callback's whole. They check no tag index and no activation.
A failure is an ExUnit.AssertionError, which is why ExUnit has to be running, as it is
under mix test.
Summary
Functions
Asserts that the decision decides expected: an event, a list of events, or
{:streams, members}, as Decree.Decision.decide/2 would answer it. Answers the state
the fold reached with the new events applied.
Asserts that Decree.Decision.query/2 answers expected for the command.
Asserts that the decision refuses with reason.
Folds given_events, then admits and decides command, answering as a dispatch would.
Functions
Asserts that the decision decides expected: an event, a list of events, or
{:streams, members}, as Decree.Decision.decide/2 would answer it. Answers the state
the fold reached with the new events applied.
Takes the options of decision_result/4.
Asserts that Decree.Decision.query/2 answers expected for the command.
Options
:metadata- the dispatch metadata the tag context holds. Defaults to%{}.:business_events- checkDecree.Decision.followup_query/3instead, given these events.
Asserts that the decision refuses with reason.
Takes the options of decision_result/4.
@spec decision_result(module(), [struct()], struct(), keyword()) :: {:ok, [struct()]} | {:ok, term()} | {:error, term()}
Folds given_events, then admits and decides command, answering as a dispatch would.
{:ok, events}, every new event in append order, as a dispatch withreturning: :eventsanswers, or{:ok, state}, the fold with the new events applied, withreturning: :aggregate_state.{:error, reason}, the refusal a dispatch answers.:duplicatefromDecree.Decision.decide/2is{:error, :duplicate_command}.
Options
:returning-:events, the default, or:aggregate_state.:state- the state to start from, instead ofDecree.Decision.initial_state/0.