Skip to content

Commit

Permalink
Add test for Forcex.query
Browse files Browse the repository at this point in the history
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
mmrobins committed Mar 13, 2018
1 parent 7d50ab8 commit 749e684
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions test/forcex_test.exs
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

0 comments on commit 749e684

Please sign in to comment.