Skip to content

Commit

Permalink
refactor: Describe ios locales (#1886)
Browse files Browse the repository at this point in the history
Fixes #1849 

## Test Plan
Code is refactored according to the description in #1849 
Needs clarification that it follows 100% the correct methodology for passing of values.

## Checklist
- [x] Unit tested
  • Loading branch information
Sloox authored May 6, 2021
1 parent 307b583 commit fa6d6a2
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 17 deletions.
3 changes: 2 additions & 1 deletion test_runner/src/main/kotlin/ftl/api/Locale.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ data class Locale(

data class Identity(
val projectId: String,
val platform: Platform
val platform: Platform,
val locale: String? = null,
)

interface Fetch : (Identity) -> List<Locale>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ftl.api.Locale
import ftl.api.Platform
import ftl.api.fetchLocales
import ftl.args.AndroidArgs
import ftl.environment.getLocaleDescription
import ftl.presentation.cli.firebase.test.locale.getLocaleDescription
import ftl.run.exception.FlankConfigurationError
import java.nio.file.Paths

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import ftl.args.AndroidArgs
import ftl.environment.android.toCliTable
import ftl.environment.common.toCliTable
import ftl.environment.toCliTable
import ftl.presentation.cli.firebase.test.locale.toCliTable
import java.nio.file.Paths

interface DescribeAndroidTestEnvironment {
Expand Down
13 changes: 7 additions & 6 deletions test_runner/src/main/kotlin/ftl/domain/DescribeIosLocales.kt
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
package ftl.domain

import flank.common.log
import ftl.api.Locale.Identity
import ftl.api.Platform
import ftl.api.fetchLocales
import ftl.args.IosArgs
import ftl.environment.getLocaleDescription
import ftl.presentation.Output
import ftl.run.exception.FlankConfigurationError
import ftl.run.exception.FlankGeneralError
import java.nio.file.Paths

interface DescribeIosLocales {
interface DescribeIosLocales : Output {
val locale: String
val configPath: String
}

fun DescribeIosLocales.invoke() {
if (locale.isBlank()) throw FlankConfigurationError("Argument LOCALE must be specified.")
log(
fetchLocales(Identity(IosArgs.loadOrDefault(Paths.get(configPath)).project, Platform.IOS)).getLocaleDescription(locale)
)

fetchLocales(Identity(IosArgs.loadOrDefault(Paths.get(configPath)).project, Platform.IOS, locale)).find {
it.id == locale
}?.out() ?: throw FlankGeneralError("ERROR: '$locale' is not a valid locale")
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import ftl.client.google.IosCatalog
import ftl.environment.common.toCliTable
import ftl.environment.ios.toCliTable
import ftl.environment.toCliTable
import ftl.presentation.cli.firebase.test.locale.toCliTable
import java.nio.file.Paths

interface DescribeIosTestEnvironment {
Expand Down
2 changes: 1 addition & 1 deletion test_runner/src/main/kotlin/ftl/domain/ListIosLocales.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ftl.api.Locale.Identity
import ftl.api.Platform
import ftl.api.fetchLocales
import ftl.args.IosArgs
import ftl.environment.toCliTable
import ftl.presentation.cli.firebase.test.locale.toCliTable
import java.nio.file.Paths

interface ListIosLocales {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ftl.api.Locale
import ftl.config.FtlConstants
import ftl.domain.ListAndroidLocales
import ftl.domain.invoke
import ftl.environment.toCliTable
import ftl.presentation.cli.firebase.test.locale.toCliTable
import ftl.presentation.outputLogger
import ftl.presentation.throwUnknownType
import picocli.CommandLine
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package ftl.presentation.cli.firebase.test.ios.configuration

import ftl.api.Locale
import ftl.config.FtlConstants
import ftl.domain.DescribeIosLocales
import ftl.domain.invoke
import ftl.presentation.cli.firebase.test.locale.prepareDescription
import ftl.presentation.outputLogger
import ftl.presentation.throwUnknownType
import picocli.CommandLine

@Suppress("UNCHECKED_CAST")
@CommandLine.Command(
name = "describe",
headerHeading = "",
Expand Down Expand Up @@ -37,5 +42,12 @@ class IosLocalesDescribeCommand :
)
override var configPath: String = FtlConstants.defaultIosConfig

override val out = outputLogger {
when (this) {
is Locale -> prepareDescription()
else -> throwUnknownType()
}
}

override fun run() = invoke()
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package ftl.environment
package ftl.presentation.cli.firebase.test.locale

import ftl.api.Locale
import ftl.environment.TAGS
import ftl.environment.TestEnvironmentInfo
import ftl.environment.createTableColumnFor
import ftl.environment.getOrCreateList
import ftl.environment.tagToSystemOutColorMapper
import ftl.run.exception.FlankGeneralError
import ftl.util.applyColorsUsing
import ftl.util.buildTable
Expand All @@ -21,7 +26,7 @@ fun TestEnvironmentInfo.createLocalesTable() = buildTable(
createTableColumnFor(LOCALE),
createTableColumnFor(NAME),
createTableColumnFor(REGION),
createTableColumnFor(ftl.environment.TAGS).applyColorsUsing(tagToSystemOutColorMapper)
createTableColumnFor(TAGS).applyColorsUsing(tagToSystemOutColorMapper)
)

private const val LOCALE = "LOCALE"
Expand All @@ -33,9 +38,9 @@ fun List<Locale>.getLocaleDescription(localeId: String) =

private fun List<Locale>.findLocales(localeId: String) = find { it.id == localeId }

private fun Locale.prepareDescription() = """
id: $id
name: $name
fun Locale.prepareDescription() = """
id: $id
name: $name
""".trimIndent().addRegionIfExist(region).addTagsIfExists(this)

private fun String.addRegionIfExist(region: String?) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import ftl.api.fetchDeviceModelAndroid
import ftl.api.fetchLocales
import ftl.client.google.AndroidCatalog
import ftl.environment.android.toCliTable
import ftl.environment.toCliTable
import ftl.presentation.cli.firebase.test.locale.toCliTable
import ftl.test.util.FlankTestRunner
import io.mockk.every
import io.mockk.mockk
Expand Down
2 changes: 1 addition & 1 deletion test_runner/src/test/kotlin/ftl/ios/IosCatalogTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ftl.api.Locale.Identity
import ftl.api.Platform
import ftl.api.fetchLocales
import ftl.client.google.IosCatalog
import ftl.environment.toCliTable
import ftl.presentation.cli.firebase.test.locale.toCliTable
import ftl.test.util.FlankTestRunner
import org.junit.Test
import org.junit.runner.RunWith
Expand Down

0 comments on commit fa6d6a2

Please sign in to comment.