package httpapi_test import ( "net/http" "testing" ) // 个人榜的单位展示字段必须取全量单位表:停用但有积分的单位也要显示名称与简称。 func TestAthleteStandingsUsesFullTeamTable(t *testing.T) { env := newTestEnv(t) ids := env.seed(t) env.createUser("recorder", "recorder-pass", "recorder") client, _ := env.client() env.login(client, "recorder", "recorder-pass") env.do(client, http.MethodPut, "/api/results/draft", map[string]any{ "eventId": ids.event, "results": []map[string]any{ {"entryId": ids.entryA, "resultValue": 11.58, "unit": "s", "status": "ok"}, {"entryId": ids.entryB, "resultValue": 11.92, "unit": "s", "status": "ok"}, }, }, true) if status, env2 := env.do(client, http.MethodPost, "/api/results/publish", map[string]any{ "eventId": ids.event, }, true); status != http.StatusOK { t.Fatalf("发布应 200,得到 %d %+v", status, env2.Error) } env.exec(t, `UPDATE teams SET active = 0 WHERE id = ?`, ids.teamB) _, env2 := env.do(client, http.MethodGet, "/api/standings/athletes", nil, false) rows := decodeData[[]map[string]any](t, env2) seen := map[int64]map[string]any{} for _, row := range rows { seen[int64(row["athleteId"].(float64))] = row } active := seen[ids.athleteA] if active == nil || active["teamName"] != "第一分公司" || active["shortName"] != "一司" { t.Fatalf("在职单位的个人行应带单位名与简称: %+v", active) } stopped := seen[ids.athB] if stopped == nil { t.Fatalf("停用单位的运动员仍应在个人榜上: %+v", rows) } if stopped["teamName"] != "第二分公司" || stopped["shortName"] != "二司" { t.Fatalf("停用单位的个人行应补齐单位名与简称,得到 %+v", stopped) } }