Skip to content

Commit

Permalink
Merge pull request #505 from qonversion/major6
Browse files Browse the repository at this point in the history
New get and send properties requests (#504)
  • Loading branch information
SpertsyanKM authored Aug 2, 2023
2 parents 9d00e21 + 4419182 commit 3f5d05e
Show file tree
Hide file tree
Showing 37 changed files with 381 additions and 147 deletions.
6 changes: 3 additions & 3 deletions app/src/main/java/com/qonversion/android/app/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import com.qonversion.android.sdk.dto.QEnvironment;
import com.qonversion.android.sdk.dto.QLaunchMode;
import com.qonversion.android.sdk.dto.QAttributionProvider;
import com.qonversion.android.sdk.dto.QUserProperty;
import com.qonversion.android.sdk.dto.properties.QUserPropertyKey;

import java.util.Map;

Expand Down Expand Up @@ -42,8 +42,8 @@ public void onCreate() {

@Override
public void onConversionDataSuccess(final Map<String, Object> conversionData) {
Qonversion.getSharedInstance().setProperty(
QUserProperty.AppsFlyerUserId,
Qonversion.getSharedInstance().setUserProperty(
QUserPropertyKey.AppsFlyerUserId,
AppsFlyerLib.getInstance().getAppsFlyerUID(App.this)
);
Qonversion.getSharedInstance().attribution(conversionData, QAttributionProvider.AppsFlyer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.qonversion.android.sdk.dto.QEntitlement
import com.qonversion.android.sdk.dto.entitlements.QEntitlement
import com.qonversion.android.app.databinding.TableRowEntitlementBinding

class EntitlementsAdapter(private val entitlements: List<QEntitlement>) :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import com.qonversion.android.app.databinding.FragmentEntitlementsBinding
import com.qonversion.android.sdk.Qonversion
import com.qonversion.android.sdk.dto.QEntitlement
import com.qonversion.android.sdk.dto.entitlements.QEntitlement
import com.qonversion.android.sdk.dto.QonversionError
import com.qonversion.android.sdk.listeners.QonversionEntitlementsCallback

Expand Down
4 changes: 1 addition & 3 deletions app/src/main/java/com/qonversion/android/app/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ import com.qonversion.android.sdk.automations.dto.QActionResult
import com.qonversion.android.sdk.automations.dto.QActionResultType
import com.qonversion.android.sdk.automations.dto.QScreenPresentationConfig
import com.qonversion.android.sdk.automations.dto.QScreenPresentationStyle
import com.qonversion.android.sdk.dto.QEntitlement
import com.qonversion.android.sdk.dto.QRemoteConfig
import com.qonversion.android.sdk.dto.entitlements.QEntitlement
import com.qonversion.android.sdk.dto.QonversionError
import com.qonversion.android.sdk.dto.products.QProduct
import com.qonversion.android.sdk.listeners.QEntitlementsUpdateListener
import com.qonversion.android.sdk.listeners.QonversionEntitlementsCallback
import com.qonversion.android.sdk.listeners.QonversionProductsCallback
import com.qonversion.android.sdk.listeners.QonversionRemoteConfigCallback

private const val TAG = "HomeFragment"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import com.qonversion.android.sdk.Qonversion
import com.qonversion.android.sdk.dto.QonversionError
import com.qonversion.android.sdk.listeners.QonversionOfferingsCallback
import com.qonversion.android.sdk.listeners.QonversionEntitlementsCallback
import com.qonversion.android.sdk.dto.QEntitlement
import com.qonversion.android.sdk.dto.entitlements.QEntitlement
import com.qonversion.android.sdk.dto.offerings.QOfferings
import com.qonversion.android.sdk.dto.products.QProduct

Expand Down
28 changes: 10 additions & 18 deletions config/detekt/baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
<ID>FinalNewline:com.qonversion.android.sdk.internal.requests.EnvironmentRequestTest.kt:1</ID>
<ID>FinalNewline:com.qonversion.android.sdk.internal.requests.InitRequestTest.kt:1</ID>
<ID>FinalNewline:com.qonversion.android.sdk.internal.requests.OsRequestTest.kt:1</ID>
<ID>FinalNewline:com.qonversion.android.sdk.internal.requests.PropertiesRequestTest.kt:1</ID>
<ID>FinalNewline:com.qonversion.android.sdk.internal.requests.ProviderDataRequestTest.kt:1</ID>
<ID>FinalNewline:com.qonversion.android.sdk.internal.requests.queue.RequestQueueTest.kt:1</ID>
<ID>FinalNewline:com.qonversion.android.sdk.internal.requests.queue.util.kt:1</ID>
Expand All @@ -51,7 +50,6 @@
<ID>ForbiddenComment:AttributionRequestTest.kt$AttributionRequestTest$// TODO: Update test for new AttributionRequest format</ID>
<ID>ForbiddenComment:EnvironmentRequestTest.kt$EnvironmentRequestTest$// TODO: Update test for new Environment format</ID>
<ID>ForbiddenComment:InitRequestTest.kt$InitRequestTest$// TODO: Update test for new InitRequest format</ID>
<ID>ForbiddenComment:PropertiesRequestTest.kt$PropertiesRequestTest$// TODO: Update test for new PropertiesRequest format</ID>
<ID>ForbiddenComment:RequestQueueTest.kt$RequestQueueTest$// TODO: Update test for new AttributionRequest format</ID>
<ID>ForbiddenComment:RequestValidatorTest.kt$RequestValidatorTest$// TODO: Update test for new AttributionRequest format</ID>
<ID>ForbiddenComment:util.kt$Util.Companion$// TODO: Update test for new AttributionRequest format</ID>
Expand Down Expand Up @@ -193,18 +191,18 @@
<ID>MaximumLineLength:com.qonversion.android.sdk.automations.mvp.ScreenPresenterTest.kt:159</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.OutagerIntegrationTest.kt:112</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.OutagerIntegrationTest.kt:230</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.OutagerIntegrationTest.kt:360</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.OutagerIntegrationTest.kt:419</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.OutagerIntegrationTest.kt:381</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.OutagerIntegrationTest.kt:440</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.OutagerIntegrationTest.kt:88</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.QProductCenterManagerTest.kt:159</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.QProductCenterManagerTest.kt:161</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.QUserPropertiesManagerTest.kt:172</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.QUserPropertiesManagerTest.kt:174</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.QonversionRepositoryIntegrationTest.kt:115</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.QonversionRepositoryIntegrationTest.kt:323</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.QonversionRepositoryIntegrationTest.kt:386</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.QonversionRepositoryIntegrationTest.kt:656</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.QonversionRepositoryIntegrationTest.kt:877</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.QonversionRepositoryIntegrationTest.kt:717</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.QonversionRepositoryIntegrationTest.kt:91</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.QonversionRepositoryIntegrationTest.kt:938</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.api.ApiErrorMapper.kt:117</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.api.ApiErrorMapper.kt:118</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.billing.QonversionBillingService.kt:109</ID>
Expand All @@ -231,8 +229,8 @@
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.storage.SharedPreferencesCacheTest.kt:224</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.storage.SharedPreferencesCacheTest.kt:225</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.storage.TokenExtractorTest.kt:19</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.storage.util.kt:134</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.storage.util.kt:135</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.storage.util.kt:136</ID>
<ID>NestedBlockDepth:ApiErrorMapper.kt$ApiErrorMapper$fun &lt;T&gt; getErrorFromResponse(value: Response&lt;T&gt;): QonversionError</ID>
<ID>NewLineAtEndOfFile:ApiHelperTest.kt$com.qonversion.android.sdk.internal.api.ApiHelperTest.kt</ID>
<ID>NewLineAtEndOfFile:AppRequestTest.kt$com.qonversion.android.sdk.internal.requests.AppRequestTest.kt</ID>
Expand All @@ -245,7 +243,6 @@
<ID>NewLineAtEndOfFile:InitRequestTest.kt$com.qonversion.android.sdk.internal.requests.InitRequestTest.kt</ID>
<ID>NewLineAtEndOfFile:InternalConfigTest.kt$com.qonversion.android.sdk.internal.InternalConfigTest.kt</ID>
<ID>NewLineAtEndOfFile:OsRequestTest.kt$com.qonversion.android.sdk.internal.requests.OsRequestTest.kt</ID>
<ID>NewLineAtEndOfFile:PropertiesRequestTest.kt$com.qonversion.android.sdk.internal.requests.PropertiesRequestTest.kt</ID>
<ID>NewLineAtEndOfFile:ProviderDataRequestTest.kt$com.qonversion.android.sdk.internal.requests.ProviderDataRequestTest.kt</ID>
<ID>NewLineAtEndOfFile:PurchasesCacheTest.kt$com.qonversion.android.sdk.internal.storage.PurchasesCacheTest.kt</ID>
<ID>NewLineAtEndOfFile:QAutomationsManagerTest.kt$com.qonversion.android.sdk.automations.internal.QAutomationsManagerTest.kt</ID>
Expand Down Expand Up @@ -276,7 +273,6 @@
<ID>NoConsecutiveBlankLines:com.qonversion.android.sdk.internal.storage.TokenStorageTest.kt:124</ID>
<ID>NoConsecutiveBlankLines:com.qonversion.android.sdk.internal.storage.TokenStorageTest.kt:63</ID>
<ID>NoConsecutiveBlankLines:com.qonversion.android.sdk.internal.validator.RequestValidatorTest.kt:3</ID>
<ID>NoUnusedImports:com.qonversion.android.sdk.internal.storage.util.kt:4</ID>
<ID>NoWildcardImports:com.qonversion.android.sdk.automations.internal.AutomationsEventMapperTest.kt:12</ID>
<ID>NoWildcardImports:com.qonversion.android.sdk.automations.internal.AutomationsEventMapperTest.kt:6</ID>
<ID>NoWildcardImports:com.qonversion.android.sdk.automations.internal.QAutomationsManagerTest.kt:23</ID>
Expand All @@ -299,9 +295,8 @@
<ID>NoWildcardImports:com.qonversion.android.sdk.internal.QProductCenterManagerTest.kt:21</ID>
<ID>NoWildcardImports:com.qonversion.android.sdk.internal.QProductCenterManagerTest.kt:29</ID>
<ID>NoWildcardImports:com.qonversion.android.sdk.internal.QProductCenterManagerTest.kt:9</ID>
<ID>NoWildcardImports:com.qonversion.android.sdk.internal.QUserPropertiesManagerTest.kt:15</ID>
<ID>NoWildcardImports:com.qonversion.android.sdk.internal.QUserPropertiesManagerTest.kt:16</ID>
<ID>NoWildcardImports:com.qonversion.android.sdk.internal.api.ApiHeadersProvider.kt:8</ID>
<ID>NoWildcardImports:com.qonversion.android.sdk.internal.QUserPropertiesManagerTest.kt:17</ID>
<ID>NoWildcardImports:com.qonversion.android.sdk.internal.QUserPropertiesManagerTest.kt:18</ID>
<ID>NoWildcardImports:com.qonversion.android.sdk.internal.billing.BillingService.kt:6</ID>
<ID>NoWildcardImports:com.qonversion.android.sdk.internal.billing.QonversionBillingService.kt:6</ID>
<ID>NoWildcardImports:com.qonversion.android.sdk.internal.billing.QonversionBillingServiceTest.kt:5</ID>
Expand All @@ -318,8 +313,7 @@
<ID>NoWildcardImports:com.qonversion.android.sdk.internal.storage.LaunchResultCacheWrapperTest.kt:7</ID>
<ID>NoWildcardImports:com.qonversion.android.sdk.internal.storage.PurchasesCacheTest.kt:8</ID>
<ID>NoWildcardImports:com.qonversion.android.sdk.internal.storage.SharedPreferencesCacheTest.kt:5</ID>
<ID>NoWildcardImports:com.qonversion.android.sdk.internal.storage.util.kt:28</ID>
<ID>NoWildcardImports:com.qonversion.android.sdk.internal.storage.util.kt:3</ID>
<ID>NoWildcardImports:com.qonversion.android.sdk.internal.storage.util.kt:27</ID>
<ID>NoWildcardImports:com.qonversion.android.sdk.utils.kt:4</ID>
<ID>ReturnCount:AutomationsEventMapper.kt$AutomationsEventMapper$fun getEventFromRemoteMessage(messageData: Map&lt;String, String&gt;): AutomationsEvent?</ID>
<ID>ReturnCount:ExceptionHandler.kt$ExceptionHandler$private fun isQonversionException(exception: Throwable): Boolean</ID>
Expand All @@ -341,9 +335,7 @@
<ID>SpacingAroundCurly:com.qonversion.android.sdk.internal.converter.GooglePurchaseConverterTest.kt:145</ID>
<ID>SpacingAroundCurly:com.qonversion.android.sdk.internal.converter.GooglePurchaseConverterTest.kt:297</ID>
<ID>SpacingAroundCurly:com.qonversion.android.sdk.internal.converter.GooglePurchaseConverterTest.kt:303</ID>
<ID>SpacingAroundCurly:com.qonversion.android.sdk.internal.requests.PropertiesRequestTest.kt:13</ID>
<ID>SpacingAroundCurly:com.qonversion.android.sdk.internal.requests.PropertiesRequestTest.kt:19</ID>
<ID>SpacingAroundParens:com.qonversion.android.sdk.internal.QUserPropertiesManagerTest.kt:489</ID>
<ID>SpacingAroundParens:com.qonversion.android.sdk.internal.QUserPropertiesManagerTest.kt:496</ID>
<ID>SpacingAroundParens:com.qonversion.android.sdk.internal.converter.GooglePurchaseConverterTest.kt:207</ID>
<ID>SpacingAroundParens:com.qonversion.android.sdk.internal.converter.GooglePurchaseConverterTest.kt:308</ID>
<ID>SpacingAroundParens:com.qonversion.android.sdk.internal.storage.SharedPreferencesCacheTest.kt:212</ID>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.common.collect.Maps
import com.qonversion.android.sdk.QonversionConfig
import com.qonversion.android.sdk.dto.QAttributionProvider
import com.qonversion.android.sdk.dto.QEntitlementSource
import com.qonversion.android.sdk.dto.entitlements.QEntitlementSource
import com.qonversion.android.sdk.dto.QLaunchMode
import com.qonversion.android.sdk.dto.QUserProperty
import com.qonversion.android.sdk.dto.properties.QUserPropertyKey
import com.qonversion.android.sdk.dto.QonversionError
import com.qonversion.android.sdk.dto.QonversionErrorCode
import com.qonversion.android.sdk.dto.eligibility.QEligibility
Expand Down Expand Up @@ -321,7 +321,7 @@ internal class OutagerIntegrationTest {
val signal = CountDownLatch(1)
val testProperties = mapOf(
"customProperty" to "custom property value",
QUserProperty.CustomUserId.userPropertyCode to "custom user id"
QUserPropertyKey.CustomUserId.userPropertyCode to "custom user id"
)

val uid = UID_PREFIX + "_sendProperties"
Expand All @@ -343,6 +343,27 @@ internal class OutagerIntegrationTest {
signal.await()
}

@Test
fun getProperties() {
// given
val signal = CountDownLatch(1)

val uid = UID_PREFIX + "_sendProperties"
val repository = initRepository(uid)

// when and then
repository.getProperties(
{ fail("Shouldn't succeed") },
{ error ->
assertEquals(error.code, QonversionErrorCode.BackendError)
assertTrue("HTTP status code=503, error=Service Unavailable. " == error.additionalMessage)
signal.countDown()
}
)

signal.await()
}

@Test
fun eligibilityForProductIds() {
// given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.common.collect.Maps
import com.qonversion.android.sdk.QonversionConfig
import com.qonversion.android.sdk.dto.QAttributionProvider
import com.qonversion.android.sdk.dto.QEntitlementSource
import com.qonversion.android.sdk.dto.entitlements.QEntitlementSource
import com.qonversion.android.sdk.dto.QLaunchMode
import com.qonversion.android.sdk.dto.QUserProperty
import com.qonversion.android.sdk.dto.properties.QUserPropertyKey
import com.qonversion.android.sdk.dto.QonversionError
import com.qonversion.android.sdk.dto.QonversionErrorCode
import com.qonversion.android.sdk.dto.eligibility.QEligibility
Expand All @@ -20,6 +20,7 @@ import com.qonversion.android.sdk.dto.offerings.QOfferings
import com.qonversion.android.sdk.dto.products.QProduct
import com.qonversion.android.sdk.dto.products.QProductDuration
import com.qonversion.android.sdk.dto.products.QProductType
import com.qonversion.android.sdk.dto.properties.QUserProperty
import com.qonversion.android.sdk.internal.di.QDependencyInjector
import com.qonversion.android.sdk.internal.dto.QLaunchResult
import com.qonversion.android.sdk.internal.dto.QPermission
Expand All @@ -31,7 +32,6 @@ import com.qonversion.android.sdk.internal.purchase.Purchase
import com.qonversion.android.sdk.listeners.QonversionEligibilityCallback
import com.qonversion.android.sdk.listeners.QonversionLaunchCallback
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertTrue
import org.junit.Assert.fail
import org.junit.Test
Expand Down Expand Up @@ -473,7 +473,7 @@ internal class QonversionRepositoryIntegrationTest {
val signal = CountDownLatch(1)
val testProperties = mapOf(
"customProperty" to "custom property value",
QUserProperty.CustomUserId.userPropertyCode to "custom user id"
QUserPropertyKey.CustomUserId.userPropertyCode to "custom user id"
)

val uid = UID_PREFIX + "_sendProperties"
Expand Down Expand Up @@ -501,7 +501,7 @@ internal class QonversionRepositoryIntegrationTest {
val signal = CountDownLatch(1)
val testProperties = mapOf(
"customProperty" to "custom property value",
QUserProperty.CustomUserId.userPropertyCode to "custom user id"
QUserPropertyKey.CustomUserId.userPropertyCode to "custom user id"
)

val uid = UID_PREFIX + "_sendProperties"
Expand All @@ -510,10 +510,71 @@ internal class QonversionRepositoryIntegrationTest {
// when and then
repository.sendProperties(
testProperties,
{ fail("Shouldn't fail") },
{ fail("Shouldn't succeed") },
{ error ->
assertNotNull(error)
assertIncorrectProjectKeyError(error!!)
assertAccessDeniedError(error)
signal.countDown()
}
)

signal.await()
}

@Test
fun getProperties() {
// given
val signal = CountDownLatch(1)
val testProperties = mapOf(
"customProperty" to "custom property value",
QUserPropertyKey.CustomUserId.userPropertyCode to "custom user id"
)
val expRes = listOf(
QUserProperty("customProperty", "customProperty"),
QUserProperty(QUserPropertyKey.CustomUserId.userPropertyCode, "custom user id"),
)

val uid = UID_PREFIX + "_getProperties"
val repository = initRepository(uid)

// when and then
withNewUserCreated(repository) { error ->
error?.let {
fail("Failed to create user")
}

repository.sendProperties(
testProperties,
{
repository.getProperties(
{ properties ->
properties.equalsIgnoreOrder(expRes)
signal.countDown()
},
{
fail("Shouldn't fail")
}
)
},
{ fail("Failed to send properties") }
)
}

signal.await()
}

@Test
fun getPropertiesError() {
// given
val signal = CountDownLatch(1)

val uid = UID_PREFIX + "_getProperties"
val repository = initRepository(uid, INCORRECT_PROJECT_KEY)

// when and then
repository.getProperties(
{ fail("Shouldn't succeed") },
{ error ->
assertAccessDeniedError(error)
signal.countDown()
}
)
Expand Down
Loading

0 comments on commit 3f5d05e

Please sign in to comment.