@react-native-firebase/app 26.3.3 → 27.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +75 -0
- package/README.md +10 -27
- package/RNFBApp.podspec +13 -5
- package/android/build.gradle +3 -0
- package/android/src/main/java/io/invertase/firebase/common/RNFBHandleCollisionException.kt +29 -0
- package/android/src/main/java/io/invertase/firebase/common/RNFBHandleMap.kt +146 -0
- package/android/src/main/java/io/invertase/firebase/common/TaskExecutorService.kt +156 -0
- package/android/src/main/java/io/invertase/firebase/common/UniversalFirebaseModule.kt +44 -0
- package/android/src/main/java/io/invertase/firebase/common/UniversalFirebasePreferences.kt +100 -0
- package/android/src/reactnative/java/io/invertase/firebase/app/NativeRNFBTurboApp.kt +250 -0
- package/android/src/reactnative/java/io/invertase/firebase/app/ReactNativeFirebaseApp.kt +64 -0
- package/android/src/reactnative/java/io/invertase/firebase/app/{ReactNativeFirebaseAppInitProvider.java → ReactNativeFirebaseAppInitProvider.kt} +3 -4
- package/android/src/reactnative/java/io/invertase/firebase/app/ReactNativeFirebaseAppPackage.kt +47 -0
- package/android/src/reactnative/java/io/invertase/firebase/app/ReactNativeFirebaseAppRegistrar.kt +33 -0
- package/android/src/reactnative/java/io/invertase/firebase/app/ReactNativeFirebaseVersion.java +1 -1
- package/android/src/reactnative/java/io/invertase/firebase/common/RCTConvertFirebase.kt +185 -0
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseEvent.kt +35 -0
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseEventEmitter.kt +662 -0
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseJSON.kt +103 -0
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseMeta.kt +96 -0
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseModule.kt +140 -0
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebasePreferences.kt +109 -0
- package/android/src/reactnative/java/io/invertase/firebase/common/SharedUtils.kt +451 -0
- package/android/src/reactnative/java/io/invertase/firebase/interfaces/{ContextProvider.java → ContextProvider.kt} +8 -8
- package/android/src/reactnative/java/io/invertase/firebase/interfaces/{NativeError.java → NativeError.kt} +8 -8
- package/android/src/reactnative/java/io/invertase/firebase/interfaces/{NativeEvent.java → NativeEvent.kt} +6 -6
- package/android/src/reactnative/java/io/invertase/firebase/utils/NativeRNFBTurboUtils.kt +219 -0
- package/android/src/test/java/expo/core/ModuleRegistry.java +9 -0
- package/android/src/test/java/io/invertase/firebase/app/NativeRNFBTurboAppTest.java +208 -60
- package/android/src/test/java/io/invertase/firebase/app/ReactNativeFirebaseAppComponentsJavaCompatibilityTest.java +70 -0
- package/android/src/test/java/io/invertase/firebase/app/ReactNativeFirebaseAppJavaCompatibilityTest.java +60 -0
- package/android/src/test/java/io/invertase/firebase/app/ReactNativeFirebaseAppPackageTest.java +165 -0
- package/android/src/test/java/io/invertase/firebase/app/ReactNativeFirebaseAppTest.kt +167 -0
- package/android/src/test/java/io/invertase/firebase/common/RCTConvertFirebaseJavaCompatibilityTest.java +112 -0
- package/android/src/test/java/io/invertase/firebase/common/RCTConvertFirebaseTest.kt +317 -0
- package/android/src/test/java/io/invertase/firebase/common/RNFBHandleMapTest.kt +309 -0
- package/android/src/test/java/io/invertase/firebase/common/ReactNativeFirebaseEventEmitterJavaCompatibilityTest.java +176 -0
- package/android/src/test/java/io/invertase/firebase/common/ReactNativeFirebaseEventEmitterTest.java +144 -13
- package/android/src/test/java/io/invertase/firebase/common/ReactNativeFirebaseEventTest.kt +61 -0
- package/android/src/test/java/io/invertase/firebase/common/ReactNativeFirebaseJSONJavaCompatibilityTest.java +85 -0
- package/android/src/test/java/io/invertase/firebase/common/ReactNativeFirebaseJSONTest.kt +296 -0
- package/android/src/test/java/io/invertase/firebase/common/ReactNativeFirebaseMetaJavaCompatibilityTest.java +67 -0
- package/android/src/test/java/io/invertase/firebase/common/ReactNativeFirebaseMetaTest.kt +246 -0
- package/android/src/test/java/io/invertase/firebase/common/ReactNativeFirebaseModuleTest.kt +254 -0
- package/android/src/test/java/io/invertase/firebase/common/ReactNativeFirebasePreferencesJavaCompatibilityTest.java +87 -0
- package/android/src/test/java/io/invertase/firebase/common/ReactNativeFirebasePreferencesTest.kt +260 -0
- package/android/src/test/java/io/invertase/firebase/common/SharedUtilsJavaCompatibilityTest.java +255 -0
- package/android/src/test/java/io/invertase/firebase/common/SharedUtilsTest.kt +674 -0
- package/android/src/test/java/io/invertase/firebase/common/TaskExecutorServiceTest.kt +290 -0
- package/android/src/test/java/io/invertase/firebase/common/UniversalFirebaseModuleJavaCompatibilityTest.java +178 -0
- package/android/src/test/java/io/invertase/firebase/common/UniversalFirebasePreferencesJavaCompatibilityTest.java +99 -0
- package/android/src/test/java/io/invertase/firebase/common/UniversalFirebasePreferencesTest.kt +217 -0
- package/android/src/test/java/io/invertase/firebase/commoncompat/ReactNativeFirebaseModuleJavaCompatibilityTest.java +176 -0
- package/android/src/test/java/io/invertase/firebase/commoncompat/ReactNativeFirebaseModuleKotlinCompatibilityTest.kt +52 -0
- package/android/src/test/java/io/invertase/firebase/interfaces/InterfacesJavaCompatibilityTest.java +144 -0
- package/android/src/test/java/io/invertase/firebase/interfaces/NativeEventTest.kt +56 -0
- package/android/src/test/java/io/invertase/firebase/utils/NativeRNFBTurboUtilsTest.java +517 -23
- package/dist/module/FirebaseApp.js +10 -0
- package/dist/module/FirebaseApp.js.map +1 -1
- package/dist/module/common/Base64.js +13 -21
- package/dist/module/common/Base64.js.map +1 -1
- package/dist/module/common/deeps.js +3 -0
- package/dist/module/common/deeps.js.map +1 -1
- package/dist/module/common/index.js +17 -9
- package/dist/module/common/index.js.map +1 -1
- package/dist/module/internal/FirebaseModule.js.map +1 -1
- package/dist/module/internal/RNFBNativeEventEmitter.js +12 -1
- package/dist/module/internal/RNFBNativeEventEmitter.js.map +1 -1
- package/dist/module/internal/SharedEventEmitter.js +3 -1
- package/dist/module/internal/SharedEventEmitter.js.map +1 -1
- package/dist/module/internal/asyncStorage.js +7 -11
- package/dist/module/internal/asyncStorage.js.map +1 -1
- package/dist/module/internal/index.js +1 -0
- package/dist/module/internal/index.js.map +1 -1
- package/dist/module/internal/logger.js +44 -40
- package/dist/module/internal/logger.js.map +1 -1
- package/dist/module/internal/nativeModuleAndroidIos.js +2 -29
- package/dist/module/internal/nativeModuleAndroidIos.js.map +1 -1
- package/dist/module/internal/nativeModuleDebug.js +74 -0
- package/dist/module/internal/nativeModuleDebug.js.map +1 -0
- package/dist/module/internal/nativeModuleWeb.js +9 -29
- package/dist/module/internal/nativeModuleWeb.js.map +1 -1
- package/dist/module/internal/registry/app.js +8 -2
- package/dist/module/internal/registry/app.js.map +1 -1
- package/dist/module/internal/registry/modular.js +2 -2
- package/dist/module/internal/registry/modular.js.map +1 -1
- package/dist/module/internal/registry/nativeModule.js +3 -3
- package/dist/module/internal/registry/nativeModule.js.map +1 -1
- package/dist/module/internal/web/RNFBAppModule.js +16 -15
- package/dist/module/internal/web/RNFBAppModule.js.map +1 -1
- package/dist/module/internal/web/memidb/lib/FakeEventTarget.js +3 -1
- package/dist/module/internal/web/memidb/lib/FakeEventTarget.js.map +1 -1
- package/dist/module/types/app.js.map +1 -1
- package/dist/module/types/internal.js +2 -0
- package/dist/module/version.js +1 -1
- package/dist/typescript/lib/FirebaseApp.d.ts +7 -0
- package/dist/typescript/lib/FirebaseApp.d.ts.map +1 -1
- package/dist/typescript/lib/common/Base64.d.ts.map +1 -1
- package/dist/typescript/lib/common/deeps.d.ts.map +1 -1
- package/dist/typescript/lib/common/index.d.ts.map +1 -1
- package/dist/typescript/lib/internal/FirebaseModule.d.ts +2 -3
- package/dist/typescript/lib/internal/FirebaseModule.d.ts.map +1 -1
- package/dist/typescript/lib/internal/NativeModules.d.ts +4 -1
- package/dist/typescript/lib/internal/NativeModules.d.ts.map +1 -1
- package/dist/typescript/lib/internal/RNFBNativeEventEmitter.d.ts +2 -2
- package/dist/typescript/lib/internal/RNFBNativeEventEmitter.d.ts.map +1 -1
- package/dist/typescript/lib/internal/SharedEventEmitter.d.ts +3 -3
- package/dist/typescript/lib/internal/SharedEventEmitter.d.ts.map +1 -1
- package/dist/typescript/lib/internal/asyncStorage.d.ts.map +1 -1
- package/dist/typescript/lib/internal/index.d.ts +1 -0
- package/dist/typescript/lib/internal/index.d.ts.map +1 -1
- package/dist/typescript/lib/internal/logger.d.ts.map +1 -1
- package/dist/typescript/lib/internal/nativeModuleAndroidIos.d.ts.map +1 -1
- package/dist/typescript/lib/internal/nativeModuleDebug.d.ts +2 -0
- package/dist/typescript/lib/internal/nativeModuleDebug.d.ts.map +1 -0
- package/dist/typescript/lib/internal/nativeModuleWeb.d.ts.map +1 -1
- package/dist/typescript/lib/internal/registry/app.d.ts.map +1 -1
- package/dist/typescript/lib/internal/web/RNFBAppModule.d.ts +7 -7
- package/dist/typescript/lib/internal/web/RNFBAppModule.d.ts.map +1 -1
- package/dist/typescript/lib/types/app.d.ts +10 -3
- package/dist/typescript/lib/types/app.d.ts.map +1 -1
- package/dist/typescript/lib/types/internal.d.ts +12 -0
- package/dist/typescript/lib/types/internal.d.ts.map +1 -1
- package/dist/typescript/lib/version.d.ts +1 -1
- package/firebase-schema.json +5 -1
- package/firebase_spm.rb +552 -96
- package/ios/RNFBApp/RCTConvert+FIRApp.h +2 -5
- package/ios/RNFBApp/RCTConvert+FIRApp.m +11 -6
- package/ios/RNFBApp/RCTConvert+FIROptions.h +2 -5
- package/ios/RNFBApp/RCTConvert+FIROptions.m +11 -10
- package/ios/RNFBApp/RCTConvertFIRApp.swift +86 -0
- package/ios/RNFBApp/RCTConvertFIROptions.swift +259 -0
- package/ios/RNFBApp/RNFBAppCustomAuthDomains.swift +63 -0
- package/ios/RNFBApp/RNFBAppInitializeOptionsMapper.swift +113 -0
- package/ios/RNFBApp/RNFBAppLogLevelMapper.swift +53 -0
- package/ios/RNFBApp/RNFBAppModule+CustomAuthDomain.m +35 -0
- package/ios/RNFBApp/RNFBAppModule.h +6 -2
- package/ios/RNFBApp/RNFBAppModule.mm +67 -204
- package/ios/RNFBApp/RNFBAppModuleFirebase.swift +439 -0
- package/ios/RNFBApp/RNFBAppModuleImplementation.h +68 -0
- package/ios/RNFBApp/RNFBAppModuleImplementation.m +195 -0
- package/ios/RNFBApp/RNFBHandleMap.h +73 -0
- package/ios/RNFBApp/RNFBHandleMap.m +87 -0
- package/ios/RNFBApp/RNFBHandleMapStorage.swift +90 -0
- package/ios/RNFBApp/RNFBInitializeAppArguments.swift +82 -0
- package/ios/RNFBApp/RNFBJSON.m +22 -38
- package/ios/RNFBApp/RNFBJSONImplementation.swift +71 -0
- package/ios/RNFBApp/RNFBMeta.m +24 -26
- package/ios/RNFBApp/RNFBMetaStorage.swift +76 -0
- package/ios/RNFBApp/RNFBNullSentinelDecoding.swift +135 -0
- package/ios/RNFBApp/RNFBNullSentinelInterceptor.h +30 -3
- package/ios/RNFBApp/RNFBNullSentinelInterceptor.m +28 -5
- package/ios/RNFBApp/RNFBPreferences.m +22 -20
- package/ios/RNFBApp/RNFBPreferencesStorage.swift +101 -0
- package/ios/RNFBApp/RNFBRCTEventEmitter.m +36 -93
- package/ios/RNFBApp/RNFBRCTEventEmitterCore.swift +161 -0
- package/ios/RNFBApp/RNFBSharedUtils.h +2 -5
- package/ios/RNFBApp/RNFBSharedUtils.m +109 -197
- package/ios/RNFBApp/RNFBSharedUtilsConfig.swift +72 -0
- package/ios/RNFBApp/RNFBSharedUtilsFIRApp.swift +271 -0
- package/ios/RNFBApp/RNFBSharedUtilsFormatting.swift +59 -0
- package/ios/RNFBApp/RNFBSharedUtilsPromiseRejection.swift +88 -0
- package/ios/RNFBApp/RNFBUtilsHelpers.swift +116 -0
- package/ios/RNFBApp/RNFBUtilsModule+Foundation.m +44 -0
- package/ios/RNFBApp/RNFBUtilsModule+PhotoAssets.m +47 -0
- package/ios/RNFBApp/RNFBUtilsModule.h +11 -1
- package/ios/RNFBApp/RNFBUtilsModule.mm +10 -85
- package/ios/RNFBApp/RNFBUtilsModuleImplementation.h +32 -0
- package/ios/RNFBApp/RNFBUtilsModuleImplementation.m +56 -0
- package/ios/RNFBApp/RNFBVersion.m +1 -1
- package/ios/RNFBApp.xcodeproj/project.pbxproj +106 -0
- package/ios/RNFBAppUnitTests/HostStubs/FirebaseCore/FIRApp.m +171 -0
- package/ios/RNFBAppUnitTests/HostStubs/FirebaseCore/FirebaseCore.h +78 -0
- package/ios/RNFBAppUnitTests/HostStubs/FirebaseInstallations/FIRInstallations.m +7 -0
- package/ios/RNFBAppUnitTests/HostStubs/FirebaseInstallations/FirebaseInstallations.h +8 -0
- package/ios/RNFBAppUnitTests/HostStubs/RNFBAppModuleHostStub.m +55 -0
- package/ios/RNFBAppUnitTests/HostStubs/RNFBAppTurboModules.h +89 -0
- package/ios/RNFBAppUnitTests/HostStubs/RNFBAppTurboModules.mm +30 -0
- package/ios/RNFBAppUnitTests/HostStubs/React/RCTBridge.h +19 -0
- package/ios/RNFBAppUnitTests/HostStubs/React/RCTBridge.m +32 -0
- package/ios/RNFBAppUnitTests/HostStubs/React/RCTBridgeModule.h +19 -0
- package/ios/RNFBAppUnitTests/HostStubs/React/RCTConvert.h +28 -0
- package/ios/RNFBAppUnitTests/HostStubs/React/RCTConvert.m +23 -0
- package/ios/RNFBAppUnitTests/HostStubs/React/RCTEventEmitter.h +9 -0
- package/ios/RNFBAppUnitTests/HostStubs/React/RCTInvalidating.h +24 -0
- package/ios/RNFBAppUnitTests/HostStubs/React/RCTUtils.h +9 -0
- package/ios/RNFBAppUnitTests/HostStubs/module.modulemap +13 -0
- package/ios/RNFBAppUnitTests/RCTConvertFIRAppFacadeTests.m +61 -0
- package/ios/RNFBAppUnitTests/RCTConvertFIRAppTests.swift +73 -0
- package/ios/RNFBAppUnitTests/RCTConvertFIROptionsFacadeTests.m +57 -0
- package/ios/RNFBAppUnitTests/RCTConvertFIROptionsTests.swift +243 -0
- package/ios/RNFBAppUnitTests/RNFBAppCustomAuthDomainsFacadeTests.m +73 -0
- package/ios/RNFBAppUnitTests/RNFBAppCustomAuthDomainsTests.swift +70 -0
- package/ios/RNFBAppUnitTests/RNFBAppInitializeOptionsMapperTests.swift +190 -0
- package/ios/RNFBAppUnitTests/RNFBAppLogLevelFacadeTests.m +76 -0
- package/ios/RNFBAppUnitTests/RNFBAppLogLevelMapperTests.swift +59 -0
- package/ios/RNFBAppUnitTests/RNFBAppModuleFirebaseFacadeTests.m +215 -0
- package/ios/RNFBAppUnitTests/RNFBAppModuleFirebaseTests.swift +430 -0
- package/ios/RNFBAppUnitTests/RNFBAppModuleLifecycleTests.m +206 -0
- package/ios/RNFBAppUnitTests/RNFBAppModuleShellTests.mm +367 -0
- package/ios/RNFBAppUnitTests/RNFBAppUnitTests.xcodeproj/project.pbxproj +590 -0
- package/ios/RNFBAppUnitTests/RNFBAppUnitTests.xcodeproj/xcshareddata/xcschemes/RNFBAppUnitTests.xcscheme +69 -0
- package/ios/RNFBAppUnitTests/RNFBFirebaseAppClientTests.swift +165 -0
- package/ios/RNFBAppUnitTests/RNFBHandleMapStorageTests.swift +121 -0
- package/ios/RNFBAppUnitTests/RNFBHandleMapTests.m +238 -0
- package/ios/RNFBAppUnitTests/RNFBInitializeAppArgumentsTests.swift +256 -0
- package/ios/RNFBAppUnitTests/RNFBJSONImplementationTests.swift +126 -0
- package/ios/RNFBAppUnitTests/RNFBJSONTests.m +172 -0
- package/ios/RNFBAppUnitTests/RNFBMetaStorageTests.swift +106 -0
- package/ios/RNFBAppUnitTests/RNFBMetaTests.m +65 -0
- package/ios/RNFBAppUnitTests/RNFBNullSentinelDecodingTests.swift +286 -0
- package/ios/RNFBAppUnitTests/RNFBNullSentinelInterceptorTests.m +312 -0
- package/ios/RNFBAppUnitTests/RNFBPreferencesStorageTests.swift +105 -0
- package/ios/RNFBAppUnitTests/RNFBPreferencesTests.m +110 -0
- package/ios/RNFBAppUnitTests/RNFBRCTEventEmitterCoreTests.swift +163 -0
- package/ios/RNFBAppUnitTests/RNFBRCTEventEmitterFacadeTests.m +141 -0
- package/ios/RNFBAppUnitTests/RNFBSharedUtilsConfigFacadeTests.m +100 -0
- package/ios/RNFBAppUnitTests/RNFBSharedUtilsConfigTests.swift +234 -0
- package/ios/RNFBAppUnitTests/RNFBSharedUtilsFIRAppFacadeTests.m +145 -0
- package/ios/RNFBAppUnitTests/RNFBSharedUtilsFIRAppTests.swift +173 -0
- package/ios/RNFBAppUnitTests/RNFBSharedUtilsFormattingFacadeTests.m +38 -0
- package/ios/RNFBAppUnitTests/RNFBSharedUtilsFormattingTests.swift +82 -0
- package/ios/RNFBAppUnitTests/RNFBSharedUtilsNullSentinelTests.m +35 -0
- package/ios/RNFBAppUnitTests/RNFBSharedUtilsPromiseRejectionFacadeTests.m +107 -0
- package/ios/RNFBAppUnitTests/RNFBSharedUtilsPromiseRejectionTests.swift +133 -0
- package/ios/RNFBAppUnitTests/RNFBUtilsHelpersTests.swift +144 -0
- package/ios/RNFBAppUnitTests/RNFBUtilsModuleFacadeTests.m +72 -0
- package/ios/RNFBAppUnitTests/RNFBUtilsModuleShellTests.mm +282 -0
- package/ios/RNFBFirebase/Package.swift +53 -0
- package/ios/RNFBFirebase/Sources/RNFBFirebase/RNFBFirebase.swift +285 -0
- package/ios/RNFBFirebase/Sources/RNFBFirebaseBridge/Public/.gitkeep +0 -0
- package/ios/RNFBFirebase/Sources/RNFBFirebaseBridge/RNFBFirebaseBridge.m +169 -0
- package/ios/RNFBFirebase/Sources/RNFBFirebaseBridge/include/RNFBFirebaseBridge.h +52 -0
- package/ios/RNFBFirebaseUnitTests/RNFBAppDynamicFacadeTests.swift +240 -0
- package/{android/src/reactnative/java/io/invertase/firebase/app/ReactNativeFirebaseAppRegistrar.java → ios/RNFBFirebaseUnitTests/RNFBFirebaseClientImport.swift} +22 -17
- package/ios/RNFBFirebaseUnitTests/RNFBFirebaseUnitTests.xcodeproj/project.pbxproj +588 -0
- package/ios/RNFBFirebaseUnitTests/RNFBFirebaseUnitTests.xcodeproj/xcshareddata/xcschemes/RNFBFirebaseUnitTests.xcscheme +83 -0
- package/ios_config.sh +50 -22
- package/lib/FirebaseApp.ts +10 -0
- package/lib/common/Base64.ts +10 -16
- package/lib/common/deeps.ts +3 -0
- package/lib/common/index.ts +20 -9
- package/lib/internal/FirebaseModule.ts +6 -3
- package/lib/internal/NativeModules.ts +4 -1
- package/lib/internal/RNFBNativeEventEmitter.ts +14 -5
- package/lib/internal/SharedEventEmitter.ts +5 -1
- package/lib/internal/asyncStorage.ts +7 -11
- package/lib/internal/index.ts +1 -0
- package/lib/internal/logger.ts +53 -43
- package/lib/internal/nativeModuleAndroidIos.ts +2 -40
- package/lib/internal/nativeModuleDebug.ts +97 -0
- package/lib/internal/nativeModuleWeb.ts +10 -40
- package/lib/internal/react-native-vendor-emitter.d.ts +11 -0
- package/lib/internal/registry/app.ts +8 -2
- package/lib/internal/registry/modular.ts +2 -2
- package/lib/internal/registry/nativeModule.ts +3 -3
- package/lib/internal/web/RNFBAppModule.ts +16 -15
- package/lib/internal/web/memidb/lib/FakeEventTarget.js +3 -1
- package/lib/types/app.ts +10 -3
- package/lib/types/internal.ts +19 -0
- package/lib/version.ts +1 -1
- package/package.json +9 -8
- package/plugin/build/ios/appDelegate.js +19 -9
- package/plugin/build/ios/podfile.js +16 -16
- package/plugin/build/pluginConfig.d.ts +4 -2
- package/plugin/src/ios/appDelegate.ts +45 -15
- package/plugin/src/ios/podfile.ts +20 -23
- package/plugin/src/pluginConfig.ts +4 -2
- package/android/src/main/java/io/invertase/firebase/common/TaskExecutorService.java +0 -124
- package/android/src/main/java/io/invertase/firebase/common/UniversalFirebaseModule.java +0 -62
- package/android/src/main/java/io/invertase/firebase/common/UniversalFirebasePreferences.java +0 -91
- package/android/src/reactnative/java/io/invertase/firebase/app/NativeRNFBTurboApp.java +0 -222
- package/android/src/reactnative/java/io/invertase/firebase/app/ReactNativeFirebaseApp.java +0 -46
- package/android/src/reactnative/java/io/invertase/firebase/app/ReactNativeFirebaseAppPackage.java +0 -49
- package/android/src/reactnative/java/io/invertase/firebase/common/RCTConvertFirebase.java +0 -191
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseEvent.java +0 -53
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseEventEmitter.java +0 -606
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseJSON.java +0 -107
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseMeta.java +0 -101
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseModule.java +0 -146
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebasePreferences.java +0 -96
- package/android/src/reactnative/java/io/invertase/firebase/common/SharedUtils.java +0 -441
- package/android/src/reactnative/java/io/invertase/firebase/utils/NativeRNFBTurboUtils.java +0 -223
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this library except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import Foundation
|
|
18
|
+
import XCTest
|
|
19
|
+
|
|
20
|
+
final class RNFBInitializeAppArgumentsTests: XCTestCase {
|
|
21
|
+
private func nullSentinel() -> NSDictionary {
|
|
22
|
+
["__rnfbNull": true] as NSDictionary
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
private func requiredOptions() -> NSDictionary {
|
|
26
|
+
[
|
|
27
|
+
"apiKey": "key",
|
|
28
|
+
"appId": "1:123:ios:abc",
|
|
29
|
+
"messagingSenderId": "123",
|
|
30
|
+
"projectId": "project",
|
|
31
|
+
] as NSDictionary
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
private func optionsByAdding(_ extra: [String: Any]) -> NSDictionary {
|
|
35
|
+
let options = NSMutableDictionary(dictionary: requiredOptions())
|
|
36
|
+
options.addEntries(from: extra)
|
|
37
|
+
return options
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
func testOptions_sentinelIosBundleId_isDropped() {
|
|
41
|
+
let result = RNFBInitializeAppArguments.normalizedOptions(
|
|
42
|
+
optionsByAdding(["iosBundleId": nullSentinel()])
|
|
43
|
+
)!
|
|
44
|
+
XCTAssertNil(result["iosBundleId"])
|
|
45
|
+
XCTAssertFalse(result.allKeys.contains { ($0 as? String) == "iosBundleId" })
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
func testOptions_sentinelIosClientId_isDropped() {
|
|
49
|
+
let result = RNFBInitializeAppArguments.normalizedOptions(
|
|
50
|
+
optionsByAdding(["iosClientId": nullSentinel()])
|
|
51
|
+
)!
|
|
52
|
+
XCTAssertFalse(result.allKeys.contains { ($0 as? String) == "iosClientId" })
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
func testOptions_sentinelAppGroupId_isDropped() {
|
|
56
|
+
let result = RNFBInitializeAppArguments.normalizedOptions(
|
|
57
|
+
optionsByAdding(["appGroupId": nullSentinel()])
|
|
58
|
+
)!
|
|
59
|
+
XCTAssertFalse(result.allKeys.contains { ($0 as? String) == "appGroupId" })
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
func testOptions_sentinelAuthDomain_isDropped() {
|
|
63
|
+
let result = RNFBInitializeAppArguments.normalizedOptions(
|
|
64
|
+
optionsByAdding(["authDomain": nullSentinel()])
|
|
65
|
+
)!
|
|
66
|
+
XCTAssertNil(result["authDomain"])
|
|
67
|
+
XCTAssertFalse(result.allKeys.contains { ($0 as? String) == "authDomain" })
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
func testOptions_sentinelDatabaseUrlAndStorageBucket_areDropped() {
|
|
71
|
+
let result = RNFBInitializeAppArguments.normalizedOptions(
|
|
72
|
+
optionsByAdding(["databaseURL": nullSentinel(), "storageBucket": nullSentinel()])
|
|
73
|
+
)!
|
|
74
|
+
XCTAssertFalse(result.allKeys.contains { ($0 as? String) == "databaseURL" })
|
|
75
|
+
XCTAssertFalse(result.allKeys.contains { ($0 as? String) == "storageBucket" })
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
func testOptions_plainNSNullOptionalKey_isDropped() {
|
|
79
|
+
let result = RNFBInitializeAppArguments.normalizedOptions(
|
|
80
|
+
optionsByAdding(["iosBundleId": NSNull()])
|
|
81
|
+
)!
|
|
82
|
+
XCTAssertFalse(result.allKeys.contains { ($0 as? String) == "iosBundleId" })
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
func testOptions_allOptionalKeysNull_onlyRequiredKeysRemain() {
|
|
86
|
+
let result = RNFBInitializeAppArguments.normalizedOptions(
|
|
87
|
+
optionsByAdding([
|
|
88
|
+
"databaseURL": nullSentinel(),
|
|
89
|
+
"storageBucket": nullSentinel(),
|
|
90
|
+
"iosBundleId": nullSentinel(),
|
|
91
|
+
"iosClientId": nullSentinel(),
|
|
92
|
+
"appGroupId": nullSentinel(),
|
|
93
|
+
"authDomain": nullSentinel(),
|
|
94
|
+
])
|
|
95
|
+
)
|
|
96
|
+
XCTAssertEqual(result, requiredOptions())
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
func testOptions_realStrings_areUnchanged() {
|
|
100
|
+
let input = optionsByAdding([
|
|
101
|
+
"databaseURL": "https://db.firebaseio.com",
|
|
102
|
+
"storageBucket": "bucket.appspot.com",
|
|
103
|
+
"iosBundleId": "com.example.app",
|
|
104
|
+
"iosClientId": "client-id",
|
|
105
|
+
"appGroupId": "group.com.example",
|
|
106
|
+
"authDomain": "example.firebaseapp.com",
|
|
107
|
+
])
|
|
108
|
+
XCTAssertEqual(RNFBInitializeAppArguments.normalizedOptions(input), input)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
func testOptions_nullOptionalKeyDoesNotAffectSiblingStrings() {
|
|
112
|
+
let result = RNFBInitializeAppArguments.normalizedOptions(
|
|
113
|
+
optionsByAdding([
|
|
114
|
+
"iosBundleId": nullSentinel(),
|
|
115
|
+
"iosClientId": "client-id",
|
|
116
|
+
"authDomain": "example.firebaseapp.com",
|
|
117
|
+
])
|
|
118
|
+
)!
|
|
119
|
+
XCTAssertFalse(result.allKeys.contains { ($0 as? String) == "iosBundleId" })
|
|
120
|
+
XCTAssertEqual(result["iosClientId"] as? String, "client-id")
|
|
121
|
+
XCTAssertEqual(result["authDomain"] as? String, "example.firebaseapp.com")
|
|
122
|
+
XCTAssertEqual(result["apiKey"] as? String, "key")
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
func testOptions_nonOptionalKeyWithNull_isLeftAsNSNull() {
|
|
126
|
+
let result = RNFBInitializeAppArguments.normalizedOptions(
|
|
127
|
+
optionsByAdding(["projectId": nullSentinel()])
|
|
128
|
+
)!
|
|
129
|
+
XCTAssertTrue(result["projectId"] is NSNull)
|
|
130
|
+
XCTAssertEqual(result["apiKey"] as? String, "key")
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
func testOptions_oneKeyDictionaryThatIsNotSentinel_isUnchanged() {
|
|
134
|
+
let input = ["apiKey": "key"] as NSDictionary
|
|
135
|
+
XCTAssertEqual(RNFBInitializeAppArguments.normalizedOptions(input), input)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
func testOptions_sentinelLookalikeValueForOptionalKey_isNotDropped() {
|
|
139
|
+
let notSentinel = ["__rnfbNull": false] as NSDictionary
|
|
140
|
+
let result = RNFBInitializeAppArguments.normalizedOptions(
|
|
141
|
+
optionsByAdding(["iosBundleId": notSentinel])
|
|
142
|
+
)!
|
|
143
|
+
XCTAssertEqual(result["iosBundleId"] as? NSDictionary, notSentinel)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
func testOptions_nil_returnsNil() {
|
|
147
|
+
XCTAssertNil(RNFBInitializeAppArguments.normalizedOptions(nil))
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
func testOptions_rootSentinel_returnsNil() {
|
|
151
|
+
XCTAssertNil(RNFBInitializeAppArguments.normalizedOptions(nullSentinel()))
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
func testOptions_doesNotMutateInput() {
|
|
155
|
+
let input = optionsByAdding(["iosBundleId": nullSentinel()])
|
|
156
|
+
let copy = input.copy() as! NSDictionary
|
|
157
|
+
_ = RNFBInitializeAppArguments.normalizedOptions(input)
|
|
158
|
+
XCTAssertEqual(input, copy)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
func testAppConfig_sentinelName_isDropped_andSentinelDataCollection_becomesNo() {
|
|
162
|
+
let result = RNFBInitializeAppArguments.normalizedAppConfig([
|
|
163
|
+
"name": nullSentinel(),
|
|
164
|
+
"automaticDataCollectionEnabled": nullSentinel(),
|
|
165
|
+
])!
|
|
166
|
+
XCTAssertEqual(result.count, 1)
|
|
167
|
+
XCTAssertNil(result["name"])
|
|
168
|
+
XCTAssertEqual(result["automaticDataCollectionEnabled"] as? Bool, false)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
func testAppConfig_nsNullDataCollection_becomesNo() {
|
|
172
|
+
let result = RNFBInitializeAppArguments.normalizedAppConfig([
|
|
173
|
+
"automaticDataCollectionEnabled": NSNull(),
|
|
174
|
+
])!
|
|
175
|
+
XCTAssertEqual(result["automaticDataCollectionEnabled"] as? Bool, false)
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
func testAppConfig_omittedDataCollection_staysOmitted() {
|
|
179
|
+
let result = RNFBInitializeAppArguments.normalizedAppConfig(["name": "secondary"])!
|
|
180
|
+
XCTAssertNil(result["automaticDataCollectionEnabled"])
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
func testAppConfig_realValues_areUnchanged() {
|
|
184
|
+
let input = ["name": "secondary", "automaticDataCollectionEnabled": true] as NSDictionary
|
|
185
|
+
XCTAssertEqual(RNFBInitializeAppArguments.normalizedAppConfig(input), input)
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
func testAppConfig_unknownKeyWithNull_isLeftAsNSNull() {
|
|
189
|
+
let result = RNFBInitializeAppArguments.normalizedAppConfig([
|
|
190
|
+
"name": "secondary",
|
|
191
|
+
"extra": nullSentinel(),
|
|
192
|
+
])!
|
|
193
|
+
XCTAssertEqual(result["name"] as? String, "secondary")
|
|
194
|
+
XCTAssertTrue(result["extra"] is NSNull)
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
func testAppConfig_nil_returnsNil() {
|
|
198
|
+
XCTAssertNil(RNFBInitializeAppArguments.normalizedAppConfig(nil))
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
func testAppConfig_rootSentinel_returnsNil() {
|
|
202
|
+
XCTAssertNil(RNFBInitializeAppArguments.normalizedAppConfig(nullSentinel()))
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
func testAutoDataCollection_yes_returnsYes() {
|
|
206
|
+
XCTAssertEqual(
|
|
207
|
+
RNFBInitializeAppArguments.automaticDataCollectionEnabled(fromAppConfig: [
|
|
208
|
+
"automaticDataCollectionEnabled": true,
|
|
209
|
+
]),
|
|
210
|
+
NSNumber(value: true)
|
|
211
|
+
)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
func testAutoDataCollection_explicitNo_returnsNo() {
|
|
215
|
+
let result = RNFBInitializeAppArguments.automaticDataCollectionEnabled(fromAppConfig: [
|
|
216
|
+
"automaticDataCollectionEnabled": false,
|
|
217
|
+
])
|
|
218
|
+
XCTAssertNotNil(result)
|
|
219
|
+
XCTAssertFalse(result!.boolValue)
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
func testAutoDataCollection_absentKey_returnsNil() {
|
|
223
|
+
XCTAssertNil(
|
|
224
|
+
RNFBInitializeAppArguments.automaticDataCollectionEnabled(fromAppConfig: ["name": "secondary"])
|
|
225
|
+
)
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
func testAutoDataCollection_nilAppConfig_returnsNil() {
|
|
229
|
+
XCTAssertNil(RNFBInitializeAppArguments.automaticDataCollectionEnabled(fromAppConfig: nil))
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
func testAutoDataCollection_NSNull_returnsNil() {
|
|
233
|
+
XCTAssertNil(
|
|
234
|
+
RNFBInitializeAppArguments.automaticDataCollectionEnabled(fromAppConfig: [
|
|
235
|
+
"automaticDataCollectionEnabled": NSNull(),
|
|
236
|
+
])
|
|
237
|
+
)
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
func testAutoDataCollection_sentinelNormalizedUpstream_returnsNo() {
|
|
241
|
+
let normalized = RNFBInitializeAppArguments.normalizedAppConfig([
|
|
242
|
+
"automaticDataCollectionEnabled": nullSentinel(),
|
|
243
|
+
])
|
|
244
|
+
let result = RNFBInitializeAppArguments.automaticDataCollectionEnabled(fromAppConfig: normalized)
|
|
245
|
+
XCTAssertNotNil(result)
|
|
246
|
+
XCTAssertFalse(result!.boolValue)
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
func testAutoDataCollection_nonNumberValue_returnsNil() {
|
|
250
|
+
XCTAssertNil(
|
|
251
|
+
RNFBInitializeAppArguments.automaticDataCollectionEnabled(fromAppConfig: [
|
|
252
|
+
"automaticDataCollectionEnabled": "true",
|
|
253
|
+
])
|
|
254
|
+
)
|
|
255
|
+
}
|
|
256
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this library except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import Foundation
|
|
18
|
+
import XCTest
|
|
19
|
+
|
|
20
|
+
final class RNFBJSONImplementationTests: XCTestCase {
|
|
21
|
+
private func base64(_ object: Any) throws -> String {
|
|
22
|
+
try JSONSerialization.data(withJSONObject: object).base64EncodedString()
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
func testNilInvalidBase64AndInvalidJSONProduceEmptyDictionaries() {
|
|
26
|
+
let implementations = [
|
|
27
|
+
RNFBJSONImplementation(rawValue: nil),
|
|
28
|
+
RNFBJSONImplementation(rawValue: "not base64"),
|
|
29
|
+
RNFBJSONImplementation(rawValue: Data("{".utf8).base64EncodedString()),
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
for implementation in implementations {
|
|
33
|
+
XCTAssertFalse(implementation.contains("missing"))
|
|
34
|
+
XCTAssertEqual(
|
|
35
|
+
implementation.value(forKey: "missing", defaultValue: "fallback" as NSString) as? String,
|
|
36
|
+
"fallback"
|
|
37
|
+
)
|
|
38
|
+
XCTAssertEqual(implementation.jsonObject() as? NSDictionary, NSDictionary())
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
func testValidObjectPreservesFoundationValuesAndDefaultsOnlyForNilLookup() throws {
|
|
43
|
+
let implementation = RNFBJSONImplementation(rawValue: try base64([
|
|
44
|
+
"boolean": true,
|
|
45
|
+
"number": 3,
|
|
46
|
+
"string": "value",
|
|
47
|
+
"array": ["one", 2],
|
|
48
|
+
"object": ["nested": "value"],
|
|
49
|
+
"null": NSNull(),
|
|
50
|
+
]))
|
|
51
|
+
|
|
52
|
+
XCTAssertTrue(implementation.contains("boolean"))
|
|
53
|
+
XCTAssertTrue(implementation.contains("null"))
|
|
54
|
+
XCTAssertFalse(implementation.contains("missing"))
|
|
55
|
+
XCTAssertEqual(
|
|
56
|
+
implementation.value(forKey: "missing", defaultValue: "fallback" as NSString) as? String,
|
|
57
|
+
"fallback"
|
|
58
|
+
)
|
|
59
|
+
XCTAssertTrue(implementation.value(
|
|
60
|
+
forKey: "null",
|
|
61
|
+
defaultValue: "fallback" as NSString
|
|
62
|
+
) is NSNull)
|
|
63
|
+
|
|
64
|
+
let parsed = implementation.jsonObject() as! NSDictionary
|
|
65
|
+
XCTAssertEqual(parsed["boolean"] as? Bool, true)
|
|
66
|
+
XCTAssertEqual(parsed["number"] as? Int, 3)
|
|
67
|
+
XCTAssertEqual(parsed["string"] as? String, "value")
|
|
68
|
+
XCTAssertEqual(parsed["array"] as? NSArray, ["one", 2] as NSArray)
|
|
69
|
+
XCTAssertEqual(parsed["object"] as? NSDictionary, ["nested": "value"] as NSDictionary)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
func testLookupMatchesNSDictionaryKVCForSpecialKeys() {
|
|
73
|
+
let dictionary: NSDictionary = [
|
|
74
|
+
"count": "count value",
|
|
75
|
+
"@count": "at-count value",
|
|
76
|
+
"description": "description value",
|
|
77
|
+
]
|
|
78
|
+
let implementation = RNFBJSONImplementation(jsonObject: dictionary)
|
|
79
|
+
|
|
80
|
+
for key in ["count", "@count", "description"] {
|
|
81
|
+
XCTAssertEqual(
|
|
82
|
+
implementation.value(forKey: key, defaultValue: nil) as? NSObject,
|
|
83
|
+
dictionary.value(forKey: key) as? NSObject
|
|
84
|
+
)
|
|
85
|
+
XCTAssertEqual(implementation.contains(key), dictionary.value(forKey: key) != nil)
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
func testValidTopLevelArrayIsPreserved() throws {
|
|
90
|
+
let implementation = RNFBJSONImplementation(rawValue: try base64(["one", 2]))
|
|
91
|
+
|
|
92
|
+
XCTAssertEqual(implementation.jsonObject() as? NSArray, ["one", 2] as NSArray)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
func testParsingIsAnInitializationSnapshot() throws {
|
|
96
|
+
let first = RNFBJSONImplementation(rawValue: try base64(["value": "first"]))
|
|
97
|
+
let second = RNFBJSONImplementation(rawValue: try base64(["value": "second"]))
|
|
98
|
+
|
|
99
|
+
XCTAssertEqual(first.value(forKey: "value", defaultValue: nil) as? String, "first")
|
|
100
|
+
XCTAssertEqual(second.value(forKey: "value", defaultValue: nil) as? String, "second")
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
func testRawJSONPreservesLegacyDecodeBehavior() {
|
|
104
|
+
XCTAssertEqual(RNFBJSONImplementation.rawJSON(from: nil), "{}")
|
|
105
|
+
XCTAssertNil(RNFBJSONImplementation.rawJSON(from: "not base64"))
|
|
106
|
+
|
|
107
|
+
let invalidJSON = "not JSON"
|
|
108
|
+
XCTAssertEqual(
|
|
109
|
+
RNFBJSONImplementation.rawJSON(
|
|
110
|
+
from: Data(invalidJSON.utf8).base64EncodedString()
|
|
111
|
+
),
|
|
112
|
+
invalidJSON
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
let invalidUTF8 = Data([0xff, 0xfe]).base64EncodedString()
|
|
116
|
+
XCTAssertNil(RNFBJSONImplementation.rawJSON(from: invalidUTF8))
|
|
117
|
+
|
|
118
|
+
let validJSON = #"{"value":true}"#
|
|
119
|
+
XCTAssertEqual(
|
|
120
|
+
RNFBJSONImplementation.rawJSON(
|
|
121
|
+
from: Data(validJSON.utf8).base64EncodedString()
|
|
122
|
+
),
|
|
123
|
+
validJSON
|
|
124
|
+
)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this library except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
#import <XCTest/XCTest.h>
|
|
18
|
+
|
|
19
|
+
#import "RNFBHandleMapStorage-Swift.inc"
|
|
20
|
+
#import "RNFBJSON.h"
|
|
21
|
+
|
|
22
|
+
@interface RNFBJSONTests : XCTestCase
|
|
23
|
+
@end
|
|
24
|
+
|
|
25
|
+
@implementation RNFBJSONTests
|
|
26
|
+
|
|
27
|
+
- (RNFBJSON *)jsonWithObject:(NSObject *)object {
|
|
28
|
+
RNFBJSON *json = [[RNFBJSON alloc] init];
|
|
29
|
+
RNFBJSONImplementation *implementation =
|
|
30
|
+
[[RNFBJSONImplementation alloc] initWithJSONObject:object];
|
|
31
|
+
[json setValue:implementation forKey:@"implementation"];
|
|
32
|
+
return json;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
- (void)testSharedUsesStableDispatchOnceIdentity {
|
|
36
|
+
RNFBJSON *first = RNFBJSON.shared;
|
|
37
|
+
XCTAssertNotNil(first);
|
|
38
|
+
XCTAssertIdentical(first, RNFBJSON.shared);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
- (void)testPublicSelectorsAndReturnEncodingsAreUnchanged {
|
|
42
|
+
NSArray<NSString *> *selectorNames = @[
|
|
43
|
+
@"contains:",
|
|
44
|
+
@"getBooleanValue:defaultValue:",
|
|
45
|
+
@"getStringValue:defaultValue:",
|
|
46
|
+
@"getArrayValue:defaultValue:",
|
|
47
|
+
@"getAll",
|
|
48
|
+
@"getRawJSON",
|
|
49
|
+
];
|
|
50
|
+
for (NSString *selectorName in selectorNames) {
|
|
51
|
+
XCTAssertTrue([[RNFBJSON shared] respondsToSelector:NSSelectorFromString(selectorName)]);
|
|
52
|
+
}
|
|
53
|
+
XCTAssertTrue([RNFBJSON respondsToSelector:@selector(shared)]);
|
|
54
|
+
|
|
55
|
+
NSMethodSignature *contains = [RNFBJSON instanceMethodSignatureForSelector:@selector(contains:)];
|
|
56
|
+
XCTAssertEqual(strcmp(contains.methodReturnType, @encode(BOOL)), 0);
|
|
57
|
+
NSMethodSignature *boolean =
|
|
58
|
+
[RNFBJSON instanceMethodSignatureForSelector:@selector(getBooleanValue:defaultValue:)];
|
|
59
|
+
XCTAssertEqual(strcmp(boolean.methodReturnType, @encode(BOOL)), 0);
|
|
60
|
+
XCTAssertEqual(strcmp([boolean getArgumentTypeAtIndex:3], @encode(BOOL)), 0);
|
|
61
|
+
|
|
62
|
+
NSArray<NSString *> *objectReturnSelectors = @[
|
|
63
|
+
@"getStringValue:defaultValue:", @"getArrayValue:defaultValue:", @"getAll", @"getRawJSON"
|
|
64
|
+
];
|
|
65
|
+
for (NSString *selectorName in objectReturnSelectors) {
|
|
66
|
+
NSMethodSignature *signature =
|
|
67
|
+
[RNFBJSON instanceMethodSignatureForSelector:NSSelectorFromString(selectorName)];
|
|
68
|
+
XCTAssertEqual(strcmp(signature.methodReturnType, @encode(id)), 0);
|
|
69
|
+
}
|
|
70
|
+
NSMethodSignature *shared = [RNFBJSON methodSignatureForSelector:@selector(shared)];
|
|
71
|
+
XCTAssertEqual(strcmp(shared.methodReturnType, @encode(id)), 0);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
- (void)testFacadePreservesKVCContainsDefaultsAndUncheckedObjectReturns {
|
|
75
|
+
NSDictionary *dictionary = @{
|
|
76
|
+
@"boolean" : @YES,
|
|
77
|
+
@"booleanFalse" : @NO,
|
|
78
|
+
@"numericZero" : @0,
|
|
79
|
+
@"booleanString" : @"YES",
|
|
80
|
+
@"string" : @"value",
|
|
81
|
+
@"array" : @[ @"one" ],
|
|
82
|
+
@"numberAsString" : @42,
|
|
83
|
+
@"stringAsArray" : @"unchecked",
|
|
84
|
+
@"null" : NSNull.null,
|
|
85
|
+
@"count" : @"count value",
|
|
86
|
+
@"@count" : @"at-count value",
|
|
87
|
+
};
|
|
88
|
+
RNFBJSON *json = [self jsonWithObject:dictionary];
|
|
89
|
+
|
|
90
|
+
XCTAssertTrue([json contains:@"boolean"]);
|
|
91
|
+
XCTAssertTrue([json contains:@"booleanFalse"]);
|
|
92
|
+
XCTAssertTrue([json contains:@"numericZero"]);
|
|
93
|
+
XCTAssertTrue([json contains:@"null"]);
|
|
94
|
+
XCTAssertFalse([json contains:@"missing"]);
|
|
95
|
+
XCTAssertTrue([json getBooleanValue:@"boolean" defaultValue:NO]);
|
|
96
|
+
XCTAssertFalse([json getBooleanValue:@"booleanFalse" defaultValue:YES]);
|
|
97
|
+
XCTAssertFalse([json getBooleanValue:@"numericZero" defaultValue:YES]);
|
|
98
|
+
XCTAssertTrue([json getBooleanValue:@"booleanString" defaultValue:NO]);
|
|
99
|
+
XCTAssertTrue([json getBooleanValue:@"missing" defaultValue:YES]);
|
|
100
|
+
XCTAssertEqualObjects([json getStringValue:@"missing" defaultValue:@"fallback"], @"fallback");
|
|
101
|
+
XCTAssertEqualObjects([json getArrayValue:@"missing" defaultValue:@[ @"fallback" ]],
|
|
102
|
+
(@[ @"fallback" ]));
|
|
103
|
+
XCTAssertEqualObjects([json getStringValue:@"string" defaultValue:@"fallback"], @"value");
|
|
104
|
+
XCTAssertEqualObjects([json getArrayValue:@"array" defaultValue:@[]], (@[ @"one" ]));
|
|
105
|
+
|
|
106
|
+
id uncheckedString = [json getStringValue:@"numberAsString" defaultValue:@"fallback"];
|
|
107
|
+
id uncheckedArray = [json getArrayValue:@"stringAsArray" defaultValue:@[]];
|
|
108
|
+
XCTAssertEqualObjects(uncheckedString, @42);
|
|
109
|
+
XCTAssertEqualObjects(uncheckedArray, @"unchecked");
|
|
110
|
+
XCTAssertIdentical([json getStringValue:@"null" defaultValue:@"fallback"], NSNull.null);
|
|
111
|
+
|
|
112
|
+
for (NSString *key in @[ @"count", @"@count" ]) {
|
|
113
|
+
XCTAssertEqualObjects([json getStringValue:key defaultValue:@"fallback"],
|
|
114
|
+
[dictionary valueForKey:key]);
|
|
115
|
+
XCTAssertEqual([json contains:key], [dictionary valueForKey:key] != nil);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
- (void)testGetBooleanValueThrowsForNSNullArrayAndDictionaryReceivers {
|
|
120
|
+
NSDictionary *dictionary = @{
|
|
121
|
+
@"null" : NSNull.null,
|
|
122
|
+
@"array" : @[ @"one" ],
|
|
123
|
+
@"object" : @{@"nested" : @"value"},
|
|
124
|
+
};
|
|
125
|
+
RNFBJSON *json = [self jsonWithObject:dictionary];
|
|
126
|
+
|
|
127
|
+
XCTAssertThrowsSpecificNamed([json getBooleanValue:@"null" defaultValue:YES], NSException,
|
|
128
|
+
NSInvalidArgumentException);
|
|
129
|
+
XCTAssertThrowsSpecificNamed([json getBooleanValue:@"array" defaultValue:YES], NSException,
|
|
130
|
+
NSInvalidArgumentException);
|
|
131
|
+
XCTAssertThrowsSpecificNamed([json getBooleanValue:@"object" defaultValue:YES], NSException,
|
|
132
|
+
NSInvalidArgumentException);
|
|
133
|
+
|
|
134
|
+
@try {
|
|
135
|
+
[json getBooleanValue:@"null" defaultValue:YES];
|
|
136
|
+
XCTFail(@"expected NSNull boolValue to throw");
|
|
137
|
+
} @catch (NSException *exception) {
|
|
138
|
+
XCTAssertEqualObjects(exception.name, NSInvalidArgumentException);
|
|
139
|
+
XCTAssertTrue([exception.reason containsString:@"boolValue"]);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
- (void)testGetAllCopiesItemsAndReturnsIndependentImmutableSnapshot {
|
|
144
|
+
NSMutableString *mutableString = [NSMutableString stringWithString:@"before"];
|
|
145
|
+
NSMutableArray *mutableArray = [NSMutableArray arrayWithObject:@"first"];
|
|
146
|
+
NSDictionary *source = @{@"string" : mutableString, @"array" : mutableArray};
|
|
147
|
+
RNFBJSON *json = [self jsonWithObject:source];
|
|
148
|
+
|
|
149
|
+
NSDictionary *snapshot = [json getAll];
|
|
150
|
+
|
|
151
|
+
XCTAssertNotIdentical(snapshot, source);
|
|
152
|
+
XCTAssertNotIdentical(snapshot[@"string"], mutableString);
|
|
153
|
+
XCTAssertNotIdentical(snapshot[@"array"], mutableArray);
|
|
154
|
+
[mutableString appendString:@"-after"];
|
|
155
|
+
[mutableArray addObject:@"second"];
|
|
156
|
+
XCTAssertEqualObjects(snapshot[@"string"], @"before");
|
|
157
|
+
XCTAssertEqualObjects(snapshot[@"array"], (@[ @"first" ]));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
- (void)testGetAllPreservesNonDictionaryExceptionBehavior {
|
|
161
|
+
RNFBJSON *json = [self jsonWithObject:@[ @"valid", @"JSON", @"array" ]];
|
|
162
|
+
|
|
163
|
+
XCTAssertThrowsSpecificNamed([json getAll], NSException, NSInvalidArgumentException);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
- (void)testRawFacadeUsesCurrentBundleValueAndSwiftDecoder {
|
|
167
|
+
NSString *raw = [[NSBundle mainBundle].infoDictionary valueForKey:@"firebase_json_raw"];
|
|
168
|
+
XCTAssertEqualObjects([RNFBJSON.shared getRawJSON],
|
|
169
|
+
[RNFBJSONImplementation rawJSONFromRawValue:raw]);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
@end
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this library except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import Foundation
|
|
18
|
+
import XCTest
|
|
19
|
+
|
|
20
|
+
final class RNFBMetaStorageTests: XCTestCase {
|
|
21
|
+
private func storage(_ plist: [String: Any]) -> RNFBMetaStorage {
|
|
22
|
+
RNFBMetaStorage(infoDictionary: plist)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
func testMissingKeysUseDefaultsAndAreNotContained() {
|
|
26
|
+
let meta = storage([:])
|
|
27
|
+
|
|
28
|
+
XCTAssertFalse(meta.contains("missing"))
|
|
29
|
+
XCTAssertTrue(meta.getBooleanValue("missing", defaultValue: true))
|
|
30
|
+
XCTAssertFalse(meta.getBooleanValue("missing", defaultValue: false))
|
|
31
|
+
XCTAssertEqual(meta.getStringValue("missing", defaultValue: "fallback"), "fallback")
|
|
32
|
+
XCTAssertEqual(meta.getAll() as NSDictionary, NSDictionary())
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
func testPrefixIsAppliedAndUnprefixedKeysAreIgnored() {
|
|
36
|
+
let meta = storage([
|
|
37
|
+
"rnfirebase_present": "value",
|
|
38
|
+
"other_key": "ignored",
|
|
39
|
+
"rnfirebase": "not-prefixed-enough",
|
|
40
|
+
])
|
|
41
|
+
|
|
42
|
+
XCTAssertTrue(meta.contains("present"))
|
|
43
|
+
XCTAssertFalse(meta.contains("other_key"))
|
|
44
|
+
XCTAssertEqual(meta.getStringValue("present", defaultValue: "fallback"), "value")
|
|
45
|
+
XCTAssertEqual(meta.getStringValue("other_key", defaultValue: "fallback"), "fallback")
|
|
46
|
+
|
|
47
|
+
let all = meta.getAll()
|
|
48
|
+
XCTAssertEqual(all as NSDictionary, ["rnfirebase_present": "value"] as NSDictionary)
|
|
49
|
+
XCTAssertNil(all["other_key"])
|
|
50
|
+
XCTAssertNil(all["rnfirebase"])
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
func testGetAllReturnsPrefixedKeysUnstripped() {
|
|
54
|
+
let meta = storage([
|
|
55
|
+
"rnfirebase_string": "abc",
|
|
56
|
+
"rnfirebase_boolean_true": true,
|
|
57
|
+
"rnfirebase_boolean_false": false,
|
|
58
|
+
"unrelated": 1,
|
|
59
|
+
])
|
|
60
|
+
|
|
61
|
+
let all = meta.getAll()
|
|
62
|
+
XCTAssertEqual(Set(all.keys), Set([
|
|
63
|
+
"rnfirebase_string",
|
|
64
|
+
"rnfirebase_boolean_true",
|
|
65
|
+
"rnfirebase_boolean_false",
|
|
66
|
+
]))
|
|
67
|
+
XCTAssertEqual(all["rnfirebase_string"] as? String, "abc")
|
|
68
|
+
XCTAssertEqual(all["rnfirebase_boolean_true"] as? Bool, true)
|
|
69
|
+
XCTAssertEqual(all["rnfirebase_boolean_false"] as? Bool, false)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
func testPresentBooleanFalseAndNumericZeroOverrideDefaultYes() {
|
|
73
|
+
let meta = storage([
|
|
74
|
+
"rnfirebase_boolFalse": false,
|
|
75
|
+
"rnfirebase_numericZero": 0,
|
|
76
|
+
"rnfirebase_boolTrue": true,
|
|
77
|
+
"rnfirebase_numericOne": 1,
|
|
78
|
+
"rnfirebase_boolStringYes": "YES",
|
|
79
|
+
"rnfirebase_boolStringNo": "0",
|
|
80
|
+
])
|
|
81
|
+
|
|
82
|
+
XCTAssertTrue(meta.contains("boolFalse"))
|
|
83
|
+
XCTAssertTrue(meta.contains("numericZero"))
|
|
84
|
+
XCTAssertFalse(meta.getBooleanValue("boolFalse", defaultValue: true))
|
|
85
|
+
XCTAssertFalse(meta.getBooleanValue("numericZero", defaultValue: true))
|
|
86
|
+
XCTAssertTrue(meta.getBooleanValue("boolTrue", defaultValue: false))
|
|
87
|
+
XCTAssertTrue(meta.getBooleanValue("numericOne", defaultValue: false))
|
|
88
|
+
XCTAssertTrue(meta.getBooleanValue("boolStringYes", defaultValue: false))
|
|
89
|
+
XCTAssertFalse(meta.getBooleanValue("boolStringNo", defaultValue: true))
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
func testStringLookupPreservesPresentValues() {
|
|
93
|
+
let meta = storage([
|
|
94
|
+
"rnfirebase_string": "abc",
|
|
95
|
+
])
|
|
96
|
+
|
|
97
|
+
XCTAssertEqual(meta.getStringValue("string", defaultValue: "fallback"), "abc")
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
func testDefaultInitializerUsesMainBundleInfoDictionary() {
|
|
101
|
+
let production = RNFBMetaStorage()
|
|
102
|
+
let fromBundle = RNFBMetaStorage(infoDictionary: Bundle.main.infoDictionary ?? [:])
|
|
103
|
+
|
|
104
|
+
XCTAssertEqual(production.getAll() as NSDictionary, fromBundle.getAll() as NSDictionary)
|
|
105
|
+
}
|
|
106
|
+
}
|