Skip to content

Commit 0a44507

Browse files
authored
Merge pull request #6182 from woocommerce/issue/6026-networking-remove-shipping-fee
Order Creation: Add support in Networking layer to remove a shipping line from an order
2 parents 7a178bf + 8273d81 commit 0a44507

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

Networking/Networking/Model/ShippingLine.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ import Codegen
66
public struct ShippingLine: Codable, Equatable, GeneratedFakeable {
77
public let shippingID: Int64
88
public let methodTitle: String
9-
public let methodID: String
9+
10+
/// Shipping Method ID
11+
///
12+
/// Sending a null value to the REST API removes the Shipping Line.
13+
///
14+
public let methodID: String?
15+
1016
public let total: String
1117
public let totalTax: String
1218
public let taxes: [ShippingLineTax]
@@ -15,7 +21,7 @@ public struct ShippingLine: Codable, Equatable, GeneratedFakeable {
1521
///
1622
public init(shippingID: Int64,
1723
methodTitle: String,
18-
methodID: String,
24+
methodID: String?,
1925
total: String,
2026
totalTax: String,
2127
taxes: [ShippingLineTax]) {

Networking/NetworkingTests/Remote/OrdersRemoteTests.swift

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,27 @@ final class OrdersRemoteTests: XCTestCase {
211211
wait(for: [expectation], timeout: Constants.expectationTimeout)
212212
}
213213

214+
func test_update_order_properly_encodes_shipping_lines_for_removal_from_order() throws {
215+
// Given
216+
let remote = OrdersRemote(network: network)
217+
let shipping = ShippingLine(shippingID: 333, methodTitle: "Shipping", methodID: nil, total: "1.23", totalTax: "", taxes: [])
218+
let order = Order.fake().copy(shippingLines: [shipping])
219+
220+
// When
221+
remote.updateOrder(from: 123, order: order, fields: [.shippingLines]) { result in }
222+
223+
// Then
224+
let request = try XCTUnwrap(network.requestsForResponseData.last as? JetpackRequest)
225+
let received = try XCTUnwrap(request.parameters["shipping_lines"] as? [[String: AnyHashable]]).first
226+
let expected: [String: AnyHashable] = [
227+
"id": shipping.shippingID,
228+
"method_title": shipping.methodTitle,
229+
"method_id": NSNull(),
230+
"total": shipping.total
231+
]
232+
assertEqual(received, expected)
233+
}
234+
214235

215236
// MARK: - Load Order Notes Tests
216237

@@ -394,7 +415,7 @@ final class OrdersRemoteTests: XCTestCase {
394415
let expected: [String: AnyHashable] = [
395416
"id": shipping.shippingID,
396417
"method_title": shipping.methodTitle,
397-
"method_id": shipping.methodID,
418+
"method_id": shipping.methodID ?? "",
398419
"total": shipping.total
399420
]
400421
assertEqual(received, expected)

0 commit comments

Comments
 (0)