emma-ruby 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,598 @@
1
+ require_relative 'helper'
2
+
3
+ class TestEmmaMethods < Test::Unit::TestCase
4
+
5
+ context "testing of methods" do
6
+ setup do
7
+ @em = Emma::Setup.new(nil, nil, nil, true)
8
+ @member_id = '111'
9
+ @member_email = 'dennismonsewicz@gmail.com'
10
+ end
11
+
12
+ teardown do
13
+ @em = nil
14
+ @member_id = nil
15
+ @member_email = nil
16
+ end
17
+
18
+ context "testing of methods involving calls to the members endpoints" do
19
+ should "return member array list" do
20
+ VCR.use_cassette('members/list_of_members') do
21
+ response = @em.my_members
22
+ assert_instance_of Array, response
23
+ end
24
+ end
25
+
26
+ should "lookup member by id" do
27
+ VCR.use_cassette('members/single_member') do
28
+ response = @em.get_member_by_id(@member_id)
29
+ assert response.has_key?('error')
30
+ end
31
+ end
32
+
33
+ should "lookup member by email" do
34
+ VCR.use_cassette('members/single_member_by_email') do
35
+ response = @em.get_member_by_email(@member_email)
36
+ assert response.has_key?('error')
37
+ end
38
+ end
39
+
40
+ should "lookup return opted out member" do
41
+ VCR.use_cassette('members/single_member_optout_info') do
42
+ response = @em.get_optout_member(@member_id)
43
+ assert_instance_of Array, response
44
+ end
45
+ end
46
+
47
+ should "optout member" do
48
+ VCR.use_cassette('members/optout_member') do
49
+ response = @em.optout(@member_email)
50
+ assert response.has_key?('error')
51
+ end
52
+ end
53
+
54
+ should "add new members" do
55
+ VCR.use_cassette('members/add_new_members') do
56
+ response = @em.add_members(:members => [ {:email => "dennismonsewicz+22211@gmail.com"}, {:email => "dennismonsewicz+kliwuu11@gmail.com"} ])
57
+ assert response.has_key?('import_id')
58
+ end
59
+ end
60
+
61
+ should "add new member" do
62
+ VCR.use_cassette('members/add_single_member') do
63
+ response = @em.add_member(:email => 'dennismonsewicz+ldflwj@gmail.com', :fields => { :first_name => "dennis", :last_name => "the test" })
64
+ assert response.has_key?('member_id')
65
+ end
66
+ end
67
+
68
+ should "remove an array of members" do
69
+ VCR.use_cassette('members/remove_array_of_members') do
70
+ response = @em.remove_members(:member_ids => [123, 111])
71
+ assert_equal true, response
72
+ end
73
+ end
74
+
75
+ should "change the status of an array of members" do
76
+ VCR.use_cassette('members/change_status_for_array_of_members') do
77
+ response = @em.change_members_status(:member_ids => [123, 111], :status_to => "a")
78
+ assert_equal true, response
79
+ end
80
+ end
81
+
82
+ should "update a single member" do
83
+ VCR.use_cassette('members/update_member') do
84
+ response = @em.update_member(111, :status_to => "e")
85
+ assert response.has_key?('error')
86
+ end
87
+ end
88
+
89
+ should "remove a member" do
90
+ VCR.use_cassette('members/remove_member') do
91
+ response = @em.remove_member(111)
92
+ assert response.has_key?('error')
93
+ end
94
+ end
95
+
96
+ should "get a member's groups" do
97
+ VCR.use_cassette('members/members_groups') do
98
+ response = @em.get_members_groups(111)
99
+ assert response.has_key?('error')
100
+ end
101
+ end
102
+
103
+ should "add single member to a list of groups" do
104
+ VCR.use_cassette('members/add_member_to_groups') do
105
+ response = @em.add_member_to_groups(111, :group_ids => [150, 151])
106
+ assert response.has_key?('error')
107
+ end
108
+ end
109
+
110
+ should "remove a member from groups" do
111
+ VCR.use_cassette('members/remove_member_from_groups') do
112
+ response = @em.remove_member_from_groups(111, :group_ids => [150, 151])
113
+ assert response.has_key?('error')
114
+ end
115
+ end
116
+
117
+ should "remove all members tied to account" do
118
+ VCR.use_cassette('members/remove_all_members') do
119
+ response = @em.remove_all_members
120
+ assert_equal true, response
121
+ end
122
+ end
123
+
124
+ should "remove member from all groups" do
125
+ VCR.use_cassette('members/remove_member_from_groups') do
126
+ response = @em.remove_member_from_all_groups(111)
127
+ assert response.has_key?('error')
128
+ end
129
+ end
130
+
131
+ should "remove multiple members from groups" do
132
+ VCR.use_cassette('members/remove_multiple_members_from_groups') do
133
+ response = @em.remove_multiple_members_from_groups(:group_ids => [151], :member_ids => [202])
134
+ assert_equal true, response
135
+ end
136
+ end
137
+
138
+ should "get mailing history for member" do
139
+ VCR.use_cassette('members/imported_members') do
140
+ response = @em.get_mailing_history_for_member(111)
141
+ assert_instance_of Array, response
142
+ end
143
+ end
144
+
145
+ should "get list of members by import id" do
146
+ VCR.use_cassette('members/import_stats') do
147
+ response = @em.import_stats(111)
148
+ assert response.has_key?('error')
149
+ end
150
+ end
151
+
152
+ should "get information on all imports" do
153
+ VCR.use_cassette('members/my_imports') do
154
+ response = @em.my_imports
155
+ assert_instance_of Array, response
156
+ end
157
+ end
158
+
159
+ should "delete an import" do
160
+ VCR.use_cassette('members/delete_import') do
161
+ response = @em.delete_import
162
+ assert response.has_key?('error')
163
+ end
164
+ end
165
+
166
+ should "copy members to group" do
167
+ VCR.use_cassette('members/copy_members_to_group') do
168
+ response = @em.copy_members_to_group(111, :member_status_id => ["a"])
169
+ assert response.has_key?('error')
170
+ end
171
+ end
172
+
173
+ should "update group members' status" do
174
+ VCR.use_cassette('members/update_group_members_status') do
175
+ response = @em.update_group_members_status('e', 'a', 111)
176
+ assert response
177
+ end
178
+ end
179
+ end
180
+
181
+ context "testing of methods involving calls to field endpoints" do
182
+ should "return field array list" do
183
+ VCR.use_cassette('fields/list_of_fields') do
184
+ response = @em.my_fields
185
+ assert_instance_of Array, response
186
+ end
187
+ end
188
+
189
+ should "lookup field by id" do
190
+ VCR.use_cassette('fields/single_field') do
191
+ response = @em.get_field_by_id(111)
192
+ assert response.has_key?('error')
193
+ end
194
+ end
195
+
196
+ should "add new field" do
197
+ VCR.use_cassette('fields/add_field') do
198
+ response = @em.add_field :shortcut_name => "my_new_field_#{random_string}", :column_order => 1, :display_name => "My New Field (#{random_string})", :field_type => "text"
199
+ assert_instance_of Fixnum, response
200
+ end
201
+ end
202
+
203
+ should "remove field" do
204
+ VCR.use_cassette('fields/remove_field') do
205
+ response = @em.remove_field 111
206
+ assert response.has_key?('error')
207
+ end
208
+ end
209
+
210
+ should "clear member data for field" do
211
+ VCR.use_cassette('fields/remove_member_data_for_field') do
212
+ response = @em.remove_member_data_for_field 111
213
+ assert response
214
+ end
215
+ end
216
+
217
+ should "update field" do
218
+ VCR.use_cassette('fields/update_field') do
219
+ response = @em.update_field 111, :display_name => "Hello World"
220
+ assert response.has_key?("error")
221
+ end
222
+ end
223
+
224
+ end
225
+
226
+ context "testing of methods involving calls to groups endpoints" do
227
+ should "return group array list" do
228
+ VCR.use_cassette('groups/my_groups') do
229
+ response = @em.my_groups
230
+ assert_instance_of Array, response
231
+ end
232
+ end
233
+
234
+ should "create new groups" do
235
+ VCR.use_cassette('groups/add_new_groups') do
236
+ response = @em.add_new_groups :groups => [ {:group_name => "My New Group"} ]
237
+ assert_instance_of Array, response
238
+ end
239
+ end
240
+
241
+ should "get group by id" do
242
+ VCR.use_cassette('groups/get_group_by_id') do
243
+ response = @em.get_group_by_id 111
244
+ assert response.has_key?("error")
245
+ end
246
+ end
247
+
248
+ should "update group" do
249
+ VCR.use_cassette('groups/update_group') do
250
+ response = @em.update_group 111, :group_name => "New Group Name Here"
251
+ assert response.has_key?("error")
252
+ end
253
+ end
254
+
255
+ should "remove group" do
256
+ VCR.use_cassette('groups/remove_group') do
257
+ response = @em.remove_group 111
258
+ assert response.has_key?("error")
259
+ end
260
+ end
261
+
262
+ should "get members in a single active group" do
263
+ VCR.use_cassette('groups/group_members') do
264
+ response = @em.group_members 111
265
+ assert response.has_key?("error")
266
+ end
267
+ end
268
+
269
+ should "add a list of members to a group" do
270
+ VCR.use_cassette('groups/add_members_to_group') do
271
+ response = @em.add_members_to_group 111, :member_ids => [100, 102]
272
+ assert response.has_key?("error")
273
+ end
274
+ end
275
+
276
+ should "remove a list of members fomr a group" do
277
+ VCR.use_cassette('groups/remove_members_from_group') do
278
+ response = @em.remove_members_from_group 111, :member_ids => [100, 102]
279
+ assert response.has_key?("error")
280
+ end
281
+ end
282
+
283
+ should "remove all members from a group" do
284
+ VCR.use_cassette('groups/remove_all_members_from_group') do
285
+ response = @em.remove_all_members_from_group 111
286
+ assert response.has_key?("error")
287
+ end
288
+ end
289
+
290
+ should "remove all members from a groups" do
291
+ VCR.use_cassette('groups/remove_all_members_from_groups') do
292
+ response = @em.remove_all_members_from_groups 111, :member_status_id => 'a', :delete_members => true
293
+ assert response == true
294
+ end
295
+ end
296
+
297
+ should "copy members from one group to another" do
298
+ VCR.use_cassette('groups/copy_members_to_different_group') do
299
+ response = @em.copy_members_to_different_group(111, 121, :member_status_id => ["a"])
300
+ assert response == true
301
+ end
302
+ end
303
+
304
+ end
305
+
306
+ context "testing of methods involving calls to the mailings endpoints" do
307
+ should "return mailings array list" do
308
+ VCR.use_cassette('mailings/my_mailings') do
309
+ response = @em.my_mailings
310
+ assert_instance_of Array, response
311
+ end
312
+ end
313
+
314
+ should "return mailing by id" do
315
+ VCR.use_cassette('mailings/get_mailing_by_id') do
316
+ response = @em.get_mailing_by_id 111
317
+ assert response.has_key? "error"
318
+ end
319
+ end
320
+
321
+ should "return list of mailing members by id" do
322
+ VCR.use_cassette('mailings/get_mailing_members') do
323
+ response = @em.get_mailing_members 111
324
+ assert response.has_key? "error"
325
+ end
326
+ end
327
+
328
+ should "return personalized message content as sent to a specific member as part of the specified mailing." do
329
+ VCR.use_cassette('mailings/get_personalized_member_mailing') do
330
+ response = @em.get_personalized_member_mailing 111, 102
331
+ assert response.has_key? "error"
332
+ end
333
+ end
334
+
335
+ should "return list of groups a mailing was sent to" do
336
+ VCR.use_cassette('mailings/get_groups_by_mailing') do
337
+ response = @em.get_groups_by_mailing 111
338
+ assert response.has_key? "error"
339
+ end
340
+ end
341
+
342
+ should "return list of searches associated to the sent mailing" do
343
+ VCR.use_cassette('mailings/mailing_searches') do
344
+ response = @em.mailing_searches 111
345
+ assert response.has_key? "error"
346
+ end
347
+ end
348
+
349
+ should "update mailing" do
350
+ VCR.use_cassette('mailings/update_mailing') do
351
+ response = @em.update_mailing 111, :status => 'canceled'
352
+ assert response.has_key? "error"
353
+ end
354
+ end
355
+
356
+ should "remove a mailing" do
357
+ VCR.use_cassette('mailings/remove_mailing') do
358
+ response = @em.remove_mailing 111
359
+ assert response.has_key? "error"
360
+ end
361
+ end
362
+
363
+ should "cancel queued mailing" do
364
+ VCR.use_cassette('mailings/cancel_queued_mailing') do
365
+ response = @em.cancel_queued_mailing 111
366
+ assert response.has_key? "error"
367
+ end
368
+ end
369
+
370
+ should "forward mailing to additional recipients" do
371
+ VCR.use_cassette('mailings/forward_mailing_to_additional_recipients') do
372
+ response = @em.forward_mailing_to_additional_recipients 111, 102, :recipient_emails => ["testme123@gmail.com"]
373
+ assert response.has_key? "error"
374
+ end
375
+ end
376
+
377
+ should "send prior mailing to additional recipients" do
378
+ VCR.use_cassette('mailings/send_existing_mailing') do
379
+ response = @em.send_existing_mailing 111, :recipient_emails => ["testme123@gmail.com"]
380
+ assert response.has_key? "error"
381
+ end
382
+ end
383
+
384
+ should "return headsup email addresses" do
385
+ VCR.use_cassette('mailings/mailing_headsup') do
386
+ response = @em.mailing_headsup 111
387
+ assert response.has_key? "error"
388
+ end
389
+ end
390
+
391
+ should "validate mailing has valid personalization-tag syntax" do
392
+ VCR.use_cassette('mailings/validate_mailing') do
393
+ response = @em.validate_mailing :subject => "Another Test"
394
+ assert response == true
395
+ end
396
+ end
397
+
398
+ should "declares winner of split test" do
399
+ VCR.use_cassette('mailings/declare_winner_of_split_test') do
400
+ response = @em.declare_winner_of_split_test 111, 112
401
+ assert response.has_key? "error"
402
+ end
403
+ end
404
+
405
+ end
406
+
407
+ context "testing of methods involving calls to the response endpoints" do
408
+ should "return mailing by id" do
409
+ VCR.use_cassette('response/my_account_summary') do
410
+ response = @em.my_account_summary
411
+ assert_instance_of Array, response
412
+ end
413
+ end
414
+
415
+ should "method will return the counts of each type of response activity for a particular mailing." do
416
+ VCR.use_cassette('response/single_response_summary') do
417
+ response = @em.single_response_summary 111
418
+ assert response.has_key? "error"
419
+ end
420
+ end
421
+
422
+ should "Get the list of messages by id by a particular action actions include (sends, in_progress, deliveries, opens, links, clicks, forwards, optouts, signups, shares, customer_shares, customer_share_clicks)" do
423
+ %w(sends in_progress deliveries opens links clicks forwards optouts signups shares customer_shares customer_share_clicks).each do |action|
424
+ VCR.use_cassette('response/response_mailing_information_' + action) do
425
+ response = @em.response_mailing_information 111, action
426
+ assert response.has_key? "error"
427
+ end
428
+ end
429
+ end
430
+
431
+ should "Get the customer share associated with the share id." do
432
+ VCR.use_cassette('response/customer_share_information') do
433
+ response = @em.customer_share_information 111
434
+ assert response.has_key? "error"
435
+ end
436
+ end
437
+
438
+ should "Get overview of shares pertaining to this mailing_id." do
439
+ VCR.use_cassette('response/mailing_shares_overview') do
440
+ response = @em.mailing_shares_overview 111
441
+ assert response.has_key? "error"
442
+ end
443
+ end
444
+
445
+ end
446
+
447
+ context "testing of methods involving calls to the searches endpoints" do
448
+
449
+ should "Retrieve a list of saved searches." do
450
+ VCR.use_cassette('searches/my_searches') do
451
+ response = @em.my_searches
452
+ assert_instance_of Array, response
453
+ end
454
+ end
455
+
456
+ should "Retrieve a single search." do
457
+ VCR.use_cassette('searches/single_search') do
458
+ response = @em.single_search 111
459
+ assert response.has_key? "error"
460
+ end
461
+ end
462
+
463
+ should "create a single search." do
464
+ VCR.use_cassette('searches/create_search') do
465
+ response = @em.create_search :name => "New Search", :criteria => [ "or", ["group", "eq", "Monthly Newsletter"] ]
466
+ assert_instance_of Fixnum, response
467
+ end
468
+ end
469
+
470
+ should "update a single search." do
471
+ VCR.use_cassette('searches/update_search') do
472
+ response = @em.update_search 111, :name => "New Search", :criteria => [ "or", ["group", "eq", "Monthly Newsletter"] ]
473
+ assert response.has_key? "error"
474
+ end
475
+ end
476
+
477
+ should "remove a single search." do
478
+ VCR.use_cassette('searches/remove_search') do
479
+ response = @em.remove_search 111
480
+ assert response.has_key? "error"
481
+ end
482
+ end
483
+
484
+ should "return list of members of search id." do
485
+ VCR.use_cassette('searches/get_members_of_search') do
486
+ response = @em.get_members_of_search 111
487
+ assert response.has_key? "error"
488
+ end
489
+ end
490
+
491
+ end
492
+
493
+ context "testing of methods involving calls to the webhooks endpoints" do
494
+ should "Retrieve a list of webhooks." do
495
+ VCR.use_cassette('webhooks/my_webhooks') do
496
+ response = @em.my_webhooks
497
+ assert_instance_of Array, response
498
+ end
499
+ end
500
+
501
+ should "Retrieve single webhook." do
502
+ VCR.use_cassette('webhooks/get_webhook') do
503
+ response = @em.get_webhook 111
504
+ assert response.has_key? "error"
505
+ end
506
+ end
507
+
508
+ should "Retrieve webhook events list." do
509
+ VCR.use_cassette('webhooks/webhook_events') do
510
+ response = @em.webhook_events 111
511
+ assert response.has_key? "error"
512
+ end
513
+ end
514
+
515
+ should "Add webhook" do
516
+ VCR.use_cassette('webhooks/add_webhook') do
517
+ response = @em.add_webhook :url => "http://www.google.com", :event => "mailing_finish"
518
+ assert_instance_of Fixnum, response
519
+ end
520
+ end
521
+
522
+ should "update webhook" do
523
+ VCR.use_cassette('webhooks/update_webhook') do
524
+ response = @em.update_webhook 111, :url => "http://www.yahoo.com"
525
+ assert response.has_key? "error"
526
+ end
527
+ end
528
+
529
+ should "delete webhook" do
530
+ VCR.use_cassette('webhooks/remove_webhook') do
531
+ response = @em.remove_webhook 111
532
+ assert response.has_key? "error"
533
+ end
534
+ end
535
+
536
+ should "remove all webhooks" do
537
+ VCR.use_cassette('webhooks/remove_all_webhooks') do
538
+ response = @em.remove_all_webhooks
539
+ assert response == true
540
+ end
541
+ end
542
+
543
+ end
544
+
545
+ context "testing of methods involving calls to the triggers endpoints" do
546
+
547
+ should "Retrieve a list of triggers." do
548
+ VCR.use_cassette('triggers/my_triggers') do
549
+ response = @em.my_triggers
550
+ assert_instance_of Array, response
551
+ end
552
+ end
553
+
554
+ should "Add a trigger." do
555
+ VCR.use_cassette('triggers/add_trigger') do
556
+ response = @em.add_trigger :parent_mailing_id => 111, :name => "test", :event_type => "c", :object_ids => [100, 102]
557
+ assert response.has_key? "error"
558
+ end
559
+ end
560
+
561
+ should "Look up a trigger by trigger id.." do
562
+ VCR.use_cassette('triggers/get_trigger_by_id') do
563
+ response = @em.get_trigger_by_id 111
564
+ assert response.has_key? "error"
565
+ end
566
+ end
567
+
568
+ should "Update trigger." do
569
+ VCR.use_cassette('triggers/update_trigger') do
570
+ response = @em.update_trigger 111, :name => "Another test mailing update"
571
+ assert response.has_key? "error"
572
+ end
573
+ end
574
+
575
+ should "Remove a trigger." do
576
+ VCR.use_cassette('triggers/remove_trigger') do
577
+ response = @em.remove_trigger 111
578
+ assert response.has_key? "error"
579
+ end
580
+ end
581
+
582
+ should "return array of mailings sent by trigger." do
583
+ VCR.use_cassette('triggers/get_trigger_mailings') do
584
+ response = @em.get_trigger_mailings 111
585
+ assert response.has_key? "error"
586
+ end
587
+ end
588
+
589
+ end
590
+
591
+ end
592
+
593
+ def random_string(size = 6)
594
+ charset = %w{ 2 3 4 6 7 9 A C D E F G H J K M N P Q R T V W X Y Z}
595
+ (0...size).map{ charset.to_a[rand(charset.size)] }.join
596
+ end
597
+
598
+ end