Skip to content

Commit

Permalink
[DIA-3525] Add flag to enable support to uspstring within usnat campaign
Browse files Browse the repository at this point in the history
  • Loading branch information
carmelo-iriti committed Feb 19, 2024
1 parent 29630d4 commit 61d280e
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ fun config(dsl: SpConfigDataBuilder.() -> Unit): SpConfig {
return SpConfigDataBuilder().apply(dsl).build()
}
enum class ConfigOption(option: String) {
TRANSITION_CCPA_AUTH("transitionCCPAAuth")
TRANSITION_CCPA_AUTH("transitionCCPAAuth"),
SUPPORT_LEGACY_USPSTRING("supportLegacyUSPString")
}

infix fun CampaignType.to(config: Set<ConfigOption>): Map<CampaignType, Set<ConfigOption>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ internal data class IncludeDataGppParam(
val optOutOptionMode: String? = null,
@SerialName("MspaServiceProviderMode")
val serviceProviderMode: String? = null,
@SerialName("uspString")
val uspString: Boolean? = null,
)

internal fun IncludeDataGppParam.encodeToString() = JsonConverter.converter.encodeToString(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.sourcepoint.cmplibrary.creation.ConfigOption
import com.sourcepoint.cmplibrary.data.network.model.optimized.includeData.IncludeDataGppParam
import com.sourcepoint.cmplibrary.exception.CampaignType
import com.sourcepoint.cmplibrary.exception.CampaignType.CCPA
import com.sourcepoint.cmplibrary.exception.CampaignType.USNAT
import com.sourcepoint.cmplibrary.model.exposed.SpConfig
import com.sourcepoint.cmplibrary.model.exposed.SpGppConfig
import kotlinx.serialization.json.Json
Expand All @@ -18,16 +19,25 @@ internal fun SpConfig.hasTransitionCCPAAuth() =
?.configParams
?.find { it == ConfigOption.TRANSITION_CCPA_AUTH } != null

internal fun SpGppConfig?.toIncludeDataGppParam(): IncludeDataGppParam = IncludeDataGppParam(
internal fun SpConfig.hasSupportForLegacyUSPString(): IncludeDataGppParam? = campaigns
.find { it.campaignType == USNAT }
?.configParams
?.find { it == ConfigOption.SUPPORT_LEGACY_USPSTRING }
?.let { IncludeDataGppParam(uspString = true) }

internal fun SpGppConfig?.toIncludeDataGppParam(supportLegacyUSPString: Boolean? = null): IncludeDataGppParam = IncludeDataGppParam(
coveredTransaction = this?.coveredTransaction?.type,
optOutOptionMode = this?.optOutOptionMode?.type,
serviceProviderMode = this?.serviceProviderMode?.type,
uspString = supportLegacyUSPString
)

internal fun SpConfig.getGppCustomOption(): JsonElement? = when (isIncluded(CCPA)) {
false -> null
true ->
internal fun SpConfig.getGppCustomOption(): JsonElement? = when {
isIncluded(CCPA) ->
spGppConfig
?.toIncludeDataGppParam()
?.let { Json.encodeToJsonElement(it) }
isIncluded(USNAT) ->
hasSupportForLegacyUSPString()?.let { Json.encodeToJsonElement(it) }
else -> null
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,46 @@
package com.sourcepoint.cmplibrary.creation

import com.sourcepoint.cmplibrary.assertEquals
import com.sourcepoint.cmplibrary.assertFalse
import com.sourcepoint.cmplibrary.assertTrue
import com.sourcepoint.cmplibrary.* //ktlint-disable
import com.sourcepoint.cmplibrary.creation.ConfigOption.SUPPORT_LEGACY_USPSTRING
import com.sourcepoint.cmplibrary.creation.ConfigOption.TRANSITION_CCPA_AUTH
import com.sourcepoint.cmplibrary.exception.CampaignType
import com.sourcepoint.cmplibrary.model.MessageLanguage
import com.sourcepoint.cmplibrary.model.exposed.SpCampaign
import com.sourcepoint.cmplibrary.model.exposed.toTParam
import com.sourcepoint.cmplibrary.util.extensions.hasSupportForLegacyUSPString
import com.sourcepoint.cmplibrary.util.extensions.hasTransitionCCPAAuth
import org.junit.Test

class SpConfigDataBuilderTest {

@Test
fun `GIVEN a USNAT config with support for legacy uspstring VERIFY the spConfig object includes the SUPPORT_LEGACY_USPSTRING config`() {
val spConf = config {
accountId = 22
propertyName = "mobile.multicampaign.demo"
messLanguage = MessageLanguage.ENGLISH
propertyId = 16893
+(CampaignType.GDPR)
+(CampaignType.USNAT to setOf(SUPPORT_LEGACY_USPSTRING))
}

spConf.hasSupportForLegacyUSPString()!!.assertNotNull()
}

@Test
fun `GIVEN a USNAT config without support for legacy uspstring VERIFY the spConfig object does not include the SUPPORT_LEGACY_USPSTRING config`() {
val spConf = config {
accountId = 22
propertyName = "mobile.multicampaign.demo"
messLanguage = MessageLanguage.ENGLISH
propertyId = 16893
+(CampaignType.GDPR)
+(CampaignType.USNAT)
}

spConf.hasSupportForLegacyUSPString().assertNull()
}

@Test
fun `GIVEN a USNAT config with CCPA migration VERIFY the spConfig object has the TRANSITION_CCPA_AUTH config`() {
val spConf = config {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package com.sourcepoint.cmplibrary.util.extensions

import com.sourcepoint.cmplibrary.assertNotNull
import com.sourcepoint.cmplibrary.assertNull
import com.sourcepoint.cmplibrary.creation.ConfigOption
import com.sourcepoint.cmplibrary.exception.CampaignType
import com.sourcepoint.cmplibrary.model.MessageLanguage
import com.sourcepoint.cmplibrary.model.exposed.* //ktlint-disable
import com.sourcepoint.cmplibrary.model.exposed.SpGppOptionBinary.NO
import com.sourcepoint.cmplibrary.model.exposed.SpGppOptionTernary.YES
import kotlinx.serialization.json.jsonObject
import org.junit.Test

class SpConfigExtKtTest {
Expand All @@ -22,10 +24,16 @@ class SpConfigExtKtTest {
)

private val usnatCampaign = SpCampaign(
CampaignType.GDPR,
CampaignType.USNAT,
listOf(TargetingParam("location", "EU"))
)

private val usnatCampaignSupportLegacyUspstring = SpCampaign(
campaignType = CampaignType.USNAT,
targetingParams = emptyList(),
configParams = setOf(ConfigOption.SUPPORT_LEGACY_USPSTRING)
)

private val spConfig = SpConfig(
22,
"carm.uw.con",
Expand Down Expand Up @@ -58,4 +66,21 @@ class SpConfigExtKtTest {
.copy(campaigns = listOf(usnatCampaign), spGppConfig = SpGppConfig(NO, YES, YES))
.getGppCustomOption().assertNull()
}

@Test
fun `GIVEN a usnat with SUPPORT_LEGACY_USPSTRING CHECK that getGppCustomOption return the uspstring element`() {
spConfig
.copy(campaigns = listOf(usnatCampaignSupportLegacyUspstring))
.getGppCustomOption()!!
.jsonObject["uspString"]
.assertNotNull()
}

@Test
fun `GIVEN a usnat without SUPPORT_LEGACY_USPSTRING CHECK that getGppCustomOption DOES NOT RETURN the uspstring element`() {
spConfig
.copy(campaigns = listOf(usnatCampaign))
.getGppCustomOption()
.assertNull()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import com.example.uitestutil.*
import com.sourcepoint.app.v6.TestUseCase.Companion.clickOnRefreshBtnActivity
import com.sourcepoint.app.v6.TestUseCase.Companion.mockModule
import com.sourcepoint.cmplibrary.SpClient
import com.sourcepoint.cmplibrary.creation.ConfigOption
import com.sourcepoint.cmplibrary.creation.config
import com.sourcepoint.cmplibrary.creation.to
import com.sourcepoint.cmplibrary.exception.CampaignType
import com.sourcepoint.cmplibrary.model.MessageLanguage
import com.sourcepoint.cmplibrary.model.exposed.SpCampaign
Expand Down Expand Up @@ -89,7 +91,7 @@ class MainActivityKotlinAuthIdTest {
propertyName = "mobile.multicampaign.demo"
messLanguage = MessageLanguage.ENGLISH
messageTimeout = 5000
+(CampaignType.USNAT)
+(CampaignType.USNAT to setOf(ConfigOption.SUPPORT_LEGACY_USPSTRING))
}

private val spConfNative = config {
Expand Down Expand Up @@ -154,9 +156,17 @@ class MainActivityKotlinAuthIdTest {
wr { clickOnRefreshBtnActivity() }

verify(exactly = 0) { spClient.onError(any()) }
wr { verify(exactly = 3) { spClient.onSpFinished(any()) } }
wr { verify(exactly = 3) { spClient.onConsentReady(any()) } }
wr { verify(exactly = 0) { spClient.onUIReady(any()) } }
wr { verify(exactly = 3) { spClient.onSpFinished( withArg {
it.usNat!!.consent.run {
// Uncomment when DIA-3397 gets live
//gppData["IABUSPrivacy_String"].assertNotNull()
applies.assertTrue()
consentStatus!!.consentedToAll!!.assertTrue()
uuid.assertNotNull()
}
}) } }
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ import com.sourcepoint.app.v6.TestUseCase.Companion.tapToDisableSomeConsent
import com.sourcepoint.app.v6.TestUseCase.Companion.tapToEnableSomeOption
import com.sourcepoint.app.v6.TestUseCase.Companion.tapZustimmenAllOnWebView
import com.sourcepoint.cmplibrary.SpClient
import com.sourcepoint.cmplibrary.creation.ConfigOption
import com.sourcepoint.cmplibrary.creation.config
import com.sourcepoint.cmplibrary.creation.to
import com.sourcepoint.cmplibrary.data.network.model.optimized.GCMStatus
import com.sourcepoint.cmplibrary.exception.CampaignType
import com.sourcepoint.cmplibrary.model.MessageLanguage
Expand Down Expand Up @@ -91,7 +93,7 @@ class MainActivityKotlinTest {
propertyId = 16893
propertyName = "mobile.multicampaign.demo"
messLanguage = MessageLanguage.ENGLISH
+(CampaignType.USNAT)
+(CampaignType.USNAT to setOf(ConfigOption.SUPPORT_LEGACY_USPSTRING))
}

private val spConfGdprNoMessage = config {
Expand Down Expand Up @@ -131,6 +133,35 @@ class MainActivityKotlinTest {
+(CampaignType.GDPR)
}

@Test
fun GIVEN_a_USNAT_campaign_SHOW_message_and_ACCEPT_ALL() = runBlocking<Unit> {
val spClient = mockk<SpClient>(relaxed = true)
loadKoinModules(
mockModule(
spConfig = spConfUsnat,
usnatPmId = "509688",
spClientObserver = listOf(spClient)
)
)

scenario = launchActivity()

wr(backup = { clickOnRefreshBtnActivity() }) { tapAcceptOnWebView() }

verify(exactly = 0) { spClient.onError(any()) }
wr { verify(exactly = 1) { spClient.onSpFinished(any()) } }
verify { spClient.onAction(any(), withArg { it.pubData["pb_key"].assertEquals("pb_value") }) }
wr { verify(exactly = 1) { spClient.onSpFinished( withArg {
it.usNat!!.consent.run {
// Uncomment when DIA-3397 gets live
//gppData["IABUSPrivacy_String"].assertNotNull()
applies.assertTrue()
consentStatus!!.consentedToAll!!.assertTrue()
uuid.assertNotNull()
}
}) } }
}

@Test
fun GIVEN_a_gdpr_campaign_SHOW_message_and_ACCEPT_ALL() = runBlocking<Unit> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,9 @@ class TestUseCase {

fun mockModule(
spConfig: SpConfig,
gdprPmId: String,
gdprPmId: String = "",
ccpaPmId: String = "",
usnatPmId: String = "",
pAuthId: String? = null,
url: String = "",
useGdprGroupPmIfAvailable: Boolean = false,
Expand Down

0 comments on commit 61d280e

Please sign in to comment.