-
Notifications
You must be signed in to change notification settings - Fork 121
[Woo POS][Local Catalog] Delete data from all grdb tables on logout #16114
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
[Woo POS][Local Catalog] Delete data from all grdb tables on logout #16114
Conversation
9a3eaac to
c8889d7
Compare
|
|
…that it does not call `DefaultStoresManager.deauthenticate` which accesses ServiceLocator dependencies.
…bled by only resetting `ServiceLocator.grdbManager` when feature flag is enabled. `MockStoresManager.deauthenticate` depends on `DefaultStoresManager` implementation for some auth related test cases.
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 tested by printing the database path and checking all the tables were non-empty before logout, then became empty after logout. ![]()
Hope you don't mind my attempts to fix the unit test failure on test_user_is_logged_out_when_tapping_secondary_button, feel free to change the fix. I was able to reproduce the crash by running the WooCommerceTests suite as a whole (running individual test class passed). The crash was from the fatalError on catalog i1 feature flag disabled while accessing ServiceLocator.grdbManager.
WooCommerce/ServiceLocator.swift:203: Fatal error: GRDBManager accessed when pointOfSaleLocalCatalogi1 feature flag is disabled
because MockStoresManager in WooCommerceTests does not override deauthenticate, it calls DefaultStoresManager.deauthenticate which calls ServiceLocator.grdbManager.
Overriding MockStoresManager.deauthenticate as my first attempt didn't work, because some test cases in WooCommerceTests depend on the DefaultStoresManager.deauthenticate implementation to update the authentication state. As we don't have a good instance to return when the catalog i1 feature is disabled in ServiceLocator.grdbManager, I updated the GRDB reset to only be executed when the same feature flag is enabled.
| #expect(countsBefore.sites == 2) // Original site + new site | ||
| #expect(countsBefore.products == 4) | ||
| #expect(countsBefore.variations == 4) | ||
| #expect(countsBefore.productAttributes == 4) | ||
| #expect(countsBefore.variationAttributes == 4) |
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.
nit: how about checking the product/variation images as well?
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'll start adding every entity to this function in future, so it seems over the top to add all of them now...
Not at all, makes total sense. It didn't fail for me locally at all, glad you could reproduce it. I wonder whether my simulator had some leftover feature flag state or something... |

Description
This PR adds a reset function which is called on logout, to delete data from all tables when someone logs out of the app.
Steps to reproduce
Check unit tests pass.
I tested by adding the following to the top of
POSCatalogSyncCoordinator.shouldPerformFullSync(for:maxAge:):Screenshots
RELEASE-NOTES.txtif necessary.