@@ -369,15 +369,15 @@ var SendTestCasesD3C = []OutgoingTestCase{
369
369
Label : "Audio Send" ,
370
370
MsgText : "audio caption" ,
371
371
MsgURN : "whatsapp:250788123123" ,
372
- MsgAttachments : []string {"audio/mpeg:https ://foo.bar/audio .mp3" },
372
+ MsgAttachments : []string {"audio/mpeg:http ://mock.com/3456/test .mp3" },
373
373
MockResponses : map [string ][]* httpx.MockResponse {
374
374
"*/messages" : {
375
375
httpx .NewMockResponse (201 , nil , []byte (`{ "messages": [{"id": "157b5e14568e8"}] }` )),
376
376
httpx .NewMockResponse (201 , nil , []byte (`{ "messages": [{"id": "157b5e14568e8"}] }` )),
377
377
},
378
378
},
379
379
ExpectedRequests : []ExpectedRequest {
380
- {Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"audio","audio":{"link":"https ://foo.bar/audio .mp3"}}` },
380
+ {Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"audio","audio":{"link":"http ://mock.com/3456/test .mp3"}}` },
381
381
{Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"text","text":{"body":"audio caption","preview_url":false}}` },
382
382
},
383
383
ExpectedExtIDs : []string {"157b5e14568e8" , "157b5e14568e8" },
@@ -386,7 +386,7 @@ var SendTestCasesD3C = []OutgoingTestCase{
386
386
Label : "Document Send" ,
387
387
MsgText : "document caption" ,
388
388
MsgURN : "whatsapp:250788123123" ,
389
- MsgAttachments : []string {"application/pdf:https ://foo.bar/document .pdf" },
389
+ MsgAttachments : []string {"application/pdf:http ://mock.com/7890/test .pdf" },
390
390
MockResponses : map [string ][]* httpx.MockResponse {
391
391
"https://waba-v2.360dialog.io/messages" : {
392
392
httpx .NewMockResponse (201 , nil , []byte (`{ "messages": [{"id": "157b5e14568e8"}] }` )),
@@ -395,7 +395,7 @@ var SendTestCasesD3C = []OutgoingTestCase{
395
395
ExpectedRequests : []ExpectedRequest {
396
396
{
397
397
Path : "/messages" ,
398
- Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"document","document":{"link":"https ://foo.bar/document .pdf","caption":"document caption","filename":"document .pdf"}}` ,
398
+ Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"document","document":{"link":"http ://mock.com/7890/test .pdf","caption":"document caption","filename":"test .pdf"}}` ,
399
399
},
400
400
},
401
401
ExpectedExtIDs : []string {"157b5e14568e8" },
@@ -404,7 +404,7 @@ var SendTestCasesD3C = []OutgoingTestCase{
404
404
Label : "Image Send" ,
405
405
MsgText : "image caption" ,
406
406
MsgURN : "whatsapp:250788123123" ,
407
- MsgAttachments : []string {"image/jpeg:https ://foo.bar/image .jpg" },
407
+ MsgAttachments : []string {"image/jpeg:http ://mock.com/1234/test .jpg" },
408
408
MockResponses : map [string ][]* httpx.MockResponse {
409
409
"https://waba-v2.360dialog.io/messages" : {
410
410
httpx .NewMockResponse (201 , nil , []byte (`{ "messages": [{"id": "157b5e14568e8"}] }` )),
@@ -413,7 +413,7 @@ var SendTestCasesD3C = []OutgoingTestCase{
413
413
ExpectedRequests : []ExpectedRequest {
414
414
{
415
415
Path : "/messages" ,
416
- Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"image","image":{"link":"https ://foo.bar/image .jpg","caption":"image caption"}}` ,
416
+ Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"image","image":{"link":"http ://mock.com/1234/test .jpg","caption":"image caption"}}` ,
417
417
},
418
418
},
419
419
ExpectedExtIDs : []string {"157b5e14568e8" },
@@ -422,7 +422,7 @@ var SendTestCasesD3C = []OutgoingTestCase{
422
422
Label : "Video Send" ,
423
423
MsgText : "video caption" ,
424
424
MsgURN : "whatsapp:250788123123" ,
425
- MsgAttachments : []string {"video/mp4:https ://foo.bar/video .mp4" },
425
+ MsgAttachments : []string {"video/mp4:http ://mock.com/5678/test .mp4" },
426
426
MockResponses : map [string ][]* httpx.MockResponse {
427
427
"https://waba-v2.360dialog.io/messages" : {
428
428
httpx .NewMockResponse (201 , nil , []byte (`{ "messages": [{"id": "157b5e14568e8"}] }` )),
@@ -431,7 +431,7 @@ var SendTestCasesD3C = []OutgoingTestCase{
431
431
ExpectedRequests : []ExpectedRequest {
432
432
{
433
433
Path : "/messages" ,
434
- Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"video","video":{"link":"https ://foo.bar/video .mp4","caption":"video caption"}}` ,
434
+ Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"video","video":{"link":"http ://mock.com/5678/test .mp4","caption":"video caption"}}` ,
435
435
},
436
436
},
437
437
ExpectedExtIDs : []string {"157b5e14568e8" },
@@ -524,7 +524,7 @@ var SendTestCasesD3C = []OutgoingTestCase{
524
524
MsgText : "Interactive Button Msg" ,
525
525
MsgURN : "whatsapp:250788123123" ,
526
526
MsgQuickReplies : []string {"BUTTON1" },
527
- MsgAttachments : []string {"image/jpeg:https ://foo.bar/image .jpg" },
527
+ MsgAttachments : []string {"image/jpeg:http ://mock.com/1234/test .jpg" },
528
528
MockResponses : map [string ][]* httpx.MockResponse {
529
529
"https://waba-v2.360dialog.io/messages" : {
530
530
httpx .NewMockResponse (201 , nil , []byte (`{ "messages": [{"id": "157b5e14568e8"}] }` )),
@@ -534,7 +534,7 @@ var SendTestCasesD3C = []OutgoingTestCase{
534
534
ExpectedRequests : []ExpectedRequest {
535
535
{
536
536
Path : "/messages" ,
537
- Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"interactive","interactive":{"type":"button","header":{"type":"image","image":{"link":"https ://foo.bar/image .jpg"}},"body":{"text":"Interactive Button Msg"},"action":{"buttons":[{"type":"reply","reply":{"id":"0","title":"BUTTON1"}}]}}}` ,
537
+ Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"interactive","interactive":{"type":"button","header":{"type":"image","image":{"link":"http ://mock.com/1234/test .jpg"}},"body":{"text":"Interactive Button Msg"},"action":{"buttons":[{"type":"reply","reply":{"id":"0","title":"BUTTON1"}}]}}}` ,
538
538
},
539
539
},
540
540
ExpectedExtIDs : []string {"157b5e14568e8" },
@@ -544,7 +544,7 @@ var SendTestCasesD3C = []OutgoingTestCase{
544
544
MsgText : "Interactive Button Msg" ,
545
545
MsgURN : "whatsapp:250788123123" ,
546
546
MsgQuickReplies : []string {"BUTTON1" },
547
- MsgAttachments : []string {"video/mp4:https ://foo.bar/video .mp4" },
547
+ MsgAttachments : []string {"video/mp4:http ://mock.com/5678/test .mp4" },
548
548
MockResponses : map [string ][]* httpx.MockResponse {
549
549
"https://waba-v2.360dialog.io/messages" : {
550
550
httpx .NewMockResponse (201 , nil , []byte (`{ "messages": [{"id": "157b5e14568e8"}] }` )),
@@ -554,7 +554,7 @@ var SendTestCasesD3C = []OutgoingTestCase{
554
554
ExpectedRequests : []ExpectedRequest {
555
555
{
556
556
Path : "/messages" ,
557
- Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"interactive","interactive":{"type":"button","header":{"type":"video","video":{"link":"https ://foo.bar/video .mp4"}},"body":{"text":"Interactive Button Msg"},"action":{"buttons":[{"type":"reply","reply":{"id":"0","title":"BUTTON1"}}]}}}` ,
557
+ Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"interactive","interactive":{"type":"button","header":{"type":"video","video":{"link":"http ://mock.com/5678/test .mp4"}},"body":{"text":"Interactive Button Msg"},"action":{"buttons":[{"type":"reply","reply":{"id":"0","title":"BUTTON1"}}]}}}` ,
558
558
},
559
559
},
560
560
ExpectedExtIDs : []string {"157b5e14568e8" },
@@ -564,7 +564,7 @@ var SendTestCasesD3C = []OutgoingTestCase{
564
564
MsgText : "Interactive Button Msg" ,
565
565
MsgURN : "whatsapp:250788123123" ,
566
566
MsgQuickReplies : []string {"BUTTON1" },
567
- MsgAttachments : []string {"document/pdf:https ://foo.bar/document .pdf" },
567
+ MsgAttachments : []string {"document/pdf:http ://mock.com/7890/test .pdf" },
568
568
MockResponses : map [string ][]* httpx.MockResponse {
569
569
"https://waba-v2.360dialog.io/messages" : {
570
570
httpx .NewMockResponse (201 , nil , []byte (`{ "messages": [{"id": "157b5e14568e8"}] }` )),
@@ -574,7 +574,7 @@ var SendTestCasesD3C = []OutgoingTestCase{
574
574
ExpectedRequests : []ExpectedRequest {
575
575
{
576
576
Path : "/messages" ,
577
- Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"interactive","interactive":{"type":"button","header":{"type":"document","document":{"link":"https ://foo.bar/document .pdf","filename":"document .pdf"}},"body":{"text":"Interactive Button Msg"},"action":{"buttons":[{"type":"reply","reply":{"id":"0","title":"BUTTON1"}}]}}}` ,
577
+ Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"interactive","interactive":{"type":"button","header":{"type":"document","document":{"link":"http ://mock.com/7890/test .pdf","filename":"test .pdf"}},"body":{"text":"Interactive Button Msg"},"action":{"buttons":[{"type":"reply","reply":{"id":"0","title":"BUTTON1"}}]}}}` ,
578
578
},
579
579
},
580
580
ExpectedExtIDs : []string {"157b5e14568e8" },
@@ -584,15 +584,15 @@ var SendTestCasesD3C = []OutgoingTestCase{
584
584
MsgText : "Interactive Button Msg" ,
585
585
MsgURN : "whatsapp:250788123123" ,
586
586
MsgQuickReplies : []string {"ROW1" , "ROW2" , "ROW3" },
587
- MsgAttachments : []string {"audio/mp3:https ://foo.bar/audio .mp3" },
587
+ MsgAttachments : []string {"audio/mp3:http ://mock.com/3456/test .mp3" },
588
588
MockResponses : map [string ][]* httpx.MockResponse {
589
589
"*/messages" : {
590
590
httpx .NewMockResponse (201 , nil , []byte (`{ "messages": [{"id": "157b5e14568e8"}] }` )),
591
591
httpx .NewMockResponse (201 , nil , []byte (`{ "messages": [{"id": "157b5e14568e8"}] }` )),
592
592
},
593
593
},
594
594
ExpectedRequests : []ExpectedRequest {
595
- {Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"audio","audio":{"link":"https ://foo.bar/audio .mp3"}}` },
595
+ {Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"audio","audio":{"link":"http ://mock.com/3456/test .mp3"}}` },
596
596
{Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"interactive","interactive":{"type":"button","body":{"text":"Interactive Button Msg"},"action":{"buttons":[{"type":"reply","reply":{"id":"0","title":"ROW1"}},{"type":"reply","reply":{"id":"1","title":"ROW2"}},{"type":"reply","reply":{"id":"2","title":"ROW3"}}]}}}` },
597
597
},
598
598
ExpectedExtIDs : []string {"157b5e14568e8" , "157b5e14568e8" },
@@ -602,15 +602,15 @@ var SendTestCasesD3C = []OutgoingTestCase{
602
602
MsgText : "Interactive List Msg" ,
603
603
MsgURN : "whatsapp:250788123123" ,
604
604
MsgQuickReplies : []string {"ROW1" , "ROW2" , "ROW3" , "ROW4" },
605
- MsgAttachments : []string {"image/jpeg:https ://foo.bar/image .jpg" },
605
+ MsgAttachments : []string {"image/jpeg:http ://mock.com/1234/test .jpg" },
606
606
MockResponses : map [string ][]* httpx.MockResponse {
607
607
"*/messages" : {
608
608
httpx .NewMockResponse (201 , nil , []byte (`{ "messages": [{"id": "157b5e14568e8"}] }` )),
609
609
httpx .NewMockResponse (201 , nil , []byte (`{ "messages": [{"id": "157b5e14568e8"}] }` )),
610
610
},
611
611
},
612
612
ExpectedRequests : []ExpectedRequest {
613
- {Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"image","image":{"link":"https ://foo.bar/image .jpg"}}` },
613
+ {Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"image","image":{"link":"http ://mock.com/1234/test .jpg"}}` },
614
614
{Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"interactive","interactive":{"type":"list","body":{"text":"Interactive List Msg"},"action":{"button":"Menu","sections":[{"rows":[{"id":"0","title":"ROW1"},{"id":"1","title":"ROW2"},{"id":"2","title":"ROW3"},{"id":"3","title":"ROW4"}]}]}}}` },
615
615
},
616
616
ExpectedExtIDs : []string {"157b5e14568e8" , "157b5e14568e8" },
@@ -686,6 +686,30 @@ var SendTestCasesD3C = []OutgoingTestCase{
686
686
},
687
687
}
688
688
689
+ // setupMedia takes care of having the media files needed to our test server host
690
+ func setupMedia (mb * test.MockBackend ) {
691
+ imageJPG := test .NewMockMedia ("test.jpg" , "image/jpeg" , "http://mock.com/1234/test.jpg" , 1024 * 1024 , 640 , 480 , 0 , nil )
692
+
693
+ audioM4A := test .NewMockMedia ("test.m4a" , "audio/mp4" , "http://mock.com/2345/test.m4a" , 1024 * 1024 , 0 , 0 , 200 , nil )
694
+ audioMP3 := test .NewMockMedia ("test.mp3" , "audio/mpeg" , "http://mock.com/3456/test.mp3" , 1024 * 1024 , 0 , 0 , 200 , []courier.Media {audioM4A })
695
+
696
+ thumbJPG := test .NewMockMedia ("test.jpg" , "image/jpeg" , "http://mock.com/4567/test.jpg" , 1024 * 1024 , 640 , 480 , 0 , nil )
697
+ videoMP4 := test .NewMockMedia ("test.mp4" , "video/mp4" , "http://mock.com/5678/test.mp4" , 1024 * 1024 , 0 , 0 , 1000 , []courier.Media {thumbJPG })
698
+
699
+ videoMOV := test .NewMockMedia ("test.mov" , "video/quicktime" , "http://mock.com/6789/test.mov" , 100 * 1024 * 1024 , 0 , 0 , 2000 , nil )
700
+
701
+ filePDF := test .NewMockMedia ("test.pdf" , "application/pdf" , "http://mock.com/7890/test.pdf" , 100 * 1024 * 1024 , 0 , 0 , 0 , nil )
702
+
703
+ stickerWEBP := test .NewMockMedia ("test.webp" , "image/webp" , "http://mock.com/8901/test.webp" , 50 * 1024 , 480 , 480 , 0 , nil )
704
+
705
+ mb .MockMedia (imageJPG )
706
+ mb .MockMedia (audioMP3 )
707
+ mb .MockMedia (videoMP4 )
708
+ mb .MockMedia (videoMOV )
709
+ mb .MockMedia (filePDF )
710
+ mb .MockMedia (stickerWEBP )
711
+ }
712
+
689
713
func TestOutgoing (t * testing.T ) {
690
714
// shorter max msg length for testing
691
715
maxMsgLength = 100
@@ -696,5 +720,5 @@ func TestOutgoing(t *testing.T) {
696
720
})
697
721
checkRedacted := []string {"the-auth-token" }
698
722
699
- RunOutgoingTestCases (t , ChannelWAC , newWAHandler (courier .ChannelType ("D3C" ), "360Dialog" ), SendTestCasesD3C , checkRedacted , nil )
723
+ RunOutgoingTestCases (t , ChannelWAC , newWAHandler (courier .ChannelType ("D3C" ), "360Dialog" ), SendTestCasesD3C , checkRedacted , setupMedia )
700
724
}
0 commit comments