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
6 changes: 6 additions & 0 deletions packages/react-native-contentpass-cmp-onetrust/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @contentpass/react-native-contentpass-cmp-onetrust

## 0.3.2

### Patch Changes

- Handle reconsent in OneTrust adapter

## 0.3.1

### Patch Changes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentpass/react-native-contentpass-cmp-onetrust",
"version": "0.3.1",
"version": "0.3.2",
"description": "Contentpass OneTrust CMP adapter",
"source": "./src/index.ts",
"main": "./lib/commonjs/index.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ function createMockSdk(overrides: Partial<OTPublishersNativeSDK> = {}): {
.fn()
.mockResolvedValue(createPreferenceCenterData()),
saveConsent: jest.fn().mockResolvedValue(undefined),
shouldShowBanner: jest.fn().mockResolvedValue(false),
getConsentStatusForCategory: jest.fn().mockResolvedValue(1),
addEventListener: jest.fn(
(eventName: OTEventName, handler: EventHandler) => {
Expand Down Expand Up @@ -112,6 +113,22 @@ describe('createOnetrustCmpAdapter', () => {
});

describe('OnetrustCmpAdapter', () => {
it('should report full consent when all purposes are accepted and no banner is required', async () => {
const { sdk } = createMockSdk();
const adapter = await createOnetrustCmpAdapter(sdk);

await expect(adapter.hasFullConsent()).resolves.toBe(true);
});

it('should report missing consent when OneTrust requires reconsent', async () => {
const { sdk } = createMockSdk({
shouldShowBanner: jest.fn().mockResolvedValue(true),
});
const adapter = await createOnetrustCmpAdapter(sdk);

await expect(adapter.hasFullConsent()).resolves.toBe(false);
});

it('should emit consent status when OneTrust confirms preference-center choices', async () => {
const { sdk, eventHandlers } = createMockSdk({
getConsentStatusForCategory: jest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,20 @@ export default class OnetrustCmpAdapter implements CmpAdapter {
});
}

// FIXME handle reconsent scenarios
hasFullConsent = async (): Promise<boolean> => {
console.debug('[OnetrustCmpAdapter::hasFullConsent]');
const consentStatuses = await Promise.all(
this.groupIds.map((groupId) =>
this.sdk.getConsentStatusForCategory(groupId)
)
);

return consentStatuses.every(
(consentStatus: number) => consentStatus === 1
const [shouldShowBanner, consentStatuses] = await Promise.all([
this.sdk.shouldShowBanner(),
Promise.all(
this.groupIds.map((groupId) =>
this.sdk.getConsentStatusForCategory(groupId)
)
),
]);

return (
!shouldShowBanner &&
consentStatuses.every((consentStatus: number) => consentStatus === 1)
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ declare module 'react-native-onetrust-cmp' {
getBannerData(): Promise<any>;
getPreferenceCenterData(): Promise<any>;
saveConsent(interaction: OTConsentInteraction): Promise<void>;
shouldShowBanner(): Promise<boolean>;
getConsentStatusForCategory(categoryId: string): Promise<number>;
addEventListener(
eventName: OTEventName,
Expand Down
Loading