mirror of
https://github.com/ash-project/ash_graphql.git
synced 2024-09-20 13:24:14 +12:00
4f71d69c5d
improvement: support `identity: false` for udpates and destroys
95 lines
2.1 KiB
Elixir
95 lines
2.1 KiB
Elixir
defmodule AshGraphql.DestroyTest do
|
|
use ExUnit.Case, async: false
|
|
|
|
setup do
|
|
on_exit(fn ->
|
|
try do
|
|
ETS.Set.delete(ETS.Set.wrap_existing!(AshGraphql.Test.Post))
|
|
ETS.Set.delete(ETS.Set.wrap_existing!(AshGraphql.Test.Comment))
|
|
rescue
|
|
_ ->
|
|
:ok
|
|
end
|
|
end)
|
|
end
|
|
|
|
test "a destroy works" do
|
|
post = AshGraphql.Test.Api.create!(Ash.Changeset.new(AshGraphql.Test.Post, text: "foobar"))
|
|
|
|
resp =
|
|
"""
|
|
mutation DeletePost($id: ID) {
|
|
deletePost(id: $id) {
|
|
result{
|
|
text
|
|
}
|
|
errors{
|
|
message
|
|
}
|
|
}
|
|
}
|
|
"""
|
|
|> Absinthe.run(AshGraphql.Test.Schema,
|
|
variables: %{
|
|
"id" => post.id
|
|
}
|
|
)
|
|
|
|
assert {:ok, result} = resp
|
|
|
|
refute Map.has_key?(result, :errors)
|
|
assert %{data: %{"deletePost" => %{"result" => %{"text" => "foobar"}}}} = result
|
|
end
|
|
|
|
test "a destroy with a configured read action and no identity works" do
|
|
AshGraphql.Test.Api.create!(
|
|
Ash.Changeset.new(AshGraphql.Test.Post, text: "foobar", best: true)
|
|
)
|
|
|
|
resp =
|
|
"""
|
|
mutation DeleteBestPost {
|
|
deleteBestPost {
|
|
result{
|
|
text
|
|
}
|
|
errors{
|
|
message
|
|
}
|
|
}
|
|
}
|
|
"""
|
|
|> Absinthe.run(AshGraphql.Test.Schema)
|
|
|
|
assert {:ok, result} = resp
|
|
|
|
refute Map.has_key?(result, :errors)
|
|
assert %{data: %{"deleteBestPost" => %{"result" => %{"text" => "foobar"}}}} = result
|
|
end
|
|
|
|
test "destroying a non-existent record returns a not found error" do
|
|
resp =
|
|
"""
|
|
mutation DeletePost($id: ID) {
|
|
deletePost(id: $id) {
|
|
result{
|
|
text
|
|
}
|
|
errors{
|
|
message
|
|
}
|
|
}
|
|
}
|
|
"""
|
|
|> Absinthe.run(AshGraphql.Test.Schema,
|
|
variables: %{
|
|
"id" => Ash.UUID.generate()
|
|
}
|
|
)
|
|
|
|
assert {:ok, result} = resp
|
|
|
|
refute Map.has_key?(result, :errors)
|
|
assert %{data: %{"deletePost" => %{"errors" => [%{"message" => "not found"}]}}} = result
|
|
end
|
|
end
|