Skip to content

Commit

Permalink
Integrate remote endpoint to update notification settings
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmeichigo committed Dec 19, 2024
1 parent 6bbe559 commit cf8f29e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Networking/Networking/Remote/AccountRemote.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public protocol AccountRemoteProtocol {
func loadSitePlan(for siteID: Int64, completion: @escaping (Result<SitePlan, Error>) -> Void)
func loadUsernameSuggestions(from text: String) async throws -> [String]

func updateNotificationSettings(with settings: NotificationSettings) async throws

/// Creates a WPCOM account with the given email and password.
/// - Parameters:
/// - email: user input email.
Expand Down Expand Up @@ -144,6 +146,13 @@ public class AccountRemote: Remote, AccountRemoteProtocol {
return suggestions
}

public func updateNotificationSettings(with settings: NotificationSettings) async throws {
let path = Path.notificationSettings
let parameters = try settings.toDictionary()
let request = DotcomRequest(wordpressApiVersion: .mark1_1, method: .post, path: path, parameters: parameters)
return try await enqueue(request)
}

public func createAccount(email: String,
username: String,
password: String,
Expand Down Expand Up @@ -201,6 +210,7 @@ private extension AccountRemote {
static let usernameSuggestions = "users/username/suggestions"
static let accountCreation = "users/new"
static let closeAccount = "me/account/close"
static let notificationSettings = "me/notifications/settings"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ final class MockAccountRemote {
/// The results to return based on the given site ID in `loadUsernameSuggestions`.
private var loadUsernameSuggestionsResult: Result<[String], Error>?

/// Returns the value when `updateNotificationSettings` is called.
private var updateNotificationSettingsResult: Result<Void, Error> = .success(())

/// The results to return based on the given site ID in `createAccount`.
private var createAccountResult: Result<CreateAccountResult, CreateAccountError>?

Expand Down Expand Up @@ -115,6 +118,15 @@ extension MockAccountRemote: AccountRemoteProtocol {
return try result.get()
}

func updateNotificationSettings(with settings: NotificationSettings) async throws {
switch updateNotificationSettingsResult {
case .success:
break
case .failure(let error):
throw error
}
}

func createAccount(email: String,
username: String,
password: String,
Expand Down

0 comments on commit cf8f29e

Please sign in to comment.