-
Notifications
You must be signed in to change notification settings - Fork 260
/
sendgrid_test.go
3950 lines (3689 loc) · 109 KB
/
sendgrid_test.go
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 sendgrid
import (
"context"
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
"os"
"strconv"
"strings"
"testing"
"time"
"github.com/sendgrid/rest"
"github.com/sendgrid/sendgrid-go/helpers/mail"
"github.com/stretchr/testify/assert"
)
func TestLicenseYear(t *testing.T) {
d, err := os.ReadFile("LICENSE")
assert.Nil(t, err, "Cannot read the LICENSE file")
l := fmt.Sprintf("Copyright (C) %v, Twilio SendGrid, Inc.", time.Now().Year())
assert.True(t, strings.Contains(string(d), l), fmt.Sprintf("License date range is not correct, it should be: %v", l))
}
func TestRepoFiles(t *testing.T) {
fs := []string{
"Dockerfile",
".env_sample",
".gitignore",
".github/workflows/test-and-deploy.yml",
"CHANGELOG.md",
"CODE_OF_CONDUCT.md",
"CONTRIBUTING.md",
"LICENSE",
"PULL_REQUEST_TEMPLATE.md",
"README.md",
"TROUBLESHOOTING.md",
"USAGE.md",
}
for _, f := range fs {
_, err := os.Stat(f)
assert.False(t, os.IsNotExist(err), fmt.Sprintf("Repo file does not exist: %[1]v", f))
}
}
func TestGetRequest(t *testing.T) {
request := GetRequest("", "", "")
assert.Equal(t, "https://api.sendgrid.com", request.BaseURL, "Host default not set")
assert.Equal(t, "Bearer ", request.Headers["Authorization"], "Wrong default Authorization")
assert.Equal(t, "sendgrid/"+Version+";go", request.Headers["User-Agent"], "Wrong default User Agent")
request = GetRequest("API_KEY", "/v3/endpoint", "https://test.api.com")
assert.Equal(t, "Bearer API_KEY", request.Headers["Authorization"], "Wrong Authorization")
assert.Equal(t, "sendgrid/"+Version+";go", request.Headers["User-Agent"], "Wrong User Agent")
assert.Equal(t, "application/json", request.Headers["Accept"], "Wrong Accept Agent")
}
func ShouldHaveHeaders(request *rest.Request, t *testing.T) {
if request.Headers["Authorization"] != "Bearer API_KEY" {
t.Error("Wrong Authorization")
}
if request.Headers["User-Agent"] != "sendgrid/"+Version+";go" {
t.Error("Wrong User Agent")
}
if request.Headers["Accept"] != "application/json" {
t.Error("Wrong Accept header")
}
if request.Headers["On-Behalf-Of"] != "subuserUsername" {
t.Error("Wrong On-Behalf-Of")
}
}
func TestGetRequestSubuser(t *testing.T) {
request := GetRequestSubuser("API_KEY", "/v3/endpoint", "https://test.api.com", "subuserUsername")
if request.BaseURL != "https://test.api.com/v3/endpoint" {
t.Error("Host not set correctly")
}
ShouldHaveHeaders(&request, t)
}
func TestSetDataResidencyEU(t *testing.T) {
request := GetRequest("API_KEY", "", "")
request, err := SetDataResidency(request, "eu")
assert.Nil(t, err)
assert.Equal(t, "https://api.eu.sendgrid.com", request.BaseURL, "Host not correct as per the region")
}
func TestSetDataResidencyGlobal(t *testing.T) {
request := GetRequest("API_KEY", "", "https://api.sendgrid.com")
request, err := SetDataResidency(request, "global")
assert.Nil(t, err)
assert.Equal(t, "https://api.sendgrid.com", request.BaseURL, "Host not correct as per the region")
}
func TestSetDataResidencyOverrideHost(t *testing.T) {
request := GetRequest("API_KEY", "", "https://test.api.com")
request, err := SetDataResidency(request, "eu")
assert.Nil(t, err)
assert.Equal(t, "https://api.eu.sendgrid.com", request.BaseURL, "Host not correct as per the region")
}
func TestSetDataResidencyIncorrectRegion(t *testing.T) {
request := GetRequest("API_KEY", "", "")
_, err := SetDataResidency(request, "foo")
assert.NotNil(t, err, "error: region can only be \"eu\" or \"global\"")
}
func TestSetDataResidencyNullRegion(t *testing.T) {
request := GetRequest("API_KEY", "", "")
_, err := SetDataResidency(request, "")
assert.NotNil(t, err, "error: region can only be \"eu\" or \"global\"")
}
func TestSetDataResidencyDefaultRegion(t *testing.T) {
request := GetRequest("API_KEY", "", "")
assert.Equal(t, "https://api.sendgrid.com", request.BaseURL, "Host not correct as per the region")
}
func getRequest(endpoint string) rest.Request {
return GetRequest("SENDGRID_APIKEY", endpoint, "")
}
func TestCustomHTTPClient(t *testing.T) {
fakeServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
time.Sleep(time.Millisecond * 20)
fmt.Fprintln(w, "{\"message\": \"success\"}")
}))
defer fakeServer.Close()
apiKey := "SENDGRID_APIKEY"
host := fakeServer.URL
request := GetRequest(apiKey, "/v3/test_endpoint", host)
request.Method = "GET"
var custom rest.Client
custom.HTTPClient = &http.Client{Timeout: time.Millisecond * 10}
_, err := custom.Send(request)
assert.NotNil(t, err, "A timeout did not trigger as expected")
assert.True(t, strings.Contains(err.Error(), "Client.Timeout exceeded while awaiting headers"), "We did not receive the Timeout error")
}
func TestRequestRetry_rateLimit(t *testing.T) {
fakeServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("X-RateLimit-Reset", strconv.Itoa(int(time.Now().Add(1*time.Second).Unix())))
w.WriteHeader(http.StatusTooManyRequests)
}))
defer fakeServer.Close()
apiKey := "SENDGRID_APIKEY"
host := fakeServer.URL
request := GetRequest(apiKey, "/v3/test_endpoint", host)
request.Method = "GET"
var custom rest.Client
custom.HTTPClient = &http.Client{Timeout: time.Millisecond * 10}
DefaultClient = &custom
_, err := MakeRequestRetry(request)
assert.NotNil(t, err, "An error did not trigger")
assert.True(t, strings.Contains(err.Error(), "rate limit retry exceeded"), "We did not receive the rate limit error")
DefaultClient = rest.DefaultClient
}
func TestRequestRetry_rateLimit_noHeader(t *testing.T) {
fakeServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusTooManyRequests)
}))
defer fakeServer.Close()
apiKey := "SENDGRID_APIKEY"
host := fakeServer.URL
request := GetRequest(apiKey, "/v3/test_endpoint", host)
request.Method = "GET"
var custom rest.Client
custom.HTTPClient = &http.Client{Timeout: time.Millisecond * 10}
DefaultClient = &custom
_, err := MakeRequestRetry(request)
assert.NotNil(t, err, "An error did not trigger")
assert.True(t, strings.Contains(err.Error(), "rate limit retry exceeded"), "We did not receive the rate limit error")
DefaultClient = rest.DefaultClient
}
func TestRequestRetryWithContext_cancel(t *testing.T) {
fakeServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusTooManyRequests)
}))
defer fakeServer.Close()
apiKey := "SENDGRID_APIKEY"
host := fakeServer.URL
request := GetRequest(apiKey, "/v3/test_endpoint", host)
request.Method = "GET"
var custom rest.Client
custom.HTTPClient = &http.Client{Timeout: time.Millisecond * 10}
DefaultClient = &custom
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go func() {
time.Sleep(500 * time.Millisecond)
cancel()
}()
_, err := MakeRequestRetryWithContext(ctx, request)
assert.NotNil(t, err, "An error did not trigger")
assert.Equal(t, context.Canceled, err)
DefaultClient = rest.DefaultClient
}
func TestRequestAsync(t *testing.T) {
fakeServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
}))
defer fakeServer.Close()
apiKey := "SENDGRID_APIKEY"
host := fakeServer.URL
request := GetRequest(apiKey, "/v3/test_endpoint", host)
request.Method = "GET"
var custom rest.Client
custom.HTTPClient = &http.Client{Timeout: time.Millisecond * 10}
DefaultClient = &custom
r, e := MakeRequestAsync(request)
select {
case <-r:
case err := <-e:
t.Errorf("Received an error,:%v", err)
case <-time.After(10 * time.Second):
t.Error("Timed out waiting for a response")
}
DefaultClient = rest.DefaultClient
}
func TestRequestAsync_rateLimit(t *testing.T) {
fakeServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("X-RateLimit-Reset", strconv.Itoa(int(time.Now().Add(1*time.Second).Unix())))
w.WriteHeader(http.StatusTooManyRequests)
}))
defer fakeServer.Close()
apiKey := "SENDGRID_APIKEY"
host := fakeServer.URL
request := GetRequest(apiKey, "/v3/test_endpoint", host)
request.Method = "GET"
var custom rest.Client
custom.HTTPClient = &http.Client{Timeout: time.Millisecond * 10}
DefaultClient = &custom
r, e := MakeRequestAsync(request)
select {
case <-r:
t.Error("Received a valid response")
return
case err := <-e:
assert.True(t, strings.Contains(err.Error(), "rate limit retry exceeded"), "We did not receive the rate limit error")
case <-time.After(10 * time.Second):
t.Error("Timed out waiting for an error")
}
DefaultClient = rest.DefaultClient
}
func Test_test_access_settings_activity_get(t *testing.T) {
request := getRequest("/v3/access_settings/activity")
request.Method = "GET"
queryParams := make(map[string]string)
queryParams["limit"] = "1"
request.QueryParams = queryParams
request.Headers["X-Mock"] = "200"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 200, response.StatusCode, "Wrong status code returned")
}
func Test_test_access_settings_whitelist_post(t *testing.T) {
request := getRequest("/v3/access_settings/whitelist")
request.Method = "POST"
request.Body = []byte(` {
"ips": [
{
"ip": "192.168.1.1"
},
{
"ip": "192.*.*.*"
},
{
"ip": "192.168.1.3/32"
}
]
}`)
request.Headers["X-Mock"] = "201"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 201, response.StatusCode, "Wrong status code returned")
}
func Test_test_access_settings_whitelist_get(t *testing.T) {
request := getRequest("/v3/access_settings/whitelist")
request.Method = "GET"
request.Headers["X-Mock"] = "200"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 200, response.StatusCode, "Wrong status code returned")
}
func Test_test_access_settings_whitelist_delete(t *testing.T) {
request := getRequest("/v3/access_settings/whitelist")
request.Method = "DELETE"
request.Body = []byte(` {
"ids": [
1,
2,
3
]
}`)
request.Headers["X-Mock"] = "204"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 204, response.StatusCode, "Wrong status code returned")
}
func Test_test_access_settings_whitelist__rule_id__get(t *testing.T) {
request := getRequest("/v3/access_settings/whitelist/{rule_id}")
request.Method = "GET"
request.Headers["X-Mock"] = "200"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 200, response.StatusCode, "Wrong status code returned")
}
func Test_test_access_settings_whitelist__rule_id__delete(t *testing.T) {
request := getRequest("/v3/access_settings/whitelist/{rule_id}")
request.Method = "DELETE"
request.Headers["X-Mock"] = "204"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 204, response.StatusCode, "Wrong status code returned")
}
func Test_test_alerts_post(t *testing.T) {
request := getRequest("/v3/alerts")
request.Method = "POST"
request.Body = []byte(` {
"email_to": "example@example.com",
"frequency": "daily",
"type": "stats_notification"
}`)
request.Headers["X-Mock"] = "201"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 201, response.StatusCode, "Wrong status code returned")
}
func Test_test_alerts_get(t *testing.T) {
request := getRequest("/v3/alerts")
request.Method = "GET"
request.Headers["X-Mock"] = "200"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 200, response.StatusCode, "Wrong status code returned")
}
func Test_test_alerts__alert_id__patch(t *testing.T) {
request := getRequest("/v3/alerts/{alert_id}")
request.Method = "PATCH"
request.Body = []byte(` {
"email_to": "example@example.com"
}`)
request.Headers["X-Mock"] = "200"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 200, response.StatusCode, "Wrong status code returned")
}
func Test_test_alerts__alert_id__get(t *testing.T) {
request := getRequest("/v3/alerts/{alert_id}")
request.Method = "GET"
request.Headers["X-Mock"] = "200"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 200, response.StatusCode, "Wrong status code returned")
}
func Test_test_alerts__alert_id__delete(t *testing.T) {
request := getRequest("/v3/alerts/{alert_id}")
request.Method = "DELETE"
request.Headers["X-Mock"] = "204"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 204, response.StatusCode, "Wrong status code returned")
}
func Test_test_api_keys_post(t *testing.T) {
request := getRequest("/v3/api_keys")
request.Method = "POST"
request.Body = []byte(` {
"name": "My API Key",
"sample": "data",
"scopes": [
"mail.send",
"alerts.create",
"alerts.read"
]
}`)
request.Headers["X-Mock"] = "201"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 201, response.StatusCode, "Wrong status code returned")
}
func Test_test_api_keys_get(t *testing.T) {
request := getRequest("/v3/api_keys")
request.Method = "GET"
queryParams := make(map[string]string)
queryParams["limit"] = "1"
request.QueryParams = queryParams
request.Headers["X-Mock"] = "200"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 200, response.StatusCode, "Wrong status code returned")
}
func Test_test_api_keys__api_key_id__put(t *testing.T) {
request := getRequest("/v3/api_keys/{api_key_id}")
request.Method = "PUT"
request.Body = []byte(` {
"name": "A New Hope",
"scopes": [
"user.profile.read",
"user.profile.update"
]
}`)
request.Headers["X-Mock"] = "200"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 200, response.StatusCode, "Wrong status code returned")
}
func Test_test_api_keys__api_key_id__patch(t *testing.T) {
request := getRequest("/v3/api_keys/{api_key_id}")
request.Method = "PATCH"
request.Body = []byte(` {
"name": "A New Hope"
}`)
request.Headers["X-Mock"] = "200"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 200, response.StatusCode, "Wrong status code returned")
}
func Test_test_api_keys__api_key_id__get(t *testing.T) {
request := getRequest("/v3/api_keys/{api_key_id}")
request.Method = "GET"
request.Headers["X-Mock"] = "200"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 200, response.StatusCode, "Wrong status code returned")
}
func Test_test_api_keys__api_key_id__delete(t *testing.T) {
request := getRequest("/v3/api_keys/{api_key_id}")
request.Method = "DELETE"
request.Headers["X-Mock"] = "204"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 204, response.StatusCode, "Wrong status code returned")
}
func Test_test_asm_groups_post(t *testing.T) {
request := getRequest("/v3/asm/groups")
request.Method = "POST"
request.Body = []byte(` {
"description": "Suggestions for products our users might like.",
"is_default": true,
"name": "Product Suggestions"
}`)
request.Headers["X-Mock"] = "201"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 201, response.StatusCode, "Wrong status code returned")
}
func Test_test_asm_groups_get(t *testing.T) {
request := getRequest("/v3/asm/groups")
request.Method = "GET"
queryParams := make(map[string]string)
queryParams["id"] = "1"
request.QueryParams = queryParams
request.Headers["X-Mock"] = "200"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 200, response.StatusCode, "Wrong status code returned")
}
func Test_test_asm_groups__group_id__patch(t *testing.T) {
request := getRequest("/v3/asm/groups/{group_id}")
request.Method = "PATCH"
request.Body = []byte(` {
"description": "Suggestions for items our users might like.",
"id": 103,
"name": "Item Suggestions"
}`)
request.Headers["X-Mock"] = "201"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 201, response.StatusCode, "Wrong status code returned")
}
func Test_test_asm_groups__group_id__get(t *testing.T) {
request := getRequest("/v3/asm/groups/{group_id}")
request.Method = "GET"
request.Headers["X-Mock"] = "200"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 200, response.StatusCode, "Wrong status code returned")
}
func Test_test_asm_groups__group_id__delete(t *testing.T) {
request := getRequest("/v3/asm/groups/{group_id}")
request.Method = "DELETE"
request.Headers["X-Mock"] = "204"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 204, response.StatusCode, "Wrong status code returned")
}
func Test_test_asm_groups__group_id__suppressions_post(t *testing.T) {
request := getRequest("/v3/asm/groups/{group_id}/suppressions")
request.Method = "POST"
request.Body = []byte(` {
"recipient_emails": [
"test1@example.com",
"test2@example.com"
]
}`)
request.Headers["X-Mock"] = "201"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 201, response.StatusCode, "Wrong status code returned")
}
func Test_test_asm_groups__group_id__suppressions_get(t *testing.T) {
request := getRequest("/v3/asm/groups/{group_id}/suppressions")
request.Method = "GET"
request.Headers["X-Mock"] = "200"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 200, response.StatusCode, "Wrong status code returned")
}
func Test_test_asm_groups__group_id__suppressions_search_post(t *testing.T) {
request := getRequest("/v3/asm/groups/{group_id}/suppressions/search")
request.Method = "POST"
request.Body = []byte(` {
"recipient_emails": [
"exists1@example.com",
"exists2@example.com",
"doesnotexists@example.com"
]
}`)
request.Headers["X-Mock"] = "200"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 200, response.StatusCode, "Wrong status code returned")
}
func Test_test_asm_groups__group_id__suppressions__email__delete(t *testing.T) {
request := getRequest("/v3/asm/groups/{group_id}/suppressions/{email}")
request.Method = "DELETE"
request.Headers["X-Mock"] = "204"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 204, response.StatusCode, "Wrong status code returned")
}
func Test_test_asm_suppressions_get(t *testing.T) {
request := getRequest("/v3/asm/suppressions")
request.Method = "GET"
request.Headers["X-Mock"] = "200"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 200, response.StatusCode, "Wrong status code returned")
}
func Test_test_asm_suppressions_global_post(t *testing.T) {
request := getRequest("/v3/asm/suppressions/global")
request.Method = "POST"
request.Body = []byte(` {
"recipient_emails": [
"test1@example.com",
"test2@example.com"
]
}`)
request.Headers["X-Mock"] = "201"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 201, response.StatusCode, "Wrong status code returned")
}
func Test_test_asm_suppressions_global__email__get(t *testing.T) {
request := getRequest("/v3/asm/suppressions/global/{email}")
request.Method = "GET"
request.Headers["X-Mock"] = "200"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 200, response.StatusCode, "Wrong status code returned")
}
func Test_test_asm_suppressions_global__email__delete(t *testing.T) {
request := getRequest("/v3/asm/suppressions/global/{email}")
request.Method = "DELETE"
request.Headers["X-Mock"] = "204"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 204, response.StatusCode, "Wrong status code returned")
}
func Test_test_asm_suppressions__email__get(t *testing.T) {
request := getRequest("/v3/asm/suppressions/{email}")
request.Method = "GET"
request.Headers["X-Mock"] = "200"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 200, response.StatusCode, "Wrong status code returned")
}
func Test_test_browsers_stats_get(t *testing.T) {
request := getRequest("/v3/browsers/stats")
request.Method = "GET"
queryParams := make(map[string]string)
queryParams["end_date"] = "2016-04-01"
queryParams["aggregated_by"] = "day"
queryParams["browsers"] = "test_string"
queryParams["limit"] = "test_string"
queryParams["offset"] = "test_string"
queryParams["start_date"] = "2016-01-01"
request.QueryParams = queryParams
request.Headers["X-Mock"] = "200"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 200, response.StatusCode, "Wrong status code returned")
}
func Test_test_campaigns_post(t *testing.T) {
request := getRequest("/v3/campaigns")
request.Method = "POST"
request.Body = []byte(` {
"categories": [
"spring line"
],
"custom_unsubscribe_url": "",
"html_content": "<html><head><title></title></head><body><p>Check out our spring line!</p></body></html>",
"ip_pool": "marketing",
"list_ids": [
110,
124
],
"plain_content": "Check out our spring line!",
"segment_ids": [
110
],
"sender_id": 124451,
"subject": "New Products for Spring!",
"suppression_group_id": 42,
"title": "March Newsletter"
}`)
request.Headers["X-Mock"] = "201"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 201, response.StatusCode, "Wrong status code returned")
}
func Test_test_campaigns_get(t *testing.T) {
request := getRequest("/v3/campaigns")
request.Method = "GET"
queryParams := make(map[string]string)
queryParams["limit"] = "1"
queryParams["offset"] = "1"
request.QueryParams = queryParams
request.Headers["X-Mock"] = "200"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 200, response.StatusCode, "Wrong status code returned")
}
func Test_test_campaigns__campaign_id__patch(t *testing.T) {
request := getRequest("/v3/campaigns/{campaign_id}")
request.Method = "PATCH"
request.Body = []byte(` {
"categories": [
"summer line"
],
"html_content": "<html><head><title></title></head><body><p>Check out our summer line!</p></body></html>",
"plain_content": "Check out our summer line!",
"subject": "New Products for Summer!",
"title": "May Newsletter"
}`)
request.Headers["X-Mock"] = "200"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 200, response.StatusCode, "Wrong status code returned")
}
func Test_test_campaigns__campaign_id__get(t *testing.T) {
request := getRequest("/v3/campaigns/{campaign_id}")
request.Method = "GET"
request.Headers["X-Mock"] = "200"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 200, response.StatusCode, "Wrong status code returned")
}
func Test_test_campaigns__campaign_id__delete(t *testing.T) {
request := getRequest("/v3/campaigns/{campaign_id}")
request.Method = "DELETE"
request.Headers["X-Mock"] = "204"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 204, response.StatusCode, "Wrong status code returned")
}
func Test_test_campaigns__campaign_id__schedules_patch(t *testing.T) {
request := getRequest("/v3/campaigns/{campaign_id}/schedules")
request.Method = "PATCH"
request.Body = []byte(` {
"send_at": 1489451436
}`)
request.Headers["X-Mock"] = "200"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 200, response.StatusCode, "Wrong status code returned")
}
func Test_test_campaigns__campaign_id__schedules_post(t *testing.T) {
request := getRequest("/v3/campaigns/{campaign_id}/schedules")
request.Method = "POST"
request.Body = []byte(` {
"send_at": 1489771528
}`)
request.Headers["X-Mock"] = "201"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 201, response.StatusCode, "Wrong status code returned")
}
func Test_test_campaigns__campaign_id__schedules_get(t *testing.T) {
request := getRequest("/v3/campaigns/{campaign_id}/schedules")
request.Method = "GET"
request.Headers["X-Mock"] = "200"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 200, response.StatusCode, "Wrong status code returned")
}
func Test_test_campaigns__campaign_id__schedules_delete(t *testing.T) {
request := getRequest("/v3/campaigns/{campaign_id}/schedules")
request.Method = "DELETE"
request.Headers["X-Mock"] = "204"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 204, response.StatusCode, "Wrong status code returned")
}
func Test_test_campaigns__campaign_id__schedules_now_post(t *testing.T) {
request := getRequest("/v3/campaigns/{campaign_id}/schedules/now")
request.Method = "POST"
request.Headers["X-Mock"] = "201"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 201, response.StatusCode, "Wrong status code returned")
}
func Test_test_campaigns__campaign_id__schedules_test_post(t *testing.T) {
request := getRequest("/v3/campaigns/{campaign_id}/schedules/test")
request.Method = "POST"
request.Body = []byte(` {
"to": "your.email@example.com"
}`)
request.Headers["X-Mock"] = "204"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 204, response.StatusCode, "Wrong status code returned")
}
func Test_test_categories_get(t *testing.T) {
request := getRequest("/v3/categories")
request.Method = "GET"
queryParams := make(map[string]string)
queryParams["category"] = "test_string"
queryParams["limit"] = "1"
queryParams["offset"] = "1"
request.QueryParams = queryParams
request.Headers["X-Mock"] = "200"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 200, response.StatusCode, "Wrong status code returned")
}
func Test_test_categories_stats_get(t *testing.T) {
request := getRequest("/v3/categories/stats")
request.Method = "GET"
queryParams := make(map[string]string)
queryParams["end_date"] = "2016-04-01"
queryParams["aggregated_by"] = "day"
queryParams["limit"] = "1"
queryParams["offset"] = "1"
queryParams["start_date"] = "2016-01-01"
queryParams["categories"] = "test_string"
request.QueryParams = queryParams
request.Headers["X-Mock"] = "200"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 200, response.StatusCode, "Wrong status code returned")
}
func Test_test_categories_stats_sums_get(t *testing.T) {
request := getRequest("/v3/categories/stats/sums")
request.Method = "GET"
queryParams := make(map[string]string)
queryParams["end_date"] = "2016-04-01"
queryParams["aggregated_by"] = "day"
queryParams["limit"] = "1"
queryParams["sort_by_metric"] = "test_string"
queryParams["offset"] = "1"
queryParams["start_date"] = "2016-01-01"
queryParams["sort_by_direction"] = "asc"
request.QueryParams = queryParams
request.Headers["X-Mock"] = "200"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 200, response.StatusCode, "Wrong status code returned")
}
func Test_test_clients_stats_get(t *testing.T) {
request := getRequest("/v3/clients/stats")
request.Method = "GET"
queryParams := make(map[string]string)
queryParams["aggregated_by"] = "day"
queryParams["start_date"] = "2016-01-01"
queryParams["end_date"] = "2016-04-01"
request.QueryParams = queryParams
request.Headers["X-Mock"] = "200"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 200, response.StatusCode, "Wrong status code returned")
}
func Test_test_clients__client_type__stats_get(t *testing.T) {
request := getRequest("/v3/clients/{client_type}/stats")
request.Method = "GET"
queryParams := make(map[string]string)
queryParams["aggregated_by"] = "day"
queryParams["start_date"] = "2016-01-01"
queryParams["end_date"] = "2016-04-01"
request.QueryParams = queryParams
request.Headers["X-Mock"] = "200"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 200, response.StatusCode, "Wrong status code returned")
}
func Test_test_contactdb_custom_fields_post(t *testing.T) {
request := getRequest("/v3/contactdb/custom_fields")
request.Method = "POST"
request.Body = []byte(` {
"name": "pet",
"type": "text"
}`)
request.Headers["X-Mock"] = "201"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 201, response.StatusCode, "Wrong status code returned")
}
func Test_test_contactdb_custom_fields_get(t *testing.T) {
request := getRequest("/v3/contactdb/custom_fields")
request.Method = "GET"
request.Headers["X-Mock"] = "200"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 200, response.StatusCode, "Wrong status code returned")
}
func Test_test_contactdb_custom_fields__custom_field_id__get(t *testing.T) {
request := getRequest("/v3/contactdb/custom_fields/{custom_field_id}")
request.Method = "GET"
request.Headers["X-Mock"] = "200"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 200, response.StatusCode, "Wrong status code returned")
}
func Test_test_contactdb_custom_fields__custom_field_id__delete(t *testing.T) {
request := getRequest("/v3/contactdb/custom_fields/{custom_field_id}")
request.Method = "DELETE"
request.Headers["X-Mock"] = "202"
response, err := MakeRequest(request)
if err != nil {
t.Log(err)
}
assert.Equal(t, 202, response.StatusCode, "Wrong status code returned")
}
func Test_test_contactdb_lists_post(t *testing.T) {
request := getRequest("/v3/contactdb/lists")