Skip to content

Commit 8edd30d

Browse files
committed
Allow null name to remove a fee line from an order
1 parent e94ec2e commit 8edd30d

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

Networking/Networking/Model/Copiable/Models+Copiable.generated.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ extension Order {
334334
extension OrderFeeLine {
335335
public func copy(
336336
feeID: CopiableProp<Int64> = .copy,
337-
name: CopiableProp<String> = .copy,
337+
name: NullableCopiableProp<String> = .copy,
338338
taxClass: CopiableProp<String> = .copy,
339339
taxStatus: CopiableProp<OrderFeeTaxStatus> = .copy,
340340
total: CopiableProp<String> = .copy,
@@ -1741,8 +1741,8 @@ extension WCPayCardPresentPaymentDetails {
17411741
extension WCPayCardPresentReceiptDetails {
17421742
public func copy(
17431743
accountType: CopiableProp<WCPayCardFunding> = .copy,
1744-
applicationPreferredName: CopiableProp<String> = .copy,
1745-
dedicatedFileName: CopiableProp<String> = .copy
1744+
applicationPreferredName: NullableCopiableProp<String> = .copy,
1745+
dedicatedFileName: NullableCopiableProp<String> = .copy
17461746
) -> WCPayCardPresentReceiptDetails {
17471747
let accountType = accountType ?? self.accountType
17481748
let applicationPreferredName = applicationPreferredName ?? self.applicationPreferredName

Networking/Networking/Model/OrderFeeLine.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ import Codegen
55
///
66
public struct OrderFeeLine: Equatable, Codable, GeneratedFakeable, GeneratedCopiable {
77
public let feeID: Int64
8-
public let name: String
8+
9+
/// Fee Name
10+
///
11+
/// Sending a null value to the REST API removes the Fee Line from the Order.
12+
///
13+
public let name: String?
14+
915
public let taxClass: String
1016
public let taxStatus: OrderFeeTaxStatus
1117
public let total: String
@@ -16,7 +22,7 @@ public struct OrderFeeLine: Equatable, Codable, GeneratedFakeable, GeneratedCopi
1622
/// OrderFeeLine struct initializer.
1723
///
1824
public init(feeID: Int64,
19-
name: String,
25+
name: String?,
2026
taxClass: String,
2127
taxStatus: OrderFeeTaxStatus,
2228
total: String,

Networking/NetworkingTests/Remote/OrdersRemoteTests.swift

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,28 @@ final class OrdersRemoteTests: XCTestCase {
232232
assertEqual(received, expected)
233233
}
234234

235+
func test_update_order_properly_encodes_fee_lines_for_removal_from_order() throws {
236+
// Given
237+
let remote = OrdersRemote(network: network)
238+
let fee = OrderFeeLine(feeID: 333, name: nil, taxClass: "", taxStatus: .none, total: "12.34", totalTax: "", taxes: [], attributes: [])
239+
let order = Order.fake().copy(fees: [fee])
240+
241+
// When
242+
remote.updateOrder(from: 123, order: order, fields: [.fees]) { result in }
243+
244+
// Then
245+
let request = try XCTUnwrap(network.requestsForResponseData.last as? JetpackRequest)
246+
let received = try XCTUnwrap(request.parameters["fee_lines"] as? [[String: AnyHashable]]).first
247+
let expected: [String: AnyHashable] = [
248+
"id": fee.feeID,
249+
"name": NSNull(),
250+
"tax_status": fee.taxStatus.rawValue,
251+
"tax_class": fee.taxClass,
252+
"total": fee.total
253+
]
254+
assertEqual(expected, received)
255+
}
256+
235257

236258
// MARK: - Load Order Notes Tests
237259

@@ -301,7 +323,7 @@ final class OrdersRemoteTests: XCTestCase {
301323
let received = try XCTUnwrap(request.parameters["fee_lines"] as? [[String: AnyHashable]]).first
302324
let expected: [String: AnyHashable] = [
303325
"id": fee.feeID,
304-
"name": fee.name,
326+
"name": fee.name ?? "",
305327
"tax_status": fee.taxStatus.rawValue,
306328
"tax_class": fee.taxClass,
307329
"total": fee.total

0 commit comments

Comments
 (0)