FIRInstallationsStoredItemTests.m 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright 2019 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <XCTest/XCTest.h>
  17. #import "FirebaseInstallations/Source/Tests/Utils/FIRKeyedArchivingUtils.h"
  18. #import "FirebaseInstallations/Source/Library/InstallationsStore/FIRInstallationsStoredAuthToken.h"
  19. #import "FirebaseInstallations/Source/Library/InstallationsStore/FIRInstallationsStoredItem.h"
  20. @interface FIRInstallationsStoredItemTests : XCTestCase
  21. @end
  22. @implementation FIRInstallationsStoredItemTests
  23. - (void)testItemArchivingUnarchiving {
  24. FIRInstallationsStoredAuthToken *authToken = [[FIRInstallationsStoredAuthToken alloc] init];
  25. authToken.token = @"auth-token";
  26. authToken.expirationDate = [NSDate dateWithTimeIntervalSinceNow:12345];
  27. authToken.status = FIRInstallationsAuthTokenStatusTokenReceived;
  28. FIRInstallationsStoredItem *item = [[FIRInstallationsStoredItem alloc] init];
  29. item.firebaseInstallationID = @"inst-id";
  30. item.refreshToken = @"refresh-token";
  31. item.authToken = authToken;
  32. item.registrationStatus = FIRInstallationStatusRegistered;
  33. item.IIDDefaultToken = @"IIDTokenValue";
  34. NSError *error;
  35. NSData *archivedItem = [FIRKeyedArchivingUtils archivedDataWithRootObject:item error:&error];
  36. XCTAssertNotNil(archivedItem, @"Error: %@", error);
  37. FIRInstallationsStoredItem *unarchivedItem =
  38. [FIRKeyedArchivingUtils unarchivedObjectOfClass:[FIRInstallationsStoredItem class]
  39. fromData:archivedItem
  40. error:&error];
  41. XCTAssertNotNil(unarchivedItem, @"Error: %@", error);
  42. XCTAssertEqualObjects(unarchivedItem.firebaseInstallationID, item.firebaseInstallationID);
  43. XCTAssertEqualObjects(unarchivedItem.refreshToken, item.refreshToken);
  44. XCTAssertEqualObjects(unarchivedItem.authToken.token, item.authToken.token);
  45. XCTAssertEqualObjects(unarchivedItem.authToken.expirationDate, item.authToken.expirationDate);
  46. XCTAssertEqual(unarchivedItem.registrationStatus, item.registrationStatus);
  47. XCTAssertEqualObjects(unarchivedItem.IIDDefaultToken, item.IIDDefaultToken);
  48. }
  49. @end