aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkballou <kballou@devnulllabs.io>2016-11-10 17:33:43 (GMT)
committerkballou <kballou@devnulllabs.io>2016-11-13 23:31:23 (GMT)
commitc80d83ebbe2967574d6ffb1e44b38ecd8802bb80 (patch)
treeb5531f8e19a11169d12358fab4ea29d8f1f7d186
parent01b8203e4d97d08a6462c29bac8fccd11ee8fb97 (diff)
downloadzendex-c80d83ebbe2967574d6ffb1e44b38ecd8802bb80.tar.gz
zendex-c80d83ebbe2967574d6ffb1e44b38ecd8802bb80.tar.xz
refactor tests: use pattern matching for context
Since the `context` passed from the setup function is a map, we can match for it in the test cases.
-rw-r--r--test/zendex/search_test.exs13
-rw-r--r--test/zendex/ticket_test.exs12
-rw-r--r--test/zendex/user_test.exs28
3 files changed, 29 insertions, 24 deletions
diff --git a/test/zendex/search_test.exs b/test/zendex/search_test.exs
index a7102b6..b2276b7 100644
--- a/test/zendex/search_test.exs
+++ b/test/zendex/search_test.exs
@@ -1,23 +1,24 @@
defmodule Zendex.SearchTest do
use ExUnit.Case, async: true
+ alias Zendex.Connection
+
setup do
- [conn: Zendex.Connection.setup("http://test.zendesk.com", "User", "Passw")]
+ {:ok, conn: Connection.setup("http://test.zendesk.com", "User", "Passw")}
end
- test "doing a search", context do
+ test "doing a search", %{conn: conn} do
expected = ["Jimbob Ticket 1", "Jimbob Ticket 2"]
- actual = Zendex.Search.query(context[:conn],
- %{type: "ticket", requester: "Jimbob"})
+ actual = Zendex.Search.query(conn, %{type: "ticket", requester: "Jimbob"})
assert actual == expected
end
- test "doing a search with sorting", context do
+ test "doing a search with sorting", %{conn: conn} do
expected = ["Reginald Ticket 1", "Reginald Ticket 2"]
- actual = Zendex.Search.query(context[:conn],
+ actual = Zendex.Search.query(conn,
%{type: "ticket", requester: "Reginald"},
"created_at",
"desc")
diff --git a/test/zendex/ticket_test.exs b/test/zendex/ticket_test.exs
index 6bc4436..485e897 100644
--- a/test/zendex/ticket_test.exs
+++ b/test/zendex/ticket_test.exs
@@ -1,16 +1,18 @@
defmodule Zendex.TicketTest do
use ExUnit.Case, async: true
+ alias Zendex.Connection
+
setup do
- [conn: Zendex.Connection.setup("http://test.zendesk.com", "User", "Passw")]
+ {:ok, conn: Connection.setup("http://test.zendesk.com", "User", "Passw")}
end
- test "getting tickets", context do
- assert "ticket" == Zendex.Ticket.list(context[:conn])
+ test "getting tickets", %{conn: conn} do
+ assert "ticket" == Zendex.Ticket.list(conn)
end
- test "creating a ticket", context do
+ test "creating a ticket", %{conn: conn} do
assert "Ticket created successfully!" ==
- Zendex.Ticket.create(context[:conn], %{"ticket": %{}})
+ Zendex.Ticket.create(conn, %{"ticket": %{}})
end
end
diff --git a/test/zendex/user_test.exs b/test/zendex/user_test.exs
index f260f62..e86dc2c 100644
--- a/test/zendex/user_test.exs
+++ b/test/zendex/user_test.exs
@@ -3,18 +3,20 @@ defmodule Zendex.UserTest do
doctest Zendex.User
+ alias Zendex.Connection
+
setup do
- [conn: Zendex.Connection.setup("http://test.zendesk.com", "User1", "pass")]
+ {:ok, conn: Connection.setup("https://test.zendesk.com", "User1", "pass")}
end
- test "list users", context do
+ test "list users", %{conn: conn} do
expected = "users"
- 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,
@@ -49,20 +51,20 @@ defmodule Zendex.UserTest do
"user_fields" => %{"customer_complaint" => nil},
"tags" => [],
"updated_at" => "2016-10-28T21:08:23Z"}}
- 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"}]}
- 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,
@@ -73,17 +75,17 @@ defmodule Zendex.UserTest do
"topic_comments" => 116,
"topics" => 5,
"votes" => 2001}}
- actual = Zendex.User.related_information(context[:conn], 649267)
+ actual = Zendex.User.related_information(conn, 649267)
end
- test "creating a user", context do
+ test "creating a user", %{conn: conn} do
expected = %{"user" => %{"id" => 1234, "name" => "Roger", "email" => "roger@dodger.com"}}
- 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,
@@ -118,7 +120,7 @@ defmodule Zendex.UserTest do
"user_fields" => %{"customer_complaint" => nil},
"tags" => [],
"updated_at" => "2016-10-28T21:08:23Z"}}
- actual = Zendex.User.delete(context[:conn], 49043)
+ actual = Zendex.User.delete(conn, 49043)
assert expected == actual
end