@react-native-firebase/perf 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.
Files changed (36) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/RNFBPerf.podspec +6 -1
  3. package/android/build.gradle +5 -0
  4. package/android/src/main/java/io/invertase/firebase/perf/RNFBPerfHandleRegistry.kt +71 -0
  5. package/android/src/main/java/io/invertase/firebase/perf/UniversalFirebasePerfModule.java +65 -28
  6. package/android/src/test/java/io/invertase/firebase/perf/RNFBPerfHandleRegistryTest.java +205 -0
  7. package/dist/module/version.js +1 -1
  8. package/dist/typescript/lib/index.d.ts +1 -1
  9. package/dist/typescript/lib/version.d.ts +1 -1
  10. package/ios/RNFBPerf/RNFBPerfHandleRegistry.h +41 -0
  11. package/ios/RNFBPerf/RNFBPerfHandleRegistry.m +87 -0
  12. package/ios/RNFBPerf/RNFBPerfHandleRegistryStorage.swift +58 -0
  13. package/ios/RNFBPerf/RNFBPerfHelper.h +71 -0
  14. package/ios/RNFBPerf/RNFBPerfHelper.m +219 -0
  15. package/ios/RNFBPerf/RNFBPerfHttpMethodMapper.swift +86 -0
  16. package/ios/RNFBPerf/RNFBPerfHttpMetricStopApplier.swift +87 -0
  17. package/ios/RNFBPerf/RNFBPerfModule.mm +41 -174
  18. package/ios/RNFBPerf/RNFBPerfTraceStopApplier.swift +68 -0
  19. package/ios/RNFBPerf.xcodeproj/project.pbxproj +32 -0
  20. package/ios/RNFBPerfUnitTests/HostStubs/Firebase/FIRPerformanceHostStub.m +170 -0
  21. package/ios/RNFBPerfUnitTests/HostStubs/Firebase/Firebase.h +75 -0
  22. package/ios/RNFBPerfUnitTests/HostStubs/RNFBApp/RNFBSharedUtils.h +12 -0
  23. package/ios/RNFBPerfUnitTests/HostStubs/RNFBApp/RNFBSharedUtilsHostStub.m +18 -0
  24. package/ios/RNFBPerfUnitTests/HostStubs/React/RCTBridgeModule.h +10 -0
  25. package/ios/RNFBPerfUnitTests/RNFBPerfHandleRegistryTests.m +169 -0
  26. package/ios/RNFBPerfUnitTests/RNFBPerfHelperHostStubTests.m +200 -0
  27. package/ios/RNFBPerfUnitTests/RNFBPerfHttpMethodMapperFacadeTests.m +52 -0
  28. package/ios/RNFBPerfUnitTests/RNFBPerfHttpMethodMapperTests.swift +92 -0
  29. package/ios/RNFBPerfUnitTests/RNFBPerfHttpMetricStopApplierFacadeTests.m +105 -0
  30. package/ios/RNFBPerfUnitTests/RNFBPerfHttpMetricStopApplierTests.swift +201 -0
  31. package/ios/RNFBPerfUnitTests/RNFBPerfTraceStopApplierFacadeTests.m +75 -0
  32. package/ios/RNFBPerfUnitTests/RNFBPerfTraceStopApplierTests.swift +142 -0
  33. package/ios/RNFBPerfUnitTests/RNFBPerfUnitTests.xcodeproj/project.pbxproj +321 -0
  34. package/ios/RNFBPerfUnitTests/RNFBPerfUnitTests.xcodeproj/xcshareddata/xcschemes/RNFBPerfUnitTests.xcscheme +69 -0
  35. package/lib/version.ts +1 -1
  36. package/package.json +5 -4
