@@ -8,6 +8,50 @@ defmodule SparkPost.SuppressionListTest do
88
99 import Mock
1010
11+ test_with_mock "SuppressionList.upsert_one succeeds with message" ,
12+ HTTPoison , [ request: fn ( method , url , body , headers , opts ) ->
13+ assert method == :put
14+ fun = MockServer . mk_http_resp ( 200 , MockServer . get_json ( "suppressionlistupdate" ) )
15+ fun . ( method , url , body , headers , opts )
16+ end ] do
17+ { :ok , resp } = SuppressionList . upsert_one ( "test@marketing.com" , "non_transactional" , "test description" )
18+ assert resp == "Test response message"
19+ end
20+
21+ test_with_mock "SuppressionList.upsert_one fails with invalid type" ,
22+ HTTPoison , [ request: fn ( method , url , body , headers , opts ) ->
23+ assert method == :put
24+ fun = MockServer . mk_http_resp ( 400 , MockServer . get_json ( "suppressionupdate_fail" ) )
25+ fun . ( method , url , body , headers , opts )
26+ end ] do
27+ { :error , resp } = SuppressionList . upsert_one ( "test@marketing.com" , "bad_type" )
28+ assert % SparkPost.Endpoint.Error { } = resp
29+ assert resp . status_code == 400
30+ assert resp . errors == [ % { message: "Type must be one of: 'transactional', 'non_transactional'" } ]
31+ end
32+
33+ test_with_mock "SuppressionList.delete succeeds with empty body" ,
34+ HTTPoison , [ request: fn ( method , url , body , headers , opts ) ->
35+ assert method == :delete
36+ fun = MockServer . mk_http_resp ( 204 , "" )
37+ fun . ( method , url , body , headers , opts )
38+ end ] do
39+ { :ok , resp } = SuppressionList . delete ( "test@marketing.com" )
40+ assert resp == ""
41+ end
42+
43+ test_with_mock "SuppressionList.delete fails 404" ,
44+ HTTPoison , [ request: fn ( method , url , body , headers , opts ) ->
45+ assert method == :delete
46+ fun = MockServer . mk_http_resp ( 404 , MockServer . get_json ( "suppressiondelete_fail" ) )
47+ fun . ( method , url , body , headers , opts )
48+ end ] do
49+ { :error , resp } = SuppressionList . delete ( "test@marketing.com" )
50+ assert % SparkPost.Endpoint.Error { } = resp
51+ assert resp . status_code == 404
52+ assert resp . errors == [ % { message: "Recipient could not be found" } ]
53+ end
54+
1155 test_with_mock "SuppressionList.search succeeds with SuppressionList.SearchResult" ,
1256 HTTPoison , [ request: fn ( method , url , body , headers , opts ) ->
1357 assert method == :get
0 commit comments