test: Add statistics test with manual data insertion

- TestStatisticsEndpoints: tests /api/v1/statistics/summary endpoint
- TestPartialMigrationThenSyncThenComplete: tests migration + sync workflow
- insertTestData: helper to insert 5 soundtracks with 8 songs
- getTestToken: helper to get auth token for tests
- Updated other test files to use FindAllSoundtracks instead of FindAllGames

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
2026-06-01 20:43:40 +02:00
parent 90d621c195
commit d459d796cf
3 changed files with 185 additions and 11 deletions
+10 -10
View File
@@ -76,7 +76,7 @@ func TestSyncPopulatesDatabase(t *testing.T) {
// Before sync - should have no games
repo := repository.New(backend.BackendPool())
gamesBefore, err := repo.FindAllGames(backend.BackendCtx())
gamesBefore, err := repo.FindAllSoundtracks(backend.BackendCtx())
assert.NoError(t, err)
beforeCount := len(gamesBefore)
t.Logf("Games before sync: %d", beforeCount)
@@ -92,7 +92,7 @@ func TestSyncPopulatesDatabase(t *testing.T) {
}
// After sync - should have games
gamesAfter, err := repo.FindAllGames(backend.BackendCtx())
gamesAfter, err := repo.FindAllSoundtracks(backend.BackendCtx())
assert.NoError(t, err)
afterCount := len(gamesAfter)
t.Logf("Games after sync: %d", afterCount)
@@ -113,7 +113,7 @@ func TestSyncMakesDifference(t *testing.T) {
// Before sync - should have no games
repo := repository.New(backend.BackendPool())
gamesBefore, err := repo.FindAllGames(backend.BackendCtx())
gamesBefore, err := repo.FindAllSoundtracks(backend.BackendCtx())
assert.NoError(t, err)
assert.Equal(t, 0, len(gamesBefore), "Should have no games before sync")
@@ -127,7 +127,7 @@ func TestSyncMakesDifference(t *testing.T) {
}
// After sync - should have games
gamesAfter, err := repo.FindAllGames(backend.BackendCtx())
gamesAfter, err := repo.FindAllSoundtracks(backend.BackendCtx())
assert.NoError(t, err)
assert.True(t, len(gamesAfter) > 0, "Should have games after sync")
}
@@ -200,7 +200,7 @@ func TestSyncGamesNewOnlyChanges(t *testing.T) {
// Get initial count
repo := repository.New(backend.BackendPool())
gamesBefore, _ := repo.FindAllGames(backend.BackendCtx())
gamesBefore, _ := repo.FindAllSoundtracks(backend.BackendCtx())
beforeCount := len(gamesBefore)
// Run incremental sync (should not change count if nothing changed)
@@ -211,7 +211,7 @@ func TestSyncGamesNewOnlyChanges(t *testing.T) {
time.Sleep(2 * time.Second)
// Count should be the same
gamesAfter, _ := repo.FindAllGames(backend.BackendCtx())
gamesAfter, _ := repo.FindAllSoundtracks(backend.BackendCtx())
afterCount := len(gamesAfter)
// Note: This might not be exactly equal due to timing, but should be close
@@ -228,7 +228,7 @@ func TestResetGames(t *testing.T) {
// First ensure we have data
repo := repository.New(backend.BackendPool())
gamesBefore, _ := repo.FindAllGames(backend.BackendCtx())
gamesBefore, _ := repo.FindAllSoundtracks(backend.BackendCtx())
beforeCount := len(gamesBefore)
if beforeCount == 0 {
@@ -238,7 +238,7 @@ func TestResetGames(t *testing.T) {
t.Error("Sync did not complete within timeout")
return
}
gamesBefore, _ = repo.FindAllGames(backend.BackendCtx())
gamesBefore, _ = repo.FindAllSoundtracks(backend.BackendCtx())
beforeCount = len(gamesBefore)
}
@@ -253,7 +253,7 @@ func TestResetGames(t *testing.T) {
// Note: reset might take a moment to propagate
time.Sleep(1 * time.Second)
gamesAfter, _ := repo.FindAllGames(backend.BackendCtx())
gamesAfter, _ := repo.FindAllSoundtracks(backend.BackendCtx())
afterCount := len(gamesAfter)
t.Logf("Games after reset: %d", afterCount)
@@ -282,7 +282,7 @@ func TestSyncGamesNewFull(t *testing.T) {
// Verify database is populated
repo := repository.New(backend.BackendPool())
games, err := repo.FindAllGames(backend.BackendCtx())
games, err := repo.FindAllSoundtracks(backend.BackendCtx())
assert.NoError(t, err)
assert.True(t, len(games) > 0, "Database should be populated after full sync")
t.Logf("Full sync populated %d games", len(games))