mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-24 16:23:44 -04:00
Ensure letter personalisation is serialized correctly
The personalisation for letters can take different formats depending on how the letter was generated, for example it can contain either address_line_1 or addressline1. This change ensures that it is always serialized in the same way.
This commit is contained in:
@@ -11,6 +11,7 @@ from sqlalchemy.dialects.postgresql import (
|
|||||||
JSON
|
JSON
|
||||||
)
|
)
|
||||||
from sqlalchemy import UniqueConstraint, CheckConstraint
|
from sqlalchemy import UniqueConstraint, CheckConstraint
|
||||||
|
from notifications_utils.columns import Columns
|
||||||
from notifications_utils.recipients import (
|
from notifications_utils.recipients import (
|
||||||
validate_email_address,
|
validate_email_address,
|
||||||
validate_phone_number,
|
validate_phone_number,
|
||||||
@@ -1223,12 +1224,13 @@ class Notification(db.Model):
|
|||||||
}
|
}
|
||||||
|
|
||||||
if self.notification_type == LETTER_TYPE:
|
if self.notification_type == LETTER_TYPE:
|
||||||
serialized['line_1'] = self.personalisation['address_line_1']
|
col = Columns(self.personalisation)
|
||||||
serialized['line_2'] = self.personalisation.get('address_line_2')
|
serialized['line_1'] = col.get('address_line_1')
|
||||||
serialized['line_3'] = self.personalisation.get('address_line_3')
|
serialized['line_2'] = col.get('address_line_2')
|
||||||
serialized['line_4'] = self.personalisation.get('address_line_4')
|
serialized['line_3'] = col.get('address_line_3')
|
||||||
serialized['line_5'] = self.personalisation.get('address_line_5')
|
serialized['line_4'] = col.get('address_line_4')
|
||||||
serialized['line_6'] = self.personalisation.get('address_line_6')
|
serialized['line_5'] = col.get('address_line_5')
|
||||||
|
serialized['line_6'] = col.get('address_line_6')
|
||||||
serialized['postcode'] = self.personalisation['postcode']
|
serialized['postcode'] = self.personalisation['postcode']
|
||||||
serialized['estimated_delivery'] = \
|
serialized['estimated_delivery'] = \
|
||||||
get_letter_timings(serialized['created_at'])\
|
get_letter_timings(serialized['created_at'])\
|
||||||
|
|||||||
@@ -294,3 +294,16 @@ def test_service_get_default_contact_letter(sample_service):
|
|||||||
def test_service_get_default_sms_sender(notify_db_session):
|
def test_service_get_default_sms_sender(notify_db_session):
|
||||||
service = create_service()
|
service = create_service()
|
||||||
assert service.get_default_sms_sender() == 'testing'
|
assert service.get_default_sms_sender() == 'testing'
|
||||||
|
|
||||||
|
|
||||||
|
def test_letter_notification_serializes_correctly(client, sample_letter_notification):
|
||||||
|
sample_letter_notification.personalisation = {
|
||||||
|
'addressline1': 'test',
|
||||||
|
'addressline2': 'London',
|
||||||
|
'postcode': 'N1',
|
||||||
|
}
|
||||||
|
|
||||||
|
json = sample_letter_notification.serialize()
|
||||||
|
assert json['line_1'] == 'test'
|
||||||
|
assert json['line_2'] == 'London'
|
||||||
|
assert json['postcode'] == 'N1'
|
||||||
|
|||||||
Reference in New Issue
Block a user