From a42e8700d7597a9650c82f19fb7dee9ee8a708d4 Mon Sep 17 00:00:00 2001 From: Tao Xu Date: Wed, 15 Nov 2023 16:08:01 -0800 Subject: [PATCH] Fix the broken tests for SKAN v2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: - Fix the broken tests on master. - The DateComponents takes daylight saving time into account, so when you ask to subtract 35 days, it doesn't subtract exactly 35×24×60×60 seconds. Instead, it goes back 35 calendar days, which due to daylight saving time changes, can result in a slightly different number of total seconds. Differential Revision: D51377252 fbshipit-source-id: ec579ee3890988ac3dc564c095f5ae4f71134519 --- .../SKAdNetworkReporterTestsV2.swift | 26 ++++++------------- 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/FBSDKCoreKit/FBSDKCoreKitTests/Internal/AppEvents/SKAdNetwork/SKAdNetworkReporterTestsV2.swift b/FBSDKCoreKit/FBSDKCoreKitTests/Internal/AppEvents/SKAdNetwork/SKAdNetworkReporterTestsV2.swift index b75f12d0d..950516fdf 100644 --- a/FBSDKCoreKit/FBSDKCoreKitTests/Internal/AppEvents/SKAdNetwork/SKAdNetworkReporterTestsV2.swift +++ b/FBSDKCoreKit/FBSDKCoreKitTests/Internal/AppEvents/SKAdNetwork/SKAdNetworkReporterTestsV2.swift @@ -452,15 +452,11 @@ final class SKAdNetworkReporterTestsV2: XCTestCase { } func testGetCurrentPostbackWindow() { - // 1st postback window, 0-2 days - var addComponents = DateComponents() - addComponents.day = -1 - addComponents.hour = -23 - addComponents.minute = -59 - addComponents.second = -59 + let currentDate = Date() - let calendar = Calendar(identifier: .gregorian) - var expiredDate = calendar.date(byAdding: addComponents, to: Date()) + // 1st postback window, 0-2 days + var secondsInPast = 2 * 24 * 60 * 60 - 1 + var expiredDate = currentDate.addingTimeInterval(-TimeInterval(secondsInPast)) userDefaultsSpy.set( expiredDate, forKey: "com.facebook.sdk:FBSDKSettingsInstallTimestamp" @@ -471,11 +467,8 @@ final class SKAdNetworkReporterTestsV2: XCTestCase { ) // 2nd postback window, 3-7 days - addComponents.day = -6 - addComponents.hour = -23 - addComponents.minute = -59 - addComponents.second = -59 - expiredDate = calendar.date(byAdding: addComponents, to: Date()) + secondsInPast = 7 * 24 * 60 * 60 - 1 + expiredDate = currentDate.addingTimeInterval(-TimeInterval(secondsInPast)) userDefaultsSpy.set( expiredDate, forKey: "com.facebook.sdk:FBSDKSettingsInstallTimestamp" @@ -486,11 +479,8 @@ final class SKAdNetworkReporterTestsV2: XCTestCase { ) // 3rd postback window, 8-35 days - addComponents.day = -34 - addComponents.hour = -23 - addComponents.minute = -59 - addComponents.second = -59 - expiredDate = calendar.date(byAdding: addComponents, to: Date()) + secondsInPast = 35 * 24 * 60 * 60 - 1 + expiredDate = currentDate.addingTimeInterval(-TimeInterval(secondsInPast)) userDefaultsSpy.set( expiredDate, forKey: "com.facebook.sdk:FBSDKSettingsInstallTimestamp"