Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Networking/Networking.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,7 @@
DE66C5632977CBC700DAA978 /* shipping-label-eligibility-failure-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE66C5622977CBC700DAA978 /* shipping-label-eligibility-failure-without-data.json */; };
DE66C5652977CC4300DAA978 /* shipping-label-purchase-success-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE66C5642977CC4300DAA978 /* shipping-label-purchase-success-without-data.json */; };
DE66C5672977CEB800DAA978 /* shipping-label-status-success-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE66C5662977CEB800DAA978 /* shipping-label-status-success-without-data.json */; };
DE66C5692977D62700DAA978 /* plugins-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE66C5682977D62700DAA978 /* plugins-without-data.json */; };
DE6F308727966FEF004E1C9A /* CouponReportListMapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE6F308627966FEF004E1C9A /* CouponReportListMapperTests.swift */; };
DE74F29A27E08F5A0002FE59 /* SiteSettingMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE74F29927E08F5A0002FE59 /* SiteSettingMapper.swift */; };
DE74F29C27E0A1D00002FE59 /* setting-coupon.json in Resources */ = {isa = PBXBuildFile; fileRef = DE74F29B27E0A1D00002FE59 /* setting-coupon.json */; };
Expand Down Expand Up @@ -1569,6 +1570,7 @@
DE66C5622977CBC700DAA978 /* shipping-label-eligibility-failure-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "shipping-label-eligibility-failure-without-data.json"; sourceTree = "<group>"; };
DE66C5642977CC4300DAA978 /* shipping-label-purchase-success-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "shipping-label-purchase-success-without-data.json"; sourceTree = "<group>"; };
DE66C5662977CEB800DAA978 /* shipping-label-status-success-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "shipping-label-status-success-without-data.json"; sourceTree = "<group>"; };
DE66C5682977D62700DAA978 /* plugins-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "plugins-without-data.json"; sourceTree = "<group>"; };
DE6F308627966FEF004E1C9A /* CouponReportListMapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CouponReportListMapperTests.swift; sourceTree = "<group>"; };
DE74F29927E08F5A0002FE59 /* SiteSettingMapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SiteSettingMapper.swift; sourceTree = "<group>"; };
DE74F29B27E0A1D00002FE59 /* setting-coupon.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "setting-coupon.json"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2188,6 +2190,7 @@
B559EBA820A0B5B100836CD4 /* Responses */ = {
isa = PBXGroup;
children = (
DE66C5682977D62700DAA978 /* plugins-without-data.json */,
DE66C5662977CEB800DAA978 /* shipping-label-status-success-without-data.json */,
DE66C5642977CC4300DAA978 /* shipping-label-purchase-success-without-data.json */,
DE66C5622977CBC700DAA978 /* shipping-label-eligibility-failure-without-data.json */,
Expand Down Expand Up @@ -3171,6 +3174,7 @@
03E8FEC427B40E3F00F5FC7D /* wcpay-charge-card-present-minimal.json in Resources */,
EE6FDCFC2966A70400E1CECF /* product-without-data.json in Resources */,
31054724262E2FC600C5C02B /* wcpay-payment-intent-requires-capture.json in Resources */,
DE66C5692977D62700DAA978 /* plugins-without-data.json in Resources */,
7492FAE3217FBDBC00ED2C69 /* settings-general-alt.json in Resources */,
93D8BBFF226BC1DA00AD2EB3 /* me-settings.json in Resources */,
74C947842193A6C70024CB60 /* comment-moderate-approved.json in Resources */,
Expand Down
6 changes: 5 additions & 1 deletion Networking/Networking/Mapper/SitePluginsMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ struct SitePluginsMapper: Mapper {
.siteID: siteID
]

return try decoder.decode(SitePluginsEnvelope.self, from: response).plugins
do {
return try decoder.decode(SitePluginsEnvelope.self, from: response).plugins
} catch {
return try decoder.decode([SitePlugin].self, from: response)
}
}
}

