sendgrid4r 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.env.example +5 -0
- data/.rubocop.yml +8 -8
- data/README.md +2 -0
- data/lib/auth.rb +5 -2
- data/lib/client.rb +4 -2
- data/lib/sendgrid4r/factory/version_factory.rb +1 -1
- data/lib/sendgrid4r/rest/api.rb +4 -0
- data/lib/sendgrid4r/rest/api_keys/api_keys.rb +73 -0
- data/lib/sendgrid4r/rest/asm/asm.rb +28 -0
- data/lib/sendgrid4r/rest/asm/global_suppressions.rb +12 -8
- data/lib/sendgrid4r/rest/asm/groups.rb +29 -22
- data/lib/sendgrid4r/rest/asm/suppressions.rb +25 -15
- data/lib/sendgrid4r/rest/categories/categories.rb +19 -9
- data/lib/sendgrid4r/rest/contacts/custom_fields.rb +14 -8
- data/lib/sendgrid4r/rest/contacts/lists.rb +32 -20
- data/lib/sendgrid4r/rest/contacts/recipients.rb +42 -31
- data/lib/sendgrid4r/rest/contacts/reserved_fields.rb +6 -2
- data/lib/sendgrid4r/rest/contacts/segments.rb +22 -12
- data/lib/sendgrid4r/rest/ips/addresses.rb +36 -22
- data/lib/sendgrid4r/rest/ips/pools.rb +31 -16
- data/lib/sendgrid4r/rest/ips/warmup.rb +34 -15
- data/lib/sendgrid4r/rest/request.rb +33 -19
- data/lib/sendgrid4r/rest/settings/enforced_tls.rb +12 -5
- data/lib/sendgrid4r/rest/stats/advanced.rb +73 -25
- data/lib/sendgrid4r/rest/stats/category.rb +11 -6
- data/lib/sendgrid4r/rest/stats/global.rb +6 -4
- data/lib/sendgrid4r/rest/stats/parse.rb +10 -4
- data/lib/sendgrid4r/rest/stats/stats.rb +13 -18
- data/lib/sendgrid4r/rest/stats/subuser.rb +10 -6
- data/lib/sendgrid4r/rest/templates/templates.rb +23 -16
- data/lib/sendgrid4r/rest/templates/versions.rb +39 -36
- data/lib/sendgrid4r/version.rb +1 -1
- data/spec/api_keys/api_keys_spec.rb +152 -0
- data/spec/asm/asm_spec.rb +33 -0
- data/spec/asm/global_suppressions_spec.rb +111 -45
- data/spec/asm/groups_spec.rb +172 -48
- data/spec/asm/suppressions_spec.rb +180 -54
- data/spec/categories/categories_spec.rb +81 -25
- data/spec/client_spec.rb +11 -4
- data/spec/contacts/custom_fields_spec.rb +135 -44
- data/spec/contacts/lists_spec.rb +314 -84
- data/spec/contacts/recipients_spec.rb +337 -92
- data/spec/contacts/reserved_fields_spec.rb +80 -60
- data/spec/contacts/segments_spec.rb +219 -88
- data/spec/factory/condition_factory_spec.rb +12 -12
- data/spec/factory/segment_factory_spec.rb +19 -19
- data/spec/factory/version_factory_spec.rb +6 -6
- data/spec/ips/addresses_spec.rb +177 -84
- data/spec/ips/pools_spec.rb +190 -34
- data/spec/ips/warmup_spec.rb +106 -38
- data/spec/settings/enforced_tls_spec.rb +76 -18
- data/spec/stats/advanced_spec.rb +373 -196
- data/spec/stats/category_spec.rb +133 -71
- data/spec/stats/global_spec.rb +74 -47
- data/spec/stats/parse_spec.rb +46 -29
- data/spec/stats/stats_spec.rb +246 -0
- data/spec/stats/subuser_spec.rb +99 -54
- data/spec/templates/templates_spec.rb +219 -54
- data/spec/templates/versions_spec.rb +171 -67
- metadata +10 -2
@@ -1,28 +1,26 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require File.dirname(__FILE__) + '/../spec_helper'
|
3
3
|
|
4
|
-
describe
|
5
|
-
|
6
|
-
|
7
|
-
@client = SendGrid4r::Client.new(
|
8
|
-
ENV['SENDGRID_USERNAME'], ENV['SENDGRID_PASSWORD'])
|
9
|
-
@email1 = 'jones@example.com'
|
10
|
-
@email2 = 'miller@example.com'
|
11
|
-
@last_name1 = 'Jones'
|
12
|
-
@last_name2 = 'Miller'
|
13
|
-
@pet1 = 'Fluffy'
|
14
|
-
@pet2 = 'FrouFrou'
|
15
|
-
@custom_field_name = 'pet'
|
16
|
-
end
|
17
|
-
|
18
|
-
context 'always' do
|
19
|
-
it 'is normal' do
|
4
|
+
describe SendGrid4r::REST::Contacts::Recipients do
|
5
|
+
describe 'integration test' do
|
6
|
+
before do
|
20
7
|
begin
|
8
|
+
Dotenv.load
|
9
|
+
@client = SendGrid4r::Client.new(
|
10
|
+
username: ENV['SENDGRID_USERNAME'],
|
11
|
+
password: ENV['SENDGRID_PASSWORD'])
|
12
|
+
@email1 = 'jones@example.com'
|
13
|
+
@email2 = 'miller@example.com'
|
14
|
+
@last_name1 = 'Jones'
|
15
|
+
@last_name2 = 'Miller'
|
16
|
+
@pet1 = 'Fluffy'
|
17
|
+
@pet2 = 'FrouFrou'
|
18
|
+
@custom_field_name = 'pet'
|
19
|
+
|
21
20
|
# celan up test env
|
22
21
|
recipients = @client.get_recipients
|
23
|
-
expect(recipients.recipients.length >= 0).to eq(true)
|
24
22
|
recipients.recipients.each do |recipient|
|
25
|
-
next if recipient.email != @email1
|
23
|
+
next if recipient.email != @email1 && recipient.email != @email2
|
26
24
|
@client.delete_recipient(recipient.id)
|
27
25
|
end
|
28
26
|
custom_fields = @client.get_custom_fields
|
@@ -36,64 +34,314 @@ describe 'SendGrid4r::REST::Contacts::Recipients' do
|
|
36
34
|
params['email'] = @email1
|
37
35
|
params['last_name'] = @last_name1
|
38
36
|
params[@custom_field_name] = @pet1
|
39
|
-
new_recipient = @client.post_recipient(params)
|
40
|
-
|
41
|
-
|
37
|
+
@new_recipient = @client.post_recipient(params)
|
38
|
+
rescue => e
|
39
|
+
puts e.inspect
|
40
|
+
raise e
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'without block call' do
|
45
|
+
it '#post_recipient' do
|
46
|
+
begin
|
47
|
+
params = {}
|
48
|
+
params['email'] = @email2
|
49
|
+
params['last_name'] = @last_name2
|
50
|
+
params[@custom_field_name] = @pet2
|
51
|
+
new_recipient = @client.post_recipient(params)
|
52
|
+
expect(new_recipient.created_at).to be_a(Time)
|
53
|
+
new_recipient.custom_fields.each do |custom_field|
|
54
|
+
expect(
|
55
|
+
custom_field
|
56
|
+
).to be_a(SendGrid4r::REST::Contacts::CustomFields::Field)
|
57
|
+
end
|
58
|
+
expect(new_recipient.email).to eq(@email2)
|
59
|
+
expect(new_recipient.first_name).to eq(nil)
|
60
|
+
expect(new_recipient.id).to eq(@email2)
|
61
|
+
expect(new_recipient.last_clicked).to eq(nil)
|
62
|
+
expect(new_recipient.last_emailed).to eq(nil)
|
63
|
+
expect(new_recipient.last_name).to eq(@last_name2)
|
64
|
+
expect(new_recipient.last_opened).to eq(nil)
|
65
|
+
expect(new_recipient.updated_at).to be_a(Time)
|
66
|
+
rescue => e
|
67
|
+
puts e.inspect
|
68
|
+
raise e
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
it '#post_recipient for same key' do
|
73
|
+
begin
|
74
|
+
params = {}
|
75
|
+
params['email'] = @email1
|
76
|
+
params['last_name'] = @last_name1
|
77
|
+
params[@custom_field_name] = @pet1
|
78
|
+
@client.post_recipient(params)
|
79
|
+
rescue => e
|
80
|
+
puts e.inspect
|
81
|
+
raise e
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
it '#get_recipients' do
|
86
|
+
begin
|
87
|
+
recipients = @client.get_recipients(100, 0)
|
88
|
+
expect(recipients.recipients.length).to be > 0
|
89
|
+
recipients.recipients.each do |recipient|
|
90
|
+
expect(
|
91
|
+
recipient
|
92
|
+
).to be_a(SendGrid4r::REST::Contacts::Recipients::Recipient)
|
93
|
+
end
|
94
|
+
rescue => e
|
95
|
+
puts e.inspect
|
96
|
+
raise e
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
it '#get_recipient_count' do
|
101
|
+
begin
|
102
|
+
actual_count = @client.get_recipients_count
|
103
|
+
expect(actual_count).to be >= 0
|
104
|
+
rescue => e
|
105
|
+
puts e.inspect
|
106
|
+
raise e
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
it '#search_recipients' do
|
111
|
+
begin
|
112
|
+
params = {}
|
113
|
+
params['email'] = @email1
|
114
|
+
recipients = @client.search_recipients(params)
|
115
|
+
expect(recipients.recipients).to be_a(Array)
|
116
|
+
rescue => e
|
117
|
+
puts e.inspect
|
118
|
+
raise e
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
it '#get_recipient' do
|
123
|
+
begin
|
124
|
+
recipient = @client.get_recipient(@new_recipient.id)
|
42
125
|
expect(
|
43
|
-
|
44
|
-
|
126
|
+
recipient
|
127
|
+
).to be_a(SendGrid4r::REST::Contacts::Recipients::Recipient)
|
128
|
+
rescue => e
|
129
|
+
puts e.inspect
|
130
|
+
raise e
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
it '#get_lists_recipient_belong' do
|
135
|
+
begin
|
136
|
+
lists = @client.get_lists_recipient_belong(@new_recipient.id)
|
137
|
+
lists.lists.each do |list|
|
138
|
+
expect(
|
139
|
+
list.is_a?(SendGrid4r::REST::Contacts::Lists::List)
|
140
|
+
).to eq(true)
|
141
|
+
end
|
142
|
+
rescue => e
|
143
|
+
puts e.inspect
|
144
|
+
raise e
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
it '#post_recipients' do
|
149
|
+
begin
|
150
|
+
recipient1 = {}
|
151
|
+
recipient1['email'] = @email1
|
152
|
+
recipient1['last_name'] = @last_name1
|
153
|
+
recipient1[@custom_field_name] = @pet1
|
154
|
+
recipient2 = {}
|
155
|
+
recipient2['email'] = @email2
|
156
|
+
recipient2['last_name'] = @last_name2
|
157
|
+
recipient2[@custom_field_name] = @pet2
|
158
|
+
params = [recipient1, recipient2]
|
159
|
+
result = @client.post_recipients(params)
|
160
|
+
expect(result.error_count).to eq(0)
|
161
|
+
result.error_indices.each do |index|
|
162
|
+
expect(index).to be_a(Fixnum)
|
163
|
+
end
|
164
|
+
expect(result.new_count).to be_a(Fixnum)
|
165
|
+
expect(result.updated_count).to be_a(Fixnum)
|
166
|
+
rescue => e
|
167
|
+
puts e.inspect
|
168
|
+
raise e
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
it '#get_recipients_by_id' do
|
173
|
+
begin
|
174
|
+
recipient_ids = [@email1, @email2]
|
175
|
+
actual_recipients = @client.get_recipients_by_id(recipient_ids)
|
176
|
+
expect(actual_recipients.recipients).to be_a(Array)
|
177
|
+
expect(actual_recipients.recipients.length).to eq(1)
|
178
|
+
actual_recipients.recipients.each do |recip|
|
179
|
+
expect(
|
180
|
+
recip
|
181
|
+
).to be_a(SendGrid4r::REST::Contacts::Recipients::Recipient)
|
182
|
+
end
|
183
|
+
rescue => e
|
184
|
+
puts e.inspect
|
185
|
+
raise e
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
it '#delete_recipient' do
|
190
|
+
begin
|
191
|
+
@client.delete_recipient(@new_recipient.id)
|
192
|
+
expect do
|
193
|
+
@client.get_recipient(@new_recipient.id)
|
194
|
+
end.to raise_error(RestClient::ResourceNotFound)
|
195
|
+
rescue => e
|
196
|
+
puts e.inspect
|
197
|
+
raise e
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
it '#delete_recipients' do
|
202
|
+
begin
|
203
|
+
@client.delete_recipients([@email1, @email2])
|
204
|
+
rescue => e
|
205
|
+
puts e.inspect
|
206
|
+
raise e
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
context 'with block call' do
|
212
|
+
it '#post_recipient' do
|
213
|
+
params = {}
|
214
|
+
params['email'] = @email2
|
215
|
+
params['last_name'] = @last_name2
|
216
|
+
params[@custom_field_name] = @pet2
|
217
|
+
@client.post_recipient(params) do |resp, req, res|
|
218
|
+
resp =
|
219
|
+
SendGrid4r::REST::Contacts::Recipients.create_recipient(
|
220
|
+
JSON.parse(resp)
|
45
221
|
)
|
46
|
-
).to
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
expect(new_recipient.last_clicked).to eq(nil)
|
52
|
-
expect(new_recipient.last_emailed).to eq(nil)
|
53
|
-
expect(new_recipient.last_name).to eq(@last_name1)
|
54
|
-
expect(new_recipient.last_opened).to eq(nil)
|
55
|
-
expect(new_recipient.updated_at.is_a?(Fixnum)).to eq(true)
|
56
|
-
# post same recipients
|
57
|
-
@client.post_recipient(params)
|
58
|
-
# get all recipients
|
59
|
-
recipients = @client.get_recipients(100, 0)
|
60
|
-
expect(recipients.recipients.length > 0).to eq(true)
|
61
|
-
recipients.recipients.each do |recipient|
|
62
|
-
expect(
|
63
|
-
recipient.is_a?(SendGrid4r::REST::Contacts::Recipients::Recipient)
|
64
|
-
).to eq(true)
|
65
|
-
end
|
66
|
-
# get multiple recipients
|
67
|
-
recipient_ids = [@email1, @email2]
|
68
|
-
actual_recipients = @client.get_recipients_by_id(recipient_ids)
|
69
|
-
expect(actual_recipients.recipients.is_a?(Array)).to eq(true)
|
70
|
-
expect(actual_recipients.recipients.length).to eq(2)
|
71
|
-
actual_recipients.recipients.each do |recipient|
|
72
|
-
expect(
|
73
|
-
recipient.is_a?(SendGrid4r::REST::Contacts::Recipients::Recipient)
|
74
|
-
).to eq(true)
|
222
|
+
expect(resp).to be_a(
|
223
|
+
SendGrid4r::REST::Contacts::Recipients::Recipient
|
224
|
+
)
|
225
|
+
expect(req).to be_a(RestClient::Request)
|
226
|
+
expect(res).to be_a(Net::HTTPCreated)
|
75
227
|
end
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
# Search recipients
|
228
|
+
end
|
229
|
+
|
230
|
+
it '#delete_recipient' do
|
80
231
|
params = {}
|
81
232
|
params['email'] = @email1
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
).to eq(
|
233
|
+
params['last_name'] = @last_name1
|
234
|
+
params[@custom_field_name] = @pet1
|
235
|
+
recipient = @client.post_recipient(params)
|
236
|
+
@client.delete_recipient(recipient.id) do |resp, req, res|
|
237
|
+
expect(resp).to eq('')
|
238
|
+
expect(req).to be_a(RestClient::Request)
|
239
|
+
expect(res).to be_a(Net::HTTPNoContent)
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
it '#delete_recipients' do
|
244
|
+
@client.delete_recipients([@email1, @email2]) do |resp, req, res|
|
245
|
+
expect(resp).to eq('')
|
246
|
+
expect(req).to be_a(RestClient::Request)
|
247
|
+
expect(res).to be_a(Net::HTTPNoContent)
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
it '#get_recipients' do
|
252
|
+
@client.get_recipients do |resp, req, res|
|
253
|
+
resp =
|
254
|
+
SendGrid4r::REST::Contacts::Recipients.create_recipients(
|
255
|
+
JSON.parse(resp)
|
256
|
+
)
|
257
|
+
expect(resp).to be_a(
|
258
|
+
SendGrid4r::REST::Contacts::Recipients::Recipients
|
259
|
+
)
|
260
|
+
expect(req).to be_a(RestClient::Request)
|
261
|
+
expect(res).to be_a(Net::HTTPOK)
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
it '#get_recipients_by_id' do
|
266
|
+
params = {}
|
267
|
+
params['email'] = @email1
|
268
|
+
params['last_name'] = @last_name1
|
269
|
+
params[@custom_field_name] = @pet1
|
270
|
+
recipient = @client.post_recipient(params)
|
271
|
+
@client.get_recipients_by_id([recipient.id]) do |resp, req, res|
|
272
|
+
resp =
|
273
|
+
SendGrid4r::REST::Contacts::Recipients.create_recipients(
|
274
|
+
JSON.parse(resp)
|
275
|
+
)
|
276
|
+
expect(resp).to be_a(
|
277
|
+
SendGrid4r::REST::Contacts::Recipients::Recipients
|
278
|
+
)
|
279
|
+
expect(req).to be_a(RestClient::Request)
|
280
|
+
expect(res).to be_a(Net::HTTPOK)
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
it '#get_recipients_count' do
|
285
|
+
@client.get_recipients_count do |resp, req, res|
|
286
|
+
expect(JSON.parse(resp)['recipient_count']).to be_a(Fixnum)
|
287
|
+
expect(req).to be_a(RestClient::Request)
|
288
|
+
expect(res).to be_a(Net::HTTPOK)
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
it '#search_recipients' do
|
293
|
+
params = {}
|
294
|
+
params['email'] = @email1
|
295
|
+
@client.search_recipients(params) do |resp, req, res|
|
296
|
+
resp =
|
297
|
+
SendGrid4r::REST::Contacts::Recipients.create_recipients(
|
298
|
+
JSON.parse(resp)
|
299
|
+
)
|
300
|
+
expect(resp).to be_a(
|
301
|
+
SendGrid4r::REST::Contacts::Recipients::Recipients
|
302
|
+
)
|
303
|
+
expect(req).to be_a(RestClient::Request)
|
304
|
+
expect(res).to be_a(Net::HTTPOK)
|
95
305
|
end
|
96
|
-
|
306
|
+
end
|
307
|
+
|
308
|
+
it '#get_recipient' do
|
309
|
+
params = {}
|
310
|
+
params['email'] = @email1
|
311
|
+
params['last_name'] = @last_name1
|
312
|
+
params[@custom_field_name] = @pet1
|
313
|
+
recipient = @client.post_recipient(params)
|
314
|
+
@client.get_recipient(recipient.id) do |resp, req, res|
|
315
|
+
resp =
|
316
|
+
SendGrid4r::REST::Contacts::Recipients.create_recipient(
|
317
|
+
JSON.parse(resp)
|
318
|
+
)
|
319
|
+
expect(resp).to be_a(
|
320
|
+
SendGrid4r::REST::Contacts::Recipients::Recipient
|
321
|
+
)
|
322
|
+
expect(req).to be_a(RestClient::Request)
|
323
|
+
expect(res).to be_a(Net::HTTPOK)
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
it '#get_lists_recipient_belong' do
|
328
|
+
params = {}
|
329
|
+
params['email'] = @email1
|
330
|
+
params['last_name'] = @last_name1
|
331
|
+
params[@custom_field_name] = @pet1
|
332
|
+
recipient = @client.post_recipient(params)
|
333
|
+
@client.get_lists_recipient_belong(recipient.id) do |resp, req, res|
|
334
|
+
resp =
|
335
|
+
SendGrid4r::REST::Contacts::Lists.create_lists(
|
336
|
+
JSON.parse(resp)
|
337
|
+
)
|
338
|
+
expect(resp).to be_a(SendGrid4r::REST::Contacts::Lists::Lists)
|
339
|
+
expect(req).to be_a(RestClient::Request)
|
340
|
+
expect(res).to be_a(Net::HTTPOK)
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
344
|
+
it '#post_recipients' do
|
97
345
|
recipient1 = {}
|
98
346
|
recipient1['email'] = @email1
|
99
347
|
recipient1['last_name'] = @last_name1
|
@@ -103,26 +351,22 @@ describe 'SendGrid4r::REST::Contacts::Recipients' do
|
|
103
351
|
recipient2['last_name'] = @last_name2
|
104
352
|
recipient2[@custom_field_name] = @pet2
|
105
353
|
params = [recipient1, recipient2]
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
end.to raise_error(RestClient::ResourceNotFound)
|
118
|
-
# delete multiple recipients
|
119
|
-
@client.delete_recipients([@email1, @email2])
|
120
|
-
rescue => e
|
121
|
-
puts e.inspect
|
122
|
-
raise e
|
354
|
+
@client.post_recipients(params) do |resp, req, res|
|
355
|
+
resp =
|
356
|
+
SendGrid4r::REST::Contacts::Recipients.create_result(
|
357
|
+
JSON.parse(resp)
|
358
|
+
)
|
359
|
+
expect(resp).to be_a(
|
360
|
+
SendGrid4r::REST::Contacts::Recipients::ResultAddMultiple
|
361
|
+
)
|
362
|
+
expect(req).to be_a(RestClient::Request)
|
363
|
+
expect(res).to be_a(Net::HTTPCreated)
|
364
|
+
end
|
123
365
|
end
|
124
366
|
end
|
367
|
+
end
|
125
368
|
|
369
|
+
describe 'unit test' do
|
126
370
|
it 'creates recipient instance' do
|
127
371
|
json =
|
128
372
|
'{'\
|
@@ -146,7 +390,8 @@ describe 'SendGrid4r::REST::Contacts::Recipients' do
|
|
146
390
|
'}'
|
147
391
|
hash = JSON.parse(json)
|
148
392
|
actual = SendGrid4r::REST::Contacts::Recipients.create_recipient(hash)
|
149
|
-
expect(actual
|
393
|
+
expect(actual).to be_a(SendGrid4r::REST::Contacts::Recipients::Recipient)
|
394
|
+
expect(actual.created_at).to eq(Time.at(1422313607))
|
150
395
|
expect(actual.email).to eq('jones@example.com')
|
151
396
|
expect(actual.first_name).to eq(nil)
|
152
397
|
expect(actual.id).to eq('jones@example.com')
|
@@ -154,7 +399,7 @@ describe 'SendGrid4r::REST::Contacts::Recipients' do
|
|
154
399
|
expect(actual.last_emailed).to eq(nil)
|
155
400
|
expect(actual.last_name).to eq('Jones')
|
156
401
|
expect(actual.last_opened).to eq(nil)
|
157
|
-
expect(actual.updated_at).to eq(1422313790)
|
402
|
+
expect(actual.updated_at).to eq(Time.at(1422313790))
|
158
403
|
custom_field = actual.custom_fields[0]
|
159
404
|
expect(custom_field.id).to eq(23)
|
160
405
|
expect(custom_field.name).to eq('pet')
|
@@ -189,11 +434,11 @@ describe 'SendGrid4r::REST::Contacts::Recipients' do
|
|
189
434
|
'}'
|
190
435
|
hash = JSON.parse(json)
|
191
436
|
actual = SendGrid4r::REST::Contacts::Recipients.create_recipients(hash)
|
192
|
-
expect(actual.recipients
|
437
|
+
expect(actual.recipients).to be_a(Array)
|
193
438
|
actual.recipients.each do |recipient|
|
194
439
|
expect(
|
195
|
-
recipient
|
196
|
-
).to
|
440
|
+
recipient
|
441
|
+
).to be_a(SendGrid4r::REST::Contacts::Recipients::Recipient)
|
197
442
|
end
|
198
443
|
end
|
199
444
|
end
|
@@ -1,66 +1,87 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require File.dirname(__FILE__) + '/../spec_helper'
|
3
3
|
|
4
|
-
describe
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
4
|
+
describe SendGrid4r::REST::Contacts::ReservedFields do
|
5
|
+
describe 'integration test' do
|
6
|
+
before do
|
7
|
+
Dotenv.load
|
8
|
+
@client = SendGrid4r::Client.new(
|
9
|
+
username: ENV['SENDGRID_USERNAME'],
|
10
|
+
password: ENV['SENDGRID_PASSWORD'])
|
11
|
+
@first_name =
|
12
|
+
SendGrid4r::REST::Contacts::ReservedFields::Field.new(
|
13
|
+
'first_name', 'text'
|
14
|
+
)
|
15
|
+
@last_name =
|
16
|
+
SendGrid4r::REST::Contacts::ReservedFields::Field.new(
|
17
|
+
'last_name', 'text'
|
18
|
+
)
|
19
|
+
@email =
|
20
|
+
SendGrid4r::REST::Contacts::ReservedFields::Field.new(
|
21
|
+
'email', 'text'
|
22
|
+
)
|
23
|
+
@created_at =
|
24
|
+
SendGrid4r::REST::Contacts::ReservedFields::Field.new(
|
25
|
+
'created_at', 'date'
|
26
|
+
)
|
27
|
+
@updated_at =
|
28
|
+
SendGrid4r::REST::Contacts::ReservedFields::Field.new(
|
29
|
+
'updated_at', 'date'
|
30
|
+
)
|
31
|
+
@last_emailed =
|
32
|
+
SendGrid4r::REST::Contacts::ReservedFields::Field.new(
|
33
|
+
'last_emailed', 'date'
|
34
|
+
)
|
35
|
+
@last_clicked =
|
36
|
+
SendGrid4r::REST::Contacts::ReservedFields::Field.new(
|
37
|
+
'last_clicked', 'date'
|
38
|
+
)
|
39
|
+
@last_opened =
|
40
|
+
SendGrid4r::REST::Contacts::ReservedFields::Field.new(
|
41
|
+
'last_opened', 'date'
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'without block call' do
|
46
|
+
it '#get_reserved_fields' do
|
47
|
+
begin
|
48
|
+
# get the reserved fields
|
49
|
+
fields = @client.get_reserved_fields
|
50
|
+
expect(fields.reserved_fields.length).to eq(8)
|
51
|
+
set = Set.new(fields.reserved_fields)
|
52
|
+
expect(set.include?(@first_name)).to eq(true)
|
53
|
+
expect(set.include?(@last_name)).to eq(true)
|
54
|
+
expect(set.include?(@email)).to eq(true)
|
55
|
+
expect(set.include?(@created_at)).to eq(true)
|
56
|
+
expect(set.include?(@updated_at)).to eq(true)
|
57
|
+
expect(set.include?(@last_emailed)).to eq(true)
|
58
|
+
expect(set.include?(@last_clicked)).to eq(true)
|
59
|
+
expect(set.include?(@last_opened)).to eq(true)
|
60
|
+
rescue => e
|
61
|
+
puts e.inspect
|
62
|
+
raise e
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
42
66
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
expect(set.include?(@last_clicked)).to eq(true)
|
57
|
-
expect(set.include?(@last_opened)).to eq(true)
|
58
|
-
rescue => e
|
59
|
-
puts e.inspect
|
60
|
-
raise e
|
67
|
+
context 'with block call' do
|
68
|
+
it '#get_reserved_fields' do
|
69
|
+
@client.get_reserved_fields do |resp, req, res|
|
70
|
+
resp =
|
71
|
+
SendGrid4r::REST::Contacts::ReservedFields.create_fields(
|
72
|
+
JSON.parse(resp)
|
73
|
+
)
|
74
|
+
expect(resp).to be_a(
|
75
|
+
SendGrid4r::REST::Contacts::ReservedFields::Fields
|
76
|
+
)
|
77
|
+
expect(req).to be_a(RestClient::Request)
|
78
|
+
expect(res).to be_a(Net::HTTPOK)
|
79
|
+
end
|
61
80
|
end
|
62
81
|
end
|
82
|
+
end
|
63
83
|
|
84
|
+
describe 'unit test' do
|
64
85
|
it 'creates field instance' do
|
65
86
|
json =
|
66
87
|
'{'\
|
@@ -117,11 +138,10 @@ describe 'SendGrid4r::REST::Contacts::ReservedFields' do
|
|
117
138
|
'}'
|
118
139
|
hash = JSON.parse(json)
|
119
140
|
actual = SendGrid4r::REST::Contacts::ReservedFields.create_fields(hash)
|
120
|
-
expect(actual
|
141
|
+
expect(actual).to be_a(SendGrid4r::REST::Contacts::ReservedFields::Fields)
|
142
|
+
expect(actual.reserved_fields).to be_a(Array)
|
121
143
|
actual.reserved_fields.each do |field|
|
122
|
-
expect(
|
123
|
-
field.is_a?(SendGrid4r::REST::Contacts::ReservedFields::Field)
|
124
|
-
).to eq(true)
|
144
|
+
expect(field).to be_a(SendGrid4r::REST::Contacts::ReservedFields::Field)
|
125
145
|
end
|
126
146
|
end
|
127
147
|
end
|