@@ -1288,12 +1288,12 @@ var SendTestCasesWAC = []ChannelSendTestCase{
1288
1288
Label : "Audio Send" ,
1289
1289
MsgText : "audio caption" ,
1290
1290
MsgURN : "whatsapp:250788123123" ,
1291
- MsgAttachments : []string {"audio/mpeg:https ://foo.bar/audio .mp3" },
1291
+ MsgAttachments : []string {"audio/mpeg:http ://mock.com/3456/test .mp3" },
1292
1292
MockResponses : map [MockedRequest ]* httpx.MockResponse {
1293
1293
{
1294
1294
Method : "POST" ,
1295
1295
Path : "/12345_ID/messages" ,
1296
- Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"audio","audio":{"link":"https ://foo.bar/audio .mp3"}}` ,
1296
+ Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"audio","audio":{"link":"http ://mock.com/3456/test .mp3"}}` ,
1297
1297
}: httpx .NewMockResponse (201 , nil , []byte (`{ "messages": [{"id": "157b5e14568e8"}] }` )),
1298
1298
{
1299
1299
Method : "POST" ,
@@ -1309,10 +1309,10 @@ var SendTestCasesWAC = []ChannelSendTestCase{
1309
1309
Label : "Document Send" ,
1310
1310
MsgText : "document caption" ,
1311
1311
MsgURN : "whatsapp:250788123123" ,
1312
- MsgAttachments : []string {"application/pdf:https ://foo.bar/document .pdf" },
1312
+ MsgAttachments : []string {"application/pdf:http ://mock.com/7890/test .pdf" },
1313
1313
MockResponseBody : `{ "messages": [{"id": "157b5e14568e8"}] }` ,
1314
1314
MockResponseStatus : 201 ,
1315
- ExpectedRequestBody : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"document","document":{"link":"https ://foo.bar/document .pdf","caption":"document caption","filename":"document .pdf"}}` ,
1315
+ ExpectedRequestBody : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"document","document":{"link":"http ://mock.com/7890/test .pdf","caption":"document caption","filename":"test .pdf"}}` ,
1316
1316
ExpectedRequestPath : "/12345_ID/messages" ,
1317
1317
ExpectedMsgStatus : "W" ,
1318
1318
ExpectedExternalID : "157b5e14568e8" ,
@@ -1322,10 +1322,10 @@ var SendTestCasesWAC = []ChannelSendTestCase{
1322
1322
Label : "Image Send" ,
1323
1323
MsgText : "image caption" ,
1324
1324
MsgURN : "whatsapp:250788123123" ,
1325
- MsgAttachments : []string {"image/jpeg:https ://foo.bar/image .jpg" },
1325
+ MsgAttachments : []string {"image/jpeg:http ://mock.com/1234/test .jpg" },
1326
1326
MockResponseBody : `{ "messages": [{"id": "157b5e14568e8"}] }` ,
1327
1327
MockResponseStatus : 201 ,
1328
- ExpectedRequestBody : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"image","image":{"link":"https ://foo.bar/image .jpg","caption":"image caption"}}` ,
1328
+ ExpectedRequestBody : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"image","image":{"link":"http ://mock.com/1234/test .jpg","caption":"image caption"}}` ,
1329
1329
ExpectedRequestPath : "/12345_ID/messages" ,
1330
1330
ExpectedMsgStatus : "W" ,
1331
1331
ExpectedExternalID : "157b5e14568e8" ,
@@ -1335,10 +1335,10 @@ var SendTestCasesWAC = []ChannelSendTestCase{
1335
1335
Label : "Sticker Send" ,
1336
1336
MsgText : "sticker caption" ,
1337
1337
MsgURN : "whatsapp:250788123123" ,
1338
- MsgAttachments : []string {"image/webp:https ://foo.bar/sticker .webp" },
1338
+ MsgAttachments : []string {"image/webp:http ://mock.com/8901/test .webp" },
1339
1339
MockResponseBody : `{ "messages": [{"id": "157b5e14568e8"}] }` ,
1340
1340
MockResponseStatus : 201 ,
1341
- ExpectedRequestBody : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"sticker","sticker":{"link":"https ://foo.bar/sticker .webp","caption":"sticker caption"}}` ,
1341
+ ExpectedRequestBody : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"sticker","sticker":{"link":"http ://mock.com/8901/test .webp","caption":"sticker caption"}}` ,
1342
1342
ExpectedRequestPath : "/12345_ID/messages" ,
1343
1343
ExpectedMsgStatus : "W" ,
1344
1344
ExpectedExternalID : "157b5e14568e8" ,
@@ -1348,10 +1348,10 @@ var SendTestCasesWAC = []ChannelSendTestCase{
1348
1348
Label : "Video Send" ,
1349
1349
MsgText : "video caption" ,
1350
1350
MsgURN : "whatsapp:250788123123" ,
1351
- MsgAttachments : []string {"video/mp4:https ://foo.bar/video .mp4" },
1351
+ MsgAttachments : []string {"video/mp4:http ://mock.com/5678/test .mp4" },
1352
1352
MockResponseBody : `{ "messages": [{"id": "157b5e14568e8"}] }` ,
1353
1353
MockResponseStatus : 201 ,
1354
- ExpectedRequestBody : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"video","video":{"link":"https ://foo.bar/video .mp4","caption":"video caption"}}` ,
1354
+ ExpectedRequestBody : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"video","video":{"link":"http ://mock.com/5678/test .mp4","caption":"video caption"}}` ,
1355
1355
ExpectedRequestPath : "/12345_ID/messages" ,
1356
1356
ExpectedMsgStatus : "W" ,
1357
1357
ExpectedExternalID : "157b5e14568e8" ,
@@ -1438,10 +1438,10 @@ var SendTestCasesWAC = []ChannelSendTestCase{
1438
1438
MsgText : "Interactive Button Msg" ,
1439
1439
MsgURN : "whatsapp:250788123123" ,
1440
1440
MsgQuickReplies : []string {"BUTTON1" },
1441
- MsgAttachments : []string {"image/jpeg:https ://foo.bar/image .jpg" },
1441
+ MsgAttachments : []string {"image/jpeg:http ://mock.com/1234/test .jpg" },
1442
1442
MockResponseBody : `{ "messages": [{"id": "157b5e14568e8"}] }` ,
1443
1443
MockResponseStatus : 201 ,
1444
- ExpectedRequestBody : `{"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"}}]}}}` ,
1444
+ ExpectedRequestBody : `{"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"}}]}}}` ,
1445
1445
ExpectedRequestPath : "/12345_ID/messages" ,
1446
1446
ExpectedMsgStatus : "W" ,
1447
1447
ExpectedExternalID : "157b5e14568e8" ,
@@ -1452,10 +1452,10 @@ var SendTestCasesWAC = []ChannelSendTestCase{
1452
1452
MsgText : "Interactive Button Msg" ,
1453
1453
MsgURN : "whatsapp:250788123123" ,
1454
1454
MsgQuickReplies : []string {"BUTTON1" },
1455
- MsgAttachments : []string {"video/mp4:https ://foo.bar/video .mp4" },
1455
+ MsgAttachments : []string {"video/mp4:http ://mock.com/5678/test .mp4" },
1456
1456
MockResponseBody : `{ "messages": [{"id": "157b5e14568e8"}] }` ,
1457
1457
MockResponseStatus : 201 ,
1458
- ExpectedRequestBody : `{"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"}}]}}}` ,
1458
+ ExpectedRequestBody : `{"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"}}]}}}` ,
1459
1459
ExpectedRequestPath : "/12345_ID/messages" ,
1460
1460
ExpectedMsgStatus : "W" ,
1461
1461
ExpectedExternalID : "157b5e14568e8" ,
@@ -1466,10 +1466,10 @@ var SendTestCasesWAC = []ChannelSendTestCase{
1466
1466
MsgText : "Interactive Button Msg" ,
1467
1467
MsgURN : "whatsapp:250788123123" ,
1468
1468
MsgQuickReplies : []string {"BUTTON1" },
1469
- MsgAttachments : []string {"document/pdf:https ://foo.bar/document .pdf" },
1469
+ MsgAttachments : []string {"document/pdf:http ://mock.com/7890/test .pdf" },
1470
1470
MockResponseBody : `{ "messages": [{"id": "157b5e14568e8"}] }` ,
1471
1471
MockResponseStatus : 201 ,
1472
- ExpectedRequestBody : `{"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"}}]}}}` ,
1472
+ ExpectedRequestBody : `{"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"}}]}}}` ,
1473
1473
ExpectedRequestPath : "/12345_ID/messages" ,
1474
1474
ExpectedMsgStatus : "W" ,
1475
1475
ExpectedExternalID : "157b5e14568e8" ,
@@ -1480,12 +1480,12 @@ var SendTestCasesWAC = []ChannelSendTestCase{
1480
1480
MsgText : "Interactive Button Msg" ,
1481
1481
MsgURN : "whatsapp:250788123123" ,
1482
1482
MsgQuickReplies : []string {"ROW1" , "ROW2" , "ROW3" },
1483
- MsgAttachments : []string {"audio/mp3:https ://foo.bar/audio .mp3" },
1483
+ MsgAttachments : []string {"audio/mp3:http ://mock.com/3456/test .mp3" },
1484
1484
MockResponses : map [MockedRequest ]* httpx.MockResponse {
1485
1485
{
1486
1486
Method : "POST" ,
1487
1487
Path : "/12345_ID/messages" ,
1488
- Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"audio","audio":{"link":"https ://foo.bar/audio .mp3"}}` ,
1488
+ Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"audio","audio":{"link":"http ://mock.com/3456/test .mp3"}}` ,
1489
1489
}: httpx .NewMockResponse (201 , nil , []byte (`{ "messages": [{"id": "157b5e14568e8"}] }` )),
1490
1490
{
1491
1491
Method : "POST" ,
@@ -1502,12 +1502,12 @@ var SendTestCasesWAC = []ChannelSendTestCase{
1502
1502
MsgText : "Interactive List Msg" ,
1503
1503
MsgURN : "whatsapp:250788123123" ,
1504
1504
MsgQuickReplies : []string {"ROW1" , "ROW2" , "ROW3" , "ROW4" },
1505
- MsgAttachments : []string {"image/jpeg:https ://foo.bar/image .jpg" },
1505
+ MsgAttachments : []string {"image/jpeg:http ://mock.com/1234/test .jpg" },
1506
1506
MockResponses : map [MockedRequest ]* httpx.MockResponse {
1507
1507
{
1508
1508
Method : "POST" ,
1509
1509
Path : "/12345_ID/messages" ,
1510
- Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"image","image":{"link":"https ://foo.bar/image .jpg"}}` ,
1510
+ Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"image","image":{"link":"http ://mock.com/1234/test .jpg"}}` ,
1511
1511
}: httpx .NewMockResponse (201 , nil , []byte (`{ "messages": [{"id": "157b5e14568e8"}] }` )),
1512
1512
{
1513
1513
Method : "POST" ,
@@ -1553,6 +1553,30 @@ var SendTestCasesWAC = []ChannelSendTestCase{
1553
1553
},
1554
1554
}
1555
1555
1556
+ // setupMedia takes care of having the media files needed to our test server host
1557
+ func setupMedia (mb * test.MockBackend ) {
1558
+ imageJPG := test .NewMockMedia ("test.jpg" , "image/jpeg" , "http://mock.com/1234/test.jpg" , 1024 * 1024 , 640 , 480 , 0 , nil )
1559
+
1560
+ audioM4A := test .NewMockMedia ("test.m4a" , "audio/mp4" , "http://mock.com/2345/test.m4a" , 1024 * 1024 , 0 , 0 , 200 , nil )
1561
+ audioMP3 := test .NewMockMedia ("test.mp3" , "audio/mpeg" , "http://mock.com/3456/test.mp3" , 1024 * 1024 , 0 , 0 , 200 , []courier.Media {audioM4A })
1562
+
1563
+ thumbJPG := test .NewMockMedia ("test.jpg" , "image/jpeg" , "http://mock.com/4567/test.jpg" , 1024 * 1024 , 640 , 480 , 0 , nil )
1564
+ videoMP4 := test .NewMockMedia ("test.mp4" , "video/mp4" , "http://mock.com/5678/test.mp4" , 1024 * 1024 , 0 , 0 , 1000 , []courier.Media {thumbJPG })
1565
+
1566
+ videoMOV := test .NewMockMedia ("test.mov" , "video/quicktime" , "http://mock.com/6789/test.mov" , 100 * 1024 * 1024 , 0 , 0 , 2000 , nil )
1567
+
1568
+ filePDF := test .NewMockMedia ("test.pdf" , "application/pdf" , "http://mock.com/7890/test.pdf" , 100 * 1024 * 1024 , 0 , 0 , 0 , nil )
1569
+
1570
+ stickerWEBP := test .NewMockMedia ("test.webp" , "image/webp" , "http://mock.com/8901/test.webp" , 50 * 1024 , 480 , 480 , 0 , nil )
1571
+
1572
+ mb .MockMedia (imageJPG )
1573
+ mb .MockMedia (audioMP3 )
1574
+ mb .MockMedia (videoMP4 )
1575
+ mb .MockMedia (videoMOV )
1576
+ mb .MockMedia (filePDF )
1577
+ mb .MockMedia (stickerWEBP )
1578
+ }
1579
+
1556
1580
func TestSending (t * testing.T ) {
1557
1581
// shorter max msg length for testing
1558
1582
maxMsgLength = 100
@@ -1565,7 +1589,7 @@ func TestSending(t *testing.T) {
1565
1589
1566
1590
RunChannelSendTestCases (t , ChannelFBA , newHandler ("FBA" , "Facebook" , false ), SendTestCasesFBA , checkRedacted , nil )
1567
1591
RunChannelSendTestCases (t , ChannelIG , newHandler ("IG" , "Instagram" , false ), SendTestCasesIG , checkRedacted , nil )
1568
- RunChannelSendTestCases (t , ChannelWAC , newHandler ("WAC" , "Cloud API WhatsApp" , false ), SendTestCasesWAC , checkRedacted , nil )
1592
+ RunChannelSendTestCases (t , ChannelWAC , newHandler ("WAC" , "Cloud API WhatsApp" , false ), SendTestCasesWAC , checkRedacted , setupMedia )
1569
1593
}
1570
1594
1571
1595
func TestSigning (t * testing.T ) {
0 commit comments