ash/test/resource/actions/read_test.exs

69 lines
1.5 KiB
Elixir
Raw Normal View History

2019-12-06 20:00:26 +13:00
defmodule Ash.Test.Dsl.Resource.Actions.ReadTest do
@moduledoc false
2019-12-06 20:00:26 +13:00
use ExUnit.Case, async: true
defmacrop defposts(do: body) do
quote do
defmodule Post do
@moduledoc false
2020-08-19 16:49:41 +12:00
use Ash.Resource,
data_layer: Ash.DataLayer.Ets
2019-12-06 20:00:26 +13:00
attributes do
uuid_primary_key :id
end
2019-12-06 20:00:26 +13:00
unquote(body)
end
end
end
describe "representation" do
test "it creates an action" do
defposts do
actions do
read :read
2019-12-06 20:00:26 +13:00
end
end
assert [
%Ash.Resource.Actions.Read{
name: :read,
2019-12-06 20:00:26 +13:00
primary?: true,
type: :read
}
] = Ash.Resource.Info.actions(Post)
2019-12-06 20:00:26 +13:00
end
end
describe "validation" do
test "it fails if `name` is not an atom" do
assert_raise(
2020-07-16 09:06:27 +12:00
Ash.Error.Dsl.DslError,
"[Ash.Test.Dsl.Resource.Actions.ReadTest.Post]\n actions -> read -> default:\n expected :name to be an atom, got: \"default\"",
2019-12-06 20:00:26 +13:00
fn ->
defposts do
actions do
read "default"
end
end
end
)
end
test "it fails if `primary?` is not a boolean" do
assert_raise(
2020-07-16 09:06:27 +12:00
Ash.Error.Dsl.DslError,
"[Ash.Test.Dsl.Resource.Actions.ReadTest.Post]\n actions -> read -> read:\n expected :primary? to be a boolean, got: 10",
2019-12-06 20:00:26 +13:00
fn ->
defposts do
actions do
read :read, primary?: 10
2019-12-06 20:00:26 +13:00
end
end
end
)
end
end
end