ash/test/resource/actions/actions_test.exs

61 lines
1.6 KiB
Elixir
Raw Normal View History

2019-12-07 20:42:14 +13:00
defmodule Ash.Test.Dsl.Resource.Actions.ActionsTest do
2020-06-02 17:47:25 +12:00
@moduledoc false
2019-12-07 20:42:14 +13:00
use ExUnit.Case, async: true
defmacrop defposts(do: body) do
quote do
# Process.flag(:trap_exit, true)
2019-12-07 20:42:14 +13:00
defmodule Post do
2020-06-02 17:47:25 +12:00
@moduledoc false
use Ash.Resource
2019-12-07 20:42:14 +13:00
attributes do
attribute :id, :uuid, primary_key?: true, default: &Ecto.UUID.generate/0
end
2019-12-07 20:42:14 +13:00
unquote(body)
end
end
end
2020-12-31 05:55:40 +13:00
test "default actions are added" do
defposts do
end
assert Ash.Resource.primary_action!(Post, :read)
end
2019-12-07 20:42:14 +13:00
describe "validations" do
test "raises if you have multiple primary actions for a type" do
assert_raise(
2020-07-16 09:06:27 +12:00
Ash.Error.Dsl.DslError,
2020-10-06 03:40:22 +13:00
"[Ash.Resource.Transformers.SetPrimaryActions]\n actions -> create:\n Multiple actions of type create configured as `primary?: true`, but only one action per type can be the primary",
2019-12-07 20:42:14 +13:00
fn ->
defposts do
actions do
create :default, primary?: true
create :special, primary?: true
end
end
end
)
end
test "raises if you have multiple actions for a type, but none are primary" do
assert_raise(
2020-07-16 09:06:27 +12:00
Ash.Error.Dsl.DslError,
2020-10-06 03:40:22 +13:00
"[Ash.Resource.Transformers.SetPrimaryActions]\n actions -> create:\n Multiple actions of type create defined, one must be designated as `primary?: true`",
2019-12-07 20:42:14 +13:00
fn ->
defposts do
actions do
create :default
create :special
end
end
end
)
end
end
end