Fix offline entitlements integration tests#1085
Conversation
|
|
||
| fun BillingAbstract.mockQueryProductDetails( | ||
| queryProductDetailsSubsReturn: List<StoreProduct> = emptyList(), | ||
| queryProductDetailsSubsReturn: List<StoreProduct> = listOf(StoreProductFactory.createGoogleStoreProduct()), |
There was a problem hiding this comment.
Since we were defaulting to this product in many places, I just moved it here. I checked and all other places are overriding this property so nothing else should change.
| @Suppress("TooManyFunctions") | ||
| @RunWith(AndroidJUnit4::class) | ||
| class OfflineEntitlementsFreshInstallIntegrationTest : BaseOfflineEntitlementsIntegrationTest() { | ||
| class OfflineEntitlementsFreshInstallIntegrationNoPurchasesTest : BaseOfflineEntitlementsIntegrationTest() { |
There was a problem hiding this comment.
Note that I separated these in 2. One with initial purchases and one without. To make sure we didn't enter offline entitlements in either case without the product entitlement mapping.
| fun setUp() { | ||
| ensureBlockFinishes { latch -> | ||
| setUpTest { | ||
| mockBillingAbstract.mockQueryProductDetails() |
There was a problem hiding this comment.
Now, when we getCustomerInfo, if there are pending purchases (like in these tests with initial purchases), we will try to get information about the product and post it, so this was required.
|
|
||
| @RunWith(AndroidJUnit4::class) | ||
| class OfflineEntitlementsWithInitialRequestsCompletedAndNoInitialPurchasesIntegrationTest : | ||
| BaseOfflineEntitlementsWithInitialRequestsCompletedIntegrationTest() { |
There was a problem hiding this comment.
This is misleading... Here I moved the doesNotEnterOfflineEntitlementsModeIfCachedCustomerInfoAndCustomerInfoRequestReturns500 test to the OfflineEntitlementsWithInitialRequestsCompletedAndNoInitialPurchasesIntegrationTest test class.
This is because, now that we sync pending transactions when getting customer info, we would actually enter offline entitlements in this case of having an initial purchase. The case mentioned above is covered in the new test added above entersOfflineEntitlementsModeIfCachedCustomerInfoAndPostingPendingPurchasesReturns500.
| }, | ||
| onSuccess = { | ||
| // This is a known limitation. Ideally we would sync unsynced purchases | ||
| // as soon as possible to avoid getting outdated info from the backend. |
There was a problem hiding this comment.
This is precisely what we were solving with #1073.
| assertCustomerInfoDoesNotHavePurchaseData(it) | ||
| assertAcknowledgePurchaseDidNotHappen() | ||
| onSuccess = { customerInfo2 -> | ||
| // This is because the token we are using is not a real token to be used in the backend |
There was a problem hiding this comment.
We should have an active token so we can test active entitlements more easily in production. Right now, production will not return active purchases since the token is expired.
Codecov Report
@@ Coverage Diff @@
## main #1085 +/- ##
=======================================
Coverage 85.86% 85.86%
=======================================
Files 179 179
Lines 6362 6362
Branches 876 876
=======================================
Hits 5463 5463
Misses 557 557
Partials 342 342 |
**This is an automatic release.** ### Bugfixes * Default customer info schema version to latest known by SDK (#1080) via Toni Rico (@tonidero) * Handle other diagnostics-related exceptions (#1076) via Toni Rico (@tonidero) * Return error in queryPurchases if error connecting to billing client (#1072) via Toni Rico (@tonidero) ### Other Changes * Fix offline entitlements integration tests (#1085) via Toni Rico (@tonidero) * Add defaultsRelease variant tests run configuration (#1074) via Toni Rico (@tonidero) * Compose sample app: move to gradle catalog (#1081) via Toni Rico (@tonidero) * Compose sample app: automate builds (#1082) via Toni Rico (@tonidero) * Compose sample app (#1056) via Toni Rico (@tonidero) * Migrate to Gradle version catalog (#1059) via Cesar de la Vega (@vegaro) * Trusted entitlements: Add logs with verification mode (#1067) via Toni Rico (@tonidero) * Sync pending purchases before getting customer info (#1073) via Toni Rico (@tonidero) * Refactor syncing pending transactions logic out of `Purchases` (#1058) via Toni Rico (@tonidero) * Refactor CustomerInfo listener and cache logic into CustomerInfoUpdater (#1052) via Toni Rico (@tonidero) * Trusted entitlements: Add integration tests (#1071) via Toni Rico (@tonidero) * Trusted entitlements: Add internal mechanism to force signing errors for tests (#1070) via Toni Rico (@tonidero) Co-authored-by: revenuecat-ops <ops@revenuecat.com>
Description
#1073 broke some more integration tests. I fixed one in #1080, but didn't run the offline entitlements integration tests 🤦♂️ .
Most of these make sense after that functionality was added