Skip to content

Commit 708289e

Browse files
committed
Adds tests
1 parent e9c81e0 commit 708289e

File tree

3 files changed

+114
-1
lines changed

3 files changed

+114
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ private extension RemoteOrderSynchronizer {
9191

9292
setAddresses.withLatestFrom(orderPublisher)
9393
.map { addressesInput, order in
94-
order.copy(billingAddress: addressesInput?.billing, shippingAddress: addressesInput?.shipping)
94+
order.copy(billingAddress: .some(addressesInput?.billing), shippingAddress: .some(addressesInput?.shipping))
9595
}
9696
.assign(to: &$order)
9797
}

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@
424424
2602A64227BD89CE00B347F1 /* NewOrderInitialStatusResolverTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2602A64127BD89CE00B347F1 /* NewOrderInitialStatusResolverTests.swift */; };
425425
2602A64627BDBEBA00B347F1 /* ProductInputTransformer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2602A64527BDBEBA00B347F1 /* ProductInputTransformer.swift */; };
426426
2602A64827BDBF8000B347F1 /* ProductInputTransformerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2602A64727BDBF8000B347F1 /* ProductInputTransformerTests.swift */; };
427+
2602A64A27BDC80200B347F1 /* RemoteOrderSynchronizerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2602A64927BDC80200B347F1 /* RemoteOrderSynchronizerTests.swift */; };
427428
260C315E2523CC4000157BC2 /* RefundProductsTotalViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 260C315D2523CC4000157BC2 /* RefundProductsTotalViewModel.swift */; };
428429
260C31602524ECA900157BC2 /* IssueRefundViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 260C315F2524ECA900157BC2 /* IssueRefundViewController.swift */; };
429430
260C31622524EEB200157BC2 /* IssueRefundViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 260C31612524EEB200157BC2 /* IssueRefundViewController.xib */; };
@@ -2066,6 +2067,7 @@
20662067
2602A64127BD89CE00B347F1 /* NewOrderInitialStatusResolverTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewOrderInitialStatusResolverTests.swift; sourceTree = "<group>"; };
20672068
2602A64527BDBEBA00B347F1 /* ProductInputTransformer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductInputTransformer.swift; sourceTree = "<group>"; };
20682069
2602A64727BDBF8000B347F1 /* ProductInputTransformerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductInputTransformerTests.swift; sourceTree = "<group>"; };
2070+
2602A64927BDC80200B347F1 /* RemoteOrderSynchronizerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemoteOrderSynchronizerTests.swift; sourceTree = "<group>"; };
20692071
260C315D2523CC4000157BC2 /* RefundProductsTotalViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RefundProductsTotalViewModel.swift; sourceTree = "<group>"; };
20702072
260C315F2524ECA900157BC2 /* IssueRefundViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IssueRefundViewController.swift; sourceTree = "<group>"; };
20712073
260C31612524EEB200157BC2 /* IssueRefundViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = IssueRefundViewController.xib; sourceTree = "<group>"; };
@@ -4304,6 +4306,7 @@
43044306
children = (
43054307
2602A64127BD89CE00B347F1 /* NewOrderInitialStatusResolverTests.swift */,
43064308
2602A64727BDBF8000B347F1 /* ProductInputTransformerTests.swift */,
4309+
2602A64927BDC80200B347F1 /* RemoteOrderSynchronizerTests.swift */,
43074310
);
43084311
path = Synchronizer;
43094312
sourceTree = "<group>";
@@ -9351,6 +9354,7 @@
93519354
020BE76B23B4A380007FE54C /* AztecUnderlineFormatBarCommandTests.swift in Sources */,
93529355
D83F5937225B402E00626E75 /* TitleAndEditableValueTableViewCellTests.swift in Sources */,
93539356
773077F3251E954300178696 /* ProductDownloadFileViewModelTests.swift in Sources */,
9357+
2602A64A27BDC80200B347F1 /* RemoteOrderSynchronizerTests.swift in Sources */,
93549358
DE4B3B2E269455D400EEF2D8 /* MockShipmentActionStoresManager.swift in Sources */,
93559359
0246405F258B122100C10A7D /* PrintShippingLabelCoordinatorTests.swift in Sources */,
93569360
576D9F2924DB81D3007B48F4 /* StoreStatsAndTopPerformersPeriodViewModelTests.swift in Sources */,
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import XCTest
2+
import TestKit
3+
import Fakes
4+
5+
@testable import WooCommerce
6+
@testable import Yosemite
7+
8+
class RemoteOrderSynchronizerTests: XCTestCase {
9+
10+
let sampleSiteID: Int64 = 123
11+
let sampleProductID: Int64 = 234
12+
let sampleInputID: Int64 = 345
13+
14+
func test_sending_status_input_updates_local_order() throws {
15+
// Given
16+
let stores = MockStoresManager(sessionManager: .testingInstance)
17+
let synchronizer = RemoteOrderSynchronizer(siteID: sampleSiteID, stores: stores)
18+
19+
// When
20+
synchronizer.setStatus.send(.completed)
21+
22+
// Then
23+
XCTAssertEqual(synchronizer.order.status, .completed)
24+
}
25+
26+
func test_sending_new_product_input_updates_local_order() throws {
27+
// Given
28+
let product = Product.fake().copy(productID: sampleProductID)
29+
let stores = MockStoresManager(sessionManager: .testingInstance)
30+
let synchronizer = RemoteOrderSynchronizer(siteID: sampleSiteID, stores: stores)
31+
32+
// When
33+
let input = OrderSyncProductInput(product: .product(product), quantity: 1)
34+
synchronizer.setProduct.send(input)
35+
36+
// Then
37+
let item = try XCTUnwrap(synchronizer.order.items.first)
38+
XCTAssertEqual(item.itemID, input.id)
39+
XCTAssertEqual(item.productID, product.productID)
40+
XCTAssertEqual(item.quantity, input.quantity)
41+
}
42+
43+
func test_sending_update_product_input_updates_local_order() throws {
44+
// Given
45+
let product = Product.fake().copy(productID: sampleProductID)
46+
let stores = MockStoresManager(sessionManager: .testingInstance)
47+
let synchronizer = RemoteOrderSynchronizer(siteID: sampleSiteID, stores: stores)
48+
49+
// When
50+
let input = OrderSyncProductInput(id: sampleInputID, product: .product(product), quantity: 1)
51+
let input2 = OrderSyncProductInput(id: sampleInputID, product: .product(product), quantity: 2)
52+
synchronizer.setProduct.send(input)
53+
synchronizer.setProduct.send(input2)
54+
55+
// Then
56+
let item = try XCTUnwrap(synchronizer.order.items.first)
57+
XCTAssertEqual(item.itemID, input2.id)
58+
XCTAssertEqual(item.productID, product.productID)
59+
XCTAssertEqual(item.quantity, input2.quantity)
60+
}
61+
62+
func test_sending_delete_product_input_updates_local_order() throws {
63+
// Given
64+
let product = Product.fake().copy(productID: sampleProductID)
65+
let stores = MockStoresManager(sessionManager: .testingInstance)
66+
let synchronizer = RemoteOrderSynchronizer(siteID: sampleSiteID, stores: stores)
67+
68+
// When
69+
let input = OrderSyncProductInput(id: sampleInputID, product: .product(product), quantity: 1)
70+
let input2 = OrderSyncProductInput(id: sampleInputID, product: .product(product), quantity: 0)
71+
synchronizer.setProduct.send(input)
72+
synchronizer.setProduct.send(input2)
73+
74+
// Then
75+
XCTAssertEqual(synchronizer.order.items.count, 0)
76+
}
77+
78+
func test_sending_addresses_input_updates_local_order() throws {
79+
// Given
80+
let address = Address.fake().copy(firstName: "Woo", lastName: "Customer")
81+
let stores = MockStoresManager(sessionManager: .testingInstance)
82+
let synchronizer = RemoteOrderSynchronizer(siteID: sampleSiteID, stores: stores)
83+
84+
// When
85+
let input = OrderSyncAddressesInput(billing: address, shipping: address)
86+
synchronizer.setAddresses.send(input)
87+
88+
// Then
89+
XCTAssertEqual(synchronizer.order.billingAddress, address)
90+
XCTAssertEqual(synchronizer.order.shippingAddress, address)
91+
}
92+
93+
func test_sending_nil_addresses_input_updates_local_order() throws {
94+
// Given
95+
let address = Address.fake().copy(firstName: "Woo", lastName: "Customer")
96+
let stores = MockStoresManager(sessionManager: .testingInstance)
97+
let synchronizer = RemoteOrderSynchronizer(siteID: sampleSiteID, stores: stores)
98+
99+
// When
100+
let input = OrderSyncAddressesInput(billing: address, shipping: address)
101+
synchronizer.setAddresses.send(input)
102+
synchronizer.setAddresses.send(nil)
103+
104+
105+
// Then
106+
XCTAssertNil(synchronizer.order.billingAddress)
107+
XCTAssertNil(synchronizer.order.shippingAddress)
108+
}
109+
}

0 commit comments

Comments
 (0)