Skip to content

Commit 809c371

Browse files
committed
Merge branch 'feat/8637-site-settings-migration' into feat/8639-inbox-note-migration
2 parents 0d94029 + ce0ef50 commit 809c371

File tree

6 files changed

+59
-8
lines changed

6 files changed

+59
-8
lines changed

Networking/Networking.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,7 @@
701701
DE42F96F296BC9A700D514C2 /* countries-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE42F96E296BC9A700D514C2 /* countries-without-data.json */; };
702702
DE4F2A3F29750EF400B0701C /* inbox-note-list-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE4F2A3D29750EF400B0701C /* inbox-note-list-without-data.json */; };
703703
DE4F2A4029750EF400B0701C /* inbox-note-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE4F2A3E29750EF400B0701C /* inbox-note-without-data.json */; };
704+
DE4F2A4229751EAE00B0701C /* setting-coupon-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE4F2A4129751EAE00B0701C /* setting-coupon-without-data.json */; };
704705
DE50295928C5BD0200551736 /* JetpackUser.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE50295828C5BD0200551736 /* JetpackUser.swift */; };
705706
DE50295B28C5F99700551736 /* DotcomUser.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE50295A28C5F99700551736 /* DotcomUser.swift */; };
706707
DE50295D28C6068B00551736 /* JetpackUserMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE50295C28C6068B00551736 /* JetpackUserMapper.swift */; };
@@ -1522,6 +1523,7 @@
15221523
DE42F96E296BC9A700D514C2 /* countries-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "countries-without-data.json"; sourceTree = "<group>"; };
15231524
DE4F2A3D29750EF400B0701C /* inbox-note-list-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "inbox-note-list-without-data.json"; sourceTree = "<group>"; };
15241525
DE4F2A3E29750EF400B0701C /* inbox-note-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "inbox-note-without-data.json"; sourceTree = "<group>"; };
1526+
DE4F2A4129751EAE00B0701C /* setting-coupon-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "setting-coupon-without-data.json"; sourceTree = "<group>"; };
15251527
DE50295828C5BD0200551736 /* JetpackUser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JetpackUser.swift; sourceTree = "<group>"; };
15261528
DE50295A28C5F99700551736 /* DotcomUser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DotcomUser.swift; sourceTree = "<group>"; };
15271529
DE50295C28C6068B00551736 /* JetpackUserMapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JetpackUserMapper.swift; sourceTree = "<group>"; };
@@ -2149,6 +2151,7 @@
21492151
children = (
21502152
DE4F2A3D29750EF400B0701C /* inbox-note-list-without-data.json */,
21512153
DE4F2A3E29750EF400B0701C /* inbox-note-without-data.json */,
2154+
DE4F2A4129751EAE00B0701C /* setting-coupon-without-data.json */,
21522155
DEEDA4432975003800F845AB /* settings-general-without-data.json */,
21532156
DEA6B1C8296D0E8A005AA5E9 /* systemStatus-without-data.json */,
21542157
DEA6B1C7296D0E8A005AA5E9 /* systemStatusWithPluginsOnly-without-data.json */,
@@ -3165,6 +3168,7 @@
31653168
68CB801628D8A39700E169F8 /* customer.json in Resources */,
31663169
EEA658402966C05D00112DF0 /* product-search-sku-without-data.json in Resources */,
31673170
DE42F96D296BC67E00D514C2 /* wc-analytics-customers-without-data.json in Resources */,
3171+
DE4F2A4229751EAE00B0701C /* setting-coupon-without-data.json in Resources */,
31683172
03EB99982907F4AA00F06A39 /* just-in-time-message-list-multiple.json in Resources */,
31693173
EE80A25029556FBD003591E4 /* coupon-reports-without-data.json in Resources */,
31703174
451A97DE260B59870059D135 /* shipping-label-packages-success.json in Resources */,

Networking/Networking/Mapper/SiteSettingMapper.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ struct SiteSettingMapper: Mapper {
2525
.settingGroupKey: settingsGroup.rawValue
2626
]
2727

28-
return try decoder.decode(SiteSettingEnvelope.self, from: response).setting
28+
do {
29+
return try decoder.decode(SiteSettingEnvelope.self, from: response).setting
30+
} catch {
31+
return try decoder.decode(SiteSetting.self, from: response)
32+
}
2933
}
3034
}
3135

