Skip to content

Commit

Permalink
MBX-3338: Fix minus ttl
Browse files Browse the repository at this point in the history
  • Loading branch information
enotniy committed Jun 5, 2024
1 parent 1f4f762 commit ffb0eb6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion Mindbox/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>5609</string>
<string>5612</string>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -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 еще не истекло.")
}
}

0 comments on commit ffb0eb6

Please sign in to comment.