@pubtech-ai/testing 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +75 -0
- package/lib/cjs/GVLFactory.cjs +18 -0
- package/lib/cjs/GVLFactory.d.cts +5 -0
- package/lib/cjs/GVLFactory.d.ts +5 -0
- package/lib/cjs/GVLFactory.js +18 -0
- package/lib/cjs/PowerSet.d.ts +3 -0
- package/lib/cjs/PowerSet.js +1 -0
- package/lib/cjs/TCModelFactory.d.ts +6 -0
- package/lib/cjs/TCModelFactory.js +1 -0
- package/lib/cjs/TCStringFactory.d.ts +4 -0
- package/lib/cjs/TCStringFactory.js +1 -0
- package/lib/cjs/TestCollector.d.ts +4 -0
- package/lib/cjs/TestCollector.js +1 -0
- package/lib/cjs/XMLHttpTestTools.d.ts +7 -0
- package/lib/cjs/XMLHttpTestTools.js +1 -0
- package/lib/cjs/index.d.ts +12 -0
- package/lib/cjs/index.js +1 -0
- package/lib/cjs/isPrimitive.d.ts +1 -0
- package/lib/cjs/isPrimitive.js +1 -0
- package/lib/cjs/makeRandomInt.d.ts +1 -0
- package/lib/cjs/makeRandomInt.js +1 -0
- package/lib/cjs/makeRandomIntArray.d.ts +1 -0
- package/lib/cjs/makeRandomIntArray.js +1 -0
- package/lib/cjs/makeRandomString.d.ts +1 -0
- package/lib/cjs/makeRandomString.js +1 -0
- package/lib/cjs/package.json +3 -0
- package/lib/cjs/sameDataDiffRef.d.ts +1 -0
- package/lib/cjs/sameDataDiffRef.js +1 -0
- package/lib/cjs/smellsLikeGVL.d.ts +1 -0
- package/lib/cjs/smellsLikeGVL.js +1 -0
- package/lib/cjs/vendorlist/v2/purpose-restriction-vendor-list.json +284 -0
- package/lib/cjs/vendorlist/v2/purposes-bg.json +1 -0
- package/lib/cjs/vendorlist/v2/purposes-ca.json +1 -0
- package/lib/cjs/vendorlist/v2/purposes-cs.json +1 -0
- package/lib/cjs/vendorlist/v2/purposes-da.json +1 -0
- package/lib/cjs/vendorlist/v2/purposes-de.json +1 -0
- package/lib/cjs/vendorlist/v2/purposes-el.json +1 -0
- package/lib/cjs/vendorlist/v2/purposes-es.json +1 -0
- package/lib/cjs/vendorlist/v2/purposes-et.json +1 -0
- package/lib/cjs/vendorlist/v2/purposes-fi.json +1 -0
- package/lib/cjs/vendorlist/v2/purposes-fr.json +1 -0
- package/lib/cjs/vendorlist/v2/purposes-hu.json +1 -0
- package/lib/cjs/vendorlist/v2/purposes-it.json +1 -0
- package/lib/cjs/vendorlist/v2/purposes-lt.json +1 -0
- package/lib/cjs/vendorlist/v2/purposes-lv.json +1 -0
- package/lib/cjs/vendorlist/v2/purposes-mt.json +1 -0
- package/lib/cjs/vendorlist/v2/purposes-nl.json +1 -0
- package/lib/cjs/vendorlist/v2/purposes-no.json +1 -0
- package/lib/cjs/vendorlist/v2/purposes-pl.json +1 -0
- package/lib/cjs/vendorlist/v2/purposes-pt.json +1 -0
- package/lib/cjs/vendorlist/v2/purposes-ro.json +1 -0
- package/lib/cjs/vendorlist/v2/purposes-ru.json +1 -0
- package/lib/cjs/vendorlist/v2/purposes-sk.json +1 -0
- package/lib/cjs/vendorlist/v2/purposes-sl.json +1 -0
- package/lib/cjs/vendorlist/v2/purposes-sv.json +1 -0
- package/lib/cjs/vendorlist/v2/purposes-zh.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v1.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v10.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v11.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v12.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v13.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v14.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v15.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v16.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v17.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v18.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v19.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v2.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v20.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v21.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v22.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v23.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v24.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v25.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v26.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v27.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v28.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v29.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v3.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v30.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v31.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v32.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v33.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v34.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v35.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v36.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v37.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v38.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v39.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v4.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v40.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v41.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v42.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v43.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v44.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v45.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v46.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v47.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v48.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v49.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v5.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v50.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v51.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v6.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v7.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v8.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list-v9.json +1 -0
- package/lib/cjs/vendorlist/v2/vendor-list.json +1 -0
- package/lib/cjs/vendorlist/v2.2/vendor-list.json +20907 -0
- package/lib/mjs/GVLFactory.cjs +9 -0
- package/lib/mjs/GVLFactory.d.cts +5 -0
- package/lib/mjs/GVLFactory.d.ts +5 -0
- package/lib/mjs/GVLFactory.js +18 -0
- package/lib/mjs/PowerSet.d.ts +3 -0
- package/lib/mjs/PowerSet.js +14 -0
- package/lib/mjs/TCModelFactory.d.ts +6 -0
- package/lib/mjs/TCModelFactory.js +91 -0
- package/lib/mjs/TCStringFactory.d.ts +4 -0
- package/lib/mjs/TCStringFactory.js +15 -0
- package/lib/mjs/TestCollector.d.ts +4 -0
- package/lib/mjs/TestCollector.js +22 -0
- package/lib/mjs/XMLHttpTestTools.d.ts +7 -0
- package/lib/mjs/XMLHttpTestTools.js +13 -0
- package/lib/mjs/index.d.ts +12 -0
- package/lib/mjs/index.js +12 -0
- package/lib/mjs/isPrimitive.d.ts +1 -0
- package/lib/mjs/isPrimitive.js +4 -0
- package/lib/mjs/makeRandomInt.d.ts +1 -0
- package/lib/mjs/makeRandomInt.js +3 -0
- package/lib/mjs/makeRandomIntArray.d.ts +1 -0
- package/lib/mjs/makeRandomIntArray.js +19 -0
- package/lib/mjs/makeRandomString.d.ts +1 -0
- package/lib/mjs/makeRandomString.js +8 -0
- package/lib/mjs/package.json +3 -0
- package/lib/mjs/sameDataDiffRef.d.ts +1 -0
- package/lib/mjs/sameDataDiffRef.js +48 -0
- package/lib/mjs/smellsLikeGVL.d.ts +1 -0
- package/lib/mjs/smellsLikeGVL.js +15 -0
- package/lib/mjs/vendorlist/v2/purpose-restriction-vendor-list.json +284 -0
- package/lib/mjs/vendorlist/v2/purposes-bg.json +1 -0
- package/lib/mjs/vendorlist/v2/purposes-ca.json +1 -0
- package/lib/mjs/vendorlist/v2/purposes-cs.json +1 -0
- package/lib/mjs/vendorlist/v2/purposes-da.json +1 -0
- package/lib/mjs/vendorlist/v2/purposes-de.json +1 -0
- package/lib/mjs/vendorlist/v2/purposes-el.json +1 -0
- package/lib/mjs/vendorlist/v2/purposes-es.json +1 -0
- package/lib/mjs/vendorlist/v2/purposes-et.json +1 -0
- package/lib/mjs/vendorlist/v2/purposes-fi.json +1 -0
- package/lib/mjs/vendorlist/v2/purposes-fr.json +1 -0
- package/lib/mjs/vendorlist/v2/purposes-hu.json +1 -0
- package/lib/mjs/vendorlist/v2/purposes-it.json +1 -0
- package/lib/mjs/vendorlist/v2/purposes-lt.json +1 -0
- package/lib/mjs/vendorlist/v2/purposes-lv.json +1 -0
- package/lib/mjs/vendorlist/v2/purposes-mt.json +1 -0
- package/lib/mjs/vendorlist/v2/purposes-nl.json +1 -0
- package/lib/mjs/vendorlist/v2/purposes-no.json +1 -0
- package/lib/mjs/vendorlist/v2/purposes-pl.json +1 -0
- package/lib/mjs/vendorlist/v2/purposes-pt.json +1 -0
- package/lib/mjs/vendorlist/v2/purposes-ro.json +1 -0
- package/lib/mjs/vendorlist/v2/purposes-ru.json +1 -0
- package/lib/mjs/vendorlist/v2/purposes-sk.json +1 -0
- package/lib/mjs/vendorlist/v2/purposes-sl.json +1 -0
- package/lib/mjs/vendorlist/v2/purposes-sv.json +1 -0
- package/lib/mjs/vendorlist/v2/purposes-zh.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v1.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v10.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v11.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v12.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v13.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v14.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v15.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v16.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v17.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v18.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v19.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v2.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v20.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v21.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v22.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v23.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v24.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v25.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v26.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v27.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v28.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v29.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v3.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v30.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v31.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v32.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v33.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v34.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v35.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v36.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v37.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v38.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v39.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v4.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v40.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v41.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v42.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v43.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v44.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v45.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v46.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v47.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v48.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v49.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v5.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v50.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v51.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v6.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v7.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v8.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list-v9.json +1 -0
- package/lib/mjs/vendorlist/v2/vendor-list.json +1 -0
- package/lib/mjs/vendorlist/v2.2/vendor-list.json +20907 -0
- package/package.json +84 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { GVL } from '@pubtech-ai/core';
|
|
2
|
+
export class GVLFactory {
|
|
3
|
+
static getVersion(version, schema = "v2") {
|
|
4
|
+
return new GVL(require(`./vendorlist/${schema}/vendor-list-v${version}.json`));
|
|
5
|
+
}
|
|
6
|
+
static getLatest(schema = "v2") {
|
|
7
|
+
return new GVL(require(`./vendorlist/${schema}/vendor-list.json`));
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { GVL } from '@pubtech-ai/core';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
+
const __dirname = path.dirname(__filename);
|
|
9
|
+
export class GVLFactory {
|
|
10
|
+
static getVersion(version, schema = 'v2') {
|
|
11
|
+
const json = JSON.parse(fs.readFileSync(__dirname + `/vendorlist/${schema}/vendor-list-v${version}.json`).toString());
|
|
12
|
+
return new GVL(json);
|
|
13
|
+
}
|
|
14
|
+
static getLatest(schema = 'v2') {
|
|
15
|
+
const json = JSON.parse(fs.readFileSync(__dirname + `/vendorlist/${schema}/vendor-list.json`).toString());
|
|
16
|
+
return new GVL(json);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export class PowerSet {
|
|
2
|
+
static generate(numValues) {
|
|
3
|
+
const total = 1 << numValues;
|
|
4
|
+
const powSet = [];
|
|
5
|
+
for (let i = 0; i < total; i++) {
|
|
6
|
+
const group = [];
|
|
7
|
+
for (let j = 0; j < numValues; j++) {
|
|
8
|
+
group.push(!!((i >> j) & 1));
|
|
9
|
+
}
|
|
10
|
+
powSet.push(group);
|
|
11
|
+
}
|
|
12
|
+
return powSet;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { TCModel, PurposeRestriction, RestrictionType } from '@pubtech-ai/core';
|
|
2
|
+
import { makeRandomInt } from './makeRandomInt.js';
|
|
3
|
+
import { GVLFactory } from './GVLFactory.js';
|
|
4
|
+
export class TCModelFactory {
|
|
5
|
+
static noGVL(tcModel) {
|
|
6
|
+
const latestGVL = GVLFactory.getLatest();
|
|
7
|
+
if (!tcModel) {
|
|
8
|
+
tcModel = new TCModel();
|
|
9
|
+
}
|
|
10
|
+
tcModel.cmpId = makeRandomInt(2, 100);
|
|
11
|
+
tcModel.cmpVersion = makeRandomInt(1, 10);
|
|
12
|
+
tcModel.consentScreen = makeRandomInt(1, 5);
|
|
13
|
+
tcModel.isServiceSpecific = !!makeRandomInt(0, 1);
|
|
14
|
+
tcModel.vendorListVersion = makeRandomInt(1, latestGVL.vendorListVersion);
|
|
15
|
+
let counter = 0;
|
|
16
|
+
const rand = makeRandomInt(1, TCModel.consentLanguages.size);
|
|
17
|
+
TCModel.consentLanguages.forEach((lang) => {
|
|
18
|
+
counter++;
|
|
19
|
+
if (counter === rand) {
|
|
20
|
+
tcModel.consentLanguage = lang;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
tcModel.publisherCountryCode = String.fromCharCode(makeRandomInt(65, 90)) +
|
|
24
|
+
String.fromCharCode(makeRandomInt(65, 90));
|
|
25
|
+
const date = new Date();
|
|
26
|
+
const utcDate = new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate()));
|
|
27
|
+
const now = utcDate.getTime();
|
|
28
|
+
const GDPRMageddon = 1576883249;
|
|
29
|
+
tcModel.created = new Date(makeRandomInt(GDPRMageddon, now));
|
|
30
|
+
tcModel.lastUpdated = new Date(makeRandomInt(GDPRMageddon, now));
|
|
31
|
+
const mapping = {
|
|
32
|
+
'purposes': [
|
|
33
|
+
'publisherConsents',
|
|
34
|
+
'publisherLegitimateInterests',
|
|
35
|
+
'purposeConsents',
|
|
36
|
+
'purposeLegitimateInterests',
|
|
37
|
+
],
|
|
38
|
+
'specialFeatures': [
|
|
39
|
+
'specialFeatureOptins',
|
|
40
|
+
],
|
|
41
|
+
'vendors': [
|
|
42
|
+
'vendorConsents',
|
|
43
|
+
'vendorLegitimateInterests',
|
|
44
|
+
'vendorsAllowed',
|
|
45
|
+
'vendorsDisclosed',
|
|
46
|
+
],
|
|
47
|
+
};
|
|
48
|
+
Object.keys(mapping).forEach((gvlIntMap) => {
|
|
49
|
+
const ids = Object.keys(latestGVL[gvlIntMap]).map((strId) => +strId);
|
|
50
|
+
ids.forEach((id) => {
|
|
51
|
+
mapping[gvlIntMap].forEach((vectorName) => {
|
|
52
|
+
// 75% chance of being set
|
|
53
|
+
if (makeRandomInt(1, 4) !== 3) {
|
|
54
|
+
tcModel[vectorName].set(id);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
return tcModel;
|
|
60
|
+
}
|
|
61
|
+
static addPublisherRestrictions(tcModel) {
|
|
62
|
+
if (!tcModel.gvl) {
|
|
63
|
+
tcModel.gvl = GVLFactory.getLatest();
|
|
64
|
+
}
|
|
65
|
+
Object.keys(tcModel.gvl.vendors).forEach((vendorId) => {
|
|
66
|
+
const vendor = tcModel.gvl.vendors[vendorId];
|
|
67
|
+
if (vendor.flexiblePurposes.length) {
|
|
68
|
+
const purposeId = vendor.flexiblePurposes[makeRandomInt(0, vendor.flexiblePurposes.length - 1)];
|
|
69
|
+
const isInConsent = vendor.purposes.includes(purposeId);
|
|
70
|
+
const notAllowed = makeRandomInt(0, 1) === 1;
|
|
71
|
+
let purpRestriction;
|
|
72
|
+
if (notAllowed) {
|
|
73
|
+
purpRestriction = new PurposeRestriction(purposeId, RestrictionType.NOT_ALLOWED);
|
|
74
|
+
}
|
|
75
|
+
else if (isInConsent) {
|
|
76
|
+
purpRestriction = new PurposeRestriction(purposeId, RestrictionType.REQUIRE_LI);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
purpRestriction = new PurposeRestriction(purposeId, RestrictionType.REQUIRE_CONSENT);
|
|
80
|
+
}
|
|
81
|
+
tcModel.publisherRestrictions.add(+vendorId, purpRestriction);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
return tcModel;
|
|
85
|
+
}
|
|
86
|
+
static withGVL() {
|
|
87
|
+
const tcModel = this.noGVL();
|
|
88
|
+
tcModel.gvl = GVLFactory.getLatest();
|
|
89
|
+
return tcModel;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { TCModelFactory } from './TCModelFactory.js';
|
|
2
|
+
import { TCString } from '@pubtech-ai/core';
|
|
3
|
+
export class TCStringFactory {
|
|
4
|
+
static base(isForSaving = false) {
|
|
5
|
+
const encodingOptions = { isForVendors: !isForSaving };
|
|
6
|
+
const tcModel = TCModelFactory.withGVL();
|
|
7
|
+
return TCString.encode(tcModel, encodingOptions);
|
|
8
|
+
}
|
|
9
|
+
static withPubRestrictions(isForSaving = false) {
|
|
10
|
+
const encodingOptions = { isForVendors: !isForSaving };
|
|
11
|
+
let tcModel = TCModelFactory.withGVL();
|
|
12
|
+
tcModel = TCModelFactory.addPublisherRestrictions(tcModel);
|
|
13
|
+
return TCString.encode(tcModel, encodingOptions);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import lint from 'mocha-eslint';
|
|
4
|
+
export class TestCollector {
|
|
5
|
+
static async requireTests(filePath) {
|
|
6
|
+
if (fs.statSync(filePath).isDirectory()) {
|
|
7
|
+
describe(filePath.split('/').pop() + '/', () => {
|
|
8
|
+
fs.readdirSync(filePath).forEach((item) => {
|
|
9
|
+
this.requireTests(path.join(filePath, item));
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
else if (filePath.indexOf('.test.ts') === filePath.length - '.test.ts'.length) {
|
|
14
|
+
await import(filePath);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
static eslintTests(directories = ['.'], fileExtensions = ['ts', 'js', 'json']) {
|
|
18
|
+
lint([`{${directories}}/**/*.{${fileExtensions}}`], {
|
|
19
|
+
alwaysWarn: false,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as sinon from 'sinon';
|
|
2
|
+
export class XMLHttpTestTools {
|
|
3
|
+
static JSON_HEADER = { 'Content-Type': 'application/json' };
|
|
4
|
+
static xhr;
|
|
5
|
+
static requests;
|
|
6
|
+
static beforeEach() {
|
|
7
|
+
this.xhr = sinon.useFakeXMLHttpRequest();
|
|
8
|
+
this.requests = [];
|
|
9
|
+
this.xhr.onCreate = (xhr) => {
|
|
10
|
+
this.requests.push(xhr);
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from './GVLFactory.js';
|
|
2
|
+
export * from './PowerSet.js';
|
|
3
|
+
export * from './TCModelFactory.js';
|
|
4
|
+
export * from './TCStringFactory.js';
|
|
5
|
+
export * from './TestCollector.js';
|
|
6
|
+
export * from './XMLHttpTestTools.js';
|
|
7
|
+
export * from './isPrimitive.js';
|
|
8
|
+
export * from './makeRandomInt.js';
|
|
9
|
+
export * from './makeRandomIntArray.js';
|
|
10
|
+
export * from './makeRandomString.js';
|
|
11
|
+
export * from './sameDataDiffRef.js';
|
|
12
|
+
export * from './smellsLikeGVL.js';
|
package/lib/mjs/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from './GVLFactory.js';
|
|
2
|
+
export * from './PowerSet.js';
|
|
3
|
+
export * from './TCModelFactory.js';
|
|
4
|
+
export * from './TCStringFactory.js';
|
|
5
|
+
export * from './TestCollector.js';
|
|
6
|
+
export * from './XMLHttpTestTools.js';
|
|
7
|
+
export * from './isPrimitive.js';
|
|
8
|
+
export * from './makeRandomInt.js';
|
|
9
|
+
export * from './makeRandomIntArray.js';
|
|
10
|
+
export * from './makeRandomString.js';
|
|
11
|
+
export * from './sameDataDiffRef.js';
|
|
12
|
+
export * from './smellsLikeGVL.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isPrimitive: (value: unknown) => boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function makeRandomInt(betweenStart: number, betweenEnd: number): number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function makeRandomIntArray(intsBetweenStart: number, intsBetweenEnd: number, length?: number): number[];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { makeRandomInt } from './makeRandomInt.js';
|
|
2
|
+
export function makeRandomIntArray(intsBetweenStart, intsBetweenEnd, length) {
|
|
3
|
+
const intSet = new Set();
|
|
4
|
+
let retr = [];
|
|
5
|
+
if (length !== undefined && intsBetweenEnd - intsBetweenStart <= length) {
|
|
6
|
+
while (intSet.size != length) {
|
|
7
|
+
intSet.add(makeRandomInt(intsBetweenStart, intsBetweenEnd));
|
|
8
|
+
}
|
|
9
|
+
retr = Array.from(intSet);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
length = makeRandomInt(intsBetweenStart, intsBetweenEnd);
|
|
13
|
+
while (intSet.size != length) {
|
|
14
|
+
intSet.add(makeRandomInt(intsBetweenStart, intsBetweenEnd));
|
|
15
|
+
}
|
|
16
|
+
retr = Array.from(intSet);
|
|
17
|
+
}
|
|
18
|
+
return retr;
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function makeRandomString(length: number, asciiStart?: number, asciiEnd?: number): string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { makeRandomInt } from './makeRandomInt.js';
|
|
2
|
+
export function makeRandomString(length, asciiStart = 0, asciiEnd = 127) {
|
|
3
|
+
let retr = '';
|
|
4
|
+
for (let i = 0; i < length; i++) {
|
|
5
|
+
retr += String.fromCharCode(makeRandomInt(asciiStart, asciiEnd));
|
|
6
|
+
}
|
|
7
|
+
return retr;
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const sameDataDiffRef: (obj1: object, obj2: object, objName: string, ignoreKeys?: string[]) => void;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { expect } from 'chai';
|
|
2
|
+
import { isPrimitive } from './isPrimitive.js';
|
|
3
|
+
export const sameDataDiffRef = (obj1, obj2, objName, ignoreKeys) => {
|
|
4
|
+
if (obj1 === undefined && obj2 === undefined) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
expect(typeof obj1, `typeof ${objName}`).to.equal(typeof obj2);
|
|
8
|
+
expect(obj1, objName).not.to.equal(obj2);
|
|
9
|
+
const keySet = new Set(Object.keys(obj1)
|
|
10
|
+
.concat(Object.keys(obj2))
|
|
11
|
+
/**
|
|
12
|
+
* filter out all of the keys that end with an underscore since those are
|
|
13
|
+
* private members
|
|
14
|
+
*/
|
|
15
|
+
.filter((key) => (key.indexOf('_') !== key.length - 1)));
|
|
16
|
+
if (Array.isArray(ignoreKeys)) {
|
|
17
|
+
ignoreKeys.forEach((item) => {
|
|
18
|
+
if (keySet.has(item)) {
|
|
19
|
+
keySet.delete(item);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
for (const key of keySet) {
|
|
24
|
+
if (key.indexOf('_') !== key.length - 1) {
|
|
25
|
+
const item1 = obj1[key];
|
|
26
|
+
const item2 = obj2[key];
|
|
27
|
+
const itsType = typeof item1;
|
|
28
|
+
expect(typeof item2, `typeof ${objName}->${key}`).to.equal(itsType);
|
|
29
|
+
if (item1 === undefined && item2 === undefined) {
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (isPrimitive(item1)) {
|
|
33
|
+
expect(item2, `${objName}->${key}`).to.equal(item1);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
if (item1 instanceof Date) {
|
|
37
|
+
const time1 = item1.getTime();
|
|
38
|
+
const time2 = item2.getTime();
|
|
39
|
+
// should be within the 200 milisecond range
|
|
40
|
+
expect(time2, `${objName}->${key}`).to.be.within(time1 - 100, time1 + 100);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
sameDataDiffRef(item1, item2, key, ignoreKeys);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const smellsLikeGVL: (possibleGVL: object) => void;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { expect } from 'chai';
|
|
2
|
+
export const smellsLikeGVL = (possibleGVL) => {
|
|
3
|
+
expect(possibleGVL, 'maybe gvl?').to.include([
|
|
4
|
+
'gvlSpecificationVersion',
|
|
5
|
+
'vendorListVersion',
|
|
6
|
+
'tcfPolicyVersion',
|
|
7
|
+
'lastUpdated',
|
|
8
|
+
'purposes',
|
|
9
|
+
'specialPurposes',
|
|
10
|
+
'features',
|
|
11
|
+
'specialFeatures',
|
|
12
|
+
'vendors',
|
|
13
|
+
'stacks',
|
|
14
|
+
]);
|
|
15
|
+
};
|