diff options
Diffstat (limited to 'Example/Auth/Tests/FIRAuthTests.m')
-rw-r--r-- | Example/Auth/Tests/FIRAuthTests.m | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/Example/Auth/Tests/FIRAuthTests.m b/Example/Auth/Tests/FIRAuthTests.m index 35c8362..770f2c7 100644 --- a/Example/Auth/Tests/FIRAuthTests.m +++ b/Example/Auth/Tests/FIRAuthTests.m @@ -548,6 +548,66 @@ static const NSTimeInterval kWaitInterval = .5; OCMVerifyAll(_mockBackend); } +/** @fn testSignInAndRetrieveDataWithEmailPasswordSuccess + @brief Tests the flow of a successful @c signInAndRetrieveDataWithEmail:password:completion: + call. + */ +- (void)testSignInAndRetrieveDataWithEmailPasswordSuccess { + OCMExpect([_mockBackend verifyPassword:[OCMArg any] callback:[OCMArg any]]) + .andCallBlock2(^(FIRVerifyPasswordRequest *_Nullable request, + FIRVerifyPasswordResponseCallback callback) { + XCTAssertEqualObjects(request.APIKey, kAPIKey); + XCTAssertEqualObjects(request.email, kEmail); + XCTAssertEqualObjects(request.password, kFakePassword); + XCTAssertTrue(request.returnSecureToken); + dispatch_async(FIRAuthGlobalWorkQueue(), ^() { + id mockVerifyPasswordResponse = OCMClassMock([FIRVerifyPasswordResponse class]); + [self stubTokensWithMockResponse:mockVerifyPasswordResponse]; + callback(mockVerifyPasswordResponse, nil); + }); + }); + [self expectGetAccountInfo]; + XCTestExpectation *expectation = [self expectationWithDescription:@"callback"]; + [[FIRAuth auth] signOut:NULL]; + [[FIRAuth auth] signInAndRetrieveDataWithEmail:kEmail + password:kFakePassword + completion:^(FIRAuthDataResult *_Nullable result, + NSError *_Nullable error) { + XCTAssertTrue([NSThread isMainThread]); + [self assertUser:result.user]; + XCTAssertFalse(result.additionalUserInfo.isNewUser); + XCTAssertEqualObjects(result.additionalUserInfo.providerID, FIREmailAuthProviderID); + XCTAssertNil(error); + [expectation fulfill]; + }]; + [self waitForExpectationsWithTimeout:kExpectationTimeout handler:nil]; + [self assertUser:[FIRAuth auth].currentUser]; + OCMVerifyAll(_mockBackend); +} + +/** @fn testSignInAndRetrieveDataWithEmailPasswordFailure + @brief Tests the flow of a failed @c signInAndRetrieveDataWithEmail:password:completion: call. + */ +- (void)testSignInAndRetrieveDataWithEmailPasswordFailure { + OCMExpect([_mockBackend verifyPassword:[OCMArg any] callback:[OCMArg any]]) + .andDispatchError2([FIRAuthErrorUtils wrongPasswordErrorWithMessage:nil]); + XCTestExpectation *expectation = [self expectationWithDescription:@"callback"]; + [[FIRAuth auth] signOut:NULL]; + [[FIRAuth auth] signInAndRetrieveDataWithEmail:kEmail + password:kFakePassword + completion:^(FIRAuthDataResult *_Nullable result, + NSError *_Nullable error) { + XCTAssertTrue([NSThread isMainThread]); + XCTAssertNil(result); + XCTAssertEqual(error.code, FIRAuthErrorCodeWrongPassword); + XCTAssertNotNil(error.userInfo[NSLocalizedDescriptionKey]); + [expectation fulfill]; + }]; + [self waitForExpectationsWithTimeout:kExpectationTimeout handler:nil]; + XCTAssertNil([FIRAuth auth].currentUser); + OCMVerifyAll(_mockBackend); +} + /** @fn testResetPasswordSuccess @brief Tests the flow of a successful @c confirmPasswordResetWithCode:newPassword:completion: call. |