mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-19 14:08:47 -04:00
Normalize outbound SMS sender number in one off notifications
This commit is contained in:
@@ -367,6 +367,9 @@ class ServiceSmsSender(db.Model):
|
|||||||
created_at = db.Column(db.DateTime, default=datetime.datetime.utcnow, nullable=False)
|
created_at = db.Column(db.DateTime, default=datetime.datetime.utcnow, nullable=False)
|
||||||
updated_at = db.Column(db.DateTime, nullable=True, onupdate=datetime.datetime.utcnow)
|
updated_at = db.Column(db.DateTime, nullable=True, onupdate=datetime.datetime.utcnow)
|
||||||
|
|
||||||
|
def get_reply_to_text(self):
|
||||||
|
return try_validate_and_format_phone_number(self.sms_sender)
|
||||||
|
|
||||||
def serialize(self):
|
def serialize(self):
|
||||||
return {
|
return {
|
||||||
"id": str(self.id),
|
"id": str(self.id),
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ def get_reply_to_text(notification_type, sender_id, service, template):
|
|||||||
if notification_type == EMAIL_TYPE:
|
if notification_type == EMAIL_TYPE:
|
||||||
reply_to = dao_get_reply_to_by_id(service.id, sender_id).email_address
|
reply_to = dao_get_reply_to_by_id(service.id, sender_id).email_address
|
||||||
elif notification_type == SMS_TYPE:
|
elif notification_type == SMS_TYPE:
|
||||||
reply_to = dao_get_service_sms_senders_by_id(service.id, sender_id).sms_sender
|
reply_to = dao_get_service_sms_senders_by_id(service.id, sender_id).get_reply_to_text()
|
||||||
else:
|
else:
|
||||||
reply_to = template.get_reply_to_text()
|
reply_to = template.get_reply_to_text()
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ from tests.app.db import (
|
|||||||
create_user,
|
create_user,
|
||||||
create_reply_to_email,
|
create_reply_to_email,
|
||||||
create_letter_contact,
|
create_letter_contact,
|
||||||
|
create_service_sms_sender,
|
||||||
create_service,
|
create_service,
|
||||||
create_template
|
create_template
|
||||||
)
|
)
|
||||||
@@ -238,9 +239,62 @@ def test_send_one_off_letter_notification_should_use_template_reply_to_text(samp
|
|||||||
research_mode=False,
|
research_mode=False,
|
||||||
queue=None
|
queue=None
|
||||||
)
|
)
|
||||||
|
|
||||||
assert notification.reply_to_text == "Edinburgh, ED1 1AA"
|
assert notification.reply_to_text == "Edinburgh, ED1 1AA"
|
||||||
|
|
||||||
|
|
||||||
|
def test_send_one_off_sms_notification_should_use_sms_sender_reply_to_text(sample_service, celery_mock):
|
||||||
|
template = create_template(service=sample_service, template_type=SMS_TYPE)
|
||||||
|
sms_sender = create_service_sms_sender(
|
||||||
|
service=sample_service,
|
||||||
|
sms_sender='07123123123',
|
||||||
|
is_default=False
|
||||||
|
)
|
||||||
|
|
||||||
|
data = {
|
||||||
|
'to': '07111111111',
|
||||||
|
'template_id': str(template.id),
|
||||||
|
'created_by': str(sample_service.created_by_id),
|
||||||
|
'sender_id': str(sms_sender.id),
|
||||||
|
}
|
||||||
|
|
||||||
|
notification_id = send_one_off_notification(service_id=sample_service.id, post_data=data)
|
||||||
|
notification = Notification.query.get(notification_id['id'])
|
||||||
|
celery_mock.assert_called_once_with(
|
||||||
|
notification=notification,
|
||||||
|
research_mode=False,
|
||||||
|
queue=None
|
||||||
|
)
|
||||||
|
|
||||||
|
assert notification.reply_to_text == "447123123123"
|
||||||
|
|
||||||
|
|
||||||
|
def test_send_one_off_sms_notification_should_use_default_service_reply_to_text(sample_service, celery_mock):
|
||||||
|
template = create_template(service=sample_service, template_type=SMS_TYPE)
|
||||||
|
sample_service.service_sms_senders[0].is_default = False
|
||||||
|
create_service_sms_sender(
|
||||||
|
service=sample_service,
|
||||||
|
sms_sender='07123123456',
|
||||||
|
is_default=True
|
||||||
|
)
|
||||||
|
|
||||||
|
data = {
|
||||||
|
'to': '07111111111',
|
||||||
|
'template_id': str(template.id),
|
||||||
|
'created_by': str(sample_service.created_by_id),
|
||||||
|
}
|
||||||
|
|
||||||
|
notification_id = send_one_off_notification(service_id=sample_service.id, post_data=data)
|
||||||
|
notification = Notification.query.get(notification_id['id'])
|
||||||
|
celery_mock.assert_called_once_with(
|
||||||
|
notification=notification,
|
||||||
|
research_mode=False,
|
||||||
|
queue=None
|
||||||
|
)
|
||||||
|
|
||||||
|
assert notification.reply_to_text == "447123123456"
|
||||||
|
|
||||||
|
|
||||||
def test_send_one_off_notification_should_throw_exception_if_reply_to_id_doesnot_exist(
|
def test_send_one_off_notification_should_throw_exception_if_reply_to_id_doesnot_exist(
|
||||||
sample_email_template
|
sample_email_template
|
||||||
):
|
):
|
||||||
|
|||||||
Reference in New Issue
Block a user