postmark 1.21.5 → 1.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -97,6 +97,13 @@ describe(Postmark::ApiInputError) do
97
97
  it_behaves_like 'api input error'
98
98
  end
99
99
 
100
+ context '300' do
101
+ let(:code) {Postmark::ApiInputError::INVALID_EMAIL_ADDRESS}
102
+
103
+ it {is_expected.to be_a(Postmark::InvalidEmailAddressError)}
104
+ it_behaves_like 'api input error'
105
+ end
106
+
100
107
  context 'others' do
101
108
  let(:code) {'9999'}
102
109
 
@@ -142,6 +149,33 @@ describe(Postmark::MailAdapterError) do
142
149
  it {is_expected.to be_a(Postmark::Error)}
143
150
  end
144
151
 
152
+ describe(Postmark::InvalidEmailAddressError) do
153
+ describe '.new' do
154
+ let(:response) {{'Message' => message}}
155
+
156
+ subject do
157
+ Postmark::InvalidEmailAddressError.new(
158
+ Postmark::ApiInputError::INVALID_EMAIL_ADDRESS, Postmark::Json.encode(response), response)
159
+ end
160
+
161
+ let(:message) do
162
+ "Error parsing 'To': Illegal email address 'johne.xample.com'. It must contain the '@' symbol."
163
+ end
164
+
165
+ it 'body is set' do
166
+ expect(subject.body).to eq(Postmark::Json.encode(response))
167
+ end
168
+
169
+ it 'parsed body is set' do
170
+ expect(subject.parsed_body).to eq(response)
171
+ end
172
+
173
+ it 'error code is set' do
174
+ expect(subject.error_code).to eq(Postmark::ApiInputError::INVALID_EMAIL_ADDRESS)
175
+ end
176
+ end
177
+ end
178
+
145
179
  describe(Postmark::InactiveRecipientError) do
146
180
  describe '.parse_recipients' do
147
181
  let(:recipients) do
@@ -161,6 +195,12 @@ describe(Postmark::InactiveRecipientError) do
161
195
  it {is_expected.to eq(recipients.take(1))}
162
196
  end
163
197
 
198
+ context 'i/n inactive, n > 1, i < n - new message format' do
199
+ let(:message) { "Message OK, but will not deliver to these inactive addresses: #{recipients[0...2].join(', ')}" }
200
+
201
+ it {is_expected.to eq(recipients.take(2))}
202
+ end
203
+
164
204
  context 'i/n inactive, n > 1, i < n' do
165
205
  let(:message) do
166
206
  'Message OK, but will not deliver to these inactive addresses: ' \
@@ -209,6 +249,18 @@ describe(Postmark::InactiveRecipientError) do
209
249
  it 'parses recipients from json payload' do
210
250
  expect(subject.recipients).to eq([address])
211
251
  end
252
+
253
+ it 'body is set' do
254
+ expect(subject.body).to eq(Postmark::Json.encode(response))
255
+ end
256
+
257
+ it 'parsed body is set' do
258
+ expect(subject.parsed_body).to eq(response)
259
+ end
260
+
261
+ it 'error code is set' do
262
+ expect(subject.error_code).to eq(Postmark::ApiInputError::INACTIVE_RECIPIENT)
263
+ end
212
264
  end
213
265
  end
214
266
 
@@ -2,32 +2,119 @@ require 'spec_helper'
2
2
 
3
3
  describe Postmark::HashHelper do
4
4
  describe ".to_postmark" do
5
- let(:source) { {:from => "support@postmarkapp.com", :reply_to => "contact@wildbit.com"} }
6
- let(:target) { {"From" => "support@postmarkapp.com", "ReplyTo" => "contact@wildbit.com"} }
5
+ let(:source) do
6
+ {
7
+ :level_one => {
8
+ :level_two => {
9
+ :level_three => [{ :array_item => 1 }]
10
+ }
11
+ }
12
+ }
13
+ end
14
+
15
+ describe 'default behaviour' do
16
+ let(:target) do
17
+ {
18
+ 'LevelOne' => {
19
+ :level_two => {
20
+ :level_three => [{ :array_item => 1 }]
21
+ }
22
+ }
23
+ }
24
+ end
25
+
26
+ it 'does not convert nested elements' do
27
+ expect(subject.to_postmark(source)).to eq(target)
28
+ end
29
+ end
30
+
31
+ describe 'deep conversion' do
32
+ let(:target) do
33
+ {
34
+ 'LevelOne' => {
35
+ 'LevelTwo' => {
36
+ 'LevelThree' => [{ 'ArrayItem' => 1 }]
37
+ }
38
+ }
39
+ }
40
+ end
7
41
 
