mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-10 23:21:59 +01:00
count a play locally when it is scrobbled
A submitted scrobble now bumps the song's playCount/played and its album and artist ranks, so the play sorts move without waiting for a sync. The sync then overwrites them with the server's own numbers, so the increment cannot double-count.
This commit is contained in:
@@ -213,6 +213,25 @@ class LibraryDaoTest {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aRecordedPlayBumpsTheSongAlbumAndArtist() =
|
||||
runTest {
|
||||
val sourceId = source()
|
||||
val dao = db.libraryDao()
|
||||
dao.upsertArtists(listOf(artist(sourceId, "ar-1", "Artist", albumCount = 1)))
|
||||
dao.upsertAlbums(listOf(album(sourceId, "al-1", "Album", year = null, starred = null)))
|
||||
dao.upsertSongs(listOf(song(sourceId, "s1", "One", starred = null)))
|
||||
|
||||
dao.recordPlay(sourceId, "s1", 500)
|
||||
|
||||
assertEquals(1L, dao.songOnce(sourceId, "s1")!!.playCount)
|
||||
assertEquals(500L, dao.songOnce(sourceId, "s1")!!.played)
|
||||
assertEquals(1L, dao.albumOnce(sourceId, "al-1")!!.playCount)
|
||||
assertEquals(500L, dao.albumOnce(sourceId, "al-1")!!.played)
|
||||
assertEquals(1L, dao.artistOnce(sourceId, "ar-1")!!.playCount)
|
||||
assertEquals(500L, dao.artistOnce(sourceId, "ar-1")!!.played)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun reversedAlbumSortsReverseEveryTiebreaker() =
|
||||
runTest {
|
||||
|
||||
@@ -106,6 +106,36 @@ class ScrobblerTest {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aSubmissionRecordsThePlayLocally() =
|
||||
runTest {
|
||||
val sink = RecordingSink()
|
||||
val recorded = mutableListOf<Pair<String, Long>>()
|
||||
val scrobbler =
|
||||
Scrobbler(
|
||||
sink = sink,
|
||||
enabled = flowOf(true),
|
||||
scope = testScope(),
|
||||
policy = ScrobblePolicy(now = { 1_000L }),
|
||||
recordPlay = { songId, at -> recorded += songId to at },
|
||||
)
|
||||
val state = MutableStateFlow(PlaybackState())
|
||||
val position = MutableStateFlow(0L)
|
||||
scrobbler.attach(state, position)
|
||||
val item = QueueItem("s1", "Title", "Artist", "Album", null, durationMs = 30_000)
|
||||
|
||||
state.value = PlaybackState(item = item, isPlaying = true)
|
||||
assertEquals(emptyList<Pair<String, Long>>(), recorded)
|
||||
|
||||
var tick = 500L
|
||||
while (tick <= 15_000L) {
|
||||
position.value = tick
|
||||
tick += 500
|
||||
}
|
||||
|
||||
assertEquals(listOf("s1" to 1L), recorded)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun disabledSendsNothing() =
|
||||
runTest {
|
||||
|
||||
Reference in New Issue
Block a user