From 9cdf55b8c5bc5fb1a7474f47b052f51bcaa6fbae Mon Sep 17 00:00:00 2001 From: RyosukeCla Date: Fri, 29 Nov 2024 13:17:51 +0900 Subject: [PATCH 1/2] update ViewInspector Version --- .../xcshareddata/swiftpm/Package.resolved | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ios/nativebrik.xcworkspace/xcshareddata/swiftpm/Package.resolved b/ios/nativebrik.xcworkspace/xcshareddata/swiftpm/Package.resolved index 4abc8b7..fbc9d2b 100644 --- a/ios/nativebrik.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/ios/nativebrik.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -1,14 +1,15 @@ { + "originHash" : "7abf1dd76d62709d50ab97ba7b5907de6a95cbc813d2bf154db0688b92d85914", "pins" : [ { "identity" : "viewinspector", "kind" : "remoteSourceControl", "location" : "https://github.com/nalexn/ViewInspector", "state" : { - "revision" : "07c090d73e0169c342a4ed46e9010be2781eca1e", - "version" : "0.9.8" + "revision" : "5acfa0a3c095ac9ad050abe51c60d1831e8321da", + "version" : "0.10.0" } } ], - "version" : 2 + "version" : 3 } From e8d68d41128f863250ec7a86615c150a5bceb02b Mon Sep 17 00:00:00 2001 From: RyosukeCla Date: Fri, 29 Nov 2024 13:18:32 +0900 Subject: [PATCH 2/2] [ios] impl unit test for sync date from http url response --- .../Nativebrik.xcodeproj/project.pbxproj | 4 ++ .../Nativebrik/util/ios-compat.swift | 8 ++++ .../NativebrikTests/ios-compat.swift | 39 +++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 ios/Nativebrik/NativebrikTests/ios-compat.swift diff --git a/ios/Nativebrik/Nativebrik.xcodeproj/project.pbxproj b/ios/Nativebrik/Nativebrik.xcodeproj/project.pbxproj index 866ba9c..95df9ed 100644 --- a/ios/Nativebrik/Nativebrik.xcodeproj/project.pbxproj +++ b/ios/Nativebrik/Nativebrik.xcodeproj/project.pbxproj @@ -56,6 +56,7 @@ C13634642AEF92F700B9F437 /* embedding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C13634632AEF92F700B9F437 /* embedding.swift */; }; C13634662AF242B100B9F437 /* decode.swift in Sources */ = {isa = PBXBuildFile; fileRef = C13634652AF242B100B9F437 /* decode.swift */; }; C13634682AF36D7600B9F437 /* repository.swift in Sources */ = {isa = PBXBuildFile; fileRef = C13634672AF36D7600B9F437 /* repository.swift */; }; + C14FEF532CF95D8B00D243A0 /* ios-compat.swift in Sources */ = {isa = PBXBuildFile; fileRef = C14FEF522CF95D8300D243A0 /* ios-compat.swift */; }; C1F488CC2B5521FC009D7DAD /* placeholder.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1F488CB2B5521FC009D7DAD /* placeholder.swift */; }; C1FFFD7A2B22E98B00ACD132 /* yoga.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = C136344F2AEB7D5800B9F437 /* yoga.xcframework */; }; C1FFFD7D2B22E98C00ACD132 /* YogaKit.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = C13634522AEB7D6600B9F437 /* YogaKit.xcframework */; }; @@ -124,6 +125,7 @@ C13634652AF242B100B9F437 /* decode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = decode.swift; sourceTree = ""; }; C13634672AF36D7600B9F437 /* repository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = repository.swift; sourceTree = ""; }; C13634882B036E5D00B9F437 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; name = PrivacyInfo.xcprivacy; path = Nativebrik/PrivacyInfo.xcprivacy; sourceTree = ""; }; + C14FEF522CF95D8300D243A0 /* ios-compat.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ios-compat.swift"; sourceTree = ""; }; C1F488CB2B5521FC009D7DAD /* placeholder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = placeholder.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -283,6 +285,7 @@ C13633A92AEB769800B9F437 /* NativebrikTests */ = { isa = PBXGroup; children = ( + C14FEF522CF95D8300D243A0 /* ios-compat.swift */, C13633AA2AEB769800B9F437 /* sdk.swift */, C13634552AEB81EC00B9F437 /* experiment-test.swift */, C136345F2AEBB49900B9F437 /* user.swift */, @@ -470,6 +473,7 @@ files = ( C13634562AEB81EC00B9F437 /* experiment-test.swift in Sources */, C13634622AEBBC6500B9F437 /* remote-config.swift in Sources */, + C14FEF532CF95D8B00D243A0 /* ios-compat.swift in Sources */, C13633AB2AEB769800B9F437 /* sdk.swift in Sources */, C13634642AEF92F700B9F437 /* embedding.swift in Sources */, C13634682AF36D7600B9F437 /* repository.swift in Sources */, diff --git a/ios/Nativebrik/Nativebrik/util/ios-compat.swift b/ios/Nativebrik/Nativebrik/util/ios-compat.swift index f710f5b..dc16002 100644 --- a/ios/Nativebrik/Nativebrik/util/ios-compat.swift +++ b/ios/Nativebrik/Nativebrik/util/ios-compat.swift @@ -9,6 +9,14 @@ import Foundation private var DATETIME_OFFSET: Int64 = 0 +func __for_test_sync_datetime_offset(offset: Int64) { + DATETIME_OFFSET = offset +} + +func __for_test_get_datetime_offset() -> Int64 { + return DATETIME_OFFSET +} + func syncDateFromHTTPURLResponse(t0: Date, res: HTTPURLResponse) { let t1 = getCurrentDate() diff --git a/ios/Nativebrik/NativebrikTests/ios-compat.swift b/ios/Nativebrik/NativebrikTests/ios-compat.swift new file mode 100644 index 0000000..03b0f37 --- /dev/null +++ b/ios/Nativebrik/NativebrikTests/ios-compat.swift @@ -0,0 +1,39 @@ +// +// ios-compat.swift +// Nativebrik +// +// Created by Ryosuke Suzuki on 2024/11/29. +// + +import XCTest +import ViewInspector +@testable import Nativebrik + +final class IOSCompatTest: XCTestCase { + func testSyncDateFromHTTPULReponseShouldWork() throws { + __for_test_sync_datetime_offset(offset: 0) + let url = URL(string: "https://example.com")! + let now = Date() + let tomorrow = now.addingTimeInterval(24 * 60 * 60) + let formatter = DateFormatter() + formatter.dateFormat = "EEE, dd MMM yyyy HH:mm:ss zzz" + formatter.locale = Locale(identifier: "en_US_POSIX") + let formattedDate = formatter.string(from: tomorrow) + let res = HTTPURLResponse(url: url, statusCode: 400, httpVersion: "2.0", headerFields: [ + "Date": formattedDate + ])! + syncDateFromHTTPURLResponse(t0: now, res: res) + let offset = __for_test_get_datetime_offset() + let diff = abs(offset - 24 * 60 * 60 * 1000) + assert(diff < 1000, "time offset should be around 24 hours") + } + + func testGetCurrentDate() throws { + __for_test_sync_datetime_offset(offset: 24 * 60 * 60 * 1000) + let deviceCurrent = Date() + let syncedCurrent = getCurrentDate() + let diff = syncedCurrent.timeIntervalSince1970 - deviceCurrent.timeIntervalSince1970 + assert(abs(diff - 24 * 60 * 60) < 2, "diff should be around 2 sec") + } + +}