Skip to content

Commit 4722981

Browse files
committed
Setting consents and legitimateInterests values in TCData object for all vendors present on global vendor list
1 parent 14f5672 commit 4722981

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/lib/store.test.js

+13-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { expect, use } from 'chai';
33
import datetime from 'chai-datetime';
44
import Store from './store';
55
import { CmpApi } from "@iabtcf/cmpapi";
6-
import { encodeConsentData } from "./cookie/cookie";
6+
import { encodeConsentData, applyDecodeFix } from "./cookie/cookie";
77
import {GVL, TCModel} from "@iabtcf/core";
88
import {
99
PURPOSE_CONSENTS,
@@ -22,6 +22,10 @@ use(datetime);
2222
describe('store', () => {
2323
let cmpApi;
2424

25+
beforeAll(() => {
26+
applyDecodeFix();
27+
});
28+
2529
beforeEach(() => {
2630
cmpApi = new CmpApi(280, 2);
2731
});
@@ -68,6 +72,7 @@ describe('store', () => {
6872
tcModel.publisherLegitimateInterests.set(PUBLISHER_LEGITIMATE_INTERESTS);
6973
tcModel.specialFeatureOptins.set(SPECIAL_FEATURE_OPT_INS);
7074

75+
const maxVendorId = Math.max(...Object.keys(VENDOR_LIST.vendors));
7176
const encoded = encodeConsentData(tcModel);
7277

7378
const store = new Store({
@@ -81,8 +86,8 @@ describe('store', () => {
8186
// check if consents were applied to current state of tcModel
8287
expect(store.tcModel.purposeConsents.maxId).to.equal(Math.max(...PURPOSE_CONSENTS));
8388
expect(store.tcModel.purposeLegitimateInterests.maxId).to.equal(Math.max(...PURPOSE_LEGITIMATE_INTERESTS));
84-
expect(store.tcModel.vendorConsents.maxId).to.equal(Math.max(...VENDOR_CONSENTS));
85-
expect(store.tcModel.vendorLegitimateInterests.maxId).to.equal(Math.max(...VENDOR_LEGITIMATE_INTERESTS));
89+
expect(store.tcModel.vendorConsents.maxId).to.equal(maxVendorId);
90+
expect(store.tcModel.vendorLegitimateInterests.maxId).to.equal(maxVendorId);
8691
expect(store.tcModel.publisherConsents.maxId).to.equal(Math.max(...PUBLISHER_CONSENTS));
8792
expect(store.tcModel.publisherLegitimateInterests.maxId).to.equal(Math.max(...PUBLISHER_LEGITIMATE_INTERESTS));
8893
expect(store.tcModel.specialFeatureOptins.maxId).to.equal(Math.max(...SPECIAL_FEATURE_OPT_INS));
@@ -140,6 +145,7 @@ describe('store', () => {
140145
tcModel.publisherLegitimateInterests.set(PUBLISHER_LEGITIMATE_INTERESTS);
141146
tcModel.specialFeatureOptins.set(SPECIAL_FEATURE_OPT_INS);
142147

148+
const maxVendorId = Math.max(...Object.keys(VENDOR_LIST.vendors));
143149
const encoded = encodeConsentData(tcModel);
144150

145151
const store = new Store({
@@ -150,8 +156,8 @@ describe('store', () => {
150156
store.setCmpApi(cmpApi);
151157
store.updateVendorList(vendorList);
152158

153-
expect(store.tcModel.vendorConsents.size).to.equal(6);
154-
expect(store.tcModel.vendorConsents.maxId).to.equal(10);
159+
expect(store.tcModel.vendorConsents.size).to.equal(VENDOR_CONSENTS.length);
160+
expect(store.tcModel.vendorConsents.maxId).to.equal(maxVendorId);
155161
expect(store.tcModel.vendorConsents.has(10)).to.be.true;
156162
expect(store.tcModel.vendorLegitimateInterests.has(10)).to.be.false;
157163
done();
@@ -173,6 +179,7 @@ describe('store', () => {
173179
tcModel.publisherLegitimateInterests.set(PUBLISHER_LEGITIMATE_INTERESTS);
174180
tcModel.specialFeatureOptins.set(SPECIAL_FEATURE_OPT_INS);
175181

182+
const maxVendorId = Math.max(...Object.keys(VENDOR_LIST.vendors));
176183
const encoded = encodeConsentData(tcModel);
177184

178185
const store = new Store({
@@ -191,7 +198,7 @@ describe('store', () => {
191198
}
192199
});
193200

194-
expect(vendorsWithoutConsentCount).to.equal(Object.keys(VENDOR_LIST.vendors).length - 2);
201+
expect(vendorsWithoutConsentCount).to.equal(maxVendorId - VENDOR_CONSENTS.length);
195202
expect(persistedConsentData.vendorConsents.has(4)).to.be.true;
196203
expect(persistedConsentData.vendorConsents.has(5)).to.be.false;
197204

test/constants.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const PURPOSE_CONSENTS = [1, 3, 5, 7, 9];
2-
const PURPOSE_LEGITIMATE_INTERESTS = [2, 4, 6, 8];
3-
const VENDOR_CONSENTS = [1, 2, 3, 4, 8, 10];
2+
const PURPOSE_LEGITIMATE_INTERESTS = [2, 4, 6, 8, 10];
3+
const VENDOR_CONSENTS = [1, 2, 3, 4, 8];
44
const VENDOR_LEGITIMATE_INTERESTS = [1, 2, 3, 4];
55
const PUBLISHER_CONSENTS = [2, 4, 6, 8, 10];
66
const PUBLISHER_LEGITIMATE_INTERESTS = [1, 3, 5, 7, 9];

0 commit comments

Comments
 (0)