"""Router tests - Mood endpoints.""" from app.models.song import Song from app.models.settings import UserSetting class TestMoodCategories: def test_list_categories(self, client): r = client.get("/api/mood/categories") assert r.status_code == 200 data = r.json() assert len(data) == 10 names = [c["name"] for c in data] assert "Sad" in names assert "Happy" in names assert all("color_hex" in c for c in data) class TestMoodPlaylist: def test_get_playlist(self, client): r = client.get("/api/mood/Happy/playlist") assert r.status_code == 200 data = r.json() assert data["mood"] == "Happy" assert "songs" in data assert "total_songs" in data class TestSetMood: def test_set_mood(self, client): r = client.post("/api/mood/set", json={"mood": "Chill"}) assert r.status_code == 200 assert r.json()["mood"] == "Chill" def test_set_mood_persists(self, client, db_module): client.post("/api/mood/set", json={"mood": "Energetic"}) db = db_module.SessionLocal() s = db.query(UserSetting).filter(UserSetting.key == "default_mood").first() assert s is not None assert s.value == "Energetic" db.close() class TestAnalyzeMood: def test_analyze_all(self, client): r = client.post("/api/mood/analyze") assert r.status_code == 200 data = r.json() assert "analyzed" in data assert "results" in data assert data["analyzed"] == 0 def test_analyze_specific(self, client, db_module): db = db_module.SessionLocal() song = Song(id="s1", title="Test", artist="A", file_path="/tmp/t.mp3") db.add(song) db.commit() db.close() r = client.post("/api/mood/analyze", params={"song_id": "s1"}) assert r.status_code == 200 assert "song_id" in r.json() class TestSaveMoodPlaylist: def test_save(self, client): r = client.post("/api/mood/save", params={"mood": "Happy", "name": "My Happy"}) assert r.status_code == 200 data = r.json() assert data["name"] == "My Happy" assert "id" in data assert "songs" in data