This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user