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 #4644

Merged
merged 2 commits into from
Jul 19, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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