@react-native-firebase/analytics 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.
Files changed (31) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/RNFBAnalytics.podspec +49 -2
  3. package/dist/module/index.js +2 -2
  4. package/dist/module/index.js.map +1 -1
  5. package/dist/module/version.js +1 -1
  6. package/dist/typescript/lib/index.d.ts.map +1 -1
  7. package/dist/typescript/lib/version.d.ts +1 -1
  8. package/ios/RNFBAnalytics/RNFBAnalyticsConsentSettingsMapper.swift +98 -0
  9. package/ios/RNFBAnalytics/RNFBAnalyticsHelper.h +111 -0
  10. package/ios/RNFBAnalytics/RNFBAnalyticsHelper.m +338 -0
  11. package/ios/RNFBAnalytics/RNFBAnalyticsJavascriptParamsCleaner.swift +167 -0
  12. package/ios/RNFBAnalytics/RNFBAnalyticsModule.mm +32 -282
  13. package/ios/RNFBAnalytics.xcodeproj/project.pbxproj +16 -2
  14. package/ios/RNFBAnalyticsUnitTests/HostStubs/Firebase/FIRAnalyticsHostStub.m +304 -0
  15. package/ios/RNFBAnalyticsUnitTests/HostStubs/Firebase/Firebase.h +71 -0
  16. package/ios/RNFBAnalyticsUnitTests/HostStubs/RNFBAnalytics/RNFBAnalyticsLogTransactionHostStub.h +20 -0
  17. package/ios/RNFBAnalyticsUnitTests/HostStubs/RNFBAnalytics/RNFBAnalyticsLogTransactionHostStub.m +43 -0
  18. package/ios/RNFBAnalyticsUnitTests/HostStubs/RNFBApp/RNFBSharedUtils.h +21 -0
  19. package/ios/RNFBAnalyticsUnitTests/HostStubs/RNFBApp/RNFBSharedUtilsHostStub.m +26 -0
  20. package/ios/RNFBAnalyticsUnitTests/HostStubs/React/RCTBridgeModule.h +10 -0
  21. package/ios/RNFBAnalyticsUnitTests/RNFBAnalyticsConsentSettingsMapperHostStubTests.m +62 -0
  22. package/ios/RNFBAnalyticsUnitTests/RNFBAnalyticsConsentSettingsMapperTests.swift +91 -0
  23. package/ios/RNFBAnalyticsUnitTests/RNFBAnalyticsHelperHostStubTests.m +542 -0
  24. package/ios/RNFBAnalyticsUnitTests/RNFBAnalyticsJavascriptParamsCleanerHostStubTests.m +59 -0
  25. package/ios/RNFBAnalyticsUnitTests/RNFBAnalyticsJavascriptParamsCleanerTests.swift +205 -0
  26. package/ios/RNFBAnalyticsUnitTests/RNFBAnalyticsNullSentinelDecodeTests.m +111 -0
  27. package/ios/RNFBAnalyticsUnitTests/RNFBAnalyticsUnitTests.xcodeproj/project.pbxproj +302 -0
  28. package/ios/RNFBAnalyticsUnitTests/RNFBAnalyticsUnitTests.xcodeproj/xcshareddata/xcschemes/RNFBAnalyticsUnitTests.xcscheme +69 -0
  29. package/lib/index.ts +1 -1
  30. package/lib/version.ts +1 -1
  31. package/package.json +4 -4
