-
Notifications
You must be signed in to change notification settings - Fork 92
/
TCModelFactory.ts
69 lines (46 loc) · 2.48 KB
/
TCModelFactory.ts
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
import {TCModel, GVL} from '@iabtcf/core';
import {makeRandomInt} from './makeRandomInt';
import {makeRandomIntArray} from './makeRandomIntArray';
import {GVLFactory} from './GVLFactory';
export class TCModelFactory {
public static noGVL(): TCModel {
const latestGVL = GVLFactory.getLatest();
const numPurposes = Object.keys(latestGVL.purposes).length;
const numVendors = Object.keys(latestGVL.vendors).length;
const numSpecialFeatures = Object.keys(latestGVL.specialFeatures).length;
const tcModel = new TCModel();
tcModel.cmpId = makeRandomInt(2,100);
tcModel.cmpVersion = makeRandomInt(1,10);
tcModel.consentScreen = makeRandomInt(1,5);
tcModel.isServiceSpecific = !!makeRandomInt(0,1);
tcModel.vendorListVersion = makeRandomInt(1, latestGVL.vendorListVersion);
let counter = 0;
const rand = makeRandomInt(1, TCModel.consentLanguages.size);
TCModel.consentLanguages.forEach((lang: string): void => {
counter ++;
if(counter === rand) {
tcModel.consentLanguage = lang;
}
});
tcModel.publisherCountryCode = String.fromCharCode(makeRandomInt(65, 90)) + String.fromCharCode(makeRandomInt(65, 90));
const now = (new Date()).getTime();
const GDPRMageddon = 1576883249;
tcModel.created = new Date(makeRandomInt(GDPRMageddon, now));
tcModel.lastUpdated = new Date(makeRandomInt(tcModel.created.getTime(), now));
tcModel.publisherConsents.set(makeRandomIntArray(1, numPurposes, makeRandomInt(0, numPurposes)));
tcModel.publisherLegitimateInterest.set(makeRandomIntArray(1, numPurposes, makeRandomInt(0, numPurposes)));
tcModel.purposeConsents.set(makeRandomIntArray(1, numPurposes, makeRandomInt(0, numPurposes)));
tcModel.purposeLegitimateInterest.set(makeRandomIntArray(1, numPurposes, makeRandomInt(0, numPurposes)));
tcModel.vendorConsents.set(makeRandomIntArray(1, numVendors, makeRandomInt(0, numVendors)));
tcModel.vendorLegitimateInterest.set(makeRandomIntArray(1, numVendors, makeRandomInt(0, numVendors)));
tcModel.specialFeatureOptIns.set(makeRandomIntArray(1, numSpecialFeatures, makeRandomInt(0, numSpecialFeatures)));
tcModel.vendorsAllowed.set(makeRandomIntArray(1, numVendors, makeRandomInt(0, numVendors)));
tcModel.vendorsDisclosed.set(makeRandomIntArray(1, numVendors, makeRandomInt(0, numVendors)));
return tcModel;
}
public static withGVL(): TCModel {
const tcModel = this.noGVL();
tcModel.gvl = GVLFactory.getLatest();
return tcModel;
}
}