Skip to content

Commit

Permalink
[#239] add API test and model test for empty recipients
Browse files Browse the repository at this point in the history
  • Loading branch information
ffafara-tw committed Nov 2, 2020
1 parent c372423 commit 81877b7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
6 changes: 6 additions & 0 deletions tests/app/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
17 changes: 13 additions & 4 deletions tests/app/v2/notifications/test_get_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
create_notification,
create_template,
)

from app.models import (
VA_PROFILE_ID,
)

@pytest.mark.parametrize('billable_units, provider', [
(1, 'mmg'),
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 81877b7

Please sign in to comment.