Skip to content

Commit

Permalink
update storeInitialTranslations to filter translations with missing t…
Browse files Browse the repository at this point in the history
…ools or languages
  • Loading branch information
frett committed May 8, 2024
1 parent e801b73 commit 053674a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,17 @@ internal abstract class TranslationsRoomRepository(private val db: GodToolsRoomD
// endregion DownloadManager Methods

// region Initial Content Methods
override suspend fun storeInitialTranslations(translations: Collection<Translation>) =
dao.insertOrIgnoreTranslations(translations.map { TranslationEntity(it) })
@Transaction
override suspend fun storeInitialTranslations(translations: Collection<Translation>) {
val tools = db.toolsDao.getTools().mapTo(mutableSetOf()) { it.code }
val languages = db.languagesDao.getLanguages().mapTo(mutableSetOf()) { it.code }
dao.insertOrIgnoreTranslations(
translations
.filter { it.toolCode in tools }
.filter { it.languageCode in languages }
.map { TranslationEntity(it) }
)
}
// endregion Initial Content Methods

// region ManifestManager Methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,26 @@ abstract class TranslationsRepositoryIT {
assertEquals(translation.version, it.version)
}
}

@Test
fun `storeInitialTranslations() - Language doesn't exist`() = testScope.runTest {
val trans1 = randomTranslation(TOOL, Locale.ENGLISH)
val trans2 = randomTranslation(TOOL, Locale.ITALIAN)
repository.storeInitialTranslations(listOf(trans1, trans2))

assertNotNull(repository.findTranslation(trans1.id))
assertNull(repository.findTranslation(trans2.id))
}

@Test
fun `storeInitialTranslations() - Tool doesn't exist`() = testScope.runTest {
val trans1 = randomTranslation(TOOL, Locale.ENGLISH)
val trans2 = randomTranslation("invalid_tool", Locale.ENGLISH)
repository.storeInitialTranslations(listOf(trans1, trans2))

assertNotNull(repository.findTranslation(trans1.id))
assertNull(repository.findTranslation(trans2.id))
}
// endregion storeInitialTranslations()

// region markBrokenManifestNotDownloaded()
Expand Down

0 comments on commit 053674a

Please sign in to comment.