Skip to content

Commit 7d3c854

Browse files
committed
Update tests
1 parent ad6c3b7 commit 7d3c854

File tree

2 files changed

+86
-38
lines changed

2 files changed

+86
-38
lines changed

handlers/dialog360/handler_test.go

+43-19
Original file line numberDiff line numberDiff line change
@@ -352,15 +352,15 @@ var SendTestCasesD3C = []OutgoingTestCase{
352352
Label: "Audio Send",
353353
MsgText: "audio caption",
354354
MsgURN: "whatsapp:250788123123",
355-
MsgAttachments: []string{"audio/mpeg:https://foo.bar/audio.mp3"},
355+
MsgAttachments: []string{"audio/mpeg:http://mock.com/1234/test.mp3"},
356356
MockResponses: map[string][]*httpx.MockResponse{
357357
"*/messages": {
358358
httpx.NewMockResponse(201, nil, []byte(`{ "messages": [{"id": "157b5e14568e8"}] }`)),
359359
httpx.NewMockResponse(201, nil, []byte(`{ "messages": [{"id": "157b5e14568e8"}] }`)),
360360
},
361361
},
362362
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"}}`},
364364
{Body: `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"text","text":{"body":"audio caption","preview_url":false}}`},
365365
},
366366
ExpectedExtIDs: []string{"157b5e14568e8", "157b5e14568e8"},
@@ -369,7 +369,7 @@ var SendTestCasesD3C = []OutgoingTestCase{
369369
Label: "Document Send",
370370
MsgText: "document caption",
371371
MsgURN: "whatsapp:250788123123",
372-
MsgAttachments: []string{"application/pdf:https://foo.bar/document.pdf"},
372+
MsgAttachments: []string{"application/pdf:http://mock.com/1234/test.pdf"},
373373
MockResponses: map[string][]*httpx.MockResponse{
374374
"https://waba-v2.360dialog.io/messages": {
375375
httpx.NewMockResponse(201, nil, []byte(`{ "messages": [{"id": "157b5e14568e8"}] }`)),
@@ -378,7 +378,7 @@ var SendTestCasesD3C = []OutgoingTestCase{
378378
ExpectedRequests: []ExpectedRequest{
379379
{
380380
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"}}`,
382382
},
383383
},
384384
ExpectedExtIDs: []string{"157b5e14568e8"},
@@ -387,7 +387,7 @@ var SendTestCasesD3C = []OutgoingTestCase{
387387
Label: "Image Send",
388388
MsgText: "image caption",
389389
MsgURN: "whatsapp:250788123123",
390-
MsgAttachments: []string{"image/jpeg:https://foo.bar/image.jpg"},
390+
MsgAttachments: []string{"image/jpeg:http://mock.com/1234/test.jpg"},
391391
MockResponses: map[string][]*httpx.MockResponse{
392392
"https://waba-v2.360dialog.io/messages": {
393393
httpx.NewMockResponse(201, nil, []byte(`{ "messages": [{"id": "157b5e14568e8"}] }`)),
@@ -396,7 +396,7 @@ var SendTestCasesD3C = []OutgoingTestCase{
396396
ExpectedRequests: []ExpectedRequest{
397397
{
398398
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"}}`,
400400
},
401401
},
402402
ExpectedExtIDs: []string{"157b5e14568e8"},
@@ -405,7 +405,7 @@ var SendTestCasesD3C = []OutgoingTestCase{
405405
Label: "Video Send",
406406
MsgText: "video caption",
407407
MsgURN: "whatsapp:250788123123",
408-
MsgAttachments: []string{"video/mp4:https://foo.bar/video.mp4"},
408+
MsgAttachments: []string{"video/mp4:http://mock.com/1234/test.mp4"},
409409
MockResponses: map[string][]*httpx.MockResponse{
410410
"https://waba-v2.360dialog.io/messages": {
411411
httpx.NewMockResponse(201, nil, []byte(`{ "messages": [{"id": "157b5e14568e8"}] }`)),
@@ -414,7 +414,7 @@ var SendTestCasesD3C = []OutgoingTestCase{
414414
ExpectedRequests: []ExpectedRequest{
415415
{
416416
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"}}`,
418418
},
419419
},
420420
ExpectedExtIDs: []string{"157b5e14568e8"},
@@ -507,7 +507,7 @@ var SendTestCasesD3C = []OutgoingTestCase{
507507
MsgText: "Interactive Button Msg",
508508
MsgURN: "whatsapp:250788123123",
509509
MsgQuickReplies: []string{"BUTTON1"},
510-
MsgAttachments: []string{"image/jpeg:https://foo.bar/image.jpg"},
510+
MsgAttachments: []string{"image/jpeg:http://mock.com/1234/test.jpg"},
511511
MockResponses: map[string][]*httpx.MockResponse{
512512
"https://waba-v2.360dialog.io/messages": {
513513
httpx.NewMockResponse(201, nil, []byte(`{ "messages": [{"id": "157b5e14568e8"}] }`)),
@@ -517,7 +517,7 @@ var SendTestCasesD3C = []OutgoingTestCase{
517517
ExpectedRequests: []ExpectedRequest{
518518
{
519519
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"}}]}}}`,
521521
},
522522
},
523523
ExpectedExtIDs: []string{"157b5e14568e8"},
@@ -527,7 +527,7 @@ var SendTestCasesD3C = []OutgoingTestCase{
527527
MsgText: "Interactive Button Msg",
528528
MsgURN: "whatsapp:250788123123",
529529
MsgQuickReplies: []string{"BUTTON1"},
530-
MsgAttachments: []string{"video/mp4:https://foo.bar/video.mp4"},
530+
MsgAttachments: []string{"video/mp4:http://mock.com/1234/test.mp4"},
531531
MockResponses: map[string][]*httpx.MockResponse{
532532
"https://waba-v2.360dialog.io/messages": {
533533
httpx.NewMockResponse(201, nil, []byte(`{ "messages": [{"id": "157b5e14568e8"}] }`)),
@@ -537,7 +537,7 @@ var SendTestCasesD3C = []OutgoingTestCase{
537537
ExpectedRequests: []ExpectedRequest{
538538
{
539539
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"}}]}}}`,
541541
},
542542
},
543543
ExpectedExtIDs: []string{"157b5e14568e8"},
@@ -547,7 +547,7 @@ var SendTestCasesD3C = []OutgoingTestCase{
547547
MsgText: "Interactive Button Msg",
548548
MsgURN: "whatsapp:250788123123",
549549
MsgQuickReplies: []string{"BUTTON1"},
550-
MsgAttachments: []string{"document/pdf:https://foo.bar/document.pdf"},
550+
MsgAttachments: []string{"document/pdf:http://mock.com/1234/test.pdf"},
551551
MockResponses: map[string][]*httpx.MockResponse{
552552
"https://waba-v2.360dialog.io/messages": {
553553
httpx.NewMockResponse(201, nil, []byte(`{ "messages": [{"id": "157b5e14568e8"}] }`)),
@@ -557,7 +557,7 @@ var SendTestCasesD3C = []OutgoingTestCase{
557557
ExpectedRequests: []ExpectedRequest{
558558
{
559559
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"}}]}}}`,
561561
},
562562
},
563563
ExpectedExtIDs: []string{"157b5e14568e8"},
@@ -567,15 +567,15 @@ var SendTestCasesD3C = []OutgoingTestCase{
567567
MsgText: "Interactive Button Msg",
568568
MsgURN: "whatsapp:250788123123",
569569
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"},
571571
MockResponses: map[string][]*httpx.MockResponse{
572572
"*/messages": {
573573
httpx.NewMockResponse(201, nil, []byte(`{ "messages": [{"id": "157b5e14568e8"}] }`)),
574574
httpx.NewMockResponse(201, nil, []byte(`{ "messages": [{"id": "157b5e14568e8"}] }`)),
575575
},
576576
},
577577
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"}}`},
579579
{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"}}]}}}`},
580580
},
581581
ExpectedExtIDs: []string{"157b5e14568e8", "157b5e14568e8"},
@@ -585,15 +585,15 @@ var SendTestCasesD3C = []OutgoingTestCase{
585585
MsgText: "Interactive List Msg",
586586
MsgURN: "whatsapp:250788123123",
587587
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"},
589589
MockResponses: map[string][]*httpx.MockResponse{
590590
"*/messages": {
591591
httpx.NewMockResponse(201, nil, []byte(`{ "messages": [{"id": "157b5e14568e8"}] }`)),
592592
httpx.NewMockResponse(201, nil, []byte(`{ "messages": [{"id": "157b5e14568e8"}] }`)),
593593
},
594594
},
595595
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"}}`},
597597
{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"}]}]}}}`},
598598
},
599599
ExpectedExtIDs: []string{"157b5e14568e8", "157b5e14568e8"},
@@ -669,6 +669,30 @@ var SendTestCasesD3C = []OutgoingTestCase{
669669
},
670670
}
671671

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+
672696
func TestOutgoing(t *testing.T) {
673697
// shorter max msg length for testing
674698
maxMsgLength = 100
@@ -679,5 +703,5 @@ func TestOutgoing(t *testing.T) {
679703
})
680704
checkRedacted := []string{"the-auth-token"}
681705

682-
RunOutgoingTestCases(t, ChannelWAC, newWAHandler(courier.ChannelType("D3C"), "360Dialog"), SendTestCasesD3C, checkRedacted, nil)
706+
RunOutgoingTestCases(t, ChannelWAC, newWAHandler(courier.ChannelType("D3C"), "360Dialog"), SendTestCasesD3C, checkRedacted, setupMedia)
683707
}

0 commit comments

Comments
 (0)