Skip to content

Commit 99cf350

Browse files
authored
Merge pull request #6049 from woocommerce/issue/5953-mark-inbox-note-as-actioned
Mark Inbox Note as actioned from `POST wc-analytics/admin/notes/{{id}}/action/{{action_id}}` - Networking layer
2 parents a3dcd63 + bdda620 commit 99cf350

File tree

2 files changed

+83
-2
lines changed

2 files changed

+83
-2
lines changed

Networking/Networking/Remote/InboxNotesRemote.swift

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ public protocol InboxNotesRemoteProtocol {
1616
func dismissInboxNote(for siteID: Int64,
1717
noteID: Int64,
1818
completion: @escaping (Result<InboxNote, Error>) -> ())
19+
20+
func markInboxNoteAsActioned(for siteID: Int64,
21+
noteID: Int64,
22+
actionID: Int64,
23+
completion: @escaping (Result<InboxNote, Error>) -> ())
1924
}
2025

2126

@@ -75,7 +80,7 @@ public final class InboxNotesRemote: Remote, InboxNotesRemoteProtocol {
7580
/// This internally marks a notification’s is_deleted field to true and such notifications do not show in the results anymore.
7681
///
7782
/// - Parameters:
78-
/// - siteID: The site for which we'll fetch InboxNotes.
83+
/// - siteID: The site for which we'll dismiss the InboxNote.
7984
/// - noteID: The ID of the note that should be marked as dismissed.
8085
/// - completion: Closure to be executed upon completion.
8186
///
@@ -93,6 +98,33 @@ public final class InboxNotesRemote: Remote, InboxNotesRemoteProtocol {
9398

9499
enqueue(request, mapper: mapper, completion: completion)
95100
}
101+
102+
// MARK: - Set Inbox Note as `actioned`
103+
104+
/// Set an `InboxNote` as `actioned`.
105+
/// This internally marks a notification’s status as `actioned`.
106+
///
107+
/// - Parameters:
108+
/// - siteID: The site for which we'll mark the InboxNote as actioned.
109+
/// - noteID: The ID of the note.
110+
/// - actionID: The ID of the action.
111+
/// - completion: Closure to be executed upon completion.
112+
///
113+
public func markInboxNoteAsActioned(for siteID: Int64,
114+
noteID: Int64,
115+
actionID: Int64,
116+
completion: @escaping (Result<InboxNote, Error>) -> ()) {
117+
118+
let request = JetpackRequest(wooApiVersion: .wcAnalytics,
119+
method: .post,
120+
siteID: siteID,
121+
path: Path.notes + "/\(noteID)/action/\(actionID)",
122+
parameters: nil)
123+
124+
let mapper = InboxNoteMapper(siteID: siteID)
125+
126+
enqueue(request, mapper: mapper, completion: completion)
127+
}
96128
}
97129

98130
// MARK: - Constants
@@ -106,7 +138,6 @@ public extension InboxNotesRemote {
106138

107139
private enum Path {
108140
static let notes = "admin/notes"
109-
static let deleteNote = "admin/notes/delete"
110141
}
111142

112143
private enum ParameterKey {

Networking/NetworkingTests/Remote/InboxNotesRemoteTests.swift

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,54 @@ final class InboxNotesRemoteTests: XCTestCase {
147147
let resultError = try XCTUnwrap(result.failure as? NetworkError)
148148
XCTAssertEqual(resultError, .unacceptableStatusCode(statusCode: 500))
149149
}
150+
151+
// MARK: - Mark an Inbox Note as `actioned`
152+
153+
/// Verifies that markInboxNoteAsActioned properly parses the `InboxNote` sample response.
154+
///
155+
func test_markInboxNoteAsActioned_properly_returns_parsed_InboxNote() throws {
156+
// Given
157+
let remote = InboxNotesRemote(network: network)
158+
let sampleInboxNoteID: Int64 = 296
159+
let sampleActionID: Int64 = 13329
160+
161+
network.simulateResponse(requestUrlSuffix: "admin/notes/\(sampleInboxNoteID)/action/\(sampleActionID)", filename: "inbox-note")
162+
163+
// When
164+
let result = waitFor { promise in
165+
remote.markInboxNoteAsActioned(for: self.sampleSiteID, noteID: sampleInboxNoteID, actionID: sampleActionID) { result in
166+
promise(result)
167+
}
168+
}
169+
170+
// Then
171+
XCTAssert(result.isSuccess)
172+
let inboxNote = try XCTUnwrap(result.get())
173+
XCTAssertEqual(inboxNote.id, sampleInboxNoteID)
174+
XCTAssertEqual(inboxNote.actions.first?.id, sampleActionID)
175+
}
176+
177+
/// Verifies that markInboxNoteAsActioned properly relays Networking Layer errors.
178+
///
179+
func test_markInboxNoteAsActioned_properly_relays_networking_errors() throws {
180+
// Given
181+
let remote = InboxNotesRemote(network: network)
182+
let sampleInboxNoteID: Int64 = 296
183+
let sampleActionID: Int64 = 13329
184+
185+
let error = NetworkError.unacceptableStatusCode(statusCode: 500)
186+
network.simulateError(requestUrlSuffix: "admin/notes/\(sampleInboxNoteID)/action/\(sampleActionID)", error: error)
187+
188+
// When
189+
let result = waitFor { promise in
190+
remote.markInboxNoteAsActioned(for: self.sampleSiteID, noteID: sampleInboxNoteID, actionID: sampleActionID) { result in
191+
promise(result)
192+
}
193+
}
194+
195+
// Then
196+
XCTAssertTrue(result.isFailure)
197+
let resultError = try XCTUnwrap(result.failure as? NetworkError)
198+
XCTAssertEqual(resultError, .unacceptableStatusCode(statusCode: 500))
199+
}
150200
}

0 commit comments

Comments
 (0)