@react-native-firebase/app 26.4.0 → 27.1.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 +62 -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 +182 -59
- 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 +143 -12
- 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 -21
- package/dist/module/FirebaseApp.js +10 -0
- package/dist/module/FirebaseApp.js.map +1 -1
- package/dist/module/common/deeps.js +3 -0
- package/dist/module/common/deeps.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/index.js +1 -0
- package/dist/module/internal/index.js.map +1 -1
- package/dist/module/internal/registry/app.js +7 -1
- package/dist/module/internal/registry/app.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/deeps.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/index.d.ts +1 -0
- package/dist/typescript/lib/internal/index.d.ts.map +1 -1
- package/dist/typescript/lib/internal/registry/app.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 +4 -0
- 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 +65 -228
- 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.m +27 -56
- 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 -198
- 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 +100 -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 +355 -2
- package/ios/RNFBAppUnitTests/RNFBFirebaseAppClientTests.swift +165 -0
- package/ios/RNFBAppUnitTests/RNFBHandleMapStorageTests.swift +121 -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/main/java/io/invertase/firebase/common/RNFBHandleCollisionException.java → ios/RNFBFirebaseUnitTests/RNFBFirebaseClientImport.swift} +23 -14
- 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/deeps.ts +3 -0
- 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/index.ts +1 -0
- package/lib/internal/react-native-vendor-emitter.d.ts +11 -0
- package/lib/internal/registry/app.ts +7 -1
- package/lib/types/app.ts +10 -3
- package/lib/types/internal.ts +19 -0
- package/lib/version.ts +1 -1
- package/package.json +8 -8
- package/plugin/build/ios/appDelegate.js +2 -2
- package/plugin/build/ios/podfile.js +16 -16
- package/plugin/build/pluginConfig.d.ts +4 -2
- package/plugin/src/ios/appDelegate.ts +2 -2
- package/plugin/src/ios/podfile.ts +20 -23
- package/plugin/src/pluginConfig.ts +4 -2
- package/android/src/main/java/io/invertase/firebase/common/RNFBHandleMap.java +0 -150
- package/android/src/main/java/io/invertase/firebase/common/TaskExecutorService.java +0 -148
- 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 -224
- 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/app/ReactNativeFirebaseAppRegistrar.java +0 -35
- package/android/src/reactnative/java/io/invertase/firebase/common/RCTConvertFirebase.java +0 -192
- 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 -109
- 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
- package/android/src/test/java/io/invertase/firebase/common/RNFBHandleMapTest.java +0 -275
- package/android/src/test/java/io/invertase/firebase/common/ReactNativeFirebaseJSONTest.java +0 -108
- package/android/src/test/java/io/invertase/firebase/common/TaskExecutorServiceTest.java +0 -97
|
@@ -0,0 +1,173 @@
|
|
|
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
|
+
private final class StubFIROptions: NSObject, RNFBFIROptionsProviding {
|
|
21
|
+
var apiKey: String?
|
|
22
|
+
var googleAppID: String?
|
|
23
|
+
var projectID: String?
|
|
24
|
+
var databaseURL: String?
|
|
25
|
+
var storageBucket: String?
|
|
26
|
+
var gcmSenderID: String?
|
|
27
|
+
var clientID: String?
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
private final class StubFIRApp: NSObject, RNFBFIRAppProviding {
|
|
31
|
+
var name: String
|
|
32
|
+
var options: RNFBFIROptionsProviding
|
|
33
|
+
var dataCollectionEnabled = false
|
|
34
|
+
|
|
35
|
+
init(name: String, options: RNFBFIROptionsProviding) {
|
|
36
|
+
self.name = name
|
|
37
|
+
self.options = options
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
func isDataCollectionDefaultEnabled() -> Bool {
|
|
41
|
+
dataCollectionEnabled
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
private final class StubCustomDomainProvider: NSObject, RNFBCustomDomainProviding {
|
|
46
|
+
var domains: [String: String] = [:]
|
|
47
|
+
var lastRequestedName: String?
|
|
48
|
+
|
|
49
|
+
func getCustomDomain(_ appName: String) -> String? {
|
|
50
|
+
lastRequestedName = appName
|
|
51
|
+
return domains[appName]
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
private final class RecordingEventSender: NSObject, RNFBJSEventSending {
|
|
56
|
+
var lastName: String?
|
|
57
|
+
var lastBody: Any?
|
|
58
|
+
|
|
59
|
+
func sendEvent(name: String, body: Any?) {
|
|
60
|
+
lastName = name
|
|
61
|
+
lastBody = body
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
final class RNFBSharedUtilsFIRAppTests: XCTestCase {
|
|
66
|
+
private func fullyPopulatedOptions() -> StubFIROptions {
|
|
67
|
+
let options = StubFIROptions()
|
|
68
|
+
options.apiKey = "api-key"
|
|
69
|
+
options.googleAppID = "app-id"
|
|
70
|
+
options.projectID = "project-id"
|
|
71
|
+
options.databaseURL = "https://example.firebaseio.com"
|
|
72
|
+
options.storageBucket = "example.appspot.com"
|
|
73
|
+
options.gcmSenderID = "sender-id"
|
|
74
|
+
options.clientID = "client-id"
|
|
75
|
+
return options
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
func testDefaultAppNameMapsToDisplayName() {
|
|
79
|
+
let app = StubFIRApp(name: "__FIRAPP_DEFAULT", options: fullyPopulatedOptions())
|
|
80
|
+
app.dataCollectionEnabled = true
|
|
81
|
+
let domains = StubCustomDomainProvider()
|
|
82
|
+
|
|
83
|
+
let result = RNFBSharedUtilsFIRApp.firAppToDictionary(app, customDomainProvider: domains)
|
|
84
|
+
let appConfig = result["appConfig"] as? NSDictionary
|
|
85
|
+
|
|
86
|
+
XCTAssertEqual(appConfig?["name"] as? String, "[DEFAULT]")
|
|
87
|
+
XCTAssertEqual(appConfig?["automaticDataCollectionEnabled"] as? Bool, true)
|
|
88
|
+
XCTAssertEqual(domains.lastRequestedName, "[DEFAULT]")
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
func testNamedAppPreservesName() {
|
|
92
|
+
let app = StubFIRApp(name: "secondary", options: fullyPopulatedOptions())
|
|
93
|
+
let domains = StubCustomDomainProvider()
|
|
94
|
+
|
|
95
|
+
let result = RNFBSharedUtilsFIRApp.firAppToDictionary(app, customDomainProvider: domains)
|
|
96
|
+
let appConfig = result["appConfig"] as? NSDictionary
|
|
97
|
+
|
|
98
|
+
XCTAssertEqual(appConfig?["name"] as? String, "secondary")
|
|
99
|
+
XCTAssertEqual(domains.lastRequestedName, "secondary")
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
func testOptionsFieldMapping() {
|
|
103
|
+
let app = StubFIRApp(name: "secondary", options: fullyPopulatedOptions())
|
|
104
|
+
let domains = StubCustomDomainProvider()
|
|
105
|
+
|
|
106
|
+
let result = RNFBSharedUtilsFIRApp.firAppToDictionary(app, customDomainProvider: domains)
|
|
107
|
+
let options = result["options"] as? NSDictionary
|
|
108
|
+
|
|
109
|
+
XCTAssertEqual(options?["apiKey"] as? String, "api-key")
|
|
110
|
+
XCTAssertEqual(options?["appId"] as? String, "app-id")
|
|
111
|
+
XCTAssertEqual(options?["projectId"] as? String, "project-id")
|
|
112
|
+
XCTAssertEqual(options?["databaseURL"] as? String, "https://example.firebaseio.com")
|
|
113
|
+
XCTAssertEqual(options?["storageBucket"] as? String, "example.appspot.com")
|
|
114
|
+
XCTAssertEqual(options?["messagingSenderId"] as? String, "sender-id")
|
|
115
|
+
XCTAssertEqual(options?["clientId"] as? String, "client-id")
|
|
116
|
+
XCTAssertNil(options?["authDomain"])
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
func testAuthDomainPresentWhenProviderReturnsValue() {
|
|
120
|
+
let app = StubFIRApp(name: "secondary", options: fullyPopulatedOptions())
|
|
121
|
+
let domains = StubCustomDomainProvider()
|
|
122
|
+
domains.domains["secondary"] = "custom.example.com"
|
|
123
|
+
|
|
124
|
+
let result = RNFBSharedUtilsFIRApp.firAppToDictionary(app, customDomainProvider: domains)
|
|
125
|
+
let options = result["options"] as? NSDictionary
|
|
126
|
+
|
|
127
|
+
XCTAssertEqual(options?["authDomain"] as? String, "custom.example.com")
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
func testAuthDomainAbsentWhenProviderReturnsNil() {
|
|
131
|
+
let app = StubFIRApp(name: "__FIRAPP_DEFAULT", options: fullyPopulatedOptions())
|
|
132
|
+
let domains = StubCustomDomainProvider()
|
|
133
|
+
|
|
134
|
+
let result = RNFBSharedUtilsFIRApp.firAppToDictionary(app, customDomainProvider: domains)
|
|
135
|
+
let options = result["options"] as? NSDictionary
|
|
136
|
+
|
|
137
|
+
XCTAssertNil(options?["authDomain"])
|
|
138
|
+
XCTAssertEqual(domains.lastRequestedName, "[DEFAULT]")
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
func testSendJSEventInjectsAppNameAndForwards() {
|
|
142
|
+
let app = StubFIRApp(name: "__FIRAPP_DEFAULT", options: fullyPopulatedOptions())
|
|
143
|
+
let sender = RecordingEventSender()
|
|
144
|
+
let body: NSDictionary = ["foo": "bar"]
|
|
145
|
+
|
|
146
|
+
RNFBSharedUtilsFIRApp.sendJSEvent(
|
|
147
|
+
forApp: app,
|
|
148
|
+
name: "app_event",
|
|
149
|
+
body: body,
|
|
150
|
+
eventSender: sender
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
XCTAssertEqual(sender.lastName, "app_event")
|
|
154
|
+
let forwarded = sender.lastBody as? NSDictionary
|
|
155
|
+
XCTAssertEqual(forwarded?["foo"] as? String, "bar")
|
|
156
|
+
XCTAssertEqual(forwarded?["appName"] as? String, "[DEFAULT]")
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
func testSendJSEventPreservesNamedAppName() {
|
|
160
|
+
let app = StubFIRApp(name: "secondary", options: fullyPopulatedOptions())
|
|
161
|
+
let sender = RecordingEventSender()
|
|
162
|
+
|
|
163
|
+
RNFBSharedUtilsFIRApp.sendJSEvent(
|
|
164
|
+
forApp: app,
|
|
165
|
+
name: "named_event",
|
|
166
|
+
body: [:],
|
|
167
|
+
eventSender: sender
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
let forwarded = sender.lastBody as? NSDictionary
|
|
171
|
+
XCTAssertEqual(forwarded?["appName"] as? String, "secondary")
|
|
172
|
+
}
|
|
173
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
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 "RNFBSharedUtils.h"
|
|
21
|
+
|
|
22
|
+
@interface RNFBSharedUtilsFormattingFacadeTests : XCTestCase
|
|
23
|
+
@end
|
|
24
|
+
|
|
25
|
+
@implementation RNFBSharedUtilsFormattingFacadeTests
|
|
26
|
+
|
|
27
|
+
- (void)testFacadeMapsDefaultAppName {
|
|
28
|
+
XCTAssertEqualObjects([RNFBSharedUtils getAppJavaScriptName:DEFAULT_APP_NAME],
|
|
29
|
+
DEFAULT_APP_DISPLAY_NAME);
|
|
30
|
+
XCTAssertEqualObjects([RNFBSharedUtils getAppJavaScriptName:@"secondary"], @"secondary");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
- (void)testFacadeFormatsISO8601WithTrailingZ {
|
|
34
|
+
NSDate *date = [NSDate dateWithTimeIntervalSince1970:1577934245];
|
|
35
|
+
XCTAssertEqualObjects([RNFBSharedUtils getISO8601String:date], @"2020-01-02T03:04:05Z");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@end
|
|
@@ -0,0 +1,82 @@
|
|
|
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 RNFBSharedUtilsFormattingTests: XCTestCase {
|
|
21
|
+
func testDefaultAppNameMapsToDisplayName() {
|
|
22
|
+
XCTAssertEqual(
|
|
23
|
+
RNFBSharedUtilsFormatting.getAppJavaScriptName("__FIRAPP_DEFAULT"),
|
|
24
|
+
"[DEFAULT]"
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
func testNonDefaultAppNameIsReturnedUnchanged() {
|
|
29
|
+
XCTAssertEqual(
|
|
30
|
+
RNFBSharedUtilsFormatting.getAppJavaScriptName("secondary"),
|
|
31
|
+
"secondary"
|
|
32
|
+
)
|
|
33
|
+
XCTAssertEqual(
|
|
34
|
+
RNFBSharedUtilsFormatting.getAppJavaScriptName("[DEFAULT]"),
|
|
35
|
+
"[DEFAULT]"
|
|
36
|
+
)
|
|
37
|
+
XCTAssertEqual(RNFBSharedUtilsFormatting.getAppJavaScriptName(""), "")
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
func testNilAppNameReturnsNil() {
|
|
41
|
+
XCTAssertNil(RNFBSharedUtilsFormatting.getAppJavaScriptName(nil))
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
func testISO8601UsesPOSIXUTCAndTrailingZ() {
|
|
45
|
+
var components = DateComponents()
|
|
46
|
+
components.calendar = Calendar(identifier: .gregorian)
|
|
47
|
+
components.timeZone = TimeZone(abbreviation: "UTC")
|
|
48
|
+
components.year = 2020
|
|
49
|
+
components.month = 1
|
|
50
|
+
components.day = 2
|
|
51
|
+
components.hour = 3
|
|
52
|
+
components.minute = 4
|
|
53
|
+
components.second = 5
|
|
54
|
+
|
|
55
|
+
let date = components.date!
|
|
56
|
+
XCTAssertEqual(
|
|
57
|
+
RNFBSharedUtilsFormatting.getISO8601String(date),
|
|
58
|
+
"2020-01-02T03:04:05Z"
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
func testISO8601FormatsInUTCRegardlessOfLocalOffset() {
|
|
63
|
+
// 2020-01-02 03:04:05 UTC as absolute instant; format must stay UTC/`Z`.
|
|
64
|
+
let date = Date(timeIntervalSince1970: 1_577_934_245)
|
|
65
|
+
XCTAssertEqual(
|
|
66
|
+
RNFBSharedUtilsFormatting.getISO8601String(date),
|
|
67
|
+
"2020-01-02T03:04:05Z"
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
func testISO8601OmitsFractionalSeconds() {
|
|
72
|
+
let date = Date(timeIntervalSince1970: 1_577_934_245.789)
|
|
73
|
+
XCTAssertEqual(
|
|
74
|
+
RNFBSharedUtilsFormatting.getISO8601String(date),
|
|
75
|
+
"2020-01-02T03:04:05Z"
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
func testNilDateReturnsNil() {
|
|
80
|
+
XCTAssertNil(RNFBSharedUtilsFormatting.getISO8601String(nil))
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
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 "RNFBSharedUtils.h"
|
|
21
|
+
|
|
22
|
+
@interface RNFBSharedUtilsNullSentinelTests : XCTestCase
|
|
23
|
+
@end
|
|
24
|
+
|
|
25
|
+
@implementation RNFBSharedUtilsNullSentinelTests
|
|
26
|
+
|
|
27
|
+
- (void)testFacadeForwardsSentinelAndNonContainer {
|
|
28
|
+
NSDictionary *sentinel = @{@"__rnfbNull" : @YES};
|
|
29
|
+
XCTAssertTrue([[RNFBSharedUtils decodeNullSentinels:sentinel] isKindOfClass:[NSNull class]]);
|
|
30
|
+
|
|
31
|
+
NSNumber *number = @42;
|
|
32
|
+
XCTAssertTrue([RNFBSharedUtils decodeNullSentinels:number] == number);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@end
|
|
@@ -0,0 +1,107 @@
|
|
|
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 "RNFBSharedUtils.h"
|
|
21
|
+
|
|
22
|
+
@interface RNFBSharedUtilsPromiseRejectionFacadeTests : XCTestCase
|
|
23
|
+
@end
|
|
24
|
+
|
|
25
|
+
@implementation RNFBSharedUtilsPromiseRejectionFacadeTests
|
|
26
|
+
|
|
27
|
+
- (void)testFacadeExceptionPath {
|
|
28
|
+
NSException *exception = [NSException exceptionWithName:@"FacadeException"
|
|
29
|
+
reason:@"facade boom"
|
|
30
|
+
userInfo:nil];
|
|
31
|
+
|
|
32
|
+
__block NSString *capturedCode = nil;
|
|
33
|
+
__block NSString *capturedMessage = nil;
|
|
34
|
+
__block NSError *capturedError = nil;
|
|
35
|
+
|
|
36
|
+
[RNFBSharedUtils
|
|
37
|
+
rejectPromiseWithExceptionDict:^(NSString *code, NSString *message, NSError *error) {
|
|
38
|
+
capturedCode = code;
|
|
39
|
+
capturedMessage = message;
|
|
40
|
+
capturedError = error;
|
|
41
|
+
}
|
|
42
|
+
exception:exception];
|
|
43
|
+
|
|
44
|
+
XCTAssertEqualObjects(capturedCode, @"FacadeException");
|
|
45
|
+
XCTAssertEqualObjects(capturedMessage, @"facade boom");
|
|
46
|
+
XCTAssertEqualObjects(capturedError.domain, @"RNFBErrorDomain");
|
|
47
|
+
XCTAssertEqual(capturedError.code, 666);
|
|
48
|
+
XCTAssertEqualObjects(capturedError.userInfo[@"fatal"], @YES);
|
|
49
|
+
XCTAssertEqualObjects(capturedError.userInfo[@"code"], @"unknown");
|
|
50
|
+
XCTAssertEqualObjects(capturedError.userInfo[@"message"], @"facade boom");
|
|
51
|
+
XCTAssertEqualObjects(capturedError.userInfo[@"nativeErrorCode"], @"FacadeException");
|
|
52
|
+
XCTAssertEqualObjects(capturedError.userInfo[@"nativeErrorMessage"], @"facade boom");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
- (void)testFacadeNSErrorPath {
|
|
56
|
+
NSError *source = [NSError errorWithDomain:@"SourceDomain"
|
|
57
|
+
code:7
|
|
58
|
+
userInfo:@{NSLocalizedDescriptionKey : @"ns fail"}];
|
|
59
|
+
|
|
60
|
+
__block NSString *capturedCode = nil;
|
|
61
|
+
__block NSString *capturedMessage = nil;
|
|
62
|
+
__block NSError *capturedError = nil;
|
|
63
|
+
|
|
64
|
+
[RNFBSharedUtils
|
|
65
|
+
rejectPromiseWithNSError:^(NSString *code, NSString *message, NSError *error) {
|
|
66
|
+
capturedCode = code;
|
|
67
|
+
capturedMessage = message;
|
|
68
|
+
capturedError = error;
|
|
69
|
+
}
|
|
70
|
+
error:source];
|
|
71
|
+
|
|
72
|
+
XCTAssertEqualObjects(capturedCode, @"unknown");
|
|
73
|
+
XCTAssertEqualObjects(capturedMessage, @"ns fail");
|
|
74
|
+
XCTAssertEqualObjects(capturedError.domain, @"RNFBErrorDomain");
|
|
75
|
+
XCTAssertEqual(capturedError.code, 666);
|
|
76
|
+
XCTAssertEqualObjects(capturedError.userInfo[@"fatal"], @NO);
|
|
77
|
+
XCTAssertEqualObjects(capturedError.userInfo[@"nativeErrorCode"], @7);
|
|
78
|
+
XCTAssertEqualObjects(capturedError.userInfo[@"nativeErrorMessage"], @"ns fail");
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
- (void)testFacadeUserInfoPath {
|
|
82
|
+
NSMutableDictionary *userInfo = [@{
|
|
83
|
+
@"code" : @"storage/unknown",
|
|
84
|
+
@"message" : @"user info reject",
|
|
85
|
+
} mutableCopy];
|
|
86
|
+
|
|
87
|
+
__block NSString *capturedCode = nil;
|
|
88
|
+
__block NSString *capturedMessage = nil;
|
|
89
|
+
__block NSError *capturedError = nil;
|
|
90
|
+
|
|
91
|
+
[RNFBSharedUtils
|
|
92
|
+
rejectPromiseWithUserInfo:^(NSString *code, NSString *message, NSError *error) {
|
|
93
|
+
capturedCode = code;
|
|
94
|
+
capturedMessage = message;
|
|
95
|
+
capturedError = error;
|
|
96
|
+
}
|
|
97
|
+
userInfo:userInfo];
|
|
98
|
+
|
|
99
|
+
XCTAssertEqualObjects(capturedCode, @"storage/unknown");
|
|
100
|
+
XCTAssertEqualObjects(capturedMessage, @"user info reject");
|
|
101
|
+
XCTAssertEqualObjects(capturedError.domain, @"RNFBErrorDomain");
|
|
102
|
+
XCTAssertEqual(capturedError.code, 666);
|
|
103
|
+
XCTAssertEqualObjects(capturedError.userInfo[@"code"], @"storage/unknown");
|
|
104
|
+
XCTAssertEqualObjects(capturedError.userInfo[@"message"], @"user info reject");
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
@end
|
|
@@ -0,0 +1,133 @@
|
|
|
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 RNFBSharedUtilsPromiseRejectionTests: XCTestCase {
|
|
21
|
+
private let expectedDomain = "RNFBErrorDomain"
|
|
22
|
+
private let expectedCode = 666
|
|
23
|
+
|
|
24
|
+
func testExceptionPathRejectArgsAndUserInfo() {
|
|
25
|
+
let exception = NSException(
|
|
26
|
+
name: NSExceptionName("SomeException"),
|
|
27
|
+
reason: "boom reason",
|
|
28
|
+
userInfo: nil
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
var capturedCode: String?
|
|
32
|
+
var capturedMessage: String?
|
|
33
|
+
var capturedError: NSError?
|
|
34
|
+
|
|
35
|
+
RNFBSharedUtilsPromiseRejection.rejectPromise(withException: { code, message, error in
|
|
36
|
+
capturedCode = code
|
|
37
|
+
capturedMessage = message
|
|
38
|
+
capturedError = error as NSError?
|
|
39
|
+
}, exception: exception)
|
|
40
|
+
|
|
41
|
+
XCTAssertEqual(capturedCode, "SomeException")
|
|
42
|
+
XCTAssertEqual(capturedMessage, "boom reason")
|
|
43
|
+
XCTAssertEqual(capturedError?.domain, expectedDomain)
|
|
44
|
+
XCTAssertEqual(capturedError?.code, expectedCode)
|
|
45
|
+
|
|
46
|
+
let userInfo = capturedError?.userInfo ?? [:]
|
|
47
|
+
XCTAssertEqual(userInfo["fatal"] as? Bool, true)
|
|
48
|
+
XCTAssertEqual(userInfo["code"] as? String, "unknown")
|
|
49
|
+
XCTAssertEqual(userInfo["message"] as? String, "boom reason")
|
|
50
|
+
XCTAssertEqual(userInfo["nativeErrorCode"] as? String, "SomeException")
|
|
51
|
+
XCTAssertEqual(userInfo["nativeErrorMessage"] as? String, "boom reason")
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
func testExceptionPathNilReasonOmitsMessageKeys() {
|
|
55
|
+
let exception = NSException(
|
|
56
|
+
name: NSExceptionName("NilReason"),
|
|
57
|
+
reason: nil,
|
|
58
|
+
userInfo: nil
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
var capturedMessage: String?
|
|
62
|
+
var capturedError: NSError?
|
|
63
|
+
|
|
64
|
+
RNFBSharedUtilsPromiseRejection.rejectPromise(withException: { _, message, error in
|
|
65
|
+
capturedMessage = message
|
|
66
|
+
capturedError = error as NSError?
|
|
67
|
+
}, exception: exception)
|
|
68
|
+
|
|
69
|
+
XCTAssertNil(capturedMessage)
|
|
70
|
+
let userInfo = capturedError?.userInfo ?? [:]
|
|
71
|
+
XCTAssertNil(userInfo["message"])
|
|
72
|
+
XCTAssertNil(userInfo["nativeErrorMessage"])
|
|
73
|
+
XCTAssertEqual(userInfo["fatal"] as? Bool, true)
|
|
74
|
+
XCTAssertEqual(userInfo["code"] as? String, "unknown")
|
|
75
|
+
XCTAssertEqual(userInfo["nativeErrorCode"] as? String, "NilReason")
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
func testNSErrorPathRejectArgsAndUserInfo() {
|
|
79
|
+
let source = NSError(
|
|
80
|
+
domain: "SourceDomain",
|
|
81
|
+
code: 42,
|
|
82
|
+
userInfo: [NSLocalizedDescriptionKey: "localized fail"]
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
var capturedCode: String?
|
|
86
|
+
var capturedMessage: String?
|
|
87
|
+
var capturedError: NSError?
|
|
88
|
+
|
|
89
|
+
RNFBSharedUtilsPromiseRejection.rejectPromise(withNSError: { code, message, error in
|
|
90
|
+
capturedCode = code
|
|
91
|
+
capturedMessage = message
|
|
92
|
+
capturedError = error as NSError?
|
|
93
|
+
}, error: source)
|
|
94
|
+
|
|
95
|
+
XCTAssertEqual(capturedCode, "unknown")
|
|
96
|
+
XCTAssertEqual(capturedMessage, "localized fail")
|
|
97
|
+
XCTAssertEqual(capturedError?.domain, expectedDomain)
|
|
98
|
+
XCTAssertEqual(capturedError?.code, expectedCode)
|
|
99
|
+
|
|
100
|
+
let userInfo = capturedError?.userInfo ?? [:]
|
|
101
|
+
XCTAssertEqual(userInfo["fatal"] as? Bool, false)
|
|
102
|
+
XCTAssertEqual(userInfo["code"] as? String, "unknown")
|
|
103
|
+
XCTAssertEqual(userInfo["message"] as? String, "localized fail")
|
|
104
|
+
XCTAssertEqual(userInfo["nativeErrorCode"] as? NSNumber, NSNumber(value: 42))
|
|
105
|
+
XCTAssertEqual(userInfo["nativeErrorMessage"] as? String, "localized fail")
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
func testUserInfoPathRejectArgsAndError() {
|
|
109
|
+
let userInfo: NSMutableDictionary = [
|
|
110
|
+
"code": "auth/invalid",
|
|
111
|
+
"message": "bad creds",
|
|
112
|
+
"extra": "kept",
|
|
113
|
+
]
|
|
114
|
+
|
|
115
|
+
var capturedCode: String?
|
|
116
|
+
var capturedMessage: String?
|
|
117
|
+
var capturedError: NSError?
|
|
118
|
+
|
|
119
|
+
RNFBSharedUtilsPromiseRejection.rejectPromise(withUserInfo: { code, message, error in
|
|
120
|
+
capturedCode = code
|
|
121
|
+
capturedMessage = message
|
|
122
|
+
capturedError = error as NSError?
|
|
123
|
+
}, userInfo: userInfo)
|
|
124
|
+
|
|
125
|
+
XCTAssertEqual(capturedCode, "auth/invalid")
|
|
126
|
+
XCTAssertEqual(capturedMessage, "bad creds")
|
|
127
|
+
XCTAssertEqual(capturedError?.domain, expectedDomain)
|
|
128
|
+
XCTAssertEqual(capturedError?.code, expectedCode)
|
|
129
|
+
XCTAssertEqual(capturedError?.userInfo["code"] as? String, "auth/invalid")
|
|
130
|
+
XCTAssertEqual(capturedError?.userInfo["message"] as? String, "bad creds")
|
|
131
|
+
XCTAssertEqual(capturedError?.userInfo["extra"] as? String, "kept")
|
|
132
|
+
}
|
|
133
|
+
}
|