diff --git a/app/notifications/process_letter_notifications.py b/app/notifications/process_letter_notifications.py index 32b151f86..4c3efb752 100644 --- a/app/notifications/process_letter_notifications.py +++ b/app/notifications/process_letter_notifications.py @@ -3,7 +3,7 @@ from app.models import LETTER_TYPE from app.notifications.process_notifications import persist_notification -def create_letter_notification(letter_data, template, api_key, status): +def create_letter_notification(letter_data, template, api_key, status, reply_to_text=None): notification = persist_notification( template_id=template.id, template_version=template.version, @@ -18,6 +18,7 @@ def create_letter_notification(letter_data, template, api_key, status): job_row_number=None, reference=create_random_identifier(), client_reference=letter_data.get('reference'), - status=status + status=status, + reply_to_text=reply_to_text ) return notification diff --git a/app/v2/notifications/post_notifications.py b/app/v2/notifications/post_notifications.py index 0afd7fdfa..eec1a69be 100644 --- a/app/v2/notifications/post_notifications.py +++ b/app/v2/notifications/post_notifications.py @@ -183,8 +183,12 @@ def process_letter_notification(*, letter_data, api_key, template): # if we don't want to actually send the letter, then start it off in SENDING so we don't pick it up status = NOTIFICATION_CREATED if should_send else NOTIFICATION_SENDING - - notification = create_letter_notification(letter_data, template, api_key, status=status) + letter_contact_block = api_key.service.get_default_letter_contact() + notification = create_letter_notification(letter_data=letter_data, + template=template, + api_key=api_key, + status=status, + reply_to_text=letter_contact_block) if not should_send: update_letter_notifications_to_sent_to_dvla.apply_async( diff --git a/tests/app/v2/notifications/test_notification_schemas.py b/tests/app/v2/notifications/test_notification_schemas.py index a523dae8a..c51aea6d9 100644 --- a/tests/app/v2/notifications/test_notification_schemas.py +++ b/tests/app/v2/notifications/test_notification_schemas.py @@ -237,7 +237,6 @@ def valid_email_response(): @freeze_time("2017-05-12 13:00:00") def test_post_schema_valid_scheduled_for(schema): j = {"template_id": str(uuid.uuid4()), - "email_address": "joe@gmail.com", "scheduled_for": "2017-05-12 13:15"} if schema == post_email_request_schema: j.update({"email_address": "joe@gmail.com"}) diff --git a/tests/app/v2/notifications/test_post_letter_notifications.py b/tests/app/v2/notifications/test_post_letter_notifications.py index ccfa39b2f..d6eca3c8d 100644 --- a/tests/app/v2/notifications/test_post_letter_notifications.py +++ b/tests/app/v2/notifications/test_post_letter_notifications.py @@ -18,8 +18,7 @@ from app.v2.errors import RateLimitError from app.v2.notifications.notification_schemas import post_letter_response from tests import create_authorization_header -from tests.app.db import create_service, create_template - +from tests.app.db import create_service, create_template, create_letter_contact test_address = { 'address_line_1': 'test 1', @@ -78,6 +77,7 @@ def test_post_letter_notification_returns_201(client, sample_letter_template, mo ) in resp_json['template']['uri'] ) assert not resp_json['scheduled_for'] + assert not notification.reply_to_text def test_post_letter_notification_returns_400_and_missing_template( @@ -298,3 +298,21 @@ def test_post_letter_notification_fakes_dvla_when_service_is_in_trial_mode_but_u kwargs={'notification_references': [notification.reference]}, queue='research-mode-tasks' ) + + +def test_post_letter_notification_persists_notification_reply_to_text( + client, notify_db_session +): + service = create_service(service_permissions=[LETTER_TYPE]) + service_address = "12 Main Street, London" + create_letter_contact(service=service, contact_block=service_address, is_default=True) + template = create_template(service=service, template_type='letter') + data = { + "template_id": template.id, + "personalisation": {'address_line_1': 'Foo', 'address_line_2': 'Bar', 'postcode': 'Baz'} + } + letter_request(client, data=data, service_id=service.id, key_type=KEY_TYPE_NORMAL) + + notifications = Notification.query.all() + assert len(notifications) == 1 + assert notifications[0].reply_to_text == service_address