Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ internal object GetCMPDataMock {
domain = "domain",
description = "description",
)
)
),
sdks = listOf()
Comment on lines +91 to +92
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[VALIDATION] Mocks were updated to add sdks = listOf() inside ConsentDisclosureObject and the expected map for "deviceStorage" changed from a list to a map with keys disclosures/sdks. Ensure all test assertions and any other mock consumers are updated to the new structure. Also verify the real SDK's ConsentDisclosureObject constructor supports the new sdks parameter; otherwise tests will not compile.

),
isHidden = false,
)
Expand Down Expand Up @@ -628,17 +629,20 @@ internal object GetCMPDataMock {
"isDeactivated" to false,
"disableLegalBasis" to false,
"technologyUsed" to listOf("Cookies", "Pixel Tags"),
"deviceStorage" to listOf(
mapOf(
"identifier" to "identifier",
"type" to 2,
"name" to "name",
"maxAgeSeconds" to 123123L,
"cookieRefresh" to true,
"purposes" to listOf(1, 2, 3),
"domain" to "domain",
"description" to "description",
)
"deviceStorage" to mapOf(
"disclosures" to listOf(
mapOf(
"identifier" to "identifier",
"type" to 2,
"name" to "name",
"maxAgeSeconds" to 123123L,
"cookieRefresh" to true,
"purposes" to listOf(1, 2, 3),
"domain" to "domain",
"description" to "description",
)
),
"sdks" to emptyList<Map<String, Any>>()
),
Comment on lines +632 to 646
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[REFACTORING] In the expected map you changed "deviceStorage" from a list of maps to a single map with keys "disclosures" and "sdks". Confirm the code that consumes this expected map (test verification code) is updated accordingly. If many tests expect the old list shape, consider adding a small migration helper in tests to transform the new object into the older shape for backward-compatible assertions while the rest of the codebase is updated.

"isHidden" to false,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@ package com.usercentrics.reactnative.extensions

import com.usercentrics.sdk.v2.settings.data.ConsentDisclosure
import com.usercentrics.sdk.v2.settings.data.ConsentDisclosureObject
import com.usercentrics.sdk.v2.settings.data.ConsentDisclosureSDK

internal fun ConsentDisclosureObject?.serialize(): Any? {
if (this == null) {
return null
}
return disclosures.map { it.serialize() }
return mapOf(
"disclosures" to disclosures.map { it.serialize() },
"sdks" to sdks.map { it.serialize() }
)
}

private fun ConsentDisclosureSDK.serialize(): Map<String, Any> {
return mapOf(
"name" to name,
"use" to use
)
Comment on lines +11 to +21
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[VALIDATION] serialize() now serializes sdks unguarded: sdks.map { it.serialize() }. If ConsentDisclosureObject.sdks can be null, this will throw an NPE. Make this null-safe and preserve an empty list if absent: "sdks" to (sdks?.map { it.serialize() } ?: emptyList()). Also consider whether the nested structures need conversion to WritableMap at this level or are handled by the caller.

import com.usercentrics.sdk.v2.settings.data.ConsentDisclosure
import com.usercentrics.sdk.v2.settings.data.ConsentDisclosureObject
import com.usercentrics.sdk.v2.settings.data.ConsentDisclosureSDK

internal fun ConsentDisclosureObject?.serialize(): Any? {
    if (this == null) return null

    return mapOf(
        "disclosures" to disclosures.map { it.serialize() },
        "sdks" to (sdks?.map { it.serialize() } ?: emptyList())
    )
}

private fun ConsentDisclosureSDK.serialize(): Map<String, Any> {
    return mapOf(
        "name" to name,
        "use" to use
    )
}

}

internal fun ConsentDisclosure.serialize(): Any {
Expand Down
2 changes: 1 addition & 1 deletion example/ios/exampleTests/Mock/CMPData+Mock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ extension SecondLayer {
extension ConsentDisclosureObject {

static func mock() -> ConsentDisclosureObject {
return .init(disclosures: [.mock()])
return .init(disclosures: [.mock()], sdks: [])
}
}

Expand Down
5 changes: 4 additions & 1 deletion ios/Extensions/UsercentricsCMPData+Dict.swift
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,10 @@ extension UsercentricsService {

extension ConsentDisclosureObject {
func toDictionary() -> Any {
return self.disclosures.map { $0.toDictionary() }
return [
"disclosures": self.disclosures.map { $0.toDictionary() },
"sdks": self.sdks.map { ["name": $0.name, "use": $0.use] }
]
Comment on lines +367 to +370
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[CRITICAL_BUG] You changed ConsentDisclosureObject.toDictionary() from returning an array of disclosures to returning a Dictionary with keys "disclosures" and "sdks". This is a breaking shape change for any consumers that previously expected an array. Either: 1) Ensure all call sites / JS/native bridge logic were updated to expect an object with keys {disclosures, sdks}; or 2) keep backward compatible shape (e.g. return the array for old callers and add a separate field or version). Additionally guard sdks for nil to avoid crashes: "sdks": self.sdks?.map { ["name": $0.name, "use": $0.use] } ?? []

extension ConsentDisclosureObject {
    func toDictionary() -> Any {
        return [
            "disclosures": self.disclosures.map { $0.toDictionary() },
            "sdks": (self.sdks ?? []).map { [
                "name": $0.name as Any,
                "use": $0.use as Any
            ]]
        ]
    }
}

}
}

Expand Down
2 changes: 1 addition & 1 deletion sample/ios/sampleTests/Mock/CMPData+Mock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ extension SecondLayer {
extension ConsentDisclosureObject {

static func mock() -> ConsentDisclosureObject {
return .init(disclosures: [.mock()])
return .init(disclosures: [.mock()], sdks: [])
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/__tests__/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ const disclosure: ConsentDisclosure = {
}

const consentDisclosureObject: ConsentDisclosureObject = {
disclosures: [disclosure]
disclosures: [disclosure],
sdks: [],
}
Comment on lines +271 to 273
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[REFACTORING] You added sdks: [] to the test ConsentDisclosureObject fixture. After fixing the model types (see src/models/ConsentDisclosureObject.tsx), update this fixture's typing (if typings are enforced) to match ConsentDisclosureSDK[] and, if useful, add a minimal SDK entry to exercise serialization paths in tests (e.g. { name: 'sdkName', use: 'purpose' }).

const consentDisclosureObject: ConsentDisclosureObject = {
    disclosures: [disclosure],
    sdks: [
        {
            name: "sdkName",
            use: "purpose",
        },
    ],
}


const ucService: UsercentricsService = {
Expand Down
14 changes: 13 additions & 1 deletion src/models/ConsentDisclosureObject.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
export class ConsentDisclosureSDK {
name: string
use: string

constructor(name: string, use: string) {
this.name = name
this.use = use
}
}

export class ConsentDisclosureObject {

disclosures: [ConsentDisclosure]
sdks: ConsentDisclosureSDK[]

constructor(disclosures: [ConsentDisclosure]) {
constructor(disclosures: [ConsentDisclosure], sdks?: ConsentDisclosureSDK[]) {
this.disclosures = disclosures
this.sdks = sdks ?? []
}
Comment on lines 11 to 19

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

1. Ts sdks typed as tuple 🐞 Bug ✓ Correctness

ConsentDisclosureObject.sdks is typed as a 1-element tuple ([ConsentDisclosureSDK]) even though the
native payload is a variable-length list (including empty). This makes the published TypeScript API
incorrect and can break consumers that have 0 or multiple SDK entries.
Agent Prompt
### Issue description
`ConsentDisclosureObject.sdks` is declared as a tuple type (`[ConsentDisclosureSDK]`), but native returns a variable-length array (including empty). This makes the TS API contract incorrect.

### Issue Context
Android/iOS both serialize `sdks` via `.map { ... }` and Android test mocks include an empty `sdks` list.

### Fix Focus Areas
- src/models/ConsentDisclosureObject.tsx[11-19]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

}

Expand Down
Loading