Skip to content

Commit

Permalink
Fix facebookapp test
Browse files Browse the repository at this point in the history
  • Loading branch information
Robi9 committed Dec 27, 2023
1 parent 05632c2 commit b4c2161
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
7 changes: 4 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ func NewConfig() *Config {
S3DisableSSL: false,
S3ForcePathStyle: false,

FacebookApplicationSecret: "missing_facebook_app_secret",
FacebookWebhookSecret: "missing_facebook_webhook_secret",
WhatsappAdminSystemUserToken: "missing_whatsapp_admin_system_user_token",
FacebookApplicationSecret: "missing_facebook_app_secret",
FacebookWebhookSecret: "missing_facebook_webhook_secret",
WhatsappAdminSystemUserToken: "missing_whatsapp_admin_system_user_token",
WhatsappCloudApplicationSecret: "missing_whatsapp_cloud_app_secret",

MaxWorkers: 32,
LogLevel: "error",
Expand Down
2 changes: 1 addition & 1 deletion handlers/facebookapp/facebookapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -1666,7 +1666,7 @@ func (h *handler) sendCloudAPIWhatsappMsg(ctx context.Context, msg courier.Msg,
}

// if payload.contacts[0].wa_id != payload.contacts[0].input | to fix cases with 9 extra
if len(respPayload.Contacts) > 0 && respPayload.Contacts[0].WaID != msg.URN().Path() {
if respPayload != nil && len(respPayload.Contacts) > 0 && respPayload.Contacts[0].WaID != msg.URN().Path() {
if !hasNewURN {
toUpdateURN, err := urns.NewWhatsAppURN(respPayload.Contacts[0].WaID)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions handlers/facebookapp/facebookapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,7 @@ var SendTestCasesWAC = []ChannelSendTestCase{
MsgAttachments: []string{"application/pdf:https://foo.bar/document.pdf"},
MockResponseBody: `{ "messages": [{"id": "157b5e14568e8"}] }`,
MockResponseStatus: 201,
ExpectedRequestBody: `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"document","document":{"link":"https://foo.bar/document.pdf","caption":"document caption"}}`,
ExpectedRequestBody: `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"document","document":{"link":"https://foo.bar/document.pdf","caption":"document caption","filename":"document.pdf"}}`,
ExpectedRequestPath: "/12345_ID/messages",
ExpectedMsgStatus: "W",
ExpectedExternalID: "157b5e14568e8",
Expand Down Expand Up @@ -1303,7 +1303,7 @@ var SendTestCasesWAC = []ChannelSendTestCase{
MsgMetadata: json.RawMessage(`{ "templating": { "template": { "name": "revive_issue", "uuid": "171f8a4d-f725-46d7-85a6-11aceff0bfe3" }, "language": "eng", "variables": ["Chef", "tomorrow"]}}`),
MockResponseBody: `{ "messages": [{"id": "157b5e14568e8"}] }`,
MockResponseStatus: 200,
ExpectedRequestBody: `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"template","template":{"name":"revive_issue","language":{"policy":"deterministic","code":"en"},"components":[{"type":"body","sub_type":"","index":"","parameters":[{"type":"text","text":"Chef"},{"type":"text","text":"tomorrow"}]}]}}`,
ExpectedRequestBody: `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"template","template":{"name":"revive_issue","language":{"policy":"deterministic","code":"en"},"components":[{"type":"body","parameters":[{"type":"text","text":"Chef"},{"type":"text","text":"tomorrow"}]}]}}`,
SendPrep: setSendURL,
},
{
Expand All @@ -1313,7 +1313,7 @@ var SendTestCasesWAC = []ChannelSendTestCase{
MsgMetadata: json.RawMessage(`{ "templating": { "template": { "name": "revive_issue", "uuid": "171f8a4d-f725-46d7-85a6-11aceff0bfe3" }, "language": "eng", "country": "US", "variables": ["Chef", "tomorrow"]}}`),
MockResponseBody: `{ "messages": [{"id": "157b5e14568e8"}] }`,
MockResponseStatus: 200,
ExpectedRequestBody: `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"template","template":{"name":"revive_issue","language":{"policy":"deterministic","code":"en_US"},"components":[{"type":"body","sub_type":"","index":"","parameters":[{"type":"text","text":"Chef"},{"type":"text","text":"tomorrow"}]}]}}`,
ExpectedRequestBody: `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"template","template":{"name":"revive_issue","language":{"policy":"deterministic","code":"en_US"},"components":[{"type":"body","parameters":[{"type":"text","text":"Chef"},{"type":"text","text":"tomorrow"}]}]}}`,
ExpectedMsgStatus: "W",
ExpectedExternalID: "157b5e14568e8",
SendPrep: setSendURL,
Expand Down
2 changes: 1 addition & 1 deletion handlers/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func newServer(backend courier.Backend) courier.Server {
config.FacebookWebhookSecret = "fb_webhook_secret"
config.FacebookApplicationSecret = "fb_app_secret"
config.WhatsappCloudWebhookSecret = "wac_webhook_secret"
config.WhatsappCloudApplicationSecret = "wac_app_secret"
config.WhatsappCloudApplicationSecret = "fb_app_secret"
config.WhatsappAdminSystemUserToken = "wac_admin_system_user_token"

return courier.NewServerWithLogger(config, backend, logger)
Expand Down

0 comments on commit b4c2161

Please sign in to comment.