diff --git a/backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/v2ImportController/SingleStepImportControllerTest.kt b/backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/v2ImportController/SingleStepImportControllerTest.kt index 5d28d0fe7e..8cffdfa6ec 100644 --- a/backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/v2ImportController/SingleStepImportControllerTest.kt +++ b/backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/v2ImportController/SingleStepImportControllerTest.kt @@ -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 @@ -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`() { @@ -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 diff --git a/backend/app/src/test/resources/import/po/codeReferences.po b/backend/app/src/test/resources/import/po/codeReferences.po new file mode 100644 index 0000000000..0c0f5adb39 --- /dev/null +++ b/backend/app/src/test/resources/import/po/codeReferences.po @@ -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!" \ No newline at end of file diff --git a/backend/data/src/main/kotlin/io/tolgee/service/dataImport/StoredDataImporter.kt b/backend/data/src/main/kotlin/io/tolgee/service/dataImport/StoredDataImporter.kt index 8d5f52d8d6..923d709bf3 100644 --- a/backend/data/src/main/kotlin/io/tolgee/service/dataImport/StoredDataImporter.kt +++ b/backend/data/src/main/kotlin/io/tolgee/service/dataImport/StoredDataImporter.kt @@ -162,13 +162,13 @@ class StoredDataImporter( } private fun saveKeyMetaData(keyEntitiesToSave: Collection) { - 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() {