Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@financial-times/ads-permutive

Package Overview
Dependencies
Maintainers
9
Versions
136
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@financial-times/ads-permutive - npm Package Compare versions

Comparing version 5.0.0-beta.7 to 5.0.0-beta.8

86

dist/ads-permutive.js
var env = {
PERMUTIVE_PUBLIC_API_KEY: 'b2b3b748-e1f6-4bd5-b2f2-26debc8075a3',
PERMUTIVE_PUBLIC_ID: 'e1c3fd73-dd41-4abd-b80b-4278d52bf7aa'
PERMUTIVE_PUBLIC_API_KEY: "b2b3b748-e1f6-4bd5-b2f2-26debc8075a3",
PERMUTIVE_PUBLIC_ID: "e1c3fd73-dd41-4abd-b80b-4278d52bf7aa"
};

@@ -186,30 +186,30 @@

targeting: [{
key: 'device_spoor_id',
key: "device_spoor_id",
value: String
}, {
key: 'guid',
key: "guid",
value: String
}, {
key: '05',
key: "05",
value: String
}, {
key: '06',
key: "06",
value: String
}, {
key: '07',
key: "07",
value: String
}, {
key: 'slv',
key: "slv",
value: String
}, {
key: 'loggedIn',
key: "loggedIn",
value: Boolean
}, {
key: 'followedConcepts',
key: "followedConcepts",
value: Array
}, {
key: 'gender',
key: "gender",
value: String
}, {
key: 'indb2b',
key: "indb2b",
value: String

@@ -222,15 +222,15 @@ }]

targeting: [{
key: 'auuid',
key: "auuid",
value: String
}, {
key: 'title',
key: "title",
value: String
}, {
key: 'ca',
key: "ca",
value: String
}, {
key: 'topic',
key: "topic",
value: String
}, {
key: 'ad',
key: "ad",
value: String

@@ -241,15 +241,15 @@ }]

attributes: [{
key: 'brand',
key: "brand",
value: String
}, {
key: 'genre',
key: "genre",
value: Array
}, {
key: 'organisations',
key: "organisations",
value: Array
}, {
key: 'people',
key: "people",
value: Array
}, {
key: 'authors',
key: "authors",
value: Array

@@ -360,10 +360,10 @@ }]

const getByKeyInDFPTargeting = getByKeyInAdsArrayV1(dfpTargeting);
const industry = getByKeyInDFPTargeting('05');
const responsibility = getByKeyInDFPTargeting('06');
const position = getByKeyInDFPTargeting('07');
const subscriptionLevel = getByKeyInDFPTargeting('slv');
const loggedIn = getByKeyInDFPTargeting('loggedIn');
const followedConcepts = getByKeyInDFPTargeting('followedConcepts');
const gender = getByKeyInDFPTargeting('gender');
const indb2b = getByKeyInDFPTargeting('indb2b');
const industry = getByKeyInDFPTargeting("05");
const responsibility = getByKeyInDFPTargeting("06");
const position = getByKeyInDFPTargeting("07");
const subscriptionLevel = getByKeyInDFPTargeting("slv");
const loggedIn = getByKeyInDFPTargeting("loggedIn");
const followedConcepts = getByKeyInDFPTargeting("followedConcepts");
const gender = getByKeyInDFPTargeting("gender");
const indb2b = getByKeyInDFPTargeting("indb2b");
eventData.user = { ...(industry && {

@@ -403,7 +403,7 @@ industry

const getByKeyInDFPTargeting = getByKeyInAdsArrayV1(dfpTargeting);
const id = getByKeyInDFPTargeting('auuid');
const title = getByKeyInDFPTargeting('title');
const categories = getByKeyInDFPTargeting('ca');
const topics = getByKeyInDFPTargeting('topic');
const admants = getByKeyInDFPTargeting('ad');
const id = getByKeyInDFPTargeting("auuid");
const title = getByKeyInDFPTargeting("title");
const categories = getByKeyInDFPTargeting("ca");
const topics = getByKeyInDFPTargeting("topic");
const admants = getByKeyInDFPTargeting("ad");
eventData.article = { ...(id && {

@@ -416,9 +416,9 @@ id

...(categories && {
categories: categories.split(',')
categories: categories.split(",")
}),
...(topics && {
topics: topics.split(',')
topics: topics.split(",")
}),
...(admants && {
admants: admants.split(',')
admants: admants.split(",")
})

@@ -430,7 +430,7 @@ };

const getByKeyInKruxTargeting = getByKeyInAdsArrayV1(kruxTargeting);
const type = getByKeyInKruxTargeting('genre');
const organisations = getByKeyInKruxTargeting('organisations');
const people = getByKeyInKruxTargeting('people');
const authors = getByKeyInKruxTargeting('authors');
const brand = getByKeyInKruxTargeting('brand');
const type = getByKeyInKruxTargeting("genre");
const organisations = getByKeyInKruxTargeting("organisations");
const people = getByKeyInKruxTargeting("people");
const authors = getByKeyInKruxTargeting("authors");
const brand = getByKeyInKruxTargeting("brand");
eventData.article = { ...eventData.article,

@@ -437,0 +437,0 @@ ...(brand && {

@@ -1,4 +0,4 @@

export default ({
PERMUTIVE_PUBLIC_API_KEY: 'b2b3b748-e1f6-4bd5-b2f2-26debc8075a3',
PERMUTIVE_PUBLIC_ID: 'e1c3fd73-dd41-4abd-b80b-4278d52bf7aa',
})
export default {
PERMUTIVE_PUBLIC_API_KEY: "b2b3b748-e1f6-4bd5-b2f2-26debc8075a3",
PERMUTIVE_PUBLIC_ID: "e1c3fd73-dd41-4abd-b80b-4278d52bf7aa",
};

@@ -11,3 +11,3 @@ {

},
"version": "5.0.0-beta.7"
"version": "5.0.0-beta.8"
}

@@ -1,9 +0,8 @@

import filterWithSchema, { getByKeyInAdsArrayV1 } from '../utils/filterWithSchema'
import * as schemas from '../schemas'
import filterWithSchema, { getByKeyInAdsArrayV1 } from "../utils/filterWithSchema";
import * as schemas from "../schemas";
export default class AdsApiV1 {
constructor(props = {} /* AdsApiV1 */) {
for (const prop in filterWithSchema(schemas.AdsApiV1, props)) {
this[prop] = props[prop]
this[prop] = props[prop];
}

@@ -13,19 +12,19 @@ }

toPageViewData() {
const { user, article } = this
const { user, article } = this;
const eventData = {}
const eventData = {};
if (user) {
const dfpTargeting = user.dfp && user.dfp.targeting
const dfpTargeting = user.dfp && user.dfp.targeting;
if (dfpTargeting) {
const getByKeyInDFPTargeting = getByKeyInAdsArrayV1(dfpTargeting)
const industry = getByKeyInDFPTargeting('05')
const responsibility = getByKeyInDFPTargeting('06')
const position = getByKeyInDFPTargeting('07')
const subscriptionLevel = getByKeyInDFPTargeting('slv')
const loggedIn = getByKeyInDFPTargeting('loggedIn')
const followedConcepts = getByKeyInDFPTargeting('followedConcepts')
const gender = getByKeyInDFPTargeting('gender')
const indb2b = getByKeyInDFPTargeting('indb2b')
const getByKeyInDFPTargeting = getByKeyInAdsArrayV1(dfpTargeting);
const industry = getByKeyInDFPTargeting("05");
const responsibility = getByKeyInDFPTargeting("06");
const position = getByKeyInDFPTargeting("07");
const subscriptionLevel = getByKeyInDFPTargeting("slv");
const loggedIn = getByKeyInDFPTargeting("loggedIn");
const followedConcepts = getByKeyInDFPTargeting("followedConcepts");
const gender = getByKeyInDFPTargeting("gender");
const indb2b = getByKeyInDFPTargeting("indb2b");

@@ -41,3 +40,3 @@ eventData.user = {

...(indb2b && { indb2b }),
}
};
}

@@ -47,28 +46,28 @@ }

if (article) {
const dfpTargeting = article.dfp && article.dfp.targeting
const kruxTargeting = article.krux && article.krux.attributes
const dfpTargeting = article.dfp && article.dfp.targeting;
const kruxTargeting = article.krux && article.krux.attributes;
if (dfpTargeting) {
const getByKeyInDFPTargeting = getByKeyInAdsArrayV1(dfpTargeting)
const id = getByKeyInDFPTargeting('auuid')
const title = getByKeyInDFPTargeting('title')
const categories = getByKeyInDFPTargeting('ca')
const topics = getByKeyInDFPTargeting('topic')
const admants = getByKeyInDFPTargeting('ad')
const getByKeyInDFPTargeting = getByKeyInAdsArrayV1(dfpTargeting);
const id = getByKeyInDFPTargeting("auuid");
const title = getByKeyInDFPTargeting("title");
const categories = getByKeyInDFPTargeting("ca");
const topics = getByKeyInDFPTargeting("topic");
const admants = getByKeyInDFPTargeting("ad");
eventData.article = {
...(id && { id }),
...(title && { title }),
...(categories && { categories: categories.split(',') }),
...(topics && { topics: topics.split(',') }),
...(admants && { admants: admants.split(',') }),
}
...(categories && { categories: categories.split(",") }),
...(topics && { topics: topics.split(",") }),
...(admants && { admants: admants.split(",") }),
};
}
if (kruxTargeting) {
const getByKeyInKruxTargeting = getByKeyInAdsArrayV1(kruxTargeting)
const type = getByKeyInKruxTargeting('genre')
const organisations = getByKeyInKruxTargeting('organisations')
const people = getByKeyInKruxTargeting('people')
const authors = getByKeyInKruxTargeting('authors')
const brand = getByKeyInKruxTargeting('brand')
const getByKeyInKruxTargeting = getByKeyInAdsArrayV1(kruxTargeting);
const type = getByKeyInKruxTargeting("genre");
const organisations = getByKeyInKruxTargeting("organisations");
const people = getByKeyInKruxTargeting("people");
const authors = getByKeyInKruxTargeting("authors");
const brand = getByKeyInKruxTargeting("brand");
eventData.article = {

@@ -81,9 +80,8 @@ ...eventData.article,

...(authors && { authors }),
}
};
}
}
return eventData
return eventData;
}
}

@@ -1,9 +0,8 @@

import filterWithSchema from '../utils/filterWithSchema'
import * as schemas from '../schemas'
import filterWithSchema from "../utils/filterWithSchema";
import * as schemas from "../schemas";
export default class AdsApiV2 {
constructor(props = {} /* AdsApiV2 */) {
for (const prop in filterWithSchema(schemas.AdsApiV2, props)) {
this[prop] = props[prop]
this[prop] = props[prop];
}

@@ -13,5 +12,5 @@ }

toPageViewData() {
const { user, article } = this
const { user, article } = this;
return ({
return {
...this,

@@ -23,8 +22,10 @@ ...(user && {

...(user.position && user.position.code && { position: user.position.code }),
...(user.responsibility && user.responsibility.code && { responsibility: user.responsibility.code }),
...(user.responsibility &&
user.responsibility.code && { responsibility: user.responsibility.code }),
...("loggedInStatus" in user && { loggedIn: user.loggedInStatus.toString() }),
...(user.followedConcepts && user.followedConcepts.length && { followedConcepts: user.followedConcepts }),
...(user.followedConcepts &&
user.followedConcepts.length && { followedConcepts: user.followedConcepts }),
...(user.hui && user.hui.indb2b && { indb2b: user.hui.indb2b }),
...(user.hui && user.hui.gender && { gender: user.hui.gender }),
}
},
}),

@@ -41,7 +42,6 @@ ...(article && {

...(article.topic && { topics: article.topic }),
}
})
})
},
}),
};
}
}
// Currently, this model is an alias for AdsApiV2
export { default } from './AdsApiV2'
export { default } from "./AdsApiV2";

