Skip to content

Commit

Permalink
Fix info for optional fields
Browse files Browse the repository at this point in the history
Steam API does not return the fields if they are nil
  • Loading branch information
Malet committed Jul 23, 2017
1 parent f9167d6 commit 4af9385
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/ueberauth/strategy/steam.ex
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ defmodule Ueberauth.Strategy.Steam do

%Info{
image: user.avatar,
name: user.realname,
location: user.loccountrycode,
name: get_in(user, [:realname]),
location: get_in(user, [:loccountrycode]),
urls: %{
Steam: user.profileurl,
}
Expand Down
17 changes: 17 additions & 0 deletions test/ueberauth/strategy/steam_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ defmodule Ueberauth.Strategy.SteamTest do
realname: "Sample Sample", steamid: "765309403423",
timecreated: 452342342}
@sample_response %{response: %{players: [@sample_user]}}
@optional_fields [:loccountrycode, :realname]

describe "handle_request!" do
test "redirects" do
Expand Down Expand Up @@ -174,6 +175,22 @@ defmodule Ueberauth.Strategy.SteamTest do
end
end

describe "info retrievers fetch (nil optional fields)" do
setup do
conn = %{conn(:get, "http://example.com/path/callback") | private: %{steam_user: Map.drop(@sample_user, @optional_fields)}}
conn = Steam.handle_callback! conn

[conn: conn]
end

test "info", %{conn: conn} do
auth_info = %Ueberauth.Auth.Info{
image: "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/f3/f3dsf34324eawdasdas3rwe.jpg",
urls: %{Steam: "http://steamcommunity.com/id/sample/"}}
assert Steam.info(conn) == auth_info
end
end

test "connection is cleaned up" do
conn = %{conn(:get, "http://example.com/path/callback") | private: %{steam_user: @sample_user}}

Expand Down

0 comments on commit 4af9385

Please sign in to comment.