diff --git a/app/dao/services_dao.py b/app/dao/services_dao.py index c4f3f5222..4456faaae 100644 --- a/app/dao/services_dao.py +++ b/app/dao/services_dao.py @@ -127,6 +127,8 @@ def dao_fetch_live_services_data(): Service.volume_email, Service.volume_letter, this_year_ft_billing.c.notification_type + ).order_by( + asc(Service.go_live_at) ).all() results = [] for row in data: diff --git a/tests/app/dao/test_services_dao.py b/tests/app/dao/test_services_dao.py index cc22d82c9..77c93fea8 100644 --- a/tests/app/dao/test_services_dao.py +++ b/tests/app/dao/test_services_dao.py @@ -387,10 +387,10 @@ def test_get_all_user_services_should_return_empty_list_if_no_services_for_user( @freeze_time('2019-04-23T10:00:00') def test_dao_fetch_live_services_data(sample_user, mock): org = create_organisation() - service = create_service(go_live_user=sample_user) + service = create_service(go_live_user=sample_user, go_live_at='2014-04-20T10:00:00') template = create_template(service=service) - service_2 = create_service(service_name='second', go_live_user=sample_user) - create_service(service_name='third') + service_2 = create_service(service_name='second', go_live_user=sample_user, go_live_at='2017-04-20T10:00:00') + create_service(service_name='third', go_live_at='2016-04-20T10:00:00') create_service(service_name='not_live', count_as_live=False) template2 = create_template(service=service, template_type='email') template_letter_1 = create_template(service=service, template_type='letter') @@ -410,21 +410,24 @@ def test_dao_fetch_live_services_data(sample_user, mock): results = dao_fetch_live_services_data() assert len(results) == 3 - assert {'service_id': mock.ANY, 'service_name': 'Sample service', 'organisation_name': 'test_org_1', + # checks the results and that they are ordered by date: + assert results == [ + {'service_id': mock.ANY, 'service_name': 'Sample service', 'organisation_name': 'test_org_1', 'consent_to_research': None, 'contact_name': 'Test User', 'contact_email': 'notify@digital.cabinet-office.gov.uk', 'contact_mobile': '+447700900986', - 'live_date': None, 'sms_volume_intent': None, 'email_volume_intent': None, - 'letter_volume_intent': None, 'sms_totals': 2, 'email_totals': 1, 'letter_totals': 1} in results - assert {'service_id': mock.ANY, 'service_name': 'second', 'organisation_name': None, 'consent_to_research': None, - 'contact_name': 'Test User', 'contact_email': 'notify@digital.cabinet-office.gov.uk', - 'contact_mobile': '+447700900986', 'live_date': None, 'sms_volume_intent': None, - 'email_volume_intent': None, 'letter_volume_intent': None, - 'sms_totals': 0, 'email_totals': 0, 'letter_totals': 1} in results - assert {'service_id': mock.ANY, 'service_name': 'third', 'organisation_name': None, 'consent_to_research': None, + 'live_date': datetime(2014, 4, 20, 10, 0), 'sms_volume_intent': None, 'email_volume_intent': None, + 'letter_volume_intent': None, 'sms_totals': 2, 'email_totals': 1, 'letter_totals': 1}, + {'service_id': mock.ANY, 'service_name': 'third', 'organisation_name': None, 'consent_to_research': None, 'contact_name': None, 'contact_email': None, - 'contact_mobile': None, 'live_date': None, 'sms_volume_intent': None, + 'contact_mobile': None, 'live_date': datetime(2016, 4, 20, 10, 0), 'sms_volume_intent': None, 'email_volume_intent': None, 'letter_volume_intent': None, - 'sms_totals': 0, 'email_totals': 0, 'letter_totals': 0} in results + 'sms_totals': 0, 'email_totals': 0, 'letter_totals': 0}, + {'service_id': mock.ANY, 'service_name': 'second', 'organisation_name': None, 'consent_to_research': None, + 'contact_name': 'Test User', 'contact_email': 'notify@digital.cabinet-office.gov.uk', + 'contact_mobile': '+447700900986', 'live_date': datetime(2017, 4, 20, 10, 0), 'sms_volume_intent': None, + 'email_volume_intent': None, 'letter_volume_intent': None, + 'sms_totals': 0, 'email_totals': 0, 'letter_totals': 1} + ] def test_get_service_by_id_returns_none_if_no_service(notify_db):