8
- it 'converts Hash keys to Postmark format' do
9
- expect(subject.to_postmark(source)).to eq target
42
+ it 'converts nested elements when requested' do
43
+ expect(subject.to_postmark(source, :deep => true)).to eq(target)
44
+ end
10
45
  end
11
46
 
12
- it 'acts idempotentely' do
13
- expect(subject.to_postmark(target)).to eq target
47
+ it 'leaves CamelCase keys untouched' do
48
+ expect(subject.to_postmark('ReplyTo' => 'alice@example.com')).to eq('ReplyTo' => 'alice@example.com')
14
49
  end
15
50
  end
16
51
 
17
52
  describe ".to_ruby" do
18
- let(:source) { {"From" => "support@postmarkapp.com", "ReplyTo" => "contact@wildbit.com"} }
19
- let(:target) { {:from => "support@postmarkapp.com", :reply_to => "contact@wildbit.com"} }
53
+ let(:source) do
54
+ {
55
+ 'LevelOne' => {
56
+ 'LevelTwo' => {
57
+ 'LevelThree' => [{ 'ArrayItem' => 1 }]
58
+ }
59
+ }
60
+ }
61
+ end
20
62
 
21
- it 'converts Hash keys to Ruby format' do
22
- expect(subject.to_ruby(source)).to eq target
63
+ describe 'default behaviour' do
64
+ let(:target) do
65
+ {
66
+ :level_one => {
67
+ 'LevelTwo' => {
68
+ 'LevelThree' => [{ 'ArrayItem' => 1 }]
69
+ }
70
+ }
71
+ }
72
+ end
73
+
74
+ it 'does not convert nested elements' do
75
+ expect(subject.to_ruby(source)).to eq(target)
76
+ end
23
77
  end
24
78
 
25
- it 'has compatible mode' do
26
- expect(subject.to_ruby(source, true)).to eq target.merge(source)
79
+ describe 'deep conversion' do
80
+ let(:target) do
81
+ {
82
+ :level_one => {
83
+ :level_two => {
84
+ :level_three => [{ :array_item => 1 }]
85
+ }
86
+ }
87
+ }
88
+ end
89
+
90
+ it 'converts nested elements when requested' do
91
+ expect(subject.to_ruby(source, :deep => true)).to eq(target)
92
+ end
93
+ end
94
+
95
+ describe 'compatibility mode' do
96
+ let(:target) do
97
+ {
98
+ :level_one => {
99
+ 'LevelTwo' => {
100
+ 'LevelThree' => [{ 'ArrayItem' => 1 }]
101
+ }
102
+ },
103
+ 'LevelOne' => {
104
+ 'LevelTwo' => {
105
+ 'LevelThree' => [{ 'ArrayItem' => 1 }]
106
+ }
107
+ }
108
+ }
109
+ end
110
+
111
+ it 'preserves the original structure' do
112
+ expect(subject.to_ruby(source, :compatible => true)).to eq target
113
+ end
27
114
  end
28
115
 
29
- it 'acts idempotentely' do
30
- expect(subject.to_ruby(target)).to eq target
116
+ it 'leaves symbol keys untouched' do
117
+ expect(subject.to_ruby(:reply_to => 'alice@example.com')).to eq(:reply_to => 'alice@example.com')
31
118
  end
32
119
  end
33
120
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postmark
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.21.5
4
+ version: 1.22.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomek Maszkowski
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2021-07-22 00:00:00.000000000 Z
16
+ date: 2021-08-25 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: json
@@ -71,6 +71,8 @@ files:
71
71
  - ".gitignore"
72
72
  - ".rake_tasks"
73
73
  - ".rspec"
74
+ - ".ruby-gemset"
75
+ - ".ruby-version"
74
76
  - CHANGELOG.rdoc
75
77
  - CONTRIBUTING.md
76
78
  - Gemfile
@@ -150,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
152
  - !ruby/object:Gem::Version
151
153
  version: 1.3.7
152
154
  requirements: []
153
- rubygems_version: 3.2.3
155
+ rubygems_version: 3.0.8
154
156
  signing_key:
155
157
  specification_version: 4
156
158
  summary: Official Postmark API wrapper.