mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 13:33:20 +12:00
James Harton
86d74ed789
* 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.
79 lines
1.6 KiB
Elixir
79 lines
1.6 KiB
Elixir
defmodule Ash.Test.ReactorTest do
|
|
@moduledoc false
|
|
use ExUnit.Case, async: false
|
|
use Mimic
|
|
setup :set_mimic_global
|
|
|
|
test "it can be used directly" do
|
|
defmodule DirectReactor do
|
|
@moduledoc false
|
|
use Ash.Reactor
|
|
|
|
input :whom
|
|
|
|
step :greet do
|
|
argument :whom, input(:whom)
|
|
run fn %{whom: whom} -> {:ok, "Hello, #{whom}!"} end
|
|
end
|
|
end
|
|
|
|
assert {:ok, "Hello, Marty!"} = Reactor.run(DirectReactor, %{whom: "Marty"})
|
|
end
|
|
|
|
test "notifications are published when the reactor is successful" do
|
|
defmodule Post do
|
|
@moduledoc false
|
|
use Ash.Resource, data_layer: Ash.DataLayer.Ets
|
|
|
|
ets do
|
|
private? true
|
|
end
|
|
|
|
attributes do
|
|
uuid_primary_key :id
|
|
attribute :title, :string, allow_nil?: false
|
|
end
|
|
|
|
actions do
|
|
defaults [:create, :destroy]
|
|
end
|
|
end
|
|
|
|
defmodule Api do
|
|
@moduledoc false
|
|
use Ash.Api
|
|
|
|
resources do
|
|
resource Ash.Test.ReactorTest.Post
|
|
end
|
|
end
|
|
|
|
defmodule NotifyingReactor do
|
|
@moduledoc false
|
|
use Ash.Reactor
|
|
|
|
input :title
|
|
|
|
ash do
|
|
default_api Ash.Test.ReactorTest.Api
|
|
end
|
|
|
|
create :create_post, Ash.Test.ReactorTest.Post do
|
|
inputs(%{title: input(:title)})
|
|
end
|
|
end
|
|
|
|
expect(Ash.Reactor.Notifications, :publish, fn notifications ->
|
|
assert [
|
|
%Ash.Notifier.Notification{
|
|
resource: Ash.Test.ReactorTest.Post,
|
|
action: %{name: :create}
|
|
}
|
|
] = notifications
|
|
|
|
[]
|
|
end)
|
|
|
|
assert {:ok, _post} = Reactor.run(NotifyingReactor, %{title: "Title"})
|
|
end
|
|
end
|