فهرست منبع

Add config initializers.

brianna 1 سال پیش
والد
کامیت
78e175d238

+ 23 - 8
GoogleSignIn/Sources/GIDVerifyAccountDetail/Implementations/GIDVerifyAccountDetail.m

@@ -27,6 +27,29 @@
 
 @implementation GIDVerifyAccountDetail
 
+- (instancetype)initWithConfig:(GIDConfiguration *)configuration {
+  self = [super init];
+  if (self) {
+    _configuration = configuration;
+  }
+  return self;
+}
+
+- (instancetype)init {
+  GIDConfiguration *configuration;
+  // Get the bundle of the current executable.
+  NSBundle *bundle = NSBundle.mainBundle;
+
+  // If we have a bundle, try to set the active configuration from the bundle's Info.plist.
+  if (bundle) {
+    configuration = [GIDConfiguration configurationFromBundle:bundle];
+  }
+
+  return [self initWithConfig:configuration];
+}
+
+#pragma mark - Public methods
+
 - (void)verifyAccountDetails:(NSArray<GIDVerifiableAccountDetail *> *)accountDetails
     presentingViewController:(UIViewController *)presentingViewController
                   completion:(nullable void (^)(GIDVerifiedAccountDetailResult *_Nullable verifyResult,
@@ -42,14 +65,6 @@
                         hint:(nullable NSString *)hint
                   completion:(nullable void (^)(GIDVerifiedAccountDetailResult *_Nullable verifyResult,
                                                 NSError *_Nullable error))completion {
-  // Get the bundle of the current executable.
-  NSBundle *bundle = NSBundle.mainBundle;
-
-  // If we have a bundle, try to set the active configuration from the bundle's Info.plist.
-  if (bundle) {
-    _configuration = [GIDConfiguration configurationFromBundle:bundle];
-  }
-
   GIDSignInInternalOptions *options =
   [GIDSignInInternalOptions defaultOptionsWithConfiguration:_configuration
                                    presentingViewController:presentingViewController

+ 3 - 0
GoogleSignIn/Sources/Public/GoogleSignIn/GIDVerifyAccountDetail.h

@@ -43,6 +43,9 @@ typedef void (^GIDVerifyCompletion)(GIDVerifiedAccountDetailResult *_Nullable ve
 /// The active configuration for this instance of `GIDVerifyAccountDetail`.
 @property(nonatomic, nullable) GIDConfiguration *configuration;
 
+- (instancetype)initWithConfig:(GIDConfiguration *)config
+  NS_DESIGNATED_INITIALIZER;
+
 /// Starts an interactive verification flow.
 ///
 /// The completion will be called at the end of this process.  Any saved verification

+ 97 - 0
GoogleSignIn/Tests/Unit/GIDVerifyAccountDetailTest.m

@@ -0,0 +1,97 @@
+#import <XCTest/XCTest.h>
+
+#if TARGET_OS_IOS
+#import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDVerifyAccountDetail.h"
+
+#import "GoogleSignIn/Tests/Unit/GIDFakeMainBundle.h"
+
+static NSString * const kClientId = @"FakeClientID";
+
+@interface GIDVerifyAccountDetailTests : XCTestCase {
+@private
+  // Mock |UIViewController|.
+  UIViewController *_presentingViewController;
+
+  // Fake [NSBundle mainBundle];
+  GIDFakeMainBundle *_fakeMainBundle;
+
+  // The |GIDVerifyAccountDetail| object being tested.
+  GIDVerifyAccountDetail *_verifyAccountDetail;
+
+  // [comment]
+  NSArray<GIDVerifiableAccountDetail *> *_verifiableAccountDetails;
+
+  GIDConfiguration *_configuration;
+}
+@end
+
+@implementation GIDVerifyAccountDetailTests
+
+#pragma mark - Lifecycle
+
+- (void)setUp {
+  [super setUp];
+
+  _presentingViewController = [[UIViewController alloc] init];
+
+//  _verifyAccountDetail = [[GIDVerifyAccountDetail alloc] init];
+  _verifyAccountDetail = [[GIDVerifyAccountDetail alloc] init];
+
+  GIDVerifiableAccountDetail *ageOver18Detail = [[GIDVerifiableAccountDetail alloc] initWithAccountDetailType:GIDAccountDetailTypeAgeOver18];
+  _verifiableAccountDetails = @[ageOver18Detail];
+
+  _fakeMainBundle = [[GIDFakeMainBundle alloc] init];
+  [_fakeMainBundle startFakingWithClientID:kClientId];
+  [_fakeMainBundle fakeAllSchemesSupported];
+}
+
+
+#pragma mark - Tests
+
+- (void)testPresentingViewControllerException {
+  _presentingViewController = nil;
+
+  XCTAssertThrows([_verifyAccountDetail verifyAccountDetails:_verifiableAccountDetails
+                                    presentingViewController:_presentingViewController
+                                                  completion:nil]);
+}
+
+- (void)testClientIDMissingException {
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wnonnull"
+ _verifyAccountDetail.configuration = [[GIDConfiguration alloc] initWithClientID:nil];
+#pragma GCC diagnostic pop
+ BOOL threw = NO;
+ @try {
+   [_verifyAccountDetail verifyAccountDetails:_verifiableAccountDetails
+                     presentingViewController:_presentingViewController
+                                   completion:nil];
+ } @catch (NSException *exception) {
+   threw = YES;
+   XCTAssertEqualObjects(exception.description,
+                         @"You must specify |clientID| in |GIDConfiguration|");
+ } @finally {
+ }
+ XCTAssert(threw);
+}
+
+- (void)testSchemesNotSupportedException {
+  [_fakeMainBundle fakeMissingAllSchemes];
+  BOOL threw = NO;
+  @try {
+    [_verifyAccountDetail verifyAccountDetails:_verifiableAccountDetails
+                      presentingViewController:_presentingViewController
+                                    completion:nil];
+  } @catch (NSException *exception) {
+    threw = YES;
+    XCTAssertEqualObjects(exception.description,
+                          @"Your app is missing support for the following URL schemes: "
+                          "fakeclientid");
+  } @finally {
+  }
+  XCTAssert(threw);
+}
+
+@end
+
+#endif // TARGET_OS_IOS