Skip to content

Commit 98f731a

Browse files
authored
Merge pull request #5298 from woocommerce/issue/5296-order-fields-param
Fix order request failing from spaces in `_fields` parameter value for certain sites
2 parents f901be8 + 2bbea3c commit 98f731a

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

Networking/Networking/Remote/OrdersRemote.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -245,16 +245,16 @@ public extension OrdersRemote {
245245

246246
enum ParameterValues {
247247
// Same as singleOrderFieldValues except we exclude the line_items and shipping fields
248-
static let listFieldValues: String = """
249-
id,parent_id,number,status,currency,customer_id,customer_note,date_created_gmt,date_modified_gmt,date_paid_gmt,\
250-
discount_total,discount_tax,shipping_total,shipping_tax,total,total_tax,payment_method,payment_method_title,\
251-
billing,coupon_lines,shipping_lines,refunds,fee_lines
252-
"""
253-
static let singleOrderFieldValues: String = """
254-
id,parent_id,number,status,currency,customer_id,customer_note,date_created_gmt,date_modified_gmt,date_paid_gmt,\
255-
discount_total,discount_tax,shipping_total,shipping_tax,total,total_tax,payment_method,payment_method_title,shipping,\
256-
billing,coupon_lines,shipping_lines,refunds,fee_lines,line_items
257-
"""
248+
static let listFieldValues: String = commonOrderFieldValues.joined(separator: ",")
249+
static let singleOrderFieldValues: String = (commonOrderFieldValues + singleOrderExtraFieldValues).joined(separator: ",")
250+
private static let commonOrderFieldValues = [
251+
"id", "parent_id", "number", "status", "currency", "customer_id", "customer_note", "date_created_gmt", "date_modified_gmt", "date_paid_gmt",
252+
"discount_total", "discount_tax", "shipping_total", "shipping_tax", "total", "total_tax", "payment_method", "payment_method_title",
253+
"billing", "coupon_lines", "shipping_lines", "refunds", "fee_lines"
254+
]
255+
private static let singleOrderExtraFieldValues = [
256+
"line_items", "shipping"
257+
]
258258
}
259259

260260
/// Order fields supported for update

Networking/NetworkingTests/Remote/OrdersRemoteTests.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ final class OrdersRemoteTests: XCTestCase {
3636
network.removeAllSimulatedResponses()
3737
}
3838

39+
/// Verifies that the parameter `_fields` in single order and order list requests do not contain whitespace.
40+
///
41+
func test_order_fields_parameter_values_do_not_contain_whitespace() throws {
42+
// When
43+
let orderListFieldsValue = OrdersRemote.ParameterValues.listFieldValues
44+
let orderFieldsValue = OrdersRemote.ParameterValues.singleOrderFieldValues
45+
46+
// Then
47+
XCTAssertFalse(orderListFieldsValue.contains(" "))
48+
XCTAssertFalse(orderFieldsValue.contains(" "))
49+
}
50+
3951
// MARK: - Load All Orders Tests
4052

4153
/// Verifies that loadAllOrders properly parses the `orders-load-all` sample response.

RELEASE-NOTES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- [*] Order Details: Show a button on the "Product" section of Order Details screen to allow recreating shipping labels. [https://github.com/woocommerce/woocommerce-ios/pull/5255]
77
- [*] Edit Order Address - Enable `Done` button when `Use as {Shipping/Billing} Address` toggle is turned on. [https://github.com/woocommerce/woocommerce-ios/pull/5254]
88
- [*] Add/Edit Product: fix an issue where the product name keyboard is English only. [https://github.com/woocommerce/woocommerce-ios/pull/5288]
9+
- [*] Order Details: some sites cannot parse order requests where the fields parameter has spaces, and the products section cannot load as a result. The spaces are now removed. [https://github.com/woocommerce/woocommerce-ios/pull/5298]
910

1011
7.8
1112
-----

0 commit comments

Comments
 (0)