mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-21 07:51:13 -05:00
Add order by in the dao_get_reply_to_by_service_id()
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
from sqlalchemy import desc
|
||||||
|
|
||||||
from app import db
|
from app import db
|
||||||
from app.dao.dao_utils import transactional
|
from app.dao.dao_utils import transactional
|
||||||
from app.errors import InvalidRequest
|
from app.errors import InvalidRequest
|
||||||
@@ -9,7 +11,7 @@ def dao_get_reply_to_by_service_id(service_id):
|
|||||||
ServiceEmailReplyTo
|
ServiceEmailReplyTo
|
||||||
).filter(
|
).filter(
|
||||||
ServiceEmailReplyTo.service_id == service_id
|
ServiceEmailReplyTo.service_id == service_id
|
||||||
).order_by(ServiceEmailReplyTo.created_at).all()
|
).order_by(desc(ServiceEmailReplyTo.is_default), desc(ServiceEmailReplyTo.created_at)).all()
|
||||||
return reply_to
|
return reply_to
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -61,13 +61,15 @@ def test_create_or_update_email_reply_to_raises_exception_if_multilple_email_add
|
|||||||
def test_dao_get_reply_to_by_service_id(notify_db_session):
|
def test_dao_get_reply_to_by_service_id(notify_db_session):
|
||||||
service = create_service()
|
service = create_service()
|
||||||
default_reply_to = create_reply_to_email(service=service, email_address='something@email.com')
|
default_reply_to = create_reply_to_email(service=service, email_address='something@email.com')
|
||||||
|
second_reply_to = create_reply_to_email(service=service, email_address='second@email.com', is_default=False)
|
||||||
another_reply_to = create_reply_to_email(service=service, email_address='another@email.com', is_default=False)
|
another_reply_to = create_reply_to_email(service=service, email_address='another@email.com', is_default=False)
|
||||||
|
|
||||||
results = dao_get_reply_to_by_service_id(service_id=service.id)
|
results = dao_get_reply_to_by_service_id(service_id=service.id)
|
||||||
|
|
||||||
assert len(results) == 2
|
assert len(results) == 3
|
||||||
assert default_reply_to in results
|
assert default_reply_to == results[0]
|
||||||
assert another_reply_to in results
|
assert another_reply_to == results[1]
|
||||||
|
assert second_reply_to == results[2]
|
||||||
|
|
||||||
|
|
||||||
def test_add_reply_to_email_address_for_service_creates_first_email_for_service(notify_db_session):
|
def test_add_reply_to_email_address_for_service_creates_first_email_for_service(notify_db_session):
|
||||||
|
|||||||
Reference in New Issue
Block a user