Skip to content
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

Disable offline entitlements in custom entitlements computation mode #1146

Merged
merged 1 commit into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ internal class OfflineEntitlementsManager(

// We disable offline entitlements in observer mode (finishTransactions = true) since it doesn't
// provide any value and simplifies operations in that mode.
private fun isOfflineEntitlementsEnabled() = appConfig.finishTransactions && appConfig.enableOfflineEntitlements
private fun isOfflineEntitlementsEnabled() = appConfig.finishTransactions &&
appConfig.enableOfflineEntitlements &&
!appConfig.customEntitlementsComputation
}

private typealias OfflineCustomerInfoCallback = Pair<(CustomerInfo) -> Unit, (PurchasesError) -> Unit>
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ class OfflineEntitlementsManagerTest {
every {
appConfig.finishTransactions
} returns true
every {
appConfig.customEntitlementsComputation
} returns false
every {
appConfig.enableOfflineEntitlements
} returns true
Expand Down Expand Up @@ -142,6 +145,18 @@ class OfflineEntitlementsManagerTest {
assertThat(result).isFalse
}

@Test
fun `shouldCalculateOfflineCustomerInfoInGetCustomerInfoRequest returns false if custom entitlement computation`() {
every { deviceCache.getCachedCustomerInfo(appUserID) } returns null
every { appConfig.customEntitlementsComputation } returns true
val isServerError = true
val result = offlineEntitlementsManager.shouldCalculateOfflineCustomerInfoInGetCustomerInfoRequest(
isServerError,
appUserID
)
assertThat(result).isFalse
}

// endregion

// region shouldCalculateOfflineCustomerInfoInPostReceipt
Expand Down Expand Up @@ -172,6 +187,13 @@ class OfflineEntitlementsManagerTest {
assertThat(offlineEntitlementsManager.shouldCalculateOfflineCustomerInfoInPostReceipt(isServerError)).isFalse
}

@Test
fun `shouldCalculateOfflineCustomerInfoInPostReceipt returns false if custom entitlements computation mode`() {
every { appConfig.customEntitlementsComputation } returns true
val isServerError = true
assertThat(offlineEntitlementsManager.shouldCalculateOfflineCustomerInfoInPostReceipt(isServerError)).isFalse
}

// endregion

// region resetOfflineCustomerInfoCache
Expand Down Expand Up @@ -404,6 +426,13 @@ class OfflineEntitlementsManagerTest {
verify(exactly = 1) { deviceCache.cacheProductEntitlementMapping(expectedMappings) }
}

@Test
fun `updateProductEntitlementMappingCacheIfStale does nothing in custom entitlement computation mode`() {
every { appConfig.customEntitlementsComputation } returns true
offlineEntitlementsManager.updateProductEntitlementMappingCacheIfStale()
verify(exactly = 0) { backend.getProductEntitlementMapping(any(), any()) }
}

// endregion

// region helpers
Expand Down