-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create different PurchasesConfiguration that requires an appUserId pa…
…rameter
- Loading branch information
Showing
13 changed files
with
314 additions
and
45 deletions.
There are no files selected for viewing
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
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
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
19 changes: 19 additions & 0 deletions
19
...EntitlementComputationDebug/kotlin/com/revenuecat/purchases/amazon/AmazonConfiguration.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,19 @@ | ||
package com.revenuecat.purchases.amazon | ||
|
||
import android.content.Context | ||
import com.revenuecat.purchases.PurchasesConfiguration | ||
import com.revenuecat.purchases.Store | ||
|
||
class AmazonConfiguration(builder: Builder) : PurchasesConfiguration(builder) { | ||
|
||
class Builder( | ||
context: Context, | ||
apiKey: String, | ||
appUserId: String, | ||
) : PurchasesConfiguration.Builder(context, apiKey, appUserId) { | ||
|
||
init { | ||
this.store(Store.AMAZON) | ||
} | ||
} | ||
} |
File renamed without changes.
105 changes: 105 additions & 0 deletions
105
...rc/customEntitlementComputation/kotlin/com/revenuecat/purchases/PurchasesConfiguration.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,105 @@ | ||
package com.revenuecat.purchases | ||
|
||
import android.content.Context | ||
import java.util.concurrent.ExecutorService | ||
|
||
open class PurchasesConfiguration(builder: Builder) { | ||
|
||
val context: Context | ||
val apiKey: String | ||
val appUserID: String | ||
val observerMode: Boolean | ||
val service: ExecutorService? | ||
val store: Store | ||
val diagnosticsEnabled: Boolean | ||
val dangerousSettings: DangerousSettings | ||
val verificationMode: EntitlementVerificationMode | ||
|
||
init { | ||
this.context = builder.context | ||
this.apiKey = builder.apiKey | ||
this.appUserID = builder.appUserID | ||
this.observerMode = builder.observerMode | ||
this.service = builder.service | ||
this.store = builder.store | ||
this.diagnosticsEnabled = builder.diagnosticsEnabled | ||
this.verificationMode = builder.verificationMode | ||
this.dangerousSettings = builder.dangerousSettings | ||
} | ||
|
||
open class Builder( | ||
@get:JvmSynthetic internal val context: Context, | ||
@get:JvmSynthetic internal val apiKey: String, | ||
@get:JvmSynthetic internal val appUserID: String, | ||
) { | ||
@set:JvmSynthetic @get:JvmSynthetic | ||
internal var observerMode: Boolean = false | ||
|
||
@set:JvmSynthetic @get:JvmSynthetic | ||
internal var service: ExecutorService? = null | ||
|
||
@set:JvmSynthetic @get:JvmSynthetic | ||
internal var store: Store = Store.PLAY_STORE | ||
|
||
@set:JvmSynthetic @get:JvmSynthetic | ||
internal var diagnosticsEnabled: Boolean = false | ||
|
||
@set:JvmSynthetic @get:JvmSynthetic | ||
internal var verificationMode: EntitlementVerificationMode = EntitlementVerificationMode.default | ||
|
||
// TODO Default to custom entitlement computation mode | ||
@set:JvmSynthetic @get:JvmSynthetic | ||
internal var dangerousSettings: DangerousSettings = DangerousSettings() | ||
|
||
fun observerMode(observerMode: Boolean) = apply { | ||
this.observerMode = observerMode | ||
} | ||
|
||
fun service(service: ExecutorService) = apply { | ||
this.service = service | ||
} | ||
|
||
fun store(store: Store) = apply { | ||
this.store = store | ||
} | ||
|
||
/** | ||
* Enabling diagnostics will send some performance and debugging information from the SDK to our servers. | ||
* Examples of this information include response times, cache hits or error codes. | ||
* This information will be anonymized so it can't be traced back to the end-user. | ||
* The default value is false. | ||
*/ | ||
fun diagnosticsEnabled(diagnosticsEnabled: Boolean) = apply { | ||
this.diagnosticsEnabled = diagnosticsEnabled | ||
} | ||
|
||
/** | ||
* Sets the [EntitlementVerificationMode] to perform signature verification of requests to the | ||
* RevenueCat backend. | ||
* | ||
* When changing from [EntitlementVerificationMode.DISABLED] to other modes, the SDK will clear the | ||
* CustomerInfo cache. | ||
* This means users will need to connect to the internet to get their entitlements back. | ||
* | ||
* The result of the verification can be obtained from [EntitlementInfos.verification] or | ||
* [EntitlementInfo.verification]. | ||
* | ||
* Default mode is disabled. Please see https://rev.cat/trusted-entitlements for more info. | ||
*/ | ||
fun entitlementVerificationMode(verificationMode: EntitlementVerificationMode) = apply { | ||
this.verificationMode = verificationMode | ||
} | ||
|
||
/** | ||
* Only use a Dangerous Setting if suggested by RevenueCat support team. | ||
*/ | ||
fun dangerousSettings(dangerousSettings: DangerousSettings) = apply { | ||
// TODO Set custom entitlement computation mode when passing in dangerous settings | ||
this.dangerousSettings = dangerousSettings | ||
} | ||
|
||
open fun build(): PurchasesConfiguration { | ||
return PurchasesConfiguration(this) | ||
} | ||
} | ||
} |
File renamed without changes.
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
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
83 changes: 83 additions & 0 deletions
83
...ustomEntitlementComputation/kotlin/com/revenuecat/purchases/PurchasesConfigurationTest.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,83 @@ | ||
package com.revenuecat.purchases | ||
|
||
import android.content.Context | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import io.mockk.mockk | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import java.util.concurrent.ExecutorService | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class PurchasesConfigurationTest { | ||
|
||
private val apiKey = "test-api-key" | ||
private val appUserId = "test-app-user-id" | ||
|
||
private lateinit var context: Context | ||
|
||
private lateinit var builder: PurchasesConfiguration.Builder | ||
|
||
@Before | ||
fun setup() { | ||
context = mockk() | ||
|
||
builder = PurchasesConfiguration.Builder(context, apiKey, appUserId) | ||
} | ||
|
||
@Test | ||
fun `PurchasesConfiguration has expected default parameters`() { | ||
val purchasesConfiguration = builder.build() | ||
assertThat(purchasesConfiguration.apiKey).isEqualTo(apiKey) | ||
assertThat(purchasesConfiguration.context).isEqualTo(context) | ||
assertThat(purchasesConfiguration.appUserID).isEqualTo(appUserId) | ||
assertThat(purchasesConfiguration.observerMode).isFalse | ||
assertThat(purchasesConfiguration.service).isNull() | ||
assertThat(purchasesConfiguration.store).isEqualTo(Store.PLAY_STORE) | ||
assertThat(purchasesConfiguration.diagnosticsEnabled).isFalse | ||
assertThat(purchasesConfiguration.verificationMode).isEqualTo(EntitlementVerificationMode.DISABLED) | ||
assertThat(purchasesConfiguration.dangerousSettings).isEqualTo(DangerousSettings(autoSyncPurchases = true)) | ||
} | ||
|
||
@Test | ||
fun `PurchasesConfiguration sets observerMode correctly`() { | ||
val purchasesConfiguration = builder.observerMode(true).build() | ||
assertThat(purchasesConfiguration.observerMode).isTrue | ||
} | ||
|
||
@Test | ||
fun `PurchasesConfiguration sets service correctly`() { | ||
val serviceMock: ExecutorService = mockk() | ||
val purchasesConfiguration = builder.service(serviceMock).build() | ||
assertThat(purchasesConfiguration.service).isEqualTo(serviceMock) | ||
} | ||
|
||
@Test | ||
fun `PurchasesConfiguration sets store correctly`() { | ||
val purchasesConfiguration = builder.store(Store.AMAZON).build() | ||
assertThat(purchasesConfiguration.store).isEqualTo(Store.AMAZON) | ||
} | ||
|
||
@Test | ||
fun `PurchasesConfiguration sets diagnosticsEnabled correctly`() { | ||
val purchasesConfiguration = builder.diagnosticsEnabled(true).build() | ||
assertThat(purchasesConfiguration.diagnosticsEnabled).isTrue | ||
} | ||
|
||
@Test | ||
fun `PurchasesConfiguration sets informational mode correctly`() { | ||
val purchasesConfiguration = builder.entitlementVerificationMode( | ||
EntitlementVerificationMode.INFORMATIONAL, | ||
).build() | ||
assertThat(purchasesConfiguration.verificationMode).isEqualTo(EntitlementVerificationMode.INFORMATIONAL) | ||
} | ||
|
||
@Test | ||
fun `PurchasesConfiguration sets dangerous settings correctly`() { | ||
// TODO: Add test for custom entitlement computation mode | ||
val dangerousSettings = DangerousSettings(autoSyncPurchases = false) | ||
val purchasesConfiguration = builder.dangerousSettings(dangerousSettings).build() | ||
assertThat(purchasesConfiguration.dangerousSettings).isEqualTo(dangerousSettings) | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...ses/src/testCustomEntitlementComputation/kotlin/com/revenuecat/purchases/PurchasesTest.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,57 @@ | ||
// Purchases | ||
// | ||
// Copyright © 2019 RevenueCat, Inc. All rights reserved. | ||
// | ||
|
||
package com.revenuecat.purchases | ||
|
||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import com.revenuecat.purchases.common.PlatformInfo | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.robolectric.annotation.Config | ||
import java.net.URL | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
@Config(manifest = Config.NONE) | ||
@Suppress("DEPRECATION") | ||
internal class PurchasesTest : BasePurchasesTest() { | ||
|
||
@Test | ||
fun `Setting platform info sets it in the AppConfig when configuring the SDK`() { | ||
val expected = PlatformInfo("flavor", "version") | ||
Purchases.platformInfo = expected | ||
Purchases.configure(PurchasesConfiguration.Builder(mockContext, "api", "appUserId").build()) | ||
assertThat(Purchases.sharedInstance.purchasesOrchestrator.appConfig.platformInfo).isEqualTo(expected) | ||
} | ||
|
||
@Test | ||
fun `Setting proxy URL info sets it in the HttpClient when configuring the SDK`() { | ||
val expected = URL("https://a-proxy.com") | ||
Purchases.proxyURL = expected | ||
Purchases.configure(PurchasesConfiguration.Builder(mockContext, "api", "appUserId").build()) | ||
assertThat(Purchases.sharedInstance.purchasesOrchestrator.appConfig.baseURL).isEqualTo(expected) | ||
} | ||
|
||
@Test | ||
fun `Setting observer mode on sets finish transactions to false`() { | ||
val builder = PurchasesConfiguration.Builder(mockContext, "api", "appUserId").observerMode(true) | ||
Purchases.configure(builder.build()) | ||
assertThat(Purchases.sharedInstance.purchasesOrchestrator.appConfig.finishTransactions).isFalse() | ||
} | ||
|
||
@Test | ||
fun `Setting observer mode off sets finish transactions to true`() { | ||
val builder = PurchasesConfiguration.Builder(mockContext, "api", "appUserId").observerMode(false) | ||
Purchases.configure(builder.build()) | ||
assertThat(Purchases.sharedInstance.purchasesOrchestrator.appConfig.finishTransactions).isTrue() | ||
} | ||
|
||
@Test | ||
fun `Setting store in the configuration sets it on the Purchases instance`() { | ||
val builder = PurchasesConfiguration.Builder(mockContext, "api", "appUserId").store(Store.PLAY_STORE) | ||
Purchases.configure(builder.build()) | ||
assertThat(Purchases.sharedInstance.store).isEqualTo(Store.PLAY_STORE) | ||
} | ||
} |
File renamed without changes.
Oops, something went wrong.