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
8 changes: 8 additions & 0 deletions Networking/Networking.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,8 @@
DE9DEEF5291CF1B40070AD7C /* site-plugin-without-envelope.json in Resources */ = {isa = PBXBuildFile; fileRef = DE9DEEF4291CF1B40070AD7C /* site-plugin-without-envelope.json */; };
DEA6B1C4296C0F45005AA5E9 /* payment-gateway-cod-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DEA6B1C3296C0F45005AA5E9 /* payment-gateway-cod-without-data.json */; };
DEA6B1C6296C13FB005AA5E9 /* payment-gateway-list-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DEA6B1C5296C13FB005AA5E9 /* payment-gateway-list-without-data.json */; };
DEA6B1C9296D0E8B005AA5E9 /* systemStatusWithPluginsOnly-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DEA6B1C7296D0E8A005AA5E9 /* systemStatusWithPluginsOnly-without-data.json */; };
DEA6B1CA296D0E8B005AA5E9 /* systemStatus-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DEA6B1C8296D0E8A005AA5E9 /* systemStatus-without-data.json */; };
DEC2961C26BBE764005A056B /* ShippingLabelCustomsForm.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEC2961B26BBE764005A056B /* ShippingLabelCustomsForm.swift */; };
DEC51A95274CDA52009F3DF4 /* SitePluginMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEC51A94274CDA52009F3DF4 /* SitePluginMapper.swift */; };
DEC51A97274DD962009F3DF4 /* plugin.json in Resources */ = {isa = PBXBuildFile; fileRef = DEC51A96274DD962009F3DF4 /* plugin.json */; };
Expand Down Expand Up @@ -1532,6 +1534,8 @@
DE9DEEF4291CF1B40070AD7C /* site-plugin-without-envelope.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "site-plugin-without-envelope.json"; sourceTree = "<group>"; };
DEA6B1C3296C0F45005AA5E9 /* payment-gateway-cod-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "payment-gateway-cod-without-data.json"; sourceTree = "<group>"; };
DEA6B1C5296C13FB005AA5E9 /* payment-gateway-list-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "payment-gateway-list-without-data.json"; sourceTree = "<group>"; };
DEA6B1C7296D0E8A005AA5E9 /* systemStatusWithPluginsOnly-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "systemStatusWithPluginsOnly-without-data.json"; sourceTree = "<group>"; };
DEA6B1C8296D0E8A005AA5E9 /* systemStatus-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "systemStatus-without-data.json"; sourceTree = "<group>"; };
DEC2961B26BBE764005A056B /* ShippingLabelCustomsForm.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShippingLabelCustomsForm.swift; sourceTree = "<group>"; };
DEC51A94274CDA52009F3DF4 /* SitePluginMapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SitePluginMapper.swift; sourceTree = "<group>"; };
DEC51A96274DD962009F3DF4 /* plugin.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = plugin.json; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2137,6 +2141,8 @@
B559EBA820A0B5B100836CD4 /* Responses */ = {
isa = PBXGroup;
children = (
DEA6B1C8296D0E8A005AA5E9 /* systemStatus-without-data.json */,
DEA6B1C7296D0E8A005AA5E9 /* systemStatusWithPluginsOnly-without-data.json */,
DEA6B1C5296C13FB005AA5E9 /* payment-gateway-list-without-data.json */,
DEA6B1C3296C0F45005AA5E9 /* payment-gateway-cod-without-data.json */,
DE42F96E296BC9A700D514C2 /* countries-without-data.json */,
Expand Down Expand Up @@ -2944,6 +2950,7 @@
02AF07EC27492FDD00B2D81E /* media-library-from-wordpress-site.json in Resources */,
CC9A253C26442C71005DE56E /* shipping-label-eligibility-success.json in Resources */,
B5A24179217F98F600595DEF /* notifications-load-all.json in Resources */,
DEA6B1C9296D0E8B005AA5E9 /* systemStatusWithPluginsOnly-without-data.json in Resources */,
314EDF2927C02CC100A56B6F /* stripe-account-complete-empty-descriptor.json in Resources */,
028CB71F2902589E00331C09 /* create-account-error-invalid-email.json in Resources */,
E137619929151C7400FD098F /* error-wp-rest-forbidden.json in Resources */,
Expand Down Expand Up @@ -3003,6 +3010,7 @@
02BA23C922EEF62C009539E7 /* order-stats-v4-wcadmin-deactivated.json in Resources */,
CCB2CAA226209A1200285CA0 /* generic_success_data.json in Resources */,
45150AA2268373F8006922EA /* countries.json in Resources */,
DEA6B1CA296D0E8B005AA5E9 /* systemStatus-without-data.json in Resources */,
743E84F422172D0A00FAC9D7 /* shipment_tracking_multiple.json in Resources */,
02698CF624C17FC1005337C4 /* product-alternative-types.json in Resources */,
03EB99962907F03000F06A39 /* empty-data-array.json in Resources */,
Expand Down
8 changes: 7 additions & 1 deletion Networking/Networking/Mapper/SystemPluginMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ struct SystemPluginMapper: Mapper {
.siteID: siteID
]

let systemStatus = try decoder.decode(SystemStatusEnvelope.self, from: response).systemStatus
let systemStatus: SystemStatus = try {
do {
return try decoder.decode(SystemStatusEnvelope.self, from: response).systemStatus
} catch {
return try decoder.decode(SystemStatus.self, from: response)
}
}()

/// Active and in-active plugins share identical structure, but are stored in separate parts of the remote response
/// (and without an active attribute in the response). So... we use the same decoder for active and in-active plugins
Expand Down
7 changes: 5 additions & 2 deletions Networking/Networking/Mapper/SystemStatusMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ struct SystemStatusMapper: Mapper {
.siteID: siteID
]

let systemStatus = try decoder.decode(SystemStatusEnvelope.self, from: response).systemStatus
return systemStatus
do {
return try decoder.decode(SystemStatusEnvelope.self, from: response).systemStatus
} catch {
return try decoder.decode(SystemStatus.self, from: response)
}
}
}

Expand Down
14 changes: 12 additions & 2 deletions Networking/Networking/Remote/SystemStatusRemote.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ public class SystemStatusRemote: Remote {
let parameters = [
ParameterKeys.fields: [ParameterValues.activePlugins, ParameterValues.inactivePlugins]
]
let request = JetpackRequest(wooApiVersion: .mark3, method: .get, siteID: siteID, path: path, parameters: parameters)
let request = JetpackRequest(wooApiVersion: .mark3,
method: .get,
siteID: siteID,
path: path,
parameters: parameters,
availableAsRESTRequest: true)
let mapper = SystemPluginMapper(siteID: siteID)

enqueue(request, mapper: mapper, completion: completion)
Expand All @@ -31,7 +36,12 @@ public class SystemStatusRemote: Remote {
public func fetchSystemStatusReport(for siteID: Int64,
completion: @escaping (Result<SystemStatus, Error>) -> Void) {
let path = Constants.systemStatusPath
let request = JetpackRequest(wooApiVersion: .mark3, method: .get, siteID: siteID, path: path, parameters: nil)
let request = JetpackRequest(wooApiVersion: .mark3,
method: .get,
siteID: siteID,
path: path,
parameters: nil,
availableAsRESTRequest: true)
let mapper = SystemStatusMapper(siteID: siteID)
enqueue(request, mapper: mapper, completion: completion)
}
Expand Down
28 changes: 27 additions & 1 deletion Networking/NetworkingTests/Mapper/SystemPluginMapperTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,25 @@ final class SystemPluginMapperTests: XCTestCase {
XCTAssertEqual(systemPlugin.networkActivated, expectedNetworkActivated)
XCTAssertEqual(systemPlugin.active, expectedActive)
}

func test_plugins_are_parsed_successfully_when_response_has_no_data_envelope() throws {
// When
let plugins = try mapLoadSystemStatusResponseWithoutDataEnvelope()

// Then
XCTAssertEqual(plugins.count, 2)
let systemPlugin = plugins[0]
XCTAssertEqual(systemPlugin.siteID, 999999)
XCTAssertEqual(systemPlugin.plugin, "woocommerce/woocommerce.php")
XCTAssertEqual(systemPlugin.name, "WooCommerce")
XCTAssertEqual(systemPlugin.url, "https://woocommerce.com/")
XCTAssertEqual(systemPlugin.version, "5.8.0")
XCTAssertEqual(systemPlugin.versionLatest, "5.8.0")
XCTAssertEqual(systemPlugin.authorName, "Automattic")
XCTAssertEqual(systemPlugin.authorUrl, "https://woocommerce.com")
XCTAssertFalse(systemPlugin.networkActivated)
XCTAssertTrue(systemPlugin.active)
}
}

/// Private Methods.
Expand All @@ -94,9 +113,16 @@ private extension SystemPluginMapperTests {
return try SystemPluginMapper(siteID: dummySiteID).map(response: response)
}

/// Returns the SystemStatusMapper output upon receiving `systemPlugins`
/// Returns the SystemStatusMapper output upon receiving `systemStatusWithPluginsOnly`
///
func mapLoadSystemStatusResponse() throws -> [SystemPlugin] {
return try mapPlugins(from: "systemStatusWithPluginsOnly")
}

/// Returns the SystemStatusMapper output upon receiving
/// `systemStatusWithPluginsOnly-without-data`
///
func mapLoadSystemStatusResponseWithoutDataEnvelope() throws -> [SystemPlugin] {
return try mapPlugins(from: "systemStatusWithPluginsOnly-without-data")
}
}
58 changes: 57 additions & 1 deletion Networking/NetworkingTests/Mapper/SystemStatusMapperTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,56 @@ final class SystemStatusMapperTests: XCTestCase {
XCTAssertEqual(report.pages.count, 5)
XCTAssertEqual(report.postTypeCounts.count, 3)
}

