@@ -484,4 +484,63 @@ -(void)loadInbox:(void (^)(void))finishBlock
484484 [[Leanplum inbox ] downloadMessages ];
485485}
486486
487+ - (void )testDownloadMessages
488+ {
489+ // Do not need to fetch images
490+ // Prefetching will trigger downloadFile requests
491+ [[Leanplum inbox ] disableImagePrefetching ];
492+ // Ensure errors are thrown
493+ [LeanplumHelper mockThrowErrorToThrow ];
494+
495+ id <HTTPStubsDescriptor> getNewsfeedMessagesStub = [HTTPStubs stubRequestsPassingTest: ^BOOL (NSURLRequest * _Nonnull request) {
496+ return [request.URL.host isEqualToString: API_HOST];
497+ } withStubResponse: ^HTTPStubsResponse * _Nonnull (NSURLRequest *request) {
498+ NSString *response_file = OHPathForFile (@" newsfeed_response.json" , self.class );
499+ return [HTTPStubsResponse responseWithFileAtPath: response_file
500+ statusCode: 200
501+ headers: @{@" Content-Type" :@" application/json" }];
502+ }];
503+
504+ dispatch_semaphore_t semaphor = dispatch_semaphore_create (0 );
505+ [[Leanplum inbox ] onChanged: ^{
506+ [HTTPStubs removeStub: getNewsfeedMessagesStub];
507+ dispatch_semaphore_signal (semaphor);
508+ }];
509+
510+ [LeanplumHelper setup_development_test ];
511+ [[Leanplum inbox ] downloadMessages ];
512+
513+ long timedOut = dispatch_semaphore_wait (semaphor, [LeanplumHelper default_dispatch_time ]);
514+ XCTAssertTrue (timedOut == 0 );
515+ }
516+
517+ - (void )testDownloadMessagesWithCompletionHandler
518+ {
519+ // Do not need to fetch images
520+ // Prefetching will trigger downloadFile requests
521+ [[Leanplum inbox ] disableImagePrefetching ];
522+ // Ensure errors are thrown
523+ [LeanplumHelper mockThrowErrorToThrow ];
524+
525+ id <HTTPStubsDescriptor> getNewsfeedMessagesStub = [HTTPStubs stubRequestsPassingTest: ^BOOL (NSURLRequest * _Nonnull request) {
526+ return [request.URL.host isEqualToString: API_HOST];
527+ } withStubResponse: ^HTTPStubsResponse * _Nonnull (NSURLRequest *request) {
528+ NSString *response_file = OHPathForFile (@" newsfeed_response.json" , self.class );
529+ return [HTTPStubsResponse responseWithFileAtPath: response_file
530+ statusCode: 200
531+ headers: @{@" Content-Type" :@" application/json" }];
532+ }];
533+
534+ dispatch_semaphore_t semaphor = dispatch_semaphore_create (0 );
535+
536+ [LeanplumHelper setup_development_test ];
537+ [[Leanplum inbox ] downloadMessages: ^(BOOL success) {
538+ [HTTPStubs removeStub: getNewsfeedMessagesStub];
539+ dispatch_semaphore_signal (semaphor);
540+ }];
541+
542+ long timedOut = dispatch_semaphore_wait (semaphor, [LeanplumHelper default_dispatch_time ]);
543+ XCTAssertTrue (timedOut == 0 );
544+ }
545+
487546@end
0 commit comments