diff --git a/app/notifications/process_notifications.py b/app/notifications/process_notifications.py index 492e62d19..a6d1137ce 100644 --- a/app/notifications/process_notifications.py +++ b/app/notifications/process_notifications.py @@ -4,7 +4,8 @@ from flask import current_app from notifications_utils.recipients import ( get_international_phone_info, - validate_and_format_phone_number + validate_and_format_phone_number, + format_email_address ) from app import redis_store @@ -76,6 +77,8 @@ def persist_notification( notification.international = recipient_info.international notification.phone_prefix = recipient_info.country_prefix notification.rate_multiplier = recipient_info.billable_units + elif notification_type == EMAIL_TYPE: + notification.normalised_to = format_email_address(notification.to) # if simulated create a Notification model to return but do not persist the Notification to the dB if not simulated: diff --git a/tests/app/notifications/test_process_notification.py b/tests/app/notifications/test_process_notification.py index 100adf6fa..2f66ef457 100644 --- a/tests/app/notifications/test_process_notification.py +++ b/tests/app/notifications/test_process_notification.py @@ -383,3 +383,32 @@ def test_persist_sms_notification_stores_normalised_number( assert persisted_notification.to == recipient assert persisted_notification.normalised_to == expected_recipient_normalised + + +@pytest.mark.parametrize('recipient, expected_recipient_normalised', [ + ('FOO@bar.com', 'foo@bar.com'), + ('BAR@foo.com', 'bar@foo.com') + +]) +def test_persist_email_notification_stores_normalised_email( + sample_job, + sample_api_key, + mocker, + recipient, + expected_recipient_normalised +): + persist_notification( + template_id=sample_job.template.id, + template_version=sample_job.template.version, + recipient=recipient, + service=sample_job.service, + personalisation=None, + notification_type='email', + api_key_id=sample_api_key.id, + key_type=sample_api_key.key_type, + job_id=sample_job.id, + ) + persisted_notification = Notification.query.all()[0] + + assert persisted_notification.to == recipient + assert persisted_notification.normalised_to == expected_recipient_normalised