Fix 500 on two-way conversation page

We changed the schema used by the endpoint that searches for
notifications by recipient. So the admin app was looking for the wrong
thing in the JSON.

This is hard to catch in tests because it relies on our fixtures
matching what the API really returns.

This commit fixes the code to use the correct key to lookup the template
content from the JSON.

This also exposed the fact that we weren’t passing in the
personalisation any more (perhaps got lost in the re-reverts somehow)
so users were only seeing the template in the inbound view, not the
full message content.
This commit is contained in:
Chris Hill-Scott
2017-07-07 10:04:49 +01:00
parent 9f4018b36f
commit 61fd27c4f6
3 changed files with 31 additions and 10 deletions

View File

@@ -41,14 +41,20 @@ def get_sms_thread(service_id, user_number):
), key=lambda notification: notification['created_at']):
is_inbound = ('notify_number' in notification)
redact_personalisation = notification.get('template', {}).get('redact_personalisation', False)
if redact_personalisation:
notification['personalisation'] = {}
yield {
'inbound': is_inbound,
'content': SMSPreviewTemplate(
{
'content': notification.get('content') or notification['body']
'content': notification.get('content') or notification['template']['content']
},
downgrade_non_gsm_characters=(not is_inbound)
notification.get('personalisation'),
downgrade_non_gsm_characters=(not is_inbound),
redact_missing_personalisation=redact_personalisation,
),
'created_at': notification['created_at'],
'status': notification.get('status'),

View File

@@ -254,7 +254,6 @@ def notification_json(
'notifications': [{
'id': uuid.uuid4(),
'to': to,
'body': template['content'],
'template': template,
'job': job_payload,
'sent_at': sent_at,

View File

@@ -7,8 +7,9 @@ from flask import (
from notifications_python_client.errors import HTTPError
from tests.conftest import (
SERVICE_ONE_ID,
mock_get_notifications,
normalize_spaces,
)
from tests.conftest import normalize_spaces
from freezegun import freeze_time
from unittest import mock
from app.main.views.conversation import get_user_number
@@ -70,15 +71,30 @@ def test_get_user_phone_number_raises_if_both_API_requests_fail(
mock_get_notification.assert_called_once_with('service', 'notification')
@pytest.mark.parametrize('outbound_redacted, expected_outbound_content', [
(True, 'Hello hidden'),
(False, 'Hello Jo'),
])
@freeze_time("2012-01-01 00:00:00")
def test_view_conversation(
logged_in_client,
mocker,
api_user_active,
fake_uuid,
mock_get_notification,
mock_get_inbound_sms,
mock_get_notifications,
outbound_redacted,
expected_outbound_content,
):
mock_get_notifications(
mocker,
api_user_active,
template_content='Hello ((name))',
personalisation={'name': 'Jo'},
redact_personalisation=outbound_redacted,
)
response = logged_in_client.get(url_for(
'main.conversation',
service_id=SERVICE_ONE_ID,
@@ -127,23 +143,23 @@ def test_view_conversation(
'Failed (sent yesterday at 11:00pm)',
),
(
'template content',
expected_outbound_content,
'yesterday at midnight',
),
(
'template content',
expected_outbound_content,
'yesterday at midnight',
),
(
'template content',
expected_outbound_content,
'yesterday at midnight',
),
(
'template content',
expected_outbound_content,
'yesterday at midnight',
),
(
'template content',
expected_outbound_content,
'yesterday at midnight',
),
]):