Skip to content

Commit

Permalink
Replace ccpa with usnat throughout tests
Browse files Browse the repository at this point in the history
  • Loading branch information
akinsola-guardian committed Aug 29, 2024
1 parent b7f6e34 commit 0670f69
Show file tree
Hide file tree
Showing 11 changed files with 239 additions and 134 deletions.
30 changes: 21 additions & 9 deletions src/core/send-commercial-metrics.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ConsentState } from '@guardian/libs';
import type { ConsentState, USNATConsentState } from '@guardian/libs';
import { onConsent } from '@guardian/libs';
import { EventTimer } from './event-timer';
import {
Expand Down Expand Up @@ -103,16 +103,28 @@ const tcfv2AllConsentExceptPurpose8: ConsentState = {
framework: 'tcfv2',
};

const ccpaConsent: ConsentState = {
ccpa: { doNotSell: false, signalStatus: 'ready' },
const usnatNonConsentObject: USNATConsentState = {
doNotSell: true,
signalStatus: 'ready',
};

const usnatConsentObject: USNATConsentState = {
doNotSell: false,
signalStatus: 'ready',
};

const usnatConsent: ConsentState = {
ccpa: usnatConsentObject,
usnat: usnatConsentObject,
canTarget: true,
framework: 'ccpa',
framework: 'usnat',
};

const ccpaNonConsent: ConsentState = {
ccpa: { doNotSell: true, signalStatus: 'ready' },
const usnatNonConsent: ConsentState = {
ccpa: usnatNonConsentObject,
usnat: usnatNonConsentObject,
canTarget: false,
framework: 'ccpa',
framework: 'usnat',
};

const setVisibility = (value: 'hidden' | 'visible'): void => {
Expand Down Expand Up @@ -212,7 +224,7 @@ describe('send commercial metrics', () => {
});

it('sends metrics when non-TCFv2 user (i.e. USA or Australia) consents', async () => {
mockOnConsent(ccpaConsent);
mockOnConsent(usnatConsent);

await initCommercialMetrics({
pageViewId: PAGE_VIEW_ID,
Expand All @@ -231,7 +243,7 @@ describe('send commercial metrics', () => {
});

it('sends metrics when non-TCFv2 user (i.e. USA or Australia) does not consent', async () => {
mockOnConsent(ccpaNonConsent);
mockOnConsent(usnatNonConsent);

await initCommercialMetrics({
pageViewId: PAGE_VIEW_ID,
Expand Down
60 changes: 38 additions & 22 deletions src/core/targeting/build-page-targeting.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import type { ConsentState, TCFv2ConsentState } from '@guardian/libs';
import type {
ConsentState,
TCFv2ConsentState,
USNATConsentState,
} from '@guardian/libs';
import { cmp as cmp_, setCookie, storage } from '@guardian/libs';
import { getAuthStatus as getAuthStatus_ } from 'lib/identity/api';
import type { AuthStatus } from 'lib/identity/api';
Expand Down Expand Up @@ -52,17 +56,29 @@ const mockViewport = (width: number, height: number): void => {
});
};

// CCPA
const ccpaWithConsentMock: ConsentState = {
ccpa: { doNotSell: false, signalStatus: 'ready' },
const usnatConsent: USNATConsentState = {
doNotSell: false,
signalStatus: 'ready',
};

const usnatNonConsent: USNATConsentState = {
doNotSell: true,
signalStatus: 'ready',
};

// USNAT
const usnatWithConsentMock: ConsentState = {
ccpa: usnatConsent,
usnat: usnatConsent,
canTarget: true,
framework: 'ccpa',
framework: 'usnat',
};

const ccpaWithoutConsentMock: ConsentState = {
ccpa: { doNotSell: true, signalStatus: 'ready' },
const usnatWithoutConsentMock: ConsentState = {
ccpa: usnatNonConsent,
usnat: usnatNonConsent,
canTarget: false,
framework: 'ccpa',
framework: 'usnat',
};

// AUS
Expand Down Expand Up @@ -258,15 +274,15 @@ describe('Build Page Targeting', () => {
buildPageTargeting({
adFree: false,
clientSideParticipations: {},
consentState: ccpaWithConsentMock,
consentState: usnatWithConsentMock,
isSignedIn: true,
}).pa,
).toBe('t');
expect(
buildPageTargeting({
adFree: false,
clientSideParticipations: {},
consentState: ccpaWithoutConsentMock,
consentState: usnatWithoutConsentMock,
isSignedIn: true,
}).pa,
).toBe('f');
Expand All @@ -293,15 +309,15 @@ describe('Build Page Targeting', () => {
buildPageTargeting({
adFree: false,
clientSideParticipations: {},
consentState: ccpaWithConsentMock,
consentState: usnatWithConsentMock,
isSignedIn: true,
}).rdp,
).toBe('f');
expect(
buildPageTargeting({
adFree: false,
clientSideParticipations: {},
consentState: ccpaWithoutConsentMock,
consentState: usnatWithoutConsentMock,
isSignedIn: true,
}).rdp,
).toBe('t');
Expand Down Expand Up @@ -598,7 +614,7 @@ describe('Build Page Targeting', () => {
buildPageTargeting({
adFree: false,
clientSideParticipations: {},
consentState: ccpaWithConsentMock,
consentState: usnatWithConsentMock,
isSignedIn: true,
}).permutive,
).toEqual(['1', '2', '3']);
Expand All @@ -612,7 +628,7 @@ describe('Build Page Targeting', () => {
buildPageTargeting({
adFree: false,
clientSideParticipations: {},
consentState: ccpaWithConsentMock,
consentState: usnatWithConsentMock,
isSignedIn: true,
}).fr,
).toEqual('5');
Expand All @@ -624,7 +640,7 @@ describe('Build Page Targeting', () => {
buildPageTargeting({
adFree: false,
clientSideParticipations: {},
consentState: ccpaWithConsentMock,
consentState: usnatWithConsentMock,
isSignedIn: true,
}).fr,
).toEqual('16-19');
Expand All @@ -636,7 +652,7 @@ describe('Build Page Targeting', () => {
buildPageTargeting({
adFree: false,
clientSideParticipations: {},
consentState: ccpaWithConsentMock,
consentState: usnatWithConsentMock,
isSignedIn: true,
}).fr,
).toEqual('30plus');
Expand All @@ -648,7 +664,7 @@ describe('Build Page Targeting', () => {
buildPageTargeting({
adFree: false,
clientSideParticipations: {},
consentState: ccpaWithConsentMock,
consentState: usnatWithConsentMock,
isSignedIn: true,
}).fr,
).toEqual('0');
Expand All @@ -660,7 +676,7 @@ describe('Build Page Targeting', () => {
buildPageTargeting({
adFree: false,
clientSideParticipations: {},
consentState: ccpaWithConsentMock,
consentState: usnatWithConsentMock,
isSignedIn: true,
}).fr,
).toEqual('0');
Expand All @@ -672,7 +688,7 @@ describe('Build Page Targeting', () => {
buildPageTargeting({
adFree: false,
clientSideParticipations: {},
consentState: ccpaWithoutConsentMock,
consentState: usnatWithoutConsentMock,
isSignedIn: true,
}).fr,
).toEqual('0');
Expand Down Expand Up @@ -902,8 +918,8 @@ describe('Build Page Targeting', () => {
});

it.each([
[ccpaWithConsentMock, '9'],
[ccpaWithoutConsentMock, '9'],
[usnatWithConsentMock, '9'],
[usnatWithoutConsentMock, '9'],

[ausWithConsentMock, '9'],
[ausWithoutConsentMock, '9'],
Expand Down Expand Up @@ -1126,7 +1142,7 @@ describe('Build Page Targeting', () => {
buildPageTargeting({
adFree: false,
clientSideParticipations: {},
consentState: ccpaWithConsentMock,
consentState: usnatWithConsentMock,
isSignedIn: true,
}).firstvisit,
).toBeUndefined();
Expand Down
51 changes: 34 additions & 17 deletions src/core/targeting/personalised.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import type { ConsentState } from '@guardian/libs';
import type { ConsentState, USNATConsentState } from '@guardian/libs';
import { storage } from '@guardian/libs';
import type { PersonalisedTargeting } from './personalised';
import { getPersonalisedTargeting } from './personalised';

const FREQUENCY_KEY = 'gu.alreadyVisited';
const AMTGRP_STORAGE_KEY = 'gu.adManagerGroup';

const usnatConsent: USNATConsentState = {
doNotSell: false,
signalStatus: 'ready',
};

const usnatNonConsent: USNATConsentState = {
doNotSell: true,
signalStatus: 'ready',
};

describe('Personalised targeting', () => {
describe('TCFv2', () => {
test('Full consent', () => {
Expand Down Expand Up @@ -72,12 +82,13 @@ describe('Personalised targeting', () => {
});
});

describe('CCPA', () => {
describe('USNAT', () => {
it('Full Consent', () => {
const state: ConsentState = {
ccpa: { doNotSell: false, signalStatus: 'ready' },
ccpa: usnatConsent,
usnat: usnatConsent,
canTarget: true,
framework: 'ccpa',
framework: 'usnat',
};

storage.local.setRaw(FREQUENCY_KEY, '4');
Expand All @@ -97,9 +108,10 @@ describe('Personalised targeting', () => {

it('Do Not Sell', () => {
const state: ConsentState = {
ccpa: { doNotSell: true, signalStatus: 'ready' },
ccpa: usnatNonConsent,
usnat: usnatNonConsent,
canTarget: false,
framework: 'ccpa',
framework: 'usnat',
};

storage.local.setRaw(FREQUENCY_KEY, '4');
Expand Down Expand Up @@ -191,9 +203,10 @@ describe('Personalised targeting', () => {
];
test.each(frequencies)('Should get `%s` for %f', (fr, val) => {
const state: ConsentState = {
ccpa: { doNotSell: false, signalStatus: 'ready' },
ccpa: usnatConsent,
usnat: usnatConsent,
canTarget: true,
framework: 'ccpa',
framework: 'usnat',
};

storage.local.setRaw(FREQUENCY_KEY, String(val));
Expand Down Expand Up @@ -232,9 +245,10 @@ describe('Personalised targeting', () => {

test.each(groups)('Should get `%s` if it exists', (amtgrp, val) => {
const state: ConsentState = {
ccpa: { doNotSell: false, signalStatus: 'ready' },
ccpa: usnatConsent,
usnat: usnatConsent,
canTarget: true,
framework: 'ccpa',
framework: 'usnat',
};

storage.local.remove(AMTGRP_STORAGE_KEY);
Expand Down Expand Up @@ -277,11 +291,12 @@ describe('Personalised targeting', () => {
expect(storage.local.get(AMTGRP_STORAGE_KEY)).toBeNull();
});

test('Ad manager group IS set if ccpa and consent not given', () => {
test('Ad manager group IS set if usnat and consent not given', () => {
const state: ConsentState = {
ccpa: { doNotSell: true, signalStatus: 'ready' },
ccpa: usnatNonConsent,
usnat: usnatNonConsent,
canTarget: false,
framework: 'ccpa',
framework: 'usnat',
};

const targeting = getPersonalisedTargeting({
Expand Down Expand Up @@ -311,9 +326,10 @@ describe('Personalised targeting', () => {

test('Should set `permutive` to correct values if `youtube` is set to false', () => {
const state: ConsentState = {
ccpa: { doNotSell: false, signalStatus: 'ready' },
ccpa: usnatConsent,
usnat: usnatConsent,
canTarget: true,
framework: 'ccpa',
framework: 'usnat',
};

storage.local.setRaw(PERMUTIVE_KEY, '[1, 2, 3]');
Expand All @@ -328,9 +344,10 @@ describe('Personalised targeting', () => {

test('Should set `permutive` to correct values if `youtube` is set to true', () => {
const state: ConsentState = {
ccpa: { doNotSell: false, signalStatus: 'ready' },
ccpa: usnatConsent,
usnat: usnatConsent,
canTarget: true,
framework: 'ccpa',
framework: 'usnat',
};

storage.local.setRaw(PERMUTIVE_KEY, '[]');
Expand Down
Loading

0 comments on commit 0670f69

Please sign in to comment.