From 2c653ee952aff47912be19a715321aa8b808d81b Mon Sep 17 00:00:00 2001 From: nelsonic Date: Thu, 2 Apr 2020 23:34:15 +0100 Subject: [PATCH] add @doc for inject_poison/0 for #35 --- lib/elixir_auth_google.ex | 10 ++++++---- lib/httpoison_mock.ex | 3 --- mix.exs | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/elixir_auth_google.ex b/lib/elixir_auth_google.ex index 9872f53..37e7d6b 100644 --- a/lib/elixir_auth_google.ex +++ b/lib/elixir_auth_google.ex @@ -7,6 +7,11 @@ defmodule ElixirAuthGoogle do @google_token_url "https://oauth2.googleapis.com/token" @google_user_profile "https://www.googleapis.com/oauth2/v3/userinfo" + @doc """ + `inject_poison/0` injects a TestDouble of HTTPoison in Test + so that we don't have duplicate mock in consuming apps. + see: https://github.com/dwyl/elixir-auth-google/issues/35 + """ def inject_poison() do Mix.env() == :test && ElixirAuthGoogle.HTTPoisonMock || HTTPoison end @@ -71,7 +76,6 @@ defmodule ElixirAuthGoogle do }) inject_poison().post(@google_token_url, body) |> parse_body_response() - # |> IO.inspect(label: "get_token() response") end @doc """ @@ -84,11 +88,9 @@ defmodule ElixirAuthGoogle do """ @spec get_user_profile(String.t) :: String.t def get_user_profile(token) do - httpoison = inject_poison() "#{@google_user_profile}?access_token=#{token}" - |> httpoison.get() + |> inject_poison().get() |> parse_body_response() - # |> IO.inspect(label: "get_user_profile() response") end @doc """ diff --git a/lib/httpoison_mock.ex b/lib/httpoison_mock.ex index e0baaf4..1153889 100644 --- a/lib/httpoison_mock.ex +++ b/lib/httpoison_mock.ex @@ -9,7 +9,6 @@ defmodule ElixirAuthGoogle.HTTPoisonMock do Obviously, don't invoke it from your App unless you want people to see fails. """ def get("https://www.googleapis.com/oauth2/v3/userinfo?access_token=wrong_token") do - # IO.inspect("HTTPoisonMock.get access_token=wrong_token") {:error, :bad_request} end @@ -17,7 +16,6 @@ defmodule ElixirAuthGoogle.HTTPoisonMock do get/1 using a dummy _url to test body decoding. """ def get(_url) do - # IO.inspect("HTTPoisonMock.get %{name: dwyl}") {:ok, %{body: Poison.encode!( %{ email: "nelson@gmail.com", @@ -36,7 +34,6 @@ defmodule ElixirAuthGoogle.HTTPoisonMock do post/2 passing in dummy _url & _body to test return of access_token. """ def post(_url, _body) do - # IO.inspect("HTTPoisonMock.post %{ccess_token: token1}") {:ok, %{body: Poison.encode!(%{access_token: "token1"})}} end end diff --git a/mix.exs b/mix.exs index 87a8540..c3226da 100644 --- a/mix.exs +++ b/mix.exs @@ -2,7 +2,7 @@ defmodule ElixirAuthGoogle.MixProject do use Mix.Project @description "Minimalist Google OAuth Authentication for Elixir Apps" - @version "1.1.5" + @version "1.2.0" def project do [