@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.
Files changed (218) hide show
  1. package/README.md +75 -0
  2. package/lib/cjs/GVLFactory.cjs +18 -0
  3. package/lib/cjs/GVLFactory.d.cts +5 -0
  4. package/lib/cjs/GVLFactory.d.ts +5 -0
  5. package/lib/cjs/GVLFactory.js +18 -0
  6. package/lib/cjs/PowerSet.d.ts +3 -0
  7. package/lib/cjs/PowerSet.js +1 -0
  8. package/lib/cjs/TCModelFactory.d.ts +6 -0
  9. package/lib/cjs/TCModelFactory.js +1 -0
  10. package/lib/cjs/TCStringFactory.d.ts +4 -0
  11. package/lib/cjs/TCStringFactory.js +1 -0
  12. package/lib/cjs/TestCollector.d.ts +4 -0
  13. package/lib/cjs/TestCollector.js +1 -0
  14. package/lib/cjs/XMLHttpTestTools.d.ts +7 -0
  15. package/lib/cjs/XMLHttpTestTools.js +1 -0
  16. package/lib/cjs/index.d.ts +12 -0
  17. package/lib/cjs/index.js +1 -0
  18. package/lib/cjs/isPrimitive.d.ts +1 -0
  19. package/lib/cjs/isPrimitive.js +1 -0
  20. package/lib/cjs/makeRandomInt.d.ts +1 -0
  21. package/lib/cjs/makeRandomInt.js +1 -0
  22. package/lib/cjs/makeRandomIntArray.d.ts +1 -0
  23. package/lib/cjs/makeRandomIntArray.js +1 -0
  24. package/lib/cjs/makeRandomString.d.ts +1 -0
  25. package/lib/cjs/makeRandomString.js +1 -0
  26. package/lib/cjs/package.json +3 -0
  27. package/lib/cjs/sameDataDiffRef.d.ts +1 -0
  28. package/lib/cjs/sameDataDiffRef.js +1 -0
  29. package/lib/cjs/smellsLikeGVL.d.ts +1 -0
  30. package/lib/cjs/smellsLikeGVL.js +1 -0
  31. package/lib/cjs/vendorlist/v2/purpose-restriction-vendor-list.json +284 -0
  32. package/lib/cjs/vendorlist/v2/purposes-bg.json +1 -0
  33. package/lib/cjs/vendorlist/v2/purposes-ca.json +1 -0
  34. package/lib/cjs/vendorlist/v2/purposes-cs.json +1 -0
  35. package/lib/cjs/vendorlist/v2/purposes-da.json +1 -0
  36. package/lib/cjs/vendorlist/v2/purposes-de.json +1 -0
  37. package/lib/cjs/vendorlist/v2/purposes-el.json +1 -0
  38. package/lib/cjs/vendorlist/v2/purposes-es.json +1 -0
  39. package/lib/cjs/vendorlist/v2/purposes-et.json +1 -0
  40. package/lib/cjs/vendorlist/v2/purposes-fi.json +1 -0
  41. package/lib/cjs/vendorlist/v2/purposes-fr.json +1 -0
  42. package/lib/cjs/vendorlist/v2/purposes-hu.json +1 -0
  43. package/lib/cjs/vendorlist/v2/purposes-it.json +1 -0
  44. package/lib/cjs/vendorlist/v2/purposes-lt.json +1 -0
  45. package/lib/cjs/vendorlist/v2/purposes-lv.json +1 -0
  46. package/lib/cjs/vendorlist/v2/purposes-mt.json +1 -0
  47. package/lib/cjs/vendorlist/v2/purposes-nl.json +1 -0
  48. package/lib/cjs/vendorlist/v2/purposes-no.json +1 -0
  49. package/lib/cjs/vendorlist/v2/purposes-pl.json +1 -0
  50. package/lib/cjs/vendorlist/v2/purposes-pt.json +1 -0
  51. package/lib/cjs/vendorlist/v2/purposes-ro.json +1 -0
  52. package/lib/cjs/vendorlist/v2/purposes-ru.json +1 -0
  53. package/lib/cjs/vendorlist/v2/purposes-sk.json +1 -0
  54. package/lib/cjs/vendorlist/v2/purposes-sl.json +1 -0
  55. package/lib/cjs/vendorlist/v2/purposes-sv.json +1 -0
  56. package/lib/cjs/vendorlist/v2/purposes-zh.json +1 -0
  57. package/lib/cjs/vendorlist/v2/vendor-list-v1.json +1 -0
  58. package/lib/cjs/vendorlist/v2/vendor-list-v10.json +1 -0
  59. package/lib/cjs/vendorlist/v2/vendor-list-v11.json +1 -0
  60. package/lib/cjs/vendorlist/v2/vendor-list-v12.json +1 -0
  61. package/lib/cjs/vendorlist/v2/vendor-list-v13.json +1 -0
  62. package/lib/cjs/vendorlist/v2/vendor-list-v14.json +1 -0
  63. package/lib/cjs/vendorlist/v2/vendor-list-v15.json +1 -0
  64. package/lib/cjs/vendorlist/v2/vendor-list-v16.json +1 -0
  65. package/lib/cjs/vendorlist/v2/vendor-list-v17.json +1 -0
  66. package/lib/cjs/vendorlist/v2/vendor-list-v18.json +1 -0
  67. package/lib/cjs/vendorlist/v2/vendor-list-v19.json +1 -0
  68. package/lib/cjs/vendorlist/v2/vendor-list-v2.json +1 -0
  69. package/lib/cjs/vendorlist/v2/vendor-list-v20.json +1 -0
  70. package/lib/cjs/vendorlist/v2/vendor-list-v21.json +1 -0
  71. package/lib/cjs/vendorlist/v2/vendor-list-v22.json +1 -0
  72. package/lib/cjs/vendorlist/v2/vendor-list-v23.json +1 -0
  73. package/lib/cjs/vendorlist/v2/vendor-list-v24.json +1 -0
  74. package/lib/cjs/vendorlist/v2/vendor-list-v25.json +1 -0
  75. package/lib/cjs/vendorlist/v2/vendor-list-v26.json +1 -0
  76. package/lib/cjs/vendorlist/v2/vendor-list-v27.json +1 -0
  77. package/lib/cjs/vendorlist/v2/vendor-list-v28.json +1 -0
  78. package/lib/cjs/vendorlist/v2/vendor-list-v29.json +1 -0
  79. package/lib/cjs/vendorlist/v2/vendor-list-v3.json +1 -0
  80. package/lib/cjs/vendorlist/v2/vendor-list-v30.json +1 -0
  81. package/lib/cjs/vendorlist/v2/vendor-list-v31.json +1 -0
  82. package/lib/cjs/vendorlist/v2/vendor-list-v32.json +1 -0
  83. package/lib/cjs/vendorlist/v2/vendor-list-v33.json +1 -0
  84. package/lib/cjs/vendorlist/v2/vendor-list-v34.json +1 -0
  85. package/lib/cjs/vendorlist/v2/vendor-list-v35.json +1 -0
  86. package/lib/cjs/vendorlist/v2/vendor-list-v36.json +1 -0
  87. package/lib/cjs/vendorlist/v2/vendor-list-v37.json +1 -0
  88. package/lib/cjs/vendorlist/v2/vendor-list-v38.json +1 -0
  89. package/lib/cjs/vendorlist/v2/vendor-list-v39.json +1 -0
  90. package/lib/cjs/vendorlist/v2/vendor-list-v4.json +1 -0
  91. package/lib/cjs/vendorlist/v2/vendor-list-v40.json +1 -0
  92. package/lib/cjs/vendorlist/v2/vendor-list-v41.json +1 -0
  93. package/lib/cjs/vendorlist/v2/vendor-list-v42.json +1 -0
  94. package/lib/cjs/vendorlist/v2/vendor-list-v43.json +1 -0
  95. package/lib/cjs/vendorlist/v2/vendor-list-v44.json +1 -0
  96. package/lib/cjs/vendorlist/v2/vendor-list-v45.json +1 -0
  97. package/lib/cjs/vendorlist/v2/vendor-list-v46.json +1 -0
  98. package/lib/cjs/vendorlist/v2/vendor-list-v47.json +1 -0
  99. package/lib/cjs/vendorlist/v2/vendor-list-v48.json +1 -0
  100. package/lib/cjs/vendorlist/v2/vendor-list-v49.json +1 -0
  101. package/lib/cjs/vendorlist/v2/vendor-list-v5.json +1 -0
  102. package/lib/cjs/vendorlist/v2/vendor-list-v50.json +1 -0
  103. package/lib/cjs/vendorlist/v2/vendor-list-v51.json +1 -0
  104. package/lib/cjs/vendorlist/v2/vendor-list-v6.json +1 -0
  105. package/lib/cjs/vendorlist/v2/vendor-list-v7.json +1 -0
  106. package/lib/cjs/vendorlist/v2/vendor-list-v8.json +1 -0
  107. package/lib/cjs/vendorlist/v2/vendor-list-v9.json +1 -0
  108. package/lib/cjs/vendorlist/v2/vendor-list.json +1 -0
  109. package/lib/cjs/vendorlist/v2.2/vendor-list.json +20907 -0
  110. package/lib/mjs/GVLFactory.cjs +9 -0
  111. package/lib/mjs/GVLFactory.d.cts +5 -0
  112. package/lib/mjs/GVLFactory.d.ts +5 -0
  113. package/lib/mjs/GVLFactory.js +18 -0
  114. package/lib/mjs/PowerSet.d.ts +3 -0
  115. package/lib/mjs/PowerSet.js +14 -0
  116. package/lib/mjs/TCModelFactory.d.ts +6 -0
  117. package/lib/mjs/TCModelFactory.js +91 -0
  118. package/lib/mjs/TCStringFactory.d.ts +4 -0
  119. package/lib/mjs/TCStringFactory.js +15 -0
  120. package/lib/mjs/TestCollector.d.ts +4 -0
  121. package/lib/mjs/TestCollector.js +22 -0
  122. package/lib/mjs/XMLHttpTestTools.d.ts +7 -0
  123. package/lib/mjs/XMLHttpTestTools.js +13 -0
  124. package/lib/mjs/index.d.ts +12 -0
  125. package/lib/mjs/index.js +12 -0
  126. package/lib/mjs/isPrimitive.d.ts +1 -0
  127. package/lib/mjs/isPrimitive.js +4 -0
  128. package/lib/mjs/makeRandomInt.d.ts +1 -0
  129. package/lib/mjs/makeRandomInt.js +3 -0
  130. package/lib/mjs/makeRandomIntArray.d.ts +1 -0
  131. package/lib/mjs/makeRandomIntArray.js +19 -0
  132. package/lib/mjs/makeRandomString.d.ts +1 -0
  133. package/lib/mjs/makeRandomString.js +8 -0
  134. package/lib/mjs/package.json +3 -0
  135. package/lib/mjs/sameDataDiffRef.d.ts +1 -0
  136. package/lib/mjs/sameDataDiffRef.js +48 -0
  137. package/lib/mjs/smellsLikeGVL.d.ts +1 -0
  138. package/lib/mjs/smellsLikeGVL.js +15 -0
  139. package/lib/mjs/vendorlist/v2/purpose-restriction-vendor-list.json +284 -0
  140. package/lib/mjs/vendorlist/v2/purposes-bg.json +1 -0
  141. package/lib/mjs/vendorlist/v2/purposes-ca.json +1 -0
  142. package/lib/mjs/vendorlist/v2/purposes-cs.json +1 -0
  143. package/lib/mjs/vendorlist/v2/purposes-da.json +1 -0
  144. package/lib/mjs/vendorlist/v2/purposes-de.json +1 -0
  145. package/lib/mjs/vendorlist/v2/purposes-el.json +1 -0
  146. package/lib/mjs/vendorlist/v2/purposes-es.json +1 -0
  147. package/lib/mjs/vendorlist/v2/purposes-et.json +1 -0
  148. package/lib/mjs/vendorlist/v2/purposes-fi.json +1 -0
  149. package/lib/mjs/vendorlist/v2/purposes-fr.json +1 -0
  150. package/lib/mjs/vendorlist/v2/purposes-hu.json +1 -0
  151. package/lib/mjs/vendorlist/v2/purposes-it.json +1 -0
  152. package/lib/mjs/vendorlist/v2/purposes-lt.json +1 -0
  153. package/lib/mjs/vendorlist/v2/purposes-lv.json +1 -0
  154. package/lib/mjs/vendorlist/v2/purposes-mt.json +1 -0
  155. package/lib/mjs/vendorlist/v2/purposes-nl.json +1 -0
  156. package/lib/mjs/vendorlist/v2/purposes-no.json +1 -0
  157. package/lib/mjs/vendorlist/v2/purposes-pl.json +1 -0
  158. package/lib/mjs/vendorlist/v2/purposes-pt.json +1 -0
  159. package/lib/mjs/vendorlist/v2/purposes-ro.json +1 -0
  160. package/lib/mjs/vendorlist/v2/purposes-ru.json +1 -0
  161. package/lib/mjs/vendorlist/v2/purposes-sk.json +1 -0
  162. package/lib/mjs/vendorlist/v2/purposes-sl.json +1 -0
  163. package/lib/mjs/vendorlist/v2/purposes-sv.json +1 -0
  164. package/lib/mjs/vendorlist/v2/purposes-zh.json +1 -0
  165. package/lib/mjs/vendorlist/v2/vendor-list-v1.json +1 -0
  166. package/lib/mjs/vendorlist/v2/vendor-list-v10.json +1 -0
  167. package/lib/mjs/vendorlist/v2/vendor-list-v11.json +1 -0
  168. package/lib/mjs/vendorlist/v2/vendor-list-v12.json +1 -0
  169. package/lib/mjs/vendorlist/v2/vendor-list-v13.json +1 -0
  170. package/lib/mjs/vendorlist/v2/vendor-list-v14.json +1 -0
  171. package/lib/mjs/vendorlist/v2/vendor-list-v15.json +1 -0
  172. package/lib/mjs/vendorlist/v2/vendor-list-v16.json +1 -0
  173. package/lib/mjs/vendorlist/v2/vendor-list-v17.json +1 -0
  174. package/lib/mjs/vendorlist/v2/vendor-list-v18.json +1 -0
  175. package/lib/mjs/vendorlist/v2/vendor-list-v19.json +1 -0
  176. package/lib/mjs/vendorlist/v2/vendor-list-v2.json +1 -0
  177. package/lib/mjs/vendorlist/v2/vendor-list-v20.json +1 -0
  178. package/lib/mjs/vendorlist/v2/vendor-list-v21.json +1 -0
  179. package/lib/mjs/vendorlist/v2/vendor-list-v22.json +1 -0
  180. package/lib/mjs/vendorlist/v2/vendor-list-v23.json +1 -0
  181. package/lib/mjs/vendorlist/v2/vendor-list-v24.json +1 -0
  182. package/lib/mjs/vendorlist/v2/vendor-list-v25.json +1 -0
  183. package/lib/mjs/vendorlist/v2/vendor-list-v26.json +1 -0
  184. package/lib/mjs/vendorlist/v2/vendor-list-v27.json +1 -0
  185. package/lib/mjs/vendorlist/v2/vendor-list-v28.json +1 -0
  186. package/lib/mjs/vendorlist/v2/vendor-list-v29.json +1 -0
  187. package/lib/mjs/vendorlist/v2/vendor-list-v3.json +1 -0
  188. package/lib/mjs/vendorlist/v2/vendor-list-v30.json +1 -0
  189. package/lib/mjs/vendorlist/v2/vendor-list-v31.json +1 -0
  190. package/lib/mjs/vendorlist/v2/vendor-list-v32.json +1 -0
  191. package/lib/mjs/vendorlist/v2/vendor-list-v33.json +1 -0
  192. package/lib/mjs/vendorlist/v2/vendor-list-v34.json +1 -0
  193. package/lib/mjs/vendorlist/v2/vendor-list-v35.json +1 -0
  194. package/lib/mjs/vendorlist/v2/vendor-list-v36.json +1 -0
  195. package/lib/mjs/vendorlist/v2/vendor-list-v37.json +1 -0
  196. package/lib/mjs/vendorlist/v2/vendor-list-v38.json +1 -0
  197. package/lib/mjs/vendorlist/v2/vendor-list-v39.json +1 -0
  198. package/lib/mjs/vendorlist/v2/vendor-list-v4.json +1 -0
  199. package/lib/mjs/vendorlist/v2/vendor-list-v40.json +1 -0
  200. package/lib/mjs/vendorlist/v2/vendor-list-v41.json +1 -0
  201. package/lib/mjs/vendorlist/v2/vendor-list-v42.json +1 -0
  202. package/lib/mjs/vendorlist/v2/vendor-list-v43.json +1 -0
  203. package/lib/mjs/vendorlist/v2/vendor-list-v44.json +1 -0
  204. package/lib/mjs/vendorlist/v2/vendor-list-v45.json +1 -0
  205. package/lib/mjs/vendorlist/v2/vendor-list-v46.json +1 -0
  206. package/lib/mjs/vendorlist/v2/vendor-list-v47.json +1 -0
  207. package/lib/mjs/vendorlist/v2/vendor-list-v48.json +1 -0
  208. package/lib/mjs/vendorlist/v2/vendor-list-v49.json +1 -0
  209. package/lib/mjs/vendorlist/v2/vendor-list-v5.json +1 -0
  210. package/lib/mjs/vendorlist/v2/vendor-list-v50.json +1 -0
  211. package/lib/mjs/vendorlist/v2/vendor-list-v51.json +1 -0
  212. package/lib/mjs/vendorlist/v2/vendor-list-v6.json +1 -0
  213. package/lib/mjs/vendorlist/v2/vendor-list-v7.json +1 -0
  214. package/lib/mjs/vendorlist/v2/vendor-list-v8.json +1 -0
  215. package/lib/mjs/vendorlist/v2/vendor-list-v9.json +1 -0
  216. package/lib/mjs/vendorlist/v2/vendor-list.json +1 -0
  217. package/lib/mjs/vendorlist/v2.2/vendor-list.json +20907 -0
  218. 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,5 @@
