Let users search for letters

Like we have search by email address or phone number, finding an
individual letter is a common task. At the moment users are having to
click through pages and pages of letters to find the one they’re looking
for.

We have to search in the `to` and `normalised_to` fields for now because
we’re not populating the `normalised_to` column for letters at the
moment.
This commit is contained in:
Chris Hill-Scott
2020-04-21 14:19:41 +01:00
parent 750a573afc
commit 7897ae70ce
3 changed files with 52 additions and 14 deletions

View File

@@ -1293,6 +1293,7 @@ def test_dao_get_notifications_by_reference(
service = create_service()
sms_template = create_template(service=service)
email_template = create_template(service=service, template_type='email')
letter_template = create_template(service=service, template_type='letter')
sms = create_notification(
template=sms_template,
to_field='07711111111',
@@ -1305,15 +1306,28 @@ def test_dao_get_notifications_by_reference(
normalised_to='077@example.com',
client_reference='77bB',
)
letter = create_notification(
template=letter_template,
to_field='123 Example Street\nXX1X 1XX',
normalised_to='123examplestreetxx1x1xx',
client_reference='77bB',
)
results = dao_get_notifications_by_recipient_or_reference(service.id, '77')
assert len(results) == 3
assert results[0].id == letter.id
assert results[1].id == email.id
assert results[2].id == sms.id
# If notification_type isnt specified then we cant normalise the phone number
# to 4477… but this query will still find the 077… variant in the `to` field,
# as well as the email
results = dao_get_notifications_by_recipient_or_reference(service.id, '077')
assert len(results) == 2
assert results[0].id == email.id
assert results[1].id == sms.id
# If notification_type isnt specified then we cant normalise the phone number
# to 4477… so this query will only find the email sent to 077@example.com
results = dao_get_notifications_by_recipient_or_reference(service.id, '077')
results = dao_get_notifications_by_recipient_or_reference(service.id, '077@')
assert len(results) == 1
assert results[0].id == email.id
@@ -1343,6 +1357,21 @@ def test_dao_get_notifications_by_reference(
results = dao_get_notifications_by_recipient_or_reference(service.id, 'aA', notification_type='email')
assert len(results) == 0
results = dao_get_notifications_by_recipient_or_reference(service.id, 'aA', notification_type='letter')
assert len(results) == 0
results = dao_get_notifications_by_recipient_or_reference(service.id, '123')
assert len(results) == 1
assert results[0].id == letter.id
results = dao_get_notifications_by_recipient_or_reference(service.id, 'xX 1x1 Xx')
assert len(results) == 1
assert results[0].id == letter.id
results = dao_get_notifications_by_recipient_or_reference(service.id, '77', notification_type='letter')
assert len(results) == 1
assert results[0].id == letter.id
def test_dao_created_scheduled_notification(sample_notification):