postmark 1.18.0 → 1.19.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/postmark/api_client.rb +26 -1
- data/lib/postmark/version.rb +1 -1
- data/spec/integration/api_client_hashes_spec.rb +29 -35
- data/spec/integration/api_client_messages_spec.rb +16 -16
- data/spec/integration/api_client_resources_spec.rb +15 -31
- data/spec/spec_helper.rb +1 -7
- data/spec/support/custom_matchers.rb +6 -0
- data/spec/support/shared_examples.rb +16 -16
- data/spec/unit/postmark/account_api_client_spec.rb +1 -50
- data/spec/unit/postmark/api_client_spec.rb +51 -66
- data/spec/unit/postmark/bounce_spec.rb +37 -49
- data/spec/unit/postmark/client_spec.rb +0 -6
- data/spec/unit/postmark/error_spec.rb +44 -44
- data/spec/unit/postmark/handlers/mail_spec.rb +3 -3
- data/spec/unit/postmark/helpers/hash_helper_spec.rb +5 -6
- data/spec/unit/postmark/http_client_spec.rb +47 -49
- data/spec/unit/postmark/inbound_spec.rb +34 -34
- data/spec/unit/postmark/inflector_spec.rb +11 -13
- data/spec/unit/postmark/json_spec.rb +2 -2
- data/spec/unit/postmark/mail_message_converter_spec.rb +79 -82
- data/spec/unit/postmark_spec.rb +32 -32
- metadata +3 -3
@@ -23,21 +23,25 @@ describe Postmark::ApiClient do
|
|
23
23
|
subject {api_client}
|
24
24
|
|
25
25
|
context "attr readers" do
|
26
|
-
it {
|
27
|
-
it {
|
26
|
+
it { expect(subject).to respond_to(:http_client) }
|
27
|
+
it { expect(subject).to respond_to(:max_retries) }
|
28
28
|
end
|
29
29
|
|
30
30
|
context "when it's created without options" do
|
31
|
-
|
31
|
+
it "max retries" do
|
32
|
+
expect(subject.max_retries).to eq 3
|
33
|
+
end
|
32
34
|
end
|
33
35
|
|
34
36
|
context "when it's created with user options" do
|
35
37
|
subject {Postmark::ApiClient.new(api_token, :max_retries => max_retries, :foo => :bar)}
|
36
|
-
|
38
|
+
it "max_retries" do
|
39
|
+
expect(subject.max_retries).to eq max_retries
|
40
|
+
end
|
37
41
|
|
38
42
|
it 'passes other options to HttpClient instance' do
|
39
43
|
allow(Postmark::HttpClient).to receive(:new).with(api_token, :foo => :bar)
|
40
|
-
subject.
|
44
|
+
expect(subject).to be
|
41
45
|
end
|
42
46
|
end
|
43
47
|
|
@@ -46,12 +50,12 @@ describe Postmark::ApiClient do
|
|
46
50
|
|
47
51
|
it 'assigns the api token to the http client instance' do
|
48
52
|
subject.api_token = api_token
|
49
|
-
subject.http_client.api_token.
|
53
|
+
expect(subject.http_client.api_token).to eq api_token
|
50
54
|
end
|
51
55
|
|
52
56
|
it 'is aliased as api_key=' do
|
53
57
|
subject.api_key = api_token
|
54
|
-
subject.http_client.api_token.
|
58
|
+
expect(subject.http_client.api_token).to eq api_token
|
55
59
|
end
|
56
60
|
end
|
57
61
|
|
@@ -74,8 +78,7 @@ describe Postmark::ApiClient do
|
|
74
78
|
|
75
79
|
it 'converts response to ruby format' do
|
76
80
|
expect(http_client).to receive(:post).with('email', email_json) {response}
|
77
|
-
|
78
|
-
r.should have_key(:message_id)
|
81
|
+
expect(subject.deliver(message_hash)).to have_key(:message_id)
|
79
82
|
end
|
80
83
|
end
|
81
84
|
|
@@ -94,7 +97,7 @@ describe Postmark::ApiClient do
|
|
94
97
|
it 'converts response to ruby format' do
|
95
98
|
expect(http_client).to receive(:post).with('email/batch', emails_json) {response}
|
96
99
|
response = subject.deliver_in_batches([message_hash, message_hash, message_hash])
|
97
|
-
response.first.
|
100
|
+
expect(response.first).to have_key(:error_code)
|
98
101
|
end
|
99
102
|
end
|
100
103
|
|
@@ -185,7 +188,7 @@ describe Postmark::ApiClient do
|
|
185
188
|
subject.deliver_messages([message, message, message])
|
186
189
|
end
|
187
190
|
|
188
|
-
it "
|
191
|
+
it "retry 3 times" do
|
189
192
|
2.times do
|
190
193
|
expect(http_client).to receive(:post).and_raise(Postmark::InternalServerError)
|
191
194
|
end
|
@@ -193,7 +196,7 @@ describe Postmark::ApiClient do
|
|
193
196
|
expect {subject.deliver_messages([message, message, message])}.not_to raise_error
|
194
197
|
end
|
195
198
|
|
196
|
-
it "
|
199
|
+
it "retry on timeout" do
|
197
200
|
expect(http_client).to receive(:post).and_raise(Postmark::TimeoutError)
|
198
201
|
expect(http_client).to receive(:post) {response}
|
199
202
|
expect {subject.deliver_messages([message, message, message])}.not_to raise_error
|
@@ -218,7 +221,7 @@ describe Postmark::ApiClient do
|
|
218
221
|
subject.deliver_messages_with_templates(messages)
|
219
222
|
end
|
220
223
|
|
221
|
-
it "
|
224
|
+
it "retry 3 times" do
|
222
225
|
2.times do
|
223
226
|
expect(http_client).to receive(:post).and_raise(Postmark::InternalServerError)
|
224
227
|
end
|
@@ -226,7 +229,7 @@ describe Postmark::ApiClient do
|
|
226
229
|
expect {subject.deliver_messages_with_templates(messages)}.not_to raise_error
|
227
230
|
end
|
228
231
|
|
229
|
-
it "
|
232
|
+
it "retry on timeout" do
|
230
233
|
expect(http_client).to receive(:post).and_raise(Postmark::TimeoutError)
|
231
234
|
expect(http_client).to receive(:post) {response}
|
232
235
|
expect {subject.deliver_messages_with_templates(messages)}.not_to raise_error
|
@@ -239,7 +242,7 @@ describe Postmark::ApiClient do
|
|
239
242
|
|
240
243
|
it 'requests data at /deliverystats' do
|
241
244
|
expect(http_client).to receive(:get).with("deliverystats") {response}
|
242
|
-
subject.delivery_stats.
|
245
|
+
expect(subject.delivery_stats).to have_key(:bounces)
|
243
246
|
end
|
244
247
|
end
|
245
248
|
|
@@ -266,13 +269,10 @@ describe Postmark::ApiClient do
|
|
266
269
|
end
|
267
270
|
|
268
271
|
it 'loads inbound messages' do
|
269
|
-
allow(subject.http_client).to receive(:get).
|
270
|
-
with('messages/inbound', an_instance_of(Hash)).and_return(response)
|
272
|
+
allow(subject.http_client).to receive(:get).with('messages/inbound', an_instance_of(Hash)).and_return(response)
|
271
273
|
expect(subject.messages(:inbound => true).count).to eq(5)
|
272
274
|
end
|
273
|
-
|
274
275
|
end
|
275
|
-
|
276
276
|
end
|
277
277
|
|
278
278
|
describe '#get_messages' do
|
@@ -287,20 +287,15 @@ describe Postmark::ApiClient do
|
|
287
287
|
and_return(response)
|
288
288
|
subject.get_messages(:offset => 50, :count => 50)
|
289
289
|
end
|
290
|
-
|
291
290
|
end
|
292
291
|
|
293
292
|
context 'given inbound' do
|
294
293
|
let(:response) {{"TotalCount" => 1, "InboundMessages" => [{}]}}
|
295
294
|
|
296
295
|
it 'requests data at /messages/inbound' do
|
297
|
-
expect(http_client).to receive(:get).
|
298
|
-
|
299
|
-
and_return(response)
|
300
|
-
subject.get_messages(:inbound => true, :offset => 50, :count => 50).
|
301
|
-
should be_an(Array)
|
296
|
+
expect(http_client).to receive(:get).with('messages/inbound', :offset => 50, :count => 50).and_return(response)
|
297
|
+
expect(subject.get_messages(:inbound => true, :offset => 50, :count => 50)).to be_an(Array)
|
302
298
|
end
|
303
|
-
|
304
299
|
end
|
305
300
|
end
|
306
301
|
|
@@ -338,7 +333,7 @@ describe Postmark::ApiClient do
|
|
338
333
|
expect(http_client).to receive(:get).
|
339
334
|
with("messages/outbound/#{id}/details", {}).
|
340
335
|
and_return(response)
|
341
|
-
subject.get_message(id).
|
336
|
+
expect(subject.get_message(id)).to have_key(:to)
|
342
337
|
end
|
343
338
|
end
|
344
339
|
|
@@ -347,7 +342,7 @@ describe Postmark::ApiClient do
|
|
347
342
|
expect(http_client).to receive(:get).
|
348
343
|
with("messages/inbound/#{id}/details", {}).
|
349
344
|
and_return(response)
|
350
|
-
subject.get_message(id, :inbound => true).
|
345
|
+
expect(subject.get_message(id, :inbound => true)).to have_key(:to)
|
351
346
|
end
|
352
347
|
end
|
353
348
|
end
|
@@ -363,7 +358,7 @@ describe Postmark::ApiClient do
|
|
363
358
|
expect(http_client).to receive(:get).
|
364
359
|
with("messages/outbound/#{id}/dump", {}).
|
365
360
|
and_return(response)
|
366
|
-
subject.dump_message(id).
|
361
|
+
expect(subject.dump_message(id)).to have_key(:body)
|
367
362
|
end
|
368
363
|
|
369
364
|
end
|
@@ -373,7 +368,7 @@ describe Postmark::ApiClient do
|
|
373
368
|
expect(http_client).to receive(:get).
|
374
369
|
with("messages/inbound/#{id}/dump", {}).
|
375
370
|
and_return(response)
|
376
|
-
subject.dump_message(id, :inbound => true).
|
371
|
+
expect(subject.dump_message(id, :inbound => true)).to have_key(:body)
|
377
372
|
end
|
378
373
|
end
|
379
374
|
end
|
@@ -500,10 +495,7 @@ describe Postmark::ApiClient do
|
|
500
495
|
let(:response) {{'Opens' => [], 'TotalCount' => 0}}
|
501
496
|
|
502
497
|
it 'performs a GET request to /messages/outbound/opens' do
|
503
|
-
allow(http_client).
|
504
|
-
to receive(:get).with("messages/outbound/opens/#{message_id}",
|
505
|
-
options).
|
506
|
-
and_return(response)
|
498
|
+
allow(http_client).to receive(:get).with("messages/outbound/opens/#{message_id}", options).and_return(response)
|
507
499
|
expect(subject.get_opens_by_message_id(message_id, options)).to be_an(Array)
|
508
500
|
expect(subject.get_opens_by_message_id(message_id, options).count).to be_zero
|
509
501
|
end
|
@@ -516,10 +508,7 @@ describe Postmark::ApiClient do
|
|
516
508
|
let(:response) {{'Clicks' => [], 'TotalCount' => 0}}
|
517
509
|
|
518
510
|
it 'performs a GET request to /messages/outbound/clicks' do
|
519
|
-
allow(http_client).
|
520
|
-
to receive(:get).with("messages/outbound/clicks/#{message_id}",
|
521
|
-
options).
|
522
|
-
and_return(response)
|
511
|
+
allow(http_client).to receive(:get).with("messages/outbound/clicks/#{message_id}", options).and_return(response)
|
523
512
|
expect(subject.get_clicks_by_message_id(message_id, options)).to be_an(Array)
|
524
513
|
expect(subject.get_clicks_by_message_id(message_id, options).count).to be_zero
|
525
514
|
end
|
@@ -702,7 +691,7 @@ describe Postmark::ApiClient do
|
|
702
691
|
|
703
692
|
it 'requests server info from Postmark and converts it to ruby format' do
|
704
693
|
expect(http_client).to receive(:get).with('server') {response}
|
705
|
-
subject.server_info.
|
694
|
+
expect(subject.server_info).to have_key(:inbound_hash)
|
706
695
|
end
|
707
696
|
end
|
708
697
|
|
@@ -716,7 +705,7 @@ describe Postmark::ApiClient do
|
|
716
705
|
|
717
706
|
it 'updates server info in Postmark and converts it to ruby format' do
|
718
707
|
expect(http_client).to receive(:put).with('server', anything) {response}
|
719
|
-
subject.update_server_info(update)[:smtp_api_activated].
|
708
|
+
expect(subject.update_server_info(update)[:smtp_api_activated]).to be false
|
720
709
|
end
|
721
710
|
end
|
722
711
|
|
@@ -967,8 +956,7 @@ describe Postmark::ApiClient do
|
|
967
956
|
|
968
957
|
it 'converts response to ruby format' do
|
969
958
|
expect(http_client).to receive(:post).with('email/withTemplate', json_representation_of(email)) {response}
|
970
|
-
|
971
|
-
r.should have_key(:message_id)
|
959
|
+
expect(subject.deliver_with_template(message_hash)).to have_key(:message_id)
|
972
960
|
end
|
973
961
|
end
|
974
962
|
|
@@ -1039,9 +1027,9 @@ describe Postmark::ApiClient do
|
|
1039
1027
|
|
1040
1028
|
it 'converts response to ruby format' do
|
1041
1029
|
expect(http_client).to receive(:get).with('stats/outbound', {:tag => 'foo'}) {response}
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1030
|
+
response = subject.get_stats_totals(:tag => 'foo')
|
1031
|
+
expect(response).to have_key(:sent)
|
1032
|
+
expect(response).to have_key(:bounce_rate)
|
1045
1033
|
end
|
1046
1034
|
end
|
1047
1035
|
|
@@ -1073,38 +1061,35 @@ describe Postmark::ApiClient do
|
|
1073
1061
|
|
1074
1062
|
it 'converts response to ruby format' do
|
1075
1063
|
expect(http_client).to receive(:get).with('stats/outbound/sends', {:tag => 'foo'}) {response}
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1064
|
+
response = subject.get_stats_counts(:sends, :tag => 'foo')
|
1065
|
+
expect(response).to have_key(:days)
|
1066
|
+
expect(response).to have_key(:sent)
|
1079
1067
|
|
1080
|
-
first_day =
|
1081
|
-
|
1082
|
-
first_day.
|
1083
|
-
first_day.should have_key(:sent)
|
1068
|
+
first_day = response[:days].first
|
1069
|
+
expect(first_day).to have_key(:date)
|
1070
|
+
expect(first_day).to have_key(:sent)
|
1084
1071
|
end
|
1085
1072
|
|
1086
1073
|
it 'uses fromdate that is passed in' do
|
1087
1074
|
expect(http_client).to receive(:get).with('stats/outbound/sends', {:tag => 'foo', :fromdate => '2015-01-01'}) {response}
|
1088
|
-
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1092
|
-
first_day = r[:days].first
|
1075
|
+
response = subject.get_stats_counts(:sends, :tag => 'foo', :fromdate => '2015-01-01')
|
1076
|
+
expect(response).to have_key(:days)
|
1077
|
+
expect(response).to have_key(:sent)
|
1093
1078
|
|
1094
|
-
first_day
|
1095
|
-
first_day.
|
1079
|
+
first_day = response[:days].first
|
1080
|
+
expect(first_day).to have_key(:date)
|
1081
|
+
expect(first_day).to have_key(:sent)
|
1096
1082
|
end
|
1097
1083
|
|
1098
1084
|
it 'uses stats type that is passed in' do
|
1099
1085
|
expect(http_client).to receive(:get).with('stats/outbound/opens/readtimes', {:tag => 'foo', :type => :readtimes}) {response}
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
first_day = r[:days].first
|
1086
|
+
response = subject.get_stats_counts(:opens, :type => :readtimes, :tag => 'foo')
|
1087
|
+
expect(response).to have_key(:days)
|
1088
|
+
expect(response).to have_key(:sent)
|
1105
1089
|
|
1106
|
-
first_day
|
1107
|
-
first_day.
|
1090
|
+
first_day = response[:days].first
|
1091
|
+
expect(first_day).to have_key(:date)
|
1092
|
+
expect(first_day).to have_key(:sent)
|
1108
1093
|
end
|
1109
1094
|
end
|
1110
1095
|
end
|
@@ -15,49 +15,46 @@ describe Postmark::Bounce do
|
|
15
15
|
:subject => "Hello from our app!"} }
|
16
16
|
let(:bounce_data_postmark) { Postmark::HashHelper.to_postmark(bounce_data) }
|
17
17
|
let(:bounces_data) { [bounce_data, bounce_data, bounce_data] }
|
18
|
-
|
19
18
|
let(:bounce) { Postmark::Bounce.new(bounce_data) }
|
20
19
|
|
21
20
|
subject { bounce }
|
22
21
|
|
23
22
|
context "attr readers" do
|
24
|
-
|
25
|
-
it {
|
26
|
-
it {
|
27
|
-
it {
|
28
|
-
it {
|
29
|
-
it {
|
30
|
-
it {
|
31
|
-
it {
|
32
|
-
it {
|
33
|
-
it {
|
34
|
-
it {
|
35
|
-
it { should respond_to(:subject) }
|
36
|
-
|
23
|
+
it { expect(subject).to respond_to(:email) }
|
24
|
+
it { expect(subject).to respond_to(:bounced_at) }
|
25
|
+
it { expect(subject).to respond_to(:type) }
|
26
|
+
it { expect(subject).to respond_to(:description) }
|
27
|
+
it { expect(subject).to respond_to(:details) }
|
28
|
+
it { expect(subject).to respond_to(:name) }
|
29
|
+
it { expect(subject).to respond_to(:id) }
|
30
|
+
it { expect(subject).to respond_to(:server_id) }
|
31
|
+
it { expect(subject).to respond_to(:tag) }
|
32
|
+
it { expect(subject).to respond_to(:message_id) }
|
33
|
+
it { expect(subject).to respond_to(:subject) }
|
37
34
|
end
|
38
35
|
|
39
36
|
context "given a bounce created from bounce_data" do
|
40
37
|
|
41
38
|
it 'is not inactive' do
|
42
|
-
|
39
|
+
expect(subject).not_to be_inactive
|
43
40
|
end
|
44
41
|
|
45
42
|
it 'allows to activate the bounce' do
|
46
|
-
subject.can_activate
|
43
|
+
expect(subject.can_activate?).to be true
|
47
44
|
end
|
48
45
|
|
49
46
|
it 'has an available dump' do
|
50
|
-
subject.dump_available
|
47
|
+
expect(subject.dump_available?).to be true
|
51
48
|
end
|
52
49
|
|
53
|
-
its(:type) {
|
54
|
-
its(:message_id) {
|
55
|
-
its(:description) {
|
56
|
-
its(:details) {
|
57
|
-
its(:email) {
|
58
|
-
its(:bounced_at) {
|
59
|
-
its(:id) {
|
60
|
-
its(:subject) {
|
50
|
+
its(:type) { is_expected.to eq bounce_data[:type] }
|
51
|
+
its(:message_id) { is_expected.to eq bounce_data[:message_id] }
|
52
|
+
its(:description) { is_expected.to eq bounce_data[:description] }
|
53
|
+
its(:details) { is_expected.to eq bounce_data[:details] }
|
54
|
+
its(:email) { is_expected.to eq bounce_data[:email] }
|
55
|
+
its(:bounced_at) { is_expected.to eq Time.parse(bounce_data[:bounced_at]) }
|
56
|
+
its(:id) { is_expected.to eq bounce_data[:id] }
|
57
|
+
its(:subject) { is_expected.to eq bounce_data[:subject] }
|
61
58
|
|
62
59
|
end
|
63
60
|
|
@@ -65,49 +62,44 @@ describe Postmark::Bounce do
|
|
65
62
|
subject { Postmark::Bounce.new(bounce_data_postmark) }
|
66
63
|
|
67
64
|
it 'is not inactive' do
|
68
|
-
|
65
|
+
expect(subject).not_to be_inactive
|
69
66
|
end
|
70
67
|
|
71
68
|
it 'allows to activate the bounce' do
|
72
|
-
subject.can_activate
|
69
|
+
expect(subject.can_activate?).to be true
|
73
70
|
end
|
74
71
|
|
75
72
|
it 'has an available dump' do
|
76
|
-
subject.dump_available
|
73
|
+
expect(subject.dump_available?).to be true
|
77
74
|
end
|
78
75
|
|
79
|
-
its(:type) {
|
80
|
-
its(:message_id) {
|
81
|
-
its(:details) {
|
82
|
-
its(:email) {
|
83
|
-
its(:bounced_at) {
|
84
|
-
its(:id) {
|
85
|
-
its(:subject) {
|
86
|
-
|
76
|
+
its(:type) { is_expected.to eq bounce_data[:type] }
|
77
|
+
its(:message_id) { is_expected.to eq bounce_data[:message_id] }
|
78
|
+
its(:details) { is_expected.to eq bounce_data[:details] }
|
79
|
+
its(:email) { is_expected.to eq bounce_data[:email] }
|
80
|
+
its(:bounced_at) { is_expected.to eq Time.parse(bounce_data[:bounced_at]) }
|
81
|
+
its(:id) { is_expected.to eq bounce_data[:id] }
|
82
|
+
its(:subject) { is_expected.to eq bounce_data[:subject] }
|
87
83
|
end
|
88
84
|
|
89
85
|
describe "#dump" do
|
90
|
-
|
91
86
|
let(:bounce_body) { double }
|
92
87
|
let(:response) { {:body => bounce_body} }
|
93
88
|
let(:api_client) { Postmark.api_client }
|
94
89
|
|
95
90
|
it "calls #dump_bounce on shared api_client instance" do
|
96
91
|
expect(Postmark.api_client).to receive(:dump_bounce).with(bounce.id) { response }
|
97
|
-
bounce.dump.
|
92
|
+
expect(bounce.dump).to eq bounce_body
|
98
93
|
end
|
99
|
-
|
100
94
|
end
|
101
95
|
|
102
96
|
describe "#activate" do
|
103
|
-
|
104
97
|
let(:api_client) { Postmark.api_client }
|
105
98
|
|
106
99
|
it "calls #activate_bounce on shared api_client instance" do
|
107
100
|
expect(api_client).to receive(:activate_bounce).with(bounce.id) { bounce_data }
|
108
|
-
bounce.activate.
|
101
|
+
expect(bounce.activate).to be_a Postmark::Bounce
|
109
102
|
end
|
110
|
-
|
111
103
|
end
|
112
104
|
|
113
105
|
describe ".find" do
|
@@ -115,31 +107,27 @@ describe Postmark::Bounce do
|
|
115
107
|
|
116
108
|
it "calls #get_bounce on shared api_client instance" do
|
117
109
|
expect(api_client).to receive(:get_bounce).with(42) { bounce_data }
|
118
|
-
Postmark::Bounce.find(42).
|
110
|
+
expect(Postmark::Bounce.find(42)).to be_a Postmark::Bounce
|
119
111
|
end
|
120
112
|
end
|
121
113
|
|
122
114
|
describe ".all" do
|
123
|
-
|
124
115
|
let(:response) { bounces_data }
|
125
116
|
let(:api_client) { Postmark.api_client }
|
126
117
|
|
127
118
|
it "calls #get_bounces on shared api_client instance" do
|
128
119
|
expect(api_client).to receive(:get_bounces) { response }
|
129
|
-
Postmark::Bounce.all.count.
|
120
|
+
expect(Postmark::Bounce.all.count).to eq(3)
|
130
121
|
end
|
131
|
-
|
132
122
|
end
|
133
123
|
|
134
124
|
describe ".tags" do
|
135
|
-
|
136
125
|
let(:api_client) { Postmark.api_client }
|
137
126
|
let(:tags) { ["tag1", "tag2"] }
|
138
127
|
|
139
128
|
it "calls #get_bounced_tags on shared api_client instance" do
|
140
129
|
expect(api_client).to receive(:get_bounced_tags) { tags }
|
141
|
-
Postmark::Bounce.tags.
|
130
|
+
expect(Postmark::Bounce.tags).to eq tags
|
142
131
|
end
|
143
132
|
end
|
144
|
-
|
145
133
|
end
|