@@ -8,53 +8,51 @@ defmodule VoodooTest do
8
8
@ secret_key "secret_key"
9
9
@ api_host "http://foo.com"
10
10
11
- setup do
12
- Application . put_env ( :voodoo_mfg , :secret_key , @ secret_key )
13
- Application . put_env ( :voodoo_mfg , :api_host , @ api_host )
14
- :ok
15
- end
16
-
17
11
describe "secret_key/0" do
18
12
19
13
test "fails when config for key is not set" do
14
+ old_secret_key = Application . get_env ( :voodoo_mfg , :secret_key )
20
15
Application . delete_env ( :voodoo_mfg , :secret_key )
21
16
assert_raise MissingSecretKeyError , fn ->
22
17
secret_key
23
18
end
19
+ Application . put_env ( :voodoo_mfg , :secret_key , old_secret_key )
24
20
end
25
21
26
22
test "returns key when it is set in config" do
23
+ old_secret_key = Application . get_env ( :voodoo_mfg , :secret_key )
24
+ Application . put_env ( :voodoo_mfg , :secret_key , @ secret_key )
27
25
assert secret_key == @ secret_key
26
+ Application . put_env ( :voodoo_mfg , :secret_key , old_secret_key )
28
27
end
29
28
end
30
29
31
30
describe "api_host/0" do
32
31
33
32
test "fails when config for key is not set" do
33
+ old_host = Application . get_env ( :voodoo_mfg , :api_host )
34
34
Application . delete_env ( :voodoo_mfg , :api_host )
35
35
assert_raise MissingSecretKeyError , fn ->
36
36
api_host
37
37
end
38
+ Application . put_env ( :voodoo_mfg , :api_host , old_host )
38
39
end
39
40
40
41
test "returns key when it is set in config" do
42
+ old_host = Application . get_env ( :voodoo_mfg , :api_host )
43
+ Application . put_env ( :voodoo_mfg , :api_host , @ api_host )
41
44
assert api_host == @ api_host
45
+ Application . put_env ( :voodoo_mfg , :api_host , old_host )
42
46
end
43
47
end
44
48
45
49
test "process_url/1 attaches base url to endpoint" do
46
- assert process_url ( "/api " ) == "http ://foo. com/api"
47
- assert process_url ( "api " ) == "http ://foo. com/api"
50
+ assert process_url ( "/test " ) == "https ://staging-api.voodoomfg. com/api/1/test "
51
+ assert process_url ( "test " ) == "https ://staging-api.voodoomfg. com/api/1/test "
48
52
end
49
53
50
54
test "process_request_body/1 returns json" do
51
55
body = % { foo: "bar" }
52
56
assert Poison . encode! ( body ) == process_request_body ( body )
53
57
end
54
-
55
- test "process_request_headers/1 sets key and content-type headers" do
56
- headers = process_request_headers ( "" )
57
- assert { "key" , @ secret_key } in headers
58
- assert { "content-type" , "application/json" } in headers
59
- end
60
58
end
0 commit comments