2019-12-06 20:00:26 +13:00
|
|
|
defmodule Ash.Test.Dsl.Resource.Actions.ReadTest do
|
|
|
|
use ExUnit.Case, async: true
|
|
|
|
|
|
|
|
defmacrop defposts(do: body) do
|
|
|
|
quote do
|
|
|
|
defmodule Post do
|
2019-12-09 17:05:56 +13:00
|
|
|
use Ash.Resource, name: "posts", type: "post"
|
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 :default
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert [
|
|
|
|
%Ash.Resource.Actions.Read{
|
|
|
|
name: :default,
|
|
|
|
primary?: true,
|
2019-12-09 08:02:09 +13:00
|
|
|
authorization_steps: [],
|
2019-12-06 20:00:26 +13:00
|
|
|
type: :read
|
|
|
|
}
|
|
|
|
] = Ash.actions(Post)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "validation" do
|
|
|
|
test "it fails if `name` is not an atom" do
|
|
|
|
assert_raise(
|
|
|
|
Ash.Error.ResourceDslError,
|
|
|
|
"action name must be an atom at actions -> read",
|
|
|
|
fn ->
|
|
|
|
defposts do
|
|
|
|
actions do
|
|
|
|
read "default"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it fails if `primary?` is not a boolean" do
|
|
|
|
assert_raise(
|
|
|
|
Ash.Error.ResourceDslError,
|
2019-12-08 19:21:09 +13:00
|
|
|
"option primary? at actions -> read -> default must be boolean",
|
2019-12-06 20:00:26 +13:00
|
|
|
fn ->
|
|
|
|
defposts do
|
|
|
|
actions do
|
|
|
|
read :default, primary?: 10
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it fails if `rules` is not a list" do
|
|
|
|
assert_raise(
|
|
|
|
Ash.Error.ResourceDslError,
|
2019-12-30 11:28:28 +13:00
|
|
|
"option authorization_steps at actions -> read -> default must be keyword",
|
2019-12-06 20:00:26 +13:00
|
|
|
fn ->
|
|
|
|
defposts do
|
|
|
|
actions do
|
2019-12-09 08:02:09 +13:00
|
|
|
read :default, authorization_steps: 10
|
2019-12-06 20:00:26 +13:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|