RLMAncillaryObjectServerTests.m 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. ////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2017 Realm Inc.
  4. //
  5. // Licensed under the Apache License, Version 2.0 (the "License");
  6. // you may not use this file except in compliance with the License.
  7. // You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. //
  17. ////////////////////////////////////////////////////////////////////////////
  18. #import <XCTest/XCTest.h>
  19. #import "RLMSyncSessionRefreshHandle+ObjectServerTests.h"
  20. @interface RLMAncillaryObjectServerTests : XCTestCase
  21. @end
  22. @interface RLMSyncSessionRefreshHandle ()
  23. + (NSDate *)fireDateForTokenExpirationDate:(NSDate *)date nowDate:(NSDate *)nowDate;
  24. @end
  25. @implementation RLMAncillaryObjectServerTests
  26. /// Ensure the `fireDateForTokenExpirationDate:nowDate:` method works properly.
  27. /// Rationale: we swizzle this method out for our end-to-end tests, so we need to verify the original works.
  28. - (void)testRefreshHandleDateComparison {
  29. [RLMSyncSessionRefreshHandle calculateFireDateUsingTestLogic:NO blockOnRefreshCompletion:nil];
  30. // The method should return nil if the dates are equal in value.
  31. NSDate *date = [NSDate date];
  32. NSDate *nowDate = [NSDate dateWithTimeIntervalSince1970:date.timeIntervalSince1970];
  33. XCTAssertNil([RLMSyncSessionRefreshHandle fireDateForTokenExpirationDate:date nowDate:nowDate]);
  34. // The method should return nil if the expiration date is in the past.
  35. date = [NSDate dateWithTimeIntervalSince1970:(date.timeIntervalSince1970 - 1)];
  36. XCTAssertNil([RLMSyncSessionRefreshHandle fireDateForTokenExpirationDate:date nowDate:nowDate]);
  37. // The method should return nil if the expiration date is not far enough forward in the future.
  38. date = [NSDate dateWithTimeIntervalSince1970:(date.timeIntervalSince1970 + 1)];
  39. XCTAssertNil([RLMSyncSessionRefreshHandle fireDateForTokenExpirationDate:date nowDate:nowDate]);
  40. // The method should return an actual date if the expiration date is far enough forward in the future.
  41. date = [NSDate dateWithTimeIntervalSince1970:(date.timeIntervalSince1970 + 100)];
  42. NSDate *fireDate = [RLMSyncSessionRefreshHandle fireDateForTokenExpirationDate:date nowDate:nowDate];
  43. XCTAssertNotNil(fireDate);
  44. XCTAssertGreaterThan(fireDate.timeIntervalSinceReferenceDate, nowDate.timeIntervalSinceReferenceDate);
  45. XCTAssertLessThan(fireDate.timeIntervalSinceReferenceDate, date.timeIntervalSinceReferenceDate);
  46. }
  47. @end