Networking/NetworkingTests/Mapper/SiteSettingMapperTests.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ final class SiteSettingMapperTests: XCTestCase {
1717
XCTAssertEqual(setting.label, "Enable coupons")
1818
XCTAssertEqual(setting.value, "yes")
1919
}
20+
21+
/// Verifies the SiteSetting fields are parsed correctly when response has no data envelope.
22+
///
23+
func test_SiteSetting_fields_are_properly_parsed_when_response_has_no_data_envelope() throws {
24+
let setting = try XCTUnwrap(mapLoadCouponSettingResponseWithoutDataEnvelope())
25+
XCTAssertEqual(setting.siteID, dummySiteID)
26+
XCTAssertEqual(setting.settingID, "woocommerce_enable_coupons")
27+
XCTAssertEqual(setting.settingDescription, "Enable the use of coupon codes")
28+
XCTAssertEqual(setting.label, "Enable coupons")
29+
XCTAssertEqual(setting.value, "yes")
30+
}
31+
2032
func test_SiteSetting_value_field_is_properly_parsed_when_value_field_is_not_string() throws {
2133
let setting = try XCTUnwrap(loadMultiselectValueSettingResponse())
2234
XCTAssertEqual(setting.settingID, "woocommerce_all_except_countries")
@@ -41,6 +53,13 @@ private extension SiteSettingMapperTests {
4153
func mapLoadCouponSettingResponse() -> SiteSetting? {
4254
return mapSetting(from: "setting-coupon")
4355
}
56+
57+
/// Returns the SiteSettingMapper output upon receiving `setting-coupon-without-data`
58+
///
59+
func mapLoadCouponSettingResponseWithoutDataEnvelope() -> SiteSetting? {
60+
return mapSetting(from: "setting-coupon-without-data")
61+
}
62+
4463
/// Returns the SiteSettingMapper output upon receiving `setting-all-except-countries`
4564
///
4665
func loadMultiselectValueSettingResponse() -> SiteSetting? {

Networking/NetworkingTests/Mapper/SiteSettingsMapperTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class SiteSettingsMapperTests: XCTestCase {
4545
/// Verifies the SiteSetting fields are parsed correctly when response has no data envelope.
4646
///
4747
func test_SiteSetting_fields_are_properly_parsed_when_response_has_no_data_envelope() {
48-
let settings = mapLoadGeneralSiteSettingsResponseWithoutData()
48+
let settings = mapLoadGeneralSiteSettingsResponseWithoutDataEnvelope()
4949
XCTAssertEqual(settings.count, 20)
5050

5151
let firstSetting = settings[0]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"id": "woocommerce_enable_coupons",
3+
"label": "Enable coupons",
4+
"description": "Enable the use of coupon codes",
5+
"type": "checkbox",
6+
"default": "yes",
7+
"tip": "Coupons can be applied from the cart and checkout pages.",
8+
"value": "yes",
9+
"_links": {
10+
"self": [
11+
{
12+
"href": "https://jamosova3.mystagingwebsite.com/wp-json/wc/v2/settings/general/woocommerce_enable_coupons"
13+
}
14+
],
15+
"collection": [
16+
{
17+
"href": "https://jamosova3.mystagingwebsite.com/wp-json/wc/v2/settings/general"
18+
}
19+
]
20+
}
21+
}

WooCommerce/Classes/Yosemite/DefaultStoresManager.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -351,14 +351,17 @@ private extension DefaultStoresManager {
351351
}
352352
dispatch(productSettingsAction)
353353

354-
group.enter()
355-
let sitePlanAction = AccountAction.synchronizeSitePlan(siteID: siteID) { result in
356-
if case let .failure(error) = result {
357-
errors.append(error)
354+
/// skips synchronizing site plan if logged in with WPOrg credentials
355+
if siteID != WooConstants.placeholderStoreID {
356+
group.enter()
357+
let sitePlanAction = AccountAction.synchronizeSitePlan(siteID: siteID) { result in
358+
if case let .failure(error) = result {
359+
errors.append(error)
360+
}
361+
group.leave()
358362
}
359-
group.leave()
363+
dispatch(sitePlanAction)
360364
}
361-
dispatch(sitePlanAction)
362365

363366
group.notify(queue: .main) {
364367
if errors.isEmpty {

0 commit comments

Comments
 (0)