mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 15:46:07 -05:00
Added the random string reference to the letter
- uses the reference field on the notifications table to store a 16char random string used to cross reference DVLA letters back to the notification - used as letter barcode does not have space for a UUID notification id Depends on https://github.com/alphagov/notifications-utils/pull/149 Renamed the numeric_id to notification_reference in utils and changed validation rules to match this Note also the persist_notification method set "reference" to be "client_reference" which is confusing and they are different things, so fixed this too.
This commit is contained in:
@@ -907,6 +907,9 @@ def test_send_sms_does_not_send_duplicate_and_does_not_put_in_retry_queue(sample
|
||||
|
||||
|
||||
def test_persist_letter_saves_letter_to_database(sample_letter_job, mocker):
|
||||
|
||||
mocker.patch('app.celery.tasks.create_random_identifier', return_value="this-is-random-in-real-life")
|
||||
|
||||
personalisation = {
|
||||
'addressline1': 'Foo',
|
||||
'addressline2': 'Bar',
|
||||
@@ -945,6 +948,7 @@ def test_persist_letter_saves_letter_to_database(sample_letter_job, mocker):
|
||||
assert notification_db.sent_at is None
|
||||
assert notification_db.sent_by is None
|
||||
assert notification_db.personalisation == personalisation
|
||||
assert notification_db.reference == "this-is-random-in-real-life"
|
||||
|
||||
|
||||
def test_should_cancel_job_if_service_is_inactive(sample_service,
|
||||
@@ -1013,24 +1017,26 @@ def test_build_dvla_file_retries_if_all_notifications_are_not_created(sample_let
|
||||
|
||||
|
||||
def test_create_dvla_file_contents(sample_letter_template, mocker):
|
||||
mocker.patch("app.celery.tasks.random.randint", return_value=999)
|
||||
job = create_job(template=sample_letter_template, notification_count=2)
|
||||
create_notification(template=job.template, job=job)
|
||||
create_notification(template=job.template, job=job)
|
||||
create_notification(template=job.template, job=job, reference=1)
|
||||
create_notification(template=job.template, job=job, reference=2)
|
||||
mocked_letter_template = mocker.patch("app.celery.tasks.LetterDVLATemplate")
|
||||
mocked_letter_template_instance = mocked_letter_template.return_value
|
||||
mocked_letter_template_instance.__str__.return_value = "dvla|string"
|
||||
|
||||
create_dvla_file_contents(job.id)
|
||||
calls = mocked_letter_template.call_args_list
|
||||
# Template
|
||||
assert mocked_letter_template.call_args[0][0]['subject'] == 'Template subject'
|
||||
assert mocked_letter_template.call_args[0][0]['content'] == 'Dear Sir/Madam, Hello. Yours Truly, The Government.'
|
||||
assert calls[0][0][0]['subject'] == 'Template subject'
|
||||
assert calls[0][0][0]['content'] == 'Dear Sir/Madam, Hello. Yours Truly, The Government.'
|
||||
|
||||
# Personalisation
|
||||
assert mocked_letter_template.call_args[0][1] is None
|
||||
assert not calls[0][0][1]
|
||||
|
||||
# Named arguments
|
||||
assert mocked_letter_template.call_args[1]['numeric_id'] == 999
|
||||
assert mocked_letter_template.call_args[1]['contact_block'] == 'London,\nSW1A 1AA'
|
||||
assert calls[1][1]['contact_block'] == 'London,\nSW1A 1AA'
|
||||
assert calls[0][1]['notification_reference'] == '1'
|
||||
assert calls[1][1]['notification_reference'] == '2'
|
||||
|
||||
|
||||
@freeze_time("2017-03-23 11:09:00.061258")
|
||||
|
||||
@@ -179,7 +179,7 @@ def test_persist_notification_with_optionals(sample_job, sample_api_key, mocker)
|
||||
created_at=created_at,
|
||||
job_id=sample_job.id,
|
||||
job_row_number=10,
|
||||
reference="ref from client",
|
||||
client_reference="ref from client",
|
||||
notification_id=n_id)
|
||||
assert Notification.query.count() == 1
|
||||
assert NotificationHistory.query.count() == 1
|
||||
|
||||
Reference in New Issue
Block a user