"""Router tests - Search endpoints.""" from app.models.song import Song from app.models.playlist import Playlist class TestSearch: def test_empty_search(self, client): r = client.get("/api/search?q=test") assert r.status_code == 200 data = r.json() assert data["query"] == "test" assert "songs" in data assert "playlists" in data assert "total_results" in data def test_search_songs(self, client, db_module): db = db_module.SessionLocal() s = Song(id="s1", title="Hello World", artist="Test Artist", file_path="/tmp/t.mp3") db.add(s) db.commit() db.close() r = client.get("/api/search?q=Hello") assert r.status_code == 200 data = r.json() assert len(data["songs"]) >= 1 assert data["total_results"] >= 1 def test_search_playlists(self, client, db_module): db = db_module.SessionLocal() p = Playlist(id="p1", name="My Test Playlist") db.add(p) db.commit() db.close() r = client.get("/api/search?q=My+Test") assert r.status_code == 200 data = r.json() assert len(data["playlists"]) >= 1 def test_search_min_length(self, client): r = client.get("/api/search?q=") assert r.status_code == 422