mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 07:35:34 -05:00
If client reference not given, try to get it from personalisation.
This is mostly useful for letters. For templated letters sent via interface, whether one-offs or CSV uploads, we do not give our users a way to set client reference. Still, they often have a placeholder with reference that we could use to set client_reference field. Why is this helpful? When letter is returned, or when we experience some printing issues, often it is difficult to identify letters after the retention period. This change will make it easier for some users to identify letters. It will have more impact if we inform our users of this in template editing guidance.
This commit is contained in:
@@ -121,7 +121,7 @@ def persist_notification(
|
|||||||
created_at=notification_created_at,
|
created_at=notification_created_at,
|
||||||
job_id=job_id,
|
job_id=job_id,
|
||||||
job_row_number=job_row_number,
|
job_row_number=job_row_number,
|
||||||
client_reference=client_reference,
|
client_reference=client_reference or _get_reference_from_personalisation(personalisation),
|
||||||
reference=reference,
|
reference=reference,
|
||||||
created_by_id=created_by_id,
|
created_by_id=created_by_id,
|
||||||
status=status,
|
status=status,
|
||||||
@@ -159,6 +159,12 @@ def persist_notification(
|
|||||||
return notification
|
return notification
|
||||||
|
|
||||||
|
|
||||||
|
def _get_reference_from_personalisation(personalisation):
|
||||||
|
if personalisation:
|
||||||
|
return personalisation.get("reference")
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def send_notification_to_queue_detached(
|
def send_notification_to_queue_detached(
|
||||||
key_type, notification_type, notification_id, research_mode, queue=None
|
key_type, notification_type, notification_id, research_mode, queue=None
|
||||||
):
|
):
|
||||||
|
|||||||
@@ -96,6 +96,42 @@ def test_persist_notification_creates_and_save_to_db(sample_template, sample_api
|
|||||||
assert notification_from_db.reply_to_text == sample_template.service.get_default_sms_sender()
|
assert notification_from_db.reply_to_text == sample_template.service.get_default_sms_sender()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('client_reference,personalisation,expected_client_reference', [
|
||||||
|
('clientref1', {}, 'clientref1'),
|
||||||
|
('clientref1', {'reference': 'ref2'}, 'clientref1'),
|
||||||
|
(None, {'reference': 'ref2'}, 'ref2'),
|
||||||
|
(None, {'foo': 'bar'}, None),
|
||||||
|
])
|
||||||
|
def test_persist_notification_sets_client_reference_correctly(
|
||||||
|
sample_letter_template, sample_api_key, client_reference, personalisation, expected_client_reference
|
||||||
|
):
|
||||||
|
|
||||||
|
assert Notification.query.count() == 0
|
||||||
|
assert NotificationHistory.query.count() == 0
|
||||||
|
notification = persist_notification(
|
||||||
|
template_id=sample_letter_template.id,
|
||||||
|
template_version=sample_letter_template.version,
|
||||||
|
recipient='3 Somerset House',
|
||||||
|
service=sample_letter_template.service,
|
||||||
|
personalisation=personalisation,
|
||||||
|
notification_type='letter',
|
||||||
|
api_key_id=sample_api_key.id,
|
||||||
|
key_type=sample_api_key.key_type,
|
||||||
|
reference="ref",
|
||||||
|
client_reference=client_reference,
|
||||||
|
)
|
||||||
|
|
||||||
|
assert Notification.query.get(notification.id) is not None
|
||||||
|
|
||||||
|
notification_from_db = Notification.query.one()
|
||||||
|
|
||||||
|
assert notification_from_db.id == notification.id
|
||||||
|
assert notification_from_db.template_id == notification.template_id
|
||||||
|
assert notification_from_db.notification_type == notification.notification_type
|
||||||
|
assert notification_from_db.reference == notification.reference
|
||||||
|
assert notification_from_db.client_reference == expected_client_reference
|
||||||
|
|
||||||
|
|
||||||
def test_persist_notification_throws_exception_when_missing_template(sample_api_key):
|
def test_persist_notification_throws_exception_when_missing_template(sample_api_key):
|
||||||
assert Notification.query.count() == 0
|
assert Notification.query.count() == 0
|
||||||
assert NotificationHistory.query.count() == 0
|
assert NotificationHistory.query.count() == 0
|
||||||
|
|||||||
Reference in New Issue
Block a user