Skip to content

[Shipping labels] Improve address validation errors #14468

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

Open
wants to merge 15 commits into
base: trunk
Choose a base branch
from

Conversation

irfano
Copy link
Contributor

@irfano irfano commented Aug 13, 2025

Closes WOOMOB-904

Description

This PR adds support for displaying address field errors on the Edit Address screen, using the validation errors returned from the endpoint. For example, when the house number is missing, the API response looks like this:

 "errors": {
      "address": "House number is missing",
      "general": "Address not found"
    },

Steps to reproduce

  1. Go to Orders.
  2. Select an order that is eligible for creating shipping labels.
  3. Tap the Create shipping label button.
  4. Tap the Shipment details button to open the bottom sheet.
  5. Tap the Edit button next to "Ship to".
  6. Modify the address and enter an invalid one (e.g., omit the house number).
  7. Tap "Validate & Save".

Testing information

Repeat the steps for the origin address as well, but ensure that unverified addresses can't be saved as origin addresses.

The tests that have been performed

Steps above

Images/gif

Before After
Screenshot_20250814_000502 Screenshot_20250813_235844
  • I have considered if this change warrants release notes and have added them to RELEASE-NOTES.txt if necessary. Use the "[Internal]" label for non-user-facing changes.

irfano added 11 commits August 13, 2025 22:32
This commit updates the `AddressNormalizationModel` to include a new `errors` field.
The `WooShippingNetworkingMapper` is also updated to map the errors from the DTO to the model.
The `NormalizeAddressException` class is updated to accept a map of errors instead of a single error string. This allows for more granular error reporting, specifically differentiating between general errors and address-specific errors.
The error handling in `NormalizeAddress.kt` is updated to provide more specific error messages.
- If the response model is null, an "Empty response" message is used.
- `NormalizeAddressException` is now used when there are specific address errors.
- A general `Exception` is used for other errors, incorporating the error message from the response if available.
The `AddressStatus` enum has been converted to a sealed class. This change allows for more detailed state representation, particularly for the `VerifyFailed` status, which can now optionally include a `NormalizeAddressException`.
@irfano irfano added this to the 23.1 milestone Aug 13, 2025
@irfano irfano added feature: shipping labels Related to creating, ordering, or printing shipping labels. Task (new) labels Aug 13, 2025
@dangermattic
Copy link
Collaborator

1 Warning
⚠️ This PR is larger than 300 lines of changes. Please consider splitting it into smaller PRs for easier and faster reviews.

Generated by 🚫 Danger

@irfano irfano force-pushed the issue/WOOMOB-904-improve-address-validation-errors branch 2 times, most recently from edd4641 to 70a6a58 Compare August 13, 2025 21:23
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created this class to address the LargeClass Detekt error in the WooShippingEditAddressViewModel class.

@@ -12,22 +12,30 @@ class NormalizeAddress @Inject constructor(
private val site: SelectedSite,
) {
suspend operator fun invoke(address: Address): Result<AddressNormalizationModel> {
return site.getOrNull()?.let {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed site.getOrNull() to site.get() to align with the approach we use for our domain classes in the shipping label screens.

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Aug 13, 2025

📲 You can test the changes from this Pull Request in WooCommerce-Wear Android by scanning the QR code below to install the corresponding build.
App Name WooCommerce-Wear Android
Platform⌚️ Wear OS
FlavorJalapeno
Build TypeDebug
Commit3feefd5
Direct Downloadwoocommerce-wear-prototype-build-pr14468-3feefd5.apk

@irfano irfano force-pushed the issue/WOOMOB-904-improve-address-validation-errors branch from 70a6a58 to 4b1fc71 Compare August 13, 2025 21:35
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Aug 13, 2025

📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.

App Name WooCommerce Android
Platform📱 Mobile
FlavorJalapeno
Build TypeDebug
Commit3feefd5
Direct Downloadwoocommerce-prototype-build-pr14468-3feefd5.apk

@codecov-commenter
Copy link

codecov-commenter commented Aug 14, 2025

Codecov Report

❌ Patch coverage is 67.17172% with 65 lines in your changes missing coverage. Please review.
✅ Project coverage is 37.92%. Comparing base (c797d6b) to head (3feefd5).

Files with missing lines Patch % Lines
...glabels/address/WooShippingEditAddressViewModel.kt 57.14% 16 Missing and 14 partials ⚠️
...orders/wooshippinglabels/address/AddressSection.kt 0.00% 14 Missing ⚠️
...ders/wooshippinglabels/address/NormalizeAddress.kt 50.00% 3 Missing and 3 partials ⚠️
...nglabels/networking/WooShippingNetworkingMapper.kt 0.00% 5 Missing ⚠️
.../wooshippinglabels/address/EditAddressViewState.kt 94.36% 1 Missing and 3 partials ⚠️
...oid/ui/orders/wooshippinglabels/ShipmentDetails.kt 0.00% 2 Missing ⚠️
...oid/ui/orders/wooshippinglabels/networking/DTOs.kt 0.00% 2 Missing ⚠️
...inglabels/networking/WooShippingLabelRepository.kt 0.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##              trunk   #14468      +/-   ##
============================================
- Coverage     37.92%   37.92%   -0.01%     
- Complexity     9262     9266       +4     
============================================
  Files          2009     2010       +1     
  Lines        112908   112929      +21     
  Branches      14916    14932      +16     
============================================
+ Hits          42823    42826       +3     
- Misses        66186    66192       +6     
- Partials       3899     3911      +12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hichamboushaba hichamboushaba self-assigned this Aug 15, 2025
Copy link
Member

@hichamboushaba hichamboushaba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work @irfano, works well.
I just left a question, but I'm pre-approving.

Comment on lines +31 to +34
val generalError: String?
get() = errors[ERROR_GENERAL]
val addressError: String?
get() = errors[ERROR_ADDRESS]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a remark here, the iOS app exposes an error for the name field (here), and the plugin takes this a step further by accepting an error for all fields (Check lines 43 to 49 of the file address-step/fields.jsx).

I'm not sure how to trigger any of the other errors, so I'm not sure if we need to support this or not, WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't add errors for the other fields because I couldn't reproduce them. I reviewed address-step/fields.jsx but still couldn't determine the mapping. In this PR, I mapped address key to the "Address" field, but I couldn't find the keys for the other fields.
@itsmeichigo, since you used name for the "Name" field errors, have you found a way to reproduce the name error?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed address-step/fields.jsx but still couldn't determine the mapping

You can find all the keys by looking for getProps on the file: name, company, email, phone, country, address, city, state and postcode. The mapping with of the error with the key is done on line 43.

I didn't add errors for the other fields because I couldn't reproduce them

IMO we can add them without being able to reproduce them, in case the errors happen for some specific countries, but that's now a blocker for merging this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: shipping labels Related to creating, ordering, or printing shipping labels. Task (new)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants