ash/test/reactor/action_test.exs
James Harton 86d74ed789
feat(Ash.Reactor): Add a Reactor extension that makes working with resources easy. (#683)
* feat: Add `Ash.Reactor` with create support.

* improvement: Add `Ash.Reactor` update support.

* improvement: Add `Ash.Reactor` destroy support.

* improvement(Ash.Reactor): Support for transactional handling of notifications.

* improvement(Ash.Reactor): Add `read` and `get` steps.

* docs: Add the beginnings of a Reactor topic.

* improvement(Ash.Reactor): add support for generic actions.

* improvement: Add `undo` capability to `create` step.

* improvement: transaction and undo working.

* docs: Start documenting undo behaviour.

* chore: Update to Reactor 0.6.

* improvement: Automatically thread Ash tracers through Reactor.

* improvement(Ash.Reactor): Add undo to generic actions.

* docs: Improve reactor documentation.

* fix: Mimic copying `Ash.Notifier` seems to break the compiler for some reason.
2024-03-02 10:26:25 +13:00

53 lines
1.2 KiB
Elixir

defmodule Ash.Test.ReactorActionTest do
@moduledoc false
use ExUnit.Case, async: true
defmodule Wooter do
@moduledoc false
use Ash.Resource, data_layer: Ash.DataLayer.Simple
attributes do
uuid_primary_key :id
end
actions do
action :celebrate, :string do
argument :excitement_level, :integer, default: 3, allow_nil?: false
run fn input, _context ->
level = Ash.ActionInput.get_argument(input, :excitement_level)
ooo = Enum.map(1..level, fn _ -> "o" end)
{:ok, Enum.join(["W"] ++ ooo ++ ["t"])}
end
end
end
end
defmodule Api do
@moduledoc false
use Ash.Api
resources do
resource Ash.Test.ReactorActionTest.Wooter
end
end
defmodule SimpleActionReactor do
@moduledoc false
use Reactor, extensions: [Ash.Reactor]
ash do
default_api Api
end
input :excitement_level
action :celebrate, Ash.Test.ReactorActionTest.Wooter, :celebrate do
inputs(%{excitement_level: input(:excitement_level)})
end
end
test "it runs the generic action" do
assert {:ok, "Wooooooot"} = Reactor.run(SimpleActionReactor, %{excitement_level: 7})
end
end