Files
Shubhankar45 8fdd20b29f Production
2026-09-22 06:23:46 +00:00

34 lines
1018 B
Python

from datetime import date, datetime, timedelta, timezone
from app.common.enums import DCRStatus
from app.reports.models import DailyCallReport
from app.reports.repository import DCRRepository
async def test_list_scoped_orders_newest_created_report_first(db, org):
mr = org["mr1"]
hq = org["hq1"]
today = date.today()
yesterday = today - timedelta(days=1)
first = DailyCallReport(
mr_user_id=mr.id,
headquarters_id=hq.id,
report_date=today,
status=DCRStatus.DRAFT,
created_at=datetime(2024, 1, 1, 8, 0, tzinfo=timezone.utc),
)
second = DailyCallReport(
mr_user_id=mr.id,
headquarters_id=hq.id,
report_date=yesterday,
status=DCRStatus.DRAFT,
created_at=datetime(2024, 1, 1, 9, 0, tzinfo=timezone.utc),
)
db.add_all([first, second])
await db.commit()
reports = await DCRRepository(db).list_scoped(mr_user_id=mr.id, hq_ids={hq.id})
assert [r.id for r in reports] == [second.id, first.id]