added fixes for bug plan 1.0.6RC01
Some checks failed
Chore App Build, Test, and Push Docker Images / build-and-push (push) Failing after 5m43s

This commit is contained in:
2026-03-24 15:31:57 -04:00
parent 81169da05e
commit e9f4343426
27 changed files with 890 additions and 65 deletions

View File

@@ -7,11 +7,12 @@ from datetime import date as date_type
from flask import Flask
from api.child_api import child_api
from api.auth_api import auth_api
from db.db import child_db, task_db, reward_db, users_db, pending_confirmations_db, tracking_events_db
from db.db import child_db, task_db, reward_db, users_db, pending_confirmations_db, tracking_events_db, chore_schedules_db
from tinydb import Query
from models.child import Child
from models.pending_confirmation import PendingConfirmation
from models.tracking_event import TrackingEvent
from models.chore_schedule import ChoreSchedule
TEST_EMAIL = "testuser@example.com"
@@ -214,13 +215,12 @@ def test_parent_approve_chore_success(client):
data = resp.get_json()
assert data['points'] == points_before + 10
# Verify confirmation is now approved
# General chore: PendingConfirmation should be removed after approval
PQ = Query()
conf = pending_confirmations_db.get(
(PQ.child_id == child_id) & (PQ.entity_id == task_id) & (PQ.entity_type == 'chore')
)
assert conf['status'] == 'approved'
assert conf['approved_at'] is not None
assert conf is None
def test_parent_approve_chore_not_pending(client):
@@ -294,7 +294,8 @@ def test_parent_reject_chore_creates_tracking_event(client):
def test_parent_reset_chore_success(client):
child_id, task_id = setup_child_and_chore(chore_points=10)
# Confirm and approve first
_add_schedule_for(child_id, task_id)
# Confirm and approve first (scheduled chore keeps PendingConfirmation)
client.post(f'/child/{child_id}/confirm-chore', json={'task_id': task_id})
client.post(f'/child/{child_id}/approve-chore', json={'task_id': task_id})
# Now reset
@@ -320,6 +321,7 @@ def test_parent_reset_chore_not_completed(client):
def test_parent_reset_chore_creates_tracking_event(client):
child_id, task_id = setup_child_and_chore(chore_points=10)
_add_schedule_for(child_id, task_id)
client.post(f'/child/{child_id}/confirm-chore', json={'task_id': task_id})
client.post(f'/child/{child_id}/approve-chore', json={'task_id': task_id})
tracking_events_db.truncate()
@@ -330,8 +332,9 @@ def test_parent_reset_chore_creates_tracking_event(client):
def test_parent_reset_then_child_confirm_again(client):
"""Full cycle: confirm → approve → reset → confirm → approve."""
"""Full cycle: confirm → approve → reset → confirm → approve (scheduled chore)."""
child_id, task_id = setup_child_and_chore(chore_points=10)
_add_schedule_for(child_id, task_id)
child_db.update({'points': 0}, Query().id == child_id)
# First cycle
@@ -359,20 +362,19 @@ def test_parent_reset_then_child_confirm_again(client):
# ---------------------------------------------------------------------------
def test_parent_trigger_chore_directly_creates_approved_confirmation(client):
"""General chore trigger should not persist PendingConfirmation."""
child_id, task_id = setup_child_and_chore(chore_points=10)
child_db.update({'points': 0}, Query().id == child_id)
resp = client.post(f'/child/{child_id}/trigger-task', json={'task_id': task_id})
assert resp.status_code == 200
assert resp.get_json()['points'] == 10
# Verify an approved PendingConfirmation exists
# General chore: no PendingConfirmation should remain
PQ = Query()
conf = pending_confirmations_db.get(
(PQ.child_id == child_id) & (PQ.entity_id == task_id) & (PQ.entity_type == 'chore')
)
assert conf is not None
assert conf['status'] == 'approved'
assert conf['approved_at'] is not None
assert conf is None
# ---------------------------------------------------------------------------
@@ -479,3 +481,75 @@ def test_list_pending_confirmations_filters_by_user(client):
resp = client.get('/pending-confirmations')
assert resp.status_code == 200
assert resp.get_json()['count'] == 0
# ---------------------------------------------------------------------------
# Bug #3: General vs Scheduled chore approval
# ---------------------------------------------------------------------------
def _add_schedule_for(child_id, task_id):
"""Insert a simple days-mode schedule so the chore is treated as scheduled."""
chore_schedules_db.truncate()
sched = ChoreSchedule(
child_id=child_id, task_id=task_id, mode='days',
day_configs=[{'day': d, 'hour': 8, 'minute': 0} for d in range(7)]
)
chore_schedules_db.insert(sched.to_dict())
def test_approve_general_chore_removes_pending(client):
"""Approving a general (non-scheduled) chore should remove PendingConfirmation."""
child_id, task_id = setup_child_and_chore(chore_points=5)
chore_schedules_db.truncate()
client.post(f'/child/{child_id}/confirm-chore', json={'task_id': task_id})
resp = client.post(f'/child/{child_id}/approve-chore', json={'task_id': task_id})
assert resp.status_code == 200
PQ = Query()
conf = pending_confirmations_db.get(
(PQ.child_id == child_id) & (PQ.entity_id == task_id) & (PQ.entity_type == 'chore')
)
assert conf is None
def test_approve_scheduled_chore_keeps_approved_pending(client):
"""Approving a scheduled chore should keep PendingConfirmation as approved."""
child_id, task_id = setup_child_and_chore(chore_points=5)
_add_schedule_for(child_id, task_id)
client.post(f'/child/{child_id}/confirm-chore', json={'task_id': task_id})
resp = client.post(f'/child/{child_id}/approve-chore', json={'task_id': task_id})
assert resp.status_code == 200
PQ = Query()
conf = pending_confirmations_db.get(
(PQ.child_id == child_id) & (PQ.entity_id == task_id) & (PQ.entity_type == 'chore')
)
assert conf is not None
assert conf['status'] == 'approved'
assert conf['approved_at'] is not None
def test_trigger_scheduled_chore_creates_approved_confirmation(client):
"""Parent trigger on scheduled chore should create approved PendingConfirmation."""
child_id, task_id = setup_child_and_chore(chore_points=10)
_add_schedule_for(child_id, task_id)
child_db.update({'points': 0}, Query().id == child_id)
resp = client.post(f'/child/{child_id}/trigger-task', json={'task_id': task_id})
assert resp.status_code == 200
assert resp.get_json()['points'] == 10
PQ = Query()
conf = pending_confirmations_db.get(
(PQ.child_id == child_id) & (PQ.entity_id == task_id) & (PQ.entity_type == 'chore')
)
assert conf is not None
assert conf['status'] == 'approved'
def test_approve_general_chore_can_be_confirmed_again(client):
"""After approving a general chore, child can confirm it again."""
child_id, task_id = setup_child_and_chore(chore_points=5)
chore_schedules_db.truncate()
# First cycle
client.post(f'/child/{child_id}/confirm-chore', json={'task_id': task_id})
client.post(f'/child/{child_id}/approve-chore', json={'task_id': task_id})
# Should be able to confirm again
resp = client.post(f'/child/{child_id}/confirm-chore', json={'task_id': task_id})
assert resp.status_code == 200