v6 - Core - Unit tests for model, localization and session params helpers - #2950
v6 - Core - Unit tests for model, localization and session params helpers#2950araratthehero wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces comprehensive unit tests for several core utility classes, including JsonUtils, ModelUtils, LocalizationResolver, and SessionParamsFactory, along with a MockModelObject helper. A review comment points out that the test for formatting localized strings with arguments does not verify if the shopper's locale is respected, as Kotlin's String.format extension defaults to the system locale. It suggests updating the test to use a locale-sensitive argument and a specific locale to ensure correct formatting.
| fun `when format args are passed, then the string is formatted with them`() { | ||
| val result = getLocalizedString( | ||
| localizationProvider = FakeLocalizationProvider("Pay %s"), | ||
| key = CheckoutLocalizationKey.PAY_BUTTON_WITH_AMOUNT, | ||
| formatArgs = arrayOf("EUR 10.00"), | ||
| ) | ||
|
|
||
| assertEquals("Pay EUR 10.00", result) | ||
| } | ||
|
|
There was a problem hiding this comment.
The current test formats the string using a String argument ("EUR 10.00"), which does not verify whether the formatting respects the shopper's locale.
In LocalizationResolver.getLocalizedStringFor, the formatting is performed using string.format(*formatArgs). In Kotlin, this extension function defaults to Locale.getDefault(), ignoring the shopper's locale parameter passed to the method. This can lead to incorrect formatting of locale-sensitive values (such as decimals, currencies, or dates) on devices with different system locales.
To expose and prevent this issue, we should update the test to use a locale-sensitive format argument (like a Double) and a specific locale (like Locale.FRANCE), asserting that the output is formatted correctly according to that locale. Note that fixing this test will require updating LocalizationResolver.kt to use string.format(locale, *formatArgs).
| fun `when format args are passed, then the string is formatted with them`() { | |
| val result = getLocalizedString( | |
| localizationProvider = FakeLocalizationProvider("Pay %s"), | |
| key = CheckoutLocalizationKey.PAY_BUTTON_WITH_AMOUNT, | |
| formatArgs = arrayOf("EUR 10.00"), | |
| ) | |
| assertEquals("Pay EUR 10.00", result) | |
| } | |
| @Test | |
| fun whenFormatArgsArePassedThenTheStringIsFormattedUsingTheShopperLocale() { | |
| val result = getLocalizedString( | |
| localizationProvider = FakeLocalizationProvider("Pay %.2f"), | |
| key = CheckoutLocalizationKey.PAY_BUTTON_WITH_AMOUNT, | |
| locale = Locale.FRANCE, | |
| formatArgs = arrayOf(10.00), | |
| ) | |
| assertEquals("Pay 10,00", result) | |
| } |
✅ No public API changes |
|



Description
Adds unit tests for four
corehelpers that had no coverage.Checklist
Ticket Number
COSDK-546