-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.js
164 lines (130 loc) · 5.44 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/* eslint-env es6 */
"use strict";
const ava = require("ava");
const parse = require(".");
ava("empty string", (test) => {
const error = test.throws(() => parse());
test.is(error.message, "Invalid transparency and consent string specified");
});
ava("invalid string", (test) => {
const error = test.throws(() => parse("!!!"));
test.is(error.message, "Unable to decode transparency and consent string");
});
ava("unsupported version", (test) => {
const error = test.throws(() => parse("BOwxS1NOwxS1UAAAAAAADAAAAAAuiAAA"));
test.is(error.message, "Unsupported transparency and consent string version “1”");
});
ava.before((test) => {
const emptyConsent = "COwxIfeOwxIfeALAWhDAAcCAAAAAAAAAAAAAAAAAAAAA.IF0EWSQgAYWwho0QUBzBAIYAfJgSCAMgSAAQIoCkFQICERBAEKiAQHAEQJAAAGBAAkACAAQAoHCBMCQABgAARiRCEQECIDRNABIBAggAKYQFAAARmikHC3ZCY702yOmQ.YAAAAAAAAAAAAAAAAAA";
test.context.empty = parse(emptyConsent);
const givenConsent = "COuDmHAOuG5DAALAWhENAfCIAEAAACAAACgAAFgGgAIEAMEABAAQEgAgAJDgAQAFgA.IF1kXyQoGY2lho0QUBzBAIYQfJwSCgMgSAAQIsSkNQIWEBBAGPiAQHAGYJAQAGBAEkACBAQAoHGBMCQABgAgRiRCMQEGIDzNIBIBAggkaI0FACCVmmkHC3ZCY70-6u_-";
test.context.given = parse(givenConsent);
const exampleConsent = "COw4XqLOw4XqLAAAAAENAXCAAAAAAAAAAAAAAAAAAAAA.IFukWSQgAIQwgI0QEByFAAAAeIAACAIgSAAQAIAgEQACEABAAAgAQFAEAIAAAGBAAgAAAAQAIFAAMCQAAgAAQiRAEQAAAAANAAIAAggAIYQFAAARmggBC3ZCYzU2yIA.QFukWSQgAIQwgI0QEByFAAAAeIAACAIgSAAQAIAgEQACEABAAAgAQFAEAIAAAGBAAgAAAAQAIFAAMCQAAgAAQiRAEQAAAAANAAIAAggAIYQFAAARmggBC3ZCYzU2yIA.YAAAAAAAAAAAAAAAAAA";
test.context.example = parse(exampleConsent);
const tcDataConsent = "CPP3iclPP3iclAHABBENB1CsAP_AAH_AAAqIIXNf_X__b3_j-_59f_t0eY1P9_7_v-0zjhfdt-8N2f_X_L8X42M7vF36pq4KuR4Eu3LBIQdlHOHcTUmw6okVrzPsbk2cr7NKJ7PEmnMbO2dYGH9_n93TuZKY7__8___z_v-v_v____f_7-3_3__5_X---_e_V399zLv9____39nN___9v-_98ELgCTDUvIAuxLHBk2jSqFECMKwkOgFABRQDC0RWEDK4KdlcBHrCFgAhNQEYEQIMQUYMAgAEAgCQiICQA8EAiAIgEAAIAVICEABGwCCwAsDAIABQDQsQIoAhAkIMjgqOUwICJFooJ7KwBKDvY0whDLLACgUf0VGAiUIIFgZCQsHMcASAlwskCyAA.f_gAD_gAAAAA";
test.context.tcData = {
tsp: parse(tcDataConsent),
// TcString decoded with __tcfapi('getTCData')
iab: require("./tcData.fixture.json")
};
});
ava("version", (test) => {
test.is(test.context.given.version, 2);
});
ava("created", (test) => {
test.is(test.context.given.created, new Date("2020-01-31T22:00:00.000Z").getTime());
});
ava("last updated", (test) => {
test.is(test.context.given.lastUpdated, new Date("2020-02-01T22:00:00.000Z").getTime());
});
ava("cmp id", (test) => {
test.is(test.context.given.cmpId, 11);
});
ava("cmp version", (test) => {
test.is(test.context.given.cmpVersion, 22);
});
ava("consent screen", (test) => {
test.is(test.context.given.consentScreen, 33);
});
ava("consent language", (test) => {
test.is(test.context.given.consentLanguage, "EN");
});
ava("vendor list version", (test) => {
test.is(test.context.given.vendorListVersion, 31);
});
ava("tcf policy version", (test) => {
test.is(test.context.given.tcfPolicyVersion, 2);
});
ava("is service specific", (test) => {
test.false(test.context.given.isServiceSpecific);
});
ava("use non standard stacks", (test) => {
test.false(test.context.given.useNonStandardStacks);
});
ava("special feature opt ins", (test) => {
test.deepEqual(test.context.empty.specialFeatureOptins, {});
test.deepEqual(test.context.given.specialFeatureOptins, {
1: true
});
});
ava("purpose consents", (test) => {
test.deepEqual(test.context.empty.purpose.consents, {});
test.deepEqual(test.context.given.purpose.consents, {
2: true
});
});
ava("purpose legitimate interests", (test) => {
test.deepEqual(test.context.empty.purpose.legitimateInterests, {});
test.deepEqual(test.context.given.purpose.legitimateInterests, {
3: true
});
});
ava("purpose one treatment", (test) => {
test.false(test.context.given.purposeOneTreatment);
});
ava("publisher country code", (test) => {
test.is(test.context.given.publisherCC, "UA");
});
ava("vendor consents", (test) => {
test.deepEqual(test.context.empty.vendor.consents, {});
test.deepEqual(test.context.given.vendor.consents, {
8: true,
9: true,
11: true
});
});
ava("vendor legitimate interests", (test) => {
test.deepEqual(test.context.empty.vendor.legitimateInterests, {});
test.deepEqual(test.context.given.vendor.legitimateInterests, {
4: true
});
});
ava("publisher restrictions", (test) => {
test.deepEqual(test.context.empty.publisher.restrictions, {});
test.deepEqual(Object.keys(test.context.given.publisher.restrictions), ["8", "9", "11"]);
});
ava("disclosed vendors", (test) => {
test.is(Object.keys(test.context.example.outOfBand.disclosedVendors).length, 115);
});
ava("allowed vendors", (test) => {
test.is(Object.keys(test.context.example.outOfBand.allowedVendors).length, 115);
});
ava("tcData structure", (test) => {
for (const key in test.context.tcData.iab) {
// Ignore TCData keys
if (["cmpStatus", "eventStatus", "gdprApplies", "listenerId"].includes(key)) {
continue;
}
const value = test.context.tcData.iab[key];
switch (typeof value) {
case "boolean":
case "number":
case "string":
test.is(value, test.context.tcData.tsp[key]);
break;
default:
test.like(value, test.context.tcData.tsp[key]);
break;
}
}
});