from app.models.habit import ALL_WEEKDAYS_MASK, HabitType from app.schemas.habit import HabitCreate from app.services import habit_service def _make_habit(db_session, user_id, name="아침 운동"): data = HabitCreate(name=name, habit_type=HabitType.BUILD, weekdays_mask=ALL_WEEKDAYS_MASK) return habit_service.create_habit(db_session, user_id, data) def test_today_page_redirects_to_login_when_not_authenticated(client): response = client.get("/today", follow_redirects=False) assert response.status_code == 303 assert response.headers["location"] == "/login" def test_today_page_shows_created_habit(auth_client, db_session, test_user): _make_habit(db_session, test_user.id, name="아침 운동") response = auth_client.get("/today") assert response.status_code == 200 assert "아침 운동" in response.text def test_toggle_today_page_updates_checked_state(auth_client, db_session, test_user): habit = _make_habit(db_session, test_user.id, name="아침 운동") response = auth_client.post(f"/today/{habit.id}/toggle") assert response.status_code == 200 # 서버가 실제로 로그를 남겼는지 today API로 재확인 today_items = auth_client.get("/api/today").json() assert today_items[0]["checked"] is True def test_toggle_today_page_for_other_users_habit_returns_404(auth_client, db_session, other_user): others_habit = _make_habit(db_session, other_user.id, name="남의 습관") response = auth_client.post(f"/today/{others_habit.id}/toggle") assert response.status_code == 404