forked from code-corps/code-corps-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub_test.exs
More file actions
50 lines (42 loc) · 1.83 KB
/
github_test.exs
File metadata and controls
50 lines (42 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
defmodule CodeCorps.GitHubTest do
@moduledoc false
use CodeCorps.ModelCase
use CodeCorps.GitHubCase
alias CodeCorps.GitHub
describe "request/5" do
@tag bypass: %{"/foo" => {200, %{"bar" => "baz"}}}
test "handles a successful response" do
{:ok, response} = GitHub.request(%{}, :get, "foo", %{}, [])
assert response == %{"bar" => "baz"}
end
@tag bypass: %{"/foo" => {404, %{"bar" => "baz"}}}
test "handles an error response" do
{:error, response} = GitHub.request(%{}, :get, "foo", %{}, [])
assert response == CodeCorps.GitHub.APIError.new({404, %{"message" => %{"bar" => "baz"} |> Poison.encode!}})
end
end
describe "user_access_token_request/2" do
@tag bypass: %{"/" => {200, %{"bar" => "baz"}}}
test "handles a successful response" do
{:ok, response} = GitHub.user_access_token_request("foo_code", "foo_state")
assert response == %{"bar" => "baz"}
end
@tag bypass: %{"/" => {404, %{"bar" => "baz"}}}
test "handles an error response" do
{:error, response} = GitHub.user_access_token_request("foo_code", "foo_state")
assert response == CodeCorps.GitHub.APIError.new({404, %{"message" => %{"bar" => "baz"} |> Poison.encode!}})
end
end
describe "authenticated_integration_request/5" do
@tag bypass: %{"/foo" => {200, %{"bar" => "baz"}}}
test "handles a successful response" do
{:ok, response} = GitHub.authenticated_integration_request(%{}, :get, "foo", %{}, [])
assert response == %{"bar" => "baz"}
end
@tag bypass: %{"/foo" => {404, %{"bar" => "baz"}}}
test "handles an error response" do
{:error, response} = GitHub.authenticated_integration_request(%{}, :get, "foo", %{}, [])
assert response == CodeCorps.GitHub.APIError.new({404, %{"message" => %{"bar" => "baz"} |> Poison.encode!}})
end
end
end