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

View File

@@ -6,8 +6,9 @@ from werkzeug.security import generate_password_hash
from flask import Flask
from api.chore_schedule_api import chore_schedule_api
from api.auth_api import auth_api
from db.db import users_db, child_db, chore_schedules_db, task_extensions_db
from db.db import users_db, child_db, chore_schedules_db, task_extensions_db, pending_confirmations_db, task_db
from tinydb import Query
from models.pending_confirmation import PendingConfirmation
TEST_EMAIL = "sched_test@example.com"
@@ -412,3 +413,36 @@ def test_chore_schedule_to_dict_includes_enabled():
d = s.to_dict()
assert "enabled" in d
assert d["enabled"] is False
# ---------------------------------------------------------------------------
# Bug #10: Setting schedule resets pending confirmations
# ---------------------------------------------------------------------------
def test_set_schedule_resets_pending_confirmation(client):
"""Setting/updating a chore schedule should remove pending chore confirmations."""
chore_schedules_db.truncate()
pending_confirmations_db.truncate()
task_db.truncate()
task_db.insert({
'id': TEST_TASK_ID, 'name': 'Test Chore', 'points': 5,
'type': 'chore', 'user_id': TEST_USER_ID
})
pending_confirmations_db.insert(PendingConfirmation(
child_id=TEST_CHILD_ID, entity_id=TEST_TASK_ID,
entity_type='chore', user_id=TEST_USER_ID
).to_dict())
payload = {
"mode": "days",
"day_configs": [{"day": 1, "hour": 8, "minute": 0}],
}
resp = client.put(f'/child/{TEST_CHILD_ID}/task/{TEST_TASK_ID}/schedule', json=payload)
assert resp.status_code == 200
PQ = Query()
conf = pending_confirmations_db.get(
(PQ.child_id == TEST_CHILD_ID) & (PQ.entity_id == TEST_TASK_ID) & (PQ.entity_type == 'chore')
)
assert conf is None

View File

@@ -6,9 +6,10 @@ from werkzeug.security import generate_password_hash
from flask import Flask
from api.reward_api import reward_api
from api.auth_api import auth_api
from db.db import reward_db, child_db, users_db
from db.db import reward_db, child_db, users_db, pending_confirmations_db
from tinydb import Query
from models.reward import Reward
from models.pending_confirmation import PendingConfirmation
import jwt
@@ -126,4 +127,59 @@ def test_delete_assigned_reward_removes_from_child(client):
resp2 = client.delete('/reward/r_user_owned')
assert resp2.status_code == 200
child2 = child_db.search(ChildQuery.id == 'child_for_user_reward')[0]
assert 'r_user_owned' not in child2.get('rewards', [])
assert 'r_user_owned' not in child2.get('rewards', [])
# ---------------------------------------------------------------------------
# Bug #10: Editing reward cost resets pending reward requests
# ---------------------------------------------------------------------------
def test_edit_reward_cost_resets_pending_requests(client):
"""Changing a reward's cost should remove all pending reward requests for that reward."""
reward_db.truncate()
child_db.truncate()
pending_confirmations_db.truncate()
reward_db.insert({'id': 'r_pending', 'name': 'Prize', 'cost': 50, 'user_id': 'testuserid'})
child_db.insert({
'id': 'c1', 'name': 'Alice', 'age': 8, 'points': 100,
'tasks': [], 'rewards': ['r_pending'], 'user_id': 'testuserid'
})
pending_confirmations_db.insert(PendingConfirmation(
child_id='c1', entity_id='r_pending', entity_type='reward', user_id='testuserid'
).to_dict())
resp = client.put('/reward/r_pending/edit', json={'cost': 75})
assert resp.status_code == 200
PQ = Query()
conf = pending_confirmations_db.get(
(PQ.child_id == 'c1') & (PQ.entity_id == 'r_pending') & (PQ.entity_type == 'reward')
)
assert conf is None
def test_edit_reward_name_only_keeps_pending(client):
"""Changing only the reward name should not reset pending requests."""
reward_db.truncate()
child_db.truncate()
pending_confirmations_db.truncate()
reward_db.insert({'id': 'r_name', 'name': 'Old Prize', 'cost': 50, 'user_id': 'testuserid'})
child_db.insert({
'id': 'c2', 'name': 'Bob', 'age': 7, 'points': 100,
'tasks': [], 'rewards': ['r_name'], 'user_id': 'testuserid'
})
pending_confirmations_db.insert(PendingConfirmation(
child_id='c2', entity_id='r_name', entity_type='reward', user_id='testuserid'
).to_dict())
resp = client.put('/reward/r_name/edit', json={'name': 'New Prize'})
assert resp.status_code == 200
PQ = Query()
conf = pending_confirmations_db.get(
(PQ.child_id == 'c2') & (PQ.entity_id == 'r_name') & (PQ.entity_type == 'reward')
)
assert conf is not None
assert conf['status'] == 'pending'

