-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
202 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,7 @@ SELECT | |
disambiguation, | ||
type | ||
FROM series WHERE id = ?; | ||
|
||
delete: | ||
DELETE FROM series | ||
WHERE id = :id; |
33 changes: 25 additions & 8 deletions
33
...src/commonMain/kotlin/ly/david/musicsearch/data/repository/series/SeriesRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
160 changes: 160 additions & 0 deletions
160
...rc/jvmTest/kotlin/ly/david/musicsearch/data/repository/series/SeriesRepositoryImplTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
package ly.david.musicsearch.data.repository.series | ||
|
||
import kotlinx.coroutines.test.runTest | ||
import ly.david.data.test.api.FakeLookupApi | ||
import ly.david.musicsearch.data.database.dao.EntityHasRelationsDao | ||
import ly.david.musicsearch.data.database.dao.EntityHasUrlsDao | ||
import ly.david.musicsearch.data.database.dao.RelationDao | ||
import ly.david.musicsearch.data.database.dao.SeriesDao | ||
import ly.david.musicsearch.data.musicbrainz.models.UrlMusicBrainzModel | ||
import ly.david.musicsearch.data.musicbrainz.models.core.SeriesMusicBrainzModel | ||
import ly.david.musicsearch.data.musicbrainz.models.relation.Direction | ||
import ly.david.musicsearch.data.musicbrainz.models.relation.RelationMusicBrainzModel | ||
import ly.david.musicsearch.data.musicbrainz.models.relation.SerializableMusicBrainzEntity | ||
import ly.david.musicsearch.data.repository.KoinTestRule | ||
import ly.david.musicsearch.data.repository.RelationRepositoryImpl | ||
import ly.david.musicsearch.shared.domain.listitem.RelationListItemModel | ||
import ly.david.musicsearch.shared.domain.network.MusicBrainzEntity | ||
import ly.david.musicsearch.shared.domain.series.SeriesDetailsModel | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.koin.test.KoinTest | ||
import org.koin.test.inject | ||
|
||
class SeriesRepositoryImplTest : KoinTest { | ||
|
||
@get:Rule(order = 0) | ||
val koinTestRule = KoinTestRule() | ||
|
||
private val entityHasRelationsDao: EntityHasRelationsDao by inject() | ||
private val entityHasUrlsDao: EntityHasUrlsDao by inject() | ||
private val relationDao: RelationDao by inject() | ||
private val seriesDao: SeriesDao by inject() | ||
|
||
private fun createRepositoryWithFakeNetworkData( | ||
musicBrainzModel: SeriesMusicBrainzModel, | ||
): SeriesRepositoryImpl { | ||
val relationRepository = RelationRepositoryImpl( | ||
lookupApi = object : FakeLookupApi() { | ||
override suspend fun lookupSeries( | ||
seriesId: String, | ||
include: String?, | ||
): SeriesMusicBrainzModel { | ||
return musicBrainzModel | ||
} | ||
}, | ||
entityHasRelationsDao = entityHasRelationsDao, | ||
entityHasUrlsDao = entityHasUrlsDao, | ||
relationDao = relationDao, | ||
) | ||
return SeriesRepositoryImpl( | ||
seriesDao = seriesDao, | ||
relationRepository = relationRepository, | ||
lookupApi = object : FakeLookupApi() { | ||
override suspend fun lookupSeries( | ||
seriesId: String, | ||
include: String?, | ||
): SeriesMusicBrainzModel { | ||
return musicBrainzModel | ||
} | ||
}, | ||
) | ||
} | ||
|
||
@Test | ||
fun `lookup is cached, and force refresh invalidates cache`() = runTest { | ||
val sparseRepository = createRepositoryWithFakeNetworkData( | ||
musicBrainzModel = SeriesMusicBrainzModel( | ||
id = "bb3d9d84-75b8-4e67-8ad7-dcc38f764bf3", | ||
name = "Rolling Stone: 500 Greatest Albums of All Time: 2023 edition", | ||
), | ||
) | ||
val sparseDetailsModel = sparseRepository.lookupSeries( | ||
seriesId = "bb3d9d84-75b8-4e67-8ad7-dcc38f764bf3", | ||
forceRefresh = false, | ||
) | ||
assertEquals( | ||
SeriesDetailsModel( | ||
id = "bb3d9d84-75b8-4e67-8ad7-dcc38f764bf3", | ||
name = "Rolling Stone: 500 Greatest Albums of All Time: 2023 edition", | ||
), | ||
sparseDetailsModel, | ||
) | ||
|
||
val allDataRepository = createRepositoryWithFakeNetworkData( | ||
musicBrainzModel = SeriesMusicBrainzModel( | ||
id = "bb3d9d84-75b8-4e67-8ad7-dcc38f764bf3", | ||
name = "Rolling Stone: 500 Greatest Albums of All Time: 2023 edition", | ||
type = "Release group series", | ||
relations = listOf( | ||
RelationMusicBrainzModel( | ||
type = "official homepage", | ||
typeId = "b79eb9a5-46df-492d-b107-1f1fea71b0eb", | ||
direction = Direction.FORWARD, | ||
targetType = SerializableMusicBrainzEntity.URL, | ||
url = UrlMusicBrainzModel( | ||
id = "e4a5db48-cae3-404f-921d-0f1c3947f874", | ||
resource = "https://www.rollingstone.com/music/music-lists/best-albums-of-all-time-1062063/", | ||
), | ||
), | ||
RelationMusicBrainzModel( | ||
type = "wikidata", | ||
typeId = "a1eecd98-f2f2-420b-ba8e-e5bc61697869", | ||
direction = Direction.FORWARD, | ||
targetType = SerializableMusicBrainzEntity.URL, | ||
url = UrlMusicBrainzModel( | ||
id = "61036cd9-8819-4f56-8739-d7f9bd16d675", | ||
resource = "https://www.wikidata.org/wiki/Q240550", | ||
), | ||
), | ||
), | ||
), | ||
) | ||
var allDataArtistDetailsModel = allDataRepository.lookupSeries( | ||
seriesId = "bb3d9d84-75b8-4e67-8ad7-dcc38f764bf3", | ||
forceRefresh = false, | ||
) | ||
assertEquals( | ||
SeriesDetailsModel( | ||
id = "bb3d9d84-75b8-4e67-8ad7-dcc38f764bf3", | ||
name = "Rolling Stone: 500 Greatest Albums of All Time: 2023 edition", | ||
), | ||
allDataArtistDetailsModel, | ||
) | ||
allDataArtistDetailsModel = allDataRepository.lookupSeries( | ||
seriesId = "bb3d9d84-75b8-4e67-8ad7-dcc38f764bf3", | ||
forceRefresh = true, | ||
) | ||
assertEquals( | ||
SeriesDetailsModel( | ||
id = "bb3d9d84-75b8-4e67-8ad7-dcc38f764bf3", | ||
name = "Rolling Stone: 500 Greatest Albums of All Time: 2023 edition", | ||
type = "Release group series", | ||
urls = listOf( | ||
RelationListItemModel( | ||
id = "61036cd9-8819-4f56-8739-d7f9bd16d675_1", | ||
linkedEntityId = "61036cd9-8819-4f56-8739-d7f9bd16d675", | ||
label = "Wikidata", | ||
name = "https://www.wikidata.org/wiki/Q240550", | ||
disambiguation = null, | ||
attributes = "", | ||
additionalInfo = null, | ||
linkedEntity = MusicBrainzEntity.URL, | ||
), | ||
RelationListItemModel( | ||
id = "e4a5db48-cae3-404f-921d-0f1c3947f874_0", | ||
linkedEntityId = "e4a5db48-cae3-404f-921d-0f1c3947f874", | ||
label = "official homepages", | ||
name = "https://www.rollingstone.com/music/music-lists/best-albums-of-all-time-1062063/", | ||
disambiguation = null, | ||
attributes = "", | ||
additionalInfo = null, | ||
linkedEntity = MusicBrainzEntity.URL, | ||
), | ||
), | ||
), | ||
allDataArtistDetailsModel, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
...omain/src/commonMain/kotlin/ly/david/musicsearch/shared/domain/series/SeriesRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
package ly.david.musicsearch.shared.domain.series | ||
|
||
interface SeriesRepository { | ||
suspend fun lookupSeries(seriesId: String): SeriesDetailsModel | ||
suspend fun lookupSeries( | ||
seriesId: String, | ||
forceRefresh: Boolean, | ||
): SeriesDetailsModel | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters