@@ -256,7 +256,14 @@ - (void)testFlushEventsSuccessSavedEvents {
256
256
257
257
__weak typeof (self) weakSelf = self;
258
258
[self .eventDispatcher flushEvents: ^{
259
- [weakSelf checkNetworkTimerIsEnabled: weakSelf.eventDispatcher timeInterval: OPTLYEventDispatcherDefaultDispatchIntervalTime_ms];
259
+ NSArray *savedEvents = [self .eventDispatcher.dataStore getAllEvents: OPTLYDataStoreEventTypeConversion
260
+ cachedData: NO
261
+ error: nil ];
262
+ NSArray *cachedEvents = [self .eventDispatcher.dataStore getAllEvents: OPTLYDataStoreEventTypeConversion
263
+ cachedData: YES
264
+ error: nil ];
265
+ XCTAssert ([savedEvents count ] == 0 , @" Saved events should have been removed." );
266
+ XCTAssert ([cachedEvents count ] == 0 , @" Cached events should have been removed." );
260
267
[expectation fulfill ];
261
268
262
269
}];
@@ -279,7 +286,6 @@ - (void)testFlushEventsSuccessNoSavedEvents {
279
286
[self .eventDispatcher flushEvents: ^{
280
287
[weakSelf checkNetworkTimerIsDisabled: weakSelf.eventDispatcher];
281
288
[expectation fulfill ];
282
-
283
289
}];
284
290
285
291
[self waitForExpectationsWithTimeout: 10.0 handler: ^(NSError *error) {
@@ -310,6 +316,41 @@ - (void)testFlushEventsFailureSavedEvents {
310
316
}];
311
317
}
312
318
319
+ // if there are some saved events, then a successful flushSaveEvent should keep the timer enabled
320
+ - (void )testFlushSavedEventSuccessWithSavedEvents
321
+ {
322
+ BOOL usedCachedData = NO ;
323
+ #if TARGET_OS_TV
324
+ usedCachedData = YES ;
325
+ #endif
326
+ [self stubSuccessResponse ];
327
+ [self .eventDispatcher setupNetworkTimer: nil ];
328
+
329
+ for (NSInteger i = 0 ; i < 3 ; ++i) {
330
+ [self .eventDispatcher saveEvent: self .parameters
331
+ eventType: OPTLYDataStoreEventTypeConversion
332
+ error: nil ];
333
+ }
334
+
335
+ __block XCTestExpectation *expectation = [self expectationWithDescription: @" Wait for dispatchConversionEvent failure." ];
336
+ __weak typeof (self) weakSelf = self;
337
+ [self .eventDispatcher flushSavedEvent: self .parameters eventType: OPTLYDataStoreEventTypeConversion cachedData: usedCachedData callback: ^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
338
+ NSArray *events = [self .eventDispatcher.dataStore getAllEvents: OPTLYDataStoreEventTypeConversion
339
+ cachedData: usedCachedData
340
+ error: nil ];
341
+ XCTAssert ([events count ] == 2 , @" Event should have been removed." );
342
+ [weakSelf checkNetworkTimerIsEnabled: weakSelf.eventDispatcher timeInterval: OPTLYEventDispatcherDefaultDispatchIntervalTime_ms];
343
+
344
+ [expectation fulfill ];
345
+ }];
346
+
347
+ [self waitForExpectationsWithTimeout: 10.0 handler: ^(NSError *error) {
348
+ if (error) {
349
+ NSLog (@" Timeout error for dispatchConversionEvent: %@ " , error);
350
+ }
351
+ }];
352
+ }
353
+
313
354
- (void )testFlushSavedEventSuccess
314
355
{
315
356
BOOL usedCachedData = NO ;
0 commit comments