@@ -0,0 +1,18 @@
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)rejectPromiseWithUserInfo:(RCTPromiseRejectBlock)reject
9
+ userInfo:(NSMutableDictionary *)userInfo {
10
+ if (reject == nil) {
11
+ return;
12
+ }
13
+ NSString *code = userInfo[@"code"] ?: @"unknown";
14
+ NSString *message = userInfo[@"message"] ?: @"";
15
+ reject(code, message, nil);
16
+ }
17
+
18
+ @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,169 @@
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
+
18
+ #import <XCTest/XCTest.h>
19
+
20
+ #import "RNFBHandleMap.h"
21
+ #import "RNFBPerfHandleRegistry.h"
22
+
23
+ @interface FakePerfHandle : NSObject
24
+ @property(nonatomic, assign) NSInteger stopCount;
25
+ - (void)stop;
26
+ @end
27
+
28
+ @implementation FakePerfHandle
29
+ - (void)stop {
30
+ self.stopCount += 1;
31
+ }
32
+ @end
33
+
34
+ @interface RNFBPerfHandleRegistryTests : XCTestCase
35
+ @property(nonatomic, strong) RNFBPerfHandleRegistry *registry;
36
+ @end
37
+
38
+ @implementation RNFBPerfHandleRegistryTests
39
+
40
+ - (void)setUp {
41
+ [super setUp];
42
+ self.registry = [[RNFBPerfHandleRegistry alloc] init];
43
+ }
44
+
45
+ - (void)testPutGetTake_happyPath {
46
+ FakePerfHandle *handle = [[FakePerfHandle alloc] init];
47
+ NSError *error = nil;
48
+ XCTAssertTrue([self.registry put:@1 value:handle error:&error]);
49
+ XCTAssertNil(error);
50
+ XCTAssertEqual(handle, [self.registry get:@1]);
51
+ XCTAssertEqual(handle, [self.registry take:@1]);
52
+ XCTAssertNil([self.registry get:@1]);
53
+ XCTAssertEqual(handle.stopCount, 0);
54
+ }
55
+
56
+ - (void)testPut_occupiedId_returnsCollision {
57
+ FakePerfHandle *first = [[FakePerfHandle alloc] init];
58
+ XCTAssertTrue([self.registry put:@1 value:first error:nil]);
59
+
60
+ NSError *error = nil;
61
+ XCTAssertFalse([self.registry put:@1 value:[[FakePerfHandle alloc] init] error:&error]);
62
+ XCTAssertNotNil(error);
63
+ XCTAssertEqualObjects(error.domain, RNFBHandleMapErrorDomain);
64
+ XCTAssertEqual(error.code, RNFBHandleMapErrorCollision);
65
+ XCTAssertEqual(first, [self.registry get:@1]);
66
+ }
67
+
68
+ - (void)testPut_occupiedId_nilErrorPointer_returnsNO {
69
+ FakePerfHandle *first = [[FakePerfHandle alloc] init];
70
+ XCTAssertTrue([self.registry put:@1 value:first error:nil]);
71
+ XCTAssertFalse([self.registry put:@1 value:[[FakePerfHandle alloc] init] error:nil]);
72
+ XCTAssertEqual(first, [self.registry get:@1]);
73
+ }
74
+
75
+ - (void)testPutOrDiscard_collision_dropsIncomingWithoutStop {
76
+ FakePerfHandle *first = [[FakePerfHandle alloc] init];
77
+ FakePerfHandle *duplicate = [[FakePerfHandle alloc] init];
78
+ XCTAssertTrue([self.registry put:@1 value:first error:nil]);
79
+ XCTAssertFalse([self.registry putOrDiscard:@1 value:duplicate]);
80
+ XCTAssertEqual(duplicate.stopCount, 0);
81
+ XCTAssertEqual(first.stopCount, 0);
82
+ XCTAssertEqual(first, [self.registry get:@1]);
83
+ }
84
+
85
+ - (void)testPutOrDiscard_storesWhenFree {
86
+ FakePerfHandle *handle = [[FakePerfHandle alloc] init];
87
+ XCTAssertTrue([self.registry putOrDiscard:@2 value:handle]);
88
+ XCTAssertEqual(handle, [self.registry get:@2]);
89
+ XCTAssertEqual(handle.stopCount, 0);
90
+ }
91
+
92
+ - (void)testPutReplacing_whenOccupied_returnsDisplaced {
93
+ FakePerfHandle *first = [[FakePerfHandle alloc] init];
94
+ FakePerfHandle *second = [[FakePerfHandle alloc] init];
95
+ XCTAssertTrue([self.registry put:@3 value:first error:nil]);
96
+ XCTAssertEqual(first, [self.registry putReplacing:@3 value:second]);
97
+ XCTAssertEqual(second, [self.registry get:@3]);
98
+ }
99
+
100
+ - (void)testPutReplacing_whenFree_returnsNil {
101
+ FakePerfHandle *handle = [[FakePerfHandle alloc] init];
102
+ XCTAssertNil([self.registry putReplacing:@7 value:handle]);
103
+ XCTAssertEqual(handle, [self.registry get:@7]);
104
+ }
105
+
106
+ - (void)testTakeIf_missingDoesNotCallCondition {
107
+ __block BOOL conditionCalled = NO;
108
+ XCTAssertNil([self.registry takeIf:@99
109
+ when:^BOOL(id value) {
110
+ (void)value;
111
+ conditionCalled = YES;
112
+ return YES;
113
+ }]);
114
+ XCTAssertFalse(conditionCalled);
115
+ }
116
+
117
+ - (void)testTakeIf_falseLeavesValue {
118
+ FakePerfHandle *handle = [[FakePerfHandle alloc] init];
119
+ XCTAssertTrue([self.registry put:@8 value:handle error:nil]);
120
+ XCTAssertNil([self.registry takeIf:@8
121
+ when:^BOOL(id value) {
122
+ XCTAssertEqual(handle, value);
123
+ return NO;
124
+ }]);
125
+ XCTAssertEqual(handle, [self.registry get:@8]);
126
+ }
127
+
128
+ - (void)testTakeIf_trueRemovesAndReturns {
129
+ FakePerfHandle *handle = [[FakePerfHandle alloc] init];
130
+ XCTAssertTrue([self.registry put:@9 value:handle error:nil]);
131
+ XCTAssertEqual(handle, [self.registry takeIf:@9
132
+ when:^BOOL(id value) {
133
+ return value == handle;
134
+ }]);
135
+ XCTAssertNil([self.registry get:@9]);
136
+ XCTAssertEqual(handle.stopCount, 0);
137
+ }
138
+
139
+ - (void)testPutReplacing_moduleCollisionPattern_stopsDisplacedOutsideLock {
140
+ FakePerfHandle *first = [[FakePerfHandle alloc] init];
141
+ FakePerfHandle *second = [[FakePerfHandle alloc] init];
142
+ XCTAssertTrue([self.registry put:@6 value:first error:nil]);
143
+ FakePerfHandle *displaced = [self.registry putReplacing:@6 value:second];
144
+ if (displaced != nil) {
145
+ [displaced stop];
146
+ }
147
+ XCTAssertEqual(first.stopCount, 1);
148
+ XCTAssertEqual(second.stopCount, 0);
149
+ XCTAssertEqual(second, [self.registry get:@6]);
150
+ }
151
+
152
+ - (void)testTakeAll_returnsSnapshotAndLeavesEmpty {
153
+ FakePerfHandle *a = [[FakePerfHandle alloc] init];
154
+ FakePerfHandle *b = [[FakePerfHandle alloc] init];
155
+ XCTAssertTrue([self.registry put:@4 value:a error:nil]);
156
+ XCTAssertTrue([self.registry put:@5 value:b error:nil]);
157
+ NSArray *remaining = [self.registry takeAll];
158
+ XCTAssertEqual(remaining.count, 2);
159
+ XCTAssertNil([self.registry get:@4]);
160
+ XCTAssertNil([self.registry get:@5]);
161
+ XCTAssertEqual(a.stopCount, 0);
162
+ XCTAssertEqual(b.stopCount, 0);
163
+ }
164
+
165
+ - (void)testGet_whenFree_isNil {
166
+ XCTAssertNil([self.registry get:@99]);
167
+ }
168
+
169
+ @end
@@ -0,0 +1,200 @@
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
+ #import "RNFBPerfHandleRegistry.h"
21
+ #import "RNFBPerfHelper.h"
22
+
23
+ @interface RNFBPerfHelperHostStubTests : XCTestCase
24
+ @property(nonatomic, strong) RNFBPerfHandleRegistry *traces;
25
+ @property(nonatomic, strong) RNFBPerfHandleRegistry *httpMetrics;
26
+ @end
27
+
28
+ @implementation RNFBPerfHelperHostStubTests
29
+
30
+ - (void)setUp {
31
+ [super setUp];
32
+ [FIRPerformance resetTestState];
33
+ self.traces = [[RNFBPerfHandleRegistry alloc] init];
34
+ self.httpMetrics = [[RNFBPerfHandleRegistry alloc] init];
35
+ }
36
+
37
+ - (void)tearDown {
38
+ [FIRPerformance resetTestState];
39
+ self.traces = nil;
40
+ self.httpMetrics = nil;
41
+ [super tearDown];
42
+ }
43
+
44
+ - (void)testConstantsDictionary_reflectsSharedInstanceFlags {
45
+ [FIRPerformance sharedInstance].dataCollectionEnabled = YES;
46
+ [FIRPerformance sharedInstance].instrumentationEnabled = YES;
47
+
48
+ NSDictionary *constants = [RNFBPerfHelper constantsDictionary];
49
+ XCTAssertEqualObjects(constants[@"isPerformanceCollectionEnabled"], @YES);
50
+ XCTAssertEqualObjects(constants[@"isInstrumentationEnabled"], @YES);
51
+ }
52
+
53
+ - (void)testSetPerformanceCollectionEnabled_setsFlagAndResolves {
54
+ __block id resolved = @"unset";
55
+ __block BOOL rejected = NO;
56
+
57
+ [RNFBPerfHelper setPerformanceCollectionEnabled:YES
58
+ resolve:^(id result) {
59
+ resolved = result;
60
+ }
61
+ reject:^(NSString *code, NSString *message, NSError *error) {
62
+ (void)code;
63
+ (void)message;
64
+ (void)error;
65
+ rejected = YES;
66
+ }];
67
+
68
+ XCTAssertFalse(rejected);
69
+ XCTAssertEqualObjects(resolved, [NSNull null]);
70
+ XCTAssertTrue([FIRPerformance sharedInstance].dataCollectionEnabled);
71
+ }
72
+
73
+ - (void)testSetInstrumentationEnabled_setsFlagAndResolves {
74
+ __block id resolved = @"unset";
75
+
76
+ [RNFBPerfHelper setInstrumentationEnabled:YES
77
+ resolve:^(id result) {
78
+ resolved = result;
79
+ }
80
+ reject:^(NSString *code, NSString *message, NSError *error) {
81
+ (void)code;
82
+ (void)message;
83
+ (void)error;
84
+ XCTFail(@"unexpected reject");
85
+ }];
86
+
87
+ XCTAssertEqualObjects(resolved, [NSNull null]);
88
+ XCTAssertTrue([FIRPerformance sharedInstance].instrumentationEnabled);
89
+ }
90
+
91
+ - (void)testStartTrace_startsAndStoresHandle {
92
+ [RNFBPerfHelper startTraceWithId:@1 identifier:@"trace-a" inRegistry:self.traces];
93
+
94
+ FIRTrace *trace = [self.traces get:@1];
95
+ XCTAssertNotNil(trace);
96
+ XCTAssertEqualObjects(trace.name, @"trace-a");
97
+ XCTAssertEqual(trace.startCallCount, 1u);
98
+ XCTAssertEqual(FIRPerformance.createdTraces.count, 1u);
99
+ }
100
+
101
+ - (void)testStartTrace_displacesPreviousAndStopsIt {
102
+ [RNFBPerfHelper startTraceWithId:@1 identifier:@"first" inRegistry:self.traces];
103
+ FIRTrace *first = [self.traces get:@1];
104
+
105
+ [RNFBPerfHelper startTraceWithId:@1 identifier:@"second" inRegistry:self.traces];
106
+ FIRTrace *second = [self.traces get:@1];
107
+
108
+ XCTAssertNotEqual(first, second);
109
+ XCTAssertEqual(first.stopCallCount, 1u);
110
+ XCTAssertEqual(second.startCallCount, 1u);
111
+ XCTAssertEqualObjects(second.name, @"second");
112
+ }
113
+
114
+ - (void)testStopTrace_appliesMetricsAttributesAndStops {
115
+ [RNFBPerfHelper startTraceWithId:@7 identifier:@"stop-me" inRegistry:self.traces];
116
+ FIRTrace *trace = [self.traces get:@7];
117
+
118
+ [RNFBPerfHelper stopTraceWithId:@7
119
+ metrics:@{@"bytes" : @42}
120
+ attributes:@{@"screen" : @"home"}
121
+ inRegistry:self.traces];
122
+
123
+ XCTAssertNil([self.traces get:@7]);
124
+ XCTAssertEqualObjects(trace.metrics[@"bytes"], @42);
125
+ XCTAssertEqualObjects(trace.attributes[@"screen"], @"home");
126
+ XCTAssertEqual(trace.stopCallCount, 1u);
127
+ }
128
+
129
+ - (void)testStopTrace_missingHandle_isNoOp {
130
+ [RNFBPerfHelper stopTraceWithId:@99 metrics:@{@"m" : @1} attributes:nil inRegistry:self.traces];
131
+ XCTAssertEqual(FIRPerformance.createdTraces.count, 0u);
132
+ }
133
+
134
+ - (void)testStartHttpMetric_mapsMethodStartsAndStores {
135
+ [RNFBPerfHelper startHttpMetricWithId:@3
136
+ url:@"https://example.com/api"
137
+ httpMethod:@"POST"
138
+ inRegistry:self.httpMetrics];
139
+
140
+ FIRHTTPMetric *metric = [self.httpMetrics get:@3];
141
+ XCTAssertNotNil(metric);
142
+ XCTAssertEqualObjects(metric.url.absoluteString, @"https://example.com/api");
143
+ XCTAssertEqual(metric.HTTPMethod, FIRHTTPMethodPOST);
144
+ XCTAssertEqual(metric.startCallCount, 1u);
145
+ }
146
+
147
+ - (void)testStartHttpMetric_displacesPreviousAndStopsIt {
148
+ [RNFBPerfHelper startHttpMetricWithId:@3
149
+ url:@"https://example.com/a"
150
+ httpMethod:@"GET"
151
+ inRegistry:self.httpMetrics];
152
+ FIRHTTPMetric *first = [self.httpMetrics get:@3];
153
+
154
+ [RNFBPerfHelper startHttpMetricWithId:@3
155
+ url:@"https://example.com/b"
156
+ httpMethod:@"PUT"
157
+ inRegistry:self.httpMetrics];
158
+ FIRHTTPMetric *second = [self.httpMetrics get:@3];
159
+
160
+ XCTAssertNotEqual(first, second);
161
+ XCTAssertEqual(first.stopCallCount, 1u);
162
+ XCTAssertEqual(second.HTTPMethod, FIRHTTPMethodPUT);
163
+ }
164
+
165
+ - (void)testStopHttpMetric_appliesFieldsAndStops {
166
+ [RNFBPerfHelper startHttpMetricWithId:@4
167
+ url:@"https://example.com"
168
+ httpMethod:@"GET"
169
+ inRegistry:self.httpMetrics];
170
+ FIRHTTPMetric *metric = [self.httpMetrics get:@4];
171
+
172
+ [RNFBPerfHelper stopHttpMetricWithId:@4
173
+ attributes:@{@"route" : @"/v1"}
174
+ httpResponseCode:@204
175
+ requestPayloadSize:@10
176
+ responsePayloadSize:@20
177
+ responseContentType:@"application/json"
178
+ inRegistry:self.httpMetrics];
179
+
180
+ XCTAssertNil([self.httpMetrics get:@4]);
181
+ XCTAssertEqualObjects(metric.attributes[@"route"], @"/v1");
182
+ XCTAssertEqual(metric.responseCode, 204);
183
+ XCTAssertEqual(metric.requestPayloadSize, 10);
184
+ XCTAssertEqual(metric.responsePayloadSize, 20);
185
+ XCTAssertEqualObjects(metric.responseContentType, @"application/json");
186
+ XCTAssertEqual(metric.stopCallCount, 1u);
187
+ }
188
+
189
+ - (void)testStopHttpMetric_missingHandle_isNoOp {
190
+ [RNFBPerfHelper stopHttpMetricWithId:@88
191
+ attributes:nil
192
+ httpResponseCode:@200
193
+ requestPayloadSize:nil
194
+ responsePayloadSize:nil
195
+ responseContentType:nil
196
+ inRegistry:self.httpMetrics];
197
+ XCTAssertEqual(FIRPerformance.createdHttpMetrics.count, 0u);
198
+ }
199
+
200
+ @end
@@ -0,0 +1,52 @@
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
+
21
+ @interface RNFBPerfHttpMethodMapperFacadeTests : XCTestCase
22
+ @end
23
+
24
+ @implementation RNFBPerfHttpMethodMapperFacadeTests
25
+
26
+ - (void)testObjCSelectorMapsKnownMethods {
27
+ XCTAssertEqual([RNFBPerfHttpMethodMapper httpMethodRawValueForString:@"put"], 1);
28
+ XCTAssertEqual([RNFBPerfHttpMethodMapper httpMethodRawValueForString:@"POST"], 2);
29
+ XCTAssertEqual([RNFBPerfHttpMethodMapper httpMethodRawValueForString:@"delete"], 3);
30
+ XCTAssertEqual([RNFBPerfHttpMethodMapper httpMethodRawValueForString:@"HEAD"], 4);
31
+ XCTAssertEqual([RNFBPerfHttpMethodMapper httpMethodRawValueForString:@"patch"], 5);
32
+ XCTAssertEqual([RNFBPerfHttpMethodMapper httpMethodRawValueForString:@"OPTIONS"], 6);
33
+ XCTAssertEqual([RNFBPerfHttpMethodMapper httpMethodRawValueForString:@"trace"], 7);
34
+ XCTAssertEqual([RNFBPerfHttpMethodMapper httpMethodRawValueForString:@"CONNECT"], 8);
35
+ }
36
+
37
+ - (void)testObjCSelectorDefaultsUnknownNilEmptyGetToGet {
38
+ XCTAssertEqual([RNFBPerfHttpMethodMapper httpMethodRawValueForString:@"get"], 0);
39
+ XCTAssertEqual([RNFBPerfHttpMethodMapper httpMethodRawValueForString:@"bogus"], 0);
40
+ XCTAssertEqual([RNFBPerfHttpMethodMapper httpMethodRawValueForString:@""], 0);
41
+ XCTAssertEqual([RNFBPerfHttpMethodMapper httpMethodRawValueForString:nil], 0);
42
+ }
43
+
44
+ - (void)testFacadePublicSelectorUnchanged {
45
+ XCTAssertTrue(
46
+ [RNFBPerfHttpMethodMapper respondsToSelector:@selector(httpMethodRawValueForString:)]);
47
+ NSMethodSignature *signature =
48
+ [RNFBPerfHttpMethodMapper methodSignatureForSelector:@selector(httpMethodRawValueForString:)];
49
+ XCTAssertEqual(strcmp(signature.methodReturnType, @encode(NSInteger)), 0);
50
+ }
51
+
52
+ @end
@@ -0,0 +1,92 @@
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 RNFBPerfHttpMethodMapperTests: XCTestCase {
21
+ /// `FIRHTTPMethodGET`
22
+ private let getMethod = 0
23
+ /// `FIRHTTPMethodPUT`
24
+ private let putMethod = 1
25
+ /// `FIRHTTPMethodPOST`
26
+ private let postMethod = 2
27
+ /// `FIRHTTPMethodDELETE`
28
+ private let deleteMethod = 3
29
+ /// `FIRHTTPMethodHEAD`
30
+ private let headMethod = 4
31
+ /// `FIRHTTPMethodPATCH`
32
+ private let patchMethod = 5
33
+ /// `FIRHTTPMethodOPTIONS`
34
+ private let optionsMethod = 6
35
+ /// `FIRHTTPMethodTRACE`
36
+ private let traceMethod = 7
37
+ /// `FIRHTTPMethodCONNECT`
38
+ private let connectMethod = 8
39
+
40
+ func testPutMapsToPut() {
41
+ XCTAssertEqual(RNFBPerfHttpMethodMapper.httpMethodRawValue(forString: "put"), putMethod)
42
+ XCTAssertEqual(RNFBPerfHttpMethodMapper.httpMethodRawValue(forString: "PUT"), putMethod)
43
+ XCTAssertEqual(RNFBPerfHttpMethodMapper.httpMethodRawValue(forString: "Put"), putMethod)
44
+ }
45
+
46
+ func testPostMapsToPost() {
47
+ XCTAssertEqual(RNFBPerfHttpMethodMapper.httpMethodRawValue(forString: "post"), postMethod)
48
+ XCTAssertEqual(RNFBPerfHttpMethodMapper.httpMethodRawValue(forString: "POST"), postMethod)
49
+ }
50
+
51
+ func testHeadMapsToHead() {
52
+ XCTAssertEqual(RNFBPerfHttpMethodMapper.httpMethodRawValue(forString: "head"), headMethod)
53
+ XCTAssertEqual(RNFBPerfHttpMethodMapper.httpMethodRawValue(forString: "HEAD"), headMethod)
54
+ }
55
+
56
+ func testTraceMapsToTrace() {
57
+ XCTAssertEqual(RNFBPerfHttpMethodMapper.httpMethodRawValue(forString: "trace"), traceMethod)
58
+ XCTAssertEqual(RNFBPerfHttpMethodMapper.httpMethodRawValue(forString: "TRACE"), traceMethod)
59
+ }
60
+
61
+ func testPatchMapsToPatch() {
62
+ XCTAssertEqual(RNFBPerfHttpMethodMapper.httpMethodRawValue(forString: "patch"), patchMethod)
63
+ XCTAssertEqual(RNFBPerfHttpMethodMapper.httpMethodRawValue(forString: "PATCH"), patchMethod)
64
+ }
65
+
66
+ func testDeleteMapsToDelete() {
67
+ XCTAssertEqual(RNFBPerfHttpMethodMapper.httpMethodRawValue(forString: "delete"), deleteMethod)
68
+ XCTAssertEqual(RNFBPerfHttpMethodMapper.httpMethodRawValue(forString: "DELETE"), deleteMethod)
69
+ }
70
+
71
+ func testOptionsMapsToOptions() {
72
+ XCTAssertEqual(RNFBPerfHttpMethodMapper.httpMethodRawValue(forString: "options"), optionsMethod)
73
+ XCTAssertEqual(RNFBPerfHttpMethodMapper.httpMethodRawValue(forString: "OPTIONS"), optionsMethod)
74
+ }
75
+
76
+ func testConnectMapsToConnect() {
77
+ XCTAssertEqual(RNFBPerfHttpMethodMapper.httpMethodRawValue(forString: "connect"), connectMethod)
78
+ XCTAssertEqual(RNFBPerfHttpMethodMapper.httpMethodRawValue(forString: "CONNECT"), connectMethod)
79
+ }
80
+
81
+ func testGetAndUnknownDefaultToGet() {
82
+ XCTAssertEqual(RNFBPerfHttpMethodMapper.httpMethodRawValue(forString: "get"), getMethod)
83
+ XCTAssertEqual(RNFBPerfHttpMethodMapper.httpMethodRawValue(forString: "GET"), getMethod)
84
+ XCTAssertEqual(RNFBPerfHttpMethodMapper.httpMethodRawValue(forString: "bogus"), getMethod)
85
+ XCTAssertEqual(RNFBPerfHttpMethodMapper.httpMethodRawValue(forString: "unknown"), getMethod)
86
+ }
87
+
88
+ func testNilAndEmptyDefaultToGet() {
89
+ XCTAssertEqual(RNFBPerfHttpMethodMapper.httpMethodRawValue(forString: nil), getMethod)
90
+ XCTAssertEqual(RNFBPerfHttpMethodMapper.httpMethodRawValue(forString: ""), getMethod)
91
+ }
92
+ }
@@ -0,0 +1,105 @@
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
+
21
+ @interface RNFBPerfHttpMetricStopApplierFacadeStub : NSObject <RNFBPerfHttpMetricApplying>
22
+ @property(nonatomic, strong) NSMutableArray<NSDictionary *> *calls;
23
+ @end
24
+
25
+ @implementation RNFBPerfHttpMetricStopApplierFacadeStub
26
+ - (instancetype)init {
27
+ self = [super init];
28
+ if (self) {
29
+ _calls = [NSMutableArray array];
30
+ }
31
+ return self;
32
+ }
33
+
34
+ - (void)setValue:(NSString *)value forAttribute:(NSString *)attributeName {
35
+ [self.calls addObject:@{@"kind" : @"attribute", @"name" : attributeName, @"value" : value}];
36
+ }
37
+
38
+ - (void)setResponseCode:(NSInteger)responseCode {
39
+ [self.calls addObject:@{@"kind" : @"responseCode", @"value" : @(responseCode)}];
40
+ }
41
+
42
+ - (void)setRequestPayloadSize:(NSInteger)bytes {
43
+ [self.calls addObject:@{@"kind" : @"requestPayloadSize", @"value" : @(bytes)}];
44
+ }
45
+
46
+ - (void)setResponsePayloadSize:(NSInteger)bytes {
47
+ [self.calls addObject:@{@"kind" : @"responsePayloadSize", @"value" : @(bytes)}];
48
+ }
49
+
50
+ - (void)setResponseContentType:(NSString *)contentType {
51
+ [self.calls addObject:@{@"kind" : @"responseContentType", @"value" : contentType}];
52
+ }
53
+ @end
54
+
55
+ @interface RNFBPerfHttpMetricStopApplierFacadeTests : XCTestCase
56
+ @end
57
+
58
+ @implementation RNFBPerfHttpMetricStopApplierFacadeTests
59
+
60
+ - (void)testObjCSelectorAppliesAttributesThenOptionals {
61
+ RNFBPerfHttpMetricStopApplierFacadeStub *stub =
62
+ [[RNFBPerfHttpMetricStopApplierFacadeStub alloc] init];
63
+ NSDictionary *attributes = @{@"a1" : @"v1"};
64
+
65
+ [RNFBPerfHttpMetricStopApplier applyAttributes:attributes
66
+ httpResponseCode:@200
67
+ requestPayloadSize:@11
68
+ responsePayloadSize:@22
69
+ responseContentType:@"application/json"
70
+ to:stub];
71
+
72
+ XCTAssertEqual(stub.calls.count, 5u);
73
+ XCTAssertEqualObjects(stub.calls[0][@"kind"], @"attribute");
74
+ XCTAssertEqualObjects(stub.calls[0][@"name"], @"a1");
75
+ XCTAssertEqualObjects(stub.calls[0][@"value"], @"v1");
76
+ XCTAssertEqualObjects(stub.calls[1][@"kind"], @"responseCode");
77
+ XCTAssertEqualObjects(stub.calls[1][@"value"], @200);
78
+ XCTAssertEqualObjects(stub.calls[2][@"kind"], @"requestPayloadSize");
79
+ XCTAssertEqualObjects(stub.calls[2][@"value"], @11);
80
+ XCTAssertEqualObjects(stub.calls[3][@"kind"], @"responsePayloadSize");
81
+ XCTAssertEqualObjects(stub.calls[3][@"value"], @22);
82
+ XCTAssertEqualObjects(stub.calls[4][@"kind"], @"responseContentType");
83
+ XCTAssertEqualObjects(stub.calls[4][@"value"], @"application/json");
84
+ }
85
+
86
+ - (void)testObjCSelectorNilFieldsAreNoOps {
87
+ RNFBPerfHttpMetricStopApplierFacadeStub *stub =
88
+ [[RNFBPerfHttpMetricStopApplierFacadeStub alloc] init];
89
+ [RNFBPerfHttpMetricStopApplier applyAttributes:nil
90
+ httpResponseCode:nil
91
+ requestPayloadSize:nil
92
+ responsePayloadSize:nil
93
+ responseContentType:nil
94
+ to:stub];
95
+ XCTAssertEqual(stub.calls.count, 0u);
96
+ }
97
+
98
+ - (void)testFacadePublicSelectorUnchanged {
99
+ XCTAssertTrue([RNFBPerfHttpMetricStopApplier
100
+ respondsToSelector:@selector
101
+ (applyAttributes:
102
+ httpResponseCode:requestPayloadSize:responsePayloadSize:responseContentType:to:)]);
103
+ }
104
+
105
+ @end