2019-12-06 20:00:26 +13:00
|
|
|
defmodule Ash.Test.Dsl.Resource.Actions.ReadTest do
|
2020-09-26 00:20:58 +12:00
|
|
|
@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
|
2020-09-26 00:20:58 +12:00
|
|
|
@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
|
|
|
|
2020-06-30 16:31:07 +12:00
|
|
|
attributes do
|
2021-01-13 09:40:55 +13:00
|
|
|
uuid_primary_key :id
|
2020-06-30 16:31:07 +12:00
|
|
|
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
|
2021-03-08 18:59:32 +13:00
|
|
|
read :read
|
2019-12-06 20:00:26 +13:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert [
|
|
|
|
%Ash.Resource.Actions.Read{
|
2021-03-08 18:59:32 +13:00
|
|
|
name: :read,
|
2022-04-29 10:07:06 +12:00
|
|
|
primary?: false,
|
2019-12-06 20:00:26 +13:00
|
|
|
type: :read
|
|
|
|
}
|
2021-02-23 14:29:31 +13:00
|
|
|
] = 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(
|
2022-08-15 06:06:58 +12:00
|
|
|
Spark.Error.DslError,
|
2022-12-08 14:35:32 +13:00
|
|
|
"[Ash.Test.Dsl.Resource.Actions.ReadTest.Post]\n actions -> read -> default:\n invalid value for :name option: expected 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(
|
2022-08-15 06:06:58 +12:00
|
|
|
Spark.Error.DslError,
|
2022-12-08 14:35:32 +13:00
|
|
|
"[Ash.Test.Dsl.Resource.Actions.ReadTest.Post]\n actions -> read -> read:\n invalid value for :primary? option: expected boolean, got: 10",
|
2019-12-06 20:00:26 +13:00
|
|
|
fn ->
|
|
|
|
defposts do
|
|
|
|
actions do
|
2021-03-08 18:59:32 +13:00
|
|
|
read :read, primary?: 10
|
2019-12-06 20:00:26 +13:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|