diff --git a/app/schemas.py b/app/schemas.py index 168faa02c..c7061a5bb 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -308,8 +308,13 @@ class NotificationWithPersonalisationSchema(NotificationWithTemplateSchema): renderer=PassThrough() ) in_data['body'] = template.replaced - if in_data['template']['template_type'] == 'email': + template_type = in_data['template']['template_type'] + if template_type == 'email': in_data['subject'] = template.replaced_subject + in_data['content_char_count'] = None + else: + in_data['content_char_count'] = len(in_data['body']) + in_data.pop('personalisation', None) in_data['template'].pop('content', None) in_data['template'].pop('subject', None) diff --git a/tests/app/notifications/test_rest.py b/tests/app/notifications/test_rest.py index 49813da1b..09fea3219 100644 --- a/tests/app/notifications/test_rest.py +++ b/tests/app/notifications/test_rest.py @@ -557,6 +557,7 @@ def test_get_notification_by_id_returns_merged_template_content(notify_db, assert response.status_code == 200 assert notification['body'] == 'Hello world\nYour thing is due soon' assert 'subject' not in notification + assert notification['content_char_count'] == 34 def test_get_notification_by_id_returns_merged_template_content_for_email( @@ -580,6 +581,7 @@ def test_get_notification_by_id_returns_merged_template_content_for_email( assert response.status_code == 200 assert notification['body'] == 'Hello world\nThis is an email from GOV.UK' assert notification['subject'] == 'world' + assert notification['content_char_count'] is None def test_get_notifications_for_service_returns_merged_template_content(notify_api,