test: cover recommendation conversion when a song is added
This commit is contained in:
1 parent
de038deb58
commit
0613b8aedc
1 file changed
+33
-2
@@ -72,6 +72,37 @@ class MoodRepositoryTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `adding a song converts matching recommendations and drops hidden candidates`() {
|
||||
withDatabase { mediaStore, _ ->
|
||||
val mood = createMood(recommendationCount = 2)
|
||||
val one = insertSong(mediaStore, "v-1", "One")
|
||||
val two = insertSong(mediaStore, "v-2", "Two")
|
||||
storeCandidates(mood.id, 2)
|
||||
MoodRepository.promoteCandidates(mood.id, 2)
|
||||
|
||||
assertTrue(MoodRepository.addSong(mood.id, one.id, "search"))
|
||||
assertTrue(MoodRepository.addSong(mood.id, two.id, "search"))
|
||||
|
||||
val first = assertNotNull(MoodRepository.recommendation(mood.id, "v-1"))
|
||||
val second = assertNotNull(MoodRepository.recommendation(mood.id, "v-2"))
|
||||
assertEquals("added", first.state)
|
||||
assertEquals(one.id, first.songId)
|
||||
assertEquals("added", second.state)
|
||||
assertEquals(two.id, second.songId)
|
||||
assertEquals(2, MoodRepository.songIds(mood.id).size)
|
||||
assertEquals(0, MoodRepository.activeCount(mood.id))
|
||||
|
||||
// A still-hidden candidate for a video added manually is removed.
|
||||
val another = createMood(recommendationCount = 2, name = "Another")
|
||||
val three = insertSong(mediaStore, "v-3", "Three")
|
||||
storeCandidates(another.id, 1, startAt = 3)
|
||||
assertNotNull(MoodRepository.recommendation(another.id, "v-3"))
|
||||
MoodRepository.addSong(another.id, three.id, "search")
|
||||
assertNull(MoodRepository.recommendation(another.id, "v-3"))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `decisions survive a discovery refresh`() {
|
||||
withDatabase { _, _ ->
|
||||
@@ -233,10 +264,10 @@ class MoodRepositoryTest {
|
||||
refreshHours = 24,
|
||||
)
|
||||
|
||||
private fun storeCandidates(moodId: String, count: Int) {
|
||||
private fun storeCandidates(moodId: String, count: Int, startAt: Int = 1) {
|
||||
MoodRepository.storeCandidates(
|
||||
moodId,
|
||||
(1..count).map { index ->
|
||||
(startAt until startAt + count).map { index ->
|
||||
RecommendationUpsert(
|
||||
videoId = "v-$index",
|
||||
title = "Track $index",
|
||||
|
||||
Reference in new issue
Block a user