Expand Down
7 changes: 6 additions & 1 deletion Networking/Networking/Remote/SitePluginsRemote.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ public class SitePluginsRemote: Remote {
public func loadPlugins(for siteID: Int64,
completion: @escaping (Result<[SitePlugin], Error>) -> Void) {
let path = Constants.sitePluginsPath
let request = JetpackRequest(wooApiVersion: .none, method: .get, siteID: siteID, path: path, parameters: nil)
let request = JetpackRequest(wooApiVersion: .none,
method: .get,
siteID: siteID,
path: path,
parameters: nil,
availableAsRESTRequest: true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR description mentioned that other endpoints aren't converted because we're not supporting Jetpack installation for REST login. I remember we implemented WooCommerce plugin installation, does that use a different endpoint? Do we plan to support Jetpack installation in the future, with a similar upsell to JCP sites?

Copy link
Contributor Author

@itsmeichigo itsmeichigo Jan 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We implemented Woo installation in a web view only - we want to handle that natively but haven't gotten around to doing that yet. Similarly, we want to support Jetpack installation after the first iteration of the REST API project is shipped, so we'll migrate the rest of the endpoints then.

let mapper = SitePluginsMapper(siteID: siteID)

enqueue(request, mapper: mapper, completion: completion)
Expand Down
25 changes: 25 additions & 0 deletions Networking/NetworkingTests/Mapper/SitePluginsMapperTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,25 @@ class SitePluginsMapperTests: XCTestCase {
XCTAssertEqual(wooCommerceSubscriptionsPlugin.version, "3.0.13")
XCTAssertEqual(wooCommerceSubscriptionsPlugin.textDomain, "woocommerce-subscriptions")
}

/// Verifies the SitePlugin fields are parsed correctly.
///
func test_SitePlugin_fields_are_properly_parsed_when_response_has_no_data_envelope() {
let plugins = mapLoadSitePluginsResponseWithoutDataEnvelope()
XCTAssertEqual(plugins.count, 3)

let helloDollyPlugin = plugins[0]
XCTAssertNotNil(helloDollyPlugin)
XCTAssertEqual(helloDollyPlugin.siteID, dummySiteID)
XCTAssertEqual(helloDollyPlugin.status, .inactive)
XCTAssertEqual(helloDollyPlugin.name, "Hello Dolly")
XCTAssertEqual(helloDollyPlugin.pluginUri, "http://wordpress.org/plugins/hello-dolly/")
XCTAssertEqual(helloDollyPlugin.authorUri, "http://ma.tt/")
XCTAssertEqual(helloDollyPlugin.descriptionRaw, "This is not just a plugin, it...")
XCTAssertEqual(helloDollyPlugin.descriptionRendered, "This is not just a plugin, it symbolizes...")
XCTAssertEqual(helloDollyPlugin.version, "1.7.2")
XCTAssertEqual(helloDollyPlugin.textDomain, "")
}
}


Expand All @@ -61,4 +80,10 @@ private extension SitePluginsMapperTests {
func mapLoadSitePluginsResponse() -> [SitePlugin] {
return mapPlugins(from: "plugins")
}

/// Returns the SitePluginsMapper output upon receiving `plugins-without-data`
///
func mapLoadSitePluginsResponseWithoutDataEnvelope() -> [SitePlugin] {
return mapPlugins(from: "plugins-without-data")
}
}
74 changes: 74 additions & 0 deletions Networking/NetworkingTests/Responses/plugins-without-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
[
{
"plugin": "hello",
"status": "inactive",
"name": "Hello Dolly",
"plugin_uri": "http://wordpress.org/plugins/hello-dolly/",
"author": "Matt Mullenweg",
"author_uri": "http://ma.tt/",
"description": {
"raw": "This is not just a plugin, it...",
"rendered": "This is not just a plugin, it symbolizes..."
},
"version": "1.7.2",
"network_only": false,
"requires_wp": "",
"requires_php": "",
"textdomain": "",
"_links": {
"self": [
{
"href": "https://example.com/wp-json/wp/v2/plugins/hello"
}
]
}
},
{
"plugin": "jetpack/jetpack",
"status": "active",
"name": "Jetpack by WordPress.com",
"plugin_uri": "https://jetpack.com",
"author": "Automattic",
"author_uri": "https://jetpack.com",
"description": {
"raw": "Bring the power of the WordPress.com cloud to your self-hosted WordPress. Jetpack enables you to connect your blog to a WordPress.com account to use the powerful features normally only available to WordPress.com users.",
"rendered": "Bring the power of the WordPress.com cloud to your self-hosted WordPress. Jetpack enables you to connect your blog to a WordPress.com account to use the powerful features normally only available to WordPress.com users. <cite>By <a href=\"https://jetpack.com\">Automattic</a>.</cite>"
},
"version": "9.5",
"network_only": false,
"requires_wp": "5.6",
"requires_php": "5.6",
"textdomain": "jetpack",
"_links": {
"self": [
{
"href": "https://example.com/wp-json/wp/v2/plugins/jetpack/jetpack"
}
]
}
},
{
"plugin": "woocommerce/woocommerce",
"status": "active",
"name": "WooCommerce",
"plugin_uri": "https://woocommerce.com/",
"author": "Automattic",
"author_uri": "https://woocommerce.com",
"description": {
"raw": "An eCommerce toolkit that helps you sell anything. Beautifully.",
"rendered": "An eCommerce toolkit that helps you sell anything. Beautifully. <cite>By <a href=\"https://woocommerce.com\">Automattic</a>.</cite>"
},
"version": "5.1.0",
"network_only": false,
"requires_wp": "5.4",
"requires_php": "7.0",
"textdomain": "woocommerce",
"_links": {
"self": [
{
"href": "https://example.com//wp-json/wp/v2/plugins/woocommerce/woocommerce"
}
]
}
}
]