Skip to content

Commit b3b97d5

Browse files
committed
Update tests
1 parent 0e87e56 commit b3b97d5

File tree

2 files changed

+7
-103
lines changed

2 files changed

+7
-103
lines changed

WooCommerce/WooCommerceTests/ViewRelated/Shipping Label/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsFormViewModelTests.swift

Lines changed: 7 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ final class WooShippingCustomsFormViewModelTests: XCTestCase {
150150
}
151151
}
152152

153-
func test_itnValidationError_when_item_view_models_hsTariffNumberTotalValue_is_nil() {
153+
func test_itnValidationError_when_item_view_models_total_value_exceeds_threshold() {
154154
// Given
155155
viewModel = WooShippingCustomsFormViewModel(order: Order.fake().copy(currency: "USD"),
156156
shipment: sampleShipment,
@@ -173,45 +173,6 @@ final class WooShippingCustomsFormViewModelTests: XCTestCase {
173173
XCTAssertEqual(viewModel.itnValidationError, .missingForTotalShipmentValue)
174174
}
175175

176-
func test_itnValidationError_when_item_view_models_hsTariffNumberTotalValue_is_less_than_2500() {
177-
// Given
178-
viewModel = WooShippingCustomsFormViewModel(order: Order.fake(),
179-
shipment: sampleShipment,
180-
onFormReady: { _ in })
181-
182-
// When
183-
viewModel.itemsViewModels.first?.hsTariffNumberTotalValue = ("123456", 1000)
184-
185-
// Then
186-
XCTAssertNil(viewModel.itnValidationError)
187-
}
188-
189-
func test_itnValidationError_when_item_view_models_hsTariffNumberTotalValue_is_more_than_2500() {
190-
// Given
191-
viewModel = WooShippingCustomsFormViewModel(order: Order.fake(),
192-
shipment: sampleShipment,
193-
onFormReady: { _ in })
194-
195-
// When
196-
viewModel.itemsViewModels[0].requiredInformationIsEntered = true
197-
viewModel.itemsViewModels[0].hsTariffNumberTotalValue = ("123456", 1000)
198-
viewModel.itemsViewModels[1].hsTariffNumberTotalValue = ("123456", 2000)
199-
viewModel.itemsViewModels[1].requiredInformationIsEntered = true
200-
viewModel.internationalTransactionNumber = ""
201-
viewModel.updateDestinationCountry(code: "CA") // ITN is not required for Canada
202-
203-
// Then
204-
XCTAssertTrue(viewModel.requiredInformationIsEntered)
205-
XCTAssertNil(viewModel.itnValidationError)
206-
207-
// When
208-
viewModel.updateDestinationCountry(code: "UK")
209-
210-
// Then
211-
XCTAssertFalse(viewModel.requiredInformationIsEntered)
212-
XCTAssertEqual(viewModel.itnValidationError, .missingForTariffClass)
213-
}
214-
215176
func test_itnValidationError_when_destination_country_requires_ITN() {
216177
// Given
217178
let requiredDestinations = ["IR", "SY", "KP", "CU", "SD"]
@@ -481,12 +442,16 @@ final class WooShippingCustomsFormViewModelTests: XCTestCase {
481442

482443
private extension WooShippingCustomsFormViewModelTests {
483444
var sampleShipment: Shipment {
445+
return sampleShipment()
446+
}
447+
448+
func sampleShipment(_ manualValuePerUnit: Double? = nil) -> Shipment {
484449
let item1 = ShippingLabelPackageItem(productOrVariationID: 1,
485450
orderItemID: 123,
486451
name: "Shirt",
487452
weight: 0.5,
488453
quantity: 2,
489-
value: 9.99,
454+
value: manualValuePerUnit ?? 9.99,
490455
dimensions: ProductDimensions.fake(),
491456
attributes: [],
492457
imageURL: nil)
@@ -495,7 +460,7 @@ private extension WooShippingCustomsFormViewModelTests {
495460
name: "Pants",
496461
weight: 0.5,
497462
quantity: 1,
498-
value: 11,
463+
value: manualValuePerUnit ?? 11,
499464
dimensions: ProductDimensions.fake(),
500465
attributes: [],
501466
imageURL: nil)

WooCommerce/WooCommerceTests/ViewRelated/Shipping Label/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsItemViewModelTests.swift

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -66,67 +66,6 @@ final class WooShippingCustomsItemViewModelTests: XCTestCase {
6666
XCTAssertFalse(viewModel.isValidWeight, "isValidWeight should be false when the weight is zero")
6767
}
6868

69-
func test_hsTariffNumberTotalValue_when_currency_symbol_is_not_$_returns_nil() {
70-
// Given
71-
viewModel = WooShippingCustomsItemViewModel(itemName: "Test",
72-
itemProductID: 22,
73-
itemQuantity: 1,
74-
itemValue: 0,
75-
itemWeight: 0,
76-
currencySymbol: "$")
77-
78-
// Then
79-
XCTAssertNil(viewModel.hsTariffNumberTotalValue)
80-
}
81-
82-
func test_hsTariffNumberTotalValue_when_currency_symbol_is_$_but_hsTariffNumber_is_empty_returns_nil() {
83-
//Given
84-
viewModel = WooShippingCustomsItemViewModel(itemName: "Test",
85-
itemProductID: 22,
86-
itemQuantity: 1,
87-
itemValue: 0,
88-
itemWeight: 0,
89-
currencySymbol: "$")
90-
91-
// When
92-
viewModel.valuePerUnit = "1000"
93-
viewModel.hsTariffNumber = ""
94-
95-
// Then
96-
XCTAssertNil(viewModel.hsTariffNumberTotalValue)
97-
}
98-
99-
func test_hsTariffNumberTotalValue_when_currency_symbol_is_$_but_invalid_hs_tariff_number_returns_nil() {
100-
// Given
101-
viewModel = WooShippingCustomsItemViewModel(itemName: "Test",
102-
itemProductID: 22,
103-
itemQuantity: 1,
104-
itemValue: 0,
105-
itemWeight: 0,
106-
currencySymbol: "$")
107-
viewModel.hsTariffNumber = "123"
108-
viewModel.valuePerUnit = "1000"
109-
110-
// Then
111-
XCTAssertNil(viewModel.hsTariffNumberTotalValue)
112-
}
113-
114-
func test_hsTariffNumberTotalValue_when_currency_symbol_is_$_and_value_is_more_than_2500_and_valid_hs_tariff_number_returns_values() {
115-
// Given
116-
viewModel = WooShippingCustomsItemViewModel(itemName: "Test",
117-
itemProductID: 22,
118-
itemQuantity: 2,
119-
itemValue: 0,
120-
itemWeight: 0,
121-
currencySymbol: "$")
122-
viewModel.valuePerUnit = "3000"
123-
viewModel.hsTariffNumber = "123456"
124-
125-
// Then
126-
XCTAssertEqual(viewModel.hsTariffNumberTotalValue?.0, viewModel.hsTariffNumber)
127-
XCTAssertEqual(viewModel.hsTariffNumberTotalValue?.1, Decimal(string: viewModel.valuePerUnit)! * 2)
128-
}
129-
13069
func test_isNumberValid_whenGivenValidTariffNumbers_shouldReturnTrue() {
13170
XCTAssertTrue(HSTariffNumberValidator.isNumberValid("123456"))
13271
XCTAssertTrue(HSTariffNumberValidator.isNumberValid("12.34.56"))

0 commit comments

Comments
 (0)