Skip to content

Commit

Permalink
Merge pull request #8 from SourcePointUSA/DIA-4478_add_ccpa_support
Browse files Browse the repository at this point in the history
DIA-4478 add CCPA support
  • Loading branch information
andresilveirah authored Sep 9, 2024
2 parents 8351ff4 + 07317b5 commit 7f1f58e
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.sourcepoint.mobile_core.models.consents

import com.sourcepoint.mobile_core.utils.StringEnumWithDefaultSerializer
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.JsonObject

@Serializable
data class CCPAConsent(
val uuid: String? = null,
val dateCreated: String? = null,
val expirationDate: String? = null,
val signedLspa: Boolean? = null,
var uspstring: String? = null,
val rejectedVendors: List<String>? = emptyList(),
val rejectedCategories: List<String>? = emptyList(),
val status: CCPAConsentStatus = CCPAConsentStatus.Unknown,
@SerialName("GPPData") val gppData: JsonObject = JsonObject(emptyMap()),
) {
@Serializable(with = CCPAConsentStatus.Serializer::class)
enum class CCPAConsentStatus {
@SerialName("consentedAll") ConsentedAll,
@SerialName("rejectedAll") RejectedAll,
@SerialName("rejectedSome") RejectedSome,
@SerialName("rejectedNone") RejectedNone,
@SerialName("linkedNoAction") LinkedNoAction,
Unknown;
object Serializer: StringEnumWithDefaultSerializer<CCPAConsentStatus>(entries, Unknown)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ data class ConsentStatusRequest(
val hasCsp: Boolean = true
): DefaultRequest() {
@Serializable
data class MetaData(val gdpr: GDPR?, val usnat: USNat?) {
data class MetaData(val gdpr: Campaign?, val usnat: USNatCampaign?, val ccpa: Campaign?) {
@Serializable
data class GDPR(
data class Campaign(
val applies: Boolean,
val dateCreated: String? = null,
val uuid: String? = null,
Expand All @@ -24,7 +24,7 @@ data class ConsentStatusRequest(
)

@Serializable
data class USNat(
data class USNatCampaign(
val applies: Boolean,
val dateCreated: String? = null,
val uuid: String? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.sourcepoint.mobile_core.models.SPIDFAStatus
import com.sourcepoint.mobile_core.models.SPMessageLanguage
import com.sourcepoint.mobile_core.models.SPPropertyName
import com.sourcepoint.mobile_core.models.SPTargetingParams
import com.sourcepoint.mobile_core.models.consents.CCPAConsent
import kotlinx.serialization.Serializable

@Serializable
Expand Down Expand Up @@ -51,11 +52,18 @@ data class MessagesRequest(
val hasLocalData: Boolean,
val consentStatus: ConsentStatus
)

@Serializable
data class CCPA(
val targetingParams: SPTargetingParams?,
val hasLocalData: Boolean,
val consentStatus: CCPAConsent.CCPAConsentStatus
)
}
}

@Serializable
data class MetaData(val gdpr: Campaign?, val usnat: Campaign?) {
data class MetaData(val gdpr: Campaign?, val usnat: Campaign?, val ccpa: Campaign?) {
@Serializable
data class Campaign(val applies: Boolean)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ data class MetaDataRequest(
val metadata: Campaigns
): DefaultRequest() {
@Serializable
data class Campaigns(val gdpr: Campaign? = null, val usnat: Campaign? = null) {
data class Campaigns(
val gdpr: Campaign? = null,
val usnat: Campaign? = null,
val ccpa: Campaign? = null
) {
@Serializable
data class Campaign(val groupPmId: String? = null)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.sourcepoint.mobile_core.network.responses

import com.sourcepoint.mobile_core.models.consents.CCPAConsent
import com.sourcepoint.mobile_core.models.consents.GDPRConsent
import com.sourcepoint.mobile_core.models.consents.USNatConsent
import kotlinx.serialization.Serializable
Expand All @@ -12,6 +13,7 @@ data class ConsentStatusResponse (
@Serializable
data class ConsentStatusData (
val gdpr: GDPRConsent?,
val usnat: USNatConsent?
val usnat: USNatConsent?,
val ccpa: CCPAConsent?
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.sourcepoint.mobile_core.network.responses

import com.sourcepoint.mobile_core.models.consents.ConsentStatus
import com.sourcepoint.mobile_core.models.SPMessageLanguage
import com.sourcepoint.mobile_core.models.consents.CCPAConsent
import com.sourcepoint.mobile_core.models.consents.ConsentStrings
import com.sourcepoint.mobile_core.models.consents.SPGDPRVendorGrants
import com.sourcepoint.mobile_core.models.consents.USNatConsent
Expand Down Expand Up @@ -106,6 +107,15 @@ data class MessagesResponse(
@SerialName("GPPData") val gppData: JsonObject
): Campaign()

@Serializable
@SerialName("CCPA")
data class CCPA(
override val type: String = "CCPA",
val expirationDate: String,
val status: CCPAConsent.CCPAConsentStatus,
@SerialName("GPPData") val gppData: JsonObject
): Campaign()

@Serializable
data class MessageMetaData(
val categoryId: MessageCategory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import kotlinx.serialization.Serializable
@Serializable
data class MetaDataResponse (
val gdpr: MetaDataResponseGDPR?,
val usnat: MetaDataResponseUSNat?
val usnat: MetaDataResponseUSNat?,
val ccpa: MetaDataResponseCCPA?
){
@Serializable
data class MetaDataResponseGDPR (
Expand All @@ -25,4 +26,10 @@ data class MetaDataResponse (
val additionsChangeDate: String,
@SerialName("_id") val vendorListId: String
)

@Serializable
data class MetaDataResponseCCPA (
val applies: Boolean,
val sampleRate: Float
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.sourcepoint.mobile_core.network.requests.ConsentStatusRequest
import com.sourcepoint.mobile_core.network.requests.MetaDataRequest
import com.sourcepoint.mobile_core.models.SPCampaignEnv
import com.sourcepoint.mobile_core.models.SPMessageLanguage
import com.sourcepoint.mobile_core.models.consents.CCPAConsent
import com.sourcepoint.mobile_core.models.consents.ConsentStatus
import com.sourcepoint.mobile_core.network.responses.MessagesResponse
import com.sourcepoint.mobile_core.network.requests.MessagesRequest
Expand All @@ -26,25 +27,31 @@ class SourcepointClientTest {
val response = api.getMetaData(
MetaDataRequest.Campaigns(
gdpr = MetaDataRequest.Campaigns.Campaign(),
usnat = MetaDataRequest.Campaigns.Campaign()
usnat = MetaDataRequest.Campaigns.Campaign(),
ccpa = MetaDataRequest.Campaigns.Campaign()
)
)
assertEquals(response.gdpr?.applies, true)
assertEquals(response.usnat?.applies, true)
assertEquals(response.ccpa?.applies, true)
}

@Test
fun getConsentStatus() = runTest {
val response = api.getConsentStatus(
authId = null,
metadata = ConsentStatusRequest.MetaData(
gdpr = ConsentStatusRequest.MetaData.GDPR(
gdpr = ConsentStatusRequest.MetaData.Campaign(
applies = true,
uuid = "654c39d4-b75d-4aac-925c-6322a7cc1622_28",
),
usnat = ConsentStatusRequest.MetaData.USNat(
usnat = ConsentStatusRequest.MetaData.USNatCampaign(
applies = true,
uuid = "11a0fe1c-bd4a-43bb-b179-c015f63882bc_7",
),
ccpa = ConsentStatusRequest.MetaData.Campaign(
applies = true,
uuid = "ebf53e4d-e0da-4f47-95f0-7e286e8124c3",
)
)
)
Expand All @@ -58,12 +65,17 @@ class SourcepointClientTest {
"11a0fe1c-bd4a-43bb-b179-c015f63882bc_7",
response.consentStatusData.usnat?.uuid
)
assertEquals(
"ebf53e4d-e0da-4f47-95f0-7e286e8124c3",
response.consentStatusData.ccpa?.uuid
)
}

private fun assertCampaignConsents(campaign: MessagesResponse.Campaign) {
when(campaign) {
is MessagesResponse.GDPR -> assertCampaignConsents(campaign)
is MessagesResponse.USNat -> assertCampaignConsents(campaign)
is MessagesResponse.CCPA -> assertCampaignConsents(campaign)
}
}

Expand All @@ -80,6 +92,11 @@ class SourcepointClientTest {
assertTrue(usnat.userConsents.categories.isNotEmpty())
}

private fun assertCampaignConsents(ccpa: MessagesResponse.CCPA) {
assertTrue(ccpa.gppData.isNotEmpty())
assertNotEquals(CCPAConsent.CCPAConsentStatus.Unknown, ccpa.status)
}

@Test
fun getMessages() = runTest {
val response = api.getMessages(
Expand All @@ -105,7 +122,8 @@ class SourcepointClientTest {
),
metadata = MessagesRequest.MetaData(
gdpr = MessagesRequest.MetaData.Campaign(applies = true),
usnat = MessagesRequest.MetaData.Campaign(applies = true)
usnat = MessagesRequest.MetaData.Campaign(applies = true),
ccpa = MessagesRequest.MetaData.Campaign(applies = true)
),
localState = null,
nonKeyedLocalState = null
Expand Down

0 comments on commit 7f1f58e

Please sign in to comment.