AdditionalUserInfoTests.swift 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright 2023 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 Foundation
  15. import XCTest
  16. @testable import FirebaseAuth
  17. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  18. class AdditionalUserInfoTests: XCTestCase {
  19. let kFakeProfile = ["email": "user@mail.com", "given_name": "User", "family_name": "Doe"]
  20. let kUserName = "User Doe"
  21. let kProviderID = "PROVIDER_ID"
  22. /** @fn testAdditionalUserInfoCreation
  23. @brief Tests successful creation of @c FIRAdditionalUserInfo with
  24. @c initWithProviderID:profile:username: call.
  25. */
  26. func testAdditionalUserInfoCreation() {
  27. let userInfo = AdditionalUserInfo(providerID: kProviderID,
  28. profile: kFakeProfile,
  29. username: kUserName,
  30. isNewUser: true)
  31. XCTAssertEqual(userInfo.providerID, kProviderID)
  32. XCTAssertEqual(userInfo.profile as? [String: String], kFakeProfile)
  33. XCTAssertEqual(userInfo.username, kUserName)
  34. XCTAssertTrue(userInfo.isNewUser)
  35. }
  36. /** @fn testAdditionalUserInfoCoding
  37. @brief Tests successful archiving and unarchiving of @c FIRAdditionalUserInfo.
  38. */
  39. func testAdditionalUserInfoCoding() throws {
  40. let userInfo = AdditionalUserInfo(providerID: kProviderID,
  41. profile: kFakeProfile,
  42. username: kUserName,
  43. isNewUser: true)
  44. XCTAssertTrue(AdditionalUserInfo.supportsSecureCoding)
  45. let data = try NSKeyedArchiver.archivedData(
  46. withRootObject: userInfo,
  47. requiringSecureCoding: true
  48. )
  49. let unarchivedUserInfo = try XCTUnwrap(NSKeyedUnarchiver.unarchivedObject(
  50. ofClass: AdditionalUserInfo.self, from: data
  51. ))
  52. XCTAssertEqual(unarchivedUserInfo.providerID, kProviderID)
  53. XCTAssertEqual(unarchivedUserInfo.profile as? [String: String], kFakeProfile)
  54. XCTAssertEqual(unarchivedUserInfo.username, kUserName)
  55. XCTAssertTrue(unarchivedUserInfo.isNewUser)
  56. }
  57. }