Skip to content

Commit

Permalink
Merge pull request #569 from praekeltfoundation/MOMZA-2292-add-privac…
Browse files Browse the repository at this point in the history
…y-policy-pdf

Fix WA error payload
  • Loading branch information
erikh360 committed Jun 26, 2023
2 parents 5587265 + bac94f2 commit 71c9845
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
15 changes: 14 additions & 1 deletion ndoh_hub/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,20 @@ def test_send_whatsapp_template_message_number_not_on_whatsapp(self):
responses.add(
method=responses.POST,
url="http://turn/v1/messages",
json={"error": {"code": 1013}},
json={
"errors": [
{
"code": 1013,
"details": "Recipient is not a valid WhatsApp user",
"title": "User is not valid",
}
],
"meta": {
"api_status": "stable",
"backend": {"name": "WhatsApp", "version": "latest"},
"version": "4.412.3",
},
},
)

response = send_whatsapp_template_message(
Expand Down
15 changes: 14 additions & 1 deletion ndoh_hub/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,20 @@ def test_send_whatsapp_template_message_number_not_on_whatsapp(self):
responses.add(
method=responses.POST,
url="http://turn/v1/messages",
json={"error": {"code": 1013}},
json={
"errors": [
{
"code": 1013,
"details": "Recipient is not a valid WhatsApp user",
"title": "User is not valid",
}
],
"meta": {
"api_status": "stable",
"backend": {"name": "WhatsApp", "version": "latest"},
"version": "4.412.3",
},
},
)

response = self.client.post(
Expand Down
2 changes: 1 addition & 1 deletion ndoh_hub/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def send_whatsapp_template_message(msisdn, template_name, parameters, media=None

prefered_chanel = "WhatsApp"
if "messages" not in response_data:
if response_data["error"]["code"] == 1013:
if response_data["errors"][0]["code"] == 1013:
prefered_chanel = "SMS"

return prefered_chanel

0 comments on commit 71c9845

Please sign in to comment.