Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shipping Labels: Validate that address name field is not empty #4601

Merged
merged 4 commits into from Jul 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Expand Up @@ -3,6 +3,7 @@
7.2
-----
- [*] Updated success notice message for Order Fulfillment [https://github.com/woocommerce/woocommerce-ios/pull/4589]
- [*] Shipping Labels: Updated address validation to make sure a name is entered for each address. [https://github.com/woocommerce/woocommerce-ios/pull/4601]

7.1
-----
Expand Down
Expand Up @@ -498,6 +498,14 @@ extension ShippingLabelFormViewModel {

let addressToBeVerified = ShippingLabelAddressVerification(address: address, type: type)

// Validate name field locally before validating the address remotely.
// The name field cannot be empty when creating a shipping label, but this is not part of the remote validation.
// See: https://github.com/Automattic/woocommerce-services/issues/2457
if address.name.isEmpty {
let missingNameError = ShippingLabelAddressValidationError(addressError: nil, generalError: "Name is required")
onCompletion?(.validationError(missingNameError), nil)
}

updateValidatingAddressState(true, type: type)

let action = ShippingLabelAction.validateAddress(siteID: siteID, address: addressToBeVerified) { [weak self] (result) in
Expand Down
Expand Up @@ -278,6 +278,24 @@ final class ShippingLabelFormViewModelTests: XCTestCase {
XCTAssertEqual(updatedRows?[2].displayMode, .editable)
}

func test_validateAddress_returns_validation_error_when_missing_name() {
// Given
let expectedValidationError = ShippingLabelAddressValidationError(addressError: nil, generalError: "Name is required")
let originAddress = Address.fake()
let shippingLabelFormViewModel = ShippingLabelFormViewModel(order: MockOrders().makeOrder(),
originAddress: originAddress,
destinationAddress: nil)

// When
shippingLabelFormViewModel.validateAddress(type: .origin) { validationState, validationSuccess in
guard case let .validationError(error) = validationState else {
XCTFail("Validation error was not returned")
return
}
XCTAssertEqual(error, expectedValidationError)
}
}

func test_handlePaymentMethodValueChanges_returns_updated_data_and_state_with_no_selected_payment_method() {
// Given
let viewModel = ShippingLabelFormViewModel(order: MockOrders().makeOrder(),
Expand Down