@@ -1,3 +0,3 @@

import PageView from './PageView'
export { PageView }
export default { PageView }
import PageView from "./PageView";
export { PageView };
export default { PageView };

@@ -1,7 +0,7 @@

import * as schemas from '../schemas'
import filterWithSchema from '../utils/filterWithSchema'
import PermutiveEvent from './PermutiveEvent'
import AdsApiV1 from '../models/AdsApiV1'
import AdsApiV2 from '../models/AdsApiV2'
import AdsDataManager from '../models/AdsDataManager'
import * as schemas from "../schemas";
import filterWithSchema from "../utils/filterWithSchema";
import PermutiveEvent from "./PermutiveEvent";
import AdsApiV1 from "../models/AdsApiV1";
import AdsApiV2 from "../models/AdsApiV2";
import AdsDataManager from "../models/AdsDataManager";

@@ -12,23 +12,22 @@ /**

*/
const fromModel = (Model = AdsDataManager) => (props = {}) => {
const data = new Model(props)
return new PageView({
type: props.type,
rootId: props.rootId,
...data.toPageViewData()
})
}
const fromModel =
(Model = AdsDataManager) =>
(props = {}) => {
const data = new Model(props);
return new PageView({
type: props.type,
rootId: props.rootId,
...data.toPageViewData(),
});
};
export default class PageView extends PermutiveEvent {
constructor(eventData = {} /* PageView */) {
super()
super();
this.page = filterWithSchema(schemas.PageView, eventData)
this.page = filterWithSchema(schemas.PageView, eventData);
}
static formatFrom(data, mappingFunc) {
return mappingFunc
? mappingFunc(data)
: new PageView(data)
return mappingFunc ? mappingFunc(data) : new PageView(data);
}

@@ -41,3 +40,3 @@

static fromAdsDataManager(props = {}) {
return fromModel(AdsDataManager)(props)
return fromModel(AdsDataManager)(props);
}

@@ -50,3 +49,3 @@

static fromAdsApiV2(props = {}) {
return fromModel(AdsApiV2)(props)
return fromModel(AdsApiV2)(props);
}

@@ -59,5 +58,4 @@

static fromAdsApiV1(props = {}) {
return fromModel(AdsApiV1)(props)
return fromModel(AdsApiV1)(props);
}
}
export default class PermutiveEvent {
static formatFrom(data, mappingFunc) {
return mappingFunc
? mappingFunc(data)
: data
return mappingFunc ? mappingFunc(data) : data;
}
}
export const UserApiV1 = {
dfp: {
targeting: [
{ key: 'device_spoor_id', value: String },
{ key: 'guid', value: String },
{ key: '05', value: String },
{ key: '06', value: String },
{ key: '07', value: String },
{ key: 'slv', value: String },
{ key: 'loggedIn', value: Boolean },
{ key: 'followedConcepts', value: Array },
{ key: 'gender', value: String },
{ key: 'indb2b', value: String },
]
}
}
{ key: "device_spoor_id", value: String },
{ key: "guid", value: String },
{ key: "05", value: String },
{ key: "06", value: String },
{ key: "07", value: String },
{ key: "slv", value: String },
{ key: "loggedIn", value: Boolean },
{ key: "followedConcepts", value: Array },
{ key: "gender", value: String },
{ key: "indb2b", value: String },
],
},
};

@@ -21,19 +21,19 @@ export const ArticleApiV1 = {

targeting: [
{ key: 'auuid', value: String },
{ key: 'title', value: String },
{ key: 'ca', value: String },
{ key: 'topic', value: String },
{ key: 'ad', value: String },
]
{ key: "auuid", value: String },
{ key: "title", value: String },
{ key: "ca", value: String },
{ key: "topic", value: String },
{ key: "ad", value: String },
],
},
krux: {
attributes: [
{ key: 'brand', value: String },
{ key: 'genre', value: Array },
{ key: 'organisations', value: Array },
{ key: 'people', value: Array },
{ key: 'authors', value: Array },
]
}
}
{ key: "brand", value: String },
{ key: "genre", value: Array },
{ key: "organisations", value: Array },
{ key: "people", value: Array },
{ key: "authors", value: Array },
],
},
};

@@ -43,2 +43,2 @@ export const AdsApiV1 = {

article: ArticleApiV1,
}
};
export const UserIdentityV2 = {
uuid: String,
}
};

