aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Blowers <shdblowers@gmail.com>2016-11-22 19:12:13 (GMT)
committerSteven Blowers <shdblowers@gmail.com>2016-11-22 19:12:13 (GMT)
commit04feaeb7d6c469b3000accb921ecea8d4d2d8d9d (patch)
tree7f14450256d2fb2e2716f774a0dc868e2b072e28
parent8dffc2d3d71d132f1d2b228fc24ae8155905b1a2 (diff)
downloadzendex-04feaeb7d6c469b3000accb921ecea8d4d2d8d9d.tar.gz
zendex-04feaeb7d6c469b3000accb921ecea8d4d2d8d9d.tar.xz
search test now using meck
-rw-r--r--lib/zendex/search.ex3
-rw-r--r--test/zendex/search_test.exs15
2 files changed, 16 insertions, 2 deletions
diff --git a/lib/zendex/search.ex b/lib/zendex/search.ex
index ec9ea28..f920666 100644
--- a/lib/zendex/search.ex
+++ b/lib/zendex/search.ex
@@ -6,7 +6,6 @@ defmodule Zendex.Search do
alias Zendex.CommonHelpers
@url "/api/v2/search.json?query="
- @http_client Application.get_env(:zendex, :http_client)
@doc """
Search Zendesk.
@@ -18,7 +17,7 @@ defmodule Zendex.Search do
sort_string = create_sort_string(sort_by, sort_order)
"#{connection.base_url}#{@url}#{search_string}#{sort_string}"
- |> @http_client.get!(CommonHelpers.get_headers(connection.authentication))
+ |> HTTPoison.get!(CommonHelpers.get_headers(connection.authentication))
|> CommonHelpers.decode_response
end
diff --git a/test/zendex/search_test.exs b/test/zendex/search_test.exs
index a7102b6..6a292d1 100644
--- a/test/zendex/search_test.exs
+++ b/test/zendex/search_test.exs
@@ -5,7 +5,18 @@ defmodule Zendex.SearchTest do
[conn: Zendex.Connection.setup("http://test.zendesk.com", "User", "Passw")]
end
+ setup_all do
+ :meck.new(HTTPoison)
+ on_exit fn -> :meck.unload end
+ :ok
+ end
+
test "doing a search", context do
+ stub = fn("http://test.zendesk.com/api/v2/search.json?query=requester%3AJimbob+type%3Aticket", _) ->
+ %HTTPoison.Response{body: Poison.encode!(["Jimbob Ticket 1", "Jimbob Ticket 2"])}
+ end
+ :meck.expect(HTTPoison, :get!, stub)
+
expected = ["Jimbob Ticket 1", "Jimbob Ticket 2"]
actual = Zendex.Search.query(context[:conn],
@@ -15,6 +26,10 @@ defmodule Zendex.SearchTest do
end
test "doing a search with sorting", context do
+ stub = fn("http://test.zendesk.com/api/v2/search.json?query=requester%3AReginald+type%3Aticket&sort_by=created_at&sort_order=desc", _) ->
+ %HTTPoison.Response{body: Poison.encode!(["Reginald Ticket 1", "Reginald Ticket 2"])}
+ end
+ :meck.expect(HTTPoison, :get!, stub)
expected = ["Reginald Ticket 1", "Reginald Ticket 2"]
actual = Zendex.Search.query(context[:conn],