Skip to content

Commit

Permalink
fix: Mapping with null namespace is used
Browse files Browse the repository at this point in the history
  • Loading branch information
JanCizmar committed May 6, 2024
1 parent e625a2d commit b3917c6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,27 @@ class SingleStepImportControllerTest : ProjectAuthControllerTest("/v2/projects/"
getTestTranslation(namespace = "test").assert.isNotNull
}

@Test
@ProjectJWTAuthTestMethod
fun `maps null namespace from non-null mapping`() {
val fileName = "guessed-ns/en.json"
performImport(
projectId = testData.project.id,
listOf(Pair(fileName, simpleJson)),
getFileMappings(fileName, namespace = null),
).andIsOk

getTestTranslation().assert.isNotNull

performImport(
projectId = testData.project.id,
listOf(Pair(fileName, simpleJson)),
mapOf(),
).andIsOk

getTestTranslation(namespace = "guessed-ns").assert.isNotNull
}

@Test
@ProjectJWTAuthTestMethod
fun `respects provided format`() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class CoreImportFilesProcessor(
val mappedNamespace = findMappedNamespace()

if (mappedNamespace != null) {
return mappedNamespace
return getSafeNamespace(mappedNamespace)
}

if (this.namespace != null) {
Expand All @@ -174,6 +174,12 @@ class CoreImportFilesProcessor(
}

private fun FileProcessorContext.findMappedNamespace(): String? {
if (mapping != null) {
// if mapping is present, use it even when the namespace is null to avoid
// guessing from the file name
return this.mapping?.namespace ?: ""
}

return this.mapping?.namespace
}

Expand Down

0 comments on commit b3917c6

Please sign in to comment.