aboutsummaryrefslogtreecommitdiffhomepage
path: root/Example/Auth/Tests/FIRUserTests.m
diff options
context:
space:
mode:
authorGravatar Mathew Huusko V <mhuusko5@gmail.com>2017-06-02 18:42:17 +0100
committerGravatar Paul Beusterien <paulbeusterien@google.com>2017-06-02 10:42:17 -0700
commit5c59342e6e19989c012877362af529b3d5d0abeb (patch)
tree457f5da7c41ee45b8d3f55f83017fff2ab718781 /Example/Auth/Tests/FIRUserTests.m
parent6f700dd6c81711a8605c2587b4f2acfd4e07466b (diff)
macOS (#38)
* Example/Core: create macOS app/tests target * Example/Core: Core_Example/Tests -> Core_Example/Tests_iOS * Example/Core: macOS building/tests passing * Example/Database: separate iOS/macOS targets * BuildFrameworks: macOS * .travis.yml, test.sh: AllUnitTests -> AllUnitTests_iOS * test.sh: add AllUnitTests_macOS * Example/Storage: Example/Tests->_iOS * Example/Storage: macOS * test.sh: try to prevent double error 65 * test.sh: build before test * Example/Auth|Messaging: -> _iOS * Example/Auth: macOS build * Example/Auth: macOS passing * Example/Firebase: pod de/re-integrate; fix static DerivedData references; copy phase for OCMock * Example/Firebase: manually copied OCMock, Products Dir vs. Frameworks * Example/Firebase: copied OCMock, prevent header removal * Example/Storage: integration tests sdk fix * Example/Auth: macOS exclude FIRAuthAppCredentialManager; cleanup * Firebase/Core: remove nullability annotation * Firebase/Core|Database: correct TARGET_X usage for correctness and anticipation of OS_WATCH|TV branches * build.swift: style fix * Firebase/Core: FIRLogger: fix macOS intermittent va_list error
Diffstat (limited to 'Example/Auth/Tests/FIRUserTests.m')
-rw-r--r--Example/Auth/Tests/FIRUserTests.m53
1 files changed, 35 insertions, 18 deletions
diff --git a/Example/Auth/Tests/FIRUserTests.m b/Example/Auth/Tests/FIRUserTests.m
index 5a4c00a..c90da44 100644
--- a/Example/Auth/Tests/FIRUserTests.m
+++ b/Example/Auth/Tests/FIRUserTests.m
@@ -20,7 +20,6 @@
#import "Facebook/FIRFacebookAuthProvider.h"
#import "Google/FIRGoogleAuthProvider.h"
#import "Phone/FIRPhoneAuthCredential_Internal.h"
-#import "Phone/FIRPhoneAuthProvider.h"
#import "FIRAdditionalUserInfo.h"
#import "FIRAuth.h"
#import "FIRAuthErrorUtils.h"
@@ -42,6 +41,10 @@
#import "OCMStubRecorder+FIRAuthUnitTests.h"
#import <OCMock/OCMock.h>
+#if TARGET_OS_IOS
+#import "Phone/FIRPhoneAuthProvider.h"
+#endif
+
NS_ASSUME_NONNULL_BEGIN
/** @var kAPIKey
@@ -139,10 +142,10 @@ static NSString *const kPhotoURL = @"https://host.domain/image";
*/
static NSString *const kNewPhotoURL = @"https://host.domain/new/image";
-/** @var kPassword
+/** @var kFakePassword
@brief The fake user password.
*/
-static NSString *const kPassword = @"123456";
+static NSString *const kFakePassword = @"123456";
/** @var kNewPassword
@brief The fake new user password.
@@ -276,10 +279,12 @@ static const NSTimeInterval kExpectationTimeout = 1;
OCMStub([mockFacebookUserInfo federatedID]).andReturn(kFacebookID);
OCMStub([mockFacebookUserInfo email]).andReturn(kFacebookEmail);
+ #if TARGET_OS_IOS
// Mock auth provider user info from Phone auth provider for GetAccountInfo.
id mockPhoneUserInfo = OCMClassMock([FIRGetAccountInfoResponseProviderUserInfo class]);
OCMStub([mockPhoneUserInfo providerID]).andReturn(FIRPhoneAuthProviderID);
OCMStub([mockPhoneUserInfo phoneNumber]).andReturn(kPhoneNumber);
+ #endif
// Mock the root user info object for GetAccountInfo.
id mockGetAccountInfoResponseUser = OCMClassMock([FIRGetAccountInfoResponseUser class]);
@@ -288,11 +293,15 @@ static const NSTimeInterval kExpectationTimeout = 1;
OCMStub([mockGetAccountInfoResponseUser emailVerified]).andReturn(YES);
OCMStub([mockGetAccountInfoResponseUser displayName]).andReturn(kGoogleDisplayName);
OCMStub([mockGetAccountInfoResponseUser photoURL]).andReturn([NSURL URLWithString:kPhotoURL]);
- OCMStub([mockGetAccountInfoResponseUser providerUserInfo])
- .andReturn((@[ mockPasswordUserInfo,
- mockGoogleUserInfo,
- mockFacebookUserInfo,
- mockPhoneUserInfo ]));
+ NSArray *providerUserInfos = @[
+ #if TARGET_OS_IOS
+ mockPhoneUserInfo,
+ #endif
+ mockPasswordUserInfo,
+ mockGoogleUserInfo,
+ mockFacebookUserInfo
+ ];
+ OCMStub([mockGetAccountInfoResponseUser providerUserInfo]).andReturn(providerUserInfos);
OCMStub([mockGetAccountInfoResponseUser passwordHash]).andReturn(kPasswordHash);
XCTestExpectation *expectation = [self expectationWithDescription:@"callback"];
@@ -309,7 +318,7 @@ static const NSTimeInterval kExpectationTimeout = 1;
XCTAssertFalse(user.anonymous);
XCTAssertTrue(user.emailVerified);
XCTAssertEqualObjects(user.refreshToken, kRefreshToken);
- XCTAssertEqual(user.providerData.count, 4u);
+ XCTAssertEqual(user.providerData.count, providerUserInfos.count);
NSDictionary<NSString *, id<FIRUserInfo>> *providerMap =
[self dictionaryWithUserInfoArray:user.providerData];
@@ -338,10 +347,12 @@ static const NSTimeInterval kExpectationTimeout = 1;
XCTAssertNil(facebookUserInfo.photoURL);
XCTAssertEqualObjects(facebookUserInfo.email, kFacebookEmail);
+ #if TARGET_OS_IOS
// Verify FIRUserInfo properties from the phone auth provider.
id<FIRUserInfo> phoneUserInfo = providerMap[FIRPhoneAuthProviderID];
XCTAssertNotNil(phoneUserInfo);
XCTAssertEqualObjects(phoneUserInfo.phoneNumber, kPhoneNumber);
+ #endif
[expectation fulfill];
}];
@@ -425,6 +436,7 @@ static const NSTimeInterval kExpectationTimeout = 1;
OCMVerifyAll(_mockBackend);
}
+#if TARGET_OS_IOS
/** @fn testUpdatePhoneSuccess
@brief Tests the flow of a successful @c updatePhoneNumberCredential:completion: call.
*/
@@ -487,6 +499,7 @@ static const NSTimeInterval kExpectationTimeout = 1;
[self waitForExpectationsWithTimeout:kExpectationTimeout handler:nil];
OCMVerifyAll(_mockBackend);
}
+#endif
/** @fn testUpdatePasswordSuccess
@brief Tests the flow of a successful @c updatePassword:completion: call.
@@ -737,7 +750,7 @@ static const NSTimeInterval kExpectationTimeout = 1;
});
});
FIRAuthCredential *emailCredential =
- [FIREmailAuthProvider credentialWithEmail:kEmail password:kPassword];
+ [FIREmailAuthProvider credentialWithEmail:kEmail password:kFakePassword];
[user reauthenticateWithCredential:emailCredential completion:^(NSError *_Nullable error) {
XCTAssertNil(error);
// Verify that the current user is unchanged.
@@ -851,7 +864,7 @@ static const NSTimeInterval kExpectationTimeout = 1;
});
});
FIRAuthCredential *emailCredential =
- [FIREmailAuthProvider credentialWithEmail:kEmail password:kPassword];
+ [FIREmailAuthProvider credentialWithEmail:kEmail password:kFakePassword];
[user reauthenticateWithCredential:emailCredential completion:^(NSError *_Nullable error) {
// Verify user mismatch error.
XCTAssertEqual(error.code, FIRAuthErrorCodeUserMismatch);
@@ -1087,7 +1100,7 @@ static const NSTimeInterval kExpectationTimeout = 1;
FIRSetAccountInfoResponseCallback callback) {
XCTAssertEqualObjects(request.APIKey, kAPIKey);
XCTAssertEqualObjects(request.accessToken, kAccessToken);
- XCTAssertEqualObjects(request.password, kPassword);
+ XCTAssertEqualObjects(request.password, kFakePassword);
XCTAssertNil(request.localID);
XCTAssertNil(request.displayName);
dispatch_async(FIRAuthGlobalWorkQueue(), ^() {
@@ -1097,7 +1110,7 @@ static const NSTimeInterval kExpectationTimeout = 1;
});
FIRAuthCredential *linkEmailCredential =
- [FIREmailAuthProvider credentialWithEmail:kEmail password:kPassword];
+ [FIREmailAuthProvider credentialWithEmail:kEmail password:kFakePassword];
[authResult.user linkAndRetrieveDataWithCredential:linkEmailCredential
completion:^(FIRAuthDataResult *_Nullable
linkAuthResult,
@@ -1154,7 +1167,7 @@ static const NSTimeInterval kExpectationTimeout = 1;
FIRSetAccountInfoResponseCallback callback) {
XCTAssertEqualObjects(request.APIKey, kAPIKey);
XCTAssertEqualObjects(request.accessToken, kAccessToken);
- XCTAssertEqualObjects(request.password, kPassword);
+ XCTAssertEqualObjects(request.password, kFakePassword);
XCTAssertNil(request.localID);
XCTAssertNil(request.displayName);
dispatch_async(FIRAuthGlobalWorkQueue(), ^() {
@@ -1164,7 +1177,7 @@ static const NSTimeInterval kExpectationTimeout = 1;
});
FIRAuthCredential *linkEmailCredential =
- [FIREmailAuthProvider credentialWithEmail:kEmail password:kPassword];
+ [FIREmailAuthProvider credentialWithEmail:kEmail password:kFakePassword];
[authResult.user linkAndRetrieveDataWithCredential:linkEmailCredential
completion:^(FIRAuthDataResult *_Nullable
linkAuthResult,
@@ -1226,7 +1239,7 @@ static const NSTimeInterval kExpectationTimeout = 1;
});
FIRAuthCredential *linkEmailCredential =
- [FIREmailAuthProvider credentialWithEmail:kEmail password:kPassword];
+ [FIREmailAuthProvider credentialWithEmail:kEmail password:kFakePassword];
[authResult.user linkAndRetrieveDataWithCredential:linkEmailCredential
completion:^(FIRAuthDataResult *_Nullable
linkAuthResult,
@@ -1378,6 +1391,7 @@ static const NSTimeInterval kExpectationTimeout = 1;
OCMVerifyAll(_mockBackend);
}
+#if TARGET_OS_IOS
/** @fn testlinkPhoneAuthCredentialSuccess
@brief Tests the flow of a successful @c linkAndRetrieveDataWithCredential:completion:
call using a phoneAuthCredential.
@@ -1593,6 +1607,7 @@ static const NSTimeInterval kExpectationTimeout = 1;
[self waitForExpectationsWithTimeout:kExpectationTimeout handler:nil];
OCMVerifyAll(_mockBackend);
}
+#endif
#pragma mark - Helpers
@@ -1618,8 +1633,8 @@ static const NSTimeInterval kExpectationTimeout = 1;
});
[self expectGetAccountInfoWithMockUserInfoResponse:mockUserInfoResponse];
[[FIRAuth auth] signOut:NULL];
- [[FIRAuth auth] signInWithEmail:kEmail password:kPassword completion:^(FIRUser *_Nullable user,
- NSError *_Nullable error) {
+ [[FIRAuth auth] signInWithEmail:kEmail password:kFakePassword completion:^(FIRUser *_Nullable user,
+ NSError *_Nullable error) {
XCTAssertNotNil(user);
XCTAssertNil(error);
completion(user);
@@ -1770,6 +1785,7 @@ static const NSTimeInterval kExpectationTimeout = 1;
[self expectGetAccountInfo:providerId federatedID:federatedID displayName:displayName];
}
+#if TARGET_OS_IOS
/** @fn expectVerifyPhoneNumberRequestWithPhoneNumber:error:
@brief Expects a verify phone numner request on the mock backend and calls back with fake
account data or an error.
@@ -1795,6 +1811,7 @@ static const NSTimeInterval kExpectationTimeout = 1;
});
});
}
+#endif
@end