#9 Changed the term game to soundtrack everywhere
Build / build (push) Successful in 45s

This commit is contained in:
2026-06-29 18:39:09 +02:00
parent dbef39b828
commit a8df738108
20 changed files with 708 additions and 682 deletions
+3 -3
View File
@@ -231,7 +231,7 @@ func (m *MusicHandler) GetPreviousSong(ctx *echo.Context) error {
// GetAllSoundtracks godoc
// @Summary Get all soundtracks
// @Description Returns a list of all games in order
// @Description Returns a list of all soundtracks in order
// @Tags music
// @Accept json
// @Produce json
@@ -249,7 +249,7 @@ func (m *MusicHandler) GetAllSoundtracks(ctx *echo.Context) error {
// GetAllSoundtracksRandom godoc
// @Summary Get all soundtracks random
// @Description Returns a list of all games in random order
// @Description Returns a list of all soundtracks in random order
// @Tags music
// @Accept json
// @Produce json
@@ -285,7 +285,7 @@ func (m *MusicHandler) PutPlayed(ctx *echo.Context) error {
if err != nil {
return ctx.JSON(http.StatusBadRequest, err.Error())
}
logging.GetLogger().Info("Marking song as played", zap.Int("song_id", song))
logging.GetLogger().Info("Marking song as played", zap.Int("song_id", song))
backend.SetPlayed(song)
return ctx.NoContent(http.StatusOK)
}
+11 -11
View File
@@ -51,7 +51,7 @@ func (s *Server) RegisterRoutes() http.Handler {
e.GET("/assets/*", echo.WrapHandler(fileServer))
e.GET("/search", echo.WrapHandler(templ.Handler(web.HelloForm())))
e.POST("/find", echo.WrapHandler(http.HandlerFunc(web.FindGameWebHandler)))
e.POST("/find", echo.WrapHandler(http.HandlerFunc(web.FindSoundtrackWebHandler)))
e.Static("/", "/frontend")
@@ -136,20 +136,20 @@ func (s *Server) RegisterRoutes() http.Handler {
// Statistics API endpoints (protected by token auth)
statistics := s.statisticsHandler
protectedV1.GET("/statistics/games/most-played", func(c *echo.Context) error {
return statistics.GetMostPlayedGames(c)
protectedV1.GET("/statistics/soundtracks/most-played", func(c *echo.Context) error {
return statistics.GetMostPlayedSoundtracks(c)
})
protectedV1.GET("/statistics/games/least-played", func(c *echo.Context) error {
return statistics.GetLeastPlayedGames(c)
protectedV1.GET("/statistics/soundtracks/least-played", func(c *echo.Context) error {
return statistics.GetLeastPlayedSoundtracks(c)
})
protectedV1.GET("/statistics/games/never-played", func(c *echo.Context) error {
return statistics.GetNeverPlayedGames(c)
protectedV1.GET("/statistics/soundtracks/never-played", func(c *echo.Context) error {
return statistics.GetNeverPlayedSoundtracks(c)
})
protectedV1.GET("/statistics/games/last-played", func(c *echo.Context) error {
return statistics.GetLastPlayedGames(c)
protectedV1.GET("/statistics/soundtracks/last-played", func(c *echo.Context) error {
return statistics.GetLastPlayedSoundtracks(c)
})
protectedV1.GET("/statistics/games/oldest-played", func(c *echo.Context) error {
return statistics.GetOldestPlayedGames(c)
protectedV1.GET("/statistics/soundtracks/oldest-played", func(c *echo.Context) error {
return statistics.GetOldestPlayedSoundtracks(c)
})
protectedV1.GET("/statistics/songs/most-played", func(c *echo.Context) error {
return statistics.GetMostPlayedSongs(c)
+62 -62
View File
@@ -23,20 +23,20 @@ func NewStatisticsHandler() *StatisticsHandler {
}
}
// GetMostPlayedGames returns top N most played games with songs
// GET /api/v1/statistics/games/most-played
// GetMostPlayedSoundtracks returns top N most played soundtracks with songs
// GET /api/v1/statistics/soundtracks/most-played
//
// @Summary Get most played games
// @Description Returns the top N most played games with their songs
// @Summary Get most played soundtracks
// @Description Returns the top N most played soundtracks with their songs
// @Tags statistics
// @Accept json
// @Produce json
// @Param limit query int false "Number of results (default: 10)"
// @Success 200 {array} backend.GameWithSongs
// @Success 200 {array} backend.SoundtrackWithSongs
// @Failure 400 {object} map[string]string
// @Failure 500 {object} map[string]string
// @Router /api/v1/statistics/games/most-played [get]
func (h *StatisticsHandler) GetMostPlayedGames(ctx *echo.Context) error {
// @Router /api/v1/statistics/soundtracks/most-played [get]
func (h *StatisticsHandler) GetMostPlayedSoundtracks(ctx *echo.Context) error {
limit := 10 // default
limitStr := ctx.QueryParam("limit")
if limitStr != "" {
@@ -50,29 +50,29 @@ func (h *StatisticsHandler) GetMostPlayedGames(ctx *echo.Context) error {
limit = 100
}
}
games, err := h.statsBackend.GetMostPlayedGamesWithSongs(int32(limit))
soundtracks, err := h.statsBackend.GetMostPlayedSoundtracksWithSongs(int32(limit))
if err != nil {
logging.GetLogger().Error("Failed to get most played games", zap.String("error", err.Error()))
logging.GetLogger().Error("Failed to get most played soundtracks", zap.String("error", err.Error()))
return ctx.JSON(http.StatusInternalServerError, map[string]string{"error": "Failed to get statistics"})
}
return ctx.JSON(http.StatusOK, games)
return ctx.JSON(http.StatusOK, soundtracks)
}
// GetLeastPlayedGames returns top N least played games with songs
// GET /api/v1/statistics/games/least-played
// GetLeastPlayedSoundtracks returns top N least played soundtracks with songs
// GET /api/v1/statistics/soundtracks/least-played
//
// @Summary Get least played games
// @Description Returns the top N least played games with their songs
// @Summary Get least played soundtracks
// @Description Returns the top N least played soundtracks with their songs
// @Tags statistics
// @Accept json
// @Produce json
// @Param limit query int false "Number of results (default: 10)"
// @Success 200 {array} backend.GameWithSongs
// @Success 200 {array} backend.SoundtrackWithSongs
// @Failure 400 {object} map[string]string
// @Failure 500 {object} map[string]string
// @Router /api/v1/statistics/games/least-played [get]
func (h *StatisticsHandler) GetLeastPlayedGames(ctx *echo.Context) error {
// @Router /api/v1/statistics/soundtracks/least-played [get]
func (h *StatisticsHandler) GetLeastPlayedSoundtracks(ctx *echo.Context) error {
limit := 10
limitStr := ctx.QueryParam("limit")
if limitStr != "" {
@@ -85,20 +85,20 @@ func (h *StatisticsHandler) GetLeastPlayedGames(ctx *echo.Context) error {
limit = 100
}
}
games, err := h.statsBackend.GetLeastPlayedGamesWithSongs(int32(limit))
soundtracks, err := h.statsBackend.GetLeastPlayedSoundtracksWithSongs(int32(limit))
if err != nil {
logging.GetLogger().Error("Failed to get least played games", zap.String("error", err.Error()))
logging.GetLogger().Error("Failed to get least played soundtracks", zap.String("error", err.Error()))
return ctx.JSON(http.StatusInternalServerError, map[string]string{"error": "Failed to get statistics"})
}
return ctx.JSON(http.StatusOK, games)
return ctx.JSON(http.StatusOK, soundtracks)
}
// GetMostPlayedSongs returns top N most played songs with game info
// GetMostPlayedSongs returns top N most played songs with soundtrack info
// GET /api/v1/statistics/songs/most-played
//
// @Summary Get most played songs
// @Description Returns the top N most played songs with their game info
// @Description Returns the top N most played songs with their soundtrack info
// @Tags statistics
// @Accept json
// @Produce json
@@ -120,8 +120,8 @@ func (h *StatisticsHandler) GetMostPlayedSongs(ctx *echo.Context) error {
limit = 100
}
}
songs, err := h.statsBackend.GetMostPlayedSongsWithGame(int32(limit))
songs, err := h.statsBackend.GetMostPlayedSongsWithSoundtrack(int32(limit))
if err != nil {
logging.GetLogger().Error("Failed to get most played songs", zap.String("error", err.Error()))
return ctx.JSON(http.StatusInternalServerError, map[string]string{"error": "Failed to get statistics"})
@@ -129,11 +129,11 @@ func (h *StatisticsHandler) GetMostPlayedSongs(ctx *echo.Context) error {
return ctx.JSON(http.StatusOK, songs)
}
// GetLeastPlayedSongs returns top N least played songs with game info
// GetLeastPlayedSongs returns top N least played songs with soundtrack info
// GET /api/v1/statistics/songs/least-played
//
// @Summary Get least played songs
// @Description Returns the top N least played songs with their game info
// @Description Returns the top N least played songs with their soundtrack info
// @Tags statistics
// @Accept json
// @Produce json
@@ -155,8 +155,8 @@ func (h *StatisticsHandler) GetLeastPlayedSongs(ctx *echo.Context) error {
limit = 100
}
}
songs, err := h.statsBackend.GetLeastPlayedSongsWithGame(int32(limit))
songs, err := h.statsBackend.GetLeastPlayedSongsWithSoundtrack(int32(limit))
if err != nil {
logging.GetLogger().Error("Failed to get least played songs", zap.String("error", err.Error()))
return ctx.JSON(http.StatusInternalServerError, map[string]string{"error": "Failed to get statistics"})
@@ -164,40 +164,40 @@ func (h *StatisticsHandler) GetLeastPlayedSongs(ctx *echo.Context) error {
return ctx.JSON(http.StatusOK, songs)
}
// GetNeverPlayedGames returns games that have never been played
// GET /api/v1/statistics/games/never-played
// GetNeverPlayedSoundtracks returns soundtracks that have never been played
// GET /api/v1/statistics/soundtracks/never-played
//
// @Summary Get never played games
// @Description Returns all games that have never been played (times_played = 0)
// @Summary Get never played soundtracks
// @Description Returns all soundtracks that have never been played (times_played = 0)
// @Tags statistics
// @Accept json
// @Produce json
// @Success 200 {array} backend.GameWithSongs
// @Success 200 {array} backend.SoundtrackWithSongs
// @Failure 500 {object} map[string]string
// @Router /api/v1/statistics/games/never-played [get]
func (h *StatisticsHandler) GetNeverPlayedGames(ctx *echo.Context) error {
games, err := h.statsBackend.GetNeverPlayedGames()
// @Router /api/v1/statistics/soundtracks/never-played [get]
func (h *StatisticsHandler) GetNeverPlayedSoundtracks(ctx *echo.Context) error {
soundtracks, err := h.statsBackend.GetNeverPlayedSoundtracks()
if err != nil {
logging.GetLogger().Error("Failed to get never played games", zap.String("error", err.Error()))
logging.GetLogger().Error("Failed to get never played soundtracks", zap.String("error", err.Error()))
return ctx.JSON(http.StatusInternalServerError, map[string]string{"error": "Failed to get statistics"})
}
return ctx.JSON(http.StatusOK, games)
return ctx.JSON(http.StatusOK, soundtracks)
}
// GetLastPlayedGames returns most recently played games
// GET /api/v1/statistics/games/last-played
// GetLastPlayedSoundtracks returns most recently played soundtracks
// GET /api/v1/statistics/soundtracks/last-played
//
// @Summary Get last played games
// @Description Returns the most recently played games
// @Summary Get last played soundtracks
// @Description Returns the most recently played soundtracks
// @Tags statistics
// @Accept json
// @Produce json
// @Param limit query int false "Number of results (default: 10)"
// @Success 200 {array} backend.GameWithSongs
// @Success 200 {array} backend.SoundtrackWithSongs
// @Failure 400 {object} map[string]string
// @Failure 500 {object} map[string]string
// @Router /api/v1/statistics/games/last-played [get]
func (h *StatisticsHandler) GetLastPlayedGames(ctx *echo.Context) error {
// @Router /api/v1/statistics/soundtracks/last-played [get]
func (h *StatisticsHandler) GetLastPlayedSoundtracks(ctx *echo.Context) error {
limit := 10
limitStr := ctx.QueryParam("limit")
if limitStr != "" {
@@ -210,29 +210,29 @@ func (h *StatisticsHandler) GetLastPlayedGames(ctx *echo.Context) error {
limit = 100
}
}
games, err := h.statsBackend.GetLastPlayedGames(int32(limit))
soundtracks, err := h.statsBackend.GetLastPlayedSoundtracks(int32(limit))
if err != nil {
logging.GetLogger().Error("Failed to get last played games", zap.String("error", err.Error()))
logging.GetLogger().Error("Failed to get last played soundtracks", zap.String("error", err.Error()))
return ctx.JSON(http.StatusInternalServerError, map[string]string{"error": "Failed to get statistics"})
}
return ctx.JSON(http.StatusOK, games)
return ctx.JSON(http.StatusOK, soundtracks)
}
// GetOldestPlayedGames returns least recently played games
// GET /api/v1/statistics/games/oldest-played
// GetOldestPlayedSoundtracks returns least recently played soundtracks
// GET /api/v1/statistics/soundtracks/oldest-played
//
// @Summary Get oldest played games
// @Description Returns the least recently played games (that have been played at least once)
// @Summary Get oldest played soundtracks
// @Description Returns the least recently played soundtracks (that have been played at least once)
// @Tags statistics
// @Accept json
// @Produce json
// @Param limit query int false "Number of results (default: 10)"
// @Success 200 {array} backend.GameWithSongs
// @Success 200 {array} backend.SoundtrackWithSongs
// @Failure 400 {object} map[string]string
// @Failure 500 {object} map[string]string
// @Router /api/v1/statistics/games/oldest-played [get]
func (h *StatisticsHandler) GetOldestPlayedGames(ctx *echo.Context) error {
// @Router /api/v1/statistics/soundtracks/oldest-played [get]
func (h *StatisticsHandler) GetOldestPlayedSoundtracks(ctx *echo.Context) error {
limit := 10
limitStr := ctx.QueryParam("limit")
if limitStr != "" {
@@ -245,13 +245,13 @@ func (h *StatisticsHandler) GetOldestPlayedGames(ctx *echo.Context) error {
limit = 100
}
}
games, err := h.statsBackend.GetOldestPlayedGames(int32(limit))
soundtracks, err := h.statsBackend.GetOldestPlayedSoundtracks(int32(limit))
if err != nil {
logging.GetLogger().Error("Failed to get oldest played games", zap.String("error", err.Error()))
logging.GetLogger().Error("Failed to get oldest played soundtracks", zap.String("error", err.Error()))
return ctx.JSON(http.StatusInternalServerError, map[string]string{"error": "Failed to get statistics"})
}
return ctx.JSON(http.StatusOK, games)
return ctx.JSON(http.StatusOK, soundtracks)
}
// GetStatisticsSummary returns overall statistics
+2 -2
View File
@@ -91,8 +91,8 @@ func TestPartialMigrationThenSyncThenComplete(t *testing.T) {
require.NoError(t, err)
// After sync with /sync/new, only soundtracks matching filesystem remain
// testMusic has 3 games
require.Equal(t, int64(3), summary.TotalGames)
// testMusic has 3 soundtracks
require.Equal(t, int64(3), summary.TotalSoundtracks)
}
// insertTestData inserts 5 test soundtracks with songs into the database
+4 -4
View File
@@ -36,7 +36,7 @@ func (s *SyncHandler) SyncProgress(ctx *echo.Context) error {
// SyncSoundtracksNewOnlyChanges godoc
// @Summary Sync soundtracks with only changes
// @Description Starts syncing games with only new changes
// @Description Starts syncing soundtracks with only new changes
// @Tags sync
// @Accept json
// @Produce json
@@ -55,8 +55,8 @@ func (s *SyncHandler) SyncSoundtracksNewOnlyChanges(ctx *echo.Context) error {
}
// SyncSoundtracksNewFull godoc
// @Summary Sync all games fully
// @Description Starts a full sync of all games
// @Summary Sync all soundtracks fully
// @Description Starts a full sync of all soundtracks
// @Tags sync
// @Accept json
// @Produce json
@@ -76,7 +76,7 @@ func (s *SyncHandler) SyncSoundtracksNewFull(ctx *echo.Context) error {
// ResetDB godoc
// @Summary Reset soundtracks database
// @Description Resets the games database by deleting all games and songs
// @Description Resets the soundtracks database by deleting all soundtracks and songs
// @Tags sync
// @Accept json
// @Produce json
+42 -42
View File
@@ -28,7 +28,7 @@ func waitForSyncCompletion(t *testing.T, e *echo.Echo, maxAttempts int) bool {
if err == nil && progress.Progress != "" {
// Successfully parsed as ProgressResponse with non-empty progress
t.Logf("Sync progress: %s%%", progress.Progress)
if progress.Progress == "100" {
if progress.Progress == "100" {
t.Log("Sync completed!")
// Wait for Syncing flag to be updated
for j := 0; j < 50; j++ {
@@ -61,7 +61,7 @@ func waitForSyncCompletion(t *testing.T, e *echo.Echo, maxAttempts int) bool {
return false
}
// TestSyncPopulatesDatabase verifies that sync populates the database with games
// TestSyncPopulatesDatabase verifies that sync populates the database with soundtracks
func TestSyncPopulatesDatabase(t *testing.T) {
db.TestSetupDB(t)
defer db.TestTearDownDB(t)
@@ -74,12 +74,12 @@ func TestSyncPopulatesDatabase(t *testing.T) {
// Clear any existing data first
db.TestClearDatabase(t)
// Before sync - should have no games
// Before sync - should have no soundtracks
repo := repository.New(backend.BackendPool())
gamesBefore, err := repo.FindAllSoundtracks(backend.BackendCtx())
soundtracksBefore, err := repo.FindAllSoundtracks(backend.BackendCtx())
assert.NoError(t, err)
beforeCount := len(gamesBefore)
t.Logf("Games before sync: %d", beforeCount)
beforeCount := len(soundtracksBefore)
t.Logf("Soundtracks before sync: %d", beforeCount)
assert.Equal(t, 0, beforeCount, "Database should be empty after clear")
// Run sync
@@ -91,14 +91,14 @@ func TestSyncPopulatesDatabase(t *testing.T) {
t.Error("Sync did not complete within timeout")
}
// After sync - should have games
gamesAfter, err := repo.FindAllSoundtracks(backend.BackendCtx())
// After sync - should have soundtracks
soundtracksAfter, err := repo.FindAllSoundtracks(backend.BackendCtx())
assert.NoError(t, err)
afterCount := len(gamesAfter)
t.Logf("Games after sync: %d", afterCount)
afterCount := len(soundtracksAfter)
t.Logf("Soundtracks after sync: %d", afterCount)
// Should have more games than before (unless database was already populated)
assert.True(t, afterCount > 0, "Database should have games after sync")
// Should have more soundtracks than before (unless database was already populated)
assert.True(t, afterCount > 0, "Database should have soundtracks after sync")
}
// TestSyncMakesDifference verifies that sync actually changes the database state
@@ -111,11 +111,11 @@ func TestSyncMakesDifference(t *testing.T) {
// Clear any existing data first
db.TestClearDatabase(t)
// Before sync - should have no games
// Before sync - should have no soundtracks
repo := repository.New(backend.BackendPool())
gamesBefore, err := repo.FindAllSoundtracks(backend.BackendCtx())
soundtracksBefore, err := repo.FindAllSoundtracks(backend.BackendCtx())
assert.NoError(t, err)
assert.Equal(t, 0, len(gamesBefore), "Should have no games before sync")
assert.Equal(t, 0, len(soundtracksBefore), "Should have no soundtracks before sync")
// Run sync
resp := MakeTestRequest(t, e, "GET", "/sync/full")
@@ -126,10 +126,10 @@ func TestSyncMakesDifference(t *testing.T) {
t.Error("Sync did not complete within timeout")
}
// After sync - should have games
gamesAfter, err := repo.FindAllSoundtracks(backend.BackendCtx())
// After sync - should have soundtracks
soundtracksAfter, err := repo.FindAllSoundtracks(backend.BackendCtx())
assert.NoError(t, err)
assert.True(t, len(gamesAfter) > 0, "Should have games after sync")
assert.True(t, len(soundtracksAfter) > 0, "Should have soundtracks after sync")
}
// TestSyncProgress verifies the sync progress endpoint
@@ -183,8 +183,8 @@ func TestSyncProgress(t *testing.T) {
assert.True(t, foundComplete, "Should have seen completion")
}
// TestSyncGamesNewOnlyChanges verifies the incremental sync endpoint
func TestSyncGamesNewOnlyChanges(t *testing.T) {
// TestSyncSoundtracksNewOnlyChanges verifies the incremental sync endpoint
func TestSyncSoundtracksNewOnlyChanges(t *testing.T) {
db.TestSetupDB(t)
defer db.TestTearDownDB(t)
@@ -200,8 +200,8 @@ func TestSyncGamesNewOnlyChanges(t *testing.T) {
// Get initial count
repo := repository.New(backend.BackendPool())
gamesBefore, _ := repo.FindAllSoundtracks(backend.BackendCtx())
beforeCount := len(gamesBefore)
soundtracksBefore, _ := repo.FindAllSoundtracks(backend.BackendCtx())
beforeCount := len(soundtracksBefore)
// Run incremental sync (should not change count if nothing changed)
resp := MakeTestRequest(t, e, "GET", "/sync/new")
@@ -211,16 +211,16 @@ func TestSyncGamesNewOnlyChanges(t *testing.T) {
time.Sleep(2 * time.Second)
// Count should be the same
gamesAfter, _ := repo.FindAllSoundtracks(backend.BackendCtx())
afterCount := len(gamesAfter)
soundtracksAfter, _ := repo.FindAllSoundtracks(backend.BackendCtx())
afterCount := len(soundtracksAfter)
// Note: This might not be exactly equal due to timing, but should be close
t.Logf("Games before incremental sync: %d, after: %d", beforeCount, afterCount)
t.Logf("Soundtracks before incremental sync: %d, after: %d", beforeCount, afterCount)
}
// TestResetGames verifies the reset endpoint clears the database
// TestResetSoundtracks verifies the reset endpoint clears the database
// RUN THIS LAST
func TestResetGames(t *testing.T) {
func TestResetSoundtracks(t *testing.T) {
db.TestSetupDB(t)
defer db.TestTearDownDB(t)
@@ -228,8 +228,8 @@ func TestResetGames(t *testing.T) {
// First ensure we have data
repo := repository.New(backend.BackendPool())
gamesBefore, _ := repo.FindAllSoundtracks(backend.BackendCtx())
beforeCount := len(gamesBefore)
soundtracksBefore, _ := repo.FindAllSoundtracks(backend.BackendCtx())
beforeCount := len(soundtracksBefore)
if beforeCount == 0 {
// Run sync to populate
@@ -238,12 +238,12 @@ func TestResetGames(t *testing.T) {
t.Error("Sync did not complete within timeout")
return
}
gamesBefore, _ = repo.FindAllSoundtracks(backend.BackendCtx())
beforeCount = len(gamesBefore)
soundtracksBefore, _ = repo.FindAllSoundtracks(backend.BackendCtx())
beforeCount = len(soundtracksBefore)
}
t.Logf("Games before reset: %d", beforeCount)
assert.True(t, beforeCount > 0, "Should have games to reset")
t.Logf("Soundtracks before reset: %d", beforeCount)
assert.True(t, beforeCount > 0, "Should have soundtracks to reset")
// Call reset
resp := MakeTestRequest(t, e, "GET", "/sync/reset")
@@ -253,16 +253,16 @@ func TestResetGames(t *testing.T) {
// Note: reset might take a moment to propagate
time.Sleep(1 * time.Second)
gamesAfter, _ := repo.FindAllSoundtracks(backend.BackendCtx())
afterCount := len(gamesAfter)
soundtracksAfter, _ := repo.FindAllSoundtracks(backend.BackendCtx())
afterCount := len(soundtracksAfter)
t.Logf("Games after reset: %d", afterCount)
t.Logf("Soundtracks after reset: %d", afterCount)
assert.Equal(t, 0, afterCount, "Database should be empty after reset")
}
// TestSyncGamesNewFull verifies the full sync endpoint
// RUN THIS LAST (before TestResetGames)
func TestSyncGamesNewFull(t *testing.T) {
// TestSyncSoundtracksNewFull verifies the full sync endpoint
// RUN THIS LAST (before TestResetSoundtracks)
func TestSyncSoundtracksNewFull(t *testing.T) {
db.TestSetupDB(t)
defer db.TestTearDownDB(t)
@@ -282,8 +282,8 @@ func TestSyncGamesNewFull(t *testing.T) {
// Verify database is populated
repo := repository.New(backend.BackendPool())
games, err := repo.FindAllSoundtracks(backend.BackendCtx())
soundtracks, 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))
assert.True(t, len(soundtracks) > 0, "Database should be populated after full sync")
t.Logf("Full sync populated %d soundtracks", len(soundtracks))
}
+18 -18
View File
@@ -16,12 +16,12 @@ import (
// ensureSyncRan ensures that sync has been run before testing music endpoints
func ensureSyncRan(t *testing.T, e *echo.Echo) {
repo := repository.New(backend.BackendPool())
games, err := repo.FindAllSoundtracks(backend.BackendCtx())
soundtracks, err := repo.FindAllSoundtracks(backend.BackendCtx())
assert.NoError(t, err)
if len(games) == 0 {
if len(soundtracks) == 0 {
// Run sync
t.Log("No games found, running sync first...")
t.Log("No soundtracks found, running sync first...")
resp := MakeTestRequest(t, e, "GET", "/sync/full")
assert.Equal(t, http.StatusOK, resp.Code)
@@ -32,8 +32,8 @@ func ensureSyncRan(t *testing.T, e *echo.Echo) {
}
}
// TestGetAllGames verifies the /music/all/order endpoint
func TestZGetAllGames(t *testing.T) {
// TestGetAllSoundtracks verifies the /music/all/order endpoint
func TestZGetAllSoundtracks(t *testing.T) {
db.TestSetupDB(t)
defer db.TestTearDownDB(t)
@@ -45,15 +45,15 @@ func TestZGetAllGames(t *testing.T) {
resp := MakeTestRequest(t, e, "GET", "/music/all/order")
assert.Equal(t, http.StatusOK, resp.Code)
var games []string
err := json.Unmarshal(resp.Body.Bytes(), &games)
var soundtracks []string
err := json.Unmarshal(resp.Body.Bytes(), &soundtracks)
assert.NoError(t, err)
assert.NotEmpty(t, games, "Should have games after sync")
t.Logf("Found %d games", len(games))
assert.NotEmpty(t, soundtracks, "Should have soundtracks after sync")
t.Logf("Found %d soundtracks", len(soundtracks))
}
// TestGetAllGamesRandom verifies the /music/all/random endpoint
func TestZGetAllGamesRandom(t *testing.T) {
// TestGetAllSoundtracksRandom verifies the /music/all/random endpoint
func TestZGetAllSoundtracksRandom(t *testing.T) {
db.TestSetupDB(t)
defer db.TestTearDownDB(t)
@@ -65,17 +65,17 @@ func TestZGetAllGamesRandom(t *testing.T) {
resp := MakeTestRequest(t, e, "GET", "/music/all/random")
assert.Equal(t, http.StatusOK, resp.Code)
var games []string
err := json.Unmarshal(resp.Body.Bytes(), &games)
var soundtracks []string
err := json.Unmarshal(resp.Body.Bytes(), &soundtracks)
assert.NoError(t, err)
assert.NotEmpty(t, games, "Should have games after sync")
assert.NotEmpty(t, soundtracks, "Should have soundtracks after sync")
// Verify it's shuffled (not in original order)
// We can't easily verify randomness, but we can check it's the same length
resp2 := MakeTestRequest(t, e, "GET", "/music/all/order")
var gamesOrdered []string
json.Unmarshal(resp2.Body.Bytes(), &gamesOrdered)
assert.Equal(t, len(games), len(gamesOrdered), "Random and ordered should have same count")
var soundtracksOrdered []string
json.Unmarshal(resp2.Body.Bytes(), &soundtracksOrdered)
assert.Equal(t, len(soundtracks), len(soundtracksOrdered), "Random and ordered should have same count")
}
// TestGetRandomSong verifies the /music/rand endpoint
@@ -153,7 +153,7 @@ func TestZGetSongInfo(t *testing.T) {
assert.NoError(t, err)
// Note: CurrentlyPlaying might be false if no song is currently set
// Just verify we got a valid response
t.Logf("Song info: Game=%s, Song=%s", info.Game, info.Song)
t.Logf("Song info: Soundtrack=%s, Song=%s", info.Soundtrack, info.Song)
}
// TestGetPlayedSongs verifies the /music/list endpoint