Skip to content

Commit c96c854

Browse files
committed
Adds simple shipping line input
1 parent 708289e commit c96c854

File tree

5 files changed

+68
-7
lines changed

5 files changed

+68
-7
lines changed

Fakes/Fakes/Networking.generated.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ extension OrderStatusEnum {
542542
/// Returns a "ready to use" type filled with fake values.
543543
///
544544
public static func fake() -> OrderStatusEnum {
545-
.pending
545+
.autoDraft
546546
}
547547
}
548548
extension OrderTaxLine {

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

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,6 +1468,33 @@ extension ShippingLabelPurchase {
14681468
}
14691469
}
14701470

1471+
extension ShippingLine {
1472+
public func copy(
1473+
shippingID: CopiableProp<Int64> = .copy,
1474+
methodTitle: CopiableProp<String> = .copy,
1475+
methodID: NullableCopiableProp<String> = .copy,
1476+
total: CopiableProp<String> = .copy,
1477+
totalTax: CopiableProp<String> = .copy,
1478+
taxes: CopiableProp<[ShippingLineTax]> = .copy
1479+
) -> ShippingLine {
1480+
let shippingID = shippingID ?? self.shippingID
1481+
let methodTitle = methodTitle ?? self.methodTitle
1482+
let methodID = methodID ?? self.methodID
1483+
let total = total ?? self.total
1484+
let totalTax = totalTax ?? self.totalTax
1485+
let taxes = taxes ?? self.taxes
1486+
1487+
return ShippingLine(
1488+
shippingID: shippingID,
1489+
methodTitle: methodTitle,
1490+
methodID: methodID,
1491+
total: total,
1492+
totalTax: totalTax,
1493+
taxes: taxes
1494+
)
1495+
}
1496+
}
1497+
14711498
extension Site {
14721499
public func copy(
14731500
siteID: CopiableProp<Int64> = .copy,
@@ -1741,8 +1768,8 @@ extension WCPayCardPresentPaymentDetails {
17411768
extension WCPayCardPresentReceiptDetails {
17421769
public func copy(
17431770
accountType: CopiableProp<WCPayCardFunding> = .copy,
1744-
applicationPreferredName: CopiableProp<String> = .copy,
1745-
dedicatedFileName: CopiableProp<String> = .copy
1771+
applicationPreferredName: NullableCopiableProp<String> = .copy,
1772+
dedicatedFileName: NullableCopiableProp<String> = .copy
17461773
) -> WCPayCardPresentReceiptDetails {
17471774
let accountType = accountType ?? self.accountType
17481775
let applicationPreferredName = applicationPreferredName ?? self.applicationPreferredName

Networking/Networking/Model/ShippingLine.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Codegen
33

44
/// Represents a Shipping Line Entity.
55
///
6-
public struct ShippingLine: Codable, Equatable, GeneratedFakeable {
6+
public struct ShippingLine: Codable, Equatable, GeneratedFakeable, GeneratedCopiable {
77
public let shippingID: Int64
88
public let methodTitle: String
99

WooCommerce/Classes/ViewRelated/Orders/Order Creation/Synchronizer/RemoteOrderSynchronizer.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,11 @@ private extension RemoteOrderSynchronizer {
9494
order.copy(billingAddress: .some(addressesInput?.billing), shippingAddress: .some(addressesInput?.shipping))
9595
}
9696
.assign(to: &$order)
97+
98+
setShipping.withLatestFrom(orderPublisher)
99+
.map { shippingLineInput, order in
100+
order.copy(shippingLines: shippingLineInput.flatMap { [$0] } ?? [])
101+
}
102+
.assign(to: &$order)
97103
}
98104
}

WooCommerce/WooCommerceTests/ViewRelated/Orders/Order Creation/Synchronizer/RemoteOrderSynchronizerTests.swift

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import Fakes
77

88
class RemoteOrderSynchronizerTests: XCTestCase {
99

10-
let sampleSiteID: Int64 = 123
11-
let sampleProductID: Int64 = 234
12-
let sampleInputID: Int64 = 345
10+
private let sampleSiteID: Int64 = 123
11+
private let sampleProductID: Int64 = 234
12+
private let sampleInputID: Int64 = 345
13+
private let sampleShippingID: Int64 = 456
1314

1415
func test_sending_status_input_updates_local_order() throws {
1516
// Given
@@ -106,4 +107,31 @@ class RemoteOrderSynchronizerTests: XCTestCase {
106107
XCTAssertNil(synchronizer.order.billingAddress)
107108
XCTAssertNil(synchronizer.order.shippingAddress)
108109
}
110+
111+
func test_sending_shipping_input_updates_local_order() throws {
112+
// Given
113+
let shippingLine = ShippingLine.fake().copy(shippingID: sampleShippingID)
114+
let stores = MockStoresManager(sessionManager: .testingInstance)
115+
let synchronizer = RemoteOrderSynchronizer(siteID: sampleSiteID, stores: stores)
116+
117+
// When
118+
synchronizer.setShipping.send(shippingLine)
119+
120+
// Then
121+
XCTAssertEqual(synchronizer.order.shippingLines, [shippingLine])
122+
}
123+
124+
func test_sending_nil_shipping_input_updates_local_order() throws {
125+
// Given
126+
let shippingLine = ShippingLine.fake().copy(shippingID: sampleShippingID)
127+
let stores = MockStoresManager(sessionManager: .testingInstance)
128+
let synchronizer = RemoteOrderSynchronizer(siteID: sampleSiteID, stores: stores)
129+
130+
// When
131+
synchronizer.setShipping.send(shippingLine)
132+
synchronizer.setShipping.send(nil)
133+
134+
// Then
135+
XCTAssertEqual(synchronizer.order.shippingLines, [])
136+
}
109137
}

0 commit comments

Comments
 (0)