Skip to content

Commit

Permalink
add @doc for inject_poison/0 for #35
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonic committed Apr 2, 2020
1 parent f5dcf36 commit 2c653ee
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
10 changes: 6 additions & 4 deletions lib/elixir_auth_google.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 """
Expand All @@ -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 """
Expand Down
3 changes: 0 additions & 3 deletions lib/httpoison_mock.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ 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

@doc """
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",
Expand All @@ -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
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
[
Expand Down

0 comments on commit 2c653ee

Please sign in to comment.