Skip to content

Commit 32ecdda

Browse files
authored
Merge pull request #8641 from woocommerce/feat/8639-inbox-note-migration
REST API: Migrate inbox note endpoints
2 parents 602cd36 + 809c371 commit 32ecdda

File tree

8 files changed

+160
-7
lines changed

8 files changed

+160
-7
lines changed

Networking/Networking.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@
704704
DE42F96B296BC23800D514C2 /* customer-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE42F96A296BC23800D514C2 /* customer-without-data.json */; };
705705
DE42F96D296BC67E00D514C2 /* wc-analytics-customers-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE42F96C296BC67E00D514C2 /* wc-analytics-customers-without-data.json */; };
706706
DE42F96F296BC9A700D514C2 /* countries-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE42F96E296BC9A700D514C2 /* countries-without-data.json */; };
707+
DE4F2A3F29750EF400B0701C /* inbox-note-list-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE4F2A3D29750EF400B0701C /* inbox-note-list-without-data.json */; };
708+
DE4F2A4029750EF400B0701C /* inbox-note-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE4F2A3E29750EF400B0701C /* inbox-note-without-data.json */; };
707709
DE4F2A4229751EAE00B0701C /* setting-coupon-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE4F2A4129751EAE00B0701C /* setting-coupon-without-data.json */; };
708710
DE50295928C5BD0200551736 /* JetpackUser.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE50295828C5BD0200551736 /* JetpackUser.swift */; };
709711
DE50295B28C5F99700551736 /* DotcomUser.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE50295A28C5F99700551736 /* DotcomUser.swift */; };
@@ -1529,6 +1531,8 @@
15291531
DE42F96A296BC23800D514C2 /* customer-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "customer-without-data.json"; sourceTree = "<group>"; };
15301532
DE42F96C296BC67E00D514C2 /* wc-analytics-customers-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "wc-analytics-customers-without-data.json"; sourceTree = "<group>"; };
15311533
DE42F96E296BC9A700D514C2 /* countries-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "countries-without-data.json"; sourceTree = "<group>"; };
1534+
DE4F2A3D29750EF400B0701C /* inbox-note-list-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "inbox-note-list-without-data.json"; sourceTree = "<group>"; };
1535+
DE4F2A3E29750EF400B0701C /* inbox-note-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "inbox-note-without-data.json"; sourceTree = "<group>"; };
15321536
DE4F2A4129751EAE00B0701C /* setting-coupon-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "setting-coupon-without-data.json"; sourceTree = "<group>"; };
15331537
DE50295828C5BD0200551736 /* JetpackUser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JetpackUser.swift; sourceTree = "<group>"; };
15341538
DE50295A28C5F99700551736 /* DotcomUser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DotcomUser.swift; sourceTree = "<group>"; };
@@ -2155,6 +2159,8 @@
21552159
B559EBA820A0B5B100836CD4 /* Responses */ = {
21562160
isa = PBXGroup;
21572161
children = (
2162+
DE4F2A3D29750EF400B0701C /* inbox-note-list-without-data.json */,
2163+
DE4F2A3E29750EF400B0701C /* inbox-note-without-data.json */,
21582164
DE4F2A4129751EAE00B0701C /* setting-coupon-without-data.json */,
21592165
DEEDA4432975003800F845AB /* settings-general-without-data.json */,
21602166
DEA6B1C8296D0E8A005AA5E9 /* systemStatus-without-data.json */,
@@ -2954,6 +2960,7 @@
29542960
09885C8027C3FFD200910A62 /* product-variations-bulk-update.json in Resources */,
29552961
31054734262E36AB00C5C02B /* wcpay-payment-intent-error.json in Resources */,
29562962
02AF07EE27493AE700B2D81E /* media-upload-to-wordpress-site.json in Resources */,
2963+
DE4F2A4029750EF400B0701C /* inbox-note-without-data.json in Resources */,
29572964
45ED4F12239E8C57004F1BE3 /* taxes-classes.json in Resources */,
29582965
B5A2417B217F98FC00595DEF /* broken-notifications.json in Resources */,
29592966
3158A4A32729F42500C3CFA8 /* wcpay-account-dev-test.json in Resources */,
@@ -3172,6 +3179,7 @@
31723179
02698CFA24C188E9005337C4 /* product-variations-load-all-alternative-types.json in Resources */,
31733180
02616F902921336C0095BC00 /* site-creation-success.json in Resources */,
31743181
CC0786632678F79500BA9AC1 /* shipping-label-purchase-success.json in Resources */,
3182+
DE4F2A3F29750EF400B0701C /* inbox-note-list-without-data.json in Resources */,
31753183
7497376A2141F2BE0008C490 /* top-performers-week-alt.json in Resources */,
31763184
DEEDA4442975003800F845AB /* settings-general-without-data.json in Resources */,
31773185
D865CE61278CA1AE002C8520 /* stripe-payment-intent-processing.json in Resources */,

Networking/Networking/Mapper/InboxNoteListMapper.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ struct InboxNoteListMapper: Mapper {
1717
decoder.userInfo = [
1818
.siteID: siteID
1919
]
20-
return try decoder.decode(InboxNoteListEnvelope.self, from: response).data
20+
do {
21+
return try decoder.decode(InboxNoteListEnvelope.self, from: response).data
22+
} catch {
23+
return try decoder.decode([InboxNote].self, from: response)
24+
}
2125
}
2226
}
2327

Networking/Networking/Mapper/InboxNoteMapper.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ struct InboxNoteMapper: Mapper {
1717
decoder.userInfo = [
1818
.siteID: siteID
1919
]
20-
return try decoder.decode(InboxNoteEnvelope.self, from: response).data
20+
do {
21+
return try decoder.decode(InboxNoteEnvelope.self, from: response).data
22+
} catch {
23+
return try decoder.decode(InboxNote.self, from: response)
24+
}
2125
}
2226
}
2327

