Skip to content

Commit 657f995

Browse files
authored
Merge pull request #160 from firebase/google-provider-unittests
Google provider unittests implementation
2 parents cf7b3ca + d8f7705 commit 657f995

File tree

14 files changed

+4178
-8332
lines changed

14 files changed

+4178
-8332
lines changed

FirebaseAuthUI/FIRAuthPickerViewController.m

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -151,22 +151,22 @@ - (void)signInWithProviderUI:(id<FIRAuthProviderUI>)providerUI {
151151
// Sign out first to make sure sign in starts with a clean state.
152152
[providerUI signOut];
153153
[providerUI signInWithEmail:nil
154-
presentingViewController:self
155-
completion:^(FIRAuthCredential *_Nullable credential,
156-
NSError *_Nullable error) {
157-
if (error) {
158-
[self decrementActivity];
159-
160-
if (error.code == FIRAuthUIErrorCodeUserCancelledSignIn) {
161-
// User cancelled sign in, Do nothing.
162-
return;
163-
}
164-
165-
[self.navigationController dismissViewControllerAnimated:YES completion:^{
166-
[self.authUI invokeResultCallbackWithUser:nil error:error];
167-
}];
168-
return;
169-
}
154+
presentingViewController:self
155+
completion:^(FIRAuthCredential *_Nullable credential,
156+
NSError *_Nullable error) {
157+
if (error) {
158+
[self decrementActivity];
159+
160+
if (error.code == FIRAuthUIErrorCodeUserCancelledSignIn) {
161+
// User cancelled sign in, Do nothing.
162+
return;
163+
}
164+
165+
[self.navigationController dismissViewControllerAnimated:YES completion:^{
166+
[self.authUI invokeResultCallbackWithUser:nil error:error];
167+
}];
168+
return;
169+
}
170170

171171
[self.auth signInWithCredential:credential
172172
completion:^(FIRUser *_Nullable user, NSError *_Nullable error) {
@@ -231,22 +231,22 @@ - (void)handleAccountLinkingForEmail:(NSString *)email
231231
// Sign out first to make sure sign in starts with a clean state.
232232
[bestProvider signOut];
233233
[bestProvider signInWithEmail:email
234-
presentingViewController:self
235-
completion:^(FIRAuthCredential *_Nullable credential,
236-
NSError *_Nullable error) {
237-
if (error) {
238-
[self decrementActivity];
239-
240-
if (error.code == FIRAuthUIErrorCodeUserCancelledSignIn) {
241-
// User cancelled sign in, Do nothing.
242-
return;
243-
}
244-
245-
[self.navigationController dismissViewControllerAnimated:YES completion:^{
246-
[self.authUI invokeResultCallbackWithUser:nil error:error];
247-
}];
248-
return;
249-
}
234+
presentingViewController:self
235+
completion:^(FIRAuthCredential *_Nullable credential,
236+
NSError *_Nullable error) {
237+
if (error) {
238+
[self decrementActivity];
239+
240+
if (error.code == FIRAuthUIErrorCodeUserCancelledSignIn) {
241+
// User cancelled sign in, Do nothing.
242+
return;
243+
}
244+
245+
[self.navigationController dismissViewControllerAnimated:YES completion:^{
246+
[self.authUI invokeResultCallbackWithUser:nil error:error];
247+
}];
248+
return;
249+
}
250250

251251
[self.auth signInWithCredential:credential completion:^(FIRUser *_Nullable user,
252252
NSError *_Nullable error) {

FirebaseAuthUI/FIREmailEntryViewController.m

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -207,27 +207,27 @@ - (void)signInWithProvider:(id<FIRAuthProviderUI>)provider email:(NSString *)ema
207207
// Sign out first to make sure sign in starts with a clean state.
208208
[provider signOut];
209209
[provider signInWithEmail:email
210-
presentingViewController:self
211-
completion:^(FIRAuthCredential *_Nullable credential,
212-
NSError *_Nullable error) {
213-
if (error) {
214-
[self decrementActivity];
215-
216-
[self.navigationController dismissViewControllerAnimated:YES completion:^{
217-
[self.authUI invokeResultCallbackWithUser:nil error:error];
218-
}];
219-
return;
220-
}
221-
222-
[self.auth signInWithCredential:credential
223-
completion:^(FIRUser *_Nullable user, NSError *_Nullable error) {
224-
[self decrementActivity];
225-
226-
[self.navigationController dismissViewControllerAnimated:YES completion:^{
227-
[self.authUI invokeResultCallbackWithUser:user error:error];
228-
}];
229-
}];
230-
}];
210+
presentingViewController:self
211+
completion:^(FIRAuthCredential *_Nullable credential,
212+
NSError *_Nullable error) {
213+
if (error) {
214+
[self decrementActivity];
215+
216+
[self.navigationController dismissViewControllerAnimated:YES completion:^{
217+
[self.authUI invokeResultCallbackWithUser:nil error:error];
218+
}];
219+
return;
220+
}
221+
222+
[self.auth signInWithCredential:credential
223+
completion:^(FIRUser *_Nullable user, NSError *_Nullable error) {
224+
[self decrementActivity];
225+
226+
[self.navigationController dismissViewControllerAnimated:YES completion:^{
227+
[self.authUI invokeResultCallbackWithUser:user error:error];
228+
}];
229+
}];
230+
}];
231231
}
232232

233233
@end

FirebaseFacebookAuthUITests/FirebaseFacebookAuthUITests.m

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,19 @@ - (void)testSuccessfullLogin {
7171

7272
XCTestExpectation *expectation = [self expectationWithDescription:@"logged in"];
7373
[self.provider signInWithEmail:nil
74-
presentingViewController:nil
75-
completion:^(FIRAuthCredential * _Nullable credential, NSError * _Nullable error) {
76-
XCTAssertNil(error);
77-
XCTAssertNotNil(credential);
78-
FIRAuthCredential *expectedCredential = [FIRFacebookAuthProvider credentialWithAccessToken:testToken];
79-
XCTAssertEqualObjects(credential.provider, expectedCredential.provider);
80-
XCTAssertNil(self.provider.idToken);
81-
82-
//verify that we are using token from server
83-
OCMVerify([mockToken tokenString]);
84-
85-
[expectation fulfill];
86-
}];
74+
presentingViewController:nil
75+
completion:^(FIRAuthCredential * _Nullable credential, NSError * _Nullable error) {
76+
XCTAssertNil(error);
77+
XCTAssertNotNil(credential);
78+
FIRAuthCredential *expectedCredential = [FIRFacebookAuthProvider credentialWithAccessToken:testToken];
79+
XCTAssertEqualObjects(credential.provider, expectedCredential.provider);
80+
XCTAssertNil(self.provider.idToken);
81+
82+
//verify that we are using token from server
83+
OCMVerify([mockToken tokenString]);
84+
85+
[expectation fulfill];
86+
}];
8787
[self waitForExpectationsWithTimeout:0.1 handler:^(NSError * _Nullable error) {
8888
XCTAssertNil(error);
8989
}];
@@ -107,19 +107,19 @@ - (void)testCancelLogin {
107107

108108
XCTestExpectation *expectation = [self expectationWithDescription:@"logged in"];
109109
[self.provider signInWithEmail:nil
110-
presentingViewController:nil
111-
completion:^(FIRAuthCredential * _Nullable credential,
112-
NSError * _Nullable error) {
113-
XCTAssertNotNil(error);
114-
XCTAssertEqual(error.code, FIRAuthUIErrorCodeUserCancelledSignIn);
115-
XCTAssertNil(credential);
116-
XCTAssertNil(self.provider.idToken);
117-
118-
//verify that we are not using token from server if user canceled request
119-
OCMReject([mockToken tokenString]);
120-
121-
[expectation fulfill];
122-
}];
110+
presentingViewController:nil
111+
completion:^(FIRAuthCredential * _Nullable credential,
112+
NSError * _Nullable error) {
113+
XCTAssertNotNil(error);
114+
XCTAssertEqual(error.code, FIRAuthUIErrorCodeUserCancelledSignIn);
115+
XCTAssertNil(credential);
116+
XCTAssertNil(self.provider.idToken);
117+
118+
//verify that we are not using token from server if user canceled request
119+
OCMReject([mockToken tokenString]);
120+
121+
[expectation fulfill];
122+
}];
123123
[self waitForExpectationsWithTimeout:0.1 handler:^(NSError * _Nullable error) {
124124
XCTAssertNil(error);
125125
}];
@@ -132,15 +132,15 @@ - (void)testErrorLogin {
132132

133133
XCTestExpectation *expectation = [self expectationWithDescription:@"logged in"];
134134
[self.provider signInWithEmail:nil
135-
presentingViewController:nil
136-
completion:^(FIRAuthCredential * _Nullable credential,
137-
NSError * _Nullable error) {
138-
XCTAssertNotNil(error);
139-
XCTAssertEqual(error.userInfo[NSUnderlyingErrorKey], testError);
140-
XCTAssertNil(credential);
141-
XCTAssertNil(self.provider.idToken);
142-
[expectation fulfill];
143-
}];
135+
presentingViewController:nil
136+
completion:^(FIRAuthCredential * _Nullable credential,
137+
NSError * _Nullable error) {
138+
XCTAssertNotNil(error);
139+
XCTAssertEqual(error.userInfo[NSUnderlyingErrorKey], testError);
140+
XCTAssertNil(credential);
141+
XCTAssertNil(self.provider.idToken);
142+
[expectation fulfill];
143+
}];
144144
[self waitForExpectationsWithTimeout:0.1 handler:^(NSError * _Nullable error) {
145145
XCTAssertNil(error);
146146
}];
@@ -150,19 +150,21 @@ - (void)testSignOut {
150150

151151
// used to make possible initialization of FIRFacebookAuthUI
152152
id mockProviderClass = OCMClassMock([FIRFacebookAuthUI class]);
153-
OCMStub(ClassMethod([mockProviderClass frameworkBundle])).andReturn([NSBundle bundleForClass:[self class]]);
153+
OCMExpect(ClassMethod([mockProviderClass frameworkBundle])).andReturn([NSBundle bundleForClass:[self class]]);
154154

155155
id mockProvider = OCMPartialMock([[FIRFacebookAuthUI alloc] init]);
156156
id mockFacebookManager = OCMClassMock([FBSDKLoginManager class]);
157157

158158
// stub login manager
159-
OCMStub(ClassMethod([mockProvider frameworkBundle])).andReturn([NSBundle bundleForClass:[self class]]);
160-
OCMStub([mockProvider createLoginManger]).andReturn(mockFacebookManager);
159+
OCMExpect(ClassMethod([mockProvider frameworkBundle])).andReturn([NSBundle bundleForClass:[self class]]);
160+
OCMExpect([mockProvider createLoginManger]).andReturn(mockFacebookManager);
161161
[mockProvider configureProvider];
162162

163+
OCMExpect([mockFacebookManager logOut]);
163164
[mockProvider signOut];
164165

165-
OCMVerify([mockFacebookManager logOut]);
166+
OCMVerifyAll(mockFacebookManager);
167+
OCMVerifyAll(mockProvider);
166168

167169
}
168170

0 commit comments

Comments
 (0)