@@ -16,3 +16,3 @@ export const UserApiV2 = {

},
}
};

@@ -32,3 +32,3 @@ export const ArticleApiV2 = {

adUnit: Array,
}
};

@@ -38,2 +38,2 @@ export const AdsApiV2 = {

article: ArticleApiV2,
}
};
// Currently, this schema matches AdsApiV2
export * from './AdsApiV2'
export * from "./AdsApiV2";

@@ -1,3 +0,3 @@

export * from './AdsApiV1'
export * from './AdsApiV2'
export * from './PageView'
export * from "./AdsApiV1";
export * from "./AdsApiV2";
export * from "./PageView";

@@ -10,3 +10,3 @@ export const User = {

gender: String,
}
};

@@ -24,3 +24,3 @@ export const Article = {

brand: Array,
}
};

@@ -32,2 +32,2 @@ export const PageView = {

article: Article,
}
};
export default class VideoEngagement {
constructor (
public campaign: string,
public createdAt: string, // ISO 8601 string
public duration: number, // positive integer
public title: string,
public videoId: string,
public progress: number, // float 0 to 1
) {}
}
constructor(
public campaign: string,
public createdAt: string, // ISO 8601 string
public duration: number, // positive integer
public title: string,
public videoId: string,
public progress: number // float 0 to 1
) {}
}

@@ -66,29 +66,31 @@ import env from "../../env";

