From 0a1b2837cf3da02411371379fa79d3b916a83b62 Mon Sep 17 00:00:00 2001 From: Matt Robinson Date: Tue, 13 Mar 2018 13:43:00 -0700 Subject: [PATCH] Add test for oauth based login --- test/forcex/client_test.exs | 39 ++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/test/forcex/client_test.exs b/test/forcex/client_test.exs index 384be0b..105fb15 100644 --- a/test/forcex/client_test.exs +++ b/test/forcex/client_test.exs @@ -8,9 +8,10 @@ defmodule Forcex.ClientTest do test "sets the auth header and endpoint when successful" do session_id = "forcex_session_id" server_url = "https://forcex.my.salesforce.com/services/Soap/u/41.0/00Dd0000000cQ8L" + org_id = "org_id" response = """ - #{server_url}falsefalse#{server_url}#{session_id}005d0000001Jb9tAACfalsefalse$5242880USDen_USfalsetrue00Dd0000000cQ8LEAUfalseMY-ORG00ed0000000Ods2AAC00Ed0000000II8UEAW7200forcex@example.comJohn Doe005d0000001Jb9tAACen_USen_USforcex@example.comAmerica/New_YorkStandardTheme3 + #{server_url}falsefalse#{server_url}#{session_id}005d0000001Jb9tAACfalsefalse$5242880USDen_USfalsetrue#{org_id}falseMY-ORG00ed0000000Ods2AAC00Ed0000000II8UEAW7200forcex@example.comJohn Doe005d0000001Jb9tAACen_USen_USforcex@example.comAmerica/New_YorkStandardTheme3 """ Forcex.Api.MockHttp @@ -32,4 +33,40 @@ defmodule Forcex.ClientTest do assert client.endpoint == "https://forcex.my.salesforce.com/" end end + + describe "oauth based login" do + test "sets the auth header and endpoint when successful" do + org_id = "org_id" + access_token = "access_token" + + response = %{ + access_token: access_token, + id: "https://login.salesforce.com/id/#{org_id}/005d0000001Jb9tAAC", + instance_url: "https://forcex.my.salesforce.com", + issued_at: "1520973086810", + signature: "oo7i3klbG6OjXlMFQSBzFaNYCP9pnWZ98f6Kdu/Th2Q=", + token_type: "Bearer" + } + + Forcex.Api.MockHttp + |> expect(:raw_request, fn :post, _, _, _, _ -> response end) + + config = %{ + password: "password", + security_token: "security_token", + username: "forcex@example.com", + client_id: "big_ol_id", + client_secret: "sssshhhhhhhh" + } + + client = Forcex.Client.login(config) + + assert client.authorization_header == [{ + "Authorization", + "Bearer #{access_token}" + }] + + assert client.endpoint == "https://forcex.my.salesforce.com" + end + end end