Add one_off filter when getting all notifications for a service

Added the option to filter by one_off messages to the DAO function
`get_notifications_for_service`. Previously, one-off notifications
were not returned - this has changed so that the default is for
one-off notifications to be returned. Also simplified the `include_jobs`
filter for this function.

The DAO function gets used in 3 places - for the V1 and V2 API endpoints,
which will now start to return one-off messages. It also gets used by
the admin app which needs to pass in `include_one_off=False` to the
`get_all_notifications_for_service` where we don't want one-off
notifications to show, such as the API message log page.
This commit is contained in:
Katie Smith
2018-07-18 10:54:20 +01:00
parent 8d48f41776
commit b1cfa8942a
6 changed files with 38 additions and 10 deletions

View File

@@ -1384,15 +1384,21 @@ def test_get_all_notifications_for_service_including_ones_made_by_jobs(
def test_get_only_api_created_notifications_for_service(
admin_request,
sample_job,
sample_template
sample_template,
sample_user,
):
# notification sent as a job
create_notification(sample_template, job=sample_job)
# notification sent as a one-off
create_notification(sample_template, one_off=True, created_by_id=sample_user.id)
# notification sent via API
without_job = create_notification(sample_template)
resp = admin_request.get(
'service.get_all_notifications_for_service',
service_id=sample_template.service_id,
include_jobs=False
include_jobs=False,
include_one_off=False
)
assert len(resp['notifications']) == 1
assert resp['notifications'][0]['id'] == str(without_job.id)