-
Notifications
You must be signed in to change notification settings - Fork 50
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
Trusted entitlements: Add integration tests #1071
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
162 changes: 162 additions & 0 deletions
162
...ecat/purchases/trustedentitlements/TrustedEntitlementsInformationalModeIntegrationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
package com.revenuecat.purchases.trustedentitlements | ||
|
||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import com.revenuecat.purchases.BasePurchasesIntegrationTest | ||
import com.revenuecat.purchases.CacheFetchPolicy | ||
import com.revenuecat.purchases.CustomerInfo | ||
import com.revenuecat.purchases.EntitlementVerificationMode | ||
import com.revenuecat.purchases.ExperimentalPreviewRevenueCatPurchasesAPI | ||
import com.revenuecat.purchases.PurchaseParams | ||
import com.revenuecat.purchases.Purchases | ||
import com.revenuecat.purchases.VerificationResult | ||
import com.revenuecat.purchases.factories.StoreProductFactory | ||
import com.revenuecat.purchases.factories.StoreTransactionFactory | ||
import com.revenuecat.purchases.forceSigningErrors | ||
import com.revenuecat.purchases.getCustomerInfoWith | ||
import com.revenuecat.purchases.helpers.mockQueryProductDetails | ||
import com.revenuecat.purchases.purchaseWith | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.assertj.core.api.Assertions.fail | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@OptIn(ExperimentalPreviewRevenueCatPurchasesAPI::class) | ||
@RunWith(AndroidJUnit4::class) | ||
class TrustedEntitlementsInformationalModeIntegrationTest : BasePurchasesIntegrationTest() { | ||
|
||
@Before | ||
fun setup() { | ||
ensureBlockFinishes { latch -> | ||
setUpTest(entitlementVerificationMode = EntitlementVerificationMode.INFORMATIONAL) { | ||
latch.countDown() | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun initialCustomerInfoIsVerified() { | ||
var receivedCustomerInfo: CustomerInfo? = null | ||
ensureBlockFinishes { latch -> | ||
Purchases.sharedInstance.getCustomerInfoWith( | ||
onError = { fail("should be success. Error: ${it.message}") }, | ||
onSuccess = { | ||
receivedCustomerInfo = it | ||
latch.countDown() | ||
}, | ||
) | ||
} | ||
|
||
assertThat(receivedCustomerInfo).isNotNull | ||
assertThat(receivedCustomerInfo?.entitlements?.verification).isEqualTo(VerificationResult.VERIFIED) | ||
} | ||
|
||
@Test | ||
fun canPurchaseProductWithVerificationStatusCorrect() { | ||
tonidero marked this conversation as resolved.
Show resolved
Hide resolved
|
||
val storeProduct = StoreProductFactory.createGoogleStoreProduct() | ||
val storeTransaction = StoreTransactionFactory.createStoreTransaction() | ||
mockBillingAbstract.mockQueryProductDetails(queryProductDetailsSubsReturn = listOf(storeProduct)) | ||
|
||
var receivedCustomerInfo: CustomerInfo? = null | ||
ensureBlockFinishes { latch -> | ||
Purchases.sharedInstance.purchaseWith( | ||
purchaseParams = PurchaseParams.Builder(activity, storeProduct).build(), | ||
onError = { error, _ -> fail("Purchase should be successful. Error: ${error.message}") }, | ||
onSuccess = { _, customerInfo -> | ||
receivedCustomerInfo = customerInfo | ||
latch.countDown() | ||
}, | ||
) | ||
latestPurchasesUpdatedListener!!.onPurchasesUpdated(listOf(storeTransaction)) | ||
} | ||
|
||
assertThat(receivedCustomerInfo).isNotNull | ||
assertThat(receivedCustomerInfo?.entitlements?.verification).isEqualTo(VerificationResult.VERIFIED) | ||
assertThat(receivedCustomerInfo?.entitlements?.all).isNotEmpty | ||
assertThat( | ||
receivedCustomerInfo?.entitlements?.all?.values?.first()?.verification, | ||
).isEqualTo(VerificationResult.VERIFIED) | ||
} | ||
|
||
@Test | ||
fun verificationChangesAfterSuccessIsNotified() { | ||
var receivedCustomerInfo: CustomerInfo? = null | ||
ensureBlockFinishes { latch -> | ||
Purchases.sharedInstance.getCustomerInfoWith( | ||
onError = { fail("should be success. Error: ${it.message}") }, | ||
onSuccess = { | ||
receivedCustomerInfo = it | ||
latch.countDown() | ||
}, | ||
) | ||
} | ||
|
||
assertThat(receivedCustomerInfo).isNotNull | ||
assertThat(receivedCustomerInfo?.entitlements?.verification).isEqualTo(VerificationResult.VERIFIED) | ||
|
||
Purchases.sharedInstance.forceSigningErrors = true | ||
|
||
var receivedCustomerInfo2: CustomerInfo? = null | ||
ensureBlockFinishes { latch -> | ||
Purchases.sharedInstance.getCustomerInfoWith( | ||
fetchPolicy = CacheFetchPolicy.FETCH_CURRENT, | ||
onError = { fail("should be success. Error: ${it.message}") }, | ||
onSuccess = { | ||
receivedCustomerInfo2 = it | ||
latch.countDown() | ||
}, | ||
) | ||
} | ||
|
||
assertThat(receivedCustomerInfo2).isNotNull | ||
assertThat(receivedCustomerInfo2?.entitlements?.verification).isEqualTo(VerificationResult.FAILED) | ||
} | ||
|
||
@Test | ||
fun initialCustomerInfoFailsToVerify() { | ||
Purchases.sharedInstance.forceSigningErrors = true | ||
|
||
var receivedCustomerInfo: CustomerInfo? = null | ||
ensureBlockFinishes { latch -> | ||
Purchases.sharedInstance.getCustomerInfoWith( | ||
onError = { fail("should be success. Error: ${it.message}") }, | ||
onSuccess = { | ||
receivedCustomerInfo = it | ||
latch.countDown() | ||
}, | ||
) | ||
} | ||
|
||
assertThat(receivedCustomerInfo).isNotNull | ||
assertThat(receivedCustomerInfo?.entitlements?.verification).isEqualTo(VerificationResult.FAILED) | ||
} | ||
|
||
@Test | ||
fun canPurchaseProductFailingToVerifyStatus() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is nice 👍🏻 |
||
Purchases.sharedInstance.forceSigningErrors = true | ||
|
||
val storeProduct = StoreProductFactory.createGoogleStoreProduct() | ||
val storeTransaction = StoreTransactionFactory.createStoreTransaction() | ||
mockBillingAbstract.mockQueryProductDetails(queryProductDetailsSubsReturn = listOf(storeProduct)) | ||
|
||
var receivedCustomerInfo: CustomerInfo? = null | ||
ensureBlockFinishes { latch -> | ||
Purchases.sharedInstance.purchaseWith( | ||
purchaseParams = PurchaseParams.Builder(activity, storeProduct).build(), | ||
onError = { error, _ -> fail("Purchase should be successful. Error: ${error.message}") }, | ||
onSuccess = { _, customerInfo -> | ||
receivedCustomerInfo = customerInfo | ||
latch.countDown() | ||
}, | ||
) | ||
latestPurchasesUpdatedListener!!.onPurchasesUpdated(listOf(storeTransaction)) | ||
} | ||
|
||
assertThat(receivedCustomerInfo).isNotNull | ||
assertThat(receivedCustomerInfo?.entitlements?.verification).isEqualTo(VerificationResult.FAILED) | ||
assertThat(receivedCustomerInfo?.entitlements?.all).isNotEmpty | ||
assertThat( | ||
receivedCustomerInfo?.entitlements?.all?.values?.first()?.verification, | ||
).isEqualTo(VerificationResult.FAILED) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can't wait to see these with coroutines 😅
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.
Pretty straightforward and neat 💅 #1077