Skip to content

Commit

Permalink
Merge pull request #630 from qonversion/fix/sc-34753/e2e
Browse files Browse the repository at this point in the history
Fix e2e tests
  • Loading branch information
SpertsyanKM authored Aug 19, 2024
2 parents b07460d + 9a91e8b commit 4ebec02
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 54 deletions.
14 changes: 7 additions & 7 deletions config/detekt/baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,20 +153,20 @@
<ID>MaximumLineLength:com.qonversion.android.sdk.dto.products.QProduct.kt:120</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.dto.products.QProduct.kt:139</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.dto.products.QProductStoreDetails.kt:130</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.OutagerIntegrationTest.kt:213</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.OutagerIntegrationTest.kt:370</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.OutagerIntegrationTest.kt:429</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.OutagerIntegrationTest.kt:214</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.OutagerIntegrationTest.kt:371</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.OutagerIntegrationTest.kt:430</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.OutagerIntegrationTest.kt:90</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.QProductCenterManager.kt:332</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.QProductCenterManagerTest.kt:152</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.QProductCenterManagerTest.kt:153</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.QRemoteConfigManager.kt:225</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.QUserPropertiesManagerTest.kt:175</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.QonversionRepositoryIntegrationTest.kt:286</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.QonversionRepositoryIntegrationTest.kt:355</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.QonversionRepositoryIntegrationTest.kt:684</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.QonversionRepositoryIntegrationTest.kt:287</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.QonversionRepositoryIntegrationTest.kt:356</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.QonversionRepositoryIntegrationTest.kt:685</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.QonversionRepositoryIntegrationTest.kt:89</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.QonversionRepositoryIntegrationTest.kt:905</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.QonversionRepositoryIntegrationTest.kt:906</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.api.ApiErrorMapper.kt:118</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.api.ApiErrorMapper.kt:119</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.billing.QonversionBillingService.kt:253</ID>
Expand Down
4 changes: 2 additions & 2 deletions sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ dependencies {
androidTestImplementation "org.robolectric:robolectric:4.10.3"

// MockK
testImplementation 'io.mockk:mockk:1.10.0'
androidTestImplementation 'io.mockk:mockk-android:1.10.0'
testImplementation 'io.mockk:mockk:1.11.0'
androidTestImplementation 'io.mockk:mockk-android:1.11.0'

// Mockito
testImplementation 'org.mockito:mockito-core:4.3.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ internal class OutagerIntegrationTest {
originalOrderId = "GPA.3307-0767-0668-99058",
purchaseTime = 1679933171,
purchaseToken = "lgeigljfpmeoddkcebkcepjc.AO-J1Oy305qZj99jXTPEVBN8UZGoYAtjDLj4uTjRQvUFaG0vie-nr6VBlN0qnNDMU8eJR-sI7o3CwQyMOEHKl8eJsoQ86KSFzxKBR07PSpHLI_o7agXhNKY",
contextKeys = null
)

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ internal class QonversionRepositoryIntegrationTest {
originalOrderId = "GPA.3307-0767-0668-99058",
purchaseTime = 1679933171,
purchaseToken = "lgeigljfpmeoddkcebkcepjc.AO-J1Oy305qZj99jXTPEVBN8UZGoYAtjDLj4uTjRQvUFaG0vie-nr6VBlN0qnNDMU8eJR-sI7o3CwQyMOEHKl8eJsoQ86KSFzxKBR07PSpHLI_o7agXhNKY",
contextKeys = null
)

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ internal class QProductCenterManagerTest {

val purchase = mockk<Purchase>(relaxed = true)

every { purchase.productId } returns productId
every { purchase.products } returns listOf(productId)
every { purchase.purchaseToken } returns purchaseToken
every { purchase.purchaseState } returns purchaseState
every { purchase.isAcknowledged } returns isAcknowledged
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ internal class QUserPropertiesManagerTest {
private val fieldRetryDelay = "retryDelay"
private val fieldRetriesCounter = "retriesCounter"
private val fieldIsSendingScheduled = "isSendingScheduled"
private val fieldHandler = "handler"
private val minDelay = 5
private val calculatedDelay = 1
private val properties = mapOf("someKey" to "someValue")
Expand All @@ -54,7 +55,7 @@ internal class QUserPropertiesManagerTest {
mockkConstructor(Handler::class)
mockHandler = Handler(mockLooper)

propertiesManager =
propertiesManager = spyk(
QUserPropertiesManager(
mockContext,
mockRepository,
Expand All @@ -63,6 +64,8 @@ internal class QUserPropertiesManagerTest {
mockAppStateProvider,
mockLogger
)
)
propertiesManager.mockPrivateField(fieldHandler, mockHandler)
}

@Test
Expand Down Expand Up @@ -340,69 +343,39 @@ internal class QUserPropertiesManagerTest {
@Test
fun `should set and not send user property when sending properties is scheduled`() {
// given
val handlerDelay = (minDelay * 1000).toLong()
val key = "email"
val value = "some value"

val spykPropertiesManager = spyk(propertiesManager, recordPrivateCalls = true)
spykPropertiesManager.mockPrivateField(fieldIsSendingScheduled, true)
mockPostDelayed(handlerDelay)
propertiesManager.mockPrivateField(fieldIsSendingScheduled, true)
every { propertiesManager.sendPropertiesWithDelay(any()) } just runs

// when
spykPropertiesManager.setCustomUserProperty(key, value)
propertiesManager.setCustomUserProperty(key, value)

// then
verify {
mockPropertiesStorage.save(key, value)
}
verify(exactly = 0) {
spykPropertiesManager.forceSendProperties()
propertiesManager.sendPropertiesWithDelay(any())
}
}

@Test
fun `should set and send user property when it is not empty and sending is not scheduled on foreground`() {
fun `should set and send user property when it is not empty and sending is not scheduled`() {
// given
val key = "_q_email"
val value = "some value"
val handlerDelay = (minDelay * 1000).toLong()
mockPostDelayed(handlerDelay)
every { mockAppStateProvider.appState } returns AppState.Foreground

every {
propertiesManager.forceSendProperties()
} just Runs
every { propertiesManager.sendPropertiesWithDelay(any()) } just runs

// when
propertiesManager.setCustomUserProperty(key, value)

// then
verifyOrder {
mockPropertiesStorage.save(key, value)
mockHandler.postDelayed(any(), handlerDelay)
propertiesManager.forceSendProperties()
}

val isSendingScheduled = propertiesManager.getPrivateField<Boolean>(fieldIsSendingScheduled)
assertEquals("The field isSendingScheduled is not equal true", true, isSendingScheduled)
}

@Test
fun `should set and not send user property when it is not empty and sending is not scheduled on background`() {
// given
val key = "_q_email"
val value = "some value"
every { mockAppStateProvider.appState } returns AppState.Background

// when
propertiesManager.setCustomUserProperty(key, value)

// then
val isSendingScheduled = propertiesManager.getPrivateField<Boolean>(fieldIsSendingScheduled)
assertEquals("The field isSendingScheduled is not equal false", false, isSendingScheduled)
verify(exactly = 1) {
mockPropertiesStorage.save(key, value)
}
verify(exactly = 0) {
mockHandler.postDelayed(any(), any())
propertiesManager.forceSendProperties()
propertiesManager.sendPropertiesWithDelay(minDelay)
}
}

Expand Down Expand Up @@ -464,9 +437,7 @@ internal class QUserPropertiesManagerTest {
val handlerDelay = (minDelay * 1000).toLong()
mockPostDelayed(handlerDelay)

every {
propertiesManager.forceSendProperties()
} just Runs
every { propertiesManager.forceSendProperties() } just Runs

// when
propertiesManager.sendPropertiesWithDelay(minDelay)
Expand Down

0 comments on commit 4ebec02

Please sign in to comment.