aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Blowers <shdblowers@gmail.com>2016-11-22 13:37:00 (GMT)
committerSteven Blowers <shdblowers@gmail.com>2016-11-22 13:37:00 (GMT)
commite08eb7c1f4f9b2ac56433a465a4b07bbfc7e8530 (patch)
treeccf29a646449ab9afd766433d50ec2b8e6666cc2
parentea7f4479f151f95d4f1c1b7df121b4ec0dc6e309 (diff)
downloadzendex-e08eb7c1f4f9b2ac56433a465a4b07bbfc7e8530.tar.gz
zendex-e08eb7c1f4f9b2ac56433a465a4b07bbfc7e8530.tar.xz
trying out using meck on tickets module
-rw-r--r--lib/http_client/in_memory.ex11
-rw-r--r--lib/zendex/ticket.ex5
-rw-r--r--mix.exs1
-rw-r--r--mix.lock1
-rw-r--r--test/zendex/ticket_test.exs24
5 files changed, 27 insertions, 15 deletions
diff --git a/lib/http_client/in_memory.ex b/lib/http_client/in_memory.ex
index a448afd..eabe99f 100644
--- a/lib/http_client/in_memory.ex
+++ b/lib/http_client/in_memory.ex
@@ -6,11 +6,6 @@ defmodule Zendex.HttpClient.InMemory do
@base_url "http://test.zendesk.com"
- def get!(@base_url <> "/api/v2/tickets.json",
- [{"Authorization", _authentication}]) do
- fake_response("ticket")
- end
-
def get!(@base_url <> "/api/v2/search.json?query=requester%3AJimbob+type%3Aticket",
[{"Authorization", _authentication}]) do
fake_response(["Jimbob Ticket 1", "Jimbob Ticket 2"])
@@ -37,12 +32,6 @@ defmodule Zendex.HttpClient.InMemory do
%{id: 67, name: "Sarpedon Baumgartner"}]})
end
- def post!(@base_url <> "/api/v2/tickets.json",
- "{\"ticket\":{}}",
- [{"Authorization", _authentication}, {"Content-Type", "application/json"}]) do
- fake_response("Ticket created successfully!")
- end
-
def post!(@base_url <> "/api/v2/users.json",
"{\"user\":{\"name\":\"Roger\",\"email\":\"roger@dodger.com\"}}",
[{"Authorization", _authentication}, {"Content-Type", "application/json"}]) do
diff --git a/lib/zendex/ticket.ex b/lib/zendex/ticket.ex
index 9232d6e..2aaf7ae 100644
--- a/lib/zendex/ticket.ex
+++ b/lib/zendex/ticket.ex
@@ -7,7 +7,6 @@ defmodule Zendex.Ticket do
alias Zendex.CommonHelpers
@url "/api/v2/tickets.json"
- @http_client Application.get_env(:zendex, :http_client)
@doc """
List all tickets.
@@ -15,7 +14,7 @@ defmodule Zendex.Ticket do
@spec list(Zendex.Connection.t) :: map
def list(connection) do
"#{connection.base_url}#{@url}"
- |> @http_client.get!(CommonHelpers.get_headers(connection.authentication))
+ |> HTTPoison.get!(CommonHelpers.get_headers(connection.authentication))
|> CommonHelpers.decode_response
end
@@ -25,7 +24,7 @@ defmodule Zendex.Ticket do
@spec create(Zendex.Connection.t, map) :: map
def create(connection, ticket) do
"#{connection.base_url}#{@url}"
- |> @http_client.post!(Poison.encode!(ticket),
+ |> HTTPoison.post!(Poison.encode!(ticket),
CommonHelpers.get_headers(connection.authentication,
%{content_type: :json}))
|> CommonHelpers.decode_response
diff --git a/mix.exs b/mix.exs
index 41d57fd..b1b6160 100644
--- a/mix.exs
+++ b/mix.exs
@@ -24,6 +24,7 @@ defmodule Zendex.Mixfile do
defp deps do
[{:httpoison, "~> 0.9"},
{:poison, "~> 2.2"},
+ {:meck, "~> 0.8.4", only: :test},
{:ex_doc, ">= 0.0.0", only: :dev},
{:credo, "~> 0.4", only: :dev},
{:dialyxir, "~> 0.3", only: :dev},
diff --git a/mix.lock b/mix.lock
index 97e7b95..f4f1bb6 100644
--- a/mix.lock
+++ b/mix.lock
@@ -10,6 +10,7 @@
"httpoison": {:hex, :httpoison, "0.9.2", "a211a8e87403a043c41218e64df250d321f236ac57f786c6a0ccf3e9e817c819", [:mix], [{:hackney, "~> 1.6.0", [hex: :hackney, optional: false]}]},
"idna": {:hex, :idna, "1.2.0", "ac62ee99da068f43c50dc69acf700e03a62a348360126260e87f2b54eced86b2", [], []},
"jsx": {:hex, :jsx, "2.8.0", "749bec6d205c694ae1786d62cea6cc45a390437e24835fd16d12d74f07097727", [:mix, :rebar], []},
+ "meck": {:hex, :meck, "0.8.4", "59ca1cd971372aa223138efcf9b29475bde299e1953046a0c727184790ab1520", [:make, :rebar], []},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [], []},
"mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [], []},
"poison": {:hex, :poison, "2.2.0", "4763b69a8a77bd77d26f477d196428b741261a761257ff1cf92753a0d4d24a63", [], []},
diff --git a/test/zendex/ticket_test.exs b/test/zendex/ticket_test.exs
index 6bc4436..4bbe388 100644
--- a/test/zendex/ticket_test.exs
+++ b/test/zendex/ticket_test.exs
@@ -5,11 +5,33 @@ defmodule Zendex.TicketTest 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 "getting tickets", context do
- assert "ticket" == Zendex.Ticket.list(context[:conn])
+ :meck.expect(HTTPoison,
+ :get!,
+ fn("http://test.zendesk.com/api/v2/tickets.json", [{"Authorization", "Basic VXNlcjpQYXNzdw=="}]) ->
+ %HTTPoison.Response{body: Poison.encode!("ticket")}
+ end)
+
+ assert "ticket" == Zendex.Ticket.list(context[:conn])
end
test "creating a ticket", context do
+ :meck.expect(HTTPoison,
+ :post!,
+ fn(_, _, _) ->
+ %HTTPoison.Response{body: Poison.encode!("Ticket created successfully!")}
+ end)
+
assert "Ticket created successfully!" ==
Zendex.Ticket.create(context[:conn], %{"ticket": %{}})
end