From ffb0eb6963ae40ddd7dfc6f37b4c27897c1cfc20 Mon Sep 17 00:00:00 2001 From: Kitselyuk Egor Date: Wed, 5 Jun 2024 21:08:48 +0300 Subject: [PATCH] MBX-3338: Fix minus ttl --- .../Services/TTLValidationService.swift | 3 ++- Mindbox/Info.plist | 2 +- .../InappTTLTests.swift | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Mindbox/InAppMessages/Configuration/Services/TTLValidationService.swift b/Mindbox/InAppMessages/Configuration/Services/TTLValidationService.swift index ae83580b..0232e1d0 100644 --- a/Mindbox/InAppMessages/Configuration/Services/TTLValidationService.swift +++ b/Mindbox/InAppMessages/Configuration/Services/TTLValidationService.swift @@ -28,7 +28,8 @@ class TTLValidationService: TTLValidationProtocol { } guard let ttl = config.settings?.ttl?.inapps, - let ttlMilliseconds = try? ttl.parseTimeSpanToMillis() else { + let ttlMilliseconds = try? ttl.parseTimeSpanToMillis(), + ttlMilliseconds >= 0 else { Logger.common(message: "[TTL] Variables are missing or corrupted. Inapps reset will not be performed.") return false } diff --git a/Mindbox/Info.plist b/Mindbox/Info.plist index 48fa226e..9d9bfc17 100644 --- a/Mindbox/Info.plist +++ b/Mindbox/Info.plist @@ -17,6 +17,6 @@ CFBundleShortVersionString $(MARKETING_VERSION) CFBundleVersion - 5609 + 5612 diff --git a/MindboxTests/InApp/Tests/InAppConfigResponseTests/InappTTLTests.swift b/MindboxTests/InApp/Tests/InAppConfigResponseTests/InappTTLTests.swift index 0a500368..63050e2b 100644 --- a/MindboxTests/InApp/Tests/InAppConfigResponseTests/InappTTLTests.swift +++ b/MindboxTests/InApp/Tests/InAppConfigResponseTests/InappTTLTests.swift @@ -81,4 +81,22 @@ class InappTTLTests: XCTestCase { let result = service.needResetInapps(config: config) XCTAssertFalse(result, "Inapps не должны быть сброшены, так как время TTL еще не истекло.") } + + func testNeedResetInapps_WithMinusTTL_NotExceeded() throws { + persistenceStorage.configDownloadDate = Calendar.current.date(byAdding: .day, value: 1, to: Date()) + let service = TTLValidationService(persistenceStorage: persistenceStorage) + let settings = Settings(operations: nil, ttl: .init(inapps: "-2.00:00:00")) + let config = ConfigResponse(settings: settings) + let result = service.needResetInapps(config: config) + XCTAssertFalse(result, "Inapps не должны быть сброшены, так как время TTL еще не истекло.") + } + + func testNeedResetInapps_WithMinusOneDayTTL_NotExceeded() throws { + persistenceStorage.configDownloadDate = Calendar.current.date(byAdding: .day, value: -2, to: Date()) + let service = TTLValidationService(persistenceStorage: persistenceStorage) + let settings = Settings(operations: nil, ttl: .init(inapps: "-1.00:00:00")) + let config = ConfigResponse(settings: settings) + let result = service.needResetInapps(config: config) + XCTAssertFalse(result, "Inapps не должны быть сброшены, так как время TTL еще не истекло.") + } }