music-app/backend/tests/test_routers_shareplay.py
Jarian Cottingham 24c03426f8 test: add comprehensive test suite with 94% coverage
- Add pytest config with 90% coverage threshold
- 15 test files covering all routers, services, schemas, models
- 300 tests: unit tests, integration tests, edge cases, mocked external APIs
- Update CI workflow to run pytest with coverage enforcement
- Mock external services (Genius, MusicBrainz, RadioBrowser)
- In-memory SQLite DB per test via conftest fixtures
2026-07-06 06:07:31 +00:00

81 lines
2.8 KiB
Python

"""Router tests - SharePlay endpoints."""
from app.models.song import Song
from app.models.shareplay import SharePlayRoom
from app.db.database import SessionLocal
class TestCreateRoom:
def test_create(self, client):
r = client.post("/api/shareplay/create")
assert r.status_code == 200
data = r.json()
assert "id" in data
assert data["creator_user"] == "user"
assert data["active_connections"] == 1
class TestJoinRoom:
def test_join(self, client):
create = client.post("/api/shareplay/create")
room_id = create.json()["id"]
r = client.post("/api/shareplay/join", json={"room_id": room_id})
assert r.status_code == 200
assert r.json()["active_connections"] == 2
def test_join_not_found(self, client):
r = client.post("/api/shareplay/join", json={"room_id": "nonexistent"})
assert r.status_code == 404
class TestLeaveRoom:
def test_leave(self, client):
create = client.post("/api/shareplay/create")
room_id = create.json()["id"]
r = client.post("/api/shareplay/leave", json={"room_id": room_id})
assert r.status_code == 200
def test_leave_not_found(self, client):
r = client.post("/api/shareplay/leave", json={"room_id": "nonexistent"})
assert r.status_code == 404
class TestCue:
def test_get_cue(self, client):
r = client.get("/api/shareplay/cue?room_id=test")
assert r.status_code == 200
data = r.json()
assert "items" in data
assert "next_song" in data
class TestControl:
def test_play(self, client):
create = client.post("/api/shareplay/create")
room_id = create.json()["id"]
r = client.post("/api/shareplay/control", json={"room_id": room_id, "type": "play"})
assert r.status_code == 200
def test_pause(self, client):
create = client.post("/api/shareplay/create")
room_id = create.json()["id"]
r = client.post("/api/shareplay/control", json={"room_id": room_id, "type": "pause"})
assert r.status_code == 200
def test_seek(self, client):
create = client.post("/api/shareplay/create")
room_id = create.json()["id"]
r = client.post("/api/shareplay/control", json={
"room_id": room_id, "type": "seek", "payload": {"position": 42}
})
assert r.status_code == 200
def test_shuffle(self, client):
create = client.post("/api/shareplay/create")
room_id = create.json()["id"]
r = client.post("/api/shareplay/control", json={"room_id": room_id, "type": "shuffle"})
assert r.status_code == 200
def test_control_not_found(self, client):
r = client.post("/api/shareplay/control", json={"room_id": "x", "type": "play"})
assert r.status_code == 404