sendgrid4r 1.8.1 → 1.10.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.
- checksums.yaml +4 -4
- data/.rubocop.yml +6 -2
- data/README.md +1 -0
- data/lib/sendgrid4r/factory/campaign_factory.rb +18 -5
- data/lib/sendgrid4r/factory/condition_factory.rb +1 -1
- data/lib/sendgrid4r/factory/mail_factory.rb +57 -0
- data/lib/sendgrid4r/factory/segment_factory.rb +2 -5
- data/lib/sendgrid4r/factory/version_factory.rb +1 -1
- data/lib/sendgrid4r/rest/api.rb +48 -49
- data/lib/sendgrid4r/rest/api_keys_management/api_keys.rb +75 -0
- data/lib/sendgrid4r/rest/api_keys_management/permissions.rb +31 -0
- data/lib/sendgrid4r/rest/blocks.rb +49 -68
- data/lib/sendgrid4r/rest/bounces.rb +45 -64
- data/lib/sendgrid4r/rest/cancel_scheduled_sends.rb +53 -72
- data/lib/sendgrid4r/rest/categories.rb +31 -0
- data/lib/sendgrid4r/rest/email_activity.rb +72 -0
- data/lib/sendgrid4r/rest/invalid_emails.rb +50 -68
- data/lib/sendgrid4r/rest/ip_access_management.rb +86 -111
- data/lib/sendgrid4r/rest/ips/addresses.rb +50 -59
- data/lib/sendgrid4r/rest/ips/pools.rb +42 -53
- data/lib/sendgrid4r/rest/ips/warmup.rb +46 -55
- data/lib/sendgrid4r/rest/mail/address.rb +14 -0
- data/lib/sendgrid4r/rest/mail/attachment.rb +22 -0
- data/lib/sendgrid4r/rest/mail/content.rb +10 -0
- data/lib/sendgrid4r/rest/mail/mail.rb +28 -0
- data/lib/sendgrid4r/rest/mail/mail_settings.rb +62 -0
- data/lib/sendgrid4r/rest/mail/params.rb +64 -0
- data/lib/sendgrid4r/rest/mail/personalization.rb +33 -0
- data/lib/sendgrid4r/rest/mail/tracking_settings.rb +74 -0
- data/lib/sendgrid4r/rest/{contacts → marketing_campaigns/contacts}/custom_fields.rb +12 -27
- data/lib/sendgrid4r/rest/{contacts → marketing_campaigns/contacts}/lists.rb +20 -34
- data/lib/sendgrid4r/rest/marketing_campaigns/contacts/recipients.rb +134 -0
- data/lib/sendgrid4r/rest/{contacts → marketing_campaigns/contacts}/reserved_fields.rb +6 -9
- data/lib/sendgrid4r/rest/marketing_campaigns/contacts/segments.rb +86 -0
- data/lib/sendgrid4r/rest/marketing_campaigns/marketing_campaigns.rb +119 -0
- data/lib/sendgrid4r/rest/marketing_campaigns/senders.rb +101 -0
- data/lib/sendgrid4r/rest/request.rb +61 -63
- data/lib/sendgrid4r/rest/settings/enforced_tls.rb +23 -26
- data/lib/sendgrid4r/rest/settings/mail.rb +167 -183
- data/lib/sendgrid4r/rest/settings/partner.rb +33 -36
- data/lib/sendgrid4r/rest/settings/settings.rb +17 -22
- data/lib/sendgrid4r/rest/settings/tracking.rb +97 -107
- data/lib/sendgrid4r/rest/sm/global_unsubscribes.rb +52 -60
- data/lib/sendgrid4r/rest/sm/groups.rb +52 -58
- data/lib/sendgrid4r/rest/sm/sm.rb +15 -17
- data/lib/sendgrid4r/rest/sm/suppressions.rb +50 -67
- data/lib/sendgrid4r/rest/spam_reports.rb +49 -69
- data/lib/sendgrid4r/rest/stats/advanced.rb +100 -102
- data/lib/sendgrid4r/rest/stats/category.rb +31 -33
- data/lib/sendgrid4r/rest/stats/global.rb +17 -19
- data/lib/sendgrid4r/rest/stats/parse.rb +18 -20
- data/lib/sendgrid4r/rest/stats/stats.rb +59 -69
- data/lib/sendgrid4r/rest/stats/subuser.rb +70 -32
- data/lib/sendgrid4r/rest/subusers.rb +106 -134
- data/lib/sendgrid4r/rest/transactional_templates/templates.rb +63 -0
- data/lib/sendgrid4r/rest/transactional_templates/versions.rb +90 -0
- data/lib/sendgrid4r/rest/users.rb +125 -57
- data/lib/sendgrid4r/rest/webhooks/event.rb +36 -42
- data/lib/sendgrid4r/rest/webhooks/parse.rb +28 -37
- data/lib/sendgrid4r/rest/whitelabel/domains.rb +176 -222
- data/lib/sendgrid4r/rest/whitelabel/ips.rb +107 -128
- data/lib/sendgrid4r/rest/whitelabel/links.rb +131 -167
- data/lib/sendgrid4r/version.rb +1 -1
- data/lib/sendgrid4r.rb +23 -13
- data/sendgrid4r.gemspec +1 -1
- data/spec/client_spec.rb +12 -1
- data/spec/factory/campaign_factory_spec.rb +75 -35
- data/spec/factory/condition_factory_spec.rb +19 -18
- data/spec/factory/segment_factory_spec.rb +28 -21
- data/spec/factory/version_factory_spec.rb +28 -27
- data/spec/photo.jpg +0 -0
- data/spec/rest/api_keys_management/api_keys_spec.rb +174 -0
- data/spec/rest/api_keys_management/permissions_spec.rb +54 -0
- data/spec/rest/blocks_spec.rb +78 -106
- data/spec/rest/bounces_spec.rb +91 -118
- data/spec/rest/cancel_scheduled_sends_spec.rb +94 -149
- data/spec/rest/categories_spec.rb +77 -0
- data/spec/rest/email_activity_spec.rb +151 -0
- data/spec/rest/invalid_emails_spec.rb +85 -119
- data/spec/rest/ip_access_management_spec.rb +157 -195
- data/spec/rest/ips/addresses_spec.rb +94 -122
- data/spec/rest/ips/pools_spec.rb +84 -112
- data/spec/rest/ips/warmup_spec.rb +63 -71
- data/spec/rest/mail/address_spec.rb +28 -0
- data/spec/rest/mail/attachment_spec.rb +48 -0
- data/spec/rest/mail/content_spec.rb +32 -0
- data/spec/rest/mail/mail_settings_spec.rb +51 -0
- data/spec/rest/mail/mail_spec.rb +136 -0
- data/spec/rest/mail/params_spec.rb +152 -0
- data/spec/rest/mail/personalization_spec.rb +66 -0
- data/spec/rest/mail/tracking_settings_spec.rb +63 -0
- data/spec/rest/marketing_campaigns/contacts/custom_fields_spec.rb +146 -0
- data/spec/rest/marketing_campaigns/contacts/lists_spec.rb +307 -0
- data/spec/rest/marketing_campaigns/contacts/recipients_spec.rb +331 -0
- data/spec/rest/marketing_campaigns/contacts/reserved_fields_spec.rb +119 -0
- data/spec/rest/marketing_campaigns/contacts/segments_spec.rb +268 -0
- data/spec/rest/marketing_campaigns/marketing_campaigns_spec.rb +427 -0
- data/spec/rest/marketing_campaigns/senders_spec.rb +230 -0
- data/spec/rest/settings/enforced_tls_spec.rb +38 -54
- data/spec/rest/settings/mail_spec.rb +227 -330
- data/spec/rest/settings/partner_spec.rb +40 -59
- data/spec/rest/settings/settings_spec.rb +44 -42
- data/spec/rest/settings/tracking_spec.rb +130 -189
- data/spec/rest/sm/global_unsubscribes_spec.rb +47 -72
- data/spec/rest/sm/groups_spec.rb +88 -123
- data/spec/rest/sm/sm_spec.rb +32 -30
- data/spec/rest/sm/suppressions_spec.rb +105 -140
- data/spec/rest/spam_reports_spec.rb +81 -109
- data/spec/rest/stats/advanced_spec.rb +67 -125
- data/spec/rest/stats/category_spec.rb +27 -45
- data/spec/rest/stats/global_spec.rb +34 -42
- data/spec/rest/stats/parse_spec.rb +32 -30
- data/spec/rest/stats/stats_spec.rb +174 -172
- data/spec/rest/stats/subuser_spec.rb +97 -57
- data/spec/rest/subusers_spec.rb +156 -209
- data/spec/rest/transactional_templates/templates_spec.rb +199 -0
- data/spec/rest/transactional_templates/versions_spec.rb +228 -0
- data/spec/rest/users_spec.rb +176 -91
- data/spec/rest/webhooks/event_spec.rb +59 -85
- data/spec/rest/webhooks/parse_spec.rb +51 -71
- data/spec/rest/whitelabel/domains_spec.rb +333 -513
- data/spec/rest/whitelabel/ips_spec.rb +109 -147
- data/spec/rest/whitelabel/links_spec.rb +181 -265
- metadata +70 -40
- data/lib/sendgrid4r/rest/api_keys/api_keys.rb +0 -80
- data/lib/sendgrid4r/rest/api_keys/permissions.rb +0 -33
- data/lib/sendgrid4r/rest/campaigns/campaigns.rb +0 -126
- data/lib/sendgrid4r/rest/categories/categories.rb +0 -43
- data/lib/sendgrid4r/rest/contacts/recipients.rb +0 -150
- data/lib/sendgrid4r/rest/contacts/segments.rb +0 -97
- data/lib/sendgrid4r/rest/email_activity/email_activity.rb +0 -81
- data/lib/sendgrid4r/rest/templates/templates.rb +0 -69
- data/lib/sendgrid4r/rest/templates/versions.rb +0 -95
- data/spec/rest/api_keys/api_keys_spec.rb +0 -210
- data/spec/rest/api_keys/permissions_spec.rb +0 -65
- data/spec/rest/campaigns/campaigns_spec.rb +0 -492
- data/spec/rest/categories/categories_spec.rb +0 -96
- data/spec/rest/contacts/custom_fields_spec.rb +0 -174
- data/spec/rest/contacts/lists_spec.rb +0 -372
- data/spec/rest/contacts/recipients_spec.rb +0 -343
- data/spec/rest/contacts/reserved_fields_spec.rb +0 -146
- data/spec/rest/contacts/segments_spec.rb +0 -307
- data/spec/rest/email_activity/email_activity_spec.rb +0 -179
- data/spec/rest/templates/templates_spec.rb +0 -222
- data/spec/rest/templates/versions_spec.rb +0 -252
@@ -0,0 +1,331 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.dirname(__FILE__) + '/../../../spec_helper'
|
3
|
+
|
4
|
+
module SendGrid4r::REST::MarketingCampaigns::Contacts
|
5
|
+
describe Recipients do
|
6
|
+
describe 'integration test', :it do
|
7
|
+
before do
|
8
|
+
Dotenv.load
|
9
|
+
@client = SendGrid4r::Client.new(api_key: ENV['SILVER_API_KEY'])
|
10
|
+
@email1 = 'jones@example.com'
|
11
|
+
@email2 = 'miller@example.com'
|
12
|
+
@email3 = 'jones...example.com'
|
13
|
+
@last_name1 = 'Jones'
|
14
|
+
@last_name2 = 'Miller'
|
15
|
+
@last_name3 = 'Invalid'
|
16
|
+
@pet1 = 'Fluffy'
|
17
|
+
@pet2 = 'FrouFrou'
|
18
|
+
|
19
|
+
# celan up test env
|
20
|
+
recipients = @client.get_recipients
|
21
|
+
recipients.recipients.each do |recipient|
|
22
|
+
next if recipient.email != @email1 && recipient.email != @email2
|
23
|
+
@client.delete_recipient(recipient_id: recipient.id)
|
24
|
+
end
|
25
|
+
# post a recipient
|
26
|
+
params = {}
|
27
|
+
params['email'] = @email1
|
28
|
+
params['last_name'] = @last_name1
|
29
|
+
@result = @client.post_recipients(params: [params])
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'without block call' do
|
33
|
+
it '#post_recipients' do
|
34
|
+
params = {}
|
35
|
+
params['email'] = @email2
|
36
|
+
params['last_name'] = @last_name2
|
37
|
+
result = @client.post_recipients(params: [params])
|
38
|
+
expect(result.error_count).to eq(0)
|
39
|
+
expect(result.error_indices).to eq([])
|
40
|
+
expect(result.new_count).to eq(1)
|
41
|
+
expect(result.persisted_recipients).to be_a(Array)
|
42
|
+
expect(result.updated_count).to eq(0)
|
43
|
+
end
|
44
|
+
|
45
|
+
it '#post_recipients with error' do
|
46
|
+
params = {}
|
47
|
+
params['email'] = @email3
|
48
|
+
params['last_name'] = @last_name3
|
49
|
+
result = @client.post_recipients(params: [params])
|
50
|
+
expect(result.error_count).to eq(1)
|
51
|
+
expect(result.error_indices).to eq([0])
|
52
|
+
expect(result.errors).to be_a(Array)
|
53
|
+
result.errors.each do |error|
|
54
|
+
expect(error.error_indices).to be_a(Array)
|
55
|
+
expect(error.message).to be_a(String)
|
56
|
+
end
|
57
|
+
expect(result.new_count).to eq(0)
|
58
|
+
expect(result.persisted_recipients).to be_a(Array)
|
59
|
+
expect(result.updated_count).to eq(0)
|
60
|
+
end
|
61
|
+
|
62
|
+
it '#patch_recipients' do
|
63
|
+
params = {}
|
64
|
+
params['email'] = @email1
|
65
|
+
params['last_name'] = 'JonesEdit'
|
66
|
+
result = @client.patch_recipients(params: [params])
|
67
|
+
expect(result.error_count).to eq(0)
|
68
|
+
expect(result.error_indices).to eq([])
|
69
|
+
expect(result.new_count).to eq(0)
|
70
|
+
expect(result.persisted_recipients).to be_a(Array)
|
71
|
+
expect(result.updated_count).to eq(1)
|
72
|
+
end
|
73
|
+
|
74
|
+
it '#delete_recipients' do
|
75
|
+
@client.delete_recipients(recipient_ids: @result.persisted_recipients)
|
76
|
+
end
|
77
|
+
|
78
|
+
it '#get_recipients' do
|
79
|
+
recipients = @client.get_recipients(page: 1, page_size: 100)
|
80
|
+
expect(recipients.recipients.length).to be > 0
|
81
|
+
recipients.recipients.each do |recipient|
|
82
|
+
expect(recipient).to be_a(Recipients::Recipient)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
it '#get_recipient' do
|
87
|
+
recipient = @client.get_recipient(
|
88
|
+
recipient_id: @result.persisted_recipients[0]
|
89
|
+
)
|
90
|
+
expect(recipient).to be_a(Recipients::Recipient)
|
91
|
+
end
|
92
|
+
|
93
|
+
it '#delete_recipient' do
|
94
|
+
@client.delete_recipient(
|
95
|
+
recipient_id: @result.persisted_recipients[0]
|
96
|
+
)
|
97
|
+
expect do
|
98
|
+
@client.get_recipient(recipient_id: @result.persisted_recipients[0])
|
99
|
+
end.to raise_error(RestClient::ResourceNotFound)
|
100
|
+
end
|
101
|
+
|
102
|
+
it '#get_lists_recipient_belong' do
|
103
|
+
lists = @client.get_lists_recipient_belong(
|
104
|
+
recipient_id: @result.persisted_recipients[0]
|
105
|
+
)
|
106
|
+
lists.lists.each do |list|
|
107
|
+
expect(list.is_a?(Lists::List)).to eq(true)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
it '#get_recipient_count' do
|
112
|
+
actual_count = @client.get_recipients_count
|
113
|
+
expect(actual_count).to be >= 0
|
114
|
+
end
|
115
|
+
|
116
|
+
it '#search_recipients' do
|
117
|
+
params = {}
|
118
|
+
params['email'] = @email1
|
119
|
+
recipients = @client.search_recipients(params: params)
|
120
|
+
expect(recipients.recipients).to be_a(Array)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
describe 'unit test', :ut do
|
126
|
+
let(:client) do
|
127
|
+
SendGrid4r::Client.new(api_key: '')
|
128
|
+
end
|
129
|
+
|
130
|
+
let(:recipient) do
|
131
|
+
JSON.parse(
|
132
|
+
'{'\
|
133
|
+
'"created_at": 1422313607,'\
|
134
|
+
'"email": "jones@example.com",'\
|
135
|
+
'"first_name": null,'\
|
136
|
+
'"id": "YUBh",'\
|
137
|
+
'"last_clicked": null,'\
|
138
|
+
'"last_emailed": null,'\
|
139
|
+
'"last_name": "Jones",'\
|
140
|
+
'"last_opened": null,'\
|
141
|
+
'"updated_at": 1422313790,'\
|
142
|
+
'"custom_fields": ['\
|
143
|
+
'{'\
|
144
|
+
'"id": 23,'\
|
145
|
+
'"name": "pet",'\
|
146
|
+
'"value": "Fluffy",'\
|
147
|
+
'"type": "text"'\
|
148
|
+
'}'\
|
149
|
+
']'\
|
150
|
+
'}'
|
151
|
+
)
|
152
|
+
end
|
153
|
+
|
154
|
+
let(:recipients) do
|
155
|
+
JSON.parse(
|
156
|
+
'{'\
|
157
|
+
'"recipients": ['\
|
158
|
+
'{'\
|
159
|
+
'"created_at": 1422313607,'\
|
160
|
+
'"email": "jones@example.com",'\
|
161
|
+
'"first_name": null,'\
|
162
|
+
'"id": "YUBh",'\
|
163
|
+
'"last_clicked": null,'\
|
164
|
+
'"last_emailed": null,'\
|
165
|
+
'"last_name": "Jones",'\
|
166
|
+
'"last_opened": null,'\
|
167
|
+
'"updated_at": 1422313790,'\
|
168
|
+
'"custom_fields": ['\
|
169
|
+
'{'\
|
170
|
+
'"id": 23,'\
|
171
|
+
'"name": "pet",'\
|
172
|
+
'"value": "Fluffy",'\
|
173
|
+
'"type": "text"'\
|
174
|
+
'}'\
|
175
|
+
']'\
|
176
|
+
'}'\
|
177
|
+
']'\
|
178
|
+
'}'
|
179
|
+
)
|
180
|
+
end
|
181
|
+
|
182
|
+
let(:recipient_count) do
|
183
|
+
JSON.parse(
|
184
|
+
'{'\
|
185
|
+
'"recipient_count": 2'\
|
186
|
+
'}'
|
187
|
+
)
|
188
|
+
end
|
189
|
+
|
190
|
+
let(:lists) do
|
191
|
+
JSON.parse(
|
192
|
+
'{'\
|
193
|
+
'"lists": ['\
|
194
|
+
'{'\
|
195
|
+
'"id": 1,'\
|
196
|
+
'"name": "the jones",'\
|
197
|
+
'"recipient_count": 1'\
|
198
|
+
'}'\
|
199
|
+
']'\
|
200
|
+
'}'
|
201
|
+
)
|
202
|
+
end
|
203
|
+
|
204
|
+
let(:result) do
|
205
|
+
JSON.parse(
|
206
|
+
'{'\
|
207
|
+
'"error_count": 1,'\
|
208
|
+
'"error_indices": ['\
|
209
|
+
'2'\
|
210
|
+
'],'\
|
211
|
+
'"new_count": 2,'\
|
212
|
+
'"persisted_recipients": ['\
|
213
|
+
'"YUBh",'\
|
214
|
+
'"bWlsbGVyQG1pbGxlci50ZXN0"'\
|
215
|
+
'],'\
|
216
|
+
'"updated_count": 0,'\
|
217
|
+
'"errors": ['\
|
218
|
+
'{'\
|
219
|
+
'"message": "Invalid email.",'\
|
220
|
+
'"error_indices": ['\
|
221
|
+
'2'\
|
222
|
+
']'\
|
223
|
+
'}'\
|
224
|
+
']'\
|
225
|
+
'}'
|
226
|
+
)
|
227
|
+
end
|
228
|
+
|
229
|
+
it '#post_recipients' do
|
230
|
+
allow(client).to receive(:execute).and_return(result)
|
231
|
+
actual = client.post_recipients(params: {})
|
232
|
+
expect(actual).to be_a(Recipients::Result)
|
233
|
+
end
|
234
|
+
|
235
|
+
it '#patch_recipients' do
|
236
|
+
allow(client).to receive(:execute).and_return(result)
|
237
|
+
actual = client.patch_recipients(params: {})
|
238
|
+
expect(actual).to be_a(Recipients::Result)
|
239
|
+
end
|
240
|
+
|
241
|
+
it '#delete_recipients' do
|
242
|
+
allow(client).to receive(:execute).and_return('')
|
243
|
+
actual = client.delete_recipients(recipient_ids: ['', ''])
|
244
|
+
expect(actual).to eq('')
|
245
|
+
end
|
246
|
+
|
247
|
+
it '#get_recipients' do
|
248
|
+
allow(client).to receive(:execute).and_return(recipients)
|
249
|
+
actual = client.get_recipients(page: 0, page_size: 0)
|
250
|
+
expect(actual).to be_a(Recipients::Recipients)
|
251
|
+
end
|
252
|
+
|
253
|
+
it '#get_recipient' do
|
254
|
+
allow(client).to receive(:execute).and_return(recipient)
|
255
|
+
actual = client.get_recipient(recipient_id: '')
|
256
|
+
expect(actual).to be_a(Recipients::Recipient)
|
257
|
+
end
|
258
|
+
|
259
|
+
it '#delete_recipient' do
|
260
|
+
allow(client).to receive(:execute).and_return('')
|
261
|
+
actual = client.delete_recipient(recipient_id: '')
|
262
|
+
expect(actual).to eq('')
|
263
|
+
end
|
264
|
+
|
265
|
+
it '#get_lists_recipient_belong' do
|
266
|
+
allow(client).to receive(:execute).and_return(lists)
|
267
|
+
actual = client.get_lists_recipient_belong(recipient_id: '')
|
268
|
+
expect(actual).to be_a(Lists::Lists)
|
269
|
+
end
|
270
|
+
|
271
|
+
it '#get_recipient_count' do
|
272
|
+
allow(client).to receive(:execute).and_return(recipient_count)
|
273
|
+
actual = client.get_recipients_count
|
274
|
+
expect(actual).to be_a(Fixnum)
|
275
|
+
end
|
276
|
+
|
277
|
+
it '#search_recipients' do
|
278
|
+
allow(client).to receive(:execute).and_return(recipients)
|
279
|
+
actual = client.search_recipients(params: {})
|
280
|
+
expect(actual).to be_a(Recipients::Recipients)
|
281
|
+
end
|
282
|
+
|
283
|
+
it 'creates recipient instance' do
|
284
|
+
actual = Recipients.create_recipient(
|
285
|
+
recipient
|
286
|
+
)
|
287
|
+
expect(actual).to be_a(Recipients::Recipient)
|
288
|
+
expect(actual.created_at).to eq(Time.at(1422313607))
|
289
|
+
expect(actual.email).to eq('jones@example.com')
|
290
|
+
expect(actual.first_name).to eq(nil)
|
291
|
+
expect(actual.id).to eq('YUBh')
|
292
|
+
expect(actual.last_clicked).to eq(nil)
|
293
|
+
expect(actual.last_emailed).to eq(nil)
|
294
|
+
expect(actual.last_name).to eq('Jones')
|
295
|
+
expect(actual.last_opened).to eq(nil)
|
296
|
+
expect(actual.updated_at).to eq(Time.at(1422313790))
|
297
|
+
custom_field = actual.custom_fields[0]
|
298
|
+
expect(custom_field.id).to eq(23)
|
299
|
+
expect(custom_field.name).to eq('pet')
|
300
|
+
expect(custom_field.value).to eq('Fluffy')
|
301
|
+
expect(custom_field.type).to eq('text')
|
302
|
+
end
|
303
|
+
|
304
|
+
it 'creates recipients instance' do
|
305
|
+
actual = Recipients.create_recipients(recipients)
|
306
|
+
expect(actual.recipients).to be_a(Array)
|
307
|
+
actual.recipients.each do |recipient|
|
308
|
+
expect(recipient).to be_a(Recipients::Recipient)
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
it 'creates result instance' do
|
313
|
+
actual = Recipients.create_result(result)
|
314
|
+
expect(actual.error_count).to eq(1)
|
315
|
+
expect(actual.error_indices).to be_a(Array)
|
316
|
+
expect(actual.error_indices[0]).to eq(2)
|
317
|
+
expect(actual.new_count).to eq(2)
|
318
|
+
expect(actual.persisted_recipients).to be_a(Array)
|
319
|
+
expect(actual.persisted_recipients[0]).to eq('YUBh')
|
320
|
+
expect(actual.persisted_recipients[1]).to eq(
|
321
|
+
'bWlsbGVyQG1pbGxlci50ZXN0'
|
322
|
+
)
|
323
|
+
expect(actual.updated_count).to eq(0)
|
324
|
+
expect(actual.errors).to be_a(Array)
|
325
|
+
expect(actual.errors[0].message).to eq('Invalid email.')
|
326
|
+
expect(actual.error_indices).to be_a(Array)
|
327
|
+
expect(actual.error_indices[0]).to eq(2)
|
328
|
+
end
|
329
|
+
end
|
330
|
+
end
|
331
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.dirname(__FILE__) + '/../../../spec_helper'
|
3
|
+
|
4
|
+
module SendGrid4r::REST::MarketingCampaigns::Contacts
|
5
|
+
describe ReservedFields do
|
6
|
+
describe 'integration test', :it do
|
7
|
+
before do
|
8
|
+
Dotenv.load
|
9
|
+
@client = SendGrid4r::Client.new(api_key: ENV['SILVER_API_KEY'])
|
10
|
+
@first_name = ReservedFields::Field.new('first_name', 'text')
|
11
|
+
@last_name = ReservedFields::Field.new('last_name', 'text')
|
12
|
+
@email = ReservedFields::Field.new('email', 'text')
|
13
|
+
@created_at = ReservedFields::Field.new('created_at', 'date')
|
14
|
+
@updated_at = ReservedFields::Field.new('updated_at', 'date')
|
15
|
+
@last_emailed = ReservedFields::Field.new('last_emailed', 'date')
|
16
|
+
@last_clicked = ReservedFields::Field.new('last_clicked', 'date')
|
17
|
+
@last_opened = ReservedFields::Field.new('last_opened', 'date')
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'without block call' do
|
21
|
+
it '#get_reserved_fields' do
|
22
|
+
# get the reserved fields
|
23
|
+
fields = @client.get_reserved_fields
|
24
|
+
expect(fields.reserved_fields.length).to eq(8)
|
25
|
+
set = Set.new(fields.reserved_fields)
|
26
|
+
expect(set.include?(@first_name)).to eq(true)
|
27
|
+
expect(set.include?(@last_name)).to eq(true)
|
28
|
+
expect(set.include?(@email)).to eq(true)
|
29
|
+
expect(set.include?(@created_at)).to eq(true)
|
30
|
+
expect(set.include?(@updated_at)).to eq(true)
|
31
|
+
expect(set.include?(@last_emailed)).to eq(true)
|
32
|
+
expect(set.include?(@last_clicked)).to eq(true)
|
33
|
+
expect(set.include?(@last_opened)).to eq(true)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'unit test', :ut do
|
39
|
+
let(:client) do
|
40
|
+
SendGrid4r::Client.new(api_key: '')
|
41
|
+
end
|
42
|
+
|
43
|
+
let(:field) do
|
44
|
+
JSON.parse(
|
45
|
+
'{'\
|
46
|
+
'"name": "first_name",'\
|
47
|
+
'"type": "text"'\
|
48
|
+
'}'
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
let(:fields) do
|
53
|
+
JSON.parse(
|
54
|
+
'{'\
|
55
|
+
'"reserved_fields": ['\
|
56
|
+
'{'\
|
57
|
+
'"name": "first_name",'\
|
58
|
+
'"type": "text"'\
|
59
|
+
'},'\
|
60
|
+
'{'\
|
61
|
+
'"name": "last_name",'\
|
62
|
+
'"type": "text"'\
|
63
|
+
'},'\
|
64
|
+
'{'\
|
65
|
+
'"name": "email",'\
|
66
|
+
'"type": "text"'\
|
67
|
+
'},'\
|
68
|
+
'{'\
|
69
|
+
'"name": "created_at",'\
|
70
|
+
'"type": "date"'\
|
71
|
+
'},'\
|
72
|
+
'{'\
|
73
|
+
'"name": "updated_at",'\
|
74
|
+
'"type": "date"'\
|
75
|
+
'},'\
|
76
|
+
'{'\
|
77
|
+
'"name": "last_emailed",'\
|
78
|
+
'"type": "date"'\
|
79
|
+
'},'\
|
80
|
+
'{'\
|
81
|
+
'"name": "last_clicked",'\
|
82
|
+
'"type": "date"'\
|
83
|
+
'},'\
|
84
|
+
'{'\
|
85
|
+
'"name": "last_opened",'\
|
86
|
+
'"type": "date"'\
|
87
|
+
'},'\
|
88
|
+
'{'\
|
89
|
+
'"name": "my_custom_field",'\
|
90
|
+
'"type": "text"'\
|
91
|
+
'}'\
|
92
|
+
']'\
|
93
|
+
'}'
|
94
|
+
)
|
95
|
+
end
|
96
|
+
|
97
|
+
it '#get_reserved_fields' do
|
98
|
+
allow(client).to receive(:execute).and_return(fields)
|
99
|
+
actual = client.get_reserved_fields
|
100
|
+
expect(actual).to be_a(ReservedFields::Fields)
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'creates field instance' do
|
104
|
+
actual = CustomFields.create_field(field)
|
105
|
+
expect(actual.name).to eq('first_name')
|
106
|
+
expect(actual.type).to eq('text')
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'creates fields instance' do
|
110
|
+
actual = ReservedFields.create_fields(fields)
|
111
|
+
expect(actual).to be_a(ReservedFields::Fields)
|
112
|
+
expect(actual.reserved_fields).to be_a(Array)
|
113
|
+
actual.reserved_fields.each do |field|
|
114
|
+
expect(field).to be_a(ReservedFields::Field)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|