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

@@ -2103,16 +2103,28 @@ def test_search_for_notification_by_to_field_return_multiple_matches(client, sam
assert str(notification4.id) not in notification_ids
def test_search_for_notification_by_to_field_return_400_for_letter_type(
client, notify_db, notify_db_session, sample_service
def test_search_for_notification_by_to_field_for_letter(
client,
notify_db,
notify_db_session,
sample_letter_template,
sample_email_template,
sample_template,
):
letter_notification = create_notification(sample_letter_template, to_field='A. Name', normalised_to='a.name')
create_notification(sample_email_template, to_field='A.Name@example.com', normalised_to='a.name@example.com')
create_notification(sample_template, to_field='44770900123', normalised_to='44770900123')
response = client.get(
'/service/{}/notifications?to={}&template_type={}'.format(sample_service.id, 'A. Name', 'letter'),
'/service/{}/notifications?to={}&template_type={}'.format(
sample_letter_template.service_id, 'A. Name', 'letter',
),
headers=[create_authorization_header()]
)
response.status_code = 400
error_message = json.loads(response.get_data(as_text=True))
assert error_message['message'] == 'Only email and SMS can use search by recipient'
notifications = json.loads(response.get_data(as_text=True))['notifications']
assert response.status_code == 200
assert len(notifications) == 1
assert notifications[0]['id'] == str(letter_notification.id)
def test_update_service_calls_send_notification_as_service_becomes_live(notify_db, notify_db_session, client, mocker):