fix: return extension_date regardless of server UTC date
All checks were successful
Chore App Build, Test, and Push Docker Images / build-and-push (push) Successful in 4m14s
All checks were successful
Chore App Build, Test, and Push Docker Images / build-and-push (push) Successful in 4m14s
list_child_tasks used date_type.today() (server UTC) to look up the TaskExtension record. When the client's local date differed from the server's UTC date (e.g. user is UTC-5 and it's past midnight UTC), the lookup returned None and extension_date was incorrectly null. Fix: - Add get_extension_for_child_task() to db/task_extensions.py that queries by child_id + task_id only, without a date filter, and returns the entry with the latest date when multiple exist. - Update list_child_tasks to use the new function. The comment already states 'client does all time math', so returning the stored extension_date is correct — the frontend compares it to local date. - In extend_chore_time, delete any existing extension for the child+task before inserting the new one to prevent stale records from accumulating across days. - Add regression test that inserts an extension for yesterday's date and asserts extension_date is non-null in the list-tasks response. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -439,6 +439,29 @@ def test_list_child_tasks_returns_extension_date_when_set(client):
|
||||
assert tasks[TASK_GOOD_ID]['extension_date'] == today
|
||||
|
||||
|
||||
def test_list_child_tasks_returns_extension_date_for_yesterday(client):
|
||||
"""Regression: extension inserted for yesterday's date must still be returned.
|
||||
|
||||
Previously, list-tasks used date_type.today() on the server to look up
|
||||
extensions, causing a timezone mismatch when the client's local date
|
||||
differed from the server's UTC date. The fix removes the date filter so
|
||||
any stored extension is returned regardless of which date it was created
|
||||
for.
|
||||
"""
|
||||
_setup_sched_child_and_tasks(task_db, child_db)
|
||||
from datetime import date as date_type_local, timedelta
|
||||
yesterday = (date_type_local.today() - timedelta(days=1)).isoformat()
|
||||
task_extensions_db.insert({
|
||||
'id': 'ext-yesterday',
|
||||
'child_id': CHILD_SCHED_ID,
|
||||
'task_id': TASK_GOOD_ID,
|
||||
'date': yesterday,
|
||||
})
|
||||
resp = client.get(f'/child/{CHILD_SCHED_ID}/list-tasks')
|
||||
tasks = {t['id']: t for t in resp.get_json()['tasks']}
|
||||
assert tasks[TASK_GOOD_ID]['extension_date'] == yesterday
|
||||
|
||||
|
||||
def test_list_child_tasks_extension_date_null_when_not_set(client):
|
||||
"""Good chore with no extension returns extension_date=null."""
|
||||
_setup_sched_child_and_tasks(task_db, child_db)
|
||||
|
||||
Reference in New Issue
Block a user