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:
@@ -398,4 +398,54 @@ func TestServiceWithoutStore(t *testing.T) {
|
||||
if err == nil {
|
||||
t.Fatal("expected error when store is nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTrackCalendar(t *testing.T) {
|
||||
s, _ := loadSeeds()
|
||||
defer s.Stop()
|
||||
ctx := context.Background()
|
||||
|
||||
// 1. Initially calendar should be empty
|
||||
entries, err := s.GetTrackCalendar(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("get calendar: %v", err)
|
||||
}
|
||||
if len(entries) != 0 {
|
||||
t.Errorf("expected 0 entries, got %d", len(entries))
|
||||
}
|
||||
|
||||
// 2. Schedule a track
|
||||
start := time.Now().Add(-1 * time.Hour)
|
||||
end := time.Now().Add(1 * time.Hour)
|
||||
created, err := s.CreateTrackCalendar(ctx, "monaco", start, end)
|
||||
if err != nil {
|
||||
t.Fatalf("create calendar: %v", err)
|
||||
}
|
||||
if created.TrackID != "monaco" || !created.StartAt.Equal(start) || !created.EndAt.Equal(end) {
|
||||
t.Errorf("invalid created entry: %+v", created)
|
||||
}
|
||||
|
||||
// 3. Get calendar should return the entry
|
||||
entries, err = s.GetTrackCalendar(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("get calendar: %v", err)
|
||||
}
|
||||
if len(entries) != 1 || entries[0].ID != created.ID {
|
||||
t.Errorf("expected 1 entry with id %d, got %v", created.ID, entries)
|
||||
}
|
||||
|
||||
// 4. Delete entry
|
||||
err = s.DeleteTrackCalendar(ctx, created.ID)
|
||||
if err != nil {
|
||||
t.Fatalf("delete calendar: %v", err)
|
||||
}
|
||||
|
||||
// 5. Get calendar should be empty again
|
||||
entries, err = s.GetTrackCalendar(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("get calendar: %v", err)
|
||||
}
|
||||
if len(entries) != 0 {
|
||||
t.Errorf("expected 0 entries, got %d", len(entries))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user