@pubtech-ai/testing 2.9.0 → 3.0.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.
@@ -1,6 +1,7 @@
1
- import { TCModel } from '@pubtech-ai/core';
1
+ import { TCModel, GVL } from '@pubtech-ai/core';
2
2
  export declare class TCModelFactory {
3
- static noGVL(tcModel?: TCModel): TCModel;
4
- static addPublisherRestrictions(tcModel: TCModel): TCModel;
5
- static withGVL(): TCModel;
3
+ static noGVL(gvl?: GVL): TCModel;
4
+ private static createBaseTCModel;
5
+ static addPublisherRestrictions(tcModel: TCModel, gvl?: GVL): TCModel;
6
+ static withGVL(gvl?: GVL): TCModel;
6
7
  }
@@ -2,11 +2,13 @@ import { TCModel, PurposeRestriction, RestrictionType } from '@pubtech-ai/core';
2
2
  import { makeRandomInt } from './makeRandomInt.js';
3
3
  import { GVLFactory } from './GVLFactory.js';
4
4
  export class TCModelFactory {
5
- static noGVL(tcModel) {
6
- const latestGVL = GVLFactory.getLatest();
7
- if (!tcModel) {
8
- tcModel = new TCModel();
9
- }
5
+ static noGVL(gvl) {
6
+ const tcModel = this.createBaseTCModel(gvl);
7
+ return tcModel;
8
+ }
9
+ static createBaseTCModel(gvl) {
10
+ const latestGVL = gvl || GVLFactory.getLatest();
11
+ const tcModel = new TCModel();
10
12
  tcModel.cmpId = makeRandomInt(2, 100);
11
13
  tcModel.cmpVersion = makeRandomInt(1, 10);
12
14
  tcModel.consentScreen = makeRandomInt(1, 5);
@@ -58,9 +60,9 @@ export class TCModelFactory {
58
60
  });
59
61
  return tcModel;
60
62
  }
61
- static addPublisherRestrictions(tcModel) {
63
+ static addPublisherRestrictions(tcModel, gvl) {
62
64
  if (!tcModel.gvl) {
63
- tcModel.gvl = GVLFactory.getLatest();
65
+ tcModel.gvl = gvl || GVLFactory.getLatest();
64
66
  }
65
67
  Object.keys(tcModel.gvl.vendors).forEach((vendorId) => {
66
68
  const vendor = tcModel.gvl.vendors[vendorId];
@@ -83,9 +85,9 @@ export class TCModelFactory {
83
85
  });
84
86
  return tcModel;
85
87
  }
86
- static withGVL() {
87
- const tcModel = this.noGVL();
88
- tcModel.gvl = GVLFactory.getLatest();
88
+ static withGVL(gvl) {
89
+ const tcModel = this.createBaseTCModel(gvl);
90
+ tcModel.gvl = gvl || GVLFactory.getLatest();
89
91
  return tcModel;
90
92
  }
91
93
  }