ash/test/resource/actions/update_test.exs

68 lines
1.5 KiB
Elixir
Raw Normal View History

2019-12-06 20:00:26 +13:00
defmodule Ash.Test.Dsl.Resource.Actions.UpdateTest do
use ExUnit.Case, async: true
defmacrop defposts(do: body) do
quote do
defmodule Post do
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
2020-12-31 06:53:24 +13:00
defaults []
2019-12-06 20:00:26 +13:00
update :default
end
end
assert [
%Ash.Resource.Actions.Update{
name: :default,
primary?: true,
type: :update
}
] = 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,
2020-10-06 03:40:22 +13:00
"[Ash.Resource.Dsl.Update]\n actions -> update -> default:\n expected :name to be an atom, got: \"default\"",
2019-12-06 20:00:26 +13:00
fn ->
defposts do
actions do
update "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,
2020-12-01 18:51:24 +13:00
"[Ash.Resource.Dsl.Update]\n actions -> update -> default:\n expected :primary? to be a boolean, got: 10",
2019-12-06 20:00:26 +13:00
fn ->
defposts do
actions do
update :default, primary?: 10
end
end
end
)
end
end
end