mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 09:51:11 -05:00
Include the notification sender name when serializing notifications
The `serialize` method of the Notification model now includes the `created_by_name`. If a notification was sent as a one-off message this value will now be the name of the person who sent the notification. If a notification was sent through the API or by a CSV upload we don't record the id of the sender, so `created_by_name` will be `None`. This change affects the data that gets returned from these endpoints: * /v2/notifications/<notification_id> * /v2/notifications
This commit is contained in:
@@ -225,6 +225,17 @@ def test_letter_notification_serializes_with_address(client, sample_letter_notif
|
||||
assert res['postcode'] == 'SW1 1AA'
|
||||
|
||||
|
||||
def test_notification_serializes_created_by_name_with_no_created_by_id(client, sample_notification):
|
||||
res = sample_notification.serialize()
|
||||
assert res['created_by_name'] is None
|
||||
|
||||
|
||||
def test_notification_serializes_created_by_name_with_created_by_id(client, sample_notification, sample_user):
|
||||
sample_notification.created_by_id = sample_user.id
|
||||
res = sample_notification.serialize()
|
||||
assert res['created_by_name'] == sample_user.name
|
||||
|
||||
|
||||
def test_sms_notification_serializes_without_subject(client, sample_template):
|
||||
res = sample_template.serialize()
|
||||
assert res['subject'] is None
|
||||
|
||||
@@ -70,6 +70,7 @@ def test_get_notification_by_id_returns_200(
|
||||
'status': '{}'.format(sample_notification.status),
|
||||
'template': expected_template_response,
|
||||
'created_at': sample_notification.created_at.strftime(DATETIME_FORMAT),
|
||||
'created_by_name': None,
|
||||
'body': sample_notification.template.content,
|
||||
"subject": None,
|
||||
'sent_at': sample_notification.sent_at,
|
||||
@@ -120,6 +121,7 @@ def test_get_notification_by_id_with_placeholders_returns_200(
|
||||
'status': '{}'.format(sample_notification.status),
|
||||
'template': expected_template_response,
|
||||
'created_at': sample_notification.created_at.strftime(DATETIME_FORMAT),
|
||||
'created_by_name': None,
|
||||
'body': "Hello Bob\nThis is an email from GOV.UK",
|
||||
"subject": "Bob",
|
||||
'sent_at': sample_notification.sent_at,
|
||||
@@ -149,6 +151,24 @@ def test_get_notification_by_reference_returns_200(client, sample_template):
|
||||
assert json_response['notifications'][0]['reference'] == "some-client-reference"
|
||||
|
||||
|
||||
def test_get_notification_by_id_returns_created_by_name_if_notification_created_by_id(
|
||||
client,
|
||||
sample_user,
|
||||
sample_template,
|
||||
):
|
||||
sms_notification = create_notification(template=sample_template)
|
||||
sms_notification.created_by_id = sample_user.id
|
||||
|
||||
auth_header = create_authorization_header(service_id=sms_notification.service_id)
|
||||
response = client.get(
|
||||
path=url_for('v2_notifications.get_notification_by_id', notification_id=sms_notification.id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header]
|
||||
)
|
||||
|
||||
json_response = response.get_json()
|
||||
assert json_response['created_by_name'] == 'Test User'
|
||||
|
||||
|
||||
def test_get_notifications_returns_scheduled_for(client, sample_template):
|
||||
sample_notification_with_reference = create_notification(template=sample_template,
|
||||
client_reference='some-client-reference',
|
||||
|
||||
Reference in New Issue
Block a user