Skip to content

Commit 907776c

Browse files
committed
fix unit tests
1 parent 653ac35 commit 907776c

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

tests/common/CommonMocks.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,16 +446,17 @@ class MockLocalStorage: LocalStorageProtocol {
446446
attributionInfoExpiration = expiration
447447
}
448448

449-
func getPayload(currentDate: Date) -> [AnyHashable : Any]? {
449+
func getLastPushPayload(_ currentDate: Date) -> [AnyHashable : Any]? {
450450
guard !MockLocalStorage.isExpired(expiration: payloadExpiration, currentDate: currentDate) else {
451451
return nil
452452
}
453+
453454
return payload
454455
}
455456

456-
func save(payload: [AnyHashable : Any]?, withExpiration: Date?) {
457+
func saveLastPushPayload(_ payload: [AnyHashable : Any]?, withExpiration expiration: Date?) {
457458
self.payload = payload
458-
payloadExpiration = withExpiration
459+
payloadExpiration = expiration
459460
}
460461

461462
private var payload: [AnyHashable: Any]? = nil

tests/unit-tests/LocalStorageTests.swift

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,21 @@ class LocalStorageTests: XCTestCase {
114114
],
115115
],
116116
]
117+
117118
let currentDate = Date()
118119
let expiration = Calendar.current.date(byAdding: Calendar.Component.hour, value: 24, to: currentDate)!
119-
localStorage.save(payload: payload, withExpiration: expiration)
120+
121+
localStorage.saveLastPushPayload(payload, withExpiration: expiration)
122+
120123
// 23 hours, not expired, still present
121124
mockDateProvider.currentDate = Calendar.current.date(byAdding: Calendar.Component.hour, value: 23, to: currentDate)!
122-
let fromLocalStorage: [AnyHashable: Any] = localStorage.getPayload(currentDate: mockDateProvider.currentDate)!
125+
let fromLocalStorage: [AnyHashable: Any] = localStorage.getLastPushPayload(mockDateProvider.currentDate)!
126+
123127
XCTAssertTrue(NSDictionary(dictionary: payload).isEqual(to: fromLocalStorage))
124128

125129
mockDateProvider.currentDate = Calendar.current.date(byAdding: Calendar.Component.hour, value: 25, to: currentDate)!
126-
let fromLocalStorage2: [AnyHashable: Any]? = localStorage.getPayload(currentDate: mockDateProvider.currentDate)
130+
let fromLocalStorage2: [AnyHashable: Any]? = localStorage.getLastPushPayload(mockDateProvider.currentDate)
131+
127132
XCTAssertNil(fromLocalStorage2)
128133
}
129134

@@ -150,13 +155,16 @@ class LocalStorageTests: XCTestCase {
150155
],
151156
"someClass": A(),
152157
]
158+
153159
let currentDate = Date()
154160
let expiration = Calendar.current.date(byAdding: Calendar.Component.hour, value: 24, to: currentDate)!
155-
localStorage.save(payload: payload, withExpiration: expiration)
161+
162+
localStorage.saveLastPushPayload(payload, withExpiration: expiration)
156163

157164
// 23 hours, not expired, still present
158165
mockDateProvider.currentDate = Calendar.current.date(byAdding: Calendar.Component.hour, value: 23, to: currentDate)!
159-
let fromLocalStorage = localStorage.getPayload(currentDate: mockDateProvider.currentDate)
166+
let fromLocalStorage = localStorage.getLastPushPayload(mockDateProvider.currentDate)
167+
160168
XCTAssertNil(fromLocalStorage)
161169
}
162170

0 commit comments

Comments
 (0)