From f7c6b22f296455e41e2f81954a1a5769d118e5fb Mon Sep 17 00:00:00 2001 From: Darren Klein Date: Sat, 11 Dec 2021 14:10:20 -0500 Subject: [PATCH] Fixes code examples causing failing doctest. --- lib/assertions/absinthe.ex | 19 +++++++------------ test/assertions/absinthe_test.exs | 23 +++++++++++++++++++++++ 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/lib/assertions/absinthe.ex b/lib/assertions/absinthe.ex index 3e18bc1..03c809c 100644 --- a/lib/assertions/absinthe.ex +++ b/lib/assertions/absinthe.ex @@ -55,16 +55,9 @@ defmodule Assertions.Absinthe do iex> document_for(:user, 2) \""" - name - age - posts { - title - subtitle - } - comments { - body - } + posts {\n title\n __typename\n }\n name\n __typename \""" + """ @spec document_for(module(), atom(), non_neg_integer(), Keyword.t()) :: String.t() def document_for(schema, type, nesting, overrides) do @@ -84,8 +77,9 @@ defmodule Assertions.Absinthe do ## Example iex> query = "{ user { #{document_for(:user, 2)} } }" - iex> expected = %{"user" => %{"name" => "Bob", "posts" => [%{"title" => "A post"}]}} + iex> expected = %{"user" => %{"__typename" => "User", "name" => "Bob", "posts" => [%{"__typename" => "Post", "title" => "A post"}]}} iex> assert_response_equals(query, expected) + """ @spec assert_response_equals(module(), String.t(), map(), Keyword.t()) :: :ok | no_return() def assert_response_equals(schema, document, expected_response, options) do @@ -104,9 +98,10 @@ defmodule Assertions.Absinthe do iex> query = "{ user { #{document_for(:user, 2)} } }" iex> assert_response_matches(query) do - %{"user" => %{"name" => "B" <> _, "posts" => posts}} - end + ...>%{"user" => %{"name" => "B" <> _, "posts" => posts}} + ...>end iex> assert length(posts) == 1 + """ @spec assert_response_matches(module(), String.t(), Keyword.t(), Macro.expr()) :: :ok | no_return() diff --git a/test/assertions/absinthe_test.exs b/test/assertions/absinthe_test.exs index ab153d1..f788c56 100644 --- a/test/assertions/absinthe_test.exs +++ b/test/assertions/absinthe_test.exs @@ -50,6 +50,22 @@ defmodule Nested.PetsSchema do end end + object :user do + field :name, :string do + resolve(fn _, _, _ -> {:ok, "Bob"} end) + end + + field :posts, non_null(list_of(:post)) do + resolve(fn _, _, _ -> {:ok, [%{}]} end) + end + end + + object :post do + field :title, :string do + resolve(fn _, _, _ -> {:ok, "A post"} end) + end + end + input_object :add_person_input do field(:name, :string) end @@ -64,6 +80,13 @@ defmodule Nested.PetsSchema do arg(:name, :string) resolve(fn _, _, _ -> {:ok, %{}} end) end + + # :user is referenced in the code examples in the documentation, + # the :user field and object are needed to pass the doctest. + field :user, :user do + arg(:name, :string) + resolve(fn _, _, _ -> {:ok, %{}} end) + end end mutation do