mirror of
https://github.com/IS1DI/x0gp.git
synced 2026-07-16 20:47:55 +00:00
Add leaderboard for all tracks and track calendar
This commit is contained in:
@@ -259,4 +259,52 @@ func TestLeaderboard(t *testing.T) {
|
||||
t.Errorf("expected Driver One, DRV, TST, got %+v", entry)
|
||||
}
|
||||
})
|
||||
|
||||
// Test Calendar Leaderboard
|
||||
t.Run("Calendar Leaderboard", func(t *testing.T) {
|
||||
_, _ = pool.Exec(ctx, "DELETE FROM track_calendar")
|
||||
|
||||
now := time.Now()
|
||||
_, err = pool.Exec(ctx, `
|
||||
INSERT INTO track_calendar (track_id, start_at, end_at) VALUES
|
||||
('monaco', $1, $2),
|
||||
('barcelona-catalunya', $3, $4),
|
||||
('austria-redbull-ring', $5, $6)
|
||||
`,
|
||||
now.Add(-10*time.Hour), now.Add(-5*time.Hour),
|
||||
now.Add(-2*time.Hour), now.Add(2*time.Hour),
|
||||
now.Add(5*time.Hour), now.Add(10*time.Hour),
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to insert track calendar: %v", err)
|
||||
}
|
||||
defer func() {
|
||||
_, _ = pool.Exec(ctx, "DELETE FROM track_calendar")
|
||||
}()
|
||||
|
||||
svc := NewService(store, nil)
|
||||
svc.now = func() time.Time { return now }
|
||||
|
||||
res, err := svc.GetCalendarLeaderboard(ctx, currentYear, "test-driver-1")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to get calendar leaderboard: %v", err)
|
||||
}
|
||||
|
||||
if len(res) != 3 {
|
||||
t.Fatalf("expected 3 calendar entries, got %d", len(res))
|
||||
}
|
||||
|
||||
// 1. Monaco (finished)
|
||||
if res[0].TrackID != "monaco" || res[0].Status != "finished" {
|
||||
t.Errorf("expected monaco (finished), got %s (%s)", res[0].TrackID, res[0].Status)
|
||||
}
|
||||
// 2. Barcelona (active)
|
||||
if res[1].TrackID != "barcelona-catalunya" || res[1].Status != "active" {
|
||||
t.Errorf("expected barcelona-catalunya (active), got %s (%s)", res[1].TrackID, res[1].Status)
|
||||
}
|
||||
// 3. Austria (planned)
|
||||
if res[2].TrackID != "austria-redbull-ring" || res[2].Status != "planned" {
|
||||
t.Errorf("expected austria-redbull-ring (planned), got %s (%s)", res[2].TrackID, res[2].Status)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user