File tree Expand file tree Collapse file tree
main/kotlin/com/revenuecat/purchases/ui/revenuecatui/data
test/kotlin/com/revenuecat/purchases/ui/revenuecatui/data Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -67,7 +67,8 @@ private fun JsonPrimitive.matchesDeclaredType(declaredType: StateDeclaration.Val
6767 when (declaredType) {
6868 StateDeclaration .ValueType .BOOLEAN -> ! isString && booleanOrNull != null
6969 StateDeclaration .ValueType .STRING -> isString
70- StateDeclaration .ValueType .INTEGER -> ! isString && longOrNull != null
70+ // Integral doubles are accepted for parity with iOS, which coerces them via Int(exactly:).
71+ StateDeclaration .ValueType .INTEGER -> ! isString && (longOrNull != null || doubleOrNull?.rem(1.0 ) == 0.0 )
7172 StateDeclaration .ValueType .DOUBLE -> ! isString && doubleOrNull != null
7273 StateDeclaration .ValueType .UNKNOWN -> false
7374 }
Original file line number Diff line number Diff line change @@ -74,6 +74,24 @@ internal class PaywallStateStoreTests {
7474 assertThat(store.currentValueOrDefault(" open" )).isEqualTo(JsonPrimitive (false ))
7575 }
7676
77+ @Test
78+ fun `accepts an integral double write to an integer-typed key` () {
79+ val store = PaywallStateStore (mapOf (" slide" to declaration(StateDeclaration .ValueType .INTEGER , JsonPrimitive (0 ))))
80+
81+ store.applyUpdates(listOf (setUpdate(" slide" , StateUpdateValue .Literal (JsonPrimitive (2.0 )))))
82+
83+ assertThat(store.currentValueOrDefault(" slide" )).isEqualTo(JsonPrimitive (2.0 ))
84+ }
85+
86+ @Test
87+ fun `ignores a fractional double write to an integer-typed key` () {
88+ val store = PaywallStateStore (mapOf (" slide" to declaration(StateDeclaration .ValueType .INTEGER , JsonPrimitive (0 ))))
89+
90+ store.applyUpdates(listOf (setUpdate(" slide" , StateUpdateValue .Literal (JsonPrimitive (2.5 )))))
91+
92+ assertThat(store.currentValueOrDefault(" slide" )).isEqualTo(JsonPrimitive (0 ))
93+ }
94+
7795 @Test
7896 fun `accepts an integer write to a double-typed key` () {
7997 val store = PaywallStateStore (mapOf (" ratio" to declaration(StateDeclaration .ValueType .DOUBLE , JsonPrimitive (0.0 ))))
You can’t perform that action at this time.
0 commit comments