feat: add home feeds, interaction endpoints and playlists
- getAlbumList2/getAlbumList, getRandomSongs, getGenres, getSongsByGenre, getStarred2/getStarred, artist/album info and similar/top stubs - scrobble, star/unstar, setRating, bookmarks and lyrics - playlist create/get/update/delete with ownership and visibility rules - persist scanned lyrics via V3 migration - include last-played timestamps in song and album responses
This commit is contained in:
1 parent
43e726628e
commit
46266d8071
14 files changed
+1400
-9
No files matched your search
@@ -24,7 +24,6 @@ import kotlinx.serialization.json.jsonObject
|
||||
import kotlinx.serialization.json.jsonPrimitive
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertNotNull
|
||||
import kotlin.test.assertTrue
|
||||
import org.jetbrains.exposed.sql.insert
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
@@ -202,6 +201,156 @@ class BrowsingRoutesTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `album feeds genres and random songs are visibility scoped`() {
|
||||
seededContext().use { seed ->
|
||||
testApplication {
|
||||
setupApp(seed)
|
||||
val auth = credentials("alice", "alice-pw")
|
||||
|
||||
val albums = parseBody(
|
||||
client.get("/rest/getAlbumList2?$auth&type=alphabeticalByName&size=10").bodyAsText(),
|
||||
)["albumList2"]!!.jsonObject["album"]!!.jsonArray
|
||||
assertEquals(1, albums.size)
|
||||
assertEquals(seed.aliceAlbumId, albums[0].jsonObject["id"]!!.jsonPrimitive.content)
|
||||
|
||||
val recent = parseBody(
|
||||
client.get("/rest/getAlbumList2?$auth&type=recent&size=10").bodyAsText(),
|
||||
)["albumList2"]!!.jsonObject["album"]!!.jsonArray
|
||||
assertEquals(1, recent.size)
|
||||
|
||||
val genres = parseBody(client.get("/rest/getGenres?$auth").bodyAsText())["genres"]!!
|
||||
.jsonObject["genre"]!!.jsonArray
|
||||
assertEquals(listOf("Rock"), genres.map { it.jsonObject["value"]!!.jsonPrimitive.content })
|
||||
|
||||
val byGenre = parseBody(
|
||||
client.get("/rest/getSongsByGenre?$auth&genre=Rock&count=10").bodyAsText(),
|
||||
)["songsByGenre"]!!.jsonObject["song"]!!.jsonArray
|
||||
assertEquals(seed.aliceSongId, byGenre.single().jsonObject["id"]!!.jsonPrimitive.content)
|
||||
|
||||
val random = parseBody(
|
||||
client.get("/rest/getRandomSongs?$auth&size=10").bodyAsText(),
|
||||
)["randomSongs"]!!.jsonObject["song"]!!.jsonArray
|
||||
assertEquals(seed.aliceSongId, random.single().jsonObject["id"]!!.jsonPrimitive.content)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `scrobbling stars ratings and bookmarks are per user`() {
|
||||
seededContext().use { seed ->
|
||||
testApplication {
|
||||
setupApp(seed)
|
||||
val alice = credentials("alice", "alice-pw")
|
||||
val bob = credentials("bob", "bob-pw")
|
||||
|
||||
client.get("/rest/scrobble?$alice&id=${seed.aliceSongId}")
|
||||
val played = parseBody(
|
||||
client.get("/rest/getSong?$alice&id=${seed.aliceSongId}").bodyAsText(),
|
||||
)["song"]!!.jsonObject
|
||||
assertEquals(1, played["playCount"]!!.jsonPrimitive.int)
|
||||
|
||||
client.get("/rest/star?$alice&id=${seed.aliceSongId}&albumId=${seed.aliceAlbumId}")
|
||||
val starred = parseBody(client.get("/rest/getStarred2?$alice").bodyAsText())["starred2"]!!
|
||||
.jsonObject
|
||||
assertEquals(1, starred["song"]!!.jsonArray.size)
|
||||
assertEquals(1, starred["album"]!!.jsonArray.size)
|
||||
|
||||
val bobStarred = parseBody(client.get("/rest/getStarred2?$bob").bodyAsText())["starred2"]!!
|
||||
.jsonObject
|
||||
assertEquals(0, bobStarred["song"]!!.jsonArray.size)
|
||||
|
||||
client.get("/rest/setRating?$alice&id=${seed.aliceSongId}&rating=4")
|
||||
client.get("/rest/setRating?$alice&id=${seed.aliceAlbumId}&rating=5")
|
||||
|
||||
val ratedSong = parseBody(
|
||||
client.get("/rest/getSong?$alice&id=${seed.aliceSongId}").bodyAsText(),
|
||||
)["song"]!!.jsonObject
|
||||
assertEquals(4, ratedSong["userRating"]!!.jsonPrimitive.int)
|
||||
|
||||
val ratedAlbum = parseBody(
|
||||
client.get("/rest/getAlbum?$alice&id=${seed.aliceAlbumId}").bodyAsText(),
|
||||
)["album"]!!.jsonObject
|
||||
assertEquals(5, ratedAlbum["userRating"]!!.jsonPrimitive.int)
|
||||
|
||||
client.get("/rest/createBookmark?$alice&id=${seed.aliceSongId}&position=5000")
|
||||
val bookmarks = parseBody(client.get("/rest/getBookmarks?$alice").bodyAsText())["bookmarks"]!!
|
||||
.jsonObject["bookmark"]!!.jsonArray
|
||||
assertEquals(1, bookmarks.size)
|
||||
assertEquals(5000, bookmarks[0].jsonObject["position"]!!.jsonPrimitive.int)
|
||||
assertEquals(
|
||||
seed.aliceSongId,
|
||||
bookmarks[0].jsonObject["entry"]!!.jsonObject["id"]!!.jsonPrimitive.content,
|
||||
)
|
||||
|
||||
client.get("/rest/deleteBookmark?$alice&id=${seed.aliceSongId}")
|
||||
val empty = parseBody(client.get("/rest/getBookmarks?$alice").bodyAsText())["bookmarks"]!!
|
||||
.jsonObject["bookmark"]!!.jsonArray
|
||||
assertEquals(0, empty.size)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `playlists enforce ownership and filter entries by visibility`() {
|
||||
seededContext().use { seed ->
|
||||
testApplication {
|
||||
setupApp(seed)
|
||||
val alice = credentials("alice", "alice-pw")
|
||||
val bob = credentials("bob", "bob-pw")
|
||||
|
||||
val created = parseBody(
|
||||
client.get("/rest/createPlaylist?$alice&name=Alice List&songId=${seed.aliceSongId}").bodyAsText(),
|
||||
)["playlist"]!!.jsonObject
|
||||
val playlistId = created["id"]!!.jsonPrimitive.content
|
||||
assertEquals("Alice List", created["name"]!!.jsonPrimitive.content)
|
||||
assertEquals(1, created["songCount"]!!.jsonPrimitive.int)
|
||||
|
||||
val aliceList = parseBody(client.get("/rest/getPlaylists?$alice").bodyAsText())["playlists"]!!
|
||||
.jsonObject["playlist"]!!.jsonArray
|
||||
assertEquals(1, aliceList.size)
|
||||
|
||||
val bobDetail = parseBody(
|
||||
client.get("/rest/getPlaylist?$bob&id=$playlistId").bodyAsText(),
|
||||
)["playlist"]!!.jsonObject
|
||||
assertEquals(1, bobDetail["songCount"]!!.jsonPrimitive.int)
|
||||
assertEquals(0, bobDetail["entry"]!!.jsonArray.size)
|
||||
|
||||
val forbidden = parseBody(
|
||||
client.get("/rest/deletePlaylist?$bob&id=$playlistId").bodyAsText(),
|
||||
)
|
||||
assertEquals(50, forbidden["error"]!!.jsonObject["code"]!!.jsonPrimitive.int)
|
||||
|
||||
client.get("/rest/updatePlaylist?$alice&playlistId=$playlistId&songIndexToRemove=0")
|
||||
val emptied = parseBody(
|
||||
client.get("/rest/getPlaylist?$alice&id=$playlistId").bodyAsText(),
|
||||
)["playlist"]!!.jsonObject
|
||||
assertEquals(0, emptied["entry"]!!.jsonArray.size)
|
||||
|
||||
val deleted = parseBody(
|
||||
client.get("/rest/deletePlaylist?$alice&id=$playlistId").bodyAsText(),
|
||||
)
|
||||
assertEquals("ok", deleted["status"]!!.jsonPrimitive.content)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `lyrics endpoint returns an empty structure when the song has no lyrics`() {
|
||||
seededContext().use { seed ->
|
||||
testApplication {
|
||||
setupApp(seed)
|
||||
val auth = credentials("alice", "alice-pw")
|
||||
|
||||
val body = parseBody(
|
||||
client.get("/rest/getLyricsBySongId?$auth&id=${seed.aliceSongId}").bodyAsText(),
|
||||
)
|
||||
val lyricsList = body["lyricsList"]!!.jsonObject
|
||||
assertEquals(0, lyricsList["structuredLyrics"]?.jsonArray?.size ?: 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun ApplicationTestBuilder.setupApp(seed: Seed) {
|
||||
application {
|
||||
install(ContentNegotiation) {
|
||||
|
||||
Reference in new issue
Block a user