Skip to content

Commit 0892b49

Browse files
committed
Merge branch 'feature/kotlin-2.0' into feature/api-validation
2 parents 4bf9531 + 7ce7eb9 commit 0892b49

File tree

3 files changed

+32
-2
lines changed
  • firebase-analytics/src/commonMain/kotlin/dev/gitlive/firebase/analytics
  • firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal
  • firebase-database/src/commonTest/kotlin/dev/gitlive/firebase/database

3 files changed

+32
-2
lines changed

firebase-analytics/src/commonMain/kotlin/dev/gitlive/firebase/analytics/AnalyticEventConstants.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ public object FirebaseAnalyticsParam {
101101
public const val PROMOTION_NAME: String = "promotion_name"
102102
public const val QUANTITY: String = "quantity"
103103
public const val SCORE: String = "score"
104+
public const val SCREEN_CLASS: String = "screen_class"
105+
public const val SCREEN_NAME: String = "screen_name"
104106
public const val SEARCH_TERM: String = "search_term"
105107
public const val SHIPPING: String = "shipping"
106108
public const val SHIPPING_TIER: String = "shipping_tier"

firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal/decoders.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,12 @@ private fun decodeShort(value: Any?) = when (value) {
211211
else -> throw SerializationException("Expected $value to be short")
212212
}
213213

214-
private fun decodeBoolean(value: Any?) = value as Boolean
214+
private fun decodeBoolean(value: Any?) = when (value) {
215+
is Boolean -> value
216+
is Number -> value.toInt() != 0
217+
is String -> value.toBoolean()
218+
else -> throw SerializationException("Expected $value to be boolean")
219+
}
215220

216221
private fun decodeChar(value: Any?) = when (value) {
217222
is Number -> value.toInt().toChar()

firebase-database/src/commonTest/kotlin/dev/gitlive/firebase/database/database.kt

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class FirebaseDatabaseTest {
3232
lateinit var database: FirebaseDatabase
3333

3434
@Serializable
35-
data class FirebaseDatabaseChildTest(val prop1: String? = null, val time: Double = 0.0)
35+
data class FirebaseDatabaseChildTest(val prop1: String? = null, val time: Double = 0.0, val boolean: Boolean = true)
3636

3737
@Serializable
3838
data class DatabaseTest(val title: String, val likes: Int = 0)
@@ -197,6 +197,29 @@ class FirebaseDatabaseTest {
197197
assertFalse(valueEvents.first().exists)
198198
}
199199

200+
@Test
201+
fun testBooleanValue() = runTest {
202+
ensureDatabaseConnected()
203+
val reference = database.reference("FirebaseRealtimeDatabaseBooleanTest")
204+
val falseRef = reference.child("false")
205+
val trueRef = reference.child("true")
206+
falseRef.setValue(false)
207+
trueRef.setValue(true)
208+
val falseValue = falseRef.valueEvents.first().value<Boolean>()
209+
val trueValue = trueRef.valueEvents.first().value<Boolean>()
210+
assertFalse(falseValue)
211+
assertTrue(trueValue)
212+
}
213+
214+
@Test
215+
fun testBooleanValueInChild() = runTest {
216+
ensureDatabaseConnected()
217+
val reference = database.reference("FirebaseRealtimeDatabaseBooleanInChildTest")
218+
reference.setValue(FirebaseDatabaseChildTest())
219+
val value = reference.valueEvents.first().value<FirebaseDatabaseChildTest>()
220+
assertEquals(FirebaseDatabaseChildTest(), value)
221+
}
222+
200223
// Ignoring on Android Instrumented Tests due to bug in Firebase: https://github.com/firebase/firebase-android-sdk/issues/5870
201224
@IgnoreForAndroidTest
202225
@Test

0 commit comments

Comments
 (0)