doris-barbell: seed john split and routine board
Some checks failed
secret-guardrails / artifact-secret-scan (push) Has been cancelled
secret-guardrails / gitleaks (push) Has been cancelled

This commit is contained in:
Fizzlepoof
2026-05-24 02:59:14 +00:00
parent 9e0f66c2b6
commit a4c5ee7285
5 changed files with 397 additions and 56 deletions

View File

@@ -1,3 +1,4 @@
import json
from pathlib import Path
from fastapi.testclient import TestClient
@@ -30,14 +31,37 @@ def test_dashboard_summary_seeds_john_and_manndra(tmp_path: Path) -> None:
assert user_ids == ['john', 'manndra']
assert payload['counts'] == {
'exercise_templates': 0,
'exercise_templates': 31,
'measurement_entries': 0,
'routines': 0,
'routines': 5,
'weight_entries': 0,
'workout_sessions': 0,
}
john = next(user for user in payload['users'] if user['id'] == 'john')
assert john['measurement_system'] == 'imperial'
routine_names = [routine['name'] for routine in payload['routines']]
assert routine_names == [
'Monday: Chest',
'Tuesday: Back',
'Wednesday: Arms',
'Thursday: Shoulders',
'Friday: Legs',
]
assert payload['routines'][0]['exercises'][0] == {
'exercise_name': 'Bench Press',
'target_sets': 3,
'target_reps': '10',
}
assert '3 sets of 10 reps' in payload['routines'][0]['notes']
assert 'Weights are still TBD' in payload['routines'][0]['notes']
template_names = [template['name'] for template in payload['exercise_templates']]
assert template_names == [
'Resistance Band Crunches',
'Calf Raises',
'Deadlifts',
'Step Ups',
'Leg Extensions',
]
def test_updating_profile_and_logging_weight_computes_bmi(tmp_path: Path) -> None:
@@ -132,11 +156,14 @@ def test_can_create_and_list_exercise_templates(tmp_path: Path) -> None:
list_response = client.get('/api/exercises/templates')
assert list_response.status_code == 200
payload = list_response.json()
assert len(payload) == 1
assert payload[0]['name'] == 'Bench Press'
assert len(payload) == 32
assert any(
item['name'] == 'Bench Press' and item['notes'] == 'Flat bench barbell press.'
for item in payload
)
summary = client.get('/api/dashboard/summary').json()
assert summary['counts']['exercise_templates'] == 1
assert summary['counts']['exercise_templates'] == 32
def test_can_create_routine_before_real_program_arrives(tmp_path: Path) -> None:
@@ -181,11 +208,11 @@ def test_can_create_routine_before_real_program_arrives(tmp_path: Path) -> None:
list_response = client.get('/api/routines')
assert list_response.status_code == 200
payload = list_response.json()
assert len(payload) == 1
assert payload[0]['name'] == 'Push Day Placeholder'
assert len(payload) == 6
assert any(routine['name'] == 'Push Day Placeholder' for routine in payload)
summary = client.get('/api/dashboard/summary').json()
assert summary['counts']['routines'] == 1
assert summary['counts']['routines'] == 6
def test_history_endpoints_return_newest_first(tmp_path: Path) -> None:
@@ -343,7 +370,106 @@ def test_homepage_renders_core_sections_and_forms(tmp_path: Path) -> None:
assert 'Current body metrics' in body
assert 'Log weight' in body
assert 'Add exercise template' in body
assert 'Build routine draft' in body
assert 'Current routine board' in body
assert 'Monday: Chest' in body
def test_existing_state_gets_seeded_routine_backfill(tmp_path: Path) -> None:
state_path = tmp_path / 'state.json'
state_path.write_text(
json.dumps(
{
'users': {
'john': {
'id': 'john',
'display_name': 'John',
'is_stub': False,
'measurement_system': 'imperial',
'height_inches': 68.5,
'goal_weight_lbs': None,
'notes': 'Legacy state',
},
'manndra': {
'id': 'manndra',
'display_name': 'Manndra',
'is_stub': True,
'measurement_system': 'imperial',
'height_inches': None,
'goal_weight_lbs': None,
'notes': 'Legacy stub',
},
},
'exercise_templates': [],
'routines': [],
'weight_entries': [],
'measurement_entries': [],
'workout_sessions': [],
}
)
)
client = make_client(tmp_path)
payload = client.get('/api/dashboard/summary').json()
assert payload['counts']['exercise_templates'] == 31
assert payload['counts']['routines'] == 5
assert payload['routines'][0]['name'] == 'Monday: Chest'
assert payload['routines'][0]['exercises'][0]['target_sets'] == 3
assert payload['routines'][0]['exercises'][0]['target_reps'] == '10'
def test_existing_seeded_routines_upgrade_prescriptions_to_three_by_ten(tmp_path: Path) -> None:
state_path = tmp_path / 'state.json'
state_path.write_text(
json.dumps(
{
'users': {
'john': {
'id': 'john',
'display_name': 'John',
'is_stub': False,
'measurement_system': 'imperial',
'height_inches': 68.5,
'goal_weight_lbs': None,
'notes': 'Legacy state',
},
'manndra': {
'id': 'manndra',
'display_name': 'Manndra',
'is_stub': True,
'measurement_system': 'imperial',
'height_inches': None,
'goal_weight_lbs': None,
'notes': 'Legacy stub',
},
},
'exercise_templates': [],
'routines': [
{
'id': 'seed-routine-01',
'user_id': 'john',
'name': 'Monday: Chest',
'notes': 'Imported from John\'s current routine. Set and rep targets were not provided yet.',
'exercises': [
{'exercise_name': 'Bench Press', 'target_sets': 1, 'target_reps': 'TBD'},
{'exercise_name': 'Incline Bench Press', 'target_sets': 1, 'target_reps': 'TBD'},
],
}
],
'weight_entries': [],
'measurement_entries': [],
'workout_sessions': [],
}
)
)
client = make_client(tmp_path)
payload = client.get('/api/dashboard/summary').json()
monday = next(routine for routine in payload['routines'] if routine['name'] == 'Monday: Chest')
assert monday['exercises'][0]['target_sets'] == 3
assert monday['exercises'][0]['target_reps'] == '10'
assert 'Weights are still TBD' in monday['notes']
def test_weight_form_submission_redirects_and_updates_dashboard(tmp_path: Path) -> None:
@@ -404,8 +530,8 @@ def test_template_and_routine_form_submissions_redirect_and_render_entries(tmp_p
page = client.get('/')
assert page.status_code == 200
assert 'Leg Press' in page.text
assert 'Leg Day Draft' in page.text
routines = client.get('/api/routines').json()
assert routines[0]['exercises'][0]['exercise_name'] == 'Leg Press'
assert routines[0]['exercises'][1]['notes'] == 'Slow negative'
saved_routine = next(routine for routine in routines if routine['name'] == 'Leg Day Draft')
assert saved_routine['exercises'][0]['exercise_name'] == 'Leg Press'
assert saved_routine['exercises'][1]['notes'] == 'Slow negative'