func test_system_status_fields_are_properly_parsed_when_response_has_no_data_envelope() throws {
// When
let report = try mapLoadSystemStatusResponseWithoutDataEnvelope()

// Then
XCTAssertEqual(report.environment?.homeURL, "https://additional-beetle.jurassic.ninja")
XCTAssertEqual(report.environment?.siteURL, "https://additional-beetle.jurassic.ninja")
XCTAssertEqual(report.environment?.version, "5.9.0")
XCTAssertEqual(report.environment?.wpVersion, "5.8.2")
XCTAssertEqual(report.environment?.phpVersion, "7.4.26")
XCTAssertEqual(report.environment?.curlVersion, "7.47.0, OpenSSL/1.0.2g")
XCTAssertEqual(report.environment?.mysqlVersion, "5.7.33-0ubuntu0.16.04.1-log")

XCTAssertEqual(report.database?.wcDatabaseVersion, "5.9.0")
XCTAssertEqual(report.database?.databasePrefix, "wp_")
XCTAssertEqual(report.database?.databaseTables.woocommerce.count, 14)
XCTAssertEqual(report.database?.databaseTables.other.count, 29)

XCTAssertEqual(report.activePlugins.count, 4)
XCTAssertEqual(report.activePlugins[0].siteID, dummySiteID)
XCTAssertEqual(report.inactivePlugins.count, 2)
XCTAssertEqual(report.inactivePlugins[1].siteID, dummySiteID)
XCTAssertEqual(report.dropinPlugins.count, 2)
XCTAssertEqual(report.dropinPlugins[0].name, "advanced-cache.php")
XCTAssertEqual(report.mustUsePlugins.count, 1)
XCTAssertEqual(report.mustUsePlugins[0].name, "WP.com Site Helper")

XCTAssertEqual(report.theme?.name, "Twenty Twenty-One")
XCTAssertEqual(report.theme?.version, "1.4")
XCTAssertEqual(report.theme?.authorURL, "https://wordpress.org/")
XCTAssertEqual(report.theme?.hasWoocommerceSupport, true)
XCTAssertEqual(report.theme?.overrides.count, 0)

XCTAssertEqual(report.settings?.apiEnabled, false)
XCTAssertEqual(report.settings?.currency, "USD")
XCTAssertEqual(report.settings?.currencySymbol, "&#36;")
XCTAssertEqual(report.settings?.currencyPosition, "left")
XCTAssertEqual(report.settings?.numberOfDecimals, 2)
XCTAssertEqual(report.settings?.thousandSeparator, ",")
XCTAssertEqual(report.settings?.decimalSeparator, ".")
XCTAssertEqual(report.settings?.taxonomies["external"], "external")
XCTAssertEqual(report.settings?.productVisibilityTerms["exclude-from-catalog"], "exclude-from-catalog")

XCTAssertEqual(report.security?.secureConnection, true)
XCTAssertEqual(report.security?.hideErrors, false)

XCTAssertEqual(report.pages.count, 5)
XCTAssertEqual(report.postTypeCounts.count, 3)
}
}

private extension SystemStatusMapperTests {
Expand All @@ -72,9 +122,15 @@ private extension SystemStatusMapperTests {
return try SystemStatusMapper(siteID: dummySiteID).map(response: response)
}

/// Returns the SystemStatusMapper output upon receiving `systemStatus.json`
/// Returns the SystemStatus output upon receiving `systemStatus.json`
///
func mapLoadSystemStatusResponse() throws -> SystemStatus {
return try mapReport(from: "systemStatus")
}

/// Returns the SystemStatus output upon receiving `systemStatus-without-data.json`
///
func mapLoadSystemStatusResponseWithoutDataEnvelope() throws -> SystemStatus {
return try mapReport(from: "systemStatus-without-data")
}
}
Loading