ash/test/resource/identities_test.exs
2022-04-06 12:22:34 -04:00

59 lines
1.5 KiB
Elixir

defmodule Ash.Test.Resource.IdentitiesTest do
@moduledoc false
use ExUnit.Case, async: true
defmacrop defposts(do: body) do
quote do
defmodule Post do
@moduledoc false
use Ash.Resource
attributes do
uuid_primary_key :id
attribute :name, :string
attribute :contents, :string
end
unquote(body)
end
end
end
describe "representation" do
test "identities are persisted on the resource properly" do
defposts do
identities do
identity :foobar, [:name, :contents]
end
end
assert [%Ash.Resource.Identity{name: :foobar, keys: [:name, :contents]}] =
Ash.Resource.Info.identities(Post)
end
test "eager_check_with requires a primary read action" do
assert_raise Ash.Error.Dsl.DslError,
~r/but the resource has no primary read action./,
fn ->
defposts do
identities do
identity :foobar, [:name], eager_check_with: Foobar
end
end
end
end
test "Identity descriptions are allowed" do
defposts do
identities do
identity :foobar, [:name, :contents], description: "require one of name/contents"
end
end
assert [
%Ash.Resource.Identity{description: "require one of name/contents"}
] = Ash.Resource.Info.identities(Post)
end
end
end