aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkballou <kballou@devnulllabs.io>2016-11-13 01:14:24 (GMT)
committerkballou <kballou@devnulllabs.io>2016-11-14 18:19:49 (GMT)
commit141547d8440b024a240654960b8f3f55a31d8ede (patch)
tree1b3bfa811c68c6f7fa1c557b31ffdc9e6804e30f
parent011abb47be01bce1bce599e0c265c079fa55fe86 (diff)
downloadzendex-add_streaming.tar.gz
zendex-add_streaming.tar.xz
refactoring to use new Zendex HTTPoison Clientadd_streaming
This change also replaces the tests that were using the "in-memory" client with `exvcr` cassettes based tests. This does increase test time by about a second, but the overall improvement in not having to maintain a separate module for testing is nice. Mocking request/response pairs is, however, slightly tedious.
-rw-r--r--config/config.exs2
-rw-r--r--config/test.exs2
-rw-r--r--lib/http_client/in_memory.ex138
-rw-r--r--lib/zendex.ex19
-rw-r--r--lib/zendex/common_helpers.ex15
-rw-r--r--lib/zendex/search.ex10
-rw-r--r--lib/zendex/ticket.ex21
-rw-r--r--lib/zendex/user.ex148
-rw-r--r--test/fixtures/vcr_cassettes/search/search_tickets.json36
-rw-r--r--test/fixtures/vcr_cassettes/search/search_tickets_sorting.json37
-rw-r--r--test/fixtures/vcr_cassettes/tickets/create_ticket.json36
-rw-r--r--test/fixtures/vcr_cassettes/tickets/list_tickets.json36
-rw-r--r--test/fixtures/vcr_cassettes/tickets/list_tickets_pagination.json70
-rw-r--r--test/fixtures/vcr_cassettes/users/create_user.json36
-rw-r--r--test/fixtures/vcr_cassettes/users/delete_user.json36
-rw-r--r--test/fixtures/vcr_cassettes/users/list_users.json36
-rw-r--r--test/fixtures/vcr_cassettes/users/related_information.json36
-rw-r--r--test/fixtures/vcr_cassettes/users/show_many_users.json36
-rw-r--r--test/fixtures/vcr_cassettes/users/show_user.json36
-rw-r--r--test/zendex/search_test.exs54
-rw-r--r--test/zendex/ticket_test.exs64
-rw-r--r--test/zendex/user_test.exs55
22 files changed, 606 insertions, 353 deletions
diff --git a/config/config.exs b/config/config.exs
index dd0aa56..c9c59bb 100644
--- a/config/config.exs
+++ b/config/config.exs
@@ -1,5 +1,3 @@
use Mix.Config
-config :zendex, :http_client, HTTPoison
-
import_config "#{Mix.env}.exs"
diff --git a/config/test.exs b/config/test.exs
index b2a3ed8..d2d855e 100644
--- a/config/test.exs
+++ b/config/test.exs
@@ -1,3 +1 @@
use Mix.Config
-
-config :zendex, :http_client, Zendex.HttpClient.InMemory
diff --git a/lib/http_client/in_memory.ex b/lib/http_client/in_memory.ex
deleted file mode 100644
index 4c43211..0000000
--- a/lib/http_client/in_memory.ex
+++ /dev/null
@@ -1,138 +0,0 @@
-defmodule Zendex.HttpClient.InMemory do
- @moduledoc """
- Allows testing of the Zendex project by mocking out calls to an actual Zendesk
- API.
- """
-
- @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"])
- end
-
- def get!(@base_url <> "/api/v2/search.json?query=requester%3AReginald+type%3Aticket&sort_by=created_at&sort_order=desc",
- [{"Authorization", _authentication}]) do
- fake_response(["Reginald Ticket 1", "Reginald Ticket 2"])
- end
-
- def get!(@base_url <> "/api/v2/users.json",
- [{"Authorization", _authentication}]) do
- fake_response("users")
- end
-
- def get!("#{@base_url}/api/v2/users/295204.json",
- [{"Authorization", _authentication}]) do
- fake_response(%{"user" => %{"ticket_restriction" => nil,
- "chat_only" => false,
- "shared_phone_number" => nil,
- "notes" => "",
- "phone" => nil,
- "organization_id" => 11129520411,
- "last_login_at" => "2016-10-28T21:08:23Z",
- "moderator" => true,
- "shared" => false,
- "id" => 295204,
- "role" => "admin",
- "external_id" => nil,
- "shared_agent" => false,
- "photo" => nil,
- "verified" => true,
- "active" => true,
- "locale_id" => 1,
- "suspended" => false,
- "created_at" => "2015-05-28T09:12:45Z",
- "name" => "Nikolao Aikema",
- "restricted_agent" => false,
- "locale" => "en-US",
- "details" => "",
- "alias" => nil,
- "url" => "https://test.zendesk.com/api/v2/users/295204.json",
- "custom_role_id" => nil,
- "email" => "nikolao.aikema@test.com",
- "signature" => nil,
- "two_factor_auth_enabled" => nil,
- "time_zone" => "London",
- "only_private_comments" => false,
- "user_fields" => %{"customer_complaint" => nil},
- "tags" => [],
- "updated_at" => "2016-10-28T21:08:23Z"}})
- end
-
- def get!("#{@base_url}/api/v2/users/show_many.json?ids=6,67",
- [{"Authorization", _authentication}]) do
- fake_response(%{users: [%{id: 6, name: "Kiki Segal"},
- %{id: 67, name: "Sarpedon Baumgartner"}]})
- end
-
- def get!("#{@base_url}/api/v2/users/649267/related.json",
- [{"Authorization", _authentication}]) do
- fake_response(%{"user_related" => %{"assigned_tickets" => 12,
- "ccd_tickets" => 5,
- "entry_subscriptions" => 1,
- "forum_subscriptions" => 3,
- "organization_subscriptions" => 1,
- "requested_tickets" => 7,
- "subscriptions" => 6,
- "topic_comments" => 116,
- "topics" => 5,
- "votes" => 2001}})
- 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
- fake_response(%{user: %{id: 1234, name: "Roger", email: "roger@dodger.com"}})
- end
-
- def delete!("#{@base_url}/api/v2/users/49043.json",
- [{"Authorization", _authentication}]) do
- fake_response(%{"user" => %{"ticket_restriction" => nil,
- "chat_only" => false,
- "shared_phone_number" => nil,
- "notes" => "",
- "phone" => nil,
- "organization_id" => 149043,
- "last_login_at" => "2016-10-28T21:08:23Z",
- "moderator" => true,
- "shared" => false,
- "id" => 49043,
- "role" => "admin",
- "external_id" => nil,
- "shared_agent" => false,
- "photo" => nil,
- "verified" => true,
- "active" => false,
- "locale_id" => 1,
- "suspended" => false,
- "created_at" => "2015-05-28T09:12:45Z",
- "name" => "Rian Hawkins",
- "restricted_agent" => false,
- "locale" => "en-US",
- "details" => "",
- "alias" => nil,
- "url" => "https://test.zendesk.com/api/v2/users/49043.json",
- "custom_role_id" => nil,
- "email" => "rian.hawkins@test.com",
- "signature" => nil,
- "two_factor_auth_enabled" => nil,
- "time_zone" => "London",
- "only_private_comments" => false,
- "user_fields" => %{"customer_complaint" => nil},
- "tags" => [],
- "updated_at" => "2016-10-28T21:08:23Z"}})
- end
-
- defp fake_response(body), do: %{body: Poison.encode!(body)}
-end
diff --git a/lib/zendex.ex b/lib/zendex.ex
index 2fbde39..e697d8b 100644
--- a/lib/zendex.ex
+++ b/lib/zendex.ex
@@ -38,15 +38,6 @@ defmodule Zendex do
resp
end
- def patch(path, connection, body \\ "") do
- _request(:patch, url(connection, path), connection.authentication, body)
- end
-
- def patch!(path, connection, body \\ "") do
- {_, resp} = patch(path, connection, body)
- resp
- end
-
@doc """
Underlying utility retrieval function
@@ -66,8 +57,14 @@ defmodule Zendex do
{auth, _} = Map.split(connection, [:authentication])
case pagination(options) do
- nil -> request_stream(:get, url, auth, "", :one_page)
- :none -> request_stream(:get, url, auth, "", :one_page)
+ nil ->
+ :get
+ |> request_stream(url, auth, "", :one_page)
+ |> realize_if_needed
+ :none ->
+ :get
+ |> request_stream(url, auth, "", :one_page)
+ |> realize_if_needed
:auto ->
:get
|> request_stream(url, auth)
diff --git a/lib/zendex/common_helpers.ex b/lib/zendex/common_helpers.ex
deleted file mode 100644
index dceb56d..0000000
--- a/lib/zendex/common_helpers.ex
+++ /dev/null
@@ -1,15 +0,0 @@
-defmodule Zendex.CommonHelpers do
- @moduledoc """
- Contains common helper functions used throughout Zendex.
- """
-
- def decode_response(%{body: body}), do: Poison.decode!(body)
-
- def get_headers(authentication) do
- [{"Authorization", "Basic #{authentication}"}]
- end
-
- def get_headers(authentication, %{content_type: :json}) do
- get_headers(authentication) ++ [{"Content-Type", "application/json"}]
- end
-end
diff --git a/lib/zendex/search.ex b/lib/zendex/search.ex
index ec9ea28..dc4909b 100644
--- a/lib/zendex/search.ex
+++ b/lib/zendex/search.ex
@@ -3,23 +3,19 @@ defmodule Zendex.Search do
Allows use of the Zendex search API functionality.
"""
- alias Zendex.CommonHelpers
-
@url "/api/v2/search.json?query="
- @http_client Application.get_env(:zendex, :http_client)
@doc """
Search Zendesk.
"""
- @spec query(Zendex.Connection.t, map, String.t, String.t) :: map
+ @spec query(Zendex.Connection.t, map, String.t, String.t) :: no_return
def query(connection, query, sort_by \\ "", sort_order \\ "desc") do
search_string = create_search_string(query)
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))
- |> CommonHelpers.decode_response
+ "#{@url}#{search_string}#{sort_string}"
+ |> Zendex.get!(connection)
end
defp create_search_string(query) do
diff --git a/lib/zendex/ticket.ex b/lib/zendex/ticket.ex
index 9232d6e..9df77df 100644
--- a/lib/zendex/ticket.ex
+++ b/lib/zendex/ticket.ex
@@ -4,30 +4,23 @@ defmodule Zendex.Ticket do
and listing tickets.
"""
- alias Zendex.CommonHelpers
-
@url "/api/v2/tickets.json"
- @http_client Application.get_env(:zendex, :http_client)
@doc """
List all tickets.
"""
- @spec list(Zendex.Connection.t) :: map
- def list(connection) do
- "#{connection.base_url}#{@url}"
- |> @http_client.get!(CommonHelpers.get_headers(connection.authentication))
- |> CommonHelpers.decode_response
+ @spec list(Zendex.Connection.t, Keyword.t) :: [any] | {integer, any}
+ def list(connection, opts \\ []) do
+ "#{@url}"
+ |> Zendex.get!(connection, [], opts)
end
@doc """
Create a new ticket.
"""
- @spec create(Zendex.Connection.t, map) :: map
+ @spec create(Zendex.Connection.t, map) :: any
def create(connection, ticket) do
- "#{connection.base_url}#{@url}"
- |> @http_client.post!(Poison.encode!(ticket),
- CommonHelpers.get_headers(connection.authentication,
- %{content_type: :json}))
- |> CommonHelpers.decode_response
+ "#{@url}"
+ |> Zendex.post!(connection, Poison.encode!(ticket))
end
end
diff --git a/lib/zendex/user.ex b/lib/zendex/user.ex
index 9112b7f..a36f626 100644
--- a/lib/zendex/user.ex
+++ b/lib/zendex/user.ex
@@ -3,173 +3,61 @@ defmodule Zendex.User do
Interact with Zendesk user.
"""
- alias Zendex.CommonHelpers
-
@url "/api/v2/users"
- @http_client Application.get_env(:zendex, :http_client)
@doc """
List all users.
"""
- @spec list(Zendex.Connection.t) :: map
- def list(connection) do
- "#{connection.base_url}#{@url}.json"
- |> @http_client.get!(CommonHelpers.get_headers(connection.authentication))
- |> CommonHelpers.decode_response
+ @spec list(Zendex.Connection.t, Keyword.t) :: map | [map]
+ def list(connection, opts \\ []) do
+ "#{@url}.json"
+ |> Zendex.get!(connection, [], opts)
end
@doc """
Show a specific user, given their id.
-
- ## Examples
-
- iex> conn = Zendex.Connection.setup("http://test.zendesk.com", "ZendeskUser", "Password1")
- %{authentication: "WmVuZGVza1VzZXI6UGFzc3dvcmQx", base_url: "http://test.zendesk.com"}
- iex> Zendex.User.show(conn, 295204)
- %{"user" => %{"ticket_restriction" => nil,
- "chat_only" => false,
- "shared_phone_number" => nil,
- "notes" => "",
- "phone" => nil,
- "organization_id" => 11129520411,
- "last_login_at" => "2016-10-28T21:08:23Z",
- "moderator" => true,
- "shared" => false,
- "id" => 295204,
- "role" => "admin",
- "external_id" => nil,
- "shared_agent" => false,
- "photo" => nil,
- "verified" => true,
- "active" => true,
- "locale_id" => 1,
- "suspended" => false,
- "created_at" => "2015-05-28T09:12:45Z",
- "name" => "Nikolao Aikema",
- "restricted_agent" => false,
- "locale" => "en-US",
- "details" => "",
- "alias" => nil,
- "url" => "https://test.zendesk.com/api/v2/users/295204.json",
- "custom_role_id" => nil,
- "email" => "nikolao.aikema@test.com",
- "signature" => nil,
- "two_factor_auth_enabled" => nil,
- "time_zone" => "London",
- "only_private_comments" => false,
- "user_fields" => %{"customer_complaint" => nil},
- "tags" => [],
- "updated_at" => "2016-10-28T21:08:23Z"}}
-
"""
@spec show(Zendex.Connection.t, integer) :: map
def show(connection, id) do
- "#{connection.base_url}#{@url}/#{id}.json"
- |> @http_client.get!(CommonHelpers.get_headers(connection.authentication))
- |> CommonHelpers.decode_response
+ "#{@url}/#{id}.json"
+ |> Zendex.get!(connection)
end
@doc """
Show many user, given their ids.
"""
- @spec show_many(Zendex.Connection.t, [integer]) :: map
+ @spec show_many(Zendex.Connection.t, [integer]) :: no_return
def show_many(connection, ids) do
ids = Enum.join(ids, ",")
-
- "#{connection.base_url}#{@url}/show_many.json?ids=#{ids}"
- |> @http_client.get!(CommonHelpers.get_headers(connection.authentication))
- |> CommonHelpers.decode_response
+ "#{@url}/show_many.json?ids=#{ids}"
+ |> Zendex.get!(connection)
end
@doc """
Show information relating to the user, example: number of assigned tickets.
-
- ## Examples
-
- iex> conn = Zendex.Connection.setup("http://test.zendesk.com", "ZendeskUser", "Password1")
- %{authentication: "WmVuZGVza1VzZXI6UGFzc3dvcmQx", base_url: "http://test.zendesk.com"}
- iex> Zendex.User.related_information(conn, 649267)
- %{"user_related" => %{"assigned_tickets" => 12,
- "ccd_tickets" => 5,
- "entry_subscriptions" => 1,
- "forum_subscriptions" => 3,
- "organization_subscriptions" => 1,
- "requested_tickets" => 7,
- "subscriptions" => 6,
- "topic_comments" => 116,
- "topics" => 5,
- "votes" => 2001}}
-
"""
- @spec related_information(Zendex.Connection.t, integer) :: map
+ @spec related_information(Zendex.Connection.t, integer) :: no_return
def related_information(connection, id) do
- "#{connection.base_url}#{@url}/#{id}/related.json"
- |> @http_client.get!(CommonHelpers.get_headers(connection.authentication))
- |> CommonHelpers.decode_response
+ "#{@url}/#{id}/related.json"
+ |> Zendex.get!(connection)
end
@doc """
Create a new user.
"""
- @spec create(Zendex.Connection.t, map) :: map
+ @spec create(Zendex.Connection.t, map) :: any
def create(connection, user) do
- "#{connection.base_url}#{@url}.json"
- |> @http_client.post!(Poison.encode!(user),
- CommonHelpers.get_headers(connection.authentication,
- %{content_type: :json}))
- |> CommonHelpers.decode_response
+ "#{@url}.json"
+ |> Zendex.post!(connection, Poison.encode!(user))
end
@doc """
Delete a user.
-
- ## Examples
-
- iex> conn = Zendex.Connection.setup("http://test.zendesk.com", "ZendeskUser", "Password1")
- %{authentication: "WmVuZGVza1VzZXI6UGFzc3dvcmQx", base_url: "http://test.zendesk.com"}
- iex> Zendex.User.delete(conn, 49043)
- %{"user" => %{"ticket_restriction" => nil,
- "chat_only" => false,
- "shared_phone_number" => nil,
- "notes" => "",
- "phone" => nil,
- "organization_id" => 149043,
- "last_login_at" => "2016-10-28T21:08:23Z",
- "moderator" => true,
- "shared" => false,
- "id" => 49043,
- "role" => "admin",
- "external_id" => nil,
- "shared_agent" => false,
- "photo" => nil,
- "verified" => true,
- "active" => false,
- "locale_id" => 1,
- "suspended" => false,
- "created_at" => "2015-05-28T09:12:45Z",
- "name" => "Rian Hawkins",
- "restricted_agent" => false,
- "locale" => "en-US",
- "details" => "",
- "alias" => nil,
- "url" => "https://test.zendesk.com/api/v2/users/49043.json",
- "custom_role_id" => nil,
- "email" => "rian.hawkins@test.com",
- "signature" => nil,
- "two_factor_auth_enabled" => nil,
- "time_zone" => "London",
- "only_private_comments" => false,
- "user_fields" => %{"customer_complaint" => nil},
- "tags" => [],
- "updated_at" => "2016-10-28T21:08:23Z"}}
-
-
"""
- @spec show(Zendex.Connection.t, integer) :: map
+ @spec delete(Zendex.Connection.t, integer) :: {integer, map} | map
def delete(connection, id) do
- "#{connection.base_url}#{@url}/#{id}.json"
- |> @http_client.delete!(CommonHelpers.get_headers(connection.authentication))
- |> CommonHelpers.decode_response
+ "#{@url}/#{id}.json"
+ |> Zendex.delete!(connection)
end
end
diff --git a/test/fixtures/vcr_cassettes/search/search_tickets.json b/test/fixtures/vcr_cassettes/search/search_tickets.json
new file mode 100644
index 0000000..cf3dd07
--- /dev/null
+++ b/test/fixtures/vcr_cassettes/search/search_tickets.json
@@ -0,0 +1,36 @@
+[
+ {
+ "request": {
+ "body": "\"\\\"\\\"\"",
+ "headers": {
+ "user-agent": "zendex",
+ "Authorization": "Basic VXNlcjE6cGFzcw=="
+ },
+ "method": "get",
+ "options": [],
+ "request_body": "",
+ "url": "https://test.zendesk.com/api/v2/search.json?query=requester%3AJimbob+type%3Aticket"
+ },
+ "response": {
+ "body": "{\"results\":[{\"id\":1,\"description\":\"Jimbob Ticket 1\"},{\"id\":2,\"description\":\"Jimbob Ticket 2\"}],\"previous_page\":null,\"next_page\":null,\"facets\":null,\"count\":2}",
+ "headers": {
+ "Server": "nginx",
+ "Date": "Fri, 11 Nov 2016 22:02:31 GMT",
+ "Content-Type": "application/json; charset=UTF-8",
+ "Content-Length": "37",
+ "Connection": "keep-alive",
+ "Cache-Control": "private",
+ "WWW-Authenticate": "Basic realm=\"Web Password\"",
+ "Strict-Transport-Security": "max-age=31536000;",
+ "X-UA-Compatible": "IE=Edge,chrome=1",
+ "X-Zendesk-Origin-Server": "app20.pod3.dub1.zdsys.com",
+ "X-Request-Id": "55485721-bf68-44d1-c44b-b8ca3a6bdb18",
+ "X-Runtime": "0.097079",
+ "X-Rack-Cache": "miss",
+ "X-Zendesk-Request-Id": "0c2d369029535cc8a910"
+ },
+ "status_code": 200,
+ "type": "ok"
+ }
+ }
+]
diff --git a/test/fixtures/vcr_cassettes/search/search_tickets_sorting.json b/test/fixtures/vcr_cassettes/search/search_tickets_sorting.json
new file mode 100644
index 0000000..f011b98
--- /dev/null
+++ b/test/fixtures/vcr_cassettes/search/search_tickets_sorting.json
@@ -0,0 +1,37 @@
+
+[
+ {
+ "request": {
+ "body": "\"\\\"\\\"\"",
+ "headers": {
+ "user-agent": "zendex",
+ "Authorization": "Basic VXNlcjE6cGFzcw=="
+ },
+ "method": "get",
+ "options": [],
+ "request_body": "",
+ "url": "https://test.zendesk.com/api/v2/search.json?query=requester%3AReginald+type%3Aticket&sort_by=created_at&sort_order=desc"
+ },
+ "response": {
+ "body": "{\"results\":[{\"id\":1,\"description\":\"Reginald Ticket 1\"},{\"id\":2,\"description\":\"Reginald Ticket 2\"}],\"previous_page\":null,\"next_page\":null,\"facets\":null,\"count\":2}",
+ "headers": {
+ "Server": "nginx",
+ "Date": "Fri, 11 Nov 2016 22:02:31 GMT",
+ "Content-Type": "application/json; charset=UTF-8",
+ "Content-Length": "37",
+ "Connection": "keep-alive",
+ "Cache-Control": "private",
+ "WWW-Authenticate": "Basic realm=\"Web Password\"",
+ "Strict-Transport-Security": "max-age=31536000;",
+ "X-UA-Compatible": "IE=Edge,chrome=1",
+ "X-Zendesk-Origin-Server": "app20.pod3.dub1.zdsys.com",
+ "X-Request-Id": "55485721-bf68-44d1-c44b-b8ca3a6bdb18",
+ "X-Runtime": "0.097079",
+ "X-Rack-Cache": "miss",
+ "X-Zendesk-Request-Id": "0c2d369029535cc8a910"
+ },
+ "status_code": 200,
+ "type": "ok"
+ }
+ }
+]
diff --git a/test/fixtures/vcr_cassettes/tickets/create_ticket.json b/test/fixtures/vcr_cassettes/tickets/create_ticket.json
new file mode 100644
index 0000000..361a4e3
--- /dev/null
+++ b/test/fixtures/vcr_cassettes/tickets/create_ticket.json
@@ -0,0 +1,36 @@
+[
+ {
+ "request": {
+ "body": "{\"ticket\":{\"description\":\"My printer is on fire!\"}}",
+ "headers": {
+ "user-agent": "zendex",
+ "Authorization": "Basic VXNlcjE6cGFzcw=="
+ },
+ "method": "post",
+ "options": [],
+ "request_body": "",
+ "url": "https://test.zendesk.com/api/v2/tickets.json"
+ },
+ "response": {
+ "body": "{\"ticket\":{\"id\":1234,\"description\":\"My printer is on fire!\"}}",
+ "headers": {
+ "Server": "nginx",
+ "Date": "Fri, 11 Nov 2016 22:02:31 GMT",
+ "Content-Type": "application/json; charset=UTF-8",
+ "Content-Length": "37",
+ "Connection": "keep-alive",
+ "Cache-Control": "private",
+ "WWW-Authenticate": "Basic realm=\"Web Password\"",
+ "Strict-Transport-Security": "max-age=31536000;",
+ "X-UA-Compatible": "IE=Edge,chrome=1",
+ "X-Zendesk-Origin-Server": "app20.pod3.dub1.zdsys.com",
+ "X-Request-Id": "55485721-bf68-44d1-c44b-b8ca3a6bdb18",
+ "X-Runtime": "0.097079",
+ "X-Rack-Cache": "miss",
+ "X-Zendesk-Request-Id": "0c2d369029535cc8a910"
+ },
+ "status_code": 201,
+ "type": "ok"
+ }
+ }
+]
diff --git a/test/fixtures/vcr_cassettes/tickets/list_tickets.json b/test/fixtures/vcr_cassettes/tickets/list_tickets.json
new file mode 100644
index 0000000..99ff764
--- /dev/null
+++ b/test/fixtures/vcr_cassettes/tickets/list_tickets.json
@@ -0,0 +1,36 @@
+[
+ {
+ "request": {
+ "body": "\"\\\"\\\"\"",
+ "headers": {
+ "user-agent": "zendex",
+ "Authorization": "Basic VXNlcjE6cGFzcw=="
+ },
+ "method": "get",
+ "options": [],
+ "request_body": "",
+ "url": "https://test.zendesk.com/api/v2/tickets.json"
+ },
+ "response": {
+ "body": "{\"tickets\":[{\"id\":1},{\"id\":2},{\"id\":3},{\"id\":4}],\"previous_page\":null,\"next_page\":null,\"count\":4}",
+ "headers": {
+ "Server": "nginx",
+ "Date": "Fri, 11 Nov 2016 22:02:31 GMT",
+ "Content-Type": "application/json; charset=UTF-8",
+ "Content-Length": "37",
+ "Connection": "keep-alive",
+ "Cache-Control": "private",
+ "WWW-Authenticate": "Basic realm=\"Web Password\"",
+ "Strict-Transport-Security": "max-age=31536000;",
+ "X-UA-Compatible": "IE=Edge,chrome=1",
+ "X-Zendesk-Origin-Server": "app20.pod3.dub1.zdsys.com",
+ "X-Request-Id": "55485721-bf68-44d1-c44b-b8ca3a6bdb18",
+ "X-Runtime": "0.097079",
+ "X-Rack-Cache": "miss",
+ "X-Zendesk-Request-Id": "0c2d369029535cc8a910"
+ },
+ "status_code": 200,
+ "type": "ok"
+ }
+ }
+]
diff --git a/test/fixtures/vcr_cassettes/tickets/list_tickets_pagination.json b/test/fixtures/vcr_cassettes/tickets/list_tickets_pagination.json
new file mode 100644
index 0000000..6138796
--- /dev/null
+++ b/test/fixtures/vcr_cassettes/tickets/list_tickets_pagination.json
@@ -0,0 +1,70 @@
+[
+ {
+ "request": {
+ "body": "\"\\\"\\\"\"",
+ "headers": {
+ "user-agent": "zendex",
+ "Authorization": "Basic VXNlcjE6cGFzcw=="
+ },
+ "method": "get",
+ "options": [],
+ "request_body": "",
+ "url": "https://test.zendesk.com/api/v2/tickets.json"
+ },
+ "response": {
+ "body": "{\"tickets\":[{\"id\":1},{\"id\":2}],\"previous_page\":null,\"next_page\":\"https://test.zendesk.com/api/v2/tickets.json?page=2\",\"count\":4}",
+ "headers": {
+ "Server": "nginx",
+ "Date": "Fri, 11 Nov 2016 22:02:31 GMT",
+ "Content-Type": "application/json; charset=UTF-8",
+ "Content-Length": "37",
+ "Connection": "keep-alive",
+ "Cache-Control": "private",
+ "WWW-Authenticate": "Basic realm=\"Web Password\"",
+ "Strict-Transport-Security": "max-age=31536000;",
+ "X-UA-Compatible": "IE=Edge,chrome=1",
+ "X-Zendesk-Origin-Server": "app20.pod3.dub1.zdsys.com",
+ "X-Request-Id": "55485721-bf68-44d1-c44b-b8ca3a6bdb18",
+ "X-Runtime": "0.097079",
+ "X-Rack-Cache": "miss",
+ "X-Zendesk-Request-Id": "0c2d369029535cc8a910"
+ },
+ "status_code": 200,
+ "type": "ok"
+ }
+ },
+ {
+ "request": {
+ "body": "\"\\\"\\\"\"",
+ "headers": {
+ "user-agent": "zendex",
+ "Authorization": "Basic VXNlcjE6cGFzcw=="
+ },
+ "method": "get",
+ "options": [],
+ "request_body": "",
+ "url": "https://test.zendesk.com/api/v2/tickets.json?page=2"
+ },
+ "response": {
+ "body": "{\"tickets\":[{\"id\":3},{\"id\":4}],\"previous_page\":\"https://test.zendesk.com/api/v2/tickets.json?page=1\",\"next_page\":null,\"count\":4}",
+ "headers": {
+ "Server": "nginx",
+ "Date": "Fri, 11 Nov 2016 22:02:31 GMT",
+ "Content-Type": "application/json; charset=UTF-8",
+ "Content-Length": "37",
+ "Connection": "keep-alive",
+ "Cache-Control": "private",
+ "WWW-Authenticate": "Basic realm=\"Web Password\"",
+ "Strict-Transport-Security": "max-age=31536000;",
+ "X-UA-Compatible": "IE=Edge,chrome=1",
+ "X-Zendesk-Origin-Server": "app20.pod3.dub1.zdsys.com",
+ "X-Request-Id": "55485721-bf68-44d1-c44b-b8ca3a6bdb18",
+ "X-Runtime": "0.097079",
+ "X-Rack-Cache": "miss",
+ "X-Zendesk-Request-Id": "0c2d369029535cc8a910"
+ },
+ "status_code": 200,
+ "type": "ok"
+ }
+ }
+]
diff --git a/test/fixtures/vcr_cassettes/users/create_user.json b/test/fixtures/vcr_cassettes/users/create_user.json
new file mode 100644
index 0000000..f5bc7da
--- /dev/null
+++ b/test/fixtures/vcr_cassettes/users/create_user.json
@@ -0,0 +1,36 @@
+[
+ {
+ "request": {
+ "body": "\"\\\"\\\"\"",
+ "headers": {
+ "user-agent": "zendex",
+ "Authorization": "Basic VXNlcjE6cGFzcw=="
+ },
+ "method": "post",
+ "options": [],
+ "request_body": "{\"user\":{\"name\":\"Roger\",\"email\":\"roger@dodger.com\"}}",
+ "url": "https://test.zendesk.com/api/v2/users.json"
+ },
+ "response": {
+ "body": "{\"user\":{\"name\":\"Roger\",\"id\":1234,\"email\":\"roger@dodger.com\"}}",
+ "headers": {
+ "Server": "nginx",
+ "Date": "Fri, 11 Nov 2016 22:02:31 GMT",
+ "Content-Type": "application/json; charset=UTF-8",
+ "Content-Length": "37",
+ "Connection": "keep-alive",
+ "Cache-Control": "private",
+ "WWW-Authenticate": "Basic realm=\"Web Password\"",
+ "Strict-Transport-Security": "max-age=31536000;",
+ "X-UA-Compatible": "IE=Edge,chrome=1",
+ "X-Zendesk-Origin-Server": "app20.pod3.dub1.zdsys.com",
+ "X-Request-Id": "55485721-bf68-44d1-c44b-b8ca3a6bdb18",
+ "X-Runtime": "0.097079",
+ "X-Rack-Cache": "miss",
+ "X-Zendesk-Request-Id": "0c2d369029535cc8a910"
+ },
+ "status_code": 201,
+ "type": "ok"
+ }
+ }
+]
diff --git a/test/fixtures/vcr_cassettes/users/delete_user.json b/test/fixtures/vcr_cassettes/users/delete_user.json
new file mode 100644
index 0000000..243465a
--- /dev/null
+++ b/test/fixtures/vcr_cassettes/users/delete_user.json
@@ -0,0 +1,36 @@
+[
+ {
+ "request": {
+ "body": "\"\\\"\\\"\"",
+ "headers": {
+ "user-agent": "zendex",
+ "Authorization": "Basic VXNlcjE6cGFzcw=="
+ },
+ "method": "delete",
+ "options": [],
+ "request_body": "",
+ "url": "https://test.zendesk.com/api/v2/users/49043.json"
+ },
+ "response": {
+ "body": "{\"user\":{\"updated_at\":\"2016-10-28T21:08:23Z\",\"tags\":[],\"user_fields\":{\"customer_complaint\":null},\"only_private_comments\":false,\"time_zone\":\"London\",\"two_factor_auth_enabled\":null,\"signature\":null,\"email\":\"rian.hawkins@test.com\",\"custom_role_id\":null,\"url\":\"https://test.zendesk.com/api/v2/users/49043.json\",\"alias\":null,\"details\":\"\",\"locale\":\"en-US\",\"restricted_agent\":false,\"name\":\"Rian Hawkins\",\"created_at\":\"2015-05-28T09:12:45Z\",\"suspended\":false,\"locale_id\":1,\"active\":false,\"verified\":true,\"photo\":null,\"shared_agent\":false,\"external_id\":null,\"role\":\"admin\",\"id\":49043,\"shared\":false,\"moderator\":true,\"last_login_at\":\"2016-10-28T21:08:23Z\",\"organization_id\":149043,\"phone\":null,\"notes\":\"\",\"shared_phone_number\":null,\"chat_only\":false,\"ticket_restriction\":null}}",
+ "headers": {
+ "Server": "nginx",
+ "Date": "Fri, 11 Nov 2016 22:02:31 GMT",
+ "Content-Type": "application/json; charset=UTF-8",
+ "Content-Length": "37",
+ "Connection": "keep-alive",
+ "Cache-Control": "private",
+ "WWW-Authenticate": "Basic realm=\"Web Password\"",
+ "Strict-Transport-Security": "max-age=31536000;",
+ "X-UA-Compatible": "IE=Edge,chrome=1",
+ "X-Zendesk-Origin-Server": "app20.pod3.dub1.zdsys.com",
+ "X-Request-Id": "55485721-bf68-44d1-c44b-b8ca3a6bdb18",
+ "X-Runtime": "0.097079",
+ "X-Rack-Cache": "miss",
+ "X-Zendesk-Request-Id": "0c2d369029535cc8a910"
+ },
+ "status_code": 200,
+ "type": "ok"
+ }
+ }
+]
diff --git a/test/fixtures/vcr_cassettes/users/list_users.json b/test/fixtures/vcr_cassettes/users/list_users.json
new file mode 100644
index 0000000..4bfd09e
--- /dev/null
+++ b/test/fixtures/vcr_cassettes/users/list_users.json
@@ -0,0 +1,36 @@
+[
+ {
+ "request": {
+ "body": "\"\\\"\\\"\"",
+ "headers": {
+ "user-agent": "zendex",
+ "Authorization": "Basic VXNlcjE6cGFzcw=="
+ },
+ "method": "get",
+ "options": [],
+ "request_body": "",
+ "url": "https://test.zendesk.com/api/v2/users.json"
+ },
+ "response": {
+ "body": "{\"users\":[{\"id\":1},{\"id\":2},{\"id\":3},{\"id\":4}],\"previous_page\":null,\"next_page\":null,\"count\":4}",
+ "headers": {
+ "Server": "nginx",
+ "Date": "Fri, 11 Nov 2016 22:02:31 GMT",
+ "Content-Type": "application/json; charset=UTF-8",
+ "Content-Length": "37",
+ "Connection": "keep-alive",
+ "Cache-Control": "private",
+ "WWW-Authenticate": "Basic realm=\"Web Password\"",
+ "Strict-Transport-Security": "max-age=31536000;",
+ "X-UA-Compatible": "IE=Edge,chrome=1",
+ "X-Zendesk-Origin-Server": "app20.pod3.dub1.zdsys.com",
+ "X-Request-Id": "55485721-bf68-44d1-c44b-b8ca3a6bdb18",
+ "X-Runtime": "0.097079",
+ "X-Rack-Cache": "miss",
+ "X-Zendesk-Request-Id": "0c2d369029535cc8a910"
+ },
+ "status_code": 200,
+ "type": "ok"
+ }
+ }
+]
diff --git a/test/fixtures/vcr_cassettes/users/related_information.json b/test/fixtures/vcr_cassettes/users/related_information.json
new file mode 100644
index 0000000..e200d3e
--- /dev/null
+++ b/test/fixtures/vcr_cassettes/users/related_information.json
@@ -0,0 +1,36 @@
+[
+ {
+ "request": {
+ "body": "\"\\\"\\\"\"",
+ "headers": {
+ "user-agent": "zendex",
+ "Authorization": "Basic VXNlcjE6cGFzcw=="
+ },
+ "method": "get",
+ "options": [],
+ "request_body": "",
+ "url": "https://test.zendesk.com/api/v2/users/649267/related.json"
+ },
+ "response": {
+ "body": "{\"user_related\":{\"votes\":2001,\"topics\":5,\"topic_comments\":116,\"subscriptions\":6,\"requested_tickets\":7,\"organization_subscriptions\":1,\"forum_subscriptions\":3,\"entry_subscriptions\":1,\"ccd_tickets\":5,\"assigned_tickets\":12}}",
+ "headers": {
+ "Server": "nginx",
+ "Date": "Fri, 11 Nov 2016 22:02:31 GMT",
+ "Content-Type": "application/json; charset=UTF-8",
+ "Content-Length": "37",
+ "Connection": "keep-alive",
+ "Cache-Control": "private",
+ "WWW-Authenticate": "Basic realm=\"Web Password\"",
+ "Strict-Transport-Security": "max-age=31536000;",
+ "X-UA-Compatible": "IE=Edge,chrome=1",
+ "X-Zendesk-Origin-Server": "app20.pod3.dub1.zdsys.com",
+ "X-Request-Id": "55485721-bf68-44d1-c44b-b8ca3a6bdb18",
+ "X-Runtime": "0.097079",
+ "X-Rack-Cache": "miss",
+ "X-Zendesk-Request-Id": "0c2d369029535cc8a910"
+ },
+ "status_code": 200,
+ "type": "ok"
+ }
+ }
+]
diff --git a/test/fixtures/vcr_cassettes/users/show_many_users.json b/test/fixtures/vcr_cassettes/users/show_many_users.json
new file mode 100644
index 0000000..72fd198
--- /dev/null
+++ b/test/fixtures/vcr_cassettes/users/show_many_users.json
@@ -0,0 +1,36 @@
+[
+ {
+ "request": {
+ "body": "\"\\\"\\\"\"",
+ "headers": {
+ "user-agent": "zendex",
+ "Authorization": "Basic VXNlcjE6cGFzcw=="
+ },
+ "method": "get",
+ "options": [],
+ "request_body": "",
+ "url": "https://test.zendesk.com/api/v2/users/show_many.json?ids=6,67"
+ },
+ "response": {
+ "body": "{\"users\":[{\"name\":\"Kiki Segal\",\"id\":6},{\"name\":\"Sarpedon Baumgartner\",\"id\":67}]}",
+ "headers": {
+ "Server": "nginx",
+ "Date": "Fri, 11 Nov 2016 22:02:31 GMT",
+ "Content-Type": "application/json; charset=UTF-8",
+ "Content-Length": "37",
+ "Connection": "keep-alive",
+ "Cache-Control": "private",
+ "WWW-Authenticate": "Basic realm=\"Web Password\"",
+ "Strict-Transport-Security": "max-age=31536000;",
+ "X-UA-Compatible": "IE=Edge,chrome=1",
+ "X-Zendesk-Origin-Server": "app20.pod3.dub1.zdsys.com",
+ "X-Request-Id": "55485721-bf68-44d1-c44b-b8ca3a6bdb18",
+ "X-Runtime": "0.097079",
+ "X-Rack-Cache": "miss",
+ "X-Zendesk-Request-Id": "0c2d369029535cc8a910"
+ },
+ "status_code": 200,
+ "type": "ok"
+ }
+ }
+]
diff --git a/test/fixtures/vcr_cassettes/users/show_user.json b/test/fixtures/vcr_cassettes/users/show_user.json
new file mode 100644
index 0000000..138fc91
--- /dev/null
+++ b/test/fixtures/vcr_cassettes/users/show_user.json
@@ -0,0 +1,36 @@
+[
+ {
+ "request": {
+ "body": "\"\\\"\\\"\"",
+ "headers": {
+ "user-agent": "zendex",
+ "Authorization": "Basic VXNlcjE6cGFzcw=="
+ },
+ "method": "get",
+ "options": [],
+ "request_body": "",
+ "url": "https://test.zendesk.com/api/v2/users/295204.json"
+ },
+ "response": {
+ "body": "{\"user\":{\"updated_at\":\"2016-10-28T21:08:23Z\",\"tags\":[],\"user_fields\":{\"customer_complaint\":null},\"only_private_comments\":false,\"time_zone\":\"London\",\"two_factor_auth_enabled\":null,\"signature\":null,\"email\":\"nikolao.aikema@test.com\",\"custom_role_id\":null,\"url\":\"https://test.zendesk.com/api/v2/users/295204.json\",\"alias\":null,\"details\":\"\",\"locale\":\"en-US\",\"restricted_agent\":false,\"name\":\"Nikolao Aikema\",\"created_at\":\"2015-05-28T09:12:45Z\",\"suspended\":false,\"locale_id\":1,\"active\":true,\"verified\":true,\"photo\":null,\"shared_agent\":false,\"external_id\":null,\"role\":\"admin\",\"id\":295204,\"shared\":false,\"moderator\":true,\"last_login_at\":\"2016-10-28T21:08:23Z\",\"organization_id\":11129520411,\"phone\":null,\"notes\":\"\",\"shared_phone_number\":null,\"chat_only\":false,\"ticket_restriction\":null}}",
+ "headers": {
+ "Server": "nginx",
+ "Date": "Fri, 11 Nov 2016 22:02:31 GMT",
+ "Content-Type": "application/json; charset=UTF-8",
+ "Content-Length": "37",
+ "Connection": "keep-alive",
+ "Cache-Control": "private",
+ "WWW-Authenticate": "Basic realm=\"Web Password\"",
+ "Strict-Transport-Security": "max-age=31536000;",
+ "X-UA-Compatible": "IE=Edge,chrome=1",
+ "X-Zendesk-Origin-Server": "app20.pod3.dub1.zdsys.com",
+ "X-Request-Id": "55485721-bf68-44d1-c44b-b8ca3a6bdb18",
+ "X-Runtime": "0.097079",
+ "X-Rack-Cache": "miss",
+ "X-Zendesk-Request-Id": "0c2d369029535cc8a910"
+ },
+ "status_code": 200,
+ "type": "ok"
+ }
+ }
+]
diff --git a/test/zendex/search_test.exs b/test/zendex/search_test.exs
index b2276b7..b3a0708 100644
--- a/test/zendex/search_test.exs
+++ b/test/zendex/search_test.exs
@@ -1,29 +1,53 @@
defmodule Zendex.SearchTest do
- use ExUnit.Case, async: true
+ use ExUnit.Case, async: false
+ use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
+
+ @cassette_dir "test/fixtures/vcr_cassettes/search"
alias Zendex.Connection
+ setup_all do
+ ExVCR.Config.cassette_library_dir(@cassette_dir)
+ HTTPoison.start
+ end
+
setup do
- {:ok, conn: Connection.setup("http://test.zendesk.com", "User", "Passw")}
+ {:ok, conn: Connection.setup("https://test.zendesk.com", "User1", "Pass")}
end
test "doing a search", %{conn: conn} do
- expected = ["Jimbob Ticket 1", "Jimbob Ticket 2"]
-
- actual = Zendex.Search.query(conn, %{type: "ticket", requester: "Jimbob"})
-
- assert actual == expected
+ expected = %{"count" => 2,
+ "facets" => nil,
+ "next_page" => nil,
+ "previous_page" => nil,
+ "results" => [
+ %{"id" => 1, "description" => "Jimbob Ticket 1"},
+ %{"id" => 2, "description" => "Jimbob Ticket 2"}]}
+
+ use_cassette "search_tickets" do
+ actual = Zendex.Search.query(conn, %{type: "ticket", requester: "Jimbob"})
+
+ assert actual == expected
+ end
end
test "doing a search with sorting", %{conn: conn} do
- expected = ["Reginald Ticket 1", "Reginald Ticket 2"]
-
- actual = Zendex.Search.query(conn,
- %{type: "ticket", requester: "Reginald"},
- "created_at",
- "desc")
-
- assert actual == expected
+ expected = %{"count" => 2,
+ "facets" => nil,
+ "next_page" => nil,
+ "previous_page" => nil,
+ "results" => [
+ %{"id" => 1, "description" => "Reginald Ticket 1"},
+ %{"id" => 2, "description" => "Reginald Ticket 2"}]}
+
+ use_cassette "search_tickets_sorting" do
+ actual = Zendex.Search.query(conn,
+ %{type: "ticket", requester: "Reginald"},
+ "created_at",
+ "desc")
+
+ assert actual == expected
+ end
end
end
diff --git a/test/zendex/ticket_test.exs b/test/zendex/ticket_test.exs
index 485e897..759fe6a 100644
--- a/test/zendex/ticket_test.exs
+++ b/test/zendex/ticket_test.exs
@@ -1,18 +1,72 @@
defmodule Zendex.TicketTest do
- use ExUnit.Case, async: true
+ use ExUnit.Case, async: false
+ use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
alias Zendex.Connection
+ @cassette_dir "test/fixtures/vcr_cassettes/tickets"
+
+ setup_all do
+ ExVCR.Config.cassette_library_dir(@cassette_dir)
+ HTTPoison.start
+ end
+
setup do
- {:ok, conn: Connection.setup("http://test.zendesk.com", "User", "Passw")}
+ {:ok, conn: Connection.setup("https://test.zendesk.com", "User1", "Pass")}
end
test "getting tickets", %{conn: conn} do
- assert "ticket" == Zendex.Ticket.list(conn)
+ expected = %{"count" => 4,
+ "next_page" => nil,
+ "previous_page" => nil,
+ "tickets" => [%{"id" => 1},
+ %{"id" => 2},
+ %{"id" => 3},
+ %{"id" => 4}]}
+ use_cassette "list_tickets" do
+ actual = Zendex.Ticket.list(conn)
+
+ assert expected == actual
+ end
+ end
+
+ test "listing tickets with pagination", %{conn: conn} do
+ expected = [%{"count" => 4,
+ "next_page" => "https://test.zendesk.com/api/v2/tickets.json?page=2",
+ "previous_page" => nil,
+ "tickets" => [%{"id" => 1}, %{"id" => 2}]},
+ %{"count" => 4,
+ "next_page" => nil,
+ "previous_page" => "https://test.zendesk.com/api/v2/tickets.json?page=1",
+ "tickets" => [%{"id" => 3}, %{"id" => 4}]}]
+ use_cassette "list_tickets_pagination" do
+ actual = Zendex.Ticket.list(conn, pagination: :auto)
+
+ assert expected == actual
+ end
+ end
+
+ test "listing only first page", %{conn: conn} do
+ expected = %{"count" => 4,
+ "next_page" => "https://test.zendesk.com/api/v2/tickets.json?page=2",
+ "previous_page" => nil,
+ "tickets" => [%{"id" => 1}, %{"id" => 2}]}
+ use_cassette "list_tickets_pagination" do
+ actual = Zendex.Ticket.list(conn, pagination: :none)
+
+ assert expected == actual
+ end
+
end
test "creating a ticket", %{conn: conn} do
- assert "Ticket created successfully!" ==
- Zendex.Ticket.create(conn, %{"ticket": %{}})
+ expected = %{"ticket" => %{"id" => 1234,
+ "description" => "My printer is on fire!"}}
+ use_cassette "create_ticket" do
+ ticket = %{"ticket" => %{"description" => "My printer is on fire!"}}
+ actual = Zendex.Ticket.create(conn, ticket)
+
+ assert expected == actual
+ end
end
end
diff --git a/test/zendex/user_test.exs b/test/zendex/user_test.exs
index 537c23a..ee1b73a 100644
--- a/test/zendex/user_test.exs
+++ b/test/zendex/user_test.exs
@@ -1,19 +1,35 @@
defmodule Zendex.UserTest do
- use ExUnit.Case, async: true
+ use ExUnit.Case, async: false
+ use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
doctest Zendex.User
+ @cassette_dir "test/fixtures/vcr_cassettes/users"
+
alias Zendex.Connection
+ setup_all do
+ ExVCR.Config.cassette_library_dir(@cassette_dir)
+ HTTPoison.start
+ end
+
setup do
{:ok, conn: Connection.setup("https://test.zendesk.com", "User1", "pass")}
end
test "list users", %{conn: conn} do
- expected = "users"
- actual = Zendex.User.list(conn)
+ expected = %{"count" => 4,
+ "next_page" => nil,
+ "previous_page" => nil,
+ "users" => [%{"id" => 1},
+ %{"id" => 2},
+ %{"id" => 3},
+ %{"id" => 4}]}
+ use_cassette "list_users" do
+ actual = Zendex.User.list(conn)
- assert expected == actual
+ assert expected == actual
+ end
end
test "showing a user", %{conn: conn} do
@@ -51,17 +67,21 @@ defmodule Zendex.UserTest do
"user_fields" => %{"customer_complaint" => nil},
"tags" => [],
"updated_at" => "2016-10-28T21:08:23Z"}}
- actual = Zendex.User.show(conn, 295204)
- assert expected == actual
+ use_cassette "show_user" do
+ actual = Zendex.User.show(conn, 295204)
+ assert expected == actual
+ end
end
test "showing many users", %{conn: conn} do
expected = %{"users" => [%{"id" => 6, "name" => "Kiki Segal"},
%{"id" => 67, "name" => "Sarpedon Baumgartner"}]}
- actual = Zendex.User.show_many(conn, [6,67])
+ use_cassette "show_many_users" do
+ actual = Zendex.User.show_many(conn, [6,67])
- assert expected == actual
+ assert expected == actual
+ end
end
test "getting related info on a user", %{conn: conn} do
@@ -75,16 +95,20 @@ defmodule Zendex.UserTest do
"topic_comments" => 116,
"topics" => 5,
"votes" => 2001}}
- actual = Zendex.User.related_information(conn, 649267)
+ use_cassette "related_information" do
+ actual = Zendex.User.related_information(conn, 649267)
- assert expected == actual
+ assert expected == actual
+ end
end
test "creating a user", %{conn: conn} do
expected = %{"user" => %{"id" => 1234, "name" => "Roger", "email" => "roger@dodger.com"}}
- actual = Zendex.User.create(conn, %{user: %{name: "Roger", email: "roger@dodger.com"}})
+ use_cassette "create_user" do
+ actual = Zendex.User.create(conn, %{user: %{name: "Roger", email: "roger@dodger.com"}})
- assert expected == actual
+ assert expected == actual
+ end
end
test "deleting a user", %{conn: conn} do
@@ -122,8 +146,11 @@ defmodule Zendex.UserTest do
"user_fields" => %{"customer_complaint" => nil},
"tags" => [],
"updated_at" => "2016-10-28T21:08:23Z"}}
- actual = Zendex.User.delete(conn, 49043)
- assert expected == actual
+ use_cassette "delete_user" do
+ actual = Zendex.User.delete(conn, 49043)
+
+ assert expected == actual
+ end
end
end