Skip to content

Commit 59ef472

Browse files
committed
tests for set value
1 parent 6962c17 commit 59ef472

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

Modules/Sources/Yosemite/Stores/AppSettingsStore.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1300,7 +1300,12 @@ private extension AppSettingsStore {
13001300
//
13011301
private extension AppSettingsStore {
13021302
func setPOSSurveyNotificationScheduled(onCompletion: (Result<Void, Error>) -> Void) {
1303-
// TODO
1303+
do {
1304+
try generalAppSettings.setValue(true, for: \.isPOSSurveyNotificationScheduled)
1305+
onCompletion(.success(()))
1306+
} catch {
1307+
onCompletion(.failure(error))
1308+
}
13041309
}
13051310

13061311
func getPOSSurveyNotificationScheduled(onCompletion: (Bool) -> Void) {

Modules/Tests/YosemiteTests/Stores/AppSettingsStoreTests.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,6 +1525,41 @@ extension AppSettingsStoreTests {
15251525
XCTAssertFalse(result)
15261526
}
15271527

1528+
func test_getPOSSurveyNotificationScheduled_returns_true_after_setting_as_scheduled() throws {
1529+
// Given
1530+
try fileStorage?.deleteFile(at: expectedGeneralAppSettingsFileURL)
1531+
let setAction = AppSettingsAction.setPOSSurveyNotificationScheduled { _ in }
1532+
subject?.onAction(setAction)
1533+
1534+
// When
1535+
let result: Bool = waitFor { promise in
1536+
let action = AppSettingsAction.getPOSSurveyNotificationScheduled { isScheduled in
1537+
promise(isScheduled)
1538+
}
1539+
self.subject?.onAction(action)
1540+
}
1541+
1542+
// Then
1543+
XCTAssertTrue(result)
1544+
}
1545+
1546+
func test_setPOSSurveyNotificationScheduled_stores_value_correctly() throws {
1547+
// Given
1548+
try fileStorage?.deleteFile(at: expectedGeneralAppSettingsFileURL)
1549+
1550+
// When
1551+
var result: Result<Void, Error>?
1552+
let action = AppSettingsAction.setPOSSurveyNotificationScheduled { aResult in
1553+
result = aResult
1554+
}
1555+
subject?.onAction(action)
1556+
1557+
// Then
1558+
XCTAssertTrue(try XCTUnwrap(result).isSuccess)
1559+
1560+
let savedSettings: GeneralAppSettings = try XCTUnwrap(fileStorage?.data(for: expectedGeneralAppSettingsFileURL))
1561+
XCTAssertTrue(savedSettings.isPOSSurveyNotificationScheduled)
1562+
}
15281563
}
15291564

15301565
// MARK: - Utils

0 commit comments

Comments
 (0)