From 22125fdfb010ef0b8a4625e68926fc12c8a7ed22 Mon Sep 17 00:00:00 2001 From: Joseph Sanjaya Date: Sat, 30 Aug 2025 17:10:49 +0700 Subject: [PATCH] chore(#234): normalize Indonesian language code to "id" The Indonesian language code "in" is normalized to "id" in `MessagingTopicDataSource` to align with the ISO 639-1 standard used by the backend. This ensures consistency in topic generation for Indonesian language users. Tests have been added to verify this normalization for both "in" and "in_ID" inputs. --- .../data/source/MessagingTopicDataSource.kt | 21 +++++++++- .../source/MessagingTopicDataSourceTest.kt | 38 +++++++++++++++++-- 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/brainwallet/data/source/MessagingTopicDataSource.kt b/app/src/main/java/com/brainwallet/data/source/MessagingTopicDataSource.kt index 804b9aca..530d77a8 100644 --- a/app/src/main/java/com/brainwallet/data/source/MessagingTopicDataSource.kt +++ b/app/src/main/java/com/brainwallet/data/source/MessagingTopicDataSource.kt @@ -18,12 +18,29 @@ class MessagingTopicDataSource( ) } + /** + * Note: Indonesian language code is normalized from "in" to "id" to maintain + * consistency with backend batch messaging server which uses ISO 639-1 standard. + * Supports both "in" and "id" as input for Indonesian language. + */ private fun getBaseLanguageCode(languageCode: String): String { val normalizedLanguageCode = languageCode.split("_", "-").first().lowercase() + + // Handle reverse mapping: if "id" is passed, treat it as Indonesian + val searchCode = when (normalizedLanguageCode) { + "id" -> "in" + else -> normalizedLanguageCode + } + val targetLanguage = supportedLanguages.find { - it.code.split("-").first().lowercase() == normalizedLanguageCode + it.code.split("-").first().lowercase() == searchCode } ?: defaultLanguage - return targetLanguage.code.split("-").first().lowercase() + val baseCode = targetLanguage.code.split("-").first().lowercase() + + return when (baseCode) { + "in" -> "id" + else -> baseCode + } } } diff --git a/app/src/test/java/com/brainwallet/data/source/MessagingTopicDataSourceTest.kt b/app/src/test/java/com/brainwallet/data/source/MessagingTopicDataSourceTest.kt index cea284d5..57e51bd5 100644 --- a/app/src/test/java/com/brainwallet/data/source/MessagingTopicDataSourceTest.kt +++ b/app/src/test/java/com/brainwallet/data/source/MessagingTopicDataSourceTest.kt @@ -1,6 +1,5 @@ package com.brainwallet.data.source -import com.brainwallet.data.model.Language import org.junit.Before import org.junit.Test @@ -72,12 +71,45 @@ class MessagingTopicDataSourceTest { } } + @Test + fun `given Indonesian language code when getTopicsByLanguageCode called then it should normalize to id for backend consistency`() { + val result = dataSource.getTopicsByLanguageCode("in") + + val expectedTopics = listOf("initial_id", "news_id", "promo_id", "warn_id") + assert(result == expectedTopics) { + "Expected Indonesian language code 'in' to be normalized to 'id' for backend consistency but got $result" + } + } + + @Test + fun `given Indonesian locale with region when getTopicsByLanguageCode called then it should normalize to id`() { + val result = dataSource.getTopicsByLanguageCode("in_ID") + + val expectedTopics = listOf("initial_id", "news_id", "promo_id", "warn_id") + assert(result == expectedTopics) { + "Expected Indonesian locale 'in_ID' to be normalized to 'id' for backend consistency but got $result" + } + } + + @Test + fun `given id language code when getTopicsByLanguageCode called then it should be recognized as Indonesian`() { + val result = dataSource.getTopicsByLanguageCode("id") + + val expectedTopics = listOf("initial_id", "news_id", "promo_id", "warn_id") + assert(result == expectedTopics) { + "Expected 'id' language code to be recognized as Indonesian and return Indonesian topics but got $result" + } + } + @Test fun `given all supported languages when getTopicsByLanguageCode called then it should return correct base language topics`() { val testCases = mapOf( "en" to "en", - "es" to "es", - "in" to "in", + "es" to "es", + // Check All possible indonesian combination + "in" to "id", + "in_ID" to "id", + "id" to "id", "ar" to "ar", "uk" to "uk", "ru" to "ru",