|
1 | 1 | import { type ConsentState } from '@guardian/libs'; |
| 2 | +import { getConsentFor } from '@guardian/libs'; |
2 | 3 | import { isUserInVariant } from '../../../experiments/ab'; |
3 | 4 | import { pubmatic } from '../../__vendor/pubmatic'; |
4 | 5 | import { getAdvertById as getAdvertById_ } from '../../dfp/get-advert-by-id'; |
@@ -36,6 +37,16 @@ jest.mock('experiments/ab', () => ({ |
36 | 37 | isUserInVariant: jest.fn(), |
37 | 38 | })); |
38 | 39 |
|
| 40 | +jest.mock('@guardian/libs', () => ({ |
| 41 | + ...jest.requireActual('@guardian/libs'), |
| 42 | + getConsentFor: jest.fn(), |
| 43 | +})); |
| 44 | + |
| 45 | +const mockGetConsentForID5 = (hasConsent: boolean) => |
| 46 | + (getConsentFor as jest.Mock).mockImplementation((vendor: string) => |
| 47 | + vendor === 'id5' ? hasConsent : undefined, |
| 48 | + ); |
| 49 | + |
39 | 50 | const mockConsentState = { |
40 | 51 | tcfv2: { |
41 | 52 | consents: { '': true }, |
@@ -72,6 +83,8 @@ describe('initialise', () => { |
72 | 83 | jest.fn().mockReturnValue(true), |
73 | 84 | ); |
74 | 85 | jest.mocked(isUserInVariant).mockReturnValue(false); |
| 86 | + |
| 87 | + mockGetConsentForID5(true); |
75 | 88 | prebid.initialise(window, mockConsentState); |
76 | 89 |
|
77 | 90 | expect(window.pbjs?.getConfig()).toEqual({ |
@@ -202,6 +215,39 @@ describe('initialise', () => { |
202 | 215 | }); |
203 | 216 | }); |
204 | 217 |
|
| 218 | + test('should generate correct Prebid config when no consent for ID5', () => { |
| 219 | + jest.mocked(shouldIncludeBidder).mockReturnValue( |
| 220 | + jest.fn().mockReturnValue(true), |
| 221 | + ); |
| 222 | + jest.mocked(isUserInVariant).mockReturnValue(false); |
| 223 | + |
| 224 | + mockGetConsentForID5(false); |
| 225 | + prebid.initialise(window, mockConsentState); |
| 226 | + |
| 227 | + expect(window.pbjs?.getConfig('userSync')).toEqual({ |
| 228 | + syncDelay: 3000, |
| 229 | + syncEnabled: true, |
| 230 | + syncsPerBidder: 0, |
| 231 | + userIds: [ |
| 232 | + { |
| 233 | + name: 'sharedId', |
| 234 | + storage: { |
| 235 | + type: 'cookie', |
| 236 | + name: '_pubcid', |
| 237 | + expires: 365, |
| 238 | + }, |
| 239 | + }, |
| 240 | + ], |
| 241 | + auctionDelay: 500, |
| 242 | + filterSettings: { |
| 243 | + all: { |
| 244 | + bidders: '*', |
| 245 | + filter: 'include', |
| 246 | + }, |
| 247 | + }, |
| 248 | + }); |
| 249 | + }); |
| 250 | + |
205 | 251 | test('should generate correct Prebid config consent management in USNAT', () => { |
206 | 252 | prebid.initialise(window, { ...mockConsentState, framework: 'usnat' }); |
207 | 253 | expect(window.pbjs?.getConfig('consentManagement')).toEqual({ |
|
0 commit comments