const script = document.createElement("script");
const p = /** @type {Promise<void>} */ (new Promise((resolve, reject) => {
if (globalName && window[globalName]) {
return resolve();
}
const p = /** @type {Promise<void>} */ (
new Promise((resolve, reject) => {
if (globalName && window[globalName]) {
return resolve();
}
scriptId && (script.id = scriptId);
script.onload = resolve;
script.crossorigin = "anonymous";
script.onerror = reject;
script.src = url;
scriptId && (script.id = scriptId);
script.onload = resolve;
script.crossorigin = "anonymous";
script.onerror = reject;
script.src = url;
for (let attributeName in attributes) {
script.setAttribute(attributeName, attributes[attributeName]);
}
for (let attributeName in attributes) {
script.setAttribute(attributeName, attributes[attributeName]);
}
document.body.appendChild(script);
document.body.appendChild(script);
setTimeout(() => {
if (!globalName || window[globalName]) {
resolve();
} else {
let e = new Error(`Can't load ${url}`);
e.target = script;
reject(e);
}
}, timeout);
}))
setTimeout(() => {
if (!globalName || window[globalName]) {
resolve();
} else {
let e = new Error(`Can't load ${url}`);
e.target = script;
reject(e);
}
}, timeout);
})
)
.then(() => {

@@ -95,0 +97,0 @@ if (globalName) {

@@ -1,13 +0,13 @@

import filterWithSchema from './filterWithSchema'
import filterWithSchema from "./filterWithSchema";
export const ConfigOptions = {
eventsCacheLimitBytes: Number
}
eventsCacheLimitBytes: Number,
};
export const filterConfigOptions = (configOptions = {}) => {
try {
return filterWithSchema(ConfigOptions, configOptions, { throwOnError: true })
return filterWithSchema(ConfigOptions, configOptions, { throwOnError: true });
} catch (e) {
console.warn(`Invalid config option: ${e.message}`)
console.warn(`Invalid config option: ${e.message}`);
}
}
};
// Ramda's is() function. See https://github.com/ramda/ramda/blob/v0.27.0/source/is.js
export const is = (Ctor, val) => val != null && val.constructor === Ctor
export const is = (Ctor, val) => val != null && val.constructor === Ctor;
export const getByKeyInAdsArrayV1 = targetingDPArray => key => {
const foundEl = targetingDPArray.find(el => el.key === key)
return foundEl && foundEl.value
}
export const getByKeyInAdsArrayV1 = (targetingDPArray) => (key) => {
const foundEl = targetingDPArray.find((el) => el.key === key);
return foundEl && foundEl.value;
};
const isAdsApiV1Array = array => {
return !!(array && array[0] && array[0].key && array[0].value)
}
const isAdsApiV1Array = (array) => {
return !!(array && array[0] && array[0].key && array[0].value);
};
// Exported for unit tests
const filterWithSchema = (schema, data = {}, options = { adsApiV1Array: false, throwOnError: false }) => {
const filterWithSchema = (
schema,
data = {},
options = { adsApiV1Array: false, throwOnError: false }
) => {
if (data === null) {
return
return;
}
const res = {}
let schemaKeys = schema
let dataKeys = data
const res = {};
let schemaKeys = schema;
let dataKeys = data;
if (options.adsApiV1Array) {
schemaKeys = schema.map(el => el.key)
dataKeys = data.map(el => el.key)
schemaKeys = schema.map((el) => el.key);
dataKeys = data.map((el) => el.key);
}
for (const key in schemaKeys) {
const value = options.adsApiV1Array ? getByKeyInAdsArrayV1(schemaKeys)(key) : dataKeys[key]
const schemaEl = options.adsApiV1Array ? getByKeyInAdsArrayV1(dataKeys)(key) : schemaKeys[key]
const value = options.adsApiV1Array ? getByKeyInAdsArrayV1(schemaKeys)(key) : dataKeys[key];
const schemaEl = options.adsApiV1Array ? getByKeyInAdsArrayV1(dataKeys)(key) : schemaKeys[key];

@@ -35,16 +39,18 @@ if (key in dataKeys && value) {

if (options.throwOnError) {
throw new Error(`[${key}] value [${value}] does not match ${schemaEl.name}`)
throw new Error(`[${key}] value [${value}] does not match ${schemaEl.name}`);
} else {
console.warn(`ads-permutive.filterWithSchema(): [${key}] value [${value}] does not match ${schemaEl.name}`)
console.warn(
`ads-permutive.filterWithSchema(): [${key}] value [${value}] does not match ${schemaEl.name}`
);
}
continue
continue;
}
if (is(Object, schemaEl)) {
res[key] = filterWithSchema(schemaEl, value)
res[key] = filterWithSchema(schemaEl, value);
} else if (is(Array, schemaEl)) {
// Check if array is Ads Api V1 Array - Array<Object> key and value props
res[key] = filterWithSchema(schemaEl, value, { adsApiV1Array: isAdsApiV1Array(schemaEl) })
res[key] = filterWithSchema(schemaEl, value, { adsApiV1Array: isAdsApiV1Array(schemaEl) });
} else {
res[key] = value
res[key] = value;
}

@@ -54,5 +60,5 @@ }

return res
}
return res;
};
export default filterWithSchema
export default filterWithSchema;

@@ -1,2 +0,2 @@

export * from './async'
export * from './filterWithSchema'
export * from "./async";
export * from "./filterWithSchema";

@@ -1,398 +0,395 @@

import PageView from '../src/models/PageView'
import adsPermutive from '../src'
import { adsApiV1Data, adsApiV2Data, adsDataManagerData, expectedPageView, expectedUserIdentity } from './stubbedResponses'
import env from '../env'
import PageView from "../src/models/PageView";
import adsPermutive from "../src";
import {
adsApiV1Data,
adsApiV2Data,
adsDataManagerData,
expectedPageView,
expectedUserIdentity,
} from "./stubbedResponses";
import env from "../env";
const EVENTS_CACHE_LIMIT_BYTES = 25e5
const EVENTS_CACHE_LIMIT_BYTES = 25e5;
const funcNames = [
'addon',
'identify',
'track',
'trigger',
'query',
'segment',
'segments',
'ready',
'on',
'once',
'user',
'consent'
]
"addon",
"identify",
"track",
"trigger",
"query",
"segment",
"segments",
"ready",
"on",
"once",
"user",
"consent",
];
const testPermutiveObjStruct = () => {
for (const funcName of funcNames) {
expect(global.permutive).toHaveProperty(funcName)
expect(global.permutive).toHaveProperty(funcName);
}
}
};
const testConfig = (options = {}) => {
expect(global.permutive.config.projectId).toBe(env.PERMUTIVE_PUBLIC_ID)
expect(global.permutive.config.apiKey).toBe(env.PERMUTIVE_PUBLIC_API_KEY)
expect(global.permutive.config.projectId).toBe(env.PERMUTIVE_PUBLIC_ID);
expect(global.permutive.config.apiKey).toBe(env.PERMUTIVE_PUBLIC_API_KEY);
for (const opt in options) {
expect(global.permutive.config[opt]).toBe(options[opt] || EVENTS_CACHE_LIMIT_BYTES)
expect(global.permutive.config[opt]).toBe(options[opt] || EVENTS_CACHE_LIMIT_BYTES);
}
}
};
describe('[ads-permutive setup()]', () => {
describe("[ads-permutive setup()]", () => {
afterEach(() => {
delete global['permutive']
delete global['googletag']
})
delete global["permutive"];
delete global["googletag"];
});
test('Should set global.permutive and global.googletag', () => {
jest.spyOn(console, 'warn').mockImplementationOnce(() => null)
adsPermutive.setup()
test("Should set global.permutive and global.googletag", () => {
jest.spyOn(console, "warn").mockImplementationOnce(() => null);
adsPermutive.setup();
expect(global).toHaveProperty('permutive')
expect(global).toHaveProperty('googletag')
expect(global).toHaveProperty("permutive");
expect(global).toHaveProperty("googletag");
testPermutiveObjStruct()
testConfig()
})
testPermutiveObjStruct();
testConfig();
});
test('Should set eventsCacheLimitBytes to allocate up to 12kB of events cache', () => {
const eventsCacheLimitBytes = 12e3
test("Should set eventsCacheLimitBytes to allocate up to 12kB of events cache", () => {
const eventsCacheLimitBytes = 12e3;
adsPermutive.setup({
eventsCacheLimitBytes
})
eventsCacheLimitBytes,
});
expect(global).toHaveProperty('permutive')
expect(global).toHaveProperty('googletag')
expect(global).toHaveProperty("permutive");
expect(global).toHaveProperty("googletag");
testPermutiveObjStruct()
testConfig({ eventsCacheLimitBytes })
})
testPermutiveObjStruct();
testConfig({ eventsCacheLimitBytes });
});
test('Should not set eventsCacheLimitBytes if not a Number', () => {
const spyWarn = jest.spyOn(console, 'warn')
const eventsCacheLimitBytes = 'meow'
test("Should not set eventsCacheLimitBytes if not a Number", () => {
const spyWarn = jest.spyOn(console, "warn");
const eventsCacheLimitBytes = "meow";
adsPermutive.setup({
eventsCacheLimitBytes
})
eventsCacheLimitBytes,
});
expect(spyWarn).toBeCalledWith('Invalid config option: [eventsCacheLimitBytes] value [meow] does not match Number')
spyWarn.mockReset()
expect(spyWarn).toBeCalledWith(
"Invalid config option: [eventsCacheLimitBytes] value [meow] does not match Number"
);
spyWarn.mockReset();
expect(global).toHaveProperty('permutive')
expect(global).toHaveProperty('googletag')
expect(global).toHaveProperty("permutive");
expect(global).toHaveProperty("googletag");
testPermutiveObjStruct()
testConfig()
})
testPermutiveObjStruct();
testConfig();
});
describe('isInitialised()', () => {
describe("isInitialised()", () => {
test("Should return true if setup() already called", () => {
const spy = jest.spyOn(console, "warn");
test('Should return true if setup() already called', () => {
const spy = jest.spyOn(console, 'warn')
adsPermutive.setup();
const initialised = adsPermutive.isInitialised();
expect(initialised).toEqual(true);
spy.mockReset();
});
adsPermutive.setup()
const initialised = adsPermutive.isInitialised()
expect(initialised).toEqual(true)
spy.mockReset()
})
test("Should return false if setup() not yet called, and log a warning", () => {
const spy = jest.spyOn(console, "warn");
test('Should return false if setup() not yet called, and log a warning', () => {
const spy = jest.spyOn(console, 'warn')
const initialised = adsPermutive.isInitialised();
expect(spy).toBeCalledWith(
"ads-permutive.isInitialised(): window.permutive not initialised. Perhaps setup() has not been executed yet?"
);
expect(initialised).toEqual(false);
spy.mockReset();
});
});
});
const initialised = adsPermutive.isInitialised()
expect(spy).toBeCalledWith('ads-permutive.isInitialised(): window.permutive not initialised. Perhaps setup() has not been executed yet?')
expect(initialised).toEqual(false)
spy.mockReset()
})
})
})
describe('[ads-permutive]', () => {
describe("[ads-permutive]", () => {
beforeEach(() => {
adsPermutive.setup()
})
adsPermutive.setup();
});
afterEach(() => {
delete global['permutive']
delete global['googletag']
})
delete global["permutive"];
delete global["googletag"];
});
describe('getSegments()', () => {
describe("getSegments()", () => {
beforeEach(() => {
window.localStorage.clear()
})
window.localStorage.clear();
});
test('Should return an array of strings if localStorage\'s item _pdfps exists', () => {
window.localStorage.setItem('_pdfps', '["ciao","hello"]')
const segments = adsPermutive.getSegments()
expect(segments).toEqual(["ciao", "hello"])
})
test("Should return an array of strings if localStorage's item _pdfps exists", () => {
window.localStorage.setItem("_pdfps", '["ciao","hello"]');
const segments = adsPermutive.getSegments();
expect(segments).toEqual(["ciao", "hello"]);
});
test('Should return an empty array if localStorage\'s item _pdfps doesn\'t exist', () => {
const segments = adsPermutive.getSegments()
expect(segments).toEqual([])
})
test("Should return an empty array if localStorage's item _pdfps doesn't exist", () => {
const segments = adsPermutive.getSegments();
expect(segments).toEqual([]);
});
});
})
describe('getPermutiveId()', () => {
describe("getPermutiveId()", () => {
beforeEach(() => {
window.localStorage.clear()
})
window.localStorage.clear();
});
test('Should return a string if localStorage\'s item permutive-id exists', () => {
window.localStorage.setItem('permutive-id', 'some-complicated-id')
const permutiveID = adsPermutive.getPermutiveId()
expect(permutiveID).toEqual('some-complicated-id')
})
test("Should return a string if localStorage's item permutive-id exists", () => {
window.localStorage.setItem("permutive-id", "some-complicated-id");
const permutiveID = adsPermutive.getPermutiveId();
expect(permutiveID).toEqual("some-complicated-id");
});
test('Should return null if localStorage\'s item permutive-id doesn\t exist', () => {
const permutiveID = adsPermutive.getPermutiveId()
expect(permutiveID).toEqual(null)
})
test("Should return null if localStorage's item permutive-id doesn\t exist", () => {
const permutiveID = adsPermutive.getPermutiveId();
expect(permutiveID).toEqual(null);
});
});
})
describe('setTargeting()', () => {
test('should call googletag.pubads().setTargeting() with `permutive` and the result of `getSegments()`', () => {
jest.spyOn(adsPermutive, 'getSegments').mockReturnValue('mock-segments');
describe("setTargeting()", () => {
test("should call googletag.pubads().setTargeting() with `permutive` and the result of `getSegments()`", () => {
jest.spyOn(adsPermutive, "getSegments").mockReturnValue("mock-segments");
global.googletag = {
pubads: jest.fn().mockReturnValue({
setTargeting: jest.fn(),
getTargeting: () => []
getTargeting: () => [],
}),
cmd: []
}
cmd: [],
};
adsPermutive.setTargeting();
global.googletag.cmd.forEach((func) => {
func();
expect(global.googletag.pubads().setTargeting).toBeCalledWith('permutive', 'mock-segments');
})
expect(global.googletag.pubads().setTargeting).toBeCalledWith("permutive", "mock-segments");
});
});
test('should call googletag.pubads().setTargeting() with `permutive-id` and the result of `getPermutiveId()`', () => {
jest.spyOn(adsPermutive, 'getPermutiveId').mockReturnValue('mock-id');
test("should call googletag.pubads().setTargeting() with `permutive-id` and the result of `getPermutiveId()`", () => {
jest.spyOn(adsPermutive, "getPermutiveId").mockReturnValue("mock-id");
global.googletag = {
pubads: jest.fn().mockReturnValue({
setTargeting: jest.fn(),
getTargeting: () => []
getTargeting: () => [],
}),
cmd: []
}
cmd: [],
};
adsPermutive.setTargeting();
global.googletag.cmd.forEach((func) => {
func();
expect(global.googletag.pubads().setTargeting).toBeCalledWith('permutive-id', 'mock-id');
})
expect(global.googletag.pubads().setTargeting).toBeCalledWith("permutive-id", "mock-id");
});
});
// TODO Can't test this but we should
test.skip('should call googletag.pubads().setTargeting() with `view-id` and the result of `getViewId()`', () => {});
})
test.skip("should call googletag.pubads().setTargeting() with `view-id` and the result of `getViewId()`", () => {});
});
describe('identifyUser()', () => {
test('Should call permutive.identify() with the uuid', () => {
const spy = jest.spyOn(global.permutive, 'identify')
adsPermutive.identifyUser(adsApiV2Data.user)
describe("identifyUser()", () => {
test("Should call permutive.identify() with the uuid", () => {
const spy = jest.spyOn(global.permutive, "identify");
adsPermutive.identifyUser(adsApiV2Data.user);
expect(spy).toBeCalledWith(expectedUserIdentity)
spy.mockReset()
})
expect(spy).toBeCalledWith(expectedUserIdentity);
spy.mockReset();
});
test('Should not call permutive.identify() if no uuid is available in the targeting', () => {
const spy = jest.spyOn(global.permutive, 'identify')
adsPermutive.identifyUser({ ciao: 'amigo' })
test("Should not call permutive.identify() if no uuid is available in the targeting", () => {
const spy = jest.spyOn(global.permutive, "identify");
adsPermutive.identifyUser({ ciao: "amigo" });
expect(spy).not.toBeCalled()
spy.mockReset()
})
expect(spy).not.toBeCalled();
spy.mockReset();
});
});
})
describe("trackPageView()", () => {
test("Should call permutive.addon() & marshal the data into the correct Permutive PageView schema", () => {
const spy = jest.spyOn(global.permutive, "addon");
describe('trackPageView()', () => {
test('Should call permutive.addon() & marshal the data into the correct Permutive PageView schema', () => {
const spy = jest.spyOn(global.permutive, 'addon')
adsPermutive.trackPageView(expectedPageView.page);
expect(spy).toBeCalledWith("web", expectedPageView);
spy.mockReset();
});
adsPermutive.trackPageView(expectedPageView.page)
expect(spy).toBeCalledWith('web', expectedPageView)
spy.mockReset()
})
test("Should call permutive.addon() & marshal the data into the correct schema, using the formatter for Ads Data Manager", () => {
const spy = jest.spyOn(global.permutive, "addon");
test('Should call permutive.addon() & marshal the data into the correct schema, using the formatter for Ads Data Manager', () => {
const spy = jest.spyOn(global.permutive, 'addon')
const pageView = adsPermutive.fromAdsDataToPageView(adsDataManagerData);
adsPermutive.trackPageView(pageView)
adsPermutive.trackPageView(pageView);
expect(spy).toBeCalledWith('web', expectedPageView)
expect(spy).toBeCalledWith("web", expectedPageView);
spy.mockReset()
})
spy.mockReset();
});
test('Should call permutive.addon() & marshal the data into the correct schema, using the formatter for Ads API V2', () => {
const spy = jest.spyOn(global.permutive, 'addon')
test("Should call permutive.addon() & marshal the data into the correct schema, using the formatter for Ads API V2", () => {
const spy = jest.spyOn(global.permutive, "addon");
const pageView = adsPermutive.fromAdsApiV2ToPageView(adsApiV2Data);
adsPermutive.trackPageView(pageView)
adsPermutive.trackPageView(pageView);
expect(spy).toBeCalledWith('web', expectedPageView)
expect(spy).toBeCalledWith("web", expectedPageView);
spy.mockReset()
})
spy.mockReset();
});
test('Should call permutive.addon() & marshal the data into the correct schema, using the fromAdsApiV2 mapping function', () => {
const spy = jest.spyOn(global.permutive, 'addon')
test("Should call permutive.addon() & marshal the data into the correct schema, using the fromAdsApiV2 mapping function", () => {
const spy = jest.spyOn(global.permutive, "addon");
adsPermutive.trackPageView(adsApiV2Data, {
mappingFunc: PageView.fromAdsApiV2
})
expect(spy).toBeCalledWith('web', expectedPageView)
mappingFunc: PageView.fromAdsApiV2,
});
expect(spy).toBeCalledWith("web", expectedPageView);
spy.mockReset()
})
spy.mockReset();
});
test('Should call permutive.addon() & Does not throw any error if user arg is missing', () => {
const spy = jest.spyOn(global.permutive, 'addon')
const inputData = { article: adsApiV2Data.article, type: adsApiV2Data.type }
test("Should call permutive.addon() & Does not throw any error if user arg is missing", () => {
const spy = jest.spyOn(global.permutive, "addon");
const inputData = { article: adsApiV2Data.article, type: adsApiV2Data.type };
const pageView = adsPermutive.fromAdsApiV2ToPageView(inputData);
adsPermutive.trackPageView(pageView)
adsPermutive.trackPageView(pageView);
expect(spy).toBeCalledWith('web', {
expect(spy).toBeCalledWith("web", {
page: {
article: expectedPageView.page.article,
type: expectedPageView.page.type
}
})
spy.mockReset()
})
type: expectedPageView.page.type,
},
});
spy.mockReset();
});
test('Should call permutive.addon() & Does not throw any error of page arg is missing', () => {
const spy = jest.spyOn(global.permutive, 'addon')
const inputData = { article: adsApiV2Data.article, type: adsApiV2Data.type }
test("Should call permutive.addon() & Does not throw any error of page arg is missing", () => {
const spy = jest.spyOn(global.permutive, "addon");
const inputData = { article: adsApiV2Data.article, type: adsApiV2Data.type };
const pageView = adsPermutive.fromAdsApiV2ToPageView(inputData);
adsPermutive.trackPageView(pageView)
adsPermutive.trackPageView(pageView);
expect(spy).toBeCalledWith('web', {
expect(spy).toBeCalledWith("web", {
page: {
article: expectedPageView.page.article,
type: expectedPageView.page.type
}
})
spy.mockReset()
})
type: expectedPageView.page.type,
},
});
spy.mockReset();
});
test('Should call permutive.addon() & Marshals the data into the correct schema from Ads API V1', () => {
const spy = jest.spyOn(global.permutive, 'addon')
test("Should call permutive.addon() & Marshals the data into the correct schema from Ads API V1", () => {
const spy = jest.spyOn(global.permutive, "addon");
const pageView = adsPermutive.fromAdsApiV1ToPageView(adsApiV1Data);
adsPermutive.trackPageView(pageView)
adsPermutive.trackPageView(pageView);
expect(spy).toBeCalledWith('web', expectedPageView)
spy.mockReset()
})
expect(spy).toBeCalledWith("web", expectedPageView);
spy.mockReset();
});
test('Should call permutive.addon() & Marshals the partial data into the correct schema from Ads API V1', () => {
const spy = jest.spyOn(global.permutive, 'addon')
test("Should call permutive.addon() & Marshals the partial data into the correct schema from Ads API V1", () => {
const spy = jest.spyOn(global.permutive, "addon");
const inputData = {
type: 'article',
type: "article",
article: {
dfp: {
targeting: [
adsApiV1Data.article.dfp.targeting.find(el => el.key === 'topic')
]
}
}
}
targeting: [adsApiV1Data.article.dfp.targeting.find((el) => el.key === "topic")],
},
},
};
const expectedOutput = {
page: {
type: 'article',
type: "article",
article: {
topics: expectedPageView.page.article.topics,
}
}
}
},
},
};
const pageView = adsPermutive.fromAdsApiV1ToPageView(inputData);
adsPermutive.trackPageView(pageView)
adsPermutive.trackPageView(pageView);
expect(spy).toBeCalledWith('web', expectedOutput)
spy.mockReset()
})
})
expect(spy).toBeCalledWith("web", expectedOutput);
spy.mockReset();
});
});
describe('trackEvent()', () => {
describe("trackEvent()", () => {
const videoTrackingInfo = {
videoId: 'WBtgMM3qLhg',
videoId: "WBtgMM3qLhg",
progress: 0.5,
duration: 200,
createdAt: '2019-05-22T11:00:00',
title: 'DYSFUNCTIONAL: exploring sustainability through design',
campaign: 'FT Rethink',
}
createdAt: "2019-05-22T11:00:00",
title: "DYSFUNCTIONAL: exploring sustainability through design",
campaign: "FT Rethink",
};
test('Should not call permutive.track() if event name is not a string', () => {
const spy = jest.spyOn(console, 'warn')
adsPermutive.trackEvent(videoTrackingInfo)
expect(spy).toBeCalledWith('ads-permutive.trackEvent(): eventName must be a non-empty string')
spy.mockReset()
})
test("Should not call permutive.track() if event name is not a string", () => {
const spy = jest.spyOn(console, "warn");
adsPermutive.trackEvent(videoTrackingInfo);
expect(spy).toBeCalledWith(
"ads-permutive.trackEvent(): eventName must be a non-empty string"
);
spy.mockReset();
});
test('Should not call permutive.track() if event name is an empty string', () => {
const spy = jest.spyOn(console, 'warn')
adsPermutive.trackEvent('', videoTrackingInfo)
expect(spy).toBeCalledWith('ads-permutive.trackEvent(): eventName must be a non-empty string')
spy.mockReset()
})
test("Should not call permutive.track() if event name is an empty string", () => {
const spy = jest.spyOn(console, "warn");
adsPermutive.trackEvent("", videoTrackingInfo);
expect(spy).toBeCalledWith(
"ads-permutive.trackEvent(): eventName must be a non-empty string"
);
spy.mockReset();
});
test('Should call permutive.track() with event VideoEngagement and video meta data', () => {
const spy = jest.spyOn(global.permutive, 'track')
const eventName = 'VideoEngagement'
test("Should call permutive.track() with event VideoEngagement and video meta data", () => {
const spy = jest.spyOn(global.permutive, "track");
const eventName = "VideoEngagement";
adsPermutive.trackEvent(eventName, videoTrackingInfo)
expect(spy).toBeCalledWith(eventName, videoTrackingInfo)
spy.mockReset()
})
adsPermutive.trackEvent(eventName, videoTrackingInfo);
expect(spy).toBeCalledWith(eventName, videoTrackingInfo);
spy.mockReset();
});
});
})
describe('getViewId', () => {
test('Should return undefined if permutive\' view-id takes too long to be set', async () => {
describe("getViewId", () => {
test("Should return undefined if permutive' view-id takes too long to be set", async () => {
setTimeout(() => {
window.permutive._internals = {
state: {
viewId: 'something_misterious'
}
}
}, 7500)
viewId: "something_misterious",
},
};
}, 7500);
const viewId = await adsPermutive.getViewId()
expect(viewId).toEqual(undefined)
}, 8000)
const viewId = await adsPermutive.getViewId();
expect(viewId).toEqual(undefined);
}, 8000);
test('Should return undefined if permutive\' view-id is set quickly enough', async () => {
test("Should return undefined if permutive' view-id is set quickly enough", async () => {
setTimeout(() => {
window.permutive._internals = {
state: {
viewId: 'something_misterious'
}
}
}, 4500)
viewId: "something_misterious",
},
};
}, 4500);
const viewId = await adsPermutive.getViewId()
expect(viewId).toEqual(window.permutive._internals.state.viewId)
})
})
})
const viewId = await adsPermutive.getViewId();
expect(viewId).toEqual(window.permutive._internals.state.viewId);
});
});
});

