aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Blowers <shdblowers@gmail.com>2016-11-22 19:48:02 (GMT)
committerSteven Blowers <shdblowers@gmail.com>2016-11-22 19:48:02 (GMT)
commit5473dacfe2da5ca3dbe38360b49be7f1611d092b (patch)
treed8562b66308c0dbedbf667b91c20678031343c49
parent1bfac92a35eb752c4ed6cc4a510d11786d1a01c8 (diff)
downloadzendex-5473dacfe2da5ca3dbe38360b49be7f1611d092b.tar.gz
zendex-5473dacfe2da5ca3dbe38360b49be7f1611d092b.tar.xz
minor improvements to test
-rw-r--r--test/zendex/search_test.exs15
-rw-r--r--test/zendex/ticket_test.exs22
-rw-r--r--test/zendex/user_test.exs26
3 files changed, 32 insertions, 31 deletions
diff --git a/test/zendex/search_test.exs b/test/zendex/search_test.exs
index a5b6405..bb1f358 100644
--- a/test/zendex/search_test.exs
+++ b/test/zendex/search_test.exs
@@ -12,24 +12,25 @@ defmodule Zendex.SearchTest do
end
test "doing a search", %{conn: conn} 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"])}
+ expected = ["Jimbob Ticket 1", "Jimbob Ticket 2"]
+
+ stub = fn("http://test.zendesk.com/api/v2/search.json?query=requester%3AJimbob+type%3Aticket", _headers) ->
+ %HTTPoison.Response{body: Poison.encode!(expected)}
end
:meck.expect(HTTPoison, :get!, stub)
- expected = ["Jimbob Ticket 1", "Jimbob Ticket 2"]
-
actual = Zendex.Search.query(conn, %{type: "ticket", requester: "Jimbob"})
assert actual == expected
end
test "doing a search with sorting", %{conn: conn} 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"])}
+ expected = ["Reginald Ticket 1", "Reginald Ticket 2"]
+
+ stub = fn("http://test.zendesk.com/api/v2/search.json?query=requester%3AReginald+type%3Aticket&sort_by=created_at&sort_order=desc", _headers) ->
+ %HTTPoison.Response{body: Poison.encode!(expected)}
end
:meck.expect(HTTPoison, :get!, stub)
- expected = ["Reginald Ticket 1", "Reginald Ticket 2"]
actual = Zendex.Search.query(conn,
%{type: "ticket", requester: "Reginald"},
diff --git a/test/zendex/ticket_test.exs b/test/zendex/ticket_test.exs
index c4250d1..2b5a3ce 100644
--- a/test/zendex/ticket_test.exs
+++ b/test/zendex/ticket_test.exs
@@ -2,9 +2,7 @@ defmodule Zendex.TicketTest do
use ExUnit.Case, async: false
setup do
- %{conn: Zendex.Connection.setup("http://test.zendesk.com",
- "User",
- "Password123!")}
+ %{conn: Zendex.Connection.setup("http://test.zendesk.com", "User", "Passw")}
end
setup_all do
@@ -14,25 +12,27 @@ defmodule Zendex.TicketTest do
end
test "getting tickets", %{conn: conn} do
- stub = fn("http://test.zendesk.com/api/v2/tickets.json",
- [{"Authorization", "Basic VXNlcjpQYXNzd29yZDEyMyE="}]) ->
- %HTTPoison.Response{body: Poison.encode!("ticket")}
+ expected = "ticket"
+
+ stub = fn("http://test.zendesk.com/api/v2/tickets.json", _headers) ->
+ %HTTPoison.Response{body: Poison.encode!(expected)}
end
:meck.expect(HTTPoison, :get!, stub)
- assert "ticket" == Zendex.Ticket.list(conn)
+ assert expected == Zendex.Ticket.list(conn)
end
test "creating a ticket", %{conn: conn} do
+ expected = "Ticket created successfully!"
+
stub = fn("http://test.zendesk.com/api/v2/tickets.json",
"{\"ticket\":{\"title\":\"HELP!\"}}",
- [{"Authorization", "Basic VXNlcjpQYXNzd29yZDEyMyE="},
- {"Content-Type", "application/json"}]) ->
- %HTTPoison.Response{body: Poison.encode!("Ticket created successfully!")}
+ _headers) ->
+ %HTTPoison.Response{body: Poison.encode!(expected)}
end
:meck.expect(HTTPoison, :post!, stub)
- assert "Ticket created successfully!" ==
+ assert expected ==
Zendex.Ticket.create(conn, %{"ticket": %{"title": "HELP!"}})
end
end
diff --git a/test/zendex/user_test.exs b/test/zendex/user_test.exs
index 5d07c73..a1cee50 100644
--- a/test/zendex/user_test.exs
+++ b/test/zendex/user_test.exs
@@ -4,7 +4,7 @@ defmodule Zendex.UserTest do
@base_url "http://test.zendesk.com"
setup do
- [conn: Zendex.Connection.setup(@base_url, "User1", "pass")]
+ %{conn: Zendex.Connection.setup("http://test.zendesk.com", "User", "Passw")}
end
setup_all do
@@ -13,7 +13,7 @@ defmodule Zendex.UserTest do
:ok
end
- test "list users", context do
+ test "list users", %{conn: conn} do
expected = "users"
stub = fn("#{@base_url}/api/v2/users.json", _) ->
@@ -21,12 +21,12 @@ defmodule Zendex.UserTest do
end
:meck.expect(HTTPoison, :get!, stub)
- actual = Zendex.User.list(context[:conn])
+ actual = Zendex.User.list(conn)
assert expected == actual
end
- test "showing a user", context do
+ test "showing a user", %{conn: conn} do
expected = %{"user" => %{"ticket_restriction" => nil,
"chat_only" => false,
"shared_phone_number" => nil,
@@ -67,12 +67,12 @@ defmodule Zendex.UserTest do
end
:meck.expect(HTTPoison, :get!, stub)
- actual = Zendex.User.show(context[:conn], 295204)
+ actual = Zendex.User.show(conn, 295204)
assert expected == actual
end
- test "showing many users", context do
+ test "showing many users", %{conn: conn} do
expected = %{"users" => [%{"id" => 6, "name" => "Kiki Segal"},
%{"id" => 67, "name" => "Sarpedon Baumgartner"}]}
@@ -81,12 +81,12 @@ defmodule Zendex.UserTest do
end
:meck.expect(HTTPoison, :get!, stub)
- actual = Zendex.User.show_many(context[:conn], [6,67])
+ actual = Zendex.User.show_many(conn, [6,67])
assert expected == actual
end
- test "getting related info on a user", context do
+ test "getting related info on a user", %{conn: conn} do
expected = %{"user_related" => %{"assigned_tickets" => 12,
"ccd_tickets" => 5,
"entry_subscriptions" => 1,
@@ -103,12 +103,12 @@ defmodule Zendex.UserTest do
end
:meck.expect(HTTPoison, :get!, stub)
- actual = Zendex.User.related_information(context[:conn], 649267)
+ actual = Zendex.User.related_information(conn, 649267)
assert expected == actual
end
- test "creating a user", context do
+ test "creating a user", %{conn: conn} do
expected = %{"user" => %{"id" => 1234, "name" => "Roger", "email" => "roger@dodger.com"}}
stub = fn("#{@base_url}/api/v2/users.json", _, _) ->
@@ -117,12 +117,12 @@ defmodule Zendex.UserTest do
:meck.expect(HTTPoison, :post!, stub)
- actual = Zendex.User.create(context[:conn], %{user: %{name: "Roger", email: "roger@dodger.com"}})
+ actual = Zendex.User.create(conn, %{user: %{name: "Roger", email: "roger@dodger.com"}})
assert expected == actual
end
- test "deleting a user", context do
+ test "deleting a user", %{conn: conn} do
expected = %{"user" => %{"ticket_restriction" => nil,
"chat_only" => false,
"shared_phone_number" => nil,
@@ -163,7 +163,7 @@ defmodule Zendex.UserTest do
end
:meck.expect(HTTPoison, :delete!, stub)
- actual = Zendex.User.delete(context[:conn], 49043)
+ actual = Zendex.User.delete(conn, 49043)
assert expected == actual
end