@@ -0,0 +1,304 @@
1
+ /**
2
+ * Host-only stub for macOS XCTest. Not shipped in the production pod.
3
+ */
4
+ #import <Firebase/Firebase.h>
5
+
6
+ @implementation FIRAnalytics
7
+
8
+ static NSString *sLastLogEventName;
9
+ static NSDictionary *sLastLogEventParameters;
10
+ static BOOL sAnalyticsCollectionEnabledValue;
11
+ static NSString *sUserIDValue;
12
+ static NSMutableDictionary *sUserProperties;
13
+ static NSUInteger sResetAnalyticsDataCallCount;
14
+ static NSTimeInterval sSessionTimeoutIntervalValue;
15
+ static NSString *sAppInstanceIDValue;
16
+ static int64_t sSessionIDCompletionValue;
17
+ static NSError *sSessionIDCompletionError;
18
+ static BOOL sSessionIDCompletionDeferred;
19
+ static void (^sDeferredSessionIDCompletion)(int64_t, NSError *);
20
+ static NSDictionary *sLastDefaultEventParameters;
21
+ static NSString *sLastConversionEmail;
22
+ static NSData *sLastHashedEmail;
23
+ static NSString *sLastConversionPhone;
24
+ static NSData *sLastHashedPhone;
25
+ static NSDictionary *sLastConsent;
26
+ static BOOL sShouldThrowOnNextCall;
27
+
28
+ + (void)initialize {
29
+ if (self == [FIRAnalytics class]) {
30
+ sUserProperties = [NSMutableDictionary new];
31
+ }
32
+ }
33
+
34
+ + (NSString *)lastLogEventName {
35
+ return sLastLogEventName;
36
+ }
37
+
38
+ + (void)setLastLogEventName:(NSString *)lastLogEventName {
39
+ sLastLogEventName = [lastLogEventName copy];
40
+ }
41
+
42
+ + (NSDictionary *)lastLogEventParameters {
43
+ return sLastLogEventParameters;
44
+ }
45
+
46
+ + (void)setLastLogEventParameters:(NSDictionary *)lastLogEventParameters {
47
+ sLastLogEventParameters = [lastLogEventParameters copy];
48
+ }
49
+
50
+ + (BOOL)analyticsCollectionEnabledValue {
51
+ return sAnalyticsCollectionEnabledValue;
52
+ }
53
+
54
+ + (void)setAnalyticsCollectionEnabledValue:(BOOL)analyticsCollectionEnabledValue {
55
+ sAnalyticsCollectionEnabledValue = analyticsCollectionEnabledValue;
56
+ }
57
+
58
+ + (NSString *)userIDValue {
59
+ return sUserIDValue;
60
+ }
61
+
62
+ + (void)setUserIDValue:(NSString *)userIDValue {
63
+ sUserIDValue = [userIDValue copy];
64
+ }
65
+
66
+ + (NSMutableDictionary *)userProperties {
67
+ return sUserProperties;
68
+ }
69
+
70
+ + (void)setUserProperties:(NSMutableDictionary *)userProperties {
71
+ [sUserProperties removeAllObjects];
72
+ if (userProperties != nil) {
73
+ [sUserProperties addEntriesFromDictionary:userProperties];
74
+ }
75
+ }
76
+
77
+ + (NSUInteger)resetAnalyticsDataCallCount {
78
+ return sResetAnalyticsDataCallCount;
79
+ }
80
+
81
+ + (void)setResetAnalyticsDataCallCount:(NSUInteger)resetAnalyticsDataCallCount {
82
+ sResetAnalyticsDataCallCount = resetAnalyticsDataCallCount;
83
+ }
84
+
85
+ + (NSTimeInterval)sessionTimeoutIntervalValue {
86
+ return sSessionTimeoutIntervalValue;
87
+ }
88
+
89
+ + (void)setSessionTimeoutIntervalValue:(NSTimeInterval)sessionTimeoutIntervalValue {
90
+ sSessionTimeoutIntervalValue = sessionTimeoutIntervalValue;
91
+ }
92
+
93
+ + (NSString *)appInstanceIDValue {
94
+ return sAppInstanceIDValue;
95
+ }
96
+
97
+ + (void)setAppInstanceIDValue:(NSString *)appInstanceIDValue {
98
+ sAppInstanceIDValue = [appInstanceIDValue copy];
99
+ }
100
+
101
+ + (int64_t)sessionIDCompletionValue {
102
+ return sSessionIDCompletionValue;
103
+ }
104
+
105
+ + (void)setSessionIDCompletionValue:(int64_t)sessionIDCompletionValue {
106
+ sSessionIDCompletionValue = sessionIDCompletionValue;
107
+ }
108
+
109
+ + (NSError *)sessionIDCompletionError {
110
+ return sSessionIDCompletionError;
111
+ }
112
+
113
+ + (void)setSessionIDCompletionError:(NSError *)sessionIDCompletionError {
114
+ sSessionIDCompletionError = sessionIDCompletionError;
115
+ }
116
+
117
+ + (BOOL)sessionIDCompletionDeferred {
118
+ return sSessionIDCompletionDeferred;
119
+ }
120
+
121
+ + (void)setSessionIDCompletionDeferred:(BOOL)sessionIDCompletionDeferred {
122
+ sSessionIDCompletionDeferred = sessionIDCompletionDeferred;
123
+ }
124
+
125
+ + (NSDictionary *)lastDefaultEventParameters {
126
+ return sLastDefaultEventParameters;
127
+ }
128
+
129
+ + (void)setLastDefaultEventParameters:(NSDictionary *)lastDefaultEventParameters {
130
+ sLastDefaultEventParameters = [lastDefaultEventParameters copy];
131
+ }
132
+
133
+ + (NSString *)lastConversionEmail {
134
+ return sLastConversionEmail;
135
+ }
136
+
137
+ + (void)setLastConversionEmail:(NSString *)lastConversionEmail {
138
+ sLastConversionEmail = [lastConversionEmail copy];
139
+ }
140
+
141
+ + (NSData *)lastHashedEmail {
142
+ return sLastHashedEmail;
143
+ }
144
+
145
+ + (void)setLastHashedEmail:(NSData *)lastHashedEmail {
146
+ sLastHashedEmail = [lastHashedEmail copy];
147
+ }
148
+
149
+ + (NSString *)lastConversionPhone {
150
+ return sLastConversionPhone;
151
+ }
152
+
153
+ + (void)setLastConversionPhone:(NSString *)lastConversionPhone {
154
+ sLastConversionPhone = [lastConversionPhone copy];
155
+ }
156
+
157
+ + (NSData *)lastHashedPhone {
158
+ return sLastHashedPhone;
159
+ }
160
+
161
+ + (void)setLastHashedPhone:(NSData *)lastHashedPhone {
162
+ sLastHashedPhone = [lastHashedPhone copy];
163
+ }
164
+
165
+ + (NSDictionary *)lastConsent {
166
+ return sLastConsent;
167
+ }
168
+
169
+ + (void)setLastConsent:(NSDictionary *)lastConsent {
170
+ sLastConsent = [lastConsent copy];
171
+ }
172
+
173
+ + (BOOL)shouldThrowOnNextCall {
174
+ return sShouldThrowOnNextCall;
175
+ }
176
+
177
+ + (void)setShouldThrowOnNextCall:(BOOL)shouldThrowOnNextCall {
178
+ sShouldThrowOnNextCall = shouldThrowOnNextCall;
179
+ }
180
+
181
+ + (void)resetTestState {
182
+ sLastLogEventName = nil;
183
+ sLastLogEventParameters = nil;
184
+ sAnalyticsCollectionEnabledValue = NO;
185
+ sUserIDValue = nil;
186
+ [sUserProperties removeAllObjects];
187
+ sResetAnalyticsDataCallCount = 0;
188
+ sSessionTimeoutIntervalValue = 0;
189
+ sAppInstanceIDValue = nil;
190
+ sSessionIDCompletionValue = 0;
191
+ sSessionIDCompletionError = nil;
192
+ sSessionIDCompletionDeferred = NO;
193
+ sDeferredSessionIDCompletion = nil;
194
+ sLastDefaultEventParameters = nil;
195
+ sLastConversionEmail = nil;
196
+ sLastHashedEmail = nil;
197
+ sLastConversionPhone = nil;
198
+ sLastHashedPhone = nil;
199
+ sLastConsent = nil;
200
+ sShouldThrowOnNextCall = NO;
201
+ }
202
+
203
+ + (void)throwIfRequested {
204
+ if (sShouldThrowOnNextCall) {
205
+ sShouldThrowOnNextCall = NO;
206
+ @throw [NSException exceptionWithName:@"FIRAnalyticsTestException"
207
+ reason:@"stub throw"
208
+ userInfo:nil];
209
+ }
210
+ }
211
+
212
+ + (void)flushDeferredSessionIDCompletion {
213
+ if (sDeferredSessionIDCompletion != nil) {
214
+ void (^completion)(int64_t, NSError *) = sDeferredSessionIDCompletion;
215
+ sDeferredSessionIDCompletion = nil;
216
+ completion(sSessionIDCompletionValue, sSessionIDCompletionError);
217
+ }
218
+ }
219
+
220
+ + (void)logEventWithName:(NSString *)name parameters:(NSDictionary<NSString *, id> *)parameters {
221
+ [self throwIfRequested];
222
+ sLastLogEventName = [name copy];
223
+ sLastLogEventParameters = [parameters copy];
224
+ }
225
+
226
+ + (void)setAnalyticsCollectionEnabled:(BOOL)enabled {
227
+ [self throwIfRequested];
228
+ sAnalyticsCollectionEnabledValue = enabled;
229
+ }
230
+
231
+ + (void)setUserID:(NSString *)userID {
232
+ [self throwIfRequested];
233
+ sUserIDValue = [userID copy];
234
+ }
235
+
236
+ + (void)setUserPropertyString:(NSString *)value forName:(NSString *)name {
237
+ [self throwIfRequested];
238
+ if (name == nil) {
239
+ return;
240
+ }
241
+ if (value == nil) {
242
+ [sUserProperties removeObjectForKey:name];
243
+ } else {
244
+ sUserProperties[name] = value;
245
+ }
246
+ }
247
+
248
+ + (void)resetAnalyticsData {
249
+ [self throwIfRequested];
250
+ sResetAnalyticsDataCallCount += 1;
251
+ }
252
+
253
+ + (void)setSessionTimeoutInterval:(NSTimeInterval)sessionTimeoutInterval {
254
+ [self throwIfRequested];
255
+ sSessionTimeoutIntervalValue = sessionTimeoutInterval;
256
+ }
257
+
258
+ + (NSString *)appInstanceID {
259
+ [self throwIfRequested];
260
+ return sAppInstanceIDValue;
261
+ }
262
+
263
+ + (void)sessionIDWithCompletion:(void (^)(int64_t sessionID, NSError *_Nullable error))completion {
264
+ [self throwIfRequested];
265
+ if (sSessionIDCompletionDeferred) {
266
+ sDeferredSessionIDCompletion = [completion copy];
267
+ return;
268
+ }
269
+ if (completion != nil) {
270
+ completion(sSessionIDCompletionValue, sSessionIDCompletionError);
271
+ }
272
+ }
273
+
274
+ + (void)setDefaultEventParameters:(NSDictionary<NSString *, id> *)parameters {
275
+ [self throwIfRequested];
276
+ sLastDefaultEventParameters = [parameters copy];
277
+ }
278
+
279
+ + (void)initiateOnDeviceConversionMeasurementWithEmailAddress:(NSString *)emailAddress {
280
+ [self throwIfRequested];
281
+ sLastConversionEmail = [emailAddress copy];
282
+ }
283
+
284
+ + (void)initiateOnDeviceConversionMeasurementWithHashedEmailAddress:(NSData *)hashedEmailAddress {
285
+ [self throwIfRequested];
286
+ sLastHashedEmail = [hashedEmailAddress copy];
287
+ }
288
+
289
+ + (void)initiateOnDeviceConversionMeasurementWithPhoneNumber:(NSString *)phoneNumber {
290
+ [self throwIfRequested];
291
+ sLastConversionPhone = [phoneNumber copy];
292
+ }
293
+
294
+ + (void)initiateOnDeviceConversionMeasurementWithHashedPhoneNumber:(NSData *)hashedPhoneNumber {
295
+ [self throwIfRequested];
296
+ sLastHashedPhone = [hashedPhoneNumber copy];
297
+ }
298
+
299
+ + (void)setConsent:(NSDictionary *)consentSettings {
300
+ [self throwIfRequested];
301
+ sLastConsent = [consentSettings copy];
302
+ }
303
+
304
+ @end
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Host-only stub for macOS XCTest. Not shipped in the production pod.
3
+ * Mirrors Firebase Analytics `kFIRParameter*` / `FIRConsentType*` /
4
+ * `FIRConsentStatus*` string values and enough of `FIRAnalytics` for
5
+ * compiling `RNFBAnalyticsHelper.m` without linking the real SDK.
6
+ */
7
+ #import <Foundation/Foundation.h>
8
+
9
+ static NSString *const kFIRParameterQuantity = @"quantity";
10
+ static NSString *const kFIRParameterIndex = @"index";
11
+ static NSString *const kFIRParameterLevel = @"level";
12
+ static NSString *const kFIRParameterNumberOfNights = @"number_of_nights";
13
+ static NSString *const kFIRParameterNumberOfPassengers = @"number_of_passengers";
14
+ static NSString *const kFIRParameterNumberOfRooms = @"number_of_rooms";
15
+ static NSString *const kFIRParameterScore = @"score";
16
+ static NSString *const kFIRParameterItems = @"items";
17
+ static NSString *const kFIRParameterSuccess = @"success";
18
+ static NSString *const kFIRParameterExtendSession = @"extend_session";
19
+
20
+ typedef NSString *FIRConsentType;
21
+ typedef NSString *FIRConsentStatus;
22
+
23
+ static FIRConsentType const FIRConsentTypeAdStorage = @"ad_storage";
24
+ static FIRConsentType const FIRConsentTypeAnalyticsStorage = @"analytics_storage";
25
+ static FIRConsentType const FIRConsentTypeAdUserData = @"ad_user_data";
26
+ static FIRConsentType const FIRConsentTypeAdPersonalization = @"ad_personalization";
27
+ static FIRConsentStatus const FIRConsentStatusDenied = @"denied";
28
+ static FIRConsentStatus const FIRConsentStatusGranted = @"granted";
29
+
30
+ @interface FIRAnalytics : NSObject
31
+
32
+ + (void)logEventWithName:(NSString *)name
33
+ parameters:(nullable NSDictionary<NSString *, id> *)parameters;
34
+ + (void)setAnalyticsCollectionEnabled:(BOOL)enabled;
35
+ + (void)setUserID:(nullable NSString *)userID;
36
+ + (void)setUserPropertyString:(nullable NSString *)value forName:(NSString *)name;
37
+ + (void)resetAnalyticsData;
38
+ + (void)setSessionTimeoutInterval:(NSTimeInterval)sessionTimeoutInterval;
39
+ + (nullable NSString *)appInstanceID;
40
+ + (void)sessionIDWithCompletion:(void (^)(int64_t sessionID, NSError *_Nullable error))completion;
41
+ + (void)setDefaultEventParameters:(nullable NSDictionary<NSString *, id> *)parameters;
42
+ + (void)initiateOnDeviceConversionMeasurementWithEmailAddress:(NSString *)emailAddress;
43
+ + (void)initiateOnDeviceConversionMeasurementWithHashedEmailAddress:(NSData *)hashedEmailAddress;
44
+ + (void)initiateOnDeviceConversionMeasurementWithPhoneNumber:(NSString *)phoneNumber;
45
+ + (void)initiateOnDeviceConversionMeasurementWithHashedPhoneNumber:(NSData *)hashedPhoneNumber;
46
+ + (void)setConsent:(NSDictionary<FIRConsentType, FIRConsentStatus> *)consentSettings;
47
+
48
+ /** Test seams */
49
+ @property(class, nonatomic, copy, nullable) NSString *lastLogEventName;
50
+ @property(class, nonatomic, copy, nullable) NSDictionary *lastLogEventParameters;
51
+ @property(class, nonatomic, assign) BOOL analyticsCollectionEnabledValue;
52
+ @property(class, nonatomic, copy, nullable) NSString *userIDValue;
53
+ @property(class, nonatomic, copy, nullable) NSMutableDictionary *userProperties;
54
+ @property(class, nonatomic, assign) NSUInteger resetAnalyticsDataCallCount;
55
+ @property(class, nonatomic, assign) NSTimeInterval sessionTimeoutIntervalValue;
56
+ @property(class, nonatomic, copy, nullable) NSString *appInstanceIDValue;
57
+ @property(class, nonatomic, assign) int64_t sessionIDCompletionValue;
58
+ @property(class, nonatomic, copy, nullable) NSError *sessionIDCompletionError;
59
+ @property(class, nonatomic, assign) BOOL sessionIDCompletionDeferred;
60
+ @property(class, nonatomic, copy, nullable) NSDictionary *lastDefaultEventParameters;
61
+ @property(class, nonatomic, copy, nullable) NSString *lastConversionEmail;
62
+ @property(class, nonatomic, copy, nullable) NSData *lastHashedEmail;
63
+ @property(class, nonatomic, copy, nullable) NSString *lastConversionPhone;
64
+ @property(class, nonatomic, copy, nullable) NSData *lastHashedPhone;
65
+ @property(class, nonatomic, copy, nullable) NSDictionary *lastConsent;
66
+ @property(class, nonatomic, assign) BOOL shouldThrowOnNextCall;
67
+
68
+ + (void)resetTestState;
69
+ + (void)flushDeferredSessionIDCompletion;
70
+
71
+ @end
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Host-only stub for macOS XCTest. Not shipped in the production pod.
3
+ * Declares the ObjC surface of `RNFBAnalyticsLogTransaction` so
4
+ * `RNFBAnalyticsHelper.m` compiles without StoreKit / FirebaseAnalytics.
5
+ */
6
+ #import <Foundation/Foundation.h>
7
+ #import <React/RCTBridgeModule.h>
8
+
9
+ @interface RNFBAnalyticsLogTransaction : NSObject
10
+
11
+ @property(class, nonatomic, copy, nullable) NSString *lastTransactionId;
12
+ @property(class, nonatomic, assign) NSUInteger logCallCount;
13
+
14
+ + (void)resetTestState;
15
+
16
+ - (void)logTransactionWithTransactionId:(NSString *)transactionId
17
+ resolve:(RCTPromiseResolveBlock)resolve
18
+ reject:(RCTPromiseRejectBlock)reject;
19
+
20
+ @end
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Host-only stub for macOS XCTest. Not shipped in the production pod.
3
+ */
4
+ #import "RNFBAnalytics/RNFBAnalyticsLogTransactionHostStub.h"
5
+
6
+ @implementation RNFBAnalyticsLogTransaction
7
+
8
+ static NSString *sLastTransactionId;
9
+ static NSUInteger sLogCallCount;
10
+
11
+ + (NSString *)lastTransactionId {
12
+ return sLastTransactionId;
13
+ }
14
+
15
+ + (void)setLastTransactionId:(NSString *)lastTransactionId {
16
+ sLastTransactionId = [lastTransactionId copy];
17
+ }
18
+
19
+ + (NSUInteger)logCallCount {
20
+ return sLogCallCount;
21
+ }
22
+
23
+ + (void)setLogCallCount:(NSUInteger)logCallCount {
24
+ sLogCallCount = logCallCount;
25
+ }
26
+
27
+ + (void)resetTestState {
28
+ sLastTransactionId = nil;
29
+ sLogCallCount = 0;
30
+ }
31
+
32
+ - (void)logTransactionWithTransactionId:(NSString *)transactionId
33
+ resolve:(RCTPromiseResolveBlock)resolve
34
+ reject:(RCTPromiseRejectBlock)reject {
35
+ (void)reject;
36
+ sLastTransactionId = [transactionId copy];
37
+ sLogCallCount += 1;
38
+ if (resolve != nil) {
39
+ resolve([NSNull null]);
40
+ }
41
+ }
42
+
43
+ @end
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Host-only stub for macOS XCTest. Not shipped in the production pod.
3
+ */
4
+ #import <Foundation/Foundation.h>
5
+ #import <React/RCTBridgeModule.h>
6
+
7
+ #ifdef DEBUG
8
+ #define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
9
+ #else
10
+ #define DLog(...)
11
+ #endif
12
+
13
+ @interface RNFBSharedUtils : NSObject
14
+
15
+ + (void)rejectPromiseWithExceptionDict:(RCTPromiseRejectBlock)reject
16
+ exception:(NSException *)exception;
17
+
18
+ + (void)rejectPromiseWithUserInfo:(RCTPromiseRejectBlock)reject
19
+ userInfo:(NSMutableDictionary *)userInfo;
20
+
21
+ @end
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Host-only stub for macOS XCTest. Not shipped in the production pod.
3
+ */
4
+ #import "RNFBApp/RNFBSharedUtils.h"
5
+
6
+ @implementation RNFBSharedUtils
7
+
8
+ + (void)rejectPromiseWithExceptionDict:(RCTPromiseRejectBlock)reject
9
+ exception:(NSException *)exception {
10
+ if (reject == nil) {
11
+ return;
12
+ }
13
+ reject(@"unknown", exception.reason ?: @"", nil);
14
+ }
15
+
16
+ + (void)rejectPromiseWithUserInfo:(RCTPromiseRejectBlock)reject
17
+ userInfo:(NSMutableDictionary *)userInfo {
18
+ if (reject == nil) {
19
+ return;
20
+ }
21
+ NSString *code = userInfo[@"code"] ?: @"unknown";
22
+ NSString *message = userInfo[@"message"] ?: @"";
23
+ reject(code, message, nil);
24
+ }
25
+
26
+ @end
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Host-only stub for macOS XCTest. Not shipped in the production pod.
3
+ */
4
+ #import <Foundation/Foundation.h>
5
+
6
+ typedef void (^RCTPromiseResolveBlock)(id result);
7
+ typedef void (^RCTPromiseRejectBlock)(NSString *code, NSString *message, NSError *error);
8
+
9
+ @protocol RCTBridgeModule <NSObject>
10
+ @end
@@ -0,0 +1,62 @@
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 <Firebase/Firebase.h>
20
+
21
+ #if __has_include("RNFBAnalyticsJavascriptParamsCleaner-Swift.inc")
22
+ #import "RNFBAnalyticsJavascriptParamsCleaner-Swift.inc"
23
+ #elif __has_include("RNFBAnalyticsUnitTests-Swift.h")
24
+ #import "RNFBAnalyticsUnitTests-Swift.h"
25
+ #else
26
+ #error "RNFBAnalyticsConsentSettingsMapper Swift interface not found"
27
+ #endif
28
+
29
+ @interface RNFBAnalyticsConsentSettingsMapperHostStubTests : XCTestCase
30
+ @end
31
+
32
+ @implementation RNFBAnalyticsConsentSettingsMapperHostStubTests
33
+
34
+ - (void)testConsentConstants_matchHostStubFirebaseConstants {
35
+ XCTAssertEqualObjects(RNFBAnalyticsConsentSettingsMapper.consentTypeAnalyticsStorageValue,
36
+ FIRConsentTypeAnalyticsStorage);
37
+ XCTAssertEqualObjects(RNFBAnalyticsConsentSettingsMapper.consentTypeAdStorageValue,
38
+ FIRConsentTypeAdStorage);
39
+ XCTAssertEqualObjects(RNFBAnalyticsConsentSettingsMapper.consentTypeAdUserDataValue,
40
+ FIRConsentTypeAdUserData);
41
+ XCTAssertEqualObjects(RNFBAnalyticsConsentSettingsMapper.consentTypeAdPersonalizationValue,
42
+ FIRConsentTypeAdPersonalization);
43
+ XCTAssertEqualObjects(RNFBAnalyticsConsentSettingsMapper.consentStatusGrantedValue,
44
+ FIRConsentStatusGranted);
45
+ XCTAssertEqualObjects(RNFBAnalyticsConsentSettingsMapper.consentStatusDeniedValue,
46
+ FIRConsentStatusDenied);
47
+ }
48
+
49
+ - (void)testConsentDictionary_usesHostStubConsentTypeAndStatusKeys {
50
+ NSDictionary *consent = [RNFBAnalyticsConsentSettingsMapper consentDictionaryFromSettings:@{
51
+ @"analytics_storage" : @YES,
52
+ @"ad_storage" : @NO,
53
+ @"ad_user_data" : @YES,
54
+ @"ad_personalization" : @NO,
55
+ }];
56
+ XCTAssertEqualObjects(consent[FIRConsentTypeAnalyticsStorage], FIRConsentStatusGranted);
57
+ XCTAssertEqualObjects(consent[FIRConsentTypeAdStorage], FIRConsentStatusDenied);
58
+ XCTAssertEqualObjects(consent[FIRConsentTypeAdUserData], FIRConsentStatusGranted);
59
+ XCTAssertEqualObjects(consent[FIRConsentTypeAdPersonalization], FIRConsentStatusDenied);
60
+ }
61
+
62
+ @end
@@ -0,0 +1,91 @@
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
18
+
19
+ final class RNFBAnalyticsConsentSettingsMapperTests: XCTestCase {
20
+ func testConsentTypeStatusConstants_matchFirebaseStrings() {
21
+ XCTAssertEqual(
22
+ RNFBAnalyticsConsentSettingsMapper.consentTypeAnalyticsStorageValue, "analytics_storage")
23
+ XCTAssertEqual(RNFBAnalyticsConsentSettingsMapper.consentTypeAdStorageValue, "ad_storage")
24
+ XCTAssertEqual(RNFBAnalyticsConsentSettingsMapper.consentTypeAdUserDataValue, "ad_user_data")
25
+ XCTAssertEqual(
26
+ RNFBAnalyticsConsentSettingsMapper.consentTypeAdPersonalizationValue, "ad_personalization")
27
+ XCTAssertEqual(RNFBAnalyticsConsentSettingsMapper.consentStatusGrantedValue, "granted")
28
+ XCTAssertEqual(RNFBAnalyticsConsentSettingsMapper.consentStatusDeniedValue, "denied")
29
+ }
30
+
31
+ func testConsentDictionary_nilSettings_returnsEmpty() {
32
+ let result = RNFBAnalyticsConsentSettingsMapper.consentDictionary(from: nil)
33
+ XCTAssertEqual(result.count, 0)
34
+ }
35
+
36
+ func testConsentDictionary_emptySettings_returnsEmpty() {
37
+ let result = RNFBAnalyticsConsentSettingsMapper.consentDictionary(from: [:])
38
+ XCTAssertEqual(result.count, 0)
39
+ }
40
+
41
+ func testConsentDictionary_omitsMissingKeys() {
42
+ let result = RNFBAnalyticsConsentSettingsMapper.consentDictionary(from: [
43
+ "analytics_storage": true
44
+ ] as NSDictionary)
45
+ XCTAssertEqual(result.count, 1)
46
+ XCTAssertEqual(result["analytics_storage"] as? String, "granted")
47
+ XCTAssertNil(result["ad_storage"])
48
+ XCTAssertNil(result["ad_user_data"])
49
+ XCTAssertNil(result["ad_personalization"])
50
+ }
51
+
52
+ func testConsentDictionary_trueBecomesGranted_falseBecomesDenied() {
53
+ let result = RNFBAnalyticsConsentSettingsMapper.consentDictionary(from: [
54
+ "analytics_storage": true,
55
+ "ad_storage": false,
56
+ "ad_user_data": NSNumber(value: true),
57
+ "ad_personalization": NSNumber(value: 0),
58
+ ] as NSDictionary)
59
+
60
+ XCTAssertEqual(result["analytics_storage"] as? String, "granted")
61
+ XCTAssertEqual(result["ad_storage"] as? String, "denied")
62
+ XCTAssertEqual(result["ad_user_data"] as? String, "granted")
63
+ XCTAssertEqual(result["ad_personalization"] as? String, "denied")
64
+ }
65
+
66
+ func testConsentDictionary_ignoresUnknownKeys() {
67
+ let result = RNFBAnalyticsConsentSettingsMapper.consentDictionary(from: [
68
+ "analytics_storage": true,
69
+ "security_storage": true,
70
+ "other": false,
71
+ ] as NSDictionary)
72
+ XCTAssertEqual(result.count, 1)
73
+ XCTAssertEqual(result["analytics_storage"] as? String, "granted")
74
+ XCTAssertNil(result["security_storage"])
75
+ XCTAssertNil(result["other"])
76
+ }
77
+
78
+ func testConsentDictionary_allFourKeys() {
79
+ let result = RNFBAnalyticsConsentSettingsMapper.consentDictionary(from: [
80
+ "analytics_storage": false,
81
+ "ad_storage": true,
82
+ "ad_user_data": false,
83
+ "ad_personalization": true,
84
+ ] as NSDictionary)
85
+ XCTAssertEqual(result.count, 4)
86
+ XCTAssertEqual(result["analytics_storage"] as? String, "denied")
87
+ XCTAssertEqual(result["ad_storage"] as? String, "granted")
88
+ XCTAssertEqual(result["ad_user_data"] as? String, "denied")
89
+ XCTAssertEqual(result["ad_personalization"] as? String, "granted")
90
+ }
91
+ }