@@ -1,80 +0,70 @@

import PageView from '../../src/models/PageView'
import PermutiveEvent from '../../src/models/PermutiveEvent'
import { adsApiV1Data, adsApiV2Data, expectedPageView } from '../stubbedResponses'
import PageView from "../../src/models/PageView";
import PermutiveEvent from "../../src/models/PermutiveEvent";
import { adsApiV1Data, adsApiV2Data, expectedPageView } from "../stubbedResponses";
describe('[events.PageView]', () => {
describe("[events.PageView]", () => {
describe("constructor()", () => {
test("Should create a new empty instance with default mappingFunc for Ads API V2", () => {
const event = new PageView();
describe('constructor()', () => {
expect(event).toBeInstanceOf(PermutiveEvent);
expect(event).toBeInstanceOf(PageView);
expect(event).toEqual({ page: {} });
});
test('Should create a new empty instance with default mappingFunc for Ads API V2', () => {
const event = new PageView()
test("Should create a new empty instance with raw data and default mappingFunc", () => {
const event = new PageView({ user: { industry: "law" } });
expect(event).toBeInstanceOf(PermutiveEvent)
expect(event).toBeInstanceOf(PageView)
expect(event).toEqual({ page: {} })
})
test('Should create a new empty instance with raw data and default mappingFunc', () => {
const event = new PageView({ user: { industry: 'law' } })
expect(event).toBeInstanceOf(PageView)
expect(event).toBeInstanceOf(PageView);
expect(event).toEqual({
page: {
user: {
industry: 'law'
}
}
})
})
industry: "law",
},
},
});
});
});
})
describe("PageView.formatFrom()", () => {
test("Should map the input data to a PageView event using the default mappingFunc for Ads API V2", () => {
const event = PageView.formatFrom(adsApiV2Data, PageView.fromAdsApiV2);
expect(event).toBeInstanceOf(PageView);
expect(event).toEqual(expectedPageView);
});
describe('PageView.formatFrom()', () => {
test("Should map the input data to a PageView event using the custom mappingFunc", () => {
const event = PageView.formatFrom(adsApiV1Data, PageView.fromAdsApiV1);
expect(event).toBeInstanceOf(PageView);
expect(event).toEqual(expectedPageView);
});
});
test('Should map the input data to a PageView event using the default mappingFunc for Ads API V2', () => {
const event = PageView.formatFrom(adsApiV2Data, PageView.fromAdsApiV2)
expect(event).toBeInstanceOf(PageView)
expect(event).toEqual(expectedPageView)
})
describe("PageView.fromAdsApiV1()", () => {
test("Should map the input Ads API V1 data to a PageView event", () => {
const event = PageView.fromAdsApiV1(adsApiV1Data);
expect(event).toBeInstanceOf(PageView);
expect(event).toEqual(expectedPageView);
});
test('Should map the input data to a PageView event using the custom mappingFunc', () => {
const event = PageView.formatFrom(adsApiV1Data, PageView.fromAdsApiV1)
expect(event).toBeInstanceOf(PageView)
expect(event).toEqual(expectedPageView)
})
test("Should return an empty event if no data passed as arg", () => {
const event = PageView.fromAdsApiV1();
expect(event).toBeInstanceOf(PageView);
expect(event).toEqual({ page: {} });
});
});
})
describe("PageView.fromAdsApiV2()", () => {
test("Should map the input Ads API V2 data to a PageView event", () => {
const event = PageView.fromAdsApiV2(adsApiV2Data);
expect(event).toBeInstanceOf(PageView);
expect(event).toEqual(expectedPageView);
});
describe('PageView.fromAdsApiV1()', () => {
test('Should map the input Ads API V1 data to a PageView event', () => {
const event = PageView.fromAdsApiV1(adsApiV1Data)
expect(event).toBeInstanceOf(PageView)
expect(event).toEqual(expectedPageView)
})
test('Should return an empty event if no data passed as arg', () => {
const event = PageView.fromAdsApiV1()
expect(event).toBeInstanceOf(PageView)
expect(event).toEqual({ page: {} })
})
})
describe('PageView.fromAdsApiV2()', () => {
test('Should map the input Ads API V2 data to a PageView event', () => {
const event = PageView.fromAdsApiV2(adsApiV2Data)
expect(event).toBeInstanceOf(PageView)
expect(event).toEqual(expectedPageView)
})
test('Should return an empty event if no data passed as arg', () => {
const event = PageView.fromAdsApiV2()
expect(event).toBeInstanceOf(PageView)
expect(event).toEqual({ page: {} })
})
})
})
test("Should return an empty event if no data passed as arg", () => {
const event = PageView.fromAdsApiV2();
expect(event).toBeInstanceOf(PageView);
expect(event).toEqual({ page: {} });
});
});
});

@@ -1,211 +0,205 @@

const type = 'article'
const rootId = 'abc123'
const type = "article";
const rootId = "abc123";
const adsApiV1User = {
"uuid": "1a2b3c4d-1a2b-1a2b-1a2b-1a2b3c4d5e6f",
"dfp": {
"targeting": [
uuid: "1a2b3c4d-1a2b-1a2b-1a2b-1a2b3c4d5e6f",
dfp: {
targeting: [
{
"name": "Spoor ID of Browser/Device",
"key": "device_spoor_id",
"value": "d4c3b2a1-b2a1-b2a1-b2a1-f6e5d4c3b2a1"
name: "Spoor ID of Browser/Device",
key: "device_spoor_id",
value: "d4c3b2a1-b2a1-b2a1-b2a1-f6e5d4c3b2a1",
},
{
"name": "User UUID",
"key": "guid",
"value": "1a2b3c4d-1a2b-1a2b-1a2b-1a2b3c4d5e6f"
name: "User UUID",
key: "guid",
value: "1a2b3c4d-1a2b-1a2b-1a2b-1a2b3c4d5e6f",
},
{
"name": "subscription",
"key": "slv",
"value": "int"
name: "subscription",
key: "slv",
value: "int",
},
{
"name": "loggedInStatus",
"key": "loggedIn",
"value": true
name: "loggedInStatus",
key: "loggedIn",
value: true,
},
{
"name": "Followed Concepts",
"key": "followedConcepts",
"value": [
name: "Followed Concepts",
key: "followedConcepts",
value: [
{
"name": "Coronavirus pandemic",
"uuid": "87e110e6-2170-408b-b267-d3b6bdbfeaa3"
name: "Coronavirus pandemic",
uuid: "87e110e6-2170-408b-b267-d3b6bdbfeaa3",
},
{
"name": "England",
"uuid": "4327e5de-2361-40f9-bc70-47fb918cb1ba"
}
]
name: "England",
uuid: "4327e5de-2361-40f9-bc70-47fb918cb1ba",
},
],
},
{
"name": "industry",
"key": "05",
"value": "law"
name: "industry",
key: "05",
value: "law",
},
{
"name": "responsibility",
"key": "06",
"value": "pat"
name: "responsibility",
key: "06",
value: "pat",
},
{
"name": "position",
"key": "07",
"value": "pr"
name: "position",
key: "07",
value: "pr",
},
{
key: 'gender',
value: 'M'
key: "gender",
value: "M",
},
{
key: 'indb2b',
value: 'law'
key: "indb2b",
value: "law",
},
]
],
},
"krux": {
"attributes": [
krux: {
attributes: [
{
"name": "Spoor ID of Browser/Device",
"key": "device_spoor_id",
"value": "d4c3b2a1-b2a1-b2a1-b2a1-f6e5d4c3b2a1"
name: "Spoor ID of Browser/Device",
key: "device_spoor_id",
value: "d4c3b2a1-b2a1-b2a1-b2a1-f6e5d4c3b2a1",
},
{
"name": "User UUID",
"key": "guid",
"value": "1a2b3c4d-1a2b-1a2b-1a2b-1a2b3c4d5e6f"
name: "User UUID",
key: "guid",
value: "1a2b3c4d-1a2b-1a2b-1a2b-1a2b3c4d5e6f",
},
{
"name": "subscription",
"key": "subscription_level",
"value": "int"
name: "subscription",
key: "subscription_level",
value: "int",
},
{
"name": "loggedInStatus",
"key": "loggedIn",
"value": true
name: "loggedInStatus",
key: "loggedIn",
value: true,
},
{
"name": "Followed Concepts",
"key": "followedConcepts",
"value": [
name: "Followed Concepts",
key: "followedConcepts",
value: [
{
"name": "Coronavirus pandemic",
"uuid": "87e110e6-2170-408b-b267-d3b6bdbfeaa3"
name: "Coronavirus pandemic",
uuid: "87e110e6-2170-408b-b267-d3b6bdbfeaa3",
},
{
"name": "England",
"uuid": "4327e5de-2361-40f9-bc70-47fb918cb1ba"
}
]
name: "England",
uuid: "4327e5de-2361-40f9-bc70-47fb918cb1ba",
},
],
},
{
"name": "industry",
"key": "industry",
"value": "law"
name: "industry",
key: "industry",
value: "law",
},
{
"name": "responsibility",
"key": "job_responsibility",
"value": "pat"
name: "responsibility",
key: "job_responsibility",
value: "pat",
},
{
"name": "position",
"key": "job_position",
"value": "pr"
}
]
}
}
name: "position",
key: "job_position",
value: "pr",
},
],
},
};
const adsApiV2User = {
"uuid": "1a2b3c4d-1a2b-1a2b-1a2b-1a2b3c4d5e6f",
"spoorId": "d4c3b2a1-b2a1-b2a1-b2a1-f6e5d4c3b2a1",
"subscriptionLevel": "int",
"loggedInStatus": true,
"followedConcepts": [
uuid: "1a2b3c4d-1a2b-1a2b-1a2b-1a2b3c4d5e6f",
spoorId: "d4c3b2a1-b2a1-b2a1-b2a1-f6e5d4c3b2a1",
subscriptionLevel: "int",
loggedInStatus: true,
followedConcepts: [
{
"name": "Coronavirus pandemic",
"uuid": "87e110e6-2170-408b-b267-d3b6bdbfeaa3"
name: "Coronavirus pandemic",
uuid: "87e110e6-2170-408b-b267-d3b6bdbfeaa3",
},
{
"name": "England",
"uuid": "4327e5de-2361-40f9-bc70-47fb918cb1ba"
name: "England",
uuid: "4327e5de-2361-40f9-bc70-47fb918cb1ba",
},
],
"industry": {
"code": "law",
"description": "Legal services"
industry: {
code: "law",
description: "Legal services",
},
"responsibility": {
"code": "pat",
"description": "HR/Training"
responsibility: {
code: "pat",
description: "HR/Training",
},
"position": {
"code": "pr",
"description": "Professional"
position: {
code: "pr",
description: "Professional",
},
hui: {
indb2b: 'law',
gender: 'M',
indb2b: "law",
gender: "M",
},
}
};
const adsApiV1Article = {
"uuid": "a31bb1d6-60f4-11e9-b285-3acd5d43599e",
"dfp": {
"targeting": [
uuid: "a31bb1d6-60f4-11e9-b285-3acd5d43599e",
dfp: {
targeting: [
{
"name": "articleUUID",
"key": "auuid",
"value": "a31bb1d6-60f4-11e9-b285-3acd5d43599e"
name: "articleUUID",
key: "auuid",
value: "a31bb1d6-60f4-11e9-b285-3acd5d43599e",
},
{
"name": "articleTitle",
"key": "title",
"value": "Saudi Aramco in talks to buy Reliance Industries stake"
name: "articleTitle",
key: "title",
value: "Saudi Aramco in talks to buy Reliance Industries stake",
},
{
"name": "admants",
"key": "ad",
"value": "b26,bs08,bs10,bs11,bs13,bs18,bs24,bs27,bs28,bs30,cc_moodys1,cc_moodys,e1,ft02,ft11,ft14,ft19,ft25,ft31,ft32,ft38,ft39,ft40,ft46,ft56,ft59,ft69,ft70,s03,s06,sm02,sm06,sr02"
name: "admants",
key: "ad",
value:
"b26,bs08,bs10,bs11,bs13,bs18,bs24,bs27,bs28,bs30,cc_moodys1,cc_moodys,e1,ft02,ft11,ft14,ft19,ft25,ft31,ft32,ft38,ft39,ft40,ft46,ft56,ft59,ft69,ft70,s03,s06,sm02,sm06,sr02",
},
{
"name": "categories",
"key": "ca",
"value": "business,company,stocks"
name: "categories",
key: "ca",
value: "business,company,stocks",
},
{
"name": "topics",
"key": "topic",
"value": "Mergers & Acquisitions,Middle Eastern companies,Oil & Gas industry,Oil,Natural resources,Markets,Energy sector,Companies,Commodities"
}
name: "topics",
key: "topic",
value:
"Mergers & Acquisitions,Middle Eastern companies,Oil & Gas industry,Oil,Natural resources,Markets,Energy sector,Companies,Commodities",
},
],
"adUnit": [
"companies",
"energy"
]
adUnit: ["companies", "energy"],
},
"krux": {
"attributes": [
krux: {
attributes: [
{
"name": "organisations",
"key": "organisations",
"value": [
"Saudi Aramco",
"Reliance Industries Ltd"
]
name: "organisations",
key: "organisations",
value: ["Saudi Aramco", "Reliance Industries Ltd"],
},
{
"name": "genre",
"key": "genre",
"value": [
"News"
]
name: "genre",
key: "genre",
value: ["News"],
},
{
"name": "topics",
"key": "topics",
"value": [
name: "topics",
key: "topics",
value: [
"Mergers & Acquisitions",

@@ -219,34 +213,24 @@ "Middle Eastern companies",

"Companies",
"Commodities"
]
"Commodities",
],
},
{
"name": "brand",
"key": "brand",
"value": [
"The Aesthete",
"How To Spend It"
]
name: "brand",
key: "brand",
value: ["The Aesthete", "How To Spend It"],
},
{
"name": "people",
"key": "people",
"value": [
"Simon Mundy",
"Anjli Raval"
]
name: "people",
key: "people",
value: ["Simon Mundy", "Anjli Raval"],
},
{
"name": "authors",
"key": "authors",
"value": [
'Nicholas Megaw',
'Stephen Morris',
'Robert Smith'
]
name: "authors",
key: "authors",
value: ["Nicholas Megaw", "Stephen Morris", "Robert Smith"],
},
{
"name": "admants",
"key": "ad",
"value": [
name: "admants",
key: "ad",
value: [
"b26",

@@ -284,28 +268,19 @@ "bs08",

"sm06",
"sr02"
]
"sr02",
],
},
{
"name": "categories",
"key": "ca",
"value": [
'business',
'company',
'stocks'
]
}
]
}
}
name: "categories",
key: "ca",
value: ["business", "company", "stocks"],
},
],
},
};
const adsApiV2Article = {
"uuid": "a31bb1d6-60f4-11e9-b285-3acd5d43599e",
"organisation": [
"Saudi Aramco",
"Reliance Industries Ltd"
],
"genre": [
"News"
],
"topic": [
uuid: "a31bb1d6-60f4-11e9-b285-3acd5d43599e",
organisation: ["Saudi Aramco", "Reliance Industries Ltd"],
genre: ["News"],
topic: [
"Mergers & Acquisitions",

@@ -319,19 +294,9 @@ "Middle Eastern companies",

"Companies",
"Commodities"
"Commodities",
],
"brand": [
"The Aesthete",
"How To Spend It"
],
"person": [
"Simon Mundy",
"Anjli Raval"
],
"author": [
'Nicholas Megaw',
'Stephen Morris',
'Robert Smith'
],
"title": "Saudi Aramco in talks to buy Reliance Industries stake",
"admants": [
brand: ["The Aesthete", "How To Spend It"],
person: ["Simon Mundy", "Anjli Raval"],
author: ["Nicholas Megaw", "Stephen Morris", "Robert Smith"],
title: "Saudi Aramco in talks to buy Reliance Industries stake",
admants: [
"b26",

@@ -369,15 +334,8 @@ "bs08",

"sm06",
"sr02"
"sr02",
],
"categories": [
'business',
'company',
'stocks'
],
"specialReport": [],
"adUnit": [
"companies",
"energy"
]
}
categories: ["business", "company", "stocks"],
specialReport: [],
adUnit: ["companies", "energy"],
};

@@ -389,3 +347,3 @@ export const adsApiV1Data = {

article: adsApiV1Article,
}
};

@@ -397,9 +355,7 @@ export const adsApiV2Data = {

article: adsApiV2Article,
}
};
export const adsDataManagerData = adsApiV2Data
export const adsDataManagerData = adsApiV2Data;
export const expectedUserIdentity = [
{ id: adsApiV2User.uuid, tag: 'GUID' },
]
export const expectedUserIdentity = [{ id: adsApiV2User.uuid, tag: "GUID" }];

@@ -431,4 +387,4 @@ export const expectedPageView = {

title: adsApiV2Article.title,
}
}
}
},
},
};

@@ -1,55 +0,47 @@

import * as async from '../../src/utils/async'
import * as async from "../../src/utils/async";
describe('[utils.async]', () => {
describe("[utils.async]", () => {
afterEach(() => {
document.body.querySelectorAll('script').forEach(node => node.remove())
})
document.body.querySelectorAll("script").forEach((node) => node.remove());
});
describe('loadScript()', () => {
describe("loadScript()", () => {
test("Should load a script asynchronously", async () => {
const loadedSuccess = await async.loadScript("123");
expect(loadedSuccess).toEqual(true);
expect(document.body.getElementsByTagName("script").length).toEqual(1);
});
});
test('Should load a script asynchronously', async () => {
const loadedSuccess = await async.loadScript('123')
expect(loadedSuccess).toEqual(true)
expect(document.body.getElementsByTagName('script').length).toEqual(1)
})
describe("loadPermutiveScript()", () => {
test("Should load the Permutive script", async () => {
const loadedSuccess = await async.loadPermutiveScript();
expect(loadedSuccess).toEqual(true);
expect(document.body.getElementsByTagName("script").length).toEqual(1);
});
});
})
describe("waitForProp()", () => {
test("Should return undefined if it takes too long for the prop to be set", async () => {
let ciao = {};
describe('loadPermutiveScript()', () => {
test('Should load the Permutive script', async () => {
const loadedSuccess = await async.loadPermutiveScript()
expect(loadedSuccess).toEqual(true)
expect(document.body.getElementsByTagName('script').length).toEqual(1)
})
})
describe('waitForProp()', () => {
test('Should return undefined if it takes too long for the prop to be set', async () => {
let ciao = {}
setTimeout(() => {
ciao.amigo = 'hola'
}, 7500)
ciao.amigo = "hola";
}, 7500);
const valueFound = await async.waitForProp({ propGetter: () => ciao.amigo })
expect(valueFound).toEqual(undefined)
}, 8000)
const valueFound = await async.waitForProp({ propGetter: () => ciao.amigo });
expect(valueFound).toEqual(undefined);
}, 8000);
test('Should return undefined if the prop is set quickly enough', async () => {
let ciao = {}
test("Should return undefined if the prop is set quickly enough", async () => {
let ciao = {};
setTimeout(() => {
ciao.amigo = 'hola'
}, 4500)
ciao.amigo = "hola";
}, 4500);
const valueFound = await async.waitForProp({ propGetter: () => ciao.amigo })
expect(valueFound).toEqual(ciao.amigo)
})
})
})
const valueFound = await async.waitForProp({ propGetter: () => ciao.amigo });
expect(valueFound).toEqual(ciao.amigo);
});
});
});

@@ -1,15 +0,16 @@

import filterWithSchema from '../../src/utils/filterWithSchema'
import filterWithSchema from "../../src/utils/filterWithSchema";
describe('[utils.filterWithSchema]', () => {
describe('filterWithSchema()', () => {
test('Should filter the data using the input schema', () => {
describe("[utils.filterWithSchema]", () => {
describe("filterWithSchema()", () => {
test("Should filter the data using the input schema", () => {
// eslint-disable-next-line no-undef
const event = filterWithSchema(schemas.AdsAPIV2, {
appName: "article", user: {
industry: { code: 'amigo' },
appName: "article",
user: {
industry: { code: "amigo" },
responsibility: {},
ciao: 'quindi',
ciao: "quindi",
position: null,
}
})
},
});

@@ -24,7 +25,6 @@ expect(event).toEqual({

responsibility: {},
}
})
})
})
})
},
});
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc