failing test for root errors (#27)

This commit is contained in:
Michael St Clair 2021-09-11 23:02:08 -06:00 committed by GitHub
parent ffa7d3efdd
commit 05fc3dc01a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 136 additions and 1 deletions

View file

@ -280,6 +280,40 @@ defmodule AshGraphql.CreateTest do
assert message =~ "Confirmation did not match value"
end
test "root level error" do
Application.put_env(:ash, AshGraphql.Test.Api,
graphql: [show_raised_errors?: true, root_level_errors?: true]
)
resp =
"""
mutation CreatePost($input: CreatePostInput) {
createPost(input: $input) {
result{
text
}
errors{
message
}
}
}
"""
|> Absinthe.run(AshGraphql.Test.Schema,
variables: %{
"input" => %{
"text" => "foobar",
"confirmation" => "foobar2"
}
}
)
assert {:ok, result} = resp
assert %{errors: [%{message: message}]} = result
assert message =~ "Confirmation did not match value"
end
test "custom input types are used" do
resp =
"""

View file

@ -156,4 +156,33 @@ defmodule AshGraphql.DestroyTest do
assert %{data: %{"deletePost" => %{"errors" => [%{"message" => "could not be found"}]}}} =
result
end
test "root level error on destroy" do
Application.put_env(:ash, AshGraphql.Test.Api,
graphql: [show_raised_errors?: true, root_level_errors?: true]
)
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
assert %{errors: [%{message: "could not be found"}]} = result
end
end

View file

@ -67,6 +67,7 @@ defmodule AshGraphql.Test.Post do
create :create_post_with_comments_and_tags, :with_comments_and_tags
update :update_post, :update
create :update_post_confirm, :update_confirm
update :update_best_post, :update, read_action: :best_post, identity: false
destroy :archive_post, :archive
@ -139,7 +140,13 @@ defmodule AshGraphql.Test.Post do
filter(expr(best == true))
end
update(:update)
update :update, primary?: true
update :update_confirm do
argument(:confirmation, :string)
validate(confirm(:text, :confirmation))
end
destroy(:destroy, primary?: true)
destroy :archive do

View file

@ -74,4 +74,69 @@ defmodule AshGraphql.UpdateTest do
%{data: %{"updateBestPost" => %{"errors" => [], "result" => %{"text" => "barbuz"}}}}} =
resp
end
test "arguments are threaded properly" do
resp =
"""
mutation UpdatePostConfirm($input: UpdatePostConfirmInput) {
updatePostConfirm(input: $input) {
result{
text
}
errors{
message
}
}
}
"""
|> Absinthe.run(AshGraphql.Test.Schema,
variables: %{
"input" => %{
"text" => "foobar",
"confirmation" => "foobar2"
}
}
)
assert {:ok, result} = resp
assert %{data: %{"updatePostConfirm" => %{"result" => nil, "errors" => [%{"message" => message}]}}} =
result
assert message =~ "Confirmation did not match value"
end
test "root level error" do
Application.put_env(:ash, AshGraphql.Test.Api,
graphql: [show_raised_errors?: true, root_level_errors?: true]
)
resp =
"""
mutation UpdatePostConfirm($input: UpdatePostConfirmInput) {
updatePostConfirm(input: $input) {
result{
text
}
errors{
message
}
}
}
"""
|> Absinthe.run(AshGraphql.Test.Schema,
variables: %{
"input" => %{
"text" => "foobar",
"confirmation" => "foobar2"
}
}
)
assert {:ok, result} = resp
assert %{errors: [%{message: message}]} = result
assert message =~ "Confirmation did not match value"
end
end