Skip to content

Commit

Permalink
CustomEntitlementsComputation: Prevent posting subscriber attributes …
Browse files Browse the repository at this point in the history
…in post receipt (#1151)

Prevents sending subscriber attributes when posting receipts in custom
entitlements computation mode.
  • Loading branch information
aboedo authored Jul 20, 2023
1 parent 46321d2 commit 6ec7485
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ internal class Backend(
"observer_mode" to observerMode,
"price" to receiptInfo.price,
"currency" to receiptInfo.currency,
"attributes" to subscriberAttributes.takeUnless { it.isEmpty() },
"attributes" to subscriberAttributes.takeUnless { it.isEmpty() || appConfig.customEntitlementComputation },
"normal_duration" to receiptInfo.duration,
"store_user_id" to storeAppUserID,
"pricing_phases" to receiptInfo.pricingPhases?.map { it.toMap() },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class BackendTest {
private val mockAppConfig: AppConfig = mockk<AppConfig>().apply {
every { baseURL } returns mockBaseURL
every { diagnosticsURL } returns mockDiagnosticsBaseURL
every { customEntitlementComputation } returns false
}
private val dispatcher = SyncDispatcher()
private val backendHelper = BackendHelper(API_KEY, dispatcher, mockAppConfig, mockClient)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class SubscriberAttributesPosterTests {
private val mockBaseURL = URL("http://mock-api-test.revenuecat.com/")
private val mockAppConfig = mockk<AppConfig>().apply {
every { baseURL } returns mockBaseURL
every { customEntitlementComputation } returns false
}
private val appUserID = "jerry"
private val dispatcher = SyncDispatcher()
Expand Down Expand Up @@ -316,6 +317,32 @@ class SubscriberAttributesPosterTests {
assertThat(actualPostReceiptBody["attributes"]).isNotNull
}

@Test
fun `posting receipt with attributes skips them in custom entitlements computation mode`() {
every { mockAppConfig.customEntitlementComputation } returns true
mockPostReceiptResponse()

val productInfo = ReceiptInfo(
productIDs = listOf(productID)
)
backend.postReceiptData(
purchaseToken = fetchToken,
appUserID = appUserID,
isRestore = false,
observerMode = false,
subscriberAttributes = mapOfSubscriberAttributes,
receiptInfo = productInfo,
storeAppUserID = null,
onSuccess = expectedOnSuccessPostReceipt,
onError = unexpectedOnErrorPostReceipt
)

assertThat(receivedCustomerInfo).isNotNull
val actualPostReceiptBody = actualPostReceiptBodySlot.captured
assertThat(actualPostReceiptBody).isNotNull
assertThat(actualPostReceiptBody.containsKey("attributes")).isFalse
}

@Test
fun `posting receipt without attributes skips them`() {
mockPostReceiptResponse()
Expand Down

0 comments on commit 6ec7485

Please sign in to comment.