Skip to content

Commit

Permalink
fix: save code references before key metas to workaround hibernate bug (
Browse files Browse the repository at this point in the history
#2837)

FIxes [tolgee-cli#97](tolgee/tolgee-cli#97)
  • Loading branch information
Anty0 authored Jan 15, 2025
1 parent 693514f commit af8b1b1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ class SingleStepImportControllerTest : ProjectAuthControllerTest("/v2/projects/"
@Value("classpath:import/xliff/simple.xliff")
lateinit var simpleXliff: Resource

@Value("classpath:import/po/codeReferences.po")
lateinit var codeReferencesPo: Resource

lateinit var testData: SingleStepImportTestData

private val xliffFileName: String = "file.xliff"
private val poFileName = "file.po"
private val jsonFileName = "en.json"

@BeforeEach
Expand All @@ -60,6 +64,20 @@ class SingleStepImportControllerTest : ProjectAuthControllerTest("/v2/projects/"
}
}

@Test
@ProjectJWTAuthTestMethod
fun `import po with code references`() {
saveAndPrepare()
performImport(
projectId = testData.project.id,
listOf(Pair(poFileName, codeReferencesPo)),
)
executeInNewTransaction {
assertPoImported()
getTestTranslation().key.keyMeta!!.codeReferences.map { it.path }.assert.contains("dir/file.py")
}
}

@Test
@ProjectJWTAuthTestMethod
fun `does not create new key if option isn't enabled`() {
Expand Down Expand Up @@ -394,6 +412,10 @@ class SingleStepImportControllerTest : ProjectAuthControllerTest("/v2/projects/"
getTestTranslation().text.assert.isEqualTo("test")
}

private fun assertPoImported() {
getTestTranslation().text.assert.isEqualTo("In English!")
}

private fun saveAndPrepare() {
testDataService.saveTestData(testData.root)
userAccount = testData.user
Expand Down
12 changes: 12 additions & 0 deletions backend/app/src/test/resources/import/po/codeReferences.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
msgid ""
msgstr ""
"Language: en\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals = 2; plural = (n > 1)\n"
"X-Generator: Tolgee\n"

#: dir/file.py:42
msgid "test"
msgstr "In English!"
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,13 @@ class StoredDataImporter(
}

private fun saveKeyMetaData(keyEntitiesToSave: Collection<Key>) {
keyMetaService.saveAll(keyMetasToSave)
keyEntitiesToSave.flatMap {
it.keyMeta?.comments ?: emptyList()
}.also { keyMetaService.saveAllComments(it) }
keyEntitiesToSave.flatMap {
it.keyMeta?.codeReferences ?: emptyList()
}.also { keyMetaService.saveAllCodeReferences(it) }
keyMetaService.saveAll(keyMetasToSave)
}

private fun saveTranslations() {
Expand Down

0 comments on commit af8b1b1

Please sign in to comment.