-
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Revert "REVIEWED" to "TRANSLATED" when text changes (#2807)
- Loading branch information
Showing
36 changed files
with
1,208 additions
and
734 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
55 changes: 55 additions & 0 deletions
55
...app/src/test/kotlin/io/tolgee/api/v2/controllers/batch/BatchChangeTranslationStateTest.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,55 @@ | ||
package io.tolgee.api.v2.controllers.batch | ||
|
||
import io.tolgee.ProjectAuthControllerTest | ||
import io.tolgee.fixtures.andIsOk | ||
import io.tolgee.fixtures.waitForNotThrowing | ||
import io.tolgee.model.enums.TranslationState | ||
import io.tolgee.testing.annotations.ProjectJWTAuthTestMethod | ||
import io.tolgee.testing.assert | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import org.springframework.beans.factory.annotation.Autowired | ||
|
||
class BatchChangeTranslationStateTest : ProjectAuthControllerTest("/v2/projects/") { | ||
@Autowired | ||
lateinit var batchJobTestBase: BatchJobTestBase | ||
|
||
@BeforeEach | ||
fun setup() { | ||
batchJobTestBase.setup() | ||
} | ||
|
||
val testData | ||
get() = batchJobTestBase.testData | ||
|
||
@Test | ||
@ProjectJWTAuthTestMethod | ||
fun `it changes translation state`() { | ||
val keyCount = 100 | ||
val keys = testData.addStateChangeData(keyCount) | ||
batchJobTestBase.saveAndPrepare(this) | ||
|
||
val allKeyIds = keys.map { it.id }.toList() | ||
val keyIds = allKeyIds.take(10) | ||
val allLanguageIds = testData.projectBuilder.data.languages.map { it.self.id } | ||
val languagesToChangeStateIds = listOf(testData.germanLanguage.id, testData.englishLanguage.id) | ||
|
||
performProjectAuthPost( | ||
"start-batch-job/set-translation-state", | ||
mapOf( | ||
"keyIds" to keyIds, | ||
"languageIds" to languagesToChangeStateIds, | ||
"state" to "REVIEWED", | ||
), | ||
).andIsOk | ||
|
||
waitForNotThrowing(pollTime = 1000, timeout = 10000) { | ||
val all = | ||
translationService.getTranslations( | ||
keys.map { it.id }, | ||
allLanguageIds, | ||
) | ||
all.count { it.state == TranslationState.REVIEWED }.assert.isEqualTo(keyIds.size * 2) | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/batch/BatchClearTranslationsTest.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,54 @@ | ||
package io.tolgee.api.v2.controllers.batch | ||
|
||
import io.tolgee.ProjectAuthControllerTest | ||
import io.tolgee.fixtures.andIsOk | ||
import io.tolgee.fixtures.waitForNotThrowing | ||
import io.tolgee.model.enums.TranslationState | ||
import io.tolgee.testing.annotations.ProjectJWTAuthTestMethod | ||
import io.tolgee.testing.assert | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import org.springframework.beans.factory.annotation.Autowired | ||
|
||
class BatchClearTranslationsTest : ProjectAuthControllerTest("/v2/projects/") { | ||
@Autowired | ||
lateinit var batchJobTestBase: BatchJobTestBase | ||
|
||
@BeforeEach | ||
fun setup() { | ||
batchJobTestBase.setup() | ||
} | ||
|
||
val testData | ||
get() = batchJobTestBase.testData | ||
|
||
@Test | ||
@ProjectJWTAuthTestMethod | ||
fun `it clears translations`() { | ||
val keyCount = 1000 | ||
val keys = testData.addStateChangeData(keyCount) | ||
batchJobTestBase.saveAndPrepare(this) | ||
|
||
val allKeyIds = keys.map { it.id }.toList() | ||
val keyIds = allKeyIds.take(10) | ||
val allLanguageIds = testData.projectBuilder.data.languages.map { it.self.id } | ||
val languagesToClearIds = listOf(testData.germanLanguage.id, testData.englishLanguage.id) | ||
|
||
performProjectAuthPost( | ||
"start-batch-job/clear-translations", | ||
mapOf( | ||
"keyIds" to keyIds, | ||
"languageIds" to languagesToClearIds, | ||
), | ||
).andIsOk | ||
|
||
waitForNotThrowing(pollTime = 1000, timeout = 10000) { | ||
val all = | ||
translationService.getTranslations( | ||
keys.map { it.id }, | ||
allLanguageIds, | ||
) | ||
all.count { it.state == TranslationState.UNTRANSLATED && it.text == null }.assert.isEqualTo(keyIds.size * 2) | ||
} | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/batch/BatchCopyTranslationsTest.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,88 @@ | ||
package io.tolgee.api.v2.controllers.batch | ||
|
||
import io.tolgee.ProjectAuthControllerTest | ||
import io.tolgee.fixtures.andIsOk | ||
import io.tolgee.fixtures.waitForNotThrowing | ||
import io.tolgee.model.enums.TranslationState | ||
import io.tolgee.model.key.Key | ||
import io.tolgee.testing.annotations.ProjectJWTAuthTestMethod | ||
import io.tolgee.testing.assert | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import org.springframework.beans.factory.annotation.Autowired | ||
|
||
class BatchCopyTranslationsTest : ProjectAuthControllerTest("/v2/projects/") { | ||
@Autowired | ||
lateinit var batchJobTestBase: BatchJobTestBase | ||
|
||
@BeforeEach | ||
fun setup() { | ||
batchJobTestBase.setup() | ||
} | ||
|
||
val testData | ||
get() = batchJobTestBase.testData | ||
|
||
@Test | ||
@ProjectJWTAuthTestMethod | ||
fun `it copies translations`() { | ||
val keyCount = 1000 | ||
val keys = testData.addStateChangeData(keyCount) | ||
batchJobTestBase.saveAndPrepare(this) | ||
|
||
val allKeyIds = keys.map { it.id }.toList() | ||
val keyIds = allKeyIds.take(10) | ||
val allLanguageIds = testData.projectBuilder.data.languages.map { it.self.id } | ||
val languagesToChangeStateIds = listOf(testData.germanLanguage.id, testData.czechLanguage.id) | ||
|
||
performProjectAuthPost( | ||
"start-batch-job/copy-translations", | ||
mapOf( | ||
"keyIds" to keyIds, | ||
"sourceLanguageId" to testData.englishLanguage.id, | ||
"targetLanguageIds" to languagesToChangeStateIds, | ||
), | ||
).andIsOk | ||
|
||
waitForNotThrowing(pollTime = 1000, timeout = 10000) { | ||
val all = | ||
translationService.getTranslations( | ||
keys.map { it.id }, | ||
allLanguageIds, | ||
) | ||
all.count { it.text?.startsWith("en") == true }.assert.isEqualTo(allKeyIds.size + keyIds.size * 2) | ||
} | ||
} | ||
|
||
@Test | ||
@ProjectJWTAuthTestMethod | ||
fun `it resets the state for key`() { | ||
val key = testData.addKeyWithTranslationsReviewed() | ||
batchJobTestBase.saveAndPrepare(this) | ||
|
||
assertGermanAKeyState(key, TranslationState.REVIEWED) | ||
|
||
val languagesToChangeStateIds = listOf(testData.germanLanguage.id) | ||
|
||
performProjectAuthPost( | ||
"start-batch-job/copy-translations", | ||
mapOf( | ||
"keyIds" to listOf(key.id), | ||
"sourceLanguageId" to testData.englishLanguage.id, | ||
"targetLanguageIds" to languagesToChangeStateIds, | ||
), | ||
).andIsOk | ||
|
||
waitForNotThrowing(pollTime = 1000, timeout = 10000) { | ||
assertGermanAKeyState(key, TranslationState.TRANSLATED) | ||
} | ||
} | ||
|
||
private fun assertGermanAKeyState( | ||
key: Key, | ||
translationState: TranslationState, | ||
) { | ||
translationService.getTranslations(listOf(key.id), listOf(testData.germanLanguage.id)) | ||
.single().state.assert.isEqualTo(translationState) | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/batch/BatchDeleteKeysTest.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,61 @@ | ||
package io.tolgee.api.v2.controllers.batch | ||
|
||
import io.tolgee.ProjectAuthControllerTest | ||
import io.tolgee.fixtures.andIsOk | ||
import io.tolgee.fixtures.waitForNotThrowing | ||
import io.tolgee.model.batch.BatchJob | ||
import io.tolgee.testing.annotations.ProjectJWTAuthTestMethod | ||
import io.tolgee.testing.assert | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import org.springframework.beans.factory.annotation.Autowired | ||
|
||
class BatchDeleteKeysTest : ProjectAuthControllerTest("/v2/projects/") { | ||
@Autowired | ||
lateinit var batchJobTestBase: BatchJobTestBase | ||
|
||
@BeforeEach | ||
fun setup() { | ||
batchJobTestBase.setup() | ||
} | ||
|
||
val testData | ||
get() = batchJobTestBase.testData | ||
|
||
@Test | ||
@ProjectJWTAuthTestMethod | ||
fun `it deletes keys`() { | ||
val keyCount = 100 | ||
val keys = testData.addTranslationOperationData(keyCount) | ||
batchJobTestBase.saveAndPrepare(this) | ||
|
||
val keyIds = keys.map { it.id }.toList() | ||
|
||
val result = | ||
performProjectAuthPost( | ||
"start-batch-job/delete-keys", | ||
mapOf( | ||
"keyIds" to keyIds, | ||
), | ||
).andIsOk | ||
|
||
batchJobTestBase.waitForJobCompleted(result) | ||
|
||
waitForNotThrowing(pollTime = 1000, timeout = 10000) { | ||
val all = keyService.getAll(testData.projectBuilder.self.id) | ||
all.assert.hasSize(1) | ||
} | ||
|
||
waitForNotThrowing(pollTime = 1000, timeout = 10000) { | ||
executeInNewTransaction { | ||
val data = | ||
entityManager | ||
.createQuery("""from BatchJob""", BatchJob::class.java) | ||
.resultList | ||
|
||
data.assert.hasSize(1) | ||
data[0].activityRevision.assert.isNotNull | ||
} | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/batch/BatchJobRunnerStopTest.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,16 @@ | ||
package io.tolgee.api.v2.controllers.batch | ||
|
||
import io.tolgee.AbstractSpringTest | ||
import io.tolgee.batch.ApplicationBatchJobRunner | ||
import io.tolgee.testing.assert | ||
import org.junit.jupiter.api.Test | ||
import org.springframework.boot.test.context.SpringBootTest | ||
|
||
@SpringBootTest | ||
class BatchJobRunnerStopTest : AbstractSpringTest() { | ||
@Test | ||
fun `it stops`() { | ||
ApplicationBatchJobRunner.stopAll() | ||
ApplicationBatchJobRunner.runningInstances.assert.hasSize(0) | ||
} | ||
} |
Oops, something went wrong.