Skip to content

Commit

Permalink
add regression test for correct error payload
Browse files Browse the repository at this point in the history
  • Loading branch information
mwhitworth authored and sax committed Jul 15, 2021
1 parent 9201042 commit 580b719
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/integration/socket_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,35 @@ defmodule Absinthe.GraphqlWS.SocketTest do
Absinthe.Subscription.publish(Test.Site.Endpoint, %{name: "true"}, thing_changes: "2")
assert {:ok, []} = Test.Client.get_new_replies(client)
end

test "correct error payload for subscription failure", %{client: client} do
id = "subscription-with-error"

:ok =
Test.Client.push(client, %{
id: id,
type: "subscribe",
payload: %{
query: """
subscription HandleError {
handleError {
id
name
}
}
"""
}
})

assert_json_received(
client,
%{
"id" => "subscription-with-error",
"payload" => [%{"locations" => [%{"column" => 3, "line" => 2}], "message" => "subscribe error"}],
"type" => "error"
}
)
end
end

describe "handle_message callbacks" do
Expand Down
6 changes: 6 additions & 0 deletions test/support/test/site.ex
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ defmodule Test.Site do
resolve(&Resolvers.changes_subscription/3)
end

field :handle_error, :thing do
config(fn _, _ ->
{:error, "subscribe error"}
end)
end

field :handle_message, :boolean do
arg(:subscription_param, :string)

Expand Down

0 comments on commit 580b719

Please sign in to comment.