diff --git a/app/v2/notifications/post_notifications.py b/app/v2/notifications/post_notifications.py index 74961d778..80da6c16a 100644 --- a/app/v2/notifications/post_notifications.py +++ b/app/v2/notifications/post_notifications.py @@ -16,7 +16,7 @@ from app.models import ( SMS_TYPE, EMAIL_TYPE, LETTER_TYPE, - # PRECOMPILED_LETTER, + PRECOMPILED_LETTER, PRIORITY, KEY_TYPE_TEST, KEY_TYPE_TEAM, @@ -69,7 +69,7 @@ def post_precompiled_letter_notification(): # Check both permission to send letters and permission to send pre-compiled PDFs check_service_has_permission(LETTER_TYPE, authenticated_service.permissions) - # check_service_has_permission(PRECOMPILED_LETTER, authenticated_service.permissions) + check_service_has_permission(PRECOMPILED_LETTER, authenticated_service.permissions) check_rate_limiting(authenticated_service, api_user) diff --git a/tests/app/v2/notifications/test_post_notifications.py b/tests/app/v2/notifications/test_post_notifications.py index 3e1140367..493aedf15 100644 --- a/tests/app/v2/notifications/test_post_notifications.py +++ b/tests/app/v2/notifications/test_post_notifications.py @@ -697,7 +697,25 @@ def test_post_email_notification_with_invalid_reply_to_id_returns_400(client, sa assert 'BadRequestError' in resp_json['errors'][0]['error'] -def test_post_precompiled_letter_notification_returns_201(client, sample_service, notify_user, mocker): +def test_post_precompiled_letter_requires_permission(client, sample_service, notify_user, mocker): + mocker.patch('app.v2.notifications.post_notifications.upload_letter_pdf') + data = { + "reference": "letter-reference", + "content": "bGV0dGVyLWNvbnRlbnQ=" + } + auth_header = create_authorization_header(service_id=sample_service.id) + response = client.post( + path="v2/notifications/letter", + data=json.dumps(data), + headers=[('Content-Type', 'application/json'), auth_header]) + + assert response.status_code == 400, response.get_data(as_text=True) + resp_json = json.loads(response.get_data(as_text=True)) + assert resp_json['errors'][0]['message'] == 'Cannot send precompiled_letters' + + +def test_post_precompiled_letter_notification_returns_201(client, notify_user, mocker): + sample_service = create_service(service_permissions=['letter', 'precompiled_letter']) s3mock = mocker.patch('app.v2.notifications.post_notifications.upload_letter_pdf') data = { "reference": "letter-reference",