Skip to content

Commit

Permalink
Add tests for AccountAction.updateNotificationSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmeichigo committed Dec 20, 2024
1 parent 9d38e56 commit 018501e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ final class MockAccountRemote {
func whenCreatingAccount(thenReturn result: Result<CreateAccountResult, CreateAccountError>) {
createAccountResult = result
}

/// Returns the value when `updateNotificationSettings` is called.
func whenUpdatingNotificationSettings(thenReturn result: Result<Void, Error>) {
updateNotificationSettingsResult = result
}
}

extension MockAccountRemote {
Expand Down
50 changes: 50 additions & 0 deletions Yosemite/YosemiteTests/Stores/AccountStoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,56 @@ final class AccountStoreTests: XCTestCase {
XCTAssertTrue(result.isFailure)
XCTAssertEqual(result.failure as NSError?, error)
}

// MARK: - updateNotificationSettings

func test_updateNotificationSettings_returns_success_upon_success() {
// Given
let network = MockNetwork()
let accountRemote = MockAccountRemote()
accountRemote.whenUpdatingNotificationSettings(thenReturn: .success(()))
let accountStore = AccountStore(dispatcher: dispatcher,
storageManager: storageManager,
network: network,
remote: accountRemote)

// When
let result: Result<Void, Error> = waitFor { promise in
let notificationSettings = NotificationSettings.createSettings(deviceID: 132, enabledSites: [23], disabledSites: [44, 66])
let action = AccountAction.updateNotificationSettings(notificationSettings: notificationSettings) { result in
promise(result)
}
accountStore.onAction(action)
}

// Then
XCTAssertTrue(result.isSuccess)
}

func test_updateNotificationSettings_relays_error_upon_failure() {
// Given
let network = MockNetwork()
let accountRemote = MockAccountRemote()
let error = NSError(domain: "notifications", code: 33)
accountRemote.whenUpdatingNotificationSettings(thenReturn: .failure(error))
let accountStore = AccountStore(dispatcher: dispatcher,
storageManager: storageManager,
network: network,
remote: accountRemote)

// When
let result: Result<Void, Error> = waitFor { promise in
let notificationSettings = NotificationSettings.createSettings(deviceID: 132, enabledSites: [23], disabledSites: [44, 66])
let action = AccountAction.updateNotificationSettings(notificationSettings: notificationSettings) { result in
promise(result)
}
accountStore.onAction(action)
}

// Then
XCTAssertTrue(result.isFailure)
XCTAssertEqual(result.failure as NSError?, error)
}
}

// MARK: - Private Methods
Expand Down

0 comments on commit 018501e

Please sign in to comment.