@@ -26,39 +26,26 @@ defmodule SparkPost.EndpointTest do
26
26
end
27
27
end
28
28
29
- test "Endpoint.request forms correct URLs" do
30
- base_url = Application . get_env ( :sparkpost , :api_endpoint )
31
- endpt = "transmissions"
32
- params = [ campaign_id: "campaign101" ]
33
- paramstr = URI . encode_query ( params )
34
- respfn = MockServer . mk_resp
35
- with_mock HTTPotion , [ request: fn ( method , url , opts ) ->
36
- assert url == base_url <> endpt <> "?" <> paramstr
37
- respfn . ( method , url , opts )
38
- end ] do
39
- Endpoint . request ( :get , "transmissions" , [ params: params ] )
40
- end
41
- end
42
-
43
29
test "Endpoint.request succeeds with Endpoint.Response" do
44
- with_mock HTTPotion , [ request: MockServer . mk_resp ] do
45
- Endpoint . request ( :get , "transmissions" , [ ] )
30
+ with_mock HTTPoison , [ request: fn ( _ , _ , _ , _ , _ ) ->
31
+ r = MockServer . mk_resp
32
+ r . ( nil , nil , nil , nil , nil )
33
+ end ] do
34
+ Endpoint . request ( :get , "transmissions" , % { } )
46
35
end
47
36
end
48
37
49
38
test "Endpoint.request populates Endpoint.Response" do
50
39
status_code = 200
51
40
results = Poison . decode! ( MockServer . create_json , [ keys: :atoms ] ) . results
52
- with_mock HTTPotion , [ request: MockServer . mk_resp ] do
53
- resp = % Endpoint.Response { } = Endpoint . request (
54
- :get , "transmissions" , [ ] )
55
-
41
+ with_mock HTTPoison , [ request: MockServer . mk_resp ] do
42
+ resp = % Endpoint.Response { } = Endpoint . request ( :get , "transmissions" , % { } , % { } , [ ] )
56
43
assert % Endpoint.Response { status_code: ^ status_code , results: ^ results } = resp
57
44
end
58
45
end
59
46
60
47
test "Endpoint.request fails with Endpoint.Error" do
61
- with_mock HTTPotion , [ request: MockServer . mk_fail ] do
48
+ with_mock HTTPoison , [ request: MockServer . mk_fail ] do
62
49
% Endpoint.Error { } = Endpoint . request (
63
50
:get , "transmissions" , [ ] )
64
51
end
@@ -67,7 +54,7 @@ defmodule SparkPost.EndpointTest do
67
54
test "Endpoint.request populates Endpoint.Error" do
68
55
status_code = 400
69
56
errors = Poison . decode! ( MockServer . create_fail_json , [ keys: :atoms ] ) . errors
70
- with_mock HTTPotion , [ request: MockServer . mk_fail ] do
57
+ with_mock HTTPoison , [ request: MockServer . mk_fail ] do
71
58
resp = % Endpoint.Error { } = Endpoint . request (
72
59
:get , "transmissions" , [ ] )
73
60
@@ -77,42 +64,42 @@ defmodule SparkPost.EndpointTest do
77
64
78
65
test "Endpoint.request includes the core HTTP headers" do
79
66
respfn = MockServer . mk_resp
80
- with_mock HTTPotion , [ request: fn ( method , url , opts ) ->
67
+ with_mock HTTPoison , [ request: fn ( method , url , body , headers , opts ) ->
81
68
Enum . each ( Headers . for_method ( method ) , fn { header , tester } ->
82
69
header_atom = String . to_atom ( header )
83
- assert Keyword . has_key? ( opts [ : headers] , header_atom ) , "#{ header } header required for #{ method } requests"
84
- assert tester . ( opts [ : headers] [ header_atom ] ) , "Malformed header: #{ header } . See Headers module in #{ __ENV__ . file } for formatting rules."
70
+ assert Map . has_key? ( headers , header_atom ) , "#{ header } header required for #{ method } requests"
71
+ assert tester . ( headers [ header_atom ] ) , "Malformed header: #{ header } . See Headers module in #{ __ENV__ . file } for formatting rules."
85
72
end )
86
- respfn . ( method , url , opts )
73
+ respfn . ( method , url , body , headers , opts )
87
74
end
88
75
] do
89
76
Enum . each ( [ :get , :post , :put , :delete ] , fn method ->
90
- Endpoint . request ( method , "transmissions" , [ ] ) end )
77
+ Endpoint . request ( method , "transmissions" , % { } , % { } , [ ] ) end )
91
78
end
92
79
end
93
80
94
81
test "Endpoint.request includes request bodies for appropriate methods" do
95
82
respfn = MockServer . mk_resp
96
- with_mock HTTPotion , [ request: fn ( method , url , opts ) ->
97
- assert opts [ : body] == "{} "
98
- respfn . ( method , url , opts )
83
+ with_mock HTTPoison , [ request: fn ( method , url , body , headers , opts ) ->
84
+ assert body == ""
85
+ respfn . ( method , url , body , headers , opts )
99
86
end
100
87
] do
101
- Endpoint . request ( :post , "transmissions" , [ body: % { } ] )
102
- Endpoint . request ( :put , "transmissions" , [ body: % { } ] )
88
+ Endpoint . request ( :post , "transmissions" , % { } , % { } , [ ] )
89
+ Endpoint . request ( :put , "transmissions" , % { } , % { } , [ ] )
103
90
end
104
91
end
105
92
106
93
test "Endpoint.request includes request timeout" do
107
94
respfn = MockServer . mk_resp
108
- with_mock HTTPotion , [ request: fn ( method , url , opts ) ->
95
+ with_mock HTTPoison , [ request: fn ( method , url , body , headers , opts ) ->
109
96
assert Keyword . has_key? ( opts , :timeout )
110
- respfn . ( method , url , opts )
97
+ respfn . ( method , url , body , headers , opts )
111
98
end
112
99
] do
113
- Endpoint . request ( :post , "transmissions" , [ ] )
114
- Endpoint . request ( :put , "transmissions" , [ ] )
115
- Endpoint . request ( :get , "transmissions" , [ ] )
100
+ Endpoint . request ( :post , "transmissions" , % { } , % { } , [ ] )
101
+ Endpoint . request ( :put , "transmissions" , % { } , % { } , [ ] )
102
+ Endpoint . request ( :get , "transmissions" , % { } , % { } , [ ] )
116
103
end
117
104
end
118
105
end
0 commit comments