diff options
Diffstat (limited to 'Example/Auth/Tests/FIRPhoneAuthProviderTests.m')
-rw-r--r-- | Example/Auth/Tests/FIRPhoneAuthProviderTests.m | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/Example/Auth/Tests/FIRPhoneAuthProviderTests.m b/Example/Auth/Tests/FIRPhoneAuthProviderTests.m index e00fa1f..96432c7 100644 --- a/Example/Auth/Tests/FIRPhoneAuthProviderTests.m +++ b/Example/Auth/Tests/FIRPhoneAuthProviderTests.m @@ -31,6 +31,7 @@ #import "FIRAuthGlobalWorkQueue.h" #import "FIRAuthNotificationManager.h" #import "FIRAuthRequestConfiguration.h" +#import "FIRAuthSettings.h" #import "FIRAuthUIDelegate.h" #import "FIRAuthURLPresenter.h" #import "FIRAuthWebUtils.h" @@ -362,6 +363,80 @@ static const NSTimeInterval kExpectationTimeout = 2; OCMVerifyAll(_mockAppCredentialManager); } +/** @fn testVerifyPhoneNumberInTestMode + @brief Tests a successful invocation of @c verifyPhoneNumber:completion: when app verification + is disabled. + */ +- (void)testVerifyPhoneNumberInTestMode { + // Disable app verification. + FIRAuthSettings *settings = [[FIRAuthSettings alloc] init]; + settings.appVerificationDisabledForTesting = YES; + OCMStub([_mockAuth settings]).andReturn(settings); + OCMExpect([_mockNotificationManager checkNotificationForwardingWithCallback:OCMOCK_ANY]) + .andCallBlock1(^(FIRAuthNotificationForwardingCallback callback) { callback(YES); }); + OCMExpect([_mockBackend sendVerificationCode:[OCMArg any] callback:[OCMArg any]]) + .andCallBlock2(^(FIRSendVerificationCodeRequest *request, + FIRSendVerificationCodeResponseCallback callback) { + XCTAssertEqualObjects(request.phoneNumber, kTestPhoneNumber); + // Assert that the app credential is nil when in test mode. + XCTAssertNil(request.appCredential); + dispatch_async(FIRAuthGlobalWorkQueue(), ^() { + id mockSendVerificationCodeResponse = OCMClassMock([FIRSendVerificationCodeResponse class]); + OCMStub([mockSendVerificationCodeResponse verificationID]).andReturn(kTestVerificationID); + callback(mockSendVerificationCodeResponse, nil); + }); + }); + + XCTestExpectation *expectation = [self expectationWithDescription:@"callback"]; + [_provider verifyPhoneNumber:kTestPhoneNumber + completion:^(NSString *_Nullable verificationID, NSError *_Nullable error) { + XCTAssertTrue([NSThread isMainThread]); + XCTAssertNil(error); + XCTAssertEqualObjects(verificationID, kTestVerificationID); + [expectation fulfill]; + }]; + [self waitForExpectationsWithTimeout:kExpectationTimeout handler:nil]; + OCMVerifyAll(_mockBackend); + OCMVerifyAll(_mockNotificationManager); + OCMVerifyAll(_mockAppCredentialManager); +} + +/** @fn testVerifyPhoneNumberInTestModeFailure + @brief Tests a failed invocation of @c verifyPhoneNumber:completion: when app verification + is disabled. + */ +- (void)testVerifyPhoneNumberInTestModeFailure { + // Disable app verification. + FIRAuthSettings *settings = [[FIRAuthSettings alloc] init]; + settings.appVerificationDisabledForTesting = YES; + OCMStub([_mockAuth settings]).andReturn(settings); + OCMExpect([_mockNotificationManager checkNotificationForwardingWithCallback:OCMOCK_ANY]) + .andCallBlock1(^(FIRAuthNotificationForwardingCallback callback) { callback(YES); }); + OCMExpect([_mockBackend sendVerificationCode:[OCMArg any] callback:[OCMArg any]]) + .andCallBlock2(^(FIRSendVerificationCodeRequest *request, + FIRSendVerificationCodeResponseCallback callback) { + XCTAssertEqualObjects(request.phoneNumber, kTestPhoneNumber); + // Assert that the app credential is nil when in test mode. + XCTAssertNil(request.appCredential); + dispatch_async(FIRAuthGlobalWorkQueue(), ^() { + callback(nil, [FIRAuthErrorUtils networkErrorWithUnderlyingError:[NSError new]]); + }); + }); + + XCTestExpectation *expectation = [self expectationWithDescription:@"callback"]; + [_provider verifyPhoneNumber:kTestPhoneNumber + completion:^(NSString *_Nullable verificationID, NSError *_Nullable error) { + XCTAssertTrue([NSThread isMainThread]); + XCTAssertNil(verificationID); + XCTAssertEqual(error.code, FIRAuthErrorCodeNetworkError); + [expectation fulfill]; + }]; + [self waitForExpectationsWithTimeout:kExpectationTimeout handler:nil]; + OCMVerifyAll(_mockBackend); + OCMVerifyAll(_mockNotificationManager); + OCMVerifyAll(_mockAppCredentialManager); +} + /** @fn testVerifyPhoneNumberUIDelegate @brief Tests a successful invocation of @c verifyPhoneNumber:UIDelegate:completion:. */ |