@@ -21,33 +21,44 @@ + (void)initialize {
21
21
22
22
- (void )setUp {
23
23
[CleverTap setDebugLevel: 3 ];
24
- [CleverTap setCredentialsWithAccountID: @" test" token: @" test" region: @" eu1" ];
24
+ BOOL cleverTapInitialized = [[CleverTap sharedInstance ] profileGetCleverTapID ] != nil ;
25
+
26
+ if (!cleverTapInitialized) {
27
+ [CleverTap setCredentialsWithAccountID: @" test" token: @" test" region: @" eu1" ];
28
+ }
29
+
25
30
self.eventDetails = [NSMutableArray array ];
26
-
27
31
self.cleverTapInstance = [CleverTap sharedInstance ];
28
32
self.additionalInstance = [CleverTap instanceWithConfig: [[CleverTapInstanceConfig alloc ]initWithAccountId:@" test" accountToken: @" test" accountRegion: @" eu1" ]];
29
33
self.responseJson = @{ @" key1" : @" value1" , @" key2" : @[@" value2A" , @" value2B" ] }; // TODO
30
34
self.responseHeaders = @{@" Content-Type" :@" application/json" };
31
35
32
36
33
- // [HTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest *request) {
34
- // return [request.URL.host isEqualToString:@"eu1.clevertap-prod.com"];
35
- // } withStubResponse:^HTTPStubsResponse*(NSURLRequest *request) {
36
- //
37
- //
38
- // return [HTTPStubsResponse responseWithJSONObject:self.responseJson statusCode:200 headers:self.responseHeaders];
39
- // }];
37
+ [HTTPStubs stubRequestsPassingTest: ^BOOL (NSURLRequest *request) {
38
+ return [request.URL.host isEqualToString: @" eu1.clevertap-prod.com" ];
39
+ } withStubResponse: ^HTTPStubsResponse*(NSURLRequest *request) {
40
+ return [HTTPStubsResponse responseWithJSONObject: self .responseJson statusCode: 200 headers: self .responseHeaders];
41
+ }];
40
42
41
43
[HTTPStubs onStubActivation: ^(NSURLRequest * _Nonnull request, id <HTTPStubsDescriptor> _Nonnull stub, HTTPStubsResponse * _Nonnull responseStub) {
42
44
NSArray *data = [NSJSONSerialization JSONObjectWithData: [request OHHTTPStubs_HTTPBody ] options: NSJSONReadingMutableContainers error: nil ];
43
-
44
45
self.lastBatchHeader = [data objectAtIndex: 0 ];
45
46
self.lastEvent = [data objectAtIndex: 1 ];
46
47
[self .eventDetails addObject: [[EventDetail alloc ]initWithEvent:[data objectAtIndex: 1 ] name: stub.name]];
47
48
NSLog (@" LAST EVENT" );
48
49
NSLog (@" %@ " , self.lastEvent );
49
50
}];
50
- [CleverTap notfityTestAppLaunch ];
51
+ if (!cleverTapInitialized) {
52
+ [CleverTap notfityTestAppLaunch ];
53
+ XCTestExpectation *expectation = [self expectationWithDescription: @" Wait For App Launch" ];
54
+ dispatch_time_t delay = dispatch_time (DISPATCH_TIME_NOW, 2.0 * NSEC_PER_SEC);
55
+ dispatch_after (delay, dispatch_get_main_queue (), ^(void ){
56
+ [expectation fulfill ];
57
+ });
58
+ [self waitForExpectationsWithTimeout: 2.0 handler: ^(NSError *error) {
59
+ // no-op
60
+ }];
61
+ }
51
62
}
52
63
53
64
- (void )tearDown {
@@ -66,8 +77,6 @@ - (void)stubRequestsWithName:(NSString*)name {
66
77
[HTTPStubs stubRequestsPassingTest: ^BOOL (NSURLRequest *request) {
67
78
return [request.URL.host isEqualToString: @" eu1.clevertap-prod.com" ];
68
79
} withStubResponse: ^HTTPStubsResponse*(NSURLRequest *request) {
69
-
70
-
71
80
return [HTTPStubsResponse responseWithJSONObject: self .responseJson statusCode: 200 headers: self .responseHeaders];
72
81
}].name = name;
73
82
}
@@ -107,7 +116,7 @@ - (EventDetail*)getFilteredEventWithStubName: (NSString*)stubName eventName: (NS
107
116
return nil ;
108
117
}];
109
118
NSArray *filteredEvents = [self .eventDetails filteredArrayUsingPredicate: pred];
110
- return (EventDetail*)filteredEvents[0 ];
119
+ return (filteredEvents && [filteredEvents count ] > 0 ) ? ( EventDetail*)filteredEvents[0 ] : nil ;
111
120
}
112
121
113
122
@end
0 commit comments