aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Blowers <shdblowers@gmail.com>2016-10-30 18:54:34 (GMT)
committerSteven Blowers <shdblowers@gmail.com>2016-10-30 18:54:34 (GMT)
commit01d88a22c6cc00b561b0114c0865ba52f355d97c (patch)
treefc38bf9b9642fb3ccc4af6dafe3fdc61faa2d9ec
parent0c19e15c7383ccfbc45bed6c7e4c38d814e60cf6 (diff)
downloadzendex-01d88a22c6cc00b561b0114c0865ba52f355d97c.tar.gz
zendex-01d88a22c6cc00b561b0114c0865ba52f355d97c.tar.xz
refactor set_up to setup, test for encoding authorization details
-rw-r--r--README.md2
-rw-r--r--lib/zendex/connection.ex4
-rw-r--r--test/zendex/connection_test.exs12
-rw-r--r--test/zendex/search_test.exs2
-rw-r--r--test/zendex/ticket_test.exs2
-rw-r--r--test/zendex/user_test.exs2
6 files changed, 18 insertions, 6 deletions
diff --git a/README.md b/README.md
index db64ce1..786e2dc 100644
--- a/README.md
+++ b/README.md
@@ -31,7 +31,7 @@ An Elixir wrapper for the Zendesk API.
1. Setup a `Zendex.Connection` map, that will store your Zendesk details. It requires the URL of your Zendesk instance, your username and your password.
```elixir
- iex> conn = Zendex.Connection.set_up("http://test.zendesk.com", "User1", "pass")
+ iex> conn = Zendex.Connection.setup("http://test.zendesk.com", "User1", "pass")
%{authentication: "VXNlcjE6cGFzcw==", base_url: "http://test.zendesk.com"}
```
diff --git a/lib/zendex/connection.ex b/lib/zendex/connection.ex
index 4717e4f..248c253 100644
--- a/lib/zendex/connection.ex
+++ b/lib/zendex/connection.ex
@@ -7,8 +7,8 @@ defmodule Zendex.Connection do
@typedoc "The connection paramters"
@type t :: %{base_url: String.t, authentication: binary}
- @spec set_up(String.t, String.t, String.t) :: t
- def set_up(base_url, username, password) do
+ @spec setup(String.t, String.t, String.t) :: t
+ def setup(base_url, username, password) do
authentication = Base.encode64("#{username}:#{password}")
%{base_url: base_url, authentication: authentication}
diff --git a/test/zendex/connection_test.exs b/test/zendex/connection_test.exs
new file mode 100644
index 0000000..6608b44
--- /dev/null
+++ b/test/zendex/connection_test.exs
@@ -0,0 +1,12 @@
+defmodule Zendex.ConnectionTest do
+ use ExUnit.Case, async: true
+
+ test "setup encodes username and password correctly" do
+ expected = %{authentication: "WHhYQXdlc29tZVVzZXJuYW1lWHhYOnBhc3N3b3JkMTIz",
+ base_url: ""}
+ actual = Zendex.Connection.setup("", "XxXAwesomeUsernameXxX", "password123")
+
+ assert expected == actual
+ end
+
+end
diff --git a/test/zendex/search_test.exs b/test/zendex/search_test.exs
index 8d1ad8f..a7102b6 100644
--- a/test/zendex/search_test.exs
+++ b/test/zendex/search_test.exs
@@ -2,7 +2,7 @@ defmodule Zendex.SearchTest do
use ExUnit.Case, async: true
setup do
- [conn: Zendex.Connection.set_up("http://test.zendesk.com", "User", "Passw")]
+ [conn: Zendex.Connection.setup("http://test.zendesk.com", "User", "Passw")]
end
test "doing a search", context do
diff --git a/test/zendex/ticket_test.exs b/test/zendex/ticket_test.exs
index 1f1ea92..6bc4436 100644
--- a/test/zendex/ticket_test.exs
+++ b/test/zendex/ticket_test.exs
@@ -2,7 +2,7 @@ defmodule Zendex.TicketTest do
use ExUnit.Case, async: true
setup do
- [conn: Zendex.Connection.set_up("http://test.zendesk.com", "User", "Passw")]
+ [conn: Zendex.Connection.setup("http://test.zendesk.com", "User", "Passw")]
end
test "getting tickets", context do
diff --git a/test/zendex/user_test.exs b/test/zendex/user_test.exs
index 3964aac..81dfd27 100644
--- a/test/zendex/user_test.exs
+++ b/test/zendex/user_test.exs
@@ -2,7 +2,7 @@ defmodule Zendex.UserTest do
use ExUnit.Case, async: true
setup do
- [conn: Zendex.Connection.set_up("http://test.zendesk.com", "User1", "pass")]
+ [conn: Zendex.Connection.setup("http://test.zendesk.com", "User1", "pass")]
end
test "list users", context do