Phase 23: season history + division zone data + new route
CI / Build, lint & test (push) Failing after 1m19s

- migrations/0011_season_history.sql: persist one row per completed season
- models/season.rs: SeasonHistoryEntry struct; public SEASON_LENGTH /
  PROMOTION_PTS / RELEGATION_PTS consts; pts_above_safe, can_be_relegated,
  promotion_achievable helpers
- services/season.rs: write history entry on season rollover; get_history()
  returns last 20 seasons newest-first
- routes/division.rs: GET /division now includes promotion_pts, relegation_pts,
  season_length, pts_above_safe, promotion_achievable, can_be_relegated;
  new GET /division/history endpoint
- 3 new integration tests: history empty, history records after promotion,
  division response has zone fields

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
funman300
2026-06-25 18:38:02 -07:00
parent c458b8cdbd
commit 28d7490555
6 changed files with 373 additions and 4 deletions
+51
View File
@@ -1738,3 +1738,54 @@ async fn test_auth_reset_allows_new_profile() {
assert_eq!(status, StatusCode::OK, "{json}");
assert_eq!(json["profile"]["username"], "NewProfile");
}
#[tokio::test]
async fn test_division_history_empty_initially() {
let app = build_test_app().await;
auth(&app, "HistoryZero").await;
let (status, json) = json_get(&app, "/division/history").await;
assert_eq!(status, StatusCode::OK, "{json}");
assert!(json["history"].is_array());
assert_eq!(json["history"].as_array().unwrap().len(), 0);
assert_eq!(json["total"], 0);
}
#[tokio::test]
async fn test_division_history_records_after_season_end() {
let app = build_test_app().await;
auth(&app, "HistoryRecorder").await;
// Win all 10 matches to complete and promote
for _ in 0..10 {
json_post(&app, "/matches/result", serde_json::json!({
"squad_id": "dummy", "opponent_name": "Bot",
"goals_for": 3, "goals_against": 0, "mode": "squad_battles"
})).await;
}
let (status, json) = json_get(&app, "/division/history").await;
assert_eq!(status, StatusCode::OK, "{json}");
let history = json["history"].as_array().unwrap();
assert_eq!(history.len(), 1, "one completed season");
assert_eq!(history[0]["result"], "promoted");
assert_eq!(history[0]["division"], 5);
assert_eq!(history[0]["new_division"], 4);
assert_eq!(history[0]["season_number"], 1);
}
#[tokio::test]
async fn test_division_response_has_zone_fields() {
let app = build_test_app().await;
auth(&app, "ZoneChecker").await;
let (status, json) = json_get(&app, "/division").await;
assert_eq!(status, StatusCode::OK, "{json}");
assert!(json["promotion_pts"].is_number());
assert!(json["relegation_pts"].is_number());
assert!(json["season_length"].is_number());
assert!(json["pts_above_safe"].is_number());
assert_eq!(json["promotion_pts"], 21);
assert_eq!(json["relegation_pts"], 3);
assert_eq!(json["season_length"], 10);
}