diff options
author | Xiangtian Dai <xiangtian@google.com> | 2017-10-03 09:58:47 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-03 09:58:47 -0700 |
commit | 4b1b3d62d8f72a19e0359642872edd3393451f47 (patch) | |
tree | af76ebec8f1c9047a771ab1a08a8118903491923 /Example | |
parent | bde743ed25166a0b320ae157bfb1d68064f531c9 (diff) |
Simplifies logic to post auth state change notifications, which is also applied more consistently now. (#325)
Diffstat (limited to 'Example')
-rw-r--r-- | Example/Auth/Tests/FIRAuthTests.m | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/Example/Auth/Tests/FIRAuthTests.m b/Example/Auth/Tests/FIRAuthTests.m index 8e00284..d9a7461 100644 --- a/Example/Auth/Tests/FIRAuthTests.m +++ b/Example/Auth/Tests/FIRAuthTests.m @@ -1367,10 +1367,10 @@ static const NSTimeInterval kWaitInterval = .5; shouldHaveUser = YES; [self waitForSignIn]; - // Listener should fire for signing in again as the same user. + // Listener should fire for signing in again as the same user with another access token. expectation = [self expectationWithDescription:@"sign-in again"]; shouldHaveUser = YES; - [self waitForSignIn]; + [self waitForSignInWithAccessToken:kNewAccessToken]; // Listener should fire for signing out. expectation = [self expectationWithDescription:@"sign-out"]; @@ -1450,7 +1450,7 @@ static const NSTimeInterval kWaitInterval = .5; }); [self waitForExpectationsWithTimeout:kExpectationTimeout handler:nil]; - //Verify that the user is nil after failed attempt to refresh tokens caused signed out. + // Verify that the user is nil after failed attempt to refresh tokens caused signed out. XCTAssertNil([FIRAuth auth].currentUser); OCMVerifyAll(_mockBackend); } @@ -1619,11 +1619,20 @@ static const NSTimeInterval kWaitInterval = .5; data. */ - (void)expectGetAccountInfo { + [self expectGetAccountInfoWithAccessToken:kAccessToken]; +} + +/** @fn expectGetAccountInfoWithAccessToken + @param accessToken The access token for the user to check against. + @brief Expects a GetAccountInfo request on the mock backend and calls back with fake account + data. + */ +- (void)expectGetAccountInfoWithAccessToken:(NSString *)accessToken { OCMExpect([_mockBackend getAccountInfo:[OCMArg any] callback:[OCMArg any]]) .andCallBlock2(^(FIRGetAccountInfoRequest *_Nullable request, FIRGetAccountInfoResponseCallback callback) { XCTAssertEqualObjects(request.APIKey, kAPIKey); - XCTAssertEqualObjects(request.accessToken, kAccessToken); + XCTAssertEqualObjects(request.accessToken, accessToken); dispatch_async(FIRAuthGlobalWorkQueue(), ^() { id mockGetAccountInfoResponseUser = OCMClassMock([FIRGetAccountInfoResponseUser class]); OCMStub([mockGetAccountInfoResponseUser localID]).andReturn(kLocalID); @@ -1733,16 +1742,28 @@ static const NSTimeInterval kWaitInterval = .5; @remarks This method also waits for all other pending @c XCTestExpectation instances. */ - (void)waitForSignIn { + [self waitForSignInWithAccessToken:kAccessToken]; +} + +/** @fn waitForSignInWithAccessToken: + @brief Signs in a user to prepare for tests. + @param accessToken The access token for the user to have. + @remarks This method also waits for all other pending @c XCTestExpectation instances. + */ +- (void)waitForSignInWithAccessToken:(NSString *)accessToken { OCMExpect([_mockBackend verifyPassword:[OCMArg any] callback:[OCMArg any]]) .andCallBlock2(^(FIRVerifyPasswordRequest *_Nullable request, FIRVerifyPasswordResponseCallback callback) { dispatch_async(FIRAuthGlobalWorkQueue(), ^() { id mockVeriyPasswordResponse = OCMClassMock([FIRVerifyPasswordResponse class]); - [self stubTokensWithMockResponse:mockVeriyPasswordResponse]; + OCMStub([mockVeriyPasswordResponse IDToken]).andReturn(accessToken); + OCMStub([mockVeriyPasswordResponse approximateExpirationDate]) + .andReturn([NSDate dateWithTimeIntervalSinceNow:kAccessTokenTimeToLive]); + OCMStub([mockVeriyPasswordResponse refreshToken]).andReturn(kRefreshToken); callback(mockVeriyPasswordResponse, nil); }); }); - [self expectGetAccountInfo]; + [self expectGetAccountInfoWithAccessToken:accessToken]; XCTestExpectation *expectation = [self expectationWithDescription:@"callback"]; [[FIRAuth auth] signInWithEmail:kEmail password:kFakePassword completion:^(FIRUser *_Nullable user, NSError *_Nullable error) { |