mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 05:23:03 +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.
62 lines
1.3 KiB
Elixir
62 lines
1.3 KiB
Elixir
defmodule Ash.Test.ReactorReadTest do
|
|
@moduledoc false
|
|
use ExUnit.Case, async: true
|
|
|
|
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, :read]
|
|
end
|
|
|
|
code_interface do
|
|
define_for Ash.Test.ReactorReadTest.Api
|
|
define :create
|
|
end
|
|
end
|
|
|
|
defmodule Api do
|
|
@moduledoc false
|
|
use Ash.Api
|
|
|
|
resources do
|
|
resource Ash.Test.ReactorReadTest.Post
|
|
end
|
|
end
|
|
|
|
defmodule SimpleReadReactor do
|
|
@moduledoc false
|
|
use Reactor, extensions: [Ash.Reactor]
|
|
|
|
ash do
|
|
default_api Api
|
|
end
|
|
|
|
read :read_posts, Ash.Test.ReactorReadTest.Post
|
|
end
|
|
|
|
test "when a posts exist it returns them" do
|
|
expected =
|
|
~w[Marty Doc Einstein]
|
|
|> Enum.map(&Post.create!(%{title: &1}))
|
|
|
|
{:ok, actual} = Reactor.run(SimpleReadReactor, %{}, %{}, async?: false)
|
|
|
|
assert actual |> Enum.map(& &1.id) |> Enum.sort() ==
|
|
expected |> Enum.map(& &1.id) |> Enum.sort()
|
|
end
|
|
|
|
test "when posts don't exist it returns an empty list" do
|
|
assert {:ok, []} = Reactor.run(SimpleReadReactor, %{}, %{}, async?: false)
|
|
end
|
|
end
|