Skip to content

WCProductCategoryModel to Room #13996

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: migrate_product_variation_to_room_tests
Choose a base branch
from

Conversation

wzieba
Copy link
Contributor

@wzieba wzieba commented May 1, 2025

Closes: AINFRA-125

Description

This PR migrates WCProductCategoryModel to Room.

Testing information

Smoke test any feature that uses WCProductCategoryModel.

Images/gif

Screenshot 2025-05-02 at 10 31 56
  • 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.

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:

  • The PR is small and has a clear, single focus, or a valid explanation is provided in the description. If needed, please request to split it into smaller PRs.
  • Ensure Adequate Unit Test Coverage: The changes are reasonably covered by unit tests or an explanation is provided in the PR description.
  • Manual Testing: The author listed all the tests they ran, including smoke tests when needed (e.g., for refactorings). The reviewer confirmed that the PR works as expected on big (tablet) and small (phone) in case of UI changes, and no regressions are added.

@wzieba wzieba added the type: technical debt Represents or solves tech debt of the project. label May 1, 2025
@dangermattic
Copy link
Collaborator

dangermattic commented May 1, 2025

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

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented May 1, 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
Commitd512b96
Direct Downloadwoocommerce-wear-prototype-build-pr13996-d512b96.apk

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented May 1, 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
Commitd512b96
Direct Downloadwoocommerce-prototype-build-pr13996-d512b96.apk

Use constructor instead of copy when it's possible. Remove unused methods
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 12.00000% with 44 lines in your changes missing coverage. Please review.

Project coverage is 38.35%. Comparing base (3e6c29c) to head (d512b96).

Files with missing lines Patch % Lines
...rg/wordpress/android/fluxc/store/WCProductStore.kt 0.00% 23 Missing ⚠️
...products/categories/ProductCategoriesRepository.kt 0.00% 9 Missing ⚠️
...network/rest/wpcom/wc/product/ProductRestClient.kt 0.00% 6 Missing ⚠️
...est/wpcom/wc/product/ProductCategoryApiResponse.kt 0.00% 5 Missing ⚠️
...roid/fluxc/persistence/dao/ProductCategoriesDao.kt 0.00% 1 Missing ⚠️
Additional details and impacted files
@@                              Coverage Diff                              @@
##             migrate_product_variation_to_room_tests   #13996      +/-   ##
=============================================================================
+ Coverage                                      38.31%   38.35%   +0.04%     
- Complexity                                      9515     9516       +1     
=============================================================================
  Files                                           2119     2120       +1     
  Lines                                         116382   116265     -117     
  Branches                                       14934    14931       -3     
=============================================================================
+ Hits                                           44593    44595       +2     
+ Misses                                         67708    67590     -118     
+ Partials                                        4081     4080       -1     

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

@wzieba
Copy link
Contributor Author

wzieba commented May 2, 2025

There's something off with WCLeaderboardsStoreTest > fetch top performer products legacy should return mapped top performer entities correctly test. It was failing on CI, but locally, it passed every time for me. After 2 re-runs on CI, it started to pass on CI as well.

@wzieba wzieba requested a review from Copilot May 2, 2025 08:39
@wzieba wzieba added the status: blocked Blocked from progressing somehow, waiting for another piece of work to be done. label May 2, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR migrates the WCProductCategoryModel from legacy SQL-based operations to Room, replacing functions in the store, DAO, network client, and test utilities. Key changes include:

  • Refactoring database operations to use the ProductCategoriesDao with Room (upsert, delete, observe).
  • Updating API conversion methods to use immutable data classes via copy().
  • Modifying tests and UI components to accommodate the suspend functions and Room-based model.

Reviewed Changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated no comments.

Show a summary per file
File Description
ProductTestUtils.kt Removed legacy helper generators and updated getProductCategories() to use constructor-based model creation.
WCProductLeaderboardsMapperTest.kt & WCLeaderboardsStoreTest.kt Added productCategoriesDao usage to tests.
WCProductStore.kt Migrated category-related operations from ProductSqlUtils to Room DAO calls.
ProductCategoriesDao.kt New DAO definition for WCProductCategoryModel with Room annotations.
WCAndroidDatabase.kt Added WCProductCategoryModel to the Room database with updated version and migration.
ProductSqlUtils.kt Removed legacy SQL functions for product categories.
ProductRestClient.kt & ProductCategoryApiResponse.kt Updated category model conversion to use copy() for immutability.
WCProductCategoryModel.kt Converted from mutable model with WellSQL annotations to an immutable data class with Room Entity annotation.
WCDatabaseModule.kt Provided injection for the new ProductCategoriesDao.
GetCategoriesByIdsTest.kt, ProductCategoriesRepository.kt, AddProductCategoryViewModel.kt, AddProductCategoryFragment.kt Updated tests and repository functions to work with the Room migration and suspend functions.
Comments suppressed due to low confidence (2)

WooCommerce/src/test/kotlin/com/woocommerce/android/ui/products/categories/AddProductCategoryFragment.kt:115

  • Consider using viewLifecycleOwner.lifecycleScope.launch { ... } instead of runBlocking to asynchronously fetch and set the parent category name, avoiding potential UI thread blocking.
runBlocking { viewModel.getSelectedParentCategoryName()?.let { setText(it) } }

WooCommerce/src/test/kotlin/com/woocommerce/android/ui/products/categories/AddProductCategoryFragment.kt:167

  • Replace runBlocking with an asynchronous call using lifecycleScope to prevent UI thread blocking during click handling.
val parentCategoryName = runBlocking { viewModel.getSelectedParentCategoryName() }

@wzieba wzieba requested a review from ParaskP7 May 2, 2025 08:51
@wzieba wzieba changed the title [WIP] WCProductCategoryModel to Room WCProductCategoryModel to Room May 2, 2025
@wzieba wzieba marked this pull request as ready for review May 2, 2025 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: blocked Blocked from progressing somehow, waiting for another piece of work to be done. type: technical debt Represents or solves tech debt of the project.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants