Skip to content

Commit

Permalink
Fix/remove warn keys when annual limits change (#2383)
Browse files Browse the repository at this point in the history
* feat(annual limits changed): remove warning/at-limit key from redis, so users will be warned when they reach 80/100% again

* test(annual limita changed): ensure redis keys get deleted when the limits change

* fix: consolidate the code

* fix: use the correct key with each notification type
  • Loading branch information
andrewleith authored Dec 9, 2024
1 parent 34acf4d commit 923cb56
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/service/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,11 +314,16 @@ def update_service(service_id):
redis_store.delete(over_sms_daily_limit_cache_key(service_id))
if not fetched_service.restricted:
_warn_service_users_about_sms_limit_changed(service_id, current_data)

if sms_annual_limit_changed:
_warn_service_users_about_annual_limit_change(service, SMS_TYPE)
# TODO: abstract this in the annual_limits_client
redis_store.delete(f"annual-limit:{service_id}:status:near_sms_limit")
redis_store.delete(f"annual-limit:{service_id}:status:over_sms_limit")
if email_annual_limit_changed:
_warn_service_users_about_annual_limit_change(service, EMAIL_TYPE)
# TODO: abstract this in the annual_limits_client
redis_store.delete(f"annual-limit:{service_id}:status:near_email_limit")
redis_store.delete(f"annual-limit:{service_id}:status:over_email_limit")

if service_going_live:
_warn_services_users_about_going_live(service_id, current_data)
Expand Down
11 changes: 11 additions & 0 deletions tests/app/service/test_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,7 @@ def test_update_service_annual_limits(
mocker,
):
mocker.patch("app.service.rest.send_notification_to_service_users")
redis_delete = mocker.patch("app.service.rest.redis_store.delete")
admin_request.post(
"service.update_service",
service_id=sample_service.id,
Expand All @@ -1037,6 +1038,16 @@ def test_update_service_annual_limits(
_expected_status=expected_status,
)
assert getattr(sample_service, limit_field) == limit_value
if limit_field == "sms_annual_limit":
assert redis_delete.call_args_list == [
call(f"annual-limit:{sample_service.id}:status:near_sms_limit"),
call(f"annual-limit:{sample_service.id}:status:over_sms_limit"),
]
if limit_field == "email_annual_limit":
assert redis_delete.call_args_list == [
call(f"annual-limit:{sample_service.id}:status:near_email_limit"),
call(f"annual-limit:{sample_service.id}:status:over_email_limit"),
]


def test_get_users_by_service(notify_api, sample_service):
Expand Down

0 comments on commit 923cb56

Please sign in to comment.