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

Add internal customEntitlementsComputation mode to app config #1141

Merged
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 @@ -3,11 +3,15 @@ package com.revenuecat.purchases
/**
* Only use a Dangerous Setting if suggested by RevenueCat support team.
*/
data class DangerousSettings(
data class DangerousSettings internal constructor(
/**
* Disable or enable syncing purchases automatically. If this is disabled, RevenueCat will not sync any purchase
* automatically, and you will have to call syncPurchases whenever a new purchase is completed in order to send it
* to the RevenueCat's backend. Auto syncing of purchases is enabled by default.
*/
val autoSyncPurchases: Boolean = true,
)

internal val customEntitlementsComputation: Boolean = false,
) {
constructor(autoSyncPurchases: Boolean = true) : this(autoSyncPurchases, false)
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ internal class AppConfig(
log(LogIntent.INFO, ConfigureStrings.CONFIGURING_PURCHASES_PROXY_URL_SET)
} ?: URL("https://api.revenuecat.com/")
val diagnosticsURL = URL("https://api-diagnostics.revenuecat.com/")
val customEntitlementsComputation: Boolean
get() = dangerousSettings.customEntitlementsComputation

val playStoreVersionName = context.playStoreVersionName
val playServicesVersionName = context.playServicesVersionName
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.revenuecat.purchases

import androidx.test.ext.junit.runners.AndroidJUnit4
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class DangerousSettingsTest {
@Test
fun `default customEntitlementComputation is false`() {
val dangerousSettings = DangerousSettings()
assertThat(dangerousSettings.customEntitlementsComputation).isFalse
}

@Test
fun `default autoSyncPurchases is true`() {
val dangerousSettings = DangerousSettings()
assertThat(dangerousSettings.autoSyncPurchases).isTrue
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,28 @@ class AppConfigTest {
assertThat(appConfig.forceSigningErrors).isFalse
}

@Test
fun `customEntitlementComputation matches version from dangerous settings`() {
val appConfig = AppConfig(
context = mockk(relaxed = true),
observerMode = false,
platformInfo = PlatformInfo(flavor = "native", version = "3.2.0"),
proxyURL = null,
store = Store.PLAY_STORE,
dangerousSettings = DangerousSettings(customEntitlementsComputation = true)
)
assertThat(appConfig.customEntitlementsComputation).isTrue
val appConfig2 = AppConfig(
context = mockk(relaxed = true),
observerMode = false,
platformInfo = PlatformInfo(flavor = "native", version = "3.2.0"),
proxyURL = null,
store = Store.PLAY_STORE,
dangerousSettings = DangerousSettings(customEntitlementsComputation = false)
)
assertThat(appConfig2.customEntitlementsComputation).isFalse
}

@Test
fun `Given two app configs with same data, both are equal`() {
val x = AppConfig(
Expand Down Expand Up @@ -287,7 +309,7 @@ class AppConfigTest {
"AppConfig(" +
"platformInfo=PlatformInfo(flavor=native, version=3.2.0), " +
"store=PLAY_STORE, " +
"dangerousSettings=DangerousSettings(autoSyncPurchases=true), " +
"dangerousSettings=DangerousSettings(autoSyncPurchases=true, customEntitlementsComputation=false), " +
"languageTag='', " +
"versionName='', " +
"packageName='', " +
Expand Down