-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmailchimp_test.go
More file actions
1051 lines (973 loc) · 27.9 KB
/
mailchimp_test.go
File metadata and controls
1051 lines (973 loc) · 27.9 KB
1
2
3
4
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package mailchimp
import "bufio"
import "path/filepath"
import "os"
import "testing"
import "encoding/json"
//import "bytes"
//import "strings"
//import "time"
//import "fmt"
var CID = os.Getenv("MAILCHIMPCID")
var RSS = os.Getenv("MAILCHIMPRSS")
var EMAIL = os.Getenv("MAILCHIMPEMAIL")
var STORE = os.Getenv("MAILCHIMPSTORE")
var LIST = os.Getenv("MAILCHIMPLIST")
var schedule = make(chan string, 1)
var unschedule = make(chan string, 1)
var update = make(chan string, 1)
var del = make(chan string, 1)
var orderChannel = make(chan string, 1)
var folderUpdate = make(chan int, 1)
var folderDel = make(chan int, 1)
var interestGroup = make(chan bool, 1)
var interestGrouping = make(chan int, 1)
var chimp, err = New(os.Getenv("MAILCHIMPKEY"), true)
func populate(filename string, response interface{}) error {
filename = filepath.Join("json", filename+".json")
file, err := os.Open(filename)
if err != nil {
return nil
}
defer file.Close()
reader := bufio.NewReader(file)
b := make([]byte, 0)
for {
line, isPrefix, _ := reader.ReadLine()
b = append(b, line...)
if !isPrefix {
break
}
}
//some response types have an alterJson method that needs
//to be called before unmarshalling
switch r := response.(type) {
case alterJsoner:
json.Unmarshal(r.alterJson(b), response)
default:
json.Unmarshal(b, response)
}
return nil
}
func verify(t *testing.T, name string, expected interface{}, actual interface{}) {
if actual != expected {
t.Errorf("%s: expected %v but actual value was %d", name, expected, actual)
}
return
}
/*
func TestCampaignContent(t *testing.T) {
parameters := make(map[string]interface{})
parameters["cid"] = os.Getenv("MAILCHIMPCID")
parameters["for_archive"] = true
result, err := chimp.CampaignContent(parameters)
if err != nil {
t.Error("mailchimp.CampaignContent:", err)
}
if !strings.Contains(result.Html, "<head>") {
t.Error("mailchimp.CampaignContent: the Html field of the returned struct does not look like html")
}
}
*/
/*
func TestCampaignCreate(t *testing.T) {
parameters := make(map[string]interface{})
parameters["type"] = "regular"
options := make(map[string]interface{})
options["list_id"] = os.Getenv("MAILCHIMPLIST")
options["subject"] = "Go API test"
options["from_email"] = "support@partitus.com"
options["from_name"] = "Partitus"
options["to_name"] = "*|FNAME|*"
parameters["options"] = options
content := make(map[string]interface{})
content["html"] = "<p>Go API Test campaign html content</p>"
content["text"] = "Go API Test campaign text content"
parameters["content"] = content
cid, err := chimp.CampaignCreate(parameters)
if err != nil {
t.Error("mailchimp.CampaignsCreate:", err)
}
//send to TestCampaignSchedule
schedule <- cid
}
*/
/*
func TestCampaignDelete(t *testing.T) {
//wait for CampaignUnschedule
go func() {
parameters := make(map[string]interface{})
cid := <- del
parameters["cid"] = cid
_, err := chimp.CampaignDelete(parameters)
if err != nil {
t.Error("mailchimp.CampaignsDelete:", err)
}
}()
}
*/
/*
func TestCampaignEcommOrderAdd(t *testing.T) {
//untested
}
*/
/*
func TestCampaignPause(t *testing.T) {
parameters := make(map[string]interface{})
parameters["cid"] = os.Getenv("MAILCHIMPRSS")
_, err = chimp.CampaignPause(parameters)
if err != nil {
if err.(ChimpError).Err != `Cannot pause this campaign because it is currently "paused"` {
t.Error("mailchimp.CampaignsPause:", err)
}
}
}
*/
/*
func TestCampaignReplicate(t *testing.T) {
parameters := make(map[string]interface{})
parameters["cid"] = os.Getenv("MAILCHIMPCID")
_, err = chimp.CampaignReplicate(parameters)
if err != nil {
t.Error("mailchimp.CampaignReplicate", err)
}
}
*/
/*
func TestCampaignResume(t *testing.T) {
parameters := make(map[string]interface{})
parameters["cid"] = os.Getenv("MAILCHIMPRSS")
_, err = chimp.CampaignResume(parameters)
if err != nil {
if err.(ChimpError).Err != `Cannot resume this campaign because it is currently "sending"` {
t.Error("mailchimp.CampaignResume:", err)
}
}
}
*/
/*
func TestScheduleCampaign(t *testing.T) {
//waits for CampaignCreate
parameters := make(map[string]interface{})
cid := <- schedule
parameters["cid"] = cid
location, err := time.LoadLocation("Local")
parameters["schedule_time"] = time.Date(2012, 12, 25, 17, 30, 0, 0, location)
_, err = chimp.CampaignSchedule(parameters)
if err != nil {
t.Error("mailchimp.CampaignSchedule:", err)
}
unschedule <- cid
}
*/
/*
func TestCampaignSegmentTest(t *testing.T) {
parameters := make(map[string]interface{})
parameters["list_id"] = os.Getenv("MAILCHIMPLIST")
options := make(map[string]interface{})
options["match"] = "any"
conditions := make([]map[string]interface{}, 0, 1)
condition := make(map[string]interface{})
condition["field"] = "date"
condition["op"] = "lt"
condition["value"] = "last_campaign_sent"
options["conditions"] = append(conditions, condition)
parameters["options"] = options
i, err := chimp.CampaignSegmentTest(parameters)
if err != nil {
t.Error("mailchimp.CampaignSegmentTest:", err)
}
if i <= 0 {
t.Error("mailchimp.CampaignSegmentTest: expected count to be positive but got", i)
}
}
*/
/*
func TestCampaignSendNow(t *testing.T) {
//create a campaign to send
parameters := make(map[string]interface{})
parameters["type"] = "regular"
options := make(map[string]interface{})
options["list_id"] = os.Getenv("MAILCHIMPLIST")
options["subject"] = "Go API test"
options["from_email"] = "support@partitus.com"
options["from_name"] = "Partitus"
options["to_name"] = "*|FNAME|*"
parameters["options"] = options
content := make(map[string]interface{})
content["html"] = "<p>Go API Test campaign html content</p>"
content["text"] = "Go API Test campaign text content"
parameters["content"] = content
id, err := chimp.CampaignCreate(parameters)
if err != nil {
t.Error("mailchimp.CampaignsCreate:", err)
}
//now send it
response, err := chimp.CampaignSendNow(map[string]interface{}{"cid": id})
if err != nil {
t.Error("mailchimp.CampaignSendNow:", err)
}
if !response {
t.Error("mailchimp.CampaignSendNow failed to send")
}
//too soon to delete since it was just sent delete will fail
//manually delete later from account
}
*/
/*
func TestCampaignSendTest(t *testing.T) {
//create a campaign to send
parameters := make(map[string]interface{})
parameters["type"] = "regular"
options := make(map[string]interface{})
options["list_id"] = os.Getenv("MAILCHIMPLIST")
options["subject"] = "Go API test"
options["from_email"] = "support@partitus.com"
options["from_name"] = "Partitus"
options["to_name"] = "*|FNAME|*"
parameters["options"] = options
content := make(map[string]interface{})
content["html"] = "<p>Go API Test campaign html content</p>"
content["text"] = "Go API Test campaign text content"
parameters["content"] = content
id, err := chimp.CampaignCreate(parameters)
if err != nil {
t.Error("mailchimp.CampaignsCreate:", err)
}
//now send it
p := make(map[string]interface{})
p["cid"] = id
p["test_emails"] =[]string{"areed@partitus.com"}
response, err := chimp.CampaignSendTest(p)
if err != nil {
t.Error("mailchimp.CampaignSendTest:", err)
}
if !response {
t.Error("mailchimp.CampaignSendTest failed to send")
}
chimp.CampaignDelete(map[string]interface{}{"cid": id})
}
*/
/*
func TestCampaignShareReport(t *testing.T) {
result, err := chimp.CampaignShareReport(map[string]interface{}{"cid": CID})
if err != nil {
t.Error("mailchimp.CampaignShareReport:", err)
}
if !strings.HasPrefix(result.Url, "http") {
t.Error("Expected result.Url to be a valid url but got", result.Url)
}
}
*/
/*
func TestCampaignTemplateContent(t *testing.T) {
_, err := chimp.CampaignTemplateContent(map[string]interface{}{"cid": CID})
if err != nil {
t.Error("mailchimp.CampaignTemplateContent", err)
}
}
*/
/*
func TestCampaignUnschedule(t *testing.T) {
//waits for CampaignSchedule
parameters := make(map[string]interface{})
cid := <- unschedule
parameters["cid"] = cid
_, err := chimp.CampaignUnschedule(parameters)
if err != nil {
t.Error(err)
}
update <- cid
}
*/
/*
func TestCampaignUpdate(t *testing.T) {
//waits for CampaignUnschedule
parameters := make(map[string]interface{})
cid := <- update
parameters["cid"] = cid
parameters["name"] = "from_email"
parameters["value"] = "areed@partitus.com"
_, err := chimp.CampaignUpdate(parameters)
if err != nil {
t.Error(err)
}
del <- cid
}
*/
/*
func TestCampaigns(t *testing.T) {
parameters := make(map[string]interface{})
filters := make(map[string]interface{})
filters["status"] = "sent"
parameters["filters"] = filters
result, err := chimp.Campaigns(parameters)
if err != nil {
t.Error("mailchimp.Campaigns:", err)
}
if result.Data[0].Status != "sent" {
t.Error("mailchimp.Campaigns: json response did not properly unmarshal in CampaignsResult struct")
}
}
*/
/*
func TestCampaignAbuseReports(t *testing.T) {
_, err := chimp.CampaignAbuseReports(map[string]interface{}{"cid": CID})
if err != nil {
t.Error("mailchimp.CampaignAbuseReports:", err)
}
}
*/
/*
func TestCampaignAdvice(t *testing.T) {
_, err := chimp.CampaignAdvice(map[string]interface{}{"cid": CID})
if err != nil {
t.Error("mailchimp.CampaignAdvice", err)
}
}
*/
/*
func TestCampaignAnalytics(t *testing.T) {
_, err := chimp.CampaignAnalytics(map[string]interface{}{"cid": CID})
if err != nil {
if err.(ChimpError).Err != `Google Analytics Add-on required for this function` {
t.Error("mailchimp.CampaignAnalytics", err)
}
}
}
*/
/*
func TestCampaignBounceMessage(t *testing.T) {
_, err := chimp.CampaignBounceMessage(map[string]interface{}{"cid": CID, "email": "areed@partitus.com"})
if err != nil {
if err.(ChimpError).Code != 319 {
t.Error("mailchimp.CampaignBounceMessage", err)
}
}
}
*/
/*
func TestCampaignBounceMessages(t *testing.T) {
_, err := chimp.CampaignBounceMessages(map[string]interface{}{"cid": CID})
if err != nil {
t.Error("mailchimp.CampaignBounceMessages", err)
}
}
*/
/*
func TestCampaignClickStats(t *testing.T) {
_, err := chimp.CampaignClickStats(map[string]interface{}{"cid": CID})
if err != nil {
t.Error("mailchimp.CampaignClickStats", err)
}
}
*/
/*
func TestCampaignEcommOrders(t *testing.T) {
_, err := chimp.CampaignEcommOrders(map[string]interface{}{"cid": CID})
if err != nil {
t.Error("mailchimp.CampaignEcommOrders", err)
}
}
*/
/*
func TestCampaignEepUrlStats(t *testing.T) {
_, err := chimp.CampaignEepUrlStats(map[string]interface{}{"cid": CID})
if err != nil {
t.Error("mailchimp.CampaignEepUrlStats", err)
}
}
*/
/*
func TestCampaignEmailDomainPerformance(t *testing.T) {
_, err := chimp.CampaignEmailDomainPerformance(map[string]interface{}{"cid": CID})
if err != nil {
t.Error("mailchimp.CampaignEmailDomainPerformance", err)
}
}
*/
/*
func TestCampaignGeoOpens(t *testing.T) {
_, err := chimp.CampaignGeoOpens(map[string]interface{}{"cid": CID})
if err != nil {
t.Error("mailchimp.CampaignEmailGeoOpens", err)
}
}
*/
/*
func TestCampaignGeoOpensForCountry(t *testing.T) {
_, err := chimp.CampaignGeoOpensForCountry(map[string]interface{}{"cid": CID, "code": "US"})
if err != nil {
t.Error("mailchimp.CampaignGeoOpensForCountry", err)
}
}
*/
/*
func TestCampaignMembers(t *testing.T) {
result, err := chimp.CampaignMembers(map[string]interface{}{"cid": CID})
if err != nil {
t.Error("mailchimp.CampaignMembers", err)
}
if result.Total <= 0 {
t.Error("mailchimp.CampaignMembers: Expected total to be positive but got", result.Total)
}
if len(result.Data[0].Email) < 5 {
t.Error("mailchimp.CampaignMembers: First returned email address appears invalid:", result.Data[0].Email)
}
}
*/
/*
func TestCampaignStats(t *testing.T) {
result, err := chimp.CampaignStats(map[string]interface{}{"cid": CID})
if err != nil {
t.Error("mailchimp.CampaignStats", err)
}
if result.Emails_sent <= 0 {
t.Error("mailchimp.CampaignStats: expected emails_sent to be positive but got", result.Emails_sent)
}
}
*/
/*
func TestCampaignUnsubscribes(t *testing.T) {
_, err := chimp.CampaignUnsubscribes(map[string]interface{}{"cid": CID})
if err != nil {
t.Error("mailchimp.CampaignUnsubscribes", err)
}
}
*/
/*
func TestCampaignClickDetailAIM(t *testing.T) {
result, err := chimp.CampaignClickDetailAIM(map[string]interface{}{"cid": CID, "url": "http://example.com"})
if err != nil {
t.Error("mailchimp.CampaignClickDetailAIM", err)
}
t.Error(result)
}
*/
/*
func TestCampaignEmailStatsAIM(t *testing.T) {
result, err := chimp.CampaignEmailStatsAIM(map[string]interface{}{"cid": CID, "email_address": "areed@partitus.com"})
if err != nil {
t.Error("mailchimp.CampaignEmailStatsAIM", err)
}
if result.Success != 1 {
t.Error("mailchimp.CampaignEmailStatsAIM: expected to find 1 matching email but found", result.Success)
}
}
*/
/*
func TestCampaignEmailStatsAIMAll(t *testing.T) {
result, err := chimp.CampaignEmailStatsAIMAll(map[string]interface{}{"cid": CID})
if err != nil {
t.Error("mailchimp.CampaignEmailStatsAIMAll", err)
}
if _, ok := result.Data["areed@partitus.com"]; !ok {
t.Error("mailchimp.CampaignEmailStatsAIMAll: expected to get data for areed@partitus.com but didn't")
}
}
*/
/*
func TestCampaignNotOpenedAIM(t *testing.T) {
result, err := chimp.CampaignNotOpenedAIM(map[string]interface{}{"cid": CID})
if err != nil {
t.Error("mailchimp.CampaignNotOpenedAIM", err)
}
//this test will fail if a campaign has more unopens than the default page size of 1000
if len(result.Data) != result.Total {
t.Error("mailchimp.CampaignNotOpened: the length of the array of email addresses should equal Total count")
}
}
*/
/*
func TestCampaignOpenedAIM(t *testing.T) {
result, err := chimp.CampaignOpenedAIM(map[string]interface{}{"cid": CID})
if err != nil {
t.Error("mailchimp.CampaignOpenedAIM", err)
}
//this test will fail if a campaign has more opens than the default page size of 1000
if len(result.Data) != result.Total {
t.Error("mailchimp.CampaignOpenedAIM: the length of the array of email addresses should equal Total count")
}
}
*/
/*
func TestEcommOrderAdd(t *testing.T) {
parameters := make(map[string]interface{})
order := make(map[string]interface{})
//need a unique order id each time test is run
order_id := fmt.Sprint(time.Now())
order["id"] = order_id
order["email"] = EMAIL
order["total"] = 100.10
order["store_id"] = STORE
items := make([]map[string]interface{}, 1)
item := make(map[string]interface{})
item["product_id"] = "1000"
item["product_name"] = "widget_1"
item["category_id"] = 10
item["category_name"] = "widgets"
item["qty"] = 10.0
item["cost"] = 10.01
items = append(items, item)
order["items"] = items
parameters["order"] = order
go func() {
result, err := chimp.EcommOrderAdd(parameters)
if err != nil {
t.Error("mailchimp.EcommOrderAdd",err)
}
if !result {
t.Error("mailchimp.EcommOrderAdd: expected return value to be true but got", result)
} else {
orderChannel <- order_id
}
}()
}
*/
/*
func TestEcommOrderDel(t *testing.T) {
go func() {
parameters := make(map[string]interface{})
parameters["store_id"] = STORE
parameters["order_id"] = <- orderChannel
result, err := chimp.EcommOrderDel(parameters)
if err != nil {
t.Error("mailchimp.EcommOrderDel",err)
}
if !result {
t.Error("mailchimp.EcommOrderDel: expected return value to be true but got", result)
}
}()
}
*/
/*
func TestEcommOrders(t *testing.T) {
result, err := chimp.EcommOrders(nil)
if err != nil {
t.Error("mailchimp.EcommOrders", err)
}
if result.Data[0].Lines[0].Line_num != 1 {
t.Error("mailchimp.EcommOrders: expected first line_num of first order returned to be 1 but got", result.Data[0].Lines[0].Line_num)
}
}
*/
/*
func TestFolderAdd(t *testing.T) {
result, err := chimp.FolderAdd(map[string]interface{}{"name": "TesterFolder"})
if err != nil {
t.Error("mailchimp.FolderAdd", err)
}
if result <= 0 {
t.Error("Expected the folder_id to be a positive integer but got", result)
}
folderUpdate <- result
}
func TestFolderUpdate(t *testing.T) {
fid := <- folderUpdate
result, err := chimp.FolderUpdate(map[string]interface{}{"fid": fid, "name": "UpdatedTesterFolder"})
if err != nil {
t.Error("mailchimp.FolderUpdate", err)
}
if !result {
t.Error("mailchimp.FolderUpdate: expected result to be true but got", result)
}
folderDel <- fid
}
func TestFolderDel(t *testing.T) {
result, err := chimp.FolderDel(map[string]interface{}{"fid": <- folderDel})
if err != nil {
t.Error("mailchimp.FolderDel", err)
}
if !result {
t.Error("mailchimp.FolderDel expected result to be true but got", result)
}
}
*/
/*
func TestFolders(t *testing.T) {
result, err := chimp.Folders(nil)
if err != nil {
t.Error("mailchimp.Folders", err)
}
if result[0].Folder_id <= 0 {
t.Error("mailchimp.Folders: expected first Folder_id to be a positive integer but got", result[0].Folder_id)
}
}
*/
/*
func TestGmonkeyActivity(t *testing.T) {
_, err := chimp.GmonkeyActivity(nil)
if err != nil {
t.Error("mailchimp.GmonkeyActivity", err)
}
}
*/
/*
func TestGmonkeyAdd(t *testing.T) {
parameters := make(map[string]interface{})
parameters["id"] = LIST
parameters["email_address"] = []string{EMAIL}
result, err := chimp.GmonkeyAdd(parameters)
if err != nil {
t.Error("mailchimp.GmonkeyAdd", err)
}
if result.Success + result.Errors != 1 {
t.Errorf("mailchimp.GmonkeyAdd: expected either 1 success or 1 error but got %d successes and %d errors", result.Success, result.Errors)
}
if result.Errors != len(result.Data) {
t.Error("mailchimp:GmonkeyAdd: There should be one item in the data array for each error")
}
}
func TestGmonkeyDel(t *testing.T) {
parameters := make(map[string]interface{})
parameters["id"] = LIST
parameters["email_address"] = []string{EMAIL}
result, err := chimp.GmonkeyDel(parameters)
if err != nil {
t.Error("mailchimp.GmonkeyDel", err)
}
if result.Success + result.Errors != 1 {
t.Errorf("mailchimp.GmonkeyDel: expected either 1 success or 1 error but got %d successes and %d errors", result.Success, result.Errors)
}
if result.Errors != len(result.Data) {
t.Error("mailchimp:GmonkeyDel: There should be one item in the data array for each error")
}
}
func TestGmonkeyMembers(t *testing.T) {
_, err := chimp.GmonkeyMembers(nil)
if err != nil {
t.Error("mailchimp.GmonkeyMembers", err)
}
}
*/
/*
func TestCampaignsForEmail(t *testing.T) {
result, err := chimp.CampaignsForEmail(map[string]interface{}{"email_address": EMAIL})
if err != nil {
t.Error("mailchimp.CampaignsForEmail", err)
}
if len(result[0]) < 5 {
t.Error("mailchimp.CampaignsForEmail: expected a 10-character campaign ID but got", result[0])
}
}
*/
/*
func TestChimpChatter(t *testing.T) {
result, err := chimp.ChimpChatter(nil)
if err != nil {
t.Error("mailchimp.ChimpChatter", err)
}
if len(result[0].Message) <= 5 {
t.Error("mailchimp.ChimpChatter: first message looks too short to be a real message:", result[0].Message)
}
}
*/
/*
func TestGenerateText(t *testing.T) {
result, err := chimp.GenerateText(map[string]interface{}{"type": "html", "content": "<div><p>Paragraph in a div</p></div>"})
if err != nil {
t.Error("mailchimp.GenerateText", err)
}
if !strings.HasPrefix(result, "Paragraph in a div") {
t.Error("mailchimp.GenerateText: Expected result of `Paragraph in a div` but got", result)
}
}
*/
/*
func TestGetAccountDetails(t *testing.T) {
result, err := chimp.GetAccountDetails(nil)
if err != nil {
t.Error("mailchimp.GetAccountDetails", err)
}
if result.Contact.Email != EMAIL {
t.Error("mailchimp.GetAccountDetails: was expecting a differenct contact email address")
}
}
*/
/*
func TestGetVerifiedDomains(t *testing.T) {
result, err := chimp.GetVerifiedDomains(nil)
if err != nil {
t.Error("mailchimp.GetVerifiedDomains")
}
if result[0].Status != "verified" && result[0].Status != "pending" {
t.Error("mailchimp.GetVerifiedDomains: Expected first status to be \"verified\" or \"pending\" but got", result[0].Status)
}
}
*/
/*
Not Sure what the html parameter is supposed to be, so this method is untested
func TestInlineCss(t *testing.T) {
}
*/
/*
func TestListForEmail(t *testing.T) {
result, err := chimp.ListsForEmail(map[string]interface{}{"email_address": EMAIL})
if err != nil {
t.Error("mailchimp.ListsForEmail", err)
}
if len(result[0]) < 5 {
t.Error("mailchimp.ListsForEmail: Expected the first list id returned to be 10 characters but got", result[0])
}
}
*/
/*
func TestPing(t *testing.T) {
result, err := chimp.Ping()
if err != nil {
t.Error("mailchimp.Ping", err)
}
if result != "Everything's Chimpy!" {
t.Error(`Expected response "Everything's Chimpy!" but received`, result)
}
}
*/
/*
func TestListAbuseReportsResponse(t *testing.T) {
response := new(ListAbuseReportsResponse)
populate("listAbuseReports", response)
a := response.Total
if a != 2 {
t.Error("ListAbuseReportsResponse a: expected 2 but got", a)
}
b := response.Data[0].Type
if b != "AOL" {
t.Error("ListAbuseReportsResponse b: expected \"AOL\" but got", b)
}
c := response.Data[1].Date
if c.Day() != 3 {
t.Error("ListAbuseReportsResponse c: expected 3 got", c)
}
}
func TestListAbuseReports(t *testing.T) {
result, err := chimp.ListAbuseReports(map[string]interface{}{"id": LIST})
if err != nil {
t.Error("mailchimp.ListAbuseReport", err)
}
if result.Total != len(result.Data) {
t.Error("mailchimp.ListAbuseReport: Expected total to equal the number of abuse reports in Data")
}
}
*/
/*
func TestListActivityElement(t *testing.T) {
response := make([]ListActivityElement, 0)
populate("listActivity", &response)
a := response[0].User_id
if a != 1234567 {
t.Error("ListActivity: expected 1234567 but got", a)
}
b := response[0].Recipient_clicks
if b != 40 {
t.Error("ListActivity: expected 40 but got", b)
}
c := response[1].Other_adds
if c != 0 {
t.Error("ListActivity: expected 0 but got", c)
}
}
func TestListActivity(t *testing.T) {
response, err := chimp.ListActivity(map[string]interface{}{"id": LIST})
if err != nil {
t.Error("mailchimp.ListActivity", err)
}
if response[0].Day.Year() < 2000 {
t.Error("mailchimp.ListActivity: the year of the first day's values returned appears incorrect:", response[0].Day.Year())
}
}
*/
/*
func TestListBatchSubscribeResponse(t *testing.T) {
_ := new(ListBatchSubscribeResponse)
//need real json response for mocking
}
func TestListBatchSubscribe(t *testing.T) {
parameters := make(map[string]interface{})
parameters["id"] = LIST
type Email struct {
EMAIL string
EMAIL_TYPE string
}
parameters["batch"] = []Email{{EMAIL, "html"}}
parameters["double_optin"] = false
parameters["update_existing"] = true
result, err := chimp.ListBatchSubscribe(parameters)
if err != nil {
t.Error("mailchimp.ListBatchSubscribe", err)
}
if result.Add_count + result.Update_count != 1 {
t.Error("mailchimp.ListBatchSubscribe: Expected email to be subscribed or updated but it was not")
}
if len(result.Errors) != result.Error_count {
t.Error("mailchimp.ListBatchSubscribe: The error_count should equal the length of errors array")
}
}
*/
/* NO!
func TestListBatchUnsubscribeResponse(t *testing.T) {
_ := new(ListBatchUnsubscribeResponse)
//need real json response for mocking
}
//Don't run this test - can't be resubscribed via API
func TestListBatchUnsubscribe(t *testing.T) {
parameters := make(map[string]interface{})
parameters["id"] = LIST
parameters["emails"] = []string{EMAIL}
parameters["send_goodbye"] = false
result, err := chimp.ListBatchUnsubscribe(parameters)
if err != nil {
t.Error("mailchimp.ListBatchUnsubscribe", err)
}
if result.Success_count + result.Error_count != 1 {
t.Error("mailchimp.ListBatchUnsubscribe: Expected Success_count or Error_count to be 1")
}
if len(result.Errors) != result.Error_count {
t.Error("mailchimp.ListBatchUnsubscribe: Number of items in array doesn't equal Error_count")
}
}
*/
/*
func TestListClientsResponse(t *testing.T) {
response := new(ListClientsResponse)
populate("listClients", response)
a := response.Mobile.Clients[0].Members
if a != 9 {
t.Error("ListClientsResponse a: expected 9 but got", a)
}
b := response.Desktop.Penetration
if b != 0.83050847457627 {
t.Error("ListClientsResponse b: expected 0.83050847457627 but got", b)
}
c := response.Desktop.Clients[8].Percent
if c != 0.016949152542373 {
t.Error("ListClientsResponse c: expected 0.016949152542373 but got", c)
}
d := response.Mobile.Clients[1].Client
if d != "Android" {
t.Error("ListClientsResponse d: expected \"Android\" but got", d)
}
}
func TestListClients(t *testing.T) {
_, err := chimp.ListClients(map[string]interface{}{"id": LIST})
if err != nil {
t.Error("ListClients", err)
}
}
*/
/*
func TestListGrowthHistoryElement(t *testing.T) {
response := make(ListGrowthHistoryResponse, 0)
populate("listGrowthHistory", &response)
verify(t, "ListGrowthHistory", 5, int(response[0].Month.Month()))
verify(t, "ListGrowthHistory", 2, response[1].Existing)
verify(t, "ListGrowthHistory", 1, response[2].Imports)
verify(t, "ListGrowthHistory", 1, response[3].Optins)
}
func TestListGrowthHistory(t *testing.T) {
_, err := chimp.ListGrowthHistory(map[string]interface{}{"id": LIST})
if err != nil {
t.Error("ListGrowthHistory", err)
}
}
*/
/*
func TestListInterestGroupAdd(t *testing.T) {
parameters := make(map[string]interface{})
parameters["id"] = LIST
parameters["group_name"] = "Test Interest Group"
result, err := chimp.ListInterestGroupAdd(parameters)
if err != nil {
t.Error("ListInterestGroupAdd", err)
}
if !result {
t.Error("ListInterestGroupAdd: expected true but actual value was false")
}
interestGroup <- result
}
func TestListInterestGroupUpdate(t *testing.T) {
<- interestGroup
parameters := make(map[string]interface{})
parameters["id"] = LIST
parameters["old_name"] = "Test Interest Group"
parameters["new_name"] = "Updated Interest Group"
result, err := chimp.ListInterestGroupUpdate(parameters)
if err != nil {
t.Error("ListInterestGroupUpdate", err)
}
if !result {
t.Error("ListInterestGroupUpdate: expected true but actual value was false")
}
interestGroup <- result
}
func TestListInterestGroupDel(t *testing.T) {
<- interestGroup
parameters := make(map[string]interface{})
parameters["id"] = LIST
parameters["group_name"] = "Updated Interest Group"
result, err := chimp.ListInterestGroupDel(parameters)
if err != nil {
t.Error("ListInterstGroupDel", err)
}
if !result {
t.Error("ListInterestGroupDel: expected true but actual value was false")
}
}
*/
/*
func TestListInterestGrouingAdd (t *testing.T) {
parameters := make(map[string]interface{})
parameters["id"] = LIST
parameters["name"] = "Diet"
parameters["type"] = "radio"
parameters["groups"] = []string{"vegetarian", "carnivore"}
result, err := chimp.ListInterestGroupingAdd(parameters)
if err != nil {
t.Error("ListInterestGroupDel", err)