mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 01:41:05 -05:00
Update notificaiton API endpoints to use template's reply_to
Sets the reply_to_text on notification from the template value if it's set.
This commit is contained in:
@@ -18,6 +18,7 @@ from app.models import (
|
||||
from tests.app.db import (
|
||||
create_user,
|
||||
create_reply_to_email,
|
||||
create_letter_contact,
|
||||
create_service,
|
||||
create_template
|
||||
)
|
||||
@@ -217,7 +218,27 @@ def test_send_one_off_notification_should_add_email_reply_to_text_for_notificati
|
||||
research_mode=False,
|
||||
queue=None
|
||||
)
|
||||
notification.reply_to_text == reply_to_email.email_address
|
||||
assert notification.reply_to_text == reply_to_email.email_address
|
||||
|
||||
|
||||
def test_send_one_off_letter_notification_should_use_template_reply_to_text(sample_letter_template, celery_mock):
|
||||
letter_contact = create_letter_contact(sample_letter_template.service, "Edinburgh, ED1 1AA", is_default=False)
|
||||
sample_letter_template.reply_to = str(letter_contact.id)
|
||||
|
||||
data = {
|
||||
'to': 'user@example.com',
|
||||
'template_id': str(sample_letter_template.id),
|
||||
'created_by': str(sample_letter_template.service.created_by_id)
|
||||
}
|
||||
|
||||
notification_id = send_one_off_notification(service_id=sample_letter_template.service.id, post_data=data)
|
||||
notification = Notification.query.get(notification_id['id'])
|
||||
celery_mock.assert_called_once_with(
|
||||
notification=notification,
|
||||
research_mode=False,
|
||||
queue=None
|
||||
)
|
||||
assert notification.reply_to_text == "Edinburgh, ED1 1AA"
|
||||
|
||||
|
||||
def test_send_one_off_notification_should_throw_exception_if_reply_to_id_doesnot_exist(
|
||||
|
||||
@@ -28,6 +28,7 @@ from tests.app.db import (
|
||||
create_service,
|
||||
create_template,
|
||||
create_reply_to_email,
|
||||
create_letter_contact,
|
||||
create_service_sms_sender,
|
||||
create_service_with_inbound_number
|
||||
)
|
||||
@@ -639,3 +640,26 @@ def test_post_email_notification_with_invalid_reply_to_id_returns_400(client, sa
|
||||
assert 'email_reply_to_id {} does not exist in database for service id {}'. \
|
||||
format(fake_uuid, sample_email_template.service_id) in resp_json['errors'][0]['message']
|
||||
assert 'BadRequestError' in resp_json['errors'][0]['error']
|
||||
|
||||
|
||||
def test_letter_notification_should_use_template_reply_to(client, sample_letter_template):
|
||||
letter_contact = create_letter_contact(sample_letter_template.service, "Edinburgh, ED1 1AA", is_default=False)
|
||||
sample_letter_template.reply_to = str(letter_contact.id)
|
||||
|
||||
data = {
|
||||
'template_id': str(sample_letter_template.id),
|
||||
'personalisation': {
|
||||
'address_line_1': '123',
|
||||
'address_line_2': '234',
|
||||
'postcode': 'W1A1AA',
|
||||
}
|
||||
}
|
||||
response = client.post("v2/notifications/letter",
|
||||
data=json.dumps(data),
|
||||
headers=[('Content-Type', 'application/json'),
|
||||
create_authorization_header(service_id=sample_letter_template.service.id)]
|
||||
)
|
||||
assert response.status_code == 201, response.get_data(as_text=True)
|
||||
notifications = Notification.query.all()
|
||||
assert len(notifications) == 1
|
||||
assert notifications[0].reply_to_text == "Edinburgh, ED1 1AA"
|
||||
|
||||
Reference in New Issue
Block a user