GIDGoogleUserTest.m 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright 2021 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDGoogleUser.h"
  15. #import <XCTest/XCTest.h>
  16. #import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDAuthentication.h"
  17. #import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDProfileData.h"
  18. #import "GoogleSignIn/Sources/GIDAuthentication_Private.h"
  19. #import "GoogleSignIn/Sources/GIDGoogleUser_Private.h"
  20. #import "GoogleSignIn/Tests/Unit/GIDProfileData+Testing.h"
  21. #import "GoogleSignIn/Tests/Unit/OIDAuthState+Testing.h"
  22. #import "GoogleSignIn/Tests/Unit/OIDAuthorizationRequest+Testing.h"
  23. #import "GoogleSignIn/Tests/Unit/OIDTokenResponse+Testing.h"
  24. #ifdef SWIFT_PACKAGE
  25. @import AppAuth;
  26. #else
  27. #import <AppAuth/OIDAuthState.h>
  28. #endif
  29. @interface GIDGoogleUserTest : XCTestCase
  30. @end
  31. @implementation GIDGoogleUserTest
  32. #pragma mark - Tests
  33. - (void)testInitWithAuthState {
  34. OIDAuthState *authState = [OIDAuthState testInstance];
  35. GIDGoogleUser *user = [[GIDGoogleUser alloc] initWithAuthState:authState
  36. profileData:[GIDProfileData testInstance]];
  37. GIDAuthentication *authentication =
  38. [[GIDAuthentication alloc] initWithAuthState:authState];
  39. XCTAssertEqualObjects(user.authentication, authentication);
  40. XCTAssertEqualObjects(user.grantedScopes, @[ OIDAuthorizationRequestTestingScope2 ]);
  41. XCTAssertEqualObjects(user.userID, kUserID);
  42. XCTAssertEqualObjects(user.hostedDomain, kHostedDomain);
  43. XCTAssertEqualObjects(user.serverAuthCode, kServerAuthCode);
  44. XCTAssertEqualObjects(user.profile, [GIDProfileData testInstance]);
  45. }
  46. - (void)testCoding {
  47. GIDGoogleUser *user = [[GIDGoogleUser alloc] initWithAuthState:[OIDAuthState testInstance]
  48. profileData:[GIDProfileData testInstance]];
  49. NSData *data = [NSKeyedArchiver archivedDataWithRootObject:user];
  50. GIDGoogleUser *newUser = [NSKeyedUnarchiver unarchiveObjectWithData:data];
  51. XCTAssertEqualObjects(user, newUser);
  52. XCTAssertTrue(GIDGoogleUser.supportsSecureCoding);
  53. }
  54. @end