From 81877b7511c0ba026f87269b3bb2a2c18ae3eb2c Mon Sep 17 00:00:00 2001 From: Filip Fafara Date: Mon, 2 Nov 2020 17:53:36 -0500 Subject: [PATCH] [#239] add API test and model test for empty recipients --- tests/app/test_model.py | 6 ++++++ .../v2/notifications/test_get_notifications.py | 17 +++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/tests/app/test_model.py b/tests/app/test_model.py index d2669fa6b1..48396bdf21 100644 --- a/tests/app/test_model.py +++ b/tests/app/test_model.py @@ -257,6 +257,12 @@ def test_email_notification_serializes_with_recipient_identifiers(client, sample assert response['recipient_identifiers'] == recipient_identifiers +def test_email_notification_serializes_with_empty_recipient_identifiers(client, sample_email_template): + notifcation = create_notification(sample_email_template) + response = notifcation.serialize() + assert response['recipient_identifiers'] == [] + + def test_notification_requires_a_valid_template_version(client, sample_template): sample_template.version = 2 with pytest.raises(IntegrityError): diff --git a/tests/app/v2/notifications/test_get_notifications.py b/tests/app/v2/notifications/test_get_notifications.py index ce63a0e03b..6220643a40 100644 --- a/tests/app/v2/notifications/test_get_notifications.py +++ b/tests/app/v2/notifications/test_get_notifications.py @@ -8,7 +8,9 @@ create_notification, create_template, ) - +from app.models import ( + VA_PROFILE_ID, +) @pytest.mark.parametrize('billable_units, provider', [ (1, 'mmg'), @@ -73,17 +75,23 @@ def test_get_notification_by_id_returns_200( 'completed_at': sample_notification.completed_at(), 'scheduled_for': '2017-05-12T19:15:00.000000Z', 'postage': None, + 'recipient_identifiers': [] } assert json_response == expected_response -def test_get_notification_by_id_with_placeholders_returns_200( - client, sample_email_template_with_placeholders +@pytest.mark.parametrize('recipient_identifiers', [ + None, + [{ "id_type": VA_PROFILE_ID, "id_value": "some vaprofileid" }] +]) +def test_get_notification_by_id_with_placeholders_and_recipient_identifiers_returns_200( + client, sample_email_template_with_placeholders, recipient_identifiers ): sample_notification = create_notification( template=sample_email_template_with_placeholders, - personalisation={"name": "Bob"} + personalisation={"name": "Bob"}, + recipient_identifiers=recipient_identifiers ) auth_header = create_authorization_header(service_id=sample_notification.service_id) @@ -125,6 +133,7 @@ def test_get_notification_by_id_with_placeholders_returns_200( 'completed_at': sample_notification.completed_at(), 'scheduled_for': None, 'postage': None, + 'recipient_identifiers': recipient_identifiers if recipient_identifiers else [] } assert json_response == expected_response