View File

@@ -6,8 +6,9 @@ from werkzeug.security import generate_password_hash
from flask import Flask
from api.task_api import task_api
from api.auth_api import auth_api
from db.db import task_db, child_db, users_db
from db.db import task_db, child_db, users_db, pending_confirmations_db
from tinydb import Query
from models.pending_confirmation import PendingConfirmation
import jwt
@@ -146,4 +147,59 @@ def test_delete_assigned_task_removes_from_child(client):
assert resp.status_code == 200
# verify the task id is no longer in the child's tasks
child = child_db.search(ChildQuery.id == 'child_for_task_delete')[0]
assert 't_delete_assigned' not in child.get('tasks', [])
assert 't_delete_assigned' not in child.get('tasks', [])
# ---------------------------------------------------------------------------
# Bug #10: Editing task points/type resets pending confirmations
# ---------------------------------------------------------------------------
def test_edit_task_points_resets_pending_confirmations(client):
"""Changing a task's points should remove all pending chore confirmations for that task."""
task_db.truncate()
child_db.truncate()
pending_confirmations_db.truncate()
task_db.insert({'id': 't_pending', 'name': 'Sweep', 'points': 5, 'type': 'chore', 'user_id': 'testuserid'})
child_db.insert({
'id': 'c1', 'name': 'Alice', 'age': 8, 'points': 0,
'tasks': ['t_pending'], 'rewards': [], 'user_id': 'testuserid'
})
pending_confirmations_db.insert(PendingConfirmation(
child_id='c1', entity_id='t_pending', entity_type='chore', user_id='testuserid'
).to_dict())
resp = client.put('/task/t_pending/edit', json={'points': 10})
assert resp.status_code == 200
PQ = Query()
conf = pending_confirmations_db.get(
(PQ.child_id == 'c1') & (PQ.entity_id == 't_pending') & (PQ.entity_type == 'chore')
)
assert conf is None
def test_edit_task_name_only_keeps_pending(client):
"""Changing only the task name should not reset pending confirmations."""
task_db.truncate()
child_db.truncate()
pending_confirmations_db.truncate()
task_db.insert({'id': 't_name', 'name': 'Old Name', 'points': 5, 'type': 'chore', 'user_id': 'testuserid'})
child_db.insert({
'id': 'c2', 'name': 'Bob', 'age': 7, 'points': 0,
'tasks': ['t_name'], 'rewards': [], 'user_id': 'testuserid'
})
pending_confirmations_db.insert(PendingConfirmation(
child_id='c2', entity_id='t_name', entity_type='chore', user_id='testuserid'
).to_dict())
resp = client.put('/task/t_name/edit', json={'name': 'New Name'})
assert resp.status_code == 200
PQ = Query()
conf = pending_confirmations_db.get(
(PQ.child_id == 'c2') & (PQ.entity_id == 't_name') & (PQ.entity_type == 'chore')
)
assert conf is not None
assert conf['status'] == 'pending'