-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
77 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { onConsentChange } from './onConsentChange'; | ||
import type { Callback, ConsentState } from './types'; | ||
import type { TCFv2ConsentState } from './types/tcfv2'; | ||
import {hasConsentForUseCase} from './cmpStorage'; | ||
|
||
jest.mock('./onConsentChange'); | ||
|
||
const tcfv2ConsentState: TCFv2ConsentState = { | ||
consents: { 1: true }, | ||
eventStatus: 'tcloaded', | ||
vendorConsents: { | ||
['5efefe25b8e05c06542b2a77']: true, | ||
}, | ||
addtlConsent: 'xyz', | ||
gdprApplies: true, | ||
tcString: 'YAAA', | ||
}; | ||
|
||
const tcfv2ConsentStateNoConsent: TCFv2ConsentState = { | ||
consents: { 1: false }, | ||
eventStatus: 'tcloaded', | ||
vendorConsents: {}, | ||
addtlConsent: 'xyz', | ||
gdprApplies: true, | ||
tcString: 'YAAA', | ||
}; | ||
|
||
const mockOnConsentChange = (consentState: ConsentState) => | ||
(onConsentChange as jest.Mock).mockImplementation((cb: Callback) => | ||
cb(consentState), | ||
); | ||
|
||
describe('cmpStorage.hasConsentForUseCase returns the expected consent', () => { | ||
test('Targeted advertising when canTarget is true', async () => { | ||
const consentState: ConsentState = { | ||
tcfv2: tcfv2ConsentState, | ||
canTarget: true, | ||
framework: 'tcfv2', | ||
}; | ||
mockOnConsentChange(consentState); | ||
const hasConsent = await hasConsentForUseCase('Targeted advertising'); | ||
expect(hasConsent).toEqual(true); | ||
}); | ||
test('Targeted advertising when canTarget is false', async () => { | ||
const consentState: ConsentState = { | ||
tcfv2: tcfv2ConsentState, | ||
canTarget: false, | ||
framework: 'tcfv2', | ||
}; | ||
mockOnConsentChange(consentState); | ||
const hasConsent = await hasConsentForUseCase('Targeted advertising'); | ||
expect(hasConsent).toEqual(false); | ||
}); | ||
test('Targeted advertising when canTarget is true', async () => { | ||
const consentState: ConsentState = { | ||
tcfv2: tcfv2ConsentState, | ||
canTarget: true, | ||
framework: 'tcfv2', | ||
}; | ||
mockOnConsentChange(consentState); | ||
const hasConsent = await hasConsentForUseCase('Targeted advertising'); | ||
expect(hasConsent).toEqual(true); | ||
}); | ||
test('Essential when no consents', async () => { | ||
const consentState: ConsentState = { | ||
tcfv2: tcfv2ConsentStateNoConsent, | ||
canTarget: false, | ||
framework: 'tcfv2', | ||
}; | ||
mockOnConsentChange(consentState); | ||
const hasConsent = await hasConsentForUseCase('Essential'); | ||
expect(hasConsent).toEqual(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f9c03f6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverage report
Test suite run success
332 tests passing in 17 suites.
Report generated by 🧪jest coverage report action from f9c03f6