Browse Source

Create GIDAccountDetailType enumeration and its mapping. (#385)

Brianna Morales 2 years ago
parent
commit
08df569d9e

+ 20 - 0
GoogleSignIn/Sources/GIDVerifyAccountDetail/Implementations/GIDVerifiableAccountDetail.m

@@ -16,5 +16,25 @@
 
 #import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDVerifiableAccountDetail.h"
 
+NSString *const kAccountDetailTypeAgeOver18Scope = @"https://www.googleapis.com/auth/verified.age.over18.standard";
+
 @implementation GIDVerifiableAccountDetail
+
+- (instancetype)initWithAccountDetailType:(GIDAccountDetailType)accountDetailType {
+  self = [super init];
+  if (self) {
+    _accountDetailType = accountDetailType;
+  }
+  return self;
+}
+
+- (nullable NSString *)scope {
+  switch (self.accountDetailType) {
+    case GIDAccountDetailTypeAgeOver18:
+      return kAccountDetailTypeAgeOver18Scope;
+    default:
+      return nil;
+  }
+}
+
 @end

+ 29 - 1
GoogleSignIn/Sources/Public/GoogleSignIn/GIDVerifiableAccountDetail.h

@@ -16,7 +16,35 @@
 
 #import <Foundation/Foundation.h>
 
-/// Helper object used to hold GIDAccountDetailType representing a list of
+NS_ASSUME_NONNULL_BEGIN
+
+/// An enumeration defining the types of account details Google can verify.
+typedef NS_ENUM(NSInteger, GIDAccountDetailType) {
+  /// User account detail for age over 18.
+  GIDAccountDetailTypeAgeOver18,
+};
+
+/// String scope representing the account detail type for age over 18.
+extern NSString *const kAccountDetailTypeAgeOver18Scope;
+
+/// Helper object used to hold the enumeration representing a list of
 /// account details that Google can verify via GSI.
 @interface GIDVerifiableAccountDetail : NSObject
+
+/// The type of account detail that will be verified.
+@property(nonatomic, readonly) GIDAccountDetailType accountDetailType;
+
+/// Initializes a new GIDVerifiableAccountDetail object with the given
+/// account detail type.
+///
+/// @param accountDetailType The type of account detail that will be verified.
+- (instancetype)initWithAccountDetailType:(GIDAccountDetailType)accountDetailType;
+
+/// Retrieves the scope required to verify the account detail.
+///
+/// @return A string representing the scope required to verify the account detail.
+- (nullable NSString *)scope;
+
 @end
+
+NS_ASSUME_NONNULL_END

+ 29 - 0
GoogleSignIn/Tests/Unit/GIDVerifiableAccountDetailTest.m

@@ -0,0 +1,29 @@
+#import <XCTest/XCTest.h>
+
+#import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDVerifiableAccountDetail.h"
+
+@interface GIDVerifiableAccountDetailTests : XCTestCase
+@end
+
+@implementation GIDVerifiableAccountDetailTests
+
+- (void)testDesignatedInitializer {
+  GIDVerifiableAccountDetail *detail = [[GIDVerifiableAccountDetail alloc] initWithAccountDetailType:GIDAccountDetailTypeAgeOver18];
+  XCTAssertNotNil(detail);
+  XCTAssertEqual(detail.accountDetailType, GIDAccountDetailTypeAgeOver18);
+}
+
+- (void)testScopeRetrieval {
+  GIDVerifiableAccountDetail *detail = [[GIDVerifiableAccountDetail alloc] initWithAccountDetailType:GIDAccountDetailTypeAgeOver18];
+  NSString *retrievedScope = [detail scope];
+  XCTAssertEqualObjects(retrievedScope, kAccountDetailTypeAgeOver18Scope);
+}
+
+- (void)testScopeRetrieval_MissingScope {
+  NSInteger missingScope = 5;
+  GIDVerifiableAccountDetail *detail = [[GIDVerifiableAccountDetail alloc] initWithAccountDetailType:missingScope];
+  NSString *retrievedScope = [detail scope];
+  XCTAssertNil(retrievedScope);
+}
+
+@end