Networking/Networking/Remote/InboxNotesRemote.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ public final class InboxNotesRemote: Remote, InboxNotesRemoteProtocol {
7676
method: .get,
7777
siteID: siteID,
7878
path: Path.notes,
79-
parameters: parameters)
79+
parameters: parameters,
80+
availableAsRESTRequest: true)
8081

8182
let mapper = InboxNoteListMapper(siteID: siteID)
8283

@@ -100,7 +101,8 @@ public final class InboxNotesRemote: Remote, InboxNotesRemoteProtocol {
100101
method: .delete,
101102
siteID: siteID,
102103
path: Path.notes + "/delete/\(noteID)",
103-
parameters: [ParameterKey.fields: ParameterValue.noteFields])
104+
parameters: [ParameterKey.fields: ParameterValue.noteFields],
105+
availableAsRESTRequest: true)
104106

105107
let mapper = InboxNoteMapper(siteID: siteID)
106108

@@ -148,7 +150,8 @@ public final class InboxNotesRemote: Remote, InboxNotesRemoteProtocol {
148150
method: .delete,
149151
siteID: siteID,
150152
path: Path.notes + "/delete/all",
151-
parameters: parameters)
153+
parameters: parameters,
154+
availableAsRESTRequest: true)
152155

153156
let mapper = InboxNoteListMapper(siteID: siteID)
154157

@@ -175,7 +178,8 @@ public final class InboxNotesRemote: Remote, InboxNotesRemoteProtocol {
175178
method: .post,
176179
siteID: siteID,
177180
path: Path.notes + "/\(noteID)/action/\(actionID)",
178-
parameters: [ParameterKey.fields: ParameterValue.noteFields])
181+
parameters: [ParameterKey.fields: ParameterValue.noteFields],
182+
availableAsRESTRequest: true)
179183

180184
let mapper = InboxNoteMapper(siteID: siteID)
181185

Networking/NetworkingTests/Mapper/InboxNoteListMapperTests.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ final class InboxNoteListMapperTests: XCTestCase {
1414
XCTAssertEqual(inboxNotes.count, 24)
1515
}
1616

