From 749e684c22dd55423389044b618ab0f1409b1a79 Mon Sep 17 00:00:00 2001 From: Matt Robinson Date: Tue, 13 Mar 2018 14:29:13 -0700 Subject: [PATCH] Add test for Forcex.query 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. --- test/forcex_test.exs | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/test/forcex_test.exs b/test/forcex_test.exs index 9a0357f..ad34f94 100644 --- a/test/forcex_test.exs +++ b/test/forcex_test.exs @@ -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