@@ -352,15 +352,15 @@ var SendTestCasesD3C = []OutgoingTestCase{
352
352
Label : "Audio Send" ,
353
353
MsgText : "audio caption" ,
354
354
MsgURN : "whatsapp:250788123123" ,
355
- MsgAttachments : []string {"audio/mpeg:https ://foo.bar/audio .mp3" },
355
+ MsgAttachments : []string {"audio/mpeg:http ://mock.com/1234/test .mp3" },
356
356
MockResponses : map [string ][]* httpx.MockResponse {
357
357
"*/messages" : {
358
358
httpx .NewMockResponse (201 , nil , []byte (`{ "messages": [{"id": "157b5e14568e8"}] }` )),
359
359
httpx .NewMockResponse (201 , nil , []byte (`{ "messages": [{"id": "157b5e14568e8"}] }` )),
360
360
},
361
361
},
362
362
ExpectedRequests : []ExpectedRequest {
363
- {Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"audio","audio":{"link":"https ://foo.bar/audio .mp3"}}` },
363
+ {Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"audio","audio":{"link":"http ://mock.com/1234/test .mp3"}}` },
364
364
{Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"text","text":{"body":"audio caption","preview_url":false}}` },
365
365
},
366
366
ExpectedExtIDs : []string {"157b5e14568e8" , "157b5e14568e8" },
@@ -369,7 +369,7 @@ var SendTestCasesD3C = []OutgoingTestCase{
369
369
Label : "Document Send" ,
370
370
MsgText : "document caption" ,
371
371
MsgURN : "whatsapp:250788123123" ,
372
- MsgAttachments : []string {"application/pdf:https ://foo.bar/document .pdf" },
372
+ MsgAttachments : []string {"application/pdf:http ://mock.com/1234/test .pdf" },
373
373
MockResponses : map [string ][]* httpx.MockResponse {
374
374
"https://waba-v2.360dialog.io/messages" : {
375
375
httpx .NewMockResponse (201 , nil , []byte (`{ "messages": [{"id": "157b5e14568e8"}] }` )),
@@ -378,7 +378,7 @@ var SendTestCasesD3C = []OutgoingTestCase{
378
378
ExpectedRequests : []ExpectedRequest {
379
379
{
380
380
Path : "/messages" ,
381
- Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"document","document":{"link":"https ://foo.bar/document .pdf","caption":"document caption","filename":"document .pdf"}}` ,
381
+ Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"document","document":{"link":"http ://mock.com/1234/test .pdf","caption":"document caption","filename":"test .pdf"}}` ,
382
382
},
383
383
},
384
384
ExpectedExtIDs : []string {"157b5e14568e8" },
@@ -387,7 +387,7 @@ var SendTestCasesD3C = []OutgoingTestCase{
387
387
Label : "Image Send" ,
388
388
MsgText : "image caption" ,
389
389
MsgURN : "whatsapp:250788123123" ,
390
- MsgAttachments : []string {"image/jpeg:https ://foo.bar/image .jpg" },
390
+ MsgAttachments : []string {"image/jpeg:http ://mock.com/1234/test .jpg" },
391
391
MockResponses : map [string ][]* httpx.MockResponse {
392
392
"https://waba-v2.360dialog.io/messages" : {
393
393
httpx .NewMockResponse (201 , nil , []byte (`{ "messages": [{"id": "157b5e14568e8"}] }` )),
@@ -396,7 +396,7 @@ var SendTestCasesD3C = []OutgoingTestCase{
396
396
ExpectedRequests : []ExpectedRequest {
397
397
{
398
398
Path : "/messages" ,
399
- Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"image","image":{"link":"https ://foo.bar/image .jpg","caption":"image caption"}}` ,
399
+ Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"image","image":{"link":"http ://mock.com/1234/test .jpg","caption":"image caption"}}` ,
400
400
},
401
401
},
402
402
ExpectedExtIDs : []string {"157b5e14568e8" },
@@ -405,7 +405,7 @@ var SendTestCasesD3C = []OutgoingTestCase{
405
405
Label : "Video Send" ,
406
406
MsgText : "video caption" ,
407
407
MsgURN : "whatsapp:250788123123" ,
408
- MsgAttachments : []string {"video/mp4:https ://foo.bar/video .mp4" },
408
+ MsgAttachments : []string {"video/mp4:http ://mock.com/1234/test .mp4" },
409
409
MockResponses : map [string ][]* httpx.MockResponse {
410
410
"https://waba-v2.360dialog.io/messages" : {
411
411
httpx .NewMockResponse (201 , nil , []byte (`{ "messages": [{"id": "157b5e14568e8"}] }` )),
@@ -414,7 +414,7 @@ var SendTestCasesD3C = []OutgoingTestCase{
414
414
ExpectedRequests : []ExpectedRequest {
415
415
{
416
416
Path : "/messages" ,
417
- Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"video","video":{"link":"https ://foo.bar/video .mp4","caption":"video caption"}}` ,
417
+ Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"video","video":{"link":"http ://mock.com/1234/test .mp4","caption":"video caption"}}` ,
418
418
},
419
419
},
420
420
ExpectedExtIDs : []string {"157b5e14568e8" },
@@ -507,7 +507,7 @@ var SendTestCasesD3C = []OutgoingTestCase{
507
507
MsgText : "Interactive Button Msg" ,
508
508
MsgURN : "whatsapp:250788123123" ,
509
509
MsgQuickReplies : []string {"BUTTON1" },
510
- MsgAttachments : []string {"image/jpeg:https ://foo.bar/image .jpg" },
510
+ MsgAttachments : []string {"image/jpeg:http ://mock.com/1234/test .jpg" },
511
511
MockResponses : map [string ][]* httpx.MockResponse {
512
512
"https://waba-v2.360dialog.io/messages" : {
513
513
httpx .NewMockResponse (201 , nil , []byte (`{ "messages": [{"id": "157b5e14568e8"}] }` )),
@@ -517,7 +517,7 @@ var SendTestCasesD3C = []OutgoingTestCase{
517
517
ExpectedRequests : []ExpectedRequest {
518
518
{
519
519
Path : "/messages" ,
520
- 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"}}]}}}` ,
520
+ 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"}}]}}}` ,
521
521
},
522
522
},
523
523
ExpectedExtIDs : []string {"157b5e14568e8" },
@@ -527,7 +527,7 @@ var SendTestCasesD3C = []OutgoingTestCase{
527
527
MsgText : "Interactive Button Msg" ,
528
528
MsgURN : "whatsapp:250788123123" ,
529
529
MsgQuickReplies : []string {"BUTTON1" },
530
- MsgAttachments : []string {"video/mp4:https ://foo.bar/video .mp4" },
530
+ MsgAttachments : []string {"video/mp4:http ://mock.com/1234/test .mp4" },
531
531
MockResponses : map [string ][]* httpx.MockResponse {
532
532
"https://waba-v2.360dialog.io/messages" : {
533
533
httpx .NewMockResponse (201 , nil , []byte (`{ "messages": [{"id": "157b5e14568e8"}] }` )),
@@ -537,7 +537,7 @@ var SendTestCasesD3C = []OutgoingTestCase{
537
537
ExpectedRequests : []ExpectedRequest {
538
538
{
539
539
Path : "/messages" ,
540
- 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"}}]}}}` ,
540
+ Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"interactive","interactive":{"type":"button","header":{"type":"video","video":{"link":"http ://mock.com/1234/test .mp4"}},"body":{"text":"Interactive Button Msg"},"action":{"buttons":[{"type":"reply","reply":{"id":"0","title":"BUTTON1"}}]}}}` ,
541
541
},
542
542
},
543
543
ExpectedExtIDs : []string {"157b5e14568e8" },
@@ -547,7 +547,7 @@ var SendTestCasesD3C = []OutgoingTestCase{
547
547
MsgText : "Interactive Button Msg" ,
548
548
MsgURN : "whatsapp:250788123123" ,
549
549
MsgQuickReplies : []string {"BUTTON1" },
550
- MsgAttachments : []string {"document/pdf:https ://foo.bar/document .pdf" },
550
+ MsgAttachments : []string {"document/pdf:http ://mock.com/1234/test .pdf" },
551
551
MockResponses : map [string ][]* httpx.MockResponse {
552
552
"https://waba-v2.360dialog.io/messages" : {
553
553
httpx .NewMockResponse (201 , nil , []byte (`{ "messages": [{"id": "157b5e14568e8"}] }` )),
@@ -557,7 +557,7 @@ var SendTestCasesD3C = []OutgoingTestCase{
557
557
ExpectedRequests : []ExpectedRequest {
558
558
{
559
559
Path : "/messages" ,
560
- 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"}}]}}}` ,
560
+ Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"interactive","interactive":{"type":"button","header":{"type":"document","document":{"link":"http ://mock.com/1234/test .pdf","filename":"test .pdf"}},"body":{"text":"Interactive Button Msg"},"action":{"buttons":[{"type":"reply","reply":{"id":"0","title":"BUTTON1"}}]}}}` ,
561
561
},
562
562
},
563
563
ExpectedExtIDs : []string {"157b5e14568e8" },
@@ -567,15 +567,15 @@ var SendTestCasesD3C = []OutgoingTestCase{
567
567
MsgText : "Interactive Button Msg" ,
568
568
MsgURN : "whatsapp:250788123123" ,
569
569
MsgQuickReplies : []string {"ROW1" , "ROW2" , "ROW3" },
570
- MsgAttachments : []string {"audio/mp3:https ://foo.bar/audio .mp3" },
570
+ MsgAttachments : []string {"audio/mp3:http ://mock.com/1234/test .mp3" },
571
571
MockResponses : map [string ][]* httpx.MockResponse {
572
572
"*/messages" : {
573
573
httpx .NewMockResponse (201 , nil , []byte (`{ "messages": [{"id": "157b5e14568e8"}] }` )),
574
574
httpx .NewMockResponse (201 , nil , []byte (`{ "messages": [{"id": "157b5e14568e8"}] }` )),
575
575
},
576
576
},
577
577
ExpectedRequests : []ExpectedRequest {
578
- {Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"audio","audio":{"link":"https ://foo.bar/audio .mp3"}}` },
578
+ {Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"audio","audio":{"link":"http ://mock.com/1234/test .mp3"}}` },
579
579
{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"}}]}}}` },
580
580
},
581
581
ExpectedExtIDs : []string {"157b5e14568e8" , "157b5e14568e8" },
@@ -585,15 +585,15 @@ var SendTestCasesD3C = []OutgoingTestCase{
585
585
MsgText : "Interactive List Msg" ,
586
586
MsgURN : "whatsapp:250788123123" ,
587
587
MsgQuickReplies : []string {"ROW1" , "ROW2" , "ROW3" , "ROW4" },
588
- MsgAttachments : []string {"image/jpeg:https ://foo.bar/image .jpg" },
588
+ MsgAttachments : []string {"image/jpeg:http ://mock.com/1234/test .jpg" },
589
589
MockResponses : map [string ][]* httpx.MockResponse {
590
590
"*/messages" : {
591
591
httpx .NewMockResponse (201 , nil , []byte (`{ "messages": [{"id": "157b5e14568e8"}] }` )),
592
592
httpx .NewMockResponse (201 , nil , []byte (`{ "messages": [{"id": "157b5e14568e8"}] }` )),
593
593
},
594
594
},
595
595
ExpectedRequests : []ExpectedRequest {
596
- {Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"image","image":{"link":"https ://foo.bar/image .jpg"}}` },
596
+ {Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"image","image":{"link":"http ://mock.com/1234/test .jpg"}}` },
597
597
{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"}]}]}}}` },
598
598
},
599
599
ExpectedExtIDs : []string {"157b5e14568e8" , "157b5e14568e8" },
@@ -669,6 +669,30 @@ var SendTestCasesD3C = []OutgoingTestCase{
669
669
},
670
670
}
671
671
672
+ // setupMedia takes care of having the media files needed to our test server host
673
+ func setupMedia (mb * test.MockBackend ) {
674
+ imageJPG := test .NewMockMedia ("test.jpg" , "image/jpeg" , "http://mock.com/1234/test.jpg" , 1024 * 1024 , 640 , 480 , 0 , nil )
675
+
676
+ audioM4A := test .NewMockMedia ("test.m4a" , "audio/mp4" , "http://mock.com/2345/test.m4a" , 1024 * 1024 , 0 , 0 , 200 , nil )
677
+ audioMP3 := test .NewMockMedia ("test.mp3" , "audio/mpeg" , "http://mock.com/3456/test.mp3" , 1024 * 1024 , 0 , 0 , 200 , []courier.Media {audioM4A })
678
+
679
+ thumbJPG := test .NewMockMedia ("test.jpg" , "image/jpeg" , "http://mock.com/4567/test.jpg" , 1024 * 1024 , 640 , 480 , 0 , nil )
680
+ videoMP4 := test .NewMockMedia ("test.mp4" , "video/mp4" , "http://mock.com/5678/test.mp4" , 1024 * 1024 , 0 , 0 , 1000 , []courier.Media {thumbJPG })
681
+
682
+ videoMOV := test .NewMockMedia ("test.mov" , "video/quicktime" , "http://mock.com/6789/test.mov" , 100 * 1024 * 1024 , 0 , 0 , 2000 , nil )
683
+
684
+ filePDF := test .NewMockMedia ("test.pdf" , "application/pdf" , "http://mock.com/7890/test.pdf" , 100 * 1024 * 1024 , 0 , 0 , 0 , nil )
685
+
686
+ stickerWEBP := test .NewMockMedia ("test.webp" , "image/webp" , "http://mock.com/8901/test.webp" , 50 * 1024 , 480 , 480 , 0 , nil )
687
+
688
+ mb .MockMedia (imageJPG )
689
+ mb .MockMedia (audioMP3 )
690
+ mb .MockMedia (videoMP4 )
691
+ mb .MockMedia (videoMOV )
692
+ mb .MockMedia (filePDF )
693
+ mb .MockMedia (stickerWEBP )
694
+ }
695
+
672
696
func TestOutgoing (t * testing.T ) {
673
697
// shorter max msg length for testing
674
698
maxMsgLength = 100
@@ -679,5 +703,5 @@ func TestOutgoing(t *testing.T) {
679
703
})
680
704
checkRedacted := []string {"the-auth-token" }
681
705
682
- RunOutgoingTestCases (t , ChannelWAC , newWAHandler (courier .ChannelType ("D3C" ), "360Dialog" ), SendTestCasesD3C , checkRedacted , nil )
706
+ RunOutgoingTestCases (t , ChannelWAC , newWAHandler (courier .ChannelType ("D3C" ), "360Dialog" ), SendTestCasesD3C , checkRedacted , setupMedia )
683
707
}
0 commit comments