Skip to content

[Shipping Labels] Handle marking orders as complete #14321

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 10 commits into
base: release/22.8
Choose a base branch
from

Conversation

hichamboushaba
Copy link
Member

@hichamboushaba hichamboushaba commented Jul 14, 2025

Closes WOOMOB-797

Description

This PR implements the logic of marking orders as complete when purchasing a shipping label, it also adds logic to set the default value of the toggle using the account settings, to match the web behavior.

Steps to reproduce

Happy path
  1. Open shipping label creation form.
  2. Enable the option "Mark order as complete" from the shipment details bottom sheet.
  3. Purchase the label.
  4. Wait for the label to be purchased.
  5. Confirm the order was marked as complete.
Unhappy path
1. Import the following config to the Api Faker
[
  {
    "request": {
      "httpMethod": "PUT",
      "id": 0,
      "path": "/wc/v3/orders/%",
      "queryParameters": [],
      "type": {
        "type": "wp-api"
      }
    },
    "response": {
      "body": "",
      "endpointId": 0,
      "statusCode": 403
    }
  }
]
  1. Follow steps 1 to 4 from the happy path case.
  2. Confirm that a Snack Bar is shown to indicate the failure to mark the order as complete.
Default value of the toggle

Confirm that the toggle uses the value that was used in last purchase.

Testing information

The above TCs have all the details

The tests that have been performed

The above.

  • 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.

@hichamboushaba hichamboushaba added type: enhancement A request for an enhancement. feature: shipping labels Related to creating, ordering, or printing shipping labels. labels Jul 14, 2025
@dangermattic
Copy link
Collaborator

dangermattic commented Jul 14, 2025

1 Warning
⚠️ This PR is assigned to the milestone 22.8 ❄️. The due date for this milestone has already passed.
Please assign it to a milestone with a later deadline or check whether the release for this milestone has already been finished.

Generated by 🚫 Danger

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Jul 14, 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
Commita4549c2
Direct Downloadwoocommerce-wear-prototype-build-pr14321-a4549c2.apk

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Jul 14, 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
Commita4549c2
Direct Downloadwoocommerce-prototype-build-pr14321-a4549c2.apk

@hichamboushaba hichamboushaba force-pushed the issue/WOOMOB-797-sl-mark-order-complete branch from 8e53d76 to a377995 Compare July 14, 2025 20:23
@hichamboushaba hichamboushaba force-pushed the issue/WOOMOB-797-sl-mark-order-complete branch from a377995 to 32d1294 Compare July 14, 2025 20:50
@codecov-commenter
Copy link

codecov-commenter commented Jul 14, 2025

Codecov Report

Attention: Patch coverage is 65.90909% with 15 lines in your changes missing coverage. Please review.

Project coverage is 37.66%. Comparing base (b37ce16) to head (a4549c2).

Files with missing lines Patch % Lines
...hippinglabels/WooShippingLabelCreationViewModel.kt 78.26% 0 Missing and 5 partials ⚠️
...oid/ui/orders/wooshippinglabels/networking/DTOs.kt 0.00% 4 Missing ⚠️
...nglabels/networking/WooShippingNetworkingMapper.kt 0.00% 2 Missing ⚠️
...ui/orders/wooshippinglabels/MarkOrderAsComplete.kt 90.00% 0 Missing and 1 partial ⚠️
.../orders/wooshippinglabels/PurchaseShippingLabel.kt 0.00% 1 Missing ⚠️
...inglabels/networking/WooShippingLabelRepository.kt 0.00% 1 Missing ⚠️
...inglabels/networking/WooShippingLabelRestClient.kt 0.00% 1 Missing ⚠️
Additional details and impacted files
@@                Coverage Diff                 @@
##             release/22.8   #14321      +/-   ##
==================================================
+ Coverage           37.64%   37.66%   +0.01%     
- Complexity           9082     9086       +4     
==================================================
  Files                1980     1981       +1     
  Lines              111396   111431      +35     
  Branches            14680    14686       +6     
==================================================
+ Hits                41940    41970      +30     
+ Misses              65618    65615       -3     
- Partials             3838     3846       +8     

☔ 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.

@@ -154,7 +154,7 @@ class WooShippingLabelRestClient @Inject constructor(
selectedRate: RateDTO,
parentRate: RateDTO?,
selectedRateOptions: Map<WooShippingRateModel.Option, ShippingRateSurchargeDTO>,
markOrderComplete: Boolean,
lastOrderCompleted: Boolean,
Copy link
Member Author

Choose a reason for hiding this comment

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

This argument indicates whether the user has enabled the option and is used to update the account settings, so I renamed it to a clearer name.

Comment on lines +306 to +315
onBlocking {
invoke(any(), any(), any(), any(), any(), any(), any(), any(), any(), isNull(), isNull())
} doReturn Result.success(
PurchasedLabelData(
labels = listOf(shippingLabelModel.copy(status = PURCHASED)),
origin = emptyMap(),
destination = emptyMap(),
rates = emptyMap()
)
)
Copy link
Member Author

Choose a reason for hiding this comment

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

I moved the default initialization to the mock declaration and then removed it from the tests, this reduces code duplication.

Comment on lines -735 to +759
val ratesState = (
sut.viewState.runAndCaptureValues {
sut.onPackageSelected(defaultPackageData)
advanceUntilIdle()
}.last() as DataState
).shipmentUIList.first().shippingRatesState as ShippingRatesState.DataState
val ratesState = sut.viewState.runAndCaptureValues {
sut.onPackageSelected(defaultPackageData)
advanceUntilIdle()
}.last().let { viewState ->
(viewState as DataState).shipmentUIList.first().shippingRatesState as ShippingRatesState.DataState
}
Copy link
Member Author

Choose a reason for hiding this comment

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

I just improved the formatting here and in similar sections. The parentheses made the code harder to read, and I overlooked them when I first added them.

@hichamboushaba hichamboushaba requested review from irfano and JorgeMucientes and removed request for irfano July 15, 2025 08:06
@hichamboushaba hichamboushaba added this to the 22.8 ❄️ milestone Jul 15, 2025
@hichamboushaba hichamboushaba marked this pull request as ready for review July 15, 2025 08:07
@irfano irfano self-assigned this Jul 15, 2025
Comment on lines +849 to +855
whenever(markOrderAsComplete(orderId)) doReturn Result.success(Unit)
whenever(observeShippingLabelStatus(eq(orderId), any())) doReturn flowOf(
ObserveShippingLabelStatus.ObserveShippingLabelStatusResult(
status = PURCHASED,
shippingLabelModel = shippingLabelModel.copy(status = PURCHASED)
)
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: We can add these mocks for markOrderAsComplete and observeShippingLabelStatus to the global definitions like you did for the purchaseShippingLabel mock.

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't move these because they are not used in many tests, and also for the observeShippingLabelStatus returning the PURCHASED status doesn't seem like a default behavior. WDYT about this thought?

@hichamboushaba
Copy link
Member Author

Thanks @irfano for the review, I applied all your suggestions except one where I shared my opinion.

Regarding the MarkOrderAsCompleteTest suggestions, this class was fully generated with AI, do you think we need to be this careful about code review for tests like this? I just want to have your perspective here, as IMO it's OK to have non-optimal code in tests as long there is no performance issues and it tests the behavior as expected, and that's why AI is a good fit for writing tests.

@hichamboushaba hichamboushaba requested a review from irfano July 15, 2025 19:40
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. type: enhancement A request for an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants