Skip to content

Commit e262374

Browse files
committed
clean up CookieConsentManager constructor and update tests
1 parent 256166f commit e262374

3 files changed

Lines changed: 9 additions & 13 deletions

File tree

src/cookieConsentManager.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,11 @@ export interface ICookieConsentManager {
3939
* unless explicitly opted out by the user.
4040
*/
4141
export default class CookieConsentManager implements ICookieConsentManager {
42-
private flags: ICookieConsentFlags = {
43-
noFunctional: false,
44-
noTargeting: false,
45-
};
46-
47-
constructor(flags: Partial<ICookieConsentFlags> = {}) {
48-
const { noFunctional, noTargeting } = flags;
49-
this.flags.noFunctional = noFunctional === true;
50-
this.flags.noTargeting = noTargeting === true;
42+
constructor(private flags: ICookieConsentFlags) {
43+
this.flags = {
44+
noFunctional: flags.noFunctional === true,
45+
noTargeting: flags.noTargeting === true,
46+
};
5147
}
5248

5349
/**

test/jest/cookieConsentManager.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import CookieConsentManager from '../../src/cookieConsentManager';
33
describe('CookieConsentManager', () => {
44
describe('#constructor', () => {
55
it('should default flags to false when not provided', () => {
6-
const cookieConsentManager = new CookieConsentManager();
6+
const cookieConsentManager = new CookieConsentManager({ noFunctional: undefined, noTargeting: undefined });
77

88
expect(cookieConsentManager.getNoFunctional()).toBe(false);
99
expect(cookieConsentManager.getNoTargeting()).toBe(false);
@@ -29,15 +29,15 @@ describe('CookieConsentManager', () => {
2929

3030
describe('#getNoFunctional', () => {
3131
it('should return the noFunctional flag value', () => {
32-
const cookieConsentManager = new CookieConsentManager({ noFunctional: true });
32+
const cookieConsentManager = new CookieConsentManager({ noFunctional: true, noTargeting: undefined });
3333

3434
expect(cookieConsentManager.getNoFunctional()).toBe(true);
3535
});
3636
});
3737

3838
describe('#getNoTargeting', () => {
3939
it('should return the noTargeting flag value', () => {
40-
const cookieConsentManager = new CookieConsentManager({ noTargeting: true });
40+
const cookieConsentManager = new CookieConsentManager({ noTargeting: true, noFunctional: undefined });
4141

4242
expect(cookieConsentManager.getNoTargeting()).toBe(true);
4343
});

test/jest/cookieSyncManager.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ describe('CookieSyncManager', () => {
454454
});
455455

456456
it('should allow cookie sync when noTargeting is false by default', () => {
457-
const cookieConsentManager = new CookieConsentManager(); // Defaults to noTargeting: false
457+
const cookieConsentManager = new CookieConsentManager({ noTargeting: undefined, noFunctional: undefined }); // Defaults to noTargeting: false
458458

459459
const mockMPInstance = ({
460460
_Store: {

0 commit comments

Comments
 (0)