17+
/// Verifies that the whole list is parsed when response has no data envelope.
18+
///
19+
func test_InboxNoteListMapper_parses_all_InboxNotes_in_response_without_data_envelope() throws {
20+
let inboxNotes = try mapLoadInboxNoteListResponseWithoutDataEnvelope()
21+
XCTAssertEqual(inboxNotes.count, 2)
22+
}
23+
1724
/// Verifies that the `siteID` is added in the mapper, to all results, because it's not provided by the API endpoint.
1825
///
1926
func test_InboxNoteListMapper_includes_siteID_in_parsed_results() throws {
@@ -77,4 +84,10 @@ private extension InboxNoteListMapperTests {
7784
func mapLoadInboxNoteListResponse() throws -> [InboxNote] {
7885
return try mapInboxNoteList(from: "inbox-note-list")
7986
}
87+
88+
/// Returns the InboxNoteListMapper output from `inbox-note-list-without-data.json`
89+
///
90+
func mapLoadInboxNoteListResponseWithoutDataEnvelope() throws -> [InboxNote] {
91+
return try mapInboxNoteList(from: "inbox-note-list-without-data")
92+
}
8093
}

Networking/NetworkingTests/Mapper/InboxNoteMapperTests.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,20 @@ final class InboxNoteMapperTests: XCTestCase {
77
///
88
private let dummySiteID: Int64 = 12983476
99

10-
/// Verifies that the whole list is parsed.
10+
/// Verifies that the inbox note is parsed.
1111
///
1212
func test_InboxNoteMapper_parses_the_InboxNote_in_response() throws {
1313
let inboxNote = try mapLoadInboxNoteResponse()
1414
XCTAssertNotNil(inboxNote)
1515
}
1616

17+
/// Verifies that the inbox note is parsed when response has no data envelope.
18+
///
19+
func test_InboxNoteMapper_parses_the_InboxNote_in_response_without_data_envelope() throws {
20+
let inboxNote = try mapLoadInboxNoteResponseWithoutDataEnvelope()
21+
XCTAssertNotNil(inboxNote)
22+
}
23+
1724
/// Verifies that the `siteID` is added in the mapper, because it's not provided by the API endpoint.
1825
///
1926
func test_InboxNoteMapper_includes_siteID_in_parsed_result() throws {
@@ -83,6 +90,12 @@ private extension InboxNoteMapperTests {
8390
return try mapInboxNote(from: "inbox-note")
8491
}
8592

93+
/// Returns the InboxNoteMapper output from `inbox-note-without-data.json`
94+
///
95+
func mapLoadInboxNoteResponseWithoutDataEnvelope() throws -> InboxNote? {
96+
return try mapInboxNote(from: "inbox-note-without-data")
97+
}
98+
8699
/// Returns the InboxNoteMapper output from `inbox-note-without-isRead.json`
87100
///
88101
func mapLoadInboxNoteWithoutIsReadResponse() throws -> InboxNote? {
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
[
2+
{
3+
"id": 291,
4+
"name": "wc-admin-launch-checklist",
5+
"type": "info",
6+
"locale": "en_US",
7+
"title": "Ready to launch your store?",
8+
"content": "To make sure you never get that sinking \"what did I forget\" feeling, we've put together the essential pre-launch checklist.",
9+
"status": "unactioned",
10+
"date_created": "2022-01-26T09:02:08",
11+
"actions": [{
12+
"id": 13225,
13+
"name": "learn-more",
14+
"label": "Learn more",
15+
"query": "https:\/\/woocommerce.com\/posts\/pre-launch-checklist-the-essentials\/?utm_source=inbox&utm_medium=product",
16+
"status": "actioned",
17+
"primary": false,
18+
"actioned_text": "",
19+
"nonce_action": null,
20+
"nonce_name": null,
21+
"url": "https:\/\/woocommerce.com\/posts\/pre-launch-checklist-the-essentials\/?utm_source=inbox&utm_medium=product"
22+
}],
23+
"layout": "plain",
24+
"image": "",
25+
"is_deleted": false,
26+
"is_read": false,
27+
"date_created_gmt": "2022-01-26T14:32:08"
28+
}, {
29+
"id": 97,
30+
"name": "wc-admin-optimizing-the-checkout-flow",
31+
"type": "info",
32+
"locale": "en_US",
33+
"title": "Optimizing the checkout flow",
34+
"content": "It's crucial to get your store's checkout as smooth as possible to avoid losing sales. Let's take a look at how you can optimize the checkout experience for your shoppers.",
35+
"status": "unactioned",
36+
"date_created": "2022-01-26T09:02:08",
37+
"actions": [{
38+
"id": 13271,
39+
"name": "optimizing-the-checkout-flow",
40+
"label": "Learn more",
41+
"query": "https:\/\/woocommerce.com\/posts\/optimizing-woocommerce-checkout?utm_source=inbox",
42+
"status": "actioned",
43+
"primary": true,
44+
"actioned_text": "",
45+
"nonce_action": null,
46+
"nonce_name": null,
47+
"url": "https:\/\/woocommerce.com\/posts\/optimizing-woocommerce-checkout?utm_source=inbox"
48+
}],
49+
"layout": "plain",
50+
"image": "",
51+
"is_deleted": false,
52+
"is_read": false,
53+
"date_created_gmt": "2022-01-26T14:32:08"
54+
}
55+
]
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"id": 296,
3+
"name": "wc-admin-wc-helper-subscription",
4+
"type": "warning",
5+
"locale": "en_US",
6+
"title": "WooCommerce Bookings subscription expired",
7+
"content": "Your subscription expired on October 22nd. Get a new subscription to continue receiving updates and access to support.",
8+
"content_data": {
9+
"product_id": 390890,
10+
"product_name": "WooCommerce Bookings",
11+
"expired": true,
12+
"expires": 1634860800,
13+
"expires_date": "October 22nd"
14+
},
15+
"status": "unactioned",
16+
"source": "woocommerce-admin",
17+
"date_created": "2022-01-31T08:55:32",
18+
"date_reminder": null,
19+
"is_snoozable": false,
20+
"actions": [
21+
{
22+
"id": 13329,
23+
"name": "renew-subscription",
24+
"label": "Renew Subscription",
25+
"query": "https://woocommerce.com/products/woocommerce-bookings/",
26+
"status": "actioned",
27+
"primary": false,
28+
"actioned_text": "",
29+
"nonce_action": null,
30+
"nonce_name": null,
31+
"url": "https://woocommerce.com/products/woocommerce-bookings/"
32+
}
33+
],
34+
"layout": "plain",
35+
"image": "",
36+
"is_deleted": true,
37+
"is_read": false,
38+
"date_created_gmt": "2022-01-31T14:25:32",
39+
"date_reminder_gmt": null,
40+
"_links": {
41+
"self": [
42+
{
43+
"href": "https://mywootesting.mystagingwebsite.com/wp-json/wc-analytics/admin/notes/296"
44+
}
45+
],
46+
"collection": [
47+
{
48+
"href": "https://mywootesting.mystagingwebsite.com/wp-json/wc-analytics/admin/notes"
49+
}
50+
]
51+
}
52+
}

0 commit comments

Comments
 (0)