mirror of
https://github.com/ash-project/ash_graphql.git
synced 2024-09-20 05:13:33 +12:00
failing test for root errors (#27)
This commit is contained in:
parent
ffa7d3efdd
commit
05fc3dc01a
4 changed files with 136 additions and 1 deletions
|
@ -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 =
|
||||
"""
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue