Skip to content

Fix offline entitlements integration tests#1085

Merged
tonidero merged 3 commits into
mainfrom
fix-offline-entitlements-integration-tests
Jun 23, 2023
Merged

Fix offline entitlements integration tests#1085
tonidero merged 3 commits into
mainfrom
fix-offline-entitlements-integration-tests

Conversation

@tonidero

Copy link
Copy Markdown
Contributor

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

@tonidero tonidero added the test label Jun 22, 2023

fun BillingAbstract.mockQueryProductDetails(
queryProductDetailsSubsReturn: List<StoreProduct> = emptyList(),
queryProductDetailsSubsReturn: List<StoreProduct> = listOf(StoreProductFactory.createGoogleStoreProduct()),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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() {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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() {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@tonidero tonidero marked this pull request as ready for review June 22, 2023 14:21
@tonidero tonidero requested a review from a team June 22, 2023 14:21
@codecov

codecov Bot commented Jun 22, 2023

Copy link
Copy Markdown

Codecov Report

Merging #1085 (c16f580) into main (21bf89c) will not change coverage.
The diff coverage is n/a.

@@           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           

@tonidero tonidero merged commit 8d8e2f2 into main Jun 23, 2023
@tonidero tonidero deleted the fix-offline-entitlements-integration-tests branch June 23, 2023 10:52
tonidero pushed a commit that referenced this pull request Jun 23, 2023
**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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants