-
Notifications
You must be signed in to change notification settings - Fork 136
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
Unify the logic of fetching product by SKU #12540
Conversation
📲 You can test the changes from this Pull Request in WooCommerce-Wear Android by scanning the QR code below to install the corresponding build.
|
📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.
|
It's handled in the `FetchProductBySKU` use case
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## trunk #12540 +/- ##
============================================
- Coverage 40.61% 40.59% -0.02%
+ Complexity 5665 5653 -12
============================================
Files 1228 1228
Lines 68917 68900 -17
Branches 9544 9542 -2
============================================
- Hits 27991 27971 -20
- Misses 38354 38356 +2
- Partials 2572 2573 +1 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the improvement @samiuelson. The fix works fine. I've left couple of comments about showing progress bar while we fetch product from remote and adding unit tests. Let me know what you think!
@@ -904,6 +902,7 @@ class OrderCreateEditViewModel @Inject constructor( | |||
barcodeFormat = status.format | |||
) | |||
) | |||
viewState = viewState.copy(isUpdatingOrderDraft = false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓ I don't think we need this. Please refer my comment below.
)?.let { products -> | ||
handleFetchProductBySKUSuccess(products, selectedItems, source, barcodeOptions) | ||
} ?: run { | ||
val result = fetchProductBySKU(barcodeOptions.sku, barcodeOptions.barcodeFormat) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, we could write unit tests to test these business logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done – 5e74c63
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could write unit tests to test these business logic
I reviewed existing unit tests and think the logic of fetchProductBySKU
is covered pretty well. If you can see any scenario missing let me know though, @AnirudhBhat!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant adding tests for the newly made changes of showing and hiding progress bar while fetching SKU.
Version |
Thanks for the review, @AnirudhBhat! I've addressed your comments. Let me know what you think. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! I've just left one minor comment about adding unit test for the newly added logic of displaying and hiding progress bar while fetching product from SKU.
Closes: #11919
Description
This PR intends to unify the logic responsible for fetching the product by SKU.
Context: Users reported a problem that it's impossible to add a product by scanning its barcode in the order creation flow, however, the product was detected correctly in the Products screen. The hypothesis was that the EAN-13 checksum was not handled correctly in the
OrderCreateEditViewModel
, however, it turned out that the product was not found because it was fetched from the local storage only.There are also the following reasons for that change:
OrderCreateEditViewModel
class that contains too much codeTo achieve the above, this PR switches to using the existing
FetchProductBySKU
class in theOrderCreateEditViewModel
. The difference between the existing logic in the VM and theFetchProductBySKU
use case is that the latter on attempts to look for the product on the remote in case it's not found in the local cache.Steps to reproduce
Testing information
It's important to do thorough tests of the order creation flow — adding a product by scanning the barcode, including edge-cases, e.g. wrong barcode value (not matching any SKU), barcode matching existing SKU present on remote only, etc.
The tests that have been performed
I tested that this PR fixes the above scenario. Device: Pixel 8, Android 14
RELEASE-NOTES.txt
if necessary. Use the "[Internal]" label for non-user-facing changes.Reviewer (or Author, in the case of optional code reviews):
Please make sure these conditions are met before approving the PR, or request changes if the PR needs improvement: