Skip to content

Commit

Permalink
Make raw internal/Disable Android DB test
Browse files Browse the repository at this point in the history
  • Loading branch information
Daeda88 committed Apr 15, 2024
1 parent 6ba3fa0 commit 83f0192
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@file:JvmName("AndroidEncodedObject")
package dev.gitlive.firebase.internal

val EncodedObject.android: Map<String, Any?> get() = raw
val EncodedObject.android: Map<String, Any?> get() = getRaw()

@PublishedApi
internal actual fun Any.asNativeMap(): Map<*, *>? = this as? Map<*, *>
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import kotlin.jvm.JvmInline
* Platform specific object for storing encoded data that can be used for methods that explicitly require an object.
* This is essentially a [Map] of [String] and [Any]? (as represented by [raw]) but since [encode] gives a platform specific value, this method wraps that.
*/
sealed interface EncodedObject {
val raw: Map<String, Any?>
sealed interface EncodedObject

internal fun EncodedObject.getRaw(): Map<String, Any?> = when (this) {
is EncodedObjectImpl -> raw
}

@JvmInline
@PublishedApi
internal value class EncodedObjectImpl(override val raw: Map<String, Any?>) : EncodedObject
internal value class EncodedObjectImpl(val raw: Map<String, Any?>) : EncodedObject

@PublishedApi
internal expect fun Any.asNativeMap(): Map<*, *>?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,12 +428,12 @@ class EncodersTest {
testDataClass
) { encodeDefaults = false }

nativeAssertEquals(mapOf("map" to nativeMapOf("key" to "value"), "otherMap" to nativeMapOf(1 to 1), "bool" to true, "valueClass" to 42), encodedObject.raw)
nativeAssertEquals(mapOf("map" to nativeMapOf("key" to "value"), "otherMap" to nativeMapOf(1 to 1), "bool" to true, "valueClass" to 42), encodedObject.getRaw())

val testMap = mapOf("one" to 1, "two" to null, "three" to false)
assertEquals(testMap, encodeAsObject(testMap).raw)
assertEquals(testMap, encodeAsObject(testMap).getRaw())

assertEquals(emptyMap(), encodeAsObject(TestObject).raw)
assertEquals(emptyMap(), encodeAsObject(TestObject).getRaw())

assertFailsWith<IllegalArgumentException> {
encodeAsObject(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dev.gitlive.firebase.internal

val EncodedObject.ios: Map<Any?, *> get() = raw.mapKeys { (key, _) -> key }
val EncodedObject.ios: Map<Any?, *> get() = getRaw().mapKeys { (key, _) -> key }

@PublishedApi
internal actual fun Any.asNativeMap(): Map<*, *>? = this as? Map<*, *>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package dev.gitlive.firebase.internal
import kotlin.js.Json
import kotlin.js.json

val EncodedObject.js: Json get() = json(*raw.entries.map { (key, value) -> key to value }.toTypedArray())
val EncodedObject.js: Json get() = json(*getRaw().entries.map { (key, value) -> key to value }.toTypedArray())

@PublishedApi
internal actual fun Any.asNativeMap(): Map<*, *>? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
package dev.gitlive.firebase.database

import androidx.test.platform.app.InstrumentationRegistry
import org.junit.Ignore

actual val emulatorHost: String = "10.0.2.2"

actual val context: Any = InstrumentationRegistry.getInstrumentation().targetContext
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
actual annotation class IgnoreForAndroidUnitTest

actual typealias IgnoreForAndroidTest = Ignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ actual val emulatorHost: String = "10.0.2.2"

actual val context: Any = ""
actual typealias IgnoreForAndroidUnitTest = Ignore
actual typealias IgnoreForAndroidTest = Ignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import kotlin.time.Duration.Companion.minutes
expect val emulatorHost: String
expect val context: Any
expect annotation class IgnoreForAndroidUnitTest()
expect annotation class IgnoreForAndroidTest()

@IgnoreForAndroidUnitTest
class FirebaseDatabaseTest {
Expand Down Expand Up @@ -197,6 +198,8 @@ class FirebaseDatabaseTest {
assertFalse(valueEvents.first().exists)
}

// Ignoring on Android Instrumented Tests due to bug in Firebase: https://github.com/firebase/firebase-android-sdk/issues/5870
@IgnoreForAndroidTest
@Test
fun testUpdateChildrenOnDisconnect() = runTest {
setupRealtimeData()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ actual val context: Any = Unit

@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
actual annotation class IgnoreForAndroidUnitTest
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
actual annotation class IgnoreForAndroidTest
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ actual val context: Any = Unit

@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
actual annotation class IgnoreForAndroidUnitTest
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
actual annotation class IgnoreForAndroidTest
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ gradlePluginVersion=8.1.3
kotlinVersion=1.9.21
coroutinesVersion=1.7.3
serializationVersion=1.6.0
firebaseBoMVersion=32.7.0
firebaseBoMVersion=32.8.1
apiVersion=1.8
languageVersion=1.9

0 comments on commit 83f0192

Please sign in to comment.