@@ -26,39 +26,26 @@ defmodule SparkPost.EndpointTest do
2626 end
2727 end
2828
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-
4329 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" , % { } )
4635 end
4736 end
4837
4938 test "Endpoint.request populates Endpoint.Response" do
5039 status_code = 200
5140 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" , % { } , % { } , [ ] )
5643 assert % Endpoint.Response { status_code: ^ status_code , results: ^ results } = resp
5744 end
5845 end
5946
6047 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
6249 % Endpoint.Error { } = Endpoint . request (
6350 :get , "transmissions" , [ ] )
6451 end
@@ -67,7 +54,7 @@ defmodule SparkPost.EndpointTest do
6754 test "Endpoint.request populates Endpoint.Error" do
6855 status_code = 400
6956 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
7158 resp = % Endpoint.Error { } = Endpoint . request (
7259 :get , "transmissions" , [ ] )
7360
@@ -77,42 +64,42 @@ defmodule SparkPost.EndpointTest do
7764
7865 test "Endpoint.request includes the core HTTP headers" do
7966 respfn = MockServer . mk_resp
80- with_mock HTTPotion , [ request: fn ( method , url , opts ) ->
67+ with_mock HTTPoison , [ request: fn ( method , url , body , headers , opts ) ->
8168 Enum . each ( Headers . for_method ( method ) , fn { header , tester } ->
8269 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."
8572 end )
86- respfn . ( method , url , opts )
73+ respfn . ( method , url , body , headers , opts )
8774 end
8875 ] do
8976 Enum . each ( [ :get , :post , :put , :delete ] , fn method ->
90- Endpoint . request ( method , "transmissions" , [ ] ) end )
77+ Endpoint . request ( method , "transmissions" , % { } , % { } , [ ] ) end )
9178 end
9279 end
9380
9481 test "Endpoint.request includes request bodies for appropriate methods" do
9582 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 )
9986 end
10087 ] do
101- Endpoint . request ( :post , "transmissions" , [ body: % { } ] )
102- Endpoint . request ( :put , "transmissions" , [ body: % { } ] )
88+ Endpoint . request ( :post , "transmissions" , % { } , % { } , [ ] )
89+ Endpoint . request ( :put , "transmissions" , % { } , % { } , [ ] )
10390 end
10491 end
10592
10693 test "Endpoint.request includes request timeout" do
10794 respfn = MockServer . mk_resp
108- with_mock HTTPotion , [ request: fn ( method , url , opts ) ->
95+ with_mock HTTPoison , [ request: fn ( method , url , body , headers , opts ) ->
10996 assert Keyword . has_key? ( opts , :timeout )
110- respfn . ( method , url , opts )
97+ respfn . ( method , url , body , headers , opts )
11198 end
11299 ] 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" , % { } , % { } , [ ] )
116103 end
117104 end
118105end
0 commit comments