1
+ import { GVL } from '@pubtech-ai/core';
2
+ export declare class GVLFactory {
3
+ static getVersion(version: number, schema?: string): GVL;
4
+ static getLatest(schema?: string): GVL;
5
+ }
@@ -0,0 +1,5 @@
1
+ import { GVL } from '@pubtech-ai/core';
2
+ export declare class GVLFactory {
3
+ static getVersion(version: number, schema?: string): GVL;
4
+ static getLatest(schema?: string): GVL;
5
+ }
@@ -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,3 @@
1
+ export declare class PowerSet {
2
+ static generate(numValues: number): boolean[][];
3
+ }
@@ -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,6 @@
1
+ import { TCModel } from '@pubtech-ai/core';
2
+ export declare class TCModelFactory {
3
+ static noGVL(tcModel?: TCModel): TCModel;
4
+ static addPublisherRestrictions(tcModel: TCModel): TCModel;
5
+ static withGVL(): TCModel;
6
+ }
@@ -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,4 @@
1
+ export declare class TCStringFactory {
2
+ static base(isForSaving?: boolean): string;
3
+ static withPubRestrictions(isForSaving?: boolean): string;
4
+ }
@@ -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,4 @@
1
+ export declare class TestCollector {
2
+ static requireTests(filePath: string): Promise<void>;
3
+ static eslintTests(directories?: string[], fileExtensions?: string[]): void;
4
+ }
@@ -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,7 @@
1
+ import * as sinon from 'sinon';
2
+ export declare class XMLHttpTestTools {
3
+ static JSON_HEADER: object;
4
+ private static xhr;
5
+ static requests: sinon.SinonFakeXMLHttpRequest[];
6
+ static beforeEach(): void;
7
+ }
@@ -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';
@@ -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,4 @@
1
+ export const isPrimitive = (value) => {
2
+ const itsType = typeof value;
3
+ return (itsType === 'number' || itsType === 'string' || itsType === 'boolean');
4
+ };
@@ -0,0 +1 @@
1
+ export declare function makeRandomInt(betweenStart: number, betweenEnd: number): number;
@@ -0,0 +1,3 @@
1
+ export function makeRandomInt(betweenStart, betweenEnd) {
2
+ return Math.round(Math.random() * (betweenEnd - betweenStart)) + betweenStart;
3
+ }
@@ -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,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -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
+ };