mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-19 14:08:47 -04:00
Send '0', not 'null', to perf platform if no notifications are sent
This commit is contained in:
@@ -527,7 +527,7 @@ def dao_get_total_notifications_sent_per_day_for_perfomance_platform(start_date,
|
|||||||
"""
|
"""
|
||||||
SELECT
|
SELECT
|
||||||
count(notifications),
|
count(notifications),
|
||||||
sum(CASE WHEN sent_at - created_at <= interval '10 seconds' THEN 1 ELSE 0 END)
|
coalesce(sum(CASE WHEN sent_at - created_at <= interval '10 seconds' THEN 1 ELSE 0 END), 0)
|
||||||
FROM notifications
|
FROM notifications
|
||||||
WHERE
|
WHERE
|
||||||
created_at > 'START DATE' AND
|
created_at > 'START DATE' AND
|
||||||
@@ -537,14 +537,14 @@ def dao_get_total_notifications_sent_per_day_for_perfomance_platform(start_date,
|
|||||||
notification_type != 'letter';
|
notification_type != 'letter';
|
||||||
"""
|
"""
|
||||||
under_10_secs = Notification.sent_at - Notification.created_at <= timedelta(seconds=10)
|
under_10_secs = Notification.sent_at - Notification.created_at <= timedelta(seconds=10)
|
||||||
sum_column = functions.sum(
|
sum_column = functions.coalesce(functions.sum(
|
||||||
case(
|
case(
|
||||||
[
|
[
|
||||||
(under_10_secs, 1)
|
(under_10_secs, 1)
|
||||||
],
|
],
|
||||||
else_=0
|
else_=0
|
||||||
)
|
)
|
||||||
)
|
), 0)
|
||||||
return db.session.query(
|
return db.session.query(
|
||||||
func.count(Notification.id).label('messages_total'),
|
func.count(Notification.id).label('messages_total'),
|
||||||
sum_column.label('messages_within_10_secs')
|
sum_column.label('messages_within_10_secs')
|
||||||
|
|||||||
@@ -85,3 +85,10 @@ def test_get_total_notifications_counts_messages_that_have_not_sent(sample_templ
|
|||||||
result = dao_get_total_notifications_sent_per_day_for_perfomance_platform(date(2016, 10, 18), date(2016, 10, 19))
|
result = dao_get_total_notifications_sent_per_day_for_perfomance_platform(date(2016, 10, 18), date(2016, 10, 19))
|
||||||
assert result.messages_total == 1
|
assert result.messages_total == 1
|
||||||
assert result.messages_within_10_secs == 0
|
assert result.messages_within_10_secs == 0
|
||||||
|
|
||||||
|
|
||||||
|
@freeze_time('2016-10-18T10:00')
|
||||||
|
def test_get_total_notifications_returns_zero_if_no_data(notify_db_session):
|
||||||
|
result = dao_get_total_notifications_sent_per_day_for_perfomance_platform(date(2016, 10, 18), date(2016, 10, 19))
|
||||||
|
assert result.messages_total == 0
|
||||||
|
assert result.messages_within_10_secs == 0
|
||||||
|
|||||||
Reference in New Issue
Block a user