mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 02:11:11 -05:00
Update the dao_get_notification_outcomes_for_job to return the stats from either the notification table or the ft_notification_status table.
Currently if you visit the job page and the job is older than the data retention the totals on the page are all wrong because this query gets the counts from the notification table. With this change the data should always be correct. It also eliminates the need for looking at data retention. If the job is new and nothing has been created yet (i.e. the job hasn't started yet) then the page should show the correctly because the outcomes are empty (as expected), once the notifications for the jobs are created the numbers will start going up.
This commit is contained in:
@@ -622,6 +622,37 @@ def test_get_job_by_id_should_return_summed_statistics(admin_request, sample_job
|
||||
assert resp_json['data']['created_by']['name'] == 'Test User'
|
||||
|
||||
|
||||
def test_get_job_by_id_with_stats_for_old_job_where_notifications_have_been_purged(admin_request, sample_template):
|
||||
old_job = create_job(sample_template, notification_count=10, created_at=datetime.utcnow() - timedelta(days=9),
|
||||
job_status='finished')
|
||||
|
||||
def __create_ft_status(job, status, count):
|
||||
create_ft_notification_status(bst_date=job.created_at.date(),
|
||||
notification_type='sms',
|
||||
service=job.service,
|
||||
job=job,
|
||||
template=job.template,
|
||||
key_type='normal',
|
||||
notification_status=status,
|
||||
count=count)
|
||||
|
||||
__create_ft_status(old_job, 'created', 3)
|
||||
__create_ft_status(old_job, 'sending', 1)
|
||||
__create_ft_status(old_job, 'failed', 3)
|
||||
__create_ft_status(old_job, 'technical-failure', 1)
|
||||
__create_ft_status(old_job, 'temporary-failure', 2)
|
||||
|
||||
resp_json = admin_request.get('job.get_job_by_service_and_job_id', service_id=old_job.service_id, job_id=old_job.id)
|
||||
|
||||
assert resp_json['data']['id'] == str(old_job.id)
|
||||
assert {'status': 'created', 'count': 3} in resp_json['data']['statistics']
|
||||
assert {'status': 'sending', 'count': 1} in resp_json['data']['statistics']
|
||||
assert {'status': 'failed', 'count': 3} in resp_json['data']['statistics']
|
||||
assert {'status': 'technical-failure', 'count': 1} in resp_json['data']['statistics']
|
||||
assert {'status': 'temporary-failure', 'count': 2} in resp_json['data']['statistics']
|
||||
assert resp_json['data']['created_by']['name'] == 'Test User'
|
||||
|
||||
|
||||
def test_get_jobs(admin_request, sample_template):
|
||||
_setup_jobs(sample_template)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user