Skip to content

Commit

Permalink
Add test case for when config/2 returns a map
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanjos committed Oct 3, 2024
1 parent 39bdf98 commit 1ee0ad9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/absinthe/phoenix_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,18 @@ defmodule Absinthe.PhoenixTest do
assert reply == %{errors: [%{locations: [%{column: 15, line: 1}], message: "unauthorized"}]}
end

@tag :skip #TODO: update when absinthe's version is >= 1.8
test "config functions can return errors when returning map", %{socket: socket} do
ref =
push(socket, "doc", %{
"query" => "subscription {errorsMap { __typename }}"
})

assert_reply(ref, :error, reply)

assert reply == %{errors: [%{locations: [%{column: 15, line: 1}], message: "unauthorized", extensions: %{code: "UNAUTHORIZED"}}]}
end

test "can't do multiple fields on a subscription root", %{socket: socket} do
ref =
push(socket, "doc", %{
Expand Down
6 changes: 6 additions & 0 deletions test/support/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,11 @@ defmodule Schema do
{:error, "unauthorized"}
end
end

field :errors_map, :comment do
config fn _, _ ->
{:error, %{message: "unauthorized", extensions: %{code: "UNAUTHORIZED"}}}
end
end
end
end

0 comments on commit 1ee0ad9

Please sign in to comment.