From 2f9bbf3de79473997fa53bbe24b84eb7bf1f6c91 Mon Sep 17 00:00:00 2001 From: Darren Klein Date: Fri, 10 Dec 2021 17:49:13 -0500 Subject: [PATCH 1/6] Fixes code example causing failing doctest for . --- .tool-versions | 4 ++-- lib/assertions/absinthe.ex | 42 +++++++++++++++++++++++++++++++------- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/.tool-versions b/.tool-versions index cac1eca..6d3d754 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,2 +1,2 @@ -erlang 22.3.4.1 -elixir 1.10.0-otp-22 +erlang 23.3.4 +elixir 1.10.4 diff --git a/lib/assertions/absinthe.ex b/lib/assertions/absinthe.ex index 3e18bc1..5c54d72 100644 --- a/lib/assertions/absinthe.ex +++ b/lib/assertions/absinthe.ex @@ -82,10 +82,39 @@ defmodule Assertions.Absinthe do field in the response. ## Example - - iex> query = "{ user { #{document_for(:user, 2)} } }" - iex> expected = %{"user" => %{"name" => "Bob", "posts" => [%{"title" => "A post"}]}} - iex> assert_response_equals(query, expected) + iex> ExUnit.start() + iex> + iex> defmodule MyApp.Schema do + ...>use Absinthe.Schema + ...>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 + ...>query do + ...>field :user, :user do + ...>arg(:name, :string) + ...>resolve(fn _, _, _ -> {:ok, %{}} end) + ...>end + ...>end + ...>end + iex> + ...>defmodule MyApp.DataCase do + ...>use Assertions.AbsintheCase, async: true, schema: MyApp.Schema + ...>end + iex> + iex> query = "{ user { #{MyApp.DataCase.document_for(:user, 2)} } }" + iex> expected = %{"user" => %{"__typename" => "User", "name" => "Bob", "posts" => [%{"__typename" => "Post", "title" => "A post"}]}} + iex> MyApp.DataCase.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 @@ -101,11 +130,10 @@ defmodule Assertions.Absinthe do making separate assertions further down in your test. ## Example - 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()) :: From c65814ac18827257bd57fc108785a336d9021efe Mon Sep 17 00:00:00 2001 From: Darren Klein Date: Fri, 10 Dec 2021 19:09:34 -0500 Subject: [PATCH 2/6] Fixes example code causing failing doctest for document_for. --- lib/assertions/absinthe.ex | 43 ++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/lib/assertions/absinthe.ex b/lib/assertions/absinthe.ex index 5c54d72..dee863c 100644 --- a/lib/assertions/absinthe.ex +++ b/lib/assertions/absinthe.ex @@ -52,18 +52,39 @@ defmodule Assertions.Absinthe do fields with resolver functions that aren't tested in at least some fashion. ## Example - - iex> document_for(:user, 2) + iex> ExUnit.start() + iex> + iex> defmodule MyApp.Schema do + ...>use Absinthe.Schema + ...>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 + ...>query do + ...>field :user, :user do + ...>arg(:name, :string) + ...>resolve(fn _, _, _ -> {:ok, %{}} end) + ...>end + ...>end + ...>end + iex> + ...>defmodule MyApp.DataCase do + ...>use Assertions.AbsintheCase, async: true, schema: MyApp.Schema + ...>end + iex> + iex> MyApp.DataCase.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() From 198a13ad43d58bf99d820e89d3f3b88c3438d898 Mon Sep 17 00:00:00 2001 From: Darren Klein Date: Sat, 11 Dec 2021 12:12:16 -0500 Subject: [PATCH 3/6] Adds user query and object to test data structures, doctests passing. --- lib/assertions/absinthe.ex | 66 ++----------------------------- test/assertions/absinthe_test.exs | 23 +++++++++++ 2 files changed, 26 insertions(+), 63 deletions(-) diff --git a/lib/assertions/absinthe.ex b/lib/assertions/absinthe.ex index dee863c..dfa7062 100644 --- a/lib/assertions/absinthe.ex +++ b/lib/assertions/absinthe.ex @@ -52,37 +52,7 @@ defmodule Assertions.Absinthe do fields with resolver functions that aren't tested in at least some fashion. ## Example - iex> ExUnit.start() - iex> - iex> defmodule MyApp.Schema do - ...>use Absinthe.Schema - ...>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 - ...>query do - ...>field :user, :user do - ...>arg(:name, :string) - ...>resolve(fn _, _, _ -> {:ok, %{}} end) - ...>end - ...>end - ...>end - iex> - ...>defmodule MyApp.DataCase do - ...>use Assertions.AbsintheCase, async: true, schema: MyApp.Schema - ...>end - iex> - iex> MyApp.DataCase.document_for(:user, 2) + iex> document_for(:user, 2) \""" posts {\n title\n __typename\n }\n name\n __typename \""" @@ -103,39 +73,9 @@ defmodule Assertions.Absinthe do field in the response. ## Example - iex> ExUnit.start() - iex> - iex> defmodule MyApp.Schema do - ...>use Absinthe.Schema - ...>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 - ...>query do - ...>field :user, :user do - ...>arg(:name, :string) - ...>resolve(fn _, _, _ -> {:ok, %{}} end) - ...>end - ...>end - ...>end - iex> - ...>defmodule MyApp.DataCase do - ...>use Assertions.AbsintheCase, async: true, schema: MyApp.Schema - ...>end - iex> - iex> query = "{ user { #{MyApp.DataCase.document_for(:user, 2)} } }" + iex> query = "{ user { #{document_for(:user, 2)} } }" iex> expected = %{"user" => %{"__typename" => "User", "name" => "Bob", "posts" => [%{"__typename" => "Post", "title" => "A post"}]}} - iex> MyApp.DataCase.assert_response_equals(query, expected) + 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 diff --git a/test/assertions/absinthe_test.exs b/test/assertions/absinthe_test.exs index ab153d1..5c10396 100644 --- a/test/assertions/absinthe_test.exs +++ b/test/assertions/absinthe_test.exs @@ -64,6 +64,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 @@ -72,6 +79,22 @@ defmodule Nested.PetsSchema do resolve(fn _, _, _ -> {:ok, %{}} end) 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 end defmodule Assertions.AbsintheTest do From 52ccf249b4e6927ac76179388b9808433ff4bbe5 Mon Sep 17 00:00:00 2001 From: Darren Klein Date: Sat, 11 Dec 2021 12:43:33 -0500 Subject: [PATCH 4/6] Reverts tool_versions to versions currently in main repo. --- .tool-versions | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.tool-versions b/.tool-versions index 6d3d754..cac1eca 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,2 +1,2 @@ -erlang 23.3.4 -elixir 1.10.4 +erlang 22.3.4.1 +elixir 1.10.0-otp-22 From 799a281f681fab2affc789a9e5991362e6f06448 Mon Sep 17 00:00:00 2001 From: Darren Klein Date: Sat, 11 Dec 2021 12:46:34 -0500 Subject: [PATCH 5/6] Adds blank lines before and after code examples. --- .tool-versions | 4 ++-- lib/assertions/absinthe.ex | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.tool-versions b/.tool-versions index cac1eca..6d3d754 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,2 +1,2 @@ -erlang 22.3.4.1 -elixir 1.10.0-otp-22 +erlang 23.3.4 +elixir 1.10.4 diff --git a/lib/assertions/absinthe.ex b/lib/assertions/absinthe.ex index dfa7062..03c809c 100644 --- a/lib/assertions/absinthe.ex +++ b/lib/assertions/absinthe.ex @@ -52,10 +52,12 @@ defmodule Assertions.Absinthe do fields with resolver functions that aren't tested in at least some fashion. ## Example + iex> document_for(:user, 2) \""" 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 @@ -73,9 +75,11 @@ defmodule Assertions.Absinthe do field in the response. ## Example + iex> query = "{ user { #{document_for(:user, 2)} } }" 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 @@ -91,11 +95,13 @@ defmodule Assertions.Absinthe do making separate assertions further down in your test. ## Example + iex> query = "{ user { #{document_for(:user, 2)} } }" iex> assert_response_matches(query) do ...>%{"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() From 3b0a9da9052869940621808c425c44f0f8667536 Mon Sep 17 00:00:00 2001 From: Darren Klein Date: Sat, 11 Dec 2021 12:48:04 -0500 Subject: [PATCH 6/6] Again, reverts tool_versions. --- .tool-versions | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.tool-versions b/.tool-versions index 6d3d754..cac1eca 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,2 +1,2 @@ -erlang 23.3.4 -elixir 1.10.4 +erlang 22.3.4.1 +elixir 1.10.0-otp-22