Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: update TCModelFactory to accept GVL parameter in methods #468

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions modules/testing/src/TCModelFactory.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import {TCModel, PurposeRestriction, RestrictionType} from '@iabtechlabtcf/core';
import {makeRandomInt} from './makeRandomInt.js';
import {GVLFactory} from './GVLFactory.js';
import { TCModel, PurposeRestriction, RestrictionType, GVL } from '@iabtechlabtcf/core';
import { makeRandomInt } from './makeRandomInt.js';
import { GVLFactory } from './GVLFactory.js';

export class TCModelFactory {

public static noGVL(tcModel?: TCModel): TCModel {
public static noGVL(gvl?: GVL): TCModel {

const latestGVL = GVLFactory.getLatest();
const tcModel = this.createBaseTCModel(gvl);

if (!tcModel) {
return tcModel;

}

tcModel = new TCModel();
private static createBaseTCModel(gvl?: GVL): TCModel {

}
const latestGVL = gvl || GVLFactory.getLatest();
const tcModel = new TCModel();

tcModel.cmpId = makeRandomInt(2, 100);
tcModel.cmpVersion = makeRandomInt(1, 10);
Expand All @@ -25,7 +28,7 @@ export class TCModelFactory {

TCModel.consentLanguages.forEach((lang: string): void => {

counter ++;
counter++;

if (counter === rand) {

Expand Down Expand Up @@ -88,11 +91,11 @@ export class TCModelFactory {

}

public static addPublisherRestrictions(tcModel: TCModel): TCModel {
public static addPublisherRestrictions(tcModel: TCModel, gvl?: GVL): TCModel {

if (!tcModel.gvl) {

tcModel.gvl = GVLFactory.getLatest();
tcModel.gvl = gvl || GVLFactory.getLatest();

}

Expand Down Expand Up @@ -131,11 +134,11 @@ export class TCModelFactory {

}

public static withGVL(): TCModel {
public static withGVL(gvl?: GVL): TCModel {

const tcModel = this.noGVL();
const tcModel = this.createBaseTCModel(gvl);

tcModel.gvl = GVLFactory.getLatest();
tcModel.gvl = gvl || GVLFactory.getLatest();

return tcModel;

Expand Down