@@ -392,7 +392,7 @@ - (void)testGetAuthToken_WhenValidInstallationExists_ThenItIsReturned {
392
392
FBLPromise<FIRInstallationsItem *> *promise = [self .controller getAuthTokenForcingRefresh: NO ];
393
393
394
394
// 3. Wait for the promise to resolve.
395
- FBLWaitForPromisesWithTimeout (0.5 );
395
+ XCTAssert ( FBLWaitForPromisesWithTimeout (0.5 ) );
396
396
397
397
// 4. Check.
398
398
OCMVerifyAll (self.mockInstallationsStore );
@@ -414,19 +414,15 @@ - (void)testGetAuthToken_WhenValidInstallationWithExpiredTokenExists_ThenTokenRe
414
414
OCMExpect ([self .mockInstallationsStore installationForAppID: self .appID appName: self .appName])
415
415
.andReturn ([FBLPromise resolvedWith: storedInstallation]);
416
416
417
- // 1.2. Expect API request .
417
+ // 1.2. Auth Token refresh .
418
418
FIRInstallationsItem *responseInstallation =
419
- [FIRInstallationsItem createRegisteredInstallationItem ];
420
- responseInstallation.authToken .token =
421
- [responseInstallation.authToken.token stringByAppendingString: @" _new" ];
422
- OCMExpect ([self .mockAPIService refreshAuthTokenForInstallation: storedInstallation])
423
- .andReturn ([FBLPromise resolvedWith: responseInstallation]);
419
+ [self expectAuthTokenRefreshForInstallation: storedInstallation];
424
420
425
421
// 2. Request auth token.
426
422
FBLPromise<FIRInstallationsItem *> *promise = [self .controller getAuthTokenForcingRefresh: NO ];
427
423
428
424
// 3. Wait for the promise to resolve.
429
- FBLWaitForPromisesWithTimeout (0.5 );
425
+ XCTAssert ( FBLWaitForPromisesWithTimeout (0.5 ) );
430
426
431
427
// 4. Check.
432
428
OCMVerifyAll (self.mockInstallationsStore );
@@ -447,19 +443,15 @@ - (void)testGetAuthTokenForcingRefresh_WhenValidInstallationExists_ThenTokenRequ
447
443
OCMExpect ([self .mockInstallationsStore installationForAppID: self .appID appName: self .appName])
448
444
.andReturn ([FBLPromise resolvedWith: storedInstallation]);
449
445
450
- // 1.2. Expect API request .
446
+ // 1.2. Auth Token refresh .
451
447
FIRInstallationsItem *responseInstallation =
452
- [FIRInstallationsItem createRegisteredInstallationItem ];
453
- responseInstallation.authToken .token =
454
- [responseInstallation.authToken.token stringByAppendingString: @" _new" ];
455
- OCMExpect ([self .mockAPIService refreshAuthTokenForInstallation: storedInstallation])
456
- .andReturn ([FBLPromise resolvedWith: responseInstallation]);
448
+ [self expectAuthTokenRefreshForInstallation: storedInstallation];
457
449
458
450
// 2. Request auth token.
459
451
FBLPromise<FIRInstallationsItem *> *promise = [self .controller getAuthTokenForcingRefresh: YES ];
460
452
461
453
// 3. Wait for the promise to resolve.
462
- FBLWaitForPromisesWithTimeout (0.5 );
454
+ XCTAssert ( FBLWaitForPromisesWithTimeout (0.5 ) );
463
455
464
456
// 4. Check.
465
457
OCMVerifyAll (self.mockInstallationsStore );
@@ -494,7 +486,7 @@ - (void)testGetAuthToken_WhenCalledSeveralTimes_OnlyOneOperationIsPerformed {
494
486
[storagePendingPromise fulfill: storedInstallation];
495
487
496
488
// 4. Wait for the promise to resolve.
497
- FBLWaitForPromisesWithTimeout (0.5 );
489
+ XCTAssert ( FBLWaitForPromisesWithTimeout (0.5 ) );
498
490
499
491
// 5. Check.
500
492
OCMVerifyAll (self.mockInstallationsStore );
@@ -525,6 +517,10 @@ - (void)testGetAuthTokenForceRefresh_WhenCalledSeveralTimes_OnlyOneOperationIsPe
525
517
OCMExpect ([self .mockAPIService refreshAuthTokenForInstallation: storedInstallation])
526
518
.andReturn (pendingAPIPromise);
527
519
520
+ // 1.3. Expect new token to be stored.
521
+ OCMExpect ([self .mockInstallationsStore saveInstallation: responseInstallation])
522
+ .andReturn ([FBLPromise resolvedWith: [NSNull null ]]);
523
+
528
524
// 2. Request auth token n times.
529
525
NSInteger requestCount = 10 ;
530
526
NSMutableArray *authTokenPromises = [NSMutableArray arrayWithCapacity: requestCount];
@@ -536,7 +532,7 @@ - (void)testGetAuthTokenForceRefresh_WhenCalledSeveralTimes_OnlyOneOperationIsPe
536
532
[pendingAPIPromise fulfill: responseInstallation];
537
533
538
534
// 4. Wait for the promise to resolve.
539
- FBLWaitForPromisesWithTimeout (0.5 );
535
+ XCTAssert ( FBLWaitForPromisesWithTimeout (0.5 ) );
540
536
541
537
// 5. Check.
542
538
OCMVerifyAll (self.mockInstallationsStore );
@@ -664,7 +660,7 @@ - (void)testDeleteRegisteredInstallation {
664
660
FBLPromise<NSNull *> *promise = [self .controller deleteInstallation ];
665
661
666
662
// 6. Wait for operations to complete and check.
667
- FBLWaitForPromisesWithTimeout (0.5 );
663
+ XCTAssert ( FBLWaitForPromisesWithTimeout (0.5 ) );
668
664
669
665
XCTAssertNil (promise.error );
670
666
XCTAssertTrue (promise.isFulfilled );
@@ -702,7 +698,7 @@ - (void)testDeleteUnregisteredInstallation {
702
698
FBLPromise<NSNull *> *promise = [self .controller deleteInstallation ];
703
699
704
700
// 6. Wait for operations to complete and check.
705
- FBLWaitForPromisesWithTimeout (0.5 );
701
+ XCTAssert ( FBLWaitForPromisesWithTimeout (0.5 ) );
706
702
707
703
XCTAssertNil (promise.error );
708
704
XCTAssertTrue (promise.isFulfilled );
@@ -742,7 +738,7 @@ - (void)testDeleteRegisteredInstallation_WhenAPIRequestFails_ThenFailsAndInstall
742
738
FBLPromise<NSNull *> *promise = [self .controller deleteInstallation ];
743
739
744
740
// 6. Wait for operations to complete and check.
745
- FBLWaitForPromisesWithTimeout (0.5 );
741
+ XCTAssert ( FBLWaitForPromisesWithTimeout (0.5 ) );
746
742
747
743
XCTAssertEqualObjects (promise.error , error500);
748
744
XCTAssertTrue (promise.isRejected );
@@ -781,7 +777,7 @@ - (void)testDeleteRegisteredInstallation_WhenAPIFailsWithNotFound_ThenInstallati
781
777
FBLPromise<NSNull *> *promise = [self .controller deleteInstallation ];
782
778
783
779
// 6. Wait for operations to complete and check.
784
- FBLWaitForPromisesWithTimeout (0.5 );
780
+ XCTAssert ( FBLWaitForPromisesWithTimeout (0.5 ) );
785
781
786
782
XCTAssertNil (promise.error );
787
783
XCTAssertTrue (promise.isFulfilled );
@@ -839,10 +835,14 @@ - (void)testDeleteInstallation_WhenThereIsOngoingAuthTokenRequest_ThenUsesItsRes
839
835
FBLPromise<NSNull *> *deletePromise = [self .controller deleteInstallation ];
840
836
841
837
// 4. Fulfill auth token promise to proceed.
838
+ // 4.1. Expect new token to be stored on API response.
839
+ OCMExpect ([self .mockInstallationsStore saveInstallation: responseInstallation])
840
+ .andReturn ([FBLPromise resolvedWith: [NSNull null ]]);
841
+
842
842
[pendingAuthTokenAPIPromise fulfill: responseInstallation];
843
843
844
844
// 5. Wait for operations to complete and check the result.
845
- FBLWaitForPromisesWithTimeout (0.5 );
845
+ XCTAssert ( FBLWaitForPromisesWithTimeout (0.5 ) );
846
846
847
847
XCTAssertNil (deletePromise.error );
848
848
XCTAssertTrue (deletePromise.isFulfilled );
@@ -884,7 +884,7 @@ - (void)testDeleteInstallation_WhenNotDefaultApp_ThenIIDIsNotDeleted {
884
884
FBLPromise<NSNull *> *promise = [self .controller deleteInstallation ];
885
885
886
886
// 6. Wait for operations to complete and check.
887
- FBLWaitForPromisesWithTimeout (0.5 );
887
+ XCTAssert ( FBLWaitForPromisesWithTimeout (0.5 ) );
888
888
889
889
XCTAssertNil (promise.error );
890
890
XCTAssertTrue (promise.isFulfilled );
@@ -938,7 +938,7 @@ - (void)testFIDDidChangeNotificationIsSentWhenFIDCreated {
938
938
939
939
// 3. Request FID.
940
940
FBLPromise *promise = [self .controller getInstallationItem ];
941
- FBLWaitForPromisesWithTimeout (0.5 );
941
+ XCTAssert ( FBLWaitForPromisesWithTimeout (0.5 ) );
942
942
943
943
// 4. Check.
944
944
XCTAssertNil (promise.error );
@@ -1035,4 +1035,20 @@ - (void)expectInstallationStoreToBeRequestedAndReturnInstallation:
1035
1035
.andReturn ([FBLPromise resolvedWith: storedInstallation]);
1036
1036
}
1037
1037
1038
+ - (FIRInstallationsItem *)expectAuthTokenRefreshForInstallation :
1039
+ (FIRInstallationsItem *)installation {
1040
+ FIRInstallationsItem *responseInstallation =
1041
+ [FIRInstallationsItem createRegisteredInstallationItem ];
1042
+ responseInstallation.authToken .token =
1043
+ [responseInstallation.authToken.token stringByAppendingString: @" _new" ];
1044
+ OCMExpect ([self .mockAPIService refreshAuthTokenForInstallation: installation])
1045
+ .andReturn ([FBLPromise resolvedWith: responseInstallation]);
1046
+
1047
+ // 1.3. Expect new token to be stored.
1048
+ OCMExpect ([self .mockInstallationsStore saveInstallation: responseInstallation])
1049
+ .andReturn ([FBLPromise resolvedWith: [NSNull null ]]);
1050
+
1051
+ return responseInstallation;
1052
+ }
1053
+
1038
1054
@end
0 commit comments