Skip to content

Commit

Permalink
Fixed failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
Daeda88 committed Apr 19, 2024
1 parent 844f0b4 commit 5a28653
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ val LocalCacheSettings.android: com.google.firebase.firestore.LocalCacheSettings
private val callbackExecutorMap = ConcurrentHashMap<com.google.firebase.firestore.FirebaseFirestore, Executor>()

actual typealias NativeFirebaseFirestore = com.google.firebase.firestore.FirebaseFirestore
actual internal class NativeFirebaseFirestoreWrapper actual constructor(actual val native: NativeFirebaseFirestore) {
internal actual class NativeFirebaseFirestoreWrapper actual constructor(actual val native: NativeFirebaseFirestore) {

actual var settings: FirebaseFirestoreSettings
get() = with(native.firestoreSettings) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class FirebaseFirestore internal constructor(private val wrapper: NativeFirebase

constructor(native: NativeFirebaseFirestore) : this(NativeFirebaseFirestoreWrapper(native))

val native = wrapper.native
// Important to leave this as a get property since on JS it is initialized lazily
val native get() = wrapper.native
var settings: FirebaseFirestoreSettings
get() = wrapper.settings
set(value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ class FirestoreSourceTest {

firestore = Firebase.firestore(app).apply {
useEmulator(emulatorHost, 8080)
setSettings(persistenceEnabled = persistenceEnabled)
settings = firestoreSettings(settings) {
cacheSettings = if (persistenceEnabled) {
persistentCacheSettings { }
} else {
memoryCacheSettings { }
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ val LocalCacheSettings.ios: FIRLocalCacheSettingsProtocol get() = when (this) {
actual typealias NativeFirebaseFirestore = FIRFirestore

@Suppress("UNCHECKED_CAST")
actual internal class NativeFirebaseFirestoreWrapper internal actual constructor(actual val native: NativeFirebaseFirestore) {
internal actual class NativeFirebaseFirestoreWrapper internal actual constructor(actual val native: NativeFirebaseFirestore) {

actual var settings: FirebaseFirestoreSettings = firestoreSettings { }.also {
native.settings = it.ios
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ actual fun Firebase.firestore(app: FirebaseApp) =

actual data class NativeFirebaseFirestore(val js: JsFirestore)

actual internal class NativeFirebaseFirestoreWrapper internal constructor(
internal actual class NativeFirebaseFirestoreWrapper internal constructor(
private val createNative: NativeFirebaseFirestoreWrapper.() -> NativeFirebaseFirestore
){

Expand All @@ -98,13 +98,21 @@ actual internal class NativeFirebaseFirestoreWrapper internal constructor(
private data class EmulatorSettings(val host: String, val port: Int)

actual var settings: FirebaseFirestoreSettings = FirebaseFirestoreSettings.Builder().build()
set(value) {
if (lazyNative.isInitialized()) {
throw IllegalStateException("FirebaseFirestore has already been started and its settings can no longer be changed. You can only call setFirestoreSettings() before calling any other methods on a FirebaseFirestore object.")
} else {
field = value
}
}
private var emulatorSettings: EmulatorSettings? = null

// initializeFirestore must be called before any call, including before `getFirestore()`
// To allow settings to be updated, we defer creating the wrapper until the first call to `native`
actual val native: NativeFirebaseFirestore by lazy {
private val lazyNative = lazy {
createNative()
}
actual val native: NativeFirebaseFirestore by lazyNative
private val js get() = native.js

actual fun collection(collectionPath: String) = rethrow { NativeCollectionReference(jsCollection(js, collectionPath)) }
Expand Down

0 comments on commit 5a28653

Please sign in to comment.