Skip to content

Commit 92614cf

Browse files
committed
attempt to integrate keychain into tests
1 parent 907776c commit 92614cf

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

tests/common/CommonMocks.swift

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -466,18 +466,11 @@ class MockLocalStorage: LocalStorageProtocol {
466466
private var attributionInfoExpiration: Date? = nil
467467

468468
private static func isExpired(expiration: Date?, currentDate: Date) -> Bool {
469-
if let expiration = expiration {
470-
if expiration.timeIntervalSinceReferenceDate > currentDate.timeIntervalSinceReferenceDate {
471-
// expiration is later
472-
return false
473-
} else {
474-
// expired
475-
return true
476-
}
477-
} else {
478-
// no expiration
469+
guard let expiration = expiration else {
479470
return false
480471
}
472+
473+
return !(expiration.timeIntervalSinceReferenceDate > currentDate.timeIntervalSinceReferenceDate)
481474
}
482475
}
483476

tests/unit-tests/LocalStorageTests.swift

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,32 @@ import XCTest
99
class LocalStorageTests: XCTestCase {
1010
override func setUp() {
1111
super.setUp()
12+
1213
LocalStorageTests.clearTestUserDefaults()
14+
LocalStorageTests.clearTestKeychain()
1315
}
1416

15-
static let userDefaultsSuiteName = "localstorage.tests"
17+
static let localStorageTestSuiteName = "localstorage.tests"
1618

1719
private static func getTestUserDefaults() -> UserDefaults {
18-
UserDefaults(suiteName: userDefaultsSuiteName)!
20+
UserDefaults(suiteName: localStorageTestSuiteName)!
1921
}
2022

2123
private static func clearTestUserDefaults() {
22-
getTestUserDefaults().removePersistentDomain(forName: userDefaultsSuiteName)
24+
getTestUserDefaults().removePersistentDomain(forName: localStorageTestSuiteName)
25+
}
26+
27+
private static func getTestKeychain() -> IterableKeychain {
28+
IterableKeychain(wrapper: KeychainWrapper(serviceName: localStorageTestSuiteName))
29+
}
30+
31+
private static func clearTestKeychain() {
32+
let testKeychain = getTestKeychain()
33+
34+
testKeychain.email = nil
35+
testKeychain.userId = nil
36+
testKeychain.authToken = nil
37+
testKeychain.setLastPushPayload(nil, withExpiration: nil)
2338
}
2439

2540
func testUserIdAndEmail() throws {
@@ -96,7 +111,8 @@ class LocalStorageTests: XCTestCase {
96111

97112
func testPayload() throws {
98113
let mockDateProvider = MockDateProvider()
99-
let localStorage = LocalStorage(userDefaults: LocalStorageTests.getTestUserDefaults())
114+
let localStorage = LocalStorage(userDefaults: LocalStorageTests.getTestUserDefaults(), keychain: LocalStorageTests.getTestKeychain())
115+
100116
let payload: [AnyHashable: Any] = [
101117
"email": "[email protected]",
102118
"device": [

0 commit comments

Comments
 (0)