-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Since the stubbed out Api module does all the parsing of the JSON that's returned the test doesn't exercise a ton, other than a url is called and kind of documents the format of the returned data.
- Loading branch information
Showing
1 changed file
with
34 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,39 @@ | ||
defmodule ForcexTest do | ||
use ExUnit.Case | ||
|
||
test "the truth" do | ||
assert 1 + 1 == 2 | ||
import Mox | ||
setup :verify_on_exit! | ||
|
||
test "query" do | ||
response = %{ | ||
done: false, | ||
nextRecordsUrl: "/services/data/v41.0/query/01g0W00006pQQsWQAW-2000", | ||
records: [ | ||
%{Id: "0010W00002JBygyQAD", Name: "Michael Weber", attributes: %{type: "Account", url: "/services/data/v41.0/sobjects/Account/0010W00002JBygyQAD"}}, | ||
%{Id: "0010W00002JBw2mQAD", Name: "Erica Adams", attributes: %{type: "Account", url: "/services/data/v41.0/sobjects/Account/0010W00002JBw2mQAD"}}, | ||
], | ||
totalSize: 5989 | ||
} | ||
|
||
endpoint = "https://forcex.my.salesforce.com" | ||
api_version = "41.0" | ||
auth_header = [{"Authorization", "Bearer sometoken"}] | ||
query_path = "/services/data/v41.0/query" | ||
query = "select Id, Name from Account order by CreatedDate desc" | ||
query_url = "#{endpoint}#{query_path}/?#{%{"q" => query} |> URI.encode_query}" | ||
IO.puts query_url | ||
|
||
|
||
Forcex.Api.MockHttp | ||
|> expect(:raw_request, fn(:get, ^query_url, _, ^auth_header, _) -> response end) | ||
|
||
client = %Forcex.Client{ | ||
endpoint: endpoint, | ||
authorization_header: auth_header, | ||
api_version: api_version, | ||
services: %{query: query_path} | ||
} | ||
|
||
assert Forcex.query(query, client) == response | ||
end | ||
end |