ash/test/flow_test/halting_test.exs
Zach Daniel b20c4afd9b improvement: haltable flows, branch step type
fix: fix chart links rendering
2022-10-06 17:04:44 -04:00

44 lines
1.5 KiB
Elixir

defmodule Ash.FlowTest.HaltingTest do
@moduledoc false
use ExUnit.Case, async: false
alias Ash.Flow.Result
alias Ash.Test.Flow.{Api, Org, User}
setup do
ExUnit.CaptureLog.capture_log(fn ->
Ash.DataLayer.Mnesia.start(Api)
end)
on_exit(fn ->
ExUnit.CaptureLog.capture_log(fn ->
:mnesia.stop()
:mnesia.delete_schema([node()])
end)
end)
end
test "A step can halt" do
assert %Ash.Flow.Result{errors: [%Ash.Error.Flow.Halted{reason: :not_on_step_a}]} =
Ash.Test.Flow.Flows.Halting.run()
end
test "A step that halts will continue if its `halt_if` clause is no longer true" do
assert %Ash.Flow.Result{errors: [%Ash.Error.Flow.Halted{reason: :not_on_step_a}]} =
result = Ash.Test.Flow.Flows.Halting.run()
assert %Ash.Flow.Result{errors: [%Ash.Error.Flow.Halted{reason: :not_on_step_b}]} =
Ash.Test.Flow.Flows.Halting.run(%{on_step: :a}, resume: result)
end
test "A step that halts will continue if its `halt_if` clause is no longer true, and the result of steps is properly resumed" do
assert %Ash.Flow.Result{errors: [%Ash.Error.Flow.Halted{reason: :not_on_step_b}]} =
result = Ash.Test.Flow.Flows.Halting.run(%{on_step: :a})
assert %Ash.Flow.Result{errors: [%Ash.Error.Flow.Halted{reason: :not_on_step_c}]} =
result = Ash.Test.Flow.Flows.Halting.run(%{on_step: :b}, resume: result)
assert %Ash.Flow.Result{errors: [], result: "c"} =
Ash.Test.Flow.Flows.Halting.run(%{on_step: :c}, resume: result)
end
end