mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-18 08:02:31 -05:00
Give better error when sending to non-team member
Scenario we saw in research: - trying to send a message to someone outside your team - service is in trial mode Result: - error message was terrible, no-one understood it Solution: - better error message
This commit is contained in:
@@ -270,9 +270,13 @@ def send_notification(notification_type):
|
|||||||
[user.mobile_number, user.email_address] for user in service.users
|
[user.mobile_number, user.email_address] for user in service.users
|
||||||
)
|
)
|
||||||
):
|
):
|
||||||
message = 'Invalid {} for restricted service'.format(first_column_heading[notification_type])
|
raise InvalidRequest(
|
||||||
errors = {'to': [message]}
|
{'to': [(
|
||||||
raise InvalidRequest(errors, status_code=400)
|
'Can’t send to this recipient when service is in trial mode '
|
||||||
|
'– see https://www.notifications.service.gov.uk/trial-mode'
|
||||||
|
)]},
|
||||||
|
status_code=400
|
||||||
|
)
|
||||||
|
|
||||||
notification_id = create_uuid()
|
notification_id = create_uuid()
|
||||||
notification.update({"template_version": template.version})
|
notification.update({"template_version": template.version})
|
||||||
|
|||||||
@@ -227,7 +227,10 @@ def test_should_not_send_sms_if_restricted_and_not_a_service_user(notify_api, sa
|
|||||||
app.celery.tasks.send_sms.apply_async.assert_not_called()
|
app.celery.tasks.send_sms.apply_async.assert_not_called()
|
||||||
|
|
||||||
assert response.status_code == 400
|
assert response.status_code == 400
|
||||||
assert 'Invalid phone number for restricted service' in json_resp['message']['to']
|
assert [(
|
||||||
|
'Can’t send to this recipient when service is in trial mode '
|
||||||
|
'– see https://www.notifications.service.gov.uk/trial-mode'
|
||||||
|
)] == json_resp['message']['to']
|
||||||
|
|
||||||
|
|
||||||
def test_should_send_sms_if_restricted_and_a_service_user(notify_api, sample_template, mocker):
|
def test_should_send_sms_if_restricted_and_a_service_user(notify_api, sample_template, mocker):
|
||||||
@@ -519,7 +522,10 @@ def test_should_not_send_email_if_restricted_and_not_a_service_user(notify_api,
|
|||||||
app.celery.tasks.send_email.apply_async.assert_not_called()
|
app.celery.tasks.send_email.apply_async.assert_not_called()
|
||||||
|
|
||||||
assert response.status_code == 400
|
assert response.status_code == 400
|
||||||
assert 'Invalid email address for restricted service' in json_resp['message']['to']
|
assert [(
|
||||||
|
'Can’t send to this recipient when service is in trial mode – see '
|
||||||
|
'https://www.notifications.service.gov.uk/trial-mode'
|
||||||
|
)] == json_resp['message']['to']
|
||||||
|
|
||||||
|
|
||||||
@freeze_time("2016-01-01 11:09:00.061258")
|
@freeze_time("2016-01-01 11:09:00.061258")
|
||||||
@@ -698,7 +704,10 @@ def test_should_not_send_email_if_team_api_key_and_not_a_service_user(notify_api
|
|||||||
app.celery.tasks.send_email.apply_async.assert_not_called()
|
app.celery.tasks.send_email.apply_async.assert_not_called()
|
||||||
|
|
||||||
assert response.status_code == 400
|
assert response.status_code == 400
|
||||||
assert 'Invalid email address for restricted service' in json_resp['message']['to']
|
assert [(
|
||||||
|
'Can’t send to this recipient when service is in trial mode – see '
|
||||||
|
'https://www.notifications.service.gov.uk/trial-mode'
|
||||||
|
)] == json_resp['message']['to']
|
||||||
|
|
||||||
|
|
||||||
def test_should_not_send_sms_if_team_api_key_and_not_a_service_user(notify_api, sample_template, mocker):
|
def test_should_not_send_sms_if_team_api_key_and_not_a_service_user(notify_api, sample_template, mocker):
|
||||||
@@ -721,7 +730,10 @@ def test_should_not_send_sms_if_team_api_key_and_not_a_service_user(notify_api,
|
|||||||
app.celery.tasks.send_sms.apply_async.assert_not_called()
|
app.celery.tasks.send_sms.apply_async.assert_not_called()
|
||||||
|
|
||||||
assert response.status_code == 400
|
assert response.status_code == 400
|
||||||
assert 'Invalid phone number for restricted service' in json_resp['message']['to']
|
assert [(
|
||||||
|
'Can’t send to this recipient when service is in trial mode – see '
|
||||||
|
'https://www.notifications.service.gov.uk/trial-mode'
|
||||||
|
)] == json_resp['message']['to']
|
||||||
|
|
||||||
|
|
||||||
def test_should_send_email_if_team_api_key_and_a_service_user(notify_api, sample_email_template, mocker):
|
def test_should_send_email_if_team_api_key_and_a_service_user(notify_api, sample_email_template, mocker):
|
||||||
|
|||||||
Reference in New Issue
Block a user