diff --git a/app/models.py b/app/models.py index 1592557b6..4effde3c6 100644 --- a/app/models.py +++ b/app/models.py @@ -464,7 +464,7 @@ class Template(db.Model): "created_by": self.created_by.email_address, "version": self.version, "body": self.content, - "subject": self.subject if self.template_type == EMAIL_TYPE else None + "subject": self.subject if self.template_type != SMS_TYPE else None } return serialized diff --git a/tests/app/test_model.py b/tests/app/test_model.py index 9cefb66df..d38e641ab 100644 --- a/tests/app/test_model.py +++ b/tests/app/test_model.py @@ -203,3 +203,18 @@ def test_letter_notification_serializes_with_address(client, sample_letter_notif assert res['line_5'] is None assert res['line_6'] is None assert res['postcode'] == 'SW1 1AA' + + +def test_sms_notification_serializes_without_subject(client, sample_template): + res = sample_template.serialize() + assert res['subject'] is None + + +def test_email_notification_serializes_with_subject(client, sample_email_template): + res = sample_email_template.serialize() + assert res['subject'] == 'Email Subject' + + +def test_letter_notification_serializes_with_subject(client, sample_letter_template): + res = sample_letter_template.serialize() + assert res['subject'] == 'Template Subject'