Browse Source

Clean up test initialization for GIDAuthorizationFlowFake

Matt Mathias 1 year ago
parent
commit
48cdb98286

+ 1 - 1
GoogleSignIn/Sources/GIDAuthorization.m

@@ -100,7 +100,7 @@ static NSString *const kTokenURLTemplate = @"https://%@/token";
     GIDConfiguration *defaultConfiguration = [GIDConfiguration configurationFromBundle:mainBundle];
     _currentConfiguration = configuration ?: defaultConfiguration;
     _authFlow = authFlow;
-    // FIXME: This should be cleaner
+    // FIXME: This should be cleaner; i.e., the options has a configuration too...
     _authFlow.configuration = _currentConfiguration;
     _currentOptions = _authFlow.options;
     

+ 0 - 4
GoogleSignIn/Sources/GIDAuthorizationFlow/Implementations/Fake/GIDAuthorizationFlowFake.h

@@ -30,13 +30,9 @@ NS_ASSUME_NONNULL_BEGIN
 @property(nonatomic, strong, nullable) id<OIDExternalUserAgentSession> currentUserAgentSession;
 @property(nonatomic, copy, nullable) NSString *emmSupport;
 @property(nonatomic, strong, nullable) NSError *error;
-
 @property(nonatomic, strong, nullable) GIDConfiguration *configuration;
 @property(nonatomic, strong, nullable) OIDServiceConfiguration *serviceConfiguration;
 
-+ (instancetype)fakeWithDefaultOptions;
-+ (instancetype)fakeWithDefaultOptionsConfiguration:(GIDConfiguration *)configuration;
-
 @end
 
 NS_ASSUME_NONNULL_END

+ 0 - 34
GoogleSignIn/Sources/GIDAuthorizationFlow/Implementations/Fake/GIDAuthorizationFlowFake.m

@@ -21,40 +21,6 @@
 
 @implementation GIDAuthorizationFlowFake
 
-+ (instancetype)fakeWithDefaultOptions {
-  UIViewController *vc = [[UIViewController alloc] init];
-  GIDSignInInternalOptions *options = [GIDSignInInternalOptions defaultOptionsWithConfiguration:nil
-                                                                       presentingViewController:vc
-                                                                                      loginHint:nil
-                                                                                  addScopesFlow:NO
-                                                                                     completion:nil];
-  return [[self alloc] initWithSignInOptions:options
-                                   authState:nil
-                                 profileData:nil
-                                  googleUser:nil
-                    externalUserAgentSession:nil
-                                  emmSupport:nil
-                                       error:nil];
-}
-
-+ (instancetype)fakeWithDefaultOptionsConfiguration:(GIDConfiguration *)configuration {
-  UIViewController *vc = [[UIViewController alloc] init];
-  GIDSignInInternalOptions *options =
-    [GIDSignInInternalOptions defaultOptionsWithConfiguration:configuration
-                                     presentingViewController:vc
-                                                    loginHint:nil
-                                                addScopesFlow:NO
-                                                   completion:nil];
-  return [[self alloc] initWithSignInOptions:options
-                                   authState:nil
-                                 profileData:nil
-                                  googleUser:nil
-                    externalUserAgentSession:nil
-                                  emmSupport:nil
-                                       error:nil];
-
-}
-
 - (instancetype)initWithSignInOptions:(GIDSignInInternalOptions *)options
                             authState:(OIDAuthState *)authState
                           profileData:(nullable GIDProfileData *)profileData

+ 34 - 12
GoogleSignIn/Tests/Unit/GIDAuthorizationTests/GIDAuthorizationTest.m

@@ -8,6 +8,7 @@
 #import <XCTest/XCTest.h>
 #import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDAuthorization.h"
 #import "GoogleSignIn/Sources/GIDAuthorization_Private.h"
+#import "GoogleSignIn/Sources/GIDSignInInternalOptions.h"
 #import "GoogleSignIn/Tests/Unit/GIDConfiguration+Testing.h"
 #import "GoogleSignIn/Tests/Unit/OIDAuthorizationRequest+Testing.h"
 
@@ -20,19 +21,28 @@
 @implementation GIDAuthorizationTest
 
 - (void)testAuthorizationConfigurationAssertValidParameters {
-  GIDConfiguration *configuration =
+  GIDConfiguration *config =
     [[GIDConfiguration alloc] initWithClientID:OIDAuthorizationRequestTestingClientID
                                 serverClientID:kServerClientID
                                   hostedDomain:kHostedDomain
                                    openIDRealm:kOpenIDRealm];
-  GIDAuthorizationFlowFake *fakeFlow =
-    [GIDAuthorizationFlowFake fakeWithDefaultOptionsConfiguration:configuration];
-  GIDAuthorization *authorization =
-    [[GIDAuthorization alloc] initWithKeychainStore:nil
-                                      configuration:configuration
-                       authorizationFlowCoordinator:fakeFlow];
   
+  GIDSignInInternalOptions *opts = [GIDSignInInternalOptions defaultOptionsWithConfiguration:config
+                                                                    presentingViewController:nil
+                                                                                   loginHint:nil
+                                                                               addScopesFlow:NO
+                                                                                  completion:nil];
+  GIDAuthorizationFlowFake *fakeFlow = [[GIDAuthorizationFlowFake alloc] initWithSignInOptions:opts
+                                                                                     authState:nil
+                                                                                   profileData:nil
+                                                                                    googleUser:nil
+                                                                      externalUserAgentSession:nil
+                                                                                    emmSupport:nil
+                                                                                         error:nil];
   @try {
+    GIDAuthorization *authorization = [[GIDAuthorization alloc] initWithKeychainStore:nil
+                                                                        configuration:config
+                                                         authorizationFlowCoordinator:fakeFlow];
     [authorization assertValidParameters];
   }
   @catch (NSException *exception) {
@@ -42,12 +52,24 @@
 }
 
 - (void)testAuthorizationConfigurationAssertValidPresentingController {
-  GIDAuthorizationFlowFake *fakeFlow = [GIDAuthorizationFlowFake fakeWithDefaultOptions];
-  GIDAuthorization *authorization =
-    [[GIDAuthorization alloc] initWithKeychainStore:nil
-                                      configuration:nil
-                       authorizationFlowCoordinator:fakeFlow];
+  
+  UIViewController *vc = [[UIViewController alloc] init];
+  GIDSignInInternalOptions *opts = [GIDSignInInternalOptions defaultOptionsWithConfiguration:nil
+                                                                    presentingViewController:vc
+                                                                                   loginHint:nil
+                                                                               addScopesFlow:NO
+                                                                                  completion:nil];
+  GIDAuthorizationFlowFake *fakeFlow = [[GIDAuthorizationFlowFake alloc] initWithSignInOptions:opts
+                                                                                     authState:nil
+                                                                                   profileData:nil
+                                                                                    googleUser:nil
+                                                                      externalUserAgentSession:nil
+                                                                                    emmSupport:nil
+                                                                                         error:nil];
   @try {
+    GIDAuthorization *authorization = [[GIDAuthorization alloc] initWithKeychainStore:nil
+                                                                        configuration:nil
+                                                         authorizationFlowCoordinator:fakeFlow];
     [authorization assertValidPresentingController];
   }
   @catch (NSException *exception) {