2323#import " FUIGoogleAuth.h"
2424
2525@interface FUIGoogleAuth (Testing)
26- - (GIDSignIn *)configuredGoogleSignIn ;
26+ - (NSString *)clientID ;
27+ - (GIDSignIn *)googleSignIn ;
28+ - (void )handleSignInWithUser : (GIDGoogleUser *)user
29+ error : (NSError *)error
30+ presentingViewController : (UIViewController *)presentingViewController
31+ callback : (FUIAuthProviderSignInCompletionBlock)callback ;
2732@end
2833
2934@interface FirebaseGoogleAuthUITests : XCTestCase
@@ -48,6 +53,7 @@ - (void)setUp {
4853 FIRAuth *auth = [FIRAuth auth ];
4954 self.authUI = [FUIAuth authUIWithAuth: auth];
5055 self.mockProvider = OCMPartialMock ([[FUIGoogleAuth alloc ] initWithAuthUI: self .authUI]);
56+ OCMStub ([_mockProvider clientID ]).andReturn (@" clientID" );
5157}
5258
5359- (void )tearDown {
@@ -82,7 +88,7 @@ - (void)testUseEmulatorCreatesOAuthProvider {
8288 OCMVerify ([self .mockOAuthProvider providerWithProviderID: @" google.com" ]);
8389}
8490
85- - (void )testSuccessfullLogin {
91+ - (void )testSuccessfulLogin {
8692 NSString *testIdToken = @" idToken" ;
8793 NSString *testAccessToken = @" accessToken" ;
8894
@@ -99,11 +105,16 @@ - (void)testSuccessfullLogin {
99105 OCMExpect ([mockGoogleUser authentication ]).andReturn (mockAuthentication);
100106 OCMExpect ([mockAuthentication idToken ]).andReturn (testIdToken);
101107
102- OCMExpect ([_mockProvider configuredGoogleSignIn ]).andReturn (mockSignIn);
108+ OCMExpect ([_mockProvider googleSignIn ]).andReturn (mockSignIn);
103109
104- // forward call to signIn delegate
105- OCMExpect ([mockSignIn signIn ]).andDo (^(NSInvocation *invocation) {
106- [mockSignInDelegate signIn: mockSignIn didSignInForUser: mockGoogleUser withError: nil ];
110+ // forward call to signIn delegate
111+ OCMExpect ([mockSignIn signInWithConfiguration: [OCMArg any ]
112+ presentingViewController: [OCMArg any ]
113+ hint: [OCMArg any ]
114+ callback: [OCMArg any ]]).andDo (^(NSInvocation *invocation) {
115+ void (^callback)(GIDGoogleUser *, NSError *) = nil ;
116+ [invocation getArgument: &callback atIndex: 5 ];
117+ callback (mockGoogleUser, nil );
107118 });
108119
109120 XCTestExpectation *expectation = [self expectationWithDescription: @" logged in" ];
@@ -147,13 +158,15 @@ - (void)testLegacyInitSuccessfulLogin {
147158 NSString *testIdToken = @" idToken" ;
148159 NSString *testAccessToken = @" accessToken" ;
149160
150- _mockProvider = OCMPartialMock ([[FUIGoogleAuth alloc ] init ]);
161+ _mockProvider = OCMPartialMock ([[FUIGoogleAuth alloc ] init ]);
151162
152163 id mockSignInDelegate = _mockProvider;
153164 id mockSignIn = OCMClassMock ([GIDSignIn class ]);
154165 id mockAuthentication = OCMClassMock ([GIDAuthentication class ]);
155166 id mockGoogleUser = OCMClassMock ([GIDGoogleUser class ]);
156167
168+ OCMStub ([_mockProvider clientID ]).andReturn (@" clientID" );
169+
157170 // mock accessToken
158171 OCMExpect ([mockGoogleUser authentication ]).andReturn (mockAuthentication);
159172 OCMExpect ([mockAuthentication accessToken ]).andReturn (testAccessToken);
@@ -162,11 +175,16 @@ - (void)testLegacyInitSuccessfulLogin {
162175 OCMExpect ([mockGoogleUser authentication ]).andReturn (mockAuthentication);
163176 OCMExpect ([mockAuthentication idToken ]).andReturn (testIdToken);
164177
165- OCMExpect ([_mockProvider configuredGoogleSignIn ]).andReturn (mockSignIn);
178+ OCMExpect ([_mockProvider googleSignIn ]).andReturn (mockSignIn);
166179
167- // forward call to signIn delegate
168- OCMExpect ([mockSignIn signIn ]).andDo (^(NSInvocation *invocation) {
169- [mockSignInDelegate signIn: mockSignIn didSignInForUser: mockGoogleUser withError: nil ];
180+ // forward call to signIn delegate
181+ OCMExpect ([mockSignIn signInWithConfiguration: [OCMArg any ]
182+ presentingViewController: [OCMArg any ]
183+ hint: [OCMArg any ]
184+ callback: [OCMArg any ]]).andDo (^(NSInvocation *invocation) {
185+ void (^callback)(GIDGoogleUser *, NSError *) = nil ;
186+ [invocation getArgument: &callback atIndex: 5 ];
187+ callback (mockGoogleUser, nil );
170188 });
171189
172190 XCTestExpectation *expectation = [self expectationWithDescription: @" logged in" ];
@@ -222,11 +240,17 @@ - (void)testErrorLogin {
222240 OCMStub ([mockGoogleUser authentication ]).andReturn (mockAuthentication);
223241 OCMStub ([mockAuthentication idToken ]).andReturn (testIdToken);
224242
225- OCMExpect ([_mockProvider configuredGoogleSignIn ]).andReturn (mockSignIn);
243+ OCMExpect ([_mockProvider googleSignIn ]).andReturn (mockSignIn);
226244 NSError *signInError = [NSError errorWithDomain: @" sign in domain" code: kGIDSignInErrorCodeUnknown userInfo: @{}];
227245
228- OCMExpect ([mockSignIn signIn ]).andDo (^(NSInvocation *invocation) {
229- [mockSignInDelegate signIn: mockSignIn didSignInForUser: mockGoogleUser withError: signInError];
246+ // forward call to signIn delegate
247+ OCMExpect ([mockSignIn signInWithConfiguration: [OCMArg any ]
248+ presentingViewController: [OCMArg any ]
249+ hint: [OCMArg any ]
250+ callback: [OCMArg any ]]).andDo (^(NSInvocation *invocation) {
251+ void (^callback)(GIDGoogleUser *, NSError *) = nil ;
252+ [invocation getArgument: &callback atIndex: 5 ];
253+ callback (mockGoogleUser, signInError);
230254 });
231255
232256
@@ -275,11 +299,17 @@ - (void)testCancelLogin {
275299 OCMStub ([mockGoogleUser authentication ]).andReturn (mockAuthentication);
276300 OCMStub ([mockAuthentication idToken ]).andReturn (testIdToken);
277301
278- OCMExpect ([_mockProvider configuredGoogleSignIn ]).andReturn (mockSignIn);
302+ OCMExpect ([_mockProvider googleSignIn ]).andReturn (mockSignIn);
279303 NSError *signInError = [NSError errorWithDomain: @" sign in domain" code: kGIDSignInErrorCodeCanceled userInfo: @{}];
280304
281- OCMExpect ([mockSignIn signIn ]).andDo (^(NSInvocation *invocation) {
282- [mockSignInDelegate signIn: mockSignIn didSignInForUser: mockGoogleUser withError: signInError];
305+ // forward call to signIn delegate
306+ OCMExpect ([mockSignIn signInWithConfiguration: [OCMArg any ]
307+ presentingViewController: [OCMArg any ]
308+ hint: [OCMArg any ]
309+ callback: [OCMArg any ]]).andDo (^(NSInvocation *invocation) {
310+ void (^callback)(GIDGoogleUser *, NSError *) = nil ;
311+ [invocation getArgument: &callback atIndex: 5 ];
312+ callback (mockGoogleUser, signInError);
283313 });
284314
285315 XCTestExpectation *expectation = [self expectationWithDescription: @" logged in" ];
@@ -313,7 +343,7 @@ - (void)testCancelLogin {
313343
314344- (void )testSignOut {
315345 id mockSignIn = OCMClassMock ([GIDSignIn class ]);
316- OCMExpect ([_mockProvider configuredGoogleSignIn ]).andReturn (mockSignIn);
346+ OCMExpect ([_mockProvider googleSignIn ]).andReturn (mockSignIn);
317347 OCMExpect ([mockSignIn signOut ]);
318348
319349 [_mockProvider signOut ];
@@ -324,7 +354,7 @@ - (void)testSignOut {
324354
325355- (void )testUseEmulatorUsesOAuthProvider {
326356 [self .authUI useEmulatorWithHost: @" host" port: 12345 ];
327- self.mockProvider = OCMPartialMock ([[FUIGoogleAuth alloc ] initWithAuthUI: self .authUI]);
357+ self.mockProvider = OCMPartialMock ([[FUIGoogleAuth alloc ] initWithAuthUI: self .authUI]);
328358
329359 [self .mockProvider signInWithDefaultValue: nil
330360 presentingViewController: nil
@@ -334,7 +364,7 @@ - (void)testUseEmulatorUsesOAuthProvider {
334364 NSDictionary *_Nullable userInfo) {}];
335365
336366 OCMVerify ([self .mockOAuthProvider getCredentialWithUIDelegate: nil completion: OCMOCK_ANY]);
337- OCMVerify (never (), [self .mockProvider configuredGoogleSignIn ]);
367+ OCMVerify (never (), [self .mockProvider googleSignIn ]);
338368}
339369
340370
0 commit comments