Skip to content

Commit

Permalink
Update static helper method to initializer
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmeichigo committed Dec 20, 2024
1 parent 0634127 commit 406d66f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
7 changes: 5 additions & 2 deletions Networking/Networking/Model/NotificationSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public struct NotificationSettings: Equatable, Encodable {

/// Helper method to create notification settings for a given device ID.
///
public static func createSettings(deviceID: Int64, enabledSites: [Int64], disabledSites: [Int64]) -> NotificationSettings {
public init(deviceID: Int64, enabledSites: [Int64], disabledSites: [Int64]) {
let enabledSiteSettings = enabledSites.map { siteID in
Blog(blogID: siteID, devices: [
Device(deviceID: deviceID,
Expand All @@ -26,9 +26,12 @@ public struct NotificationSettings: Equatable, Encodable {
])
}

return NotificationSettings(blogs: enabledSiteSettings + disabledSiteSettings)
self.init(blogs: (enabledSiteSettings + disabledSiteSettings))
}

public init(blogs: [Blog]) {
self.blogs = blogs
}
}

public extension NotificationSettings {
Expand Down
6 changes: 3 additions & 3 deletions Networking/NetworkingTests/Remote/AccountRemoteTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ final class AccountRemoteTests: XCTestCase {
network.simulateResponse(requestUrlSuffix: "me/notifications/settings", filename: "notification-settings")

// When
let notificationSettings = NotificationSettings.createSettings(deviceID: 58089781, enabledSites: [], disabledSites: [194373765])
let notificationSettings = NotificationSettings(deviceID: 58089781, enabledSites: [], disabledSites: [194373765])
_ = try await remote.updateNotificationSettings(with: notificationSettings)

// Then
Expand All @@ -305,7 +305,7 @@ final class AccountRemoteTests: XCTestCase {
// When
var errorCaught: Error?
do {
let notificationSettings = NotificationSettings.createSettings(deviceID: 58089781, enabledSites: [194373765], disabledSites: [])
let notificationSettings = NotificationSettings(deviceID: 58089781, enabledSites: [194373765], disabledSites: [])
try await remote.updateNotificationSettings(with: notificationSettings)
} catch {
errorCaught = error
Expand All @@ -324,7 +324,7 @@ final class AccountRemoteTests: XCTestCase {
// When
var errorCaught: Error?
do {
let notificationSettings = NotificationSettings.createSettings(deviceID: 58089781, enabledSites: [194373765], disabledSites: [])
let notificationSettings = NotificationSettings(deviceID: 58089781, enabledSites: [194373765], disabledSites: [])
try await remote.updateNotificationSettings(with: notificationSettings)
} catch {
errorCaught = error
Expand Down
4 changes: 2 additions & 2 deletions Yosemite/YosemiteTests/Stores/AccountStoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ final class AccountStoreTests: XCTestCase {

// When
let result: Result<Void, Error> = waitFor { promise in
let notificationSettings = NotificationSettings.createSettings(deviceID: 132, enabledSites: [23], disabledSites: [44, 66])
let notificationSettings = NotificationSettings(deviceID: 132, enabledSites: [23], disabledSites: [44, 66])
let action = AccountAction.updateNotificationSettings(notificationSettings: notificationSettings) { result in
promise(result)
}
Expand All @@ -923,7 +923,7 @@ final class AccountStoreTests: XCTestCase {

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

0 comments on commit 406d66f

Please sign in to comment.