From d0f1788c3426b43ee3b4cef0ff214f0c47afba8b Mon Sep 17 00:00:00 2001 From: Patrick McCann Date: Tue, 17 May 2022 10:22:20 -0400 Subject: [PATCH 1/6] Delete haloRtdProvider.md --- modules/haloRtdProvider.md | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 modules/haloRtdProvider.md diff --git a/modules/haloRtdProvider.md b/modules/haloRtdProvider.md deleted file mode 100644 index 6ae5a3f75fa..00000000000 --- a/modules/haloRtdProvider.md +++ /dev/null @@ -1,3 +0,0 @@ -## Audigent Halo has been rebranded as Hadron -## Use the Hadron Rtd Submodule -## The Halo modules will be removed from Prebid 7 \ No newline at end of file From 142cc3b0fe0752016ef7f32ecdd52dd21ef7ebdd Mon Sep 17 00:00:00 2001 From: Patrick McCann Date: Tue, 17 May 2022 10:22:43 -0400 Subject: [PATCH 2/6] Delete haloIdSystem.js --- modules/haloIdSystem.js | 96 ----------------------------------------- 1 file changed, 96 deletions(-) delete mode 100644 modules/haloIdSystem.js diff --git a/modules/haloIdSystem.js b/modules/haloIdSystem.js deleted file mode 100644 index 2ce18e1e740..00000000000 --- a/modules/haloIdSystem.js +++ /dev/null @@ -1,96 +0,0 @@ -/** - * This module adds HaloID to the User ID module - * The {@link module:modules/userId} module is required - * @module modules/haloIdSystem - * @requires module:modules/userId - */ - -import {ajax} from '../src/ajax.js'; -import {getStorageManager} from '../src/storageManager.js'; -import {submodule} from '../src/hook.js'; -import { isFn, isStr, isPlainObject, logError } from '../src/utils.js'; - -const MODULE_NAME = 'haloId'; -const AU_GVLID = 561; - -export const storage = getStorageManager({gvlid: AU_GVLID, moduleName: 'halo'}); - -/** - * Param or default. - * @param {String} param - * @param {String} defaultVal - */ -function paramOrDefault(param, defaultVal, arg) { - if (isFn(param)) { - return param(arg); - } else if (isStr(param)) { - return param; - } - return defaultVal; -} - -/** @type {Submodule} */ -export const haloIdSubmodule = { - /** - * used to link submodule with config - * @type {string} - */ - name: MODULE_NAME, - /** - * decode the stored id value for passing to bid requests - * @function - * @param {{value:string}} value - * @returns {{haloId:Object}} - */ - decode(value) { - let haloId = storage.getDataFromLocalStorage('auHaloId'); - if (isStr(haloId)) { - return {haloId: haloId}; - } - return (value && typeof value['haloId'] === 'string') ? { 'haloId': value['haloId'] } : undefined; - }, - /** - * performs action to obtain id and return a value in the callback's response argument - * @function - * @param {SubmoduleConfig} [config] - * @returns {IdResponse|undefined} - */ - getId(config) { - if (!isPlainObject(config.params)) { - config.params = {}; - } - const url = paramOrDefault(config.params.url, - `https://id.halo.ad.gt/api/v1/pbhid`, - config.params.urlArg); - - const resp = function (callback) { - let haloId = storage.getDataFromLocalStorage('auHaloId'); - if (isStr(haloId)) { - const responseObj = {haloId: haloId}; - callback(responseObj); - } else { - const callbacks = { - success: response => { - let responseObj; - if (response) { - try { - responseObj = JSON.parse(response); - } catch (error) { - logError(error); - } - } - callback(responseObj); - }, - error: error => { - logError(`${MODULE_NAME}: ID fetch encountered an error`, error); - callback(); - } - }; - ajax(url, callbacks, undefined, {method: 'GET'}); - } - }; - return {callback: resp}; - } -}; - -submodule('userId', haloIdSubmodule); From a738724598fdc010da1aefc8ab9006d8ed0c2e27 Mon Sep 17 00:00:00 2001 From: Patrick McCann Date: Tue, 17 May 2022 10:22:56 -0400 Subject: [PATCH 3/6] Delete haloIdSystem.md --- modules/haloIdSystem.md | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 modules/haloIdSystem.md diff --git a/modules/haloIdSystem.md b/modules/haloIdSystem.md deleted file mode 100644 index 7c58aea3ec6..00000000000 --- a/modules/haloIdSystem.md +++ /dev/null @@ -1,4 +0,0 @@ -## Audigent Halo has been rebranded as Hadron -## Use the Hadron Id Submodule -## The Halo modules will be removed from Prebid 7 -## Contact prebid@audigent.com for more info. From be3baa4394aeea29109ab2d2274821eb2779bd8e Mon Sep 17 00:00:00 2001 From: Patrick McCann Date: Tue, 17 May 2022 10:23:10 -0400 Subject: [PATCH 4/6] Delete haloRtdProvider.js --- modules/haloRtdProvider.js | 241 ------------------------------------- 1 file changed, 241 deletions(-) delete mode 100644 modules/haloRtdProvider.js diff --git a/modules/haloRtdProvider.js b/modules/haloRtdProvider.js deleted file mode 100644 index 65d83b807ab..00000000000 --- a/modules/haloRtdProvider.js +++ /dev/null @@ -1,241 +0,0 @@ -/** - * This module adds the Audigent Halo provider to the real time data module - * The {@link module:modules/realTimeData} module is required - * The module will fetch real-time data from Audigent - * @module modules/haloRtdProvider - * @requires module:modules/realTimeData - */ -import {ajax} from '../src/ajax.js'; -import {config} from '../src/config.js'; -import {getGlobal} from '../src/prebidGlobal.js'; -import {getStorageManager} from '../src/storageManager.js'; -import {submodule} from '../src/hook.js'; -import {isFn, isStr, isArray, deepEqual, isPlainObject, logError} from '../src/utils.js'; - -const MODULE_NAME = 'realTimeData'; -const SUBMODULE_NAME = 'halo'; -const AU_GVLID = 561; - -export const HALOID_LOCAL_NAME = 'auHaloId'; -export const RTD_LOCAL_NAME = 'auHaloRtd'; -export const storage = getStorageManager({gvlid: AU_GVLID, moduleName: SUBMODULE_NAME}); - -/** - * Deep set an object unless value present. - * @param {Object} obj - * @param {String} path - * @param {Object} val - */ -function set(obj, path, val) { - const keys = path.split('.'); - const lastKey = keys.pop(); - const lastObj = keys.reduce((obj, key) => obj[key] = obj[key] || {}, obj); - lastObj[lastKey] = lastObj[lastKey] || val; -} - -/** - * Deep object merging with array deduplication. - * @param {Object} target - * @param {Object} sources - */ -function mergeDeep(target, ...sources) { - if (!sources.length) return target; - const source = sources.shift(); - - if (isPlainObject(target) && isPlainObject(source)) { - for (const key in source) { - if (isPlainObject(source[key])) { - if (!target[key]) Object.assign(target, { [key]: {} }); - mergeDeep(target[key], source[key]); - } else if (isArray(source[key])) { - if (!target[key]) { - Object.assign(target, { [key]: source[key] }); - } else if (isArray(target[key])) { - source[key].forEach(obj => { - let e = 1; - for (let i = 0; i < target[key].length; i++) { - if (deepEqual(target[key][i], obj)) { - e = 0; - break; - } - } - if (e) { - target[key].push(obj); - } - }); - } - } else { - Object.assign(target, { [key]: source[key] }); - } - } - } - - return mergeDeep(target, ...sources); -} - -/** - * Lazy merge objects. - * @param {Object} target - * @param {Object} source - */ -function mergeLazy(target, source) { - if (!isPlainObject(target)) { - target = {}; - } - - if (!isPlainObject(source)) { - source = {}; - } - - return mergeDeep(target, source); -} - -/** - * Param or default. - * @param {String} param - * @param {String} defaultVal - */ -function paramOrDefault(param, defaultVal, arg) { - if (isFn(param)) { - return param(arg); - } else if (isStr(param)) { - return param; - } - return defaultVal; -} - -/** - * Add real-time data & merge segments. - * @param {Object} bidConfig - * @param {Object} rtd - * @param {Object} rtdConfig - */ -export function addRealTimeData(bidConfig, rtd, rtdConfig) { - if (rtdConfig.params && rtdConfig.params.handleRtd) { - rtdConfig.params.handleRtd(bidConfig, rtd, rtdConfig, config); - } else { - // TODO: this and hadronRtdProvider are a copy-paste of each other - if (isPlainObject(rtd.ortb2)) { - mergeLazy(bidConfig.ortb2Fragments?.global, rtd.ortb2); - } - if (isPlainObject(rtd.ortb2b)) { - mergeLazy(bidConfig.ortb2Fragments?.bidder, Object.fromEntries(Object.entries(rtd.ortb2b).map(([_, cfg]) => [_, cfg.ortb2]))); - } - } -} - -/** - * Real-time data retrieval from Audigent - * @param {Object} reqBidsConfigObj - * @param {function} onDone - * @param {Object} rtdConfig - * @param {Object} userConsent - */ -export function getRealTimeData(bidConfig, onDone, rtdConfig, userConsent) { - if (rtdConfig && isPlainObject(rtdConfig.params) && rtdConfig.params.segmentCache) { - let jsonData = storage.getDataFromLocalStorage(RTD_LOCAL_NAME); - - if (jsonData) { - let data = JSON.parse(jsonData); - - if (data.rtd) { - addRealTimeData(bidConfig, data.rtd, rtdConfig); - onDone(); - return; - } - } - } - - const userIds = typeof getGlobal().getUserIds === 'function' ? (getGlobal()).getUserIds() : {}; - - let haloId = storage.getDataFromLocalStorage(HALOID_LOCAL_NAME); - if (isStr(haloId)) { - if (typeof getGlobal().refreshUserIds === 'function') { - (getGlobal()).refreshUserIds({submoduleNames: 'haloId'}); - } - userIds.haloId = haloId; - getRealTimeDataAsync(bidConfig, onDone, rtdConfig, userConsent, userIds); - } else { - var script = document.createElement('script'); - script.type = 'text/javascript'; - - window.pubHaloCb = (haloId) => { - userIds.haloId = haloId; - getRealTimeDataAsync(bidConfig, onDone, rtdConfig, userConsent, userIds); - } - - const haloIdUrl = rtdConfig.params && rtdConfig.params.haloIdUrl; - script.src = paramOrDefault(haloIdUrl, 'https://id.halo.ad.gt/api/v1/haloid', userIds); - document.getElementsByTagName('head')[0].appendChild(script); - } -} - -/** - * Async rtd retrieval from Audigent - * @param {function} onDone - * @param {Object} rtdConfig - * @param {Object} userConsent - * @param {Object} userIds - */ -export function getRealTimeDataAsync(bidConfig, onDone, rtdConfig, userConsent, userIds) { - let reqParams = {}; - - if (isPlainObject(rtdConfig)) { - set(rtdConfig, 'params.requestParams.ortb2', bidConfig.ortb2Fragments?.global); - reqParams = rtdConfig.params.requestParams; - } - - if (isPlainObject(window.pubHaloPm)) { - reqParams.pubHaloPm = window.pubHaloPm; - } - - const url = `https://seg.halo.ad.gt/api/v1/rtd`; - ajax(url, { - success: function (response, req) { - if (req.status === 200) { - try { - const data = JSON.parse(response); - if (data && data.rtd) { - addRealTimeData(bidConfig, data.rtd, rtdConfig); - onDone(); - storage.setDataInLocalStorage(RTD_LOCAL_NAME, JSON.stringify(data)); - } else { - onDone(); - } - } catch (err) { - logError('unable to parse audigent segment data'); - onDone(); - } - } else if (req.status === 204) { - // unrecognized partner config - onDone(); - } - }, - error: function () { - onDone(); - logError('unable to get audigent segment data'); - } - }, - JSON.stringify({'userIds': userIds, 'config': reqParams}), - {contentType: 'application/json'} - ); -} - -/** - * Module init - * @param {Object} provider - * @param {Objkect} userConsent - * @return {boolean} - */ -function init(provider, userConsent) { - return true; -} - -/** @type {RtdSubmodule} */ -export const haloSubmodule = { - name: SUBMODULE_NAME, - getBidRequestData: getRealTimeData, - init: init -}; - -submodule(MODULE_NAME, haloSubmodule); From 88c553763ceed1ce34874d5139ef6bf523c494f2 Mon Sep 17 00:00:00 2001 From: Patrick McCann Date: Tue, 17 May 2022 10:23:23 -0400 Subject: [PATCH 5/6] Delete haloIdSystem_spec.js --- test/spec/modules/haloIdSystem_spec.js | 57 -------------------------- 1 file changed, 57 deletions(-) delete mode 100644 test/spec/modules/haloIdSystem_spec.js diff --git a/test/spec/modules/haloIdSystem_spec.js b/test/spec/modules/haloIdSystem_spec.js deleted file mode 100644 index 0b8fff12abe..00000000000 --- a/test/spec/modules/haloIdSystem_spec.js +++ /dev/null @@ -1,57 +0,0 @@ -import { haloIdSubmodule, storage } from 'modules/haloIdSystem.js'; -import { server } from 'test/mocks/xhr.js'; -import * as utils from 'src/utils.js'; - -describe('HaloIdSystem', function () { - describe('getId', function() { - let getDataFromLocalStorageStub; - - beforeEach(function() { - getDataFromLocalStorageStub = sinon.stub(storage, 'getDataFromLocalStorage'); - }); - - afterEach(function () { - getDataFromLocalStorageStub.restore(); - }); - - it('gets a haloId', function() { - const config = { - params: {} - }; - const callbackSpy = sinon.spy(); - const callback = haloIdSubmodule.getId(config).callback; - callback(callbackSpy); - const request = server.requests[0]; - expect(request.url).to.eq(`https://id.halo.ad.gt/api/v1/pbhid`); - request.respond(200, { 'Content-Type': 'application/json' }, JSON.stringify({ haloId: 'testHaloId1' })); - expect(callbackSpy.lastCall.lastArg).to.deep.equal({haloId: 'testHaloId1'}); - }); - - it('gets a cached haloid', function() { - const config = { - params: {} - }; - getDataFromLocalStorageStub.withArgs('auHaloId').returns('tstCachedHaloId1'); - - const callbackSpy = sinon.spy(); - const callback = haloIdSubmodule.getId(config).callback; - callback(callbackSpy); - expect(callbackSpy.lastCall.lastArg).to.deep.equal({haloId: 'tstCachedHaloId1'}); - }); - - it('allows configurable id url', function() { - const config = { - params: { - url: 'https://haloid.publync.com' - } - }; - const callbackSpy = sinon.spy(); - const callback = haloIdSubmodule.getId(config).callback; - callback(callbackSpy); - const request = server.requests[0]; - expect(request.url).to.eq('https://haloid.publync.com'); - request.respond(200, { 'Content-Type': 'application/json' }, JSON.stringify({ haloId: 'testHaloId1' })); - expect(callbackSpy.lastCall.lastArg).to.deep.equal({haloId: 'testHaloId1'}); - }); - }); -}); From e846e90996e79a06c0ed48b648ccf6e2af74fc44 Mon Sep 17 00:00:00 2001 From: Patrick McCann Date: Tue, 17 May 2022 10:23:34 -0400 Subject: [PATCH 6/6] Delete haloRtdProvider_spec.js --- test/spec/modules/haloRtdProvider_spec.js | 753 ---------------------- 1 file changed, 753 deletions(-) delete mode 100644 test/spec/modules/haloRtdProvider_spec.js diff --git a/test/spec/modules/haloRtdProvider_spec.js b/test/spec/modules/haloRtdProvider_spec.js deleted file mode 100644 index fe516e9661e..00000000000 --- a/test/spec/modules/haloRtdProvider_spec.js +++ /dev/null @@ -1,753 +0,0 @@ -// TODO: this and haloRtdProvider_spec are a copy-paste of each other - -import {config} from 'src/config.js'; -import {HALOID_LOCAL_NAME, RTD_LOCAL_NAME, addRealTimeData, getRealTimeData, haloSubmodule, storage} from 'modules/haloRtdProvider.js'; -import {server} from 'test/mocks/xhr.js'; - -const responseHeader = {'Content-Type': 'application/json'}; - -describe('haloRtdProvider', function() { - let getDataFromLocalStorageStub; - - beforeEach(function() { - config.resetConfig(); - getDataFromLocalStorageStub = sinon.stub(storage, 'getDataFromLocalStorage'); - }); - - afterEach(function () { - getDataFromLocalStorageStub.restore(); - }); - - describe('haloSubmodule', function() { - it('successfully instantiates', function () { - expect(haloSubmodule.init()).to.equal(true); - }); - }); - - describe('Add Real-Time Data', function() { - it('merges ortb2 data', function() { - let rtdConfig = {}; - - const setConfigUserObj1 = { - name: 'www.dataprovider1.com', - ext: { taxonomyname: 'iab_audience_taxonomy' }, - segment: [{ - id: '1776' - }] - }; - - const setConfigUserObj2 = { - name: 'www.dataprovider2.com', - ext: { taxonomyname: 'iab_audience_taxonomy' }, - segment: [{ - id: '1914' - }] - }; - - const setConfigSiteObj1 = { - name: 'www.dataprovider3.com', - ext: { - taxonomyname: 'iab_audience_taxonomy' - }, - segment: [ - { - id: '1812' - }, - { - id: '1955' - } - ] - } - - let bidConfig = { - ortb2Fragments: { - global: { - user: { - data: [setConfigUserObj1, setConfigUserObj2] - }, - site: { - content: { - data: [setConfigSiteObj1] - } - } - } - } - }; - - const rtdUserObj1 = { - name: 'www.dataprovider4.com', - ext: { - taxonomyname: 'iab_audience_taxonomy' - }, - segment: [ - { - id: '1918' - }, - { - id: '1939' - } - ] - }; - - const rtdSiteObj1 = { - name: 'www.dataprovider5.com', - ext: { - taxonomyname: 'iab_audience_taxonomy' - }, - segment: [ - { - id: '1945' - }, - { - id: '2003' - } - ] - }; - - const rtd = { - ortb2: { - user: { - data: [rtdUserObj1] - }, - site: { - content: { - data: [rtdSiteObj1] - } - } - } - }; - - addRealTimeData(bidConfig, rtd, rtdConfig); - - let ortb2Config = bidConfig.ortb2Fragments.global; - - expect(ortb2Config.user.data).to.deep.include.members([setConfigUserObj1, setConfigUserObj2, rtdUserObj1]); - expect(ortb2Config.site.content.data).to.deep.include.members([setConfigSiteObj1, rtdSiteObj1]); - }); - - it('merges ortb2 data without duplication', function() { - let rtdConfig = {}; - - const userObj1 = { - name: 'www.dataprovider1.com', - ext: { taxonomyname: 'iab_audience_taxonomy' }, - segment: [{ - id: '1776' - }] - }; - - const userObj2 = { - name: 'www.dataprovider2.com', - ext: { taxonomyname: 'iab_audience_taxonomy' }, - segment: [{ - id: '1914' - }] - }; - - const siteObj1 = { - name: 'www.dataprovider3.com', - ext: { - taxonomyname: 'iab_audience_taxonomy' - }, - segment: [ - { - id: '1812' - }, - { - id: '1955' - } - ] - } - - let bidConfig = { - ortb2Fragments: { - global: { - user: { - data: [userObj1, userObj2] - }, - site: { - content: { - data: [siteObj1] - } - } - } - } - }; - - const rtd = { - ortb2: { - user: { - data: [userObj1] - }, - site: { - content: { - data: [siteObj1] - } - } - } - }; - - addRealTimeData(bidConfig, rtd, rtdConfig); - - let ortb2Config = bidConfig.ortb2Fragments.global; - - expect(ortb2Config.user.data).to.deep.include.members([userObj1, userObj2]); - expect(ortb2Config.site.content.data).to.deep.include.members([siteObj1]); - expect(ortb2Config.user.data).to.have.lengthOf(2); - expect(ortb2Config.site.content.data).to.have.lengthOf(1); - }); - - it('merges bidder-specific ortb2 data', function() { - let rtdConfig = {}; - - const configUserObj1 = { - name: 'www.dataprovider1.com', - ext: { segtax: 3 }, - segment: [{ - id: '1776' - }] - }; - - const configUserObj2 = { - name: 'www.dataprovider2.com', - ext: { segtax: 3 }, - segment: [{ - id: '1914' - }] - }; - - const configUserObj3 = { - name: 'www.dataprovider1.com', - ext: { segtax: 3 }, - segment: [{ - id: '2003' - }] - }; - - const configSiteObj1 = { - name: 'www.dataprovider3.com', - ext: { - segtax: 1 - }, - segment: [ - { - id: '1812' - }, - { - id: '1955' - } - ] - }; - - const configSiteObj2 = { - name: 'www.dataprovider3.com', - ext: { - segtax: 1 - }, - segment: [ - { - id: '1812' - } - ] - }; - - let bidConfig = { - ortb2Fragments: { - bidder: { - adbuzz: { - user: { - data: [configUserObj1, configUserObj2] - }, - site: { - content: { - data: [configSiteObj1] - } - } - }, - pubvisage: { - user: { - data: [configUserObj3] - }, - site: { - content: { - data: [configSiteObj2] - } - } - } - } - } - }; - - const rtdUserObj1 = { - name: 'www.dataprovider4.com', - ext: { - segtax: 501 - }, - segment: [ - { - id: '1918' - }, - { - id: '1939' - } - ] - }; - - const rtdUserObj2 = { - name: 'www.dataprovider2.com', - ext: { - segtax: 502 - }, - segment: [ - { - id: '1939' - } - ] - }; - - const rtdSiteObj1 = { - name: 'www.dataprovider5.com', - ext: { - segtax: 1 - }, - segment: [ - { - id: '441' - }, - { - id: '442' - } - ] - }; - - const rtdSiteObj2 = { - name: 'www.dataprovider6.com', - ext: { - segtax: 2 - }, - segment: [ - { - id: '676' - } - ] - }; - - const rtd = { - ortb2b: { - adbuzz: { - ortb2: { - user: { - data: [rtdUserObj1] - }, - site: { - content: { - data: [rtdSiteObj1] - } - } - } - }, - pubvisage: { - ortb2: { - user: { - data: [rtdUserObj2] - }, - site: { - content: { - data: [rtdSiteObj2] - } - } - } - } - } - }; - - addRealTimeData(bidConfig, rtd, rtdConfig); - - let ortb2Config = bidConfig.ortb2Fragments.bidder.adbuzz; - - expect(ortb2Config.user.data).to.deep.include.members([configUserObj1, configUserObj2, rtdUserObj1]); - expect(ortb2Config.site.content.data).to.deep.include.members([configSiteObj1, rtdSiteObj1]); - - ortb2Config = bidConfig.ortb2Fragments.bidder.pubvisage; - - expect(ortb2Config.user.data).to.deep.include.members([configUserObj3, rtdUserObj2]); - expect(ortb2Config.site.content.data).to.deep.include.members([configSiteObj2, rtdSiteObj2]); - }); - - it('merges bidder-specific ortb2 data without duplication', function() { - let rtdConfig = {}; - - const userObj1 = { - name: 'www.dataprovider1.com', - ext: { segtax: 3 }, - segment: [{ - id: '1776' - }] - }; - - const userObj2 = { - name: 'www.dataprovider2.com', - ext: { segtax: 3 }, - segment: [{ - id: '1914' - }] - }; - - const userObj3 = { - name: 'www.dataprovider1.com', - ext: { segtax: 3 }, - segment: [{ - id: '2003' - }] - }; - - const siteObj1 = { - name: 'www.dataprovider3.com', - ext: { - segtax: 1 - }, - segment: [ - { - id: '1812' - }, - { - id: '1955' - } - ] - }; - - const siteObj2 = { - name: 'www.dataprovider3.com', - ext: { - segtax: 1 - }, - segment: [ - { - id: '1812' - } - ] - }; - - let bidConfig = { - ortb2Fragments: { - bidder: { - adbuzz: { - user: { - data: [userObj1, userObj2] - }, - site: { - content: { - data: [siteObj1] - } - } - }, - pubvisage: { - user: { - data: [userObj3] - }, - site: { - content: { - data: [siteObj2] - } - } - } - } - } - }; - - const rtd = { - ortb2b: { - adbuzz: { - ortb2: { - user: { - data: [userObj1] - }, - site: { - content: { - data: [siteObj1] - } - } - } - }, - pubvisage: { - ortb2: { - user: { - data: [userObj2, userObj3] - }, - site: { - content: { - data: [siteObj1, siteObj2] - } - } - } - } - } - }; - - addRealTimeData(bidConfig, rtd, rtdConfig); - - let ortb2Config = bidConfig.ortb2Fragments.bidder.adbuzz; - - expect(ortb2Config.user.data).to.deep.include.members([userObj1]); - expect(ortb2Config.site.content.data).to.deep.include.members([siteObj1]); - - expect(ortb2Config.user.data).to.have.lengthOf(2); - expect(ortb2Config.site.content.data).to.have.lengthOf(1); - - ortb2Config = bidConfig.ortb2Fragments.bidder.pubvisage; - - expect(ortb2Config.user.data).to.deep.include.members([userObj3, userObj3]); - expect(ortb2Config.site.content.data).to.deep.include.members([siteObj1, siteObj2]); - - expect(ortb2Config.user.data).to.have.lengthOf(2); - expect(ortb2Config.site.content.data).to.have.lengthOf(2); - }); - - it('allows publisher defined rtd ortb2 logic', function() { - const rtdConfig = { - params: { - handleRtd: function(bidConfig, rtd, rtdConfig, pbConfig) { - if (rtd.ortb2.user.data[0].segment[0].id == '1776') { - pbConfig.setConfig({ortb2: rtd.ortb2}); - } else { - pbConfig.setConfig({ortb2: {}}); - } - } - } - }; - - let bidConfig = {}; - - const rtdUserObj1 = { - name: 'www.dataprovider.com', - ext: { taxonomyname: 'iab_audience_taxonomy' }, - segment: [{ - id: '1776' - }] - }; - - let rtd = { - ortb2: { - user: { - data: [rtdUserObj1] - } - } - }; - - config.resetConfig(); - - let pbConfig = config.getConfig(); - addRealTimeData(bidConfig, rtd, rtdConfig); - expect(config.getConfig().ortb2.user.data).to.deep.include.members([rtdUserObj1]); - - const rtdUserObj2 = { - name: 'www.audigent.com', - ext: { - segtax: '1', - taxprovider: '1' - }, - segment: [{ - id: 'pubseg1' - }] - }; - - rtd = { - ortb2: { - user: { - data: [rtdUserObj2] - } - } - }; - - config.resetConfig(); - - pbConfig = config.getConfig(); - addRealTimeData(bidConfig, rtd, rtdConfig); - expect(config.getConfig().ortb2).to.deep.equal({}); - }); - - it('allows publisher defined adunit logic', function() { - const rtdConfig = { - params: { - handleRtd: function(bidConfig, rtd, rtdConfig, pbConfig) { - var adUnits = bidConfig.adUnits; - for (var i = 0; i < adUnits.length; i++) { - var adUnit = adUnits[i]; - for (var j = 0; j < adUnit.bids.length; j++) { - var bid = adUnit.bids[j]; - if (bid.bidder == 'adBuzz') { - for (var k = 0; k < rtd.adBuzz.length; k++) { - bid.adBuzzData.segments.adBuzz.push(rtd.adBuzz[k]); - } - } else if (bid.bidder == 'trueBid') { - for (var k = 0; k < rtd.trueBid.length; k++) { - bid.trueBidSegments.push(rtd.trueBid[k]); - } - } - } - } - } - } - }; - - let bidConfig = { - adUnits: [ - { - bids: [ - { - bidder: 'adBuzz', - adBuzzData: { - segments: { - adBuzz: [ - { - id: 'adBuzzSeg1' - } - ] - } - } - }, - { - bidder: 'trueBid', - trueBidSegments: [] - } - ] - } - ] - }; - - const rtd = { - adBuzz: [{id: 'adBuzzSeg2'}, {id: 'adBuzzSeg3'}], - trueBid: [{id: 'truebidSeg1'}, {id: 'truebidSeg2'}, {id: 'truebidSeg3'}] - }; - - addRealTimeData(bidConfig, rtd, rtdConfig); - - expect(bidConfig.adUnits[0].bids[0].adBuzzData.segments.adBuzz[0].id).to.equal('adBuzzSeg1'); - expect(bidConfig.adUnits[0].bids[0].adBuzzData.segments.adBuzz[1].id).to.equal('adBuzzSeg2'); - expect(bidConfig.adUnits[0].bids[0].adBuzzData.segments.adBuzz[2].id).to.equal('adBuzzSeg3'); - expect(bidConfig.adUnits[0].bids[1].trueBidSegments[0].id).to.equal('truebidSeg1'); - expect(bidConfig.adUnits[0].bids[1].trueBidSegments[1].id).to.equal('truebidSeg2'); - expect(bidConfig.adUnits[0].bids[1].trueBidSegments[2].id).to.equal('truebidSeg3'); - }); - }); - - describe('Get Real-Time Data', function() { - it('gets rtd from local storage cache', function() { - const rtdConfig = { - params: { - segmentCache: true - } - }; - - const bidConfig = {ortb2Fragments: {global: {}}}; - - const rtdUserObj1 = { - name: 'www.dataprovider3.com', - ext: { - taxonomyname: 'iab_audience_taxonomy' - }, - segment: [ - { - id: '1918' - }, - { - id: '1939' - } - ] - }; - - const cachedRtd = { - rtd: { - ortb2: { - user: { - data: [rtdUserObj1] - } - } - } - }; - - getDataFromLocalStorageStub.withArgs(RTD_LOCAL_NAME).returns(JSON.stringify(cachedRtd)); - - getRealTimeData(bidConfig, () => {}, rtdConfig, {}); - expect(bidConfig.ortb2Fragments.global.user.data).to.deep.include.members([rtdUserObj1]); - }); - - it('gets real-time data via async request', function() { - const setConfigSiteObj1 = { - name: 'www.audigent.com', - ext: { - segtax: '1', - taxprovider: '1' - }, - segment: [ - { - id: 'pubseg1' - }, - { - id: 'pubseg2' - } - ] - } - - const rtdConfig = { - params: { - segmentCache: false, - usePubhalo: true, - requestParams: { - publisherId: 'testPub1' - } - } - }; - - let bidConfig = { - ortb2Fragments: { - global: { - site: { - content: { - data: [setConfigSiteObj1] - } - } - } - } - }; - - const rtdUserObj1 = { - name: 'www.audigent.com', - ext: { - segtax: '1', - taxprovider: '1' - }, - segment: [ - { - id: 'pubseg1' - }, - { - id: 'pubseg2' - } - ] - }; - - const data = { - rtd: { - ortb2: { - user: { - data: [rtdUserObj1] - } - } - } - }; - - getDataFromLocalStorageStub.withArgs(HALOID_LOCAL_NAME).returns('testhaloId1'); - getRealTimeData(bidConfig, () => {}, rtdConfig, {}); - - let request = server.requests[0]; - let postData = JSON.parse(request.requestBody); - expect(postData.config).to.have.deep.property('publisherId', 'testPub1'); - expect(postData.userIds).to.have.deep.property('haloId', 'testhaloId1'); - - request.respond(200, responseHeader, JSON.stringify(data)); - - expect(bidConfig.ortb2Fragments.global.user.data).to.deep.include.members([rtdUserObj1]); - }); - }); -});