diff --git a/modules/weboramaRtdProvider.js b/modules/weboramaRtdProvider.js index 6ba502d2c8b..270efa9d972 100644 --- a/modules/weboramaRtdProvider.js +++ b/modules/weboramaRtdProvider.js @@ -121,7 +121,6 @@ import { import { getStorageManager } from '../src/storageManager.js'; -import adapterManager from '../src/adapterManager.js'; import {MODULE_TYPE_RTD} from '../src/activities/modules.js'; /** @type {string} */ @@ -304,24 +303,25 @@ class WeboramaRtdProvider { */ #initSubSection(moduleParams, subSection, ...requiredFields) { /** @type {CommonConf} */ - const weboSectionConf = moduleParams[subSection] || { enabled: false }; + const subSectionConf = moduleParams[subSection] || { enabled: false }; - if (weboSectionConf.enabled === false) { + if (subSectionConf.enabled === false) { delete moduleParams[subSection]; return false; } try { - this.#normalizeConf(moduleParams, weboSectionConf); + this.#normalizeConf(moduleParams, subSectionConf); requiredFields.forEach(field => { - if (!(field in weboSectionConf)) { + if (!(field in subSectionConf)) { throw `missing required field '${field}''`; } }); } catch (e) { logError(`unable to initialize: error on ${subSection} configuration:`, e); + return false; } @@ -667,6 +667,7 @@ class WeboramaRtdProvider { onData: dataConf.onData, }; } + /** handle individual bid * @method * @private @@ -680,18 +681,8 @@ class WeboramaRtdProvider { * @returns {void} */ // eslint-disable-next-line no-dupe-class-members - #handleBid(reqBidsConfigObj, bid, profile, metadata) { + #handleBid(reqBidsConfigObj, bid, profile, metadata, extraConf) { this.#handleBidViaORTB2(reqBidsConfigObj, bid.bidder, profile, metadata); - - /** @type {Object.} */ - const bidderAliasRegistry = adapterManager.aliasRegistry || {}; - - /** @type {string} */ - const bidder = bidderAliasRegistry[bid.bidder] || bid.bidder; - - if (bidder == 'appnexus') { - this.#handleAppnexusBid(reqBidsConfigObj, bid, profile); - } } /** function that handles bid request data @@ -705,22 +696,26 @@ class WeboramaRtdProvider { return [deepClone(ph.data), deepClone(ph.metadata)]; } - /** handle appnexus/xandr bid + /** set ortb2 data using path * @method * @private - * @param {Object} reqBidsConfigObj - * @param {Object} reqBidsConfigObj.ortb2Fragments - * @param {Object} reqBidsConfigObj.ortb2Fragments.bidder - * @param {Object} bid - * @param {Object} bid.parameters - * @param {Profile} profile + * @param {Object} ortb2Fragments + * @param {Object} ortb2Fragments.bidder + * @param {string} bidder + * @param {string} path + * @param {any} data * @returns {void} */ // eslint-disable-next-line no-dupe-class-members - #handleAppnexusBid(reqBidsConfigObj, bid, profile) { - const base = 'params.keywords'; - this.#assignProfileToObject(bid, base, profile); - // this.#setBidderOrtb2(reqBidsConfigObj.ortb2Fragments?.bidder, bid.bidder, base, profile); + #setOrtb2(ortb2Fragments, bidder, path, data) { + let ortb2Conf = {}; + deepSetValue(ortb2Conf, path, data); + + if (bidder) { + ortb2Conf = {[bidder]: ortb2Conf}; + } + + mergeDeep(ortb2Fragments, ortb2Conf); } /** handle generic bid via ortb2 arbitrary data diff --git a/modules/weboramaRtdProvider.md b/modules/weboramaRtdProvider.md index 0c6e3339787..dd7c30402de 100644 --- a/modules/weboramaRtdProvider.md +++ b/modules/weboramaRtdProvider.md @@ -16,7 +16,7 @@ Weborama provides a Real-Time Data Submodule for `Prebid.js`, allowing to easy i * LiTE by SFBX® (Local inApp Trust Engine) provides “Zero Party Data” given by users, stored and calculated only on the user’s device. Through a unique cohorting system, it enables better monetization in a consent/consentless and identity-less mode. -Contact prebid-support@weborama.com for more information. +Contact [prebid-support@weborama.com] for more information. ### Publisher Usage @@ -79,7 +79,7 @@ pbjs.setConfig({ Each module can perform two actions: -* set targeting on [GPT](https://docs.prebid.org/dev-docs/publisher-api-reference/setTargetingForGPTAsync.html) / [AST](https://docs.prebid.org/dev-docs/publisher-api-reference/setTargetingForAst.html]) via `prebid.js` +* set targeting on [GPT](https://docs.prebid.org/dev-docs/publisher-api-reference/setTargetingForGPTAsync.html) / [AST](https://docs.prebid.org/dev-docs/publisher-api-reference/setTargetingForAst.html) via `prebid.js` * send data to other `prebid.js` bidder modules (check the complete list at the end of this page) @@ -156,9 +156,9 @@ This property support the following types | Type | Description | Example | Notes | | :------------ | :------------ | :------------ |:------------ | | Boolean|If true, set prebid targeting for all adunits, or not in case of false| `true` | default value | -| String|Will set prebid targeting only for one adunit | `'adUnitCode1'` | | -| Array of Strings|Will set prebid targeting only for some adunits| `['adUnitCode1','adUnitCode2']` | | -| Callback |Will be executed for each adunit, expects return a true value to set prebid targeting or not| `function(adUnitCode){return adUnitCode == 'adUnitCode';}` | | +| String|Will set prebid targeting only for one adunit | `'adUnitCode1'` | **DEPRECATED** | +| Array of Strings|Will set prebid targeting only for some adunits| `['adUnitCode1','adUnitCode2']` | **DEPRECATED** | +| Callback |Will be executed for each adunit, expects return a true value to set prebid targeting or not| `function(adUnitCode){return adUnitCode == 'adUnitCode';}` | **DEPRECATED** | The complete callback function signature is: @@ -168,26 +168,7 @@ setPrebidTargeting: function(adUnitCode, data, metadata){ } ``` -This callback will be executed with the adUnitCode, profile and a metadata with the following fields - -| Name |Type | Description | Notes | -| :------------ | :------------ | :------------ |:------------ | -| user | Boolean | If true, it contains user-centric data | | -| source | String | Represent the source of data | can be `contextual`, `wam` or `lite` | -| isDefault | Boolean | If true, it contains the default profile defined in the configuration | | - -It is possible customize the targeting based on the parameters: - -```javascript -setPrebidTargeting: function(adUnitCode, data, metadata){ - // check metadata.source can be omitted if defined in params.weboUserDataConf - if (adUnitCode == 'adUnitCode1' && metadata.source == 'wam'){ - data['foo']=['bar']; // add this section only for adUnitCode1 - delete data['other']; // remove this section - } - return true; -} -``` +Since `Prebid.js` version 8, we use First Party Data Support to propagate data to differente SSPs. We will deprecate the support to other formats than Boolean. ##### Property sendToBidders supported types @@ -198,8 +179,8 @@ This property support the following types | Boolean|If true, send data to all bidders, or not in case of false| `true` | default value | | String|Will send data to only one bidder | `'appnexus'` | | | Array of Strings|Will send data to only some bidders | `['appnexus','pubmatic']` | | -| Object |Will send data to only some bidders and some ad units | `{appnexus: true, pubmatic:['adUnitCode1']}` | | -| Callback |Will be executed for each adunit, expects return a true value to set prebid targeting or not| `function(bid, adUnitCode){return bid.bidder == 'appnexus' && adUnitCode == 'adUnitCode';}` | | +| Object |Will send data to only some bidders and some ad units | `{appnexus: true, pubmatic:['adUnitCode1']}` | **DEPRECATED** | +| Callback |Will be executed for each adunit, expects return a true value to set prebid targeting or not| `function(bid, adUnitCode){return bid.bidder == 'appnexus' && adUnitCode == 'adUnitCode';}` | the parameter `adUnitCode` can be consider **DEPRECATED** | A better look on the `Object` type @@ -218,7 +199,7 @@ sendToBidders: function(bid, adUnitCode, data, metadata){ } ``` -This callback will be executed with the bid object (contains a field `bidder` with name), adUnitCode, profile and a metadata with the following fields +This callback will be executed with the bid object (contains a field `bidder` with name), adUnitCode (**deprecated**), profile and a metadata with the following fields | Name |Type | Description | Notes | | :------------ | :------------ | :------------ |:------------ | @@ -230,7 +211,7 @@ It is possible customize the targeting based on the parameters: ```javascript sendToBidders: function(bid, adUnitCode, data, metadata){ - if (bid.bidder == 'appnexus' && adUnitCode == 'adUnitCode1'){ + if (bid.bidder == 'appnexus'){ data['foo']=['bar']; // add this section only for appnexus + adUnitCode1 delete data['other']; // remove this section } @@ -238,6 +219,8 @@ sendToBidders: function(bid, adUnitCode, data, metadata){ } ``` +Since `Prebid.js` version 8, we use First Party Data Support to propagate data to differente SSPs. We will deprecate the support to formats that thandle with `adUnitCode` at some point. + To be possible customize the way we send data to bidders via this callback: ```javascript @@ -537,10 +520,10 @@ pbjs.que.push(function () { }, weboUserDataConf: { accountId: 12345, // recommended - setPrebidTargeting: ['adUnitCode1',...], // set target only on certain adunits + setPrebidTargeting: true sendToBidders: { // send to only some bidders and adunits - 'appnexus': true, // all adunits for appnexus - 'pubmatic': ['adUnitCode1',...] // some adunits for pubmatic + 'appnexus': true, // enable appnexus + 'pubmatic': false // explicit disable pubmatic // other bidders will be ignored }, defaultProfile: { // optional @@ -552,11 +535,9 @@ pbjs.que.push(function () { //, onData: function (data, ...) { ...} }, sfbxLiteDataConf: { - setPrebidTargeting: function(adUnitCode){ // specify set target via callback - return adUnitCode == 'adUnitCode1'; - }, + setPrebidTargeting: true, sendToBidders: function(bid, adUnitCode){ // specify sendToBidders via callback - return bid.bidder == 'appnexus' && adUnitCode == 'adUnitCode1'; + return bid.bidder == 'appnexus'; } defaultProfile: { // optional lite_occupation: ['gérant', 'bénévole'], @@ -575,12 +556,9 @@ pbjs.que.push(function () { ### Supported Bidders -We currently support the following bidder adapters with dedicated code: +We set the bidder ortb2 `site.ext.data` and `user.ext.data` sections (as arbitrary data). The following bidders may support it, to be sure, check the `First Party Data Support` on the feature list for the particular bidder from [here](https://docs.prebid.org/dev-docs/bidders). We may set the ortb2 global if no specific bidders are set on `sendToBidders` configuration. * AppNexus SSP - -We also set the bidder (and global, if no specific bidders are set on `sendToBidders`) ortb2 `site.ext.data` and `user.ext.data` sections (as arbitrary data). The following bidders may support it, to be sure, check the `First Party Data Support` on the feature list for the particular bidder from [here](https://docs.prebid.org/dev-docs/bidders). - * Adagio * AdformOpenRTB * AdKernel diff --git a/test/spec/modules/weboramaRtdProvider_spec.js b/test/spec/modules/weboramaRtdProvider_spec.js index 7de8474d7c9..84d5a28724f 100644 --- a/test/spec/modules/weboramaRtdProvider_spec.js +++ b/test/spec/modules/weboramaRtdProvider_spec.js @@ -11,11 +11,14 @@ import { } from '../../../modules/weboramaRtdProvider.js'; import 'src/prebid.js'; +import { deepAccess, deepClone } from '../../../src/utils.js'; const responseHeader = { 'Content-Type': 'application/json' }; +const APPNEXUS = 'appnexus'; + describe('weboramaRtdProvider', function() { describe('weboramaSubmodule', function() { it('successfully instantiates and call contextual api', function() { @@ -87,6 +90,18 @@ describe('weboramaRtdProvider', function() { webo_ds: ['baz'], }; const adUnitCode = 'adunit1'; + const adUnitsBids = [{ + bidder: 'smartadserver' + }, { + bidder: 'pubmatic' + }, { + bidder: 'appnexus' + }, { + bidder: 'rubicon' + }, { + bidder: 'other' + }]; + const reqBidsConfigObj = { ortb2Fragments: { global: {}, @@ -94,17 +109,7 @@ describe('weboramaRtdProvider', function() { }, adUnits: [{ code: adUnitCode, - bids: [{ - bidder: 'smartadserver' - }, { - bidder: 'pubmatic' - }, { - bidder: 'appnexus' - }, { - bidder: 'rubicon' - }, { - bidder: 'other' - }] + bids: deepClone(adUnitsBids), }] }; @@ -129,20 +134,28 @@ describe('weboramaRtdProvider', function() { 'adunit1': data, }); - expect(reqBidsConfigObj.adUnits[0].bids.length).to.equal(5); - expect(reqBidsConfigObj.adUnits[0].bids[0].params).to.be.undefined; - expect(reqBidsConfigObj.adUnits[0].bids[1].params).to.be.undefined; - expect(reqBidsConfigObj.adUnits[0].bids[2].params.keywords).to.deep.equal(data); - expect(reqBidsConfigObj.adUnits[0].bids[3].params).to.be.undefined; - ['smartadserver', 'pubmatic', 'appnexus', 'rubicon', 'other'].forEach((v) => { - expect(reqBidsConfigObj.ortb2Fragments.bidder[v]).to.deep.equal({ + reqBidsConfigObj.adUnits.forEach(adUnit => { + expect(adUnit.bids).to.deep.equal(adUnitsBids); + }); + + const bidders = Object.values(adUnitsBids).map(v => v.bidder); + const expectedORTB2BidderFragments = bidders.reduce((frag, bidder) => { + frag[bidder] = { site: { ext: { data: data }, } - }); - }) + }; + + return frag + }, {}); + + expect(reqBidsConfigObj.ortb2Fragments).to.deep.equal({ + global: {}, + bidder: expectedORTB2BidderFragments, + }); + expect(onDataResponse).to.deep.equal({ data: data, meta: { @@ -174,6 +187,17 @@ describe('weboramaRtdProvider', function() { webo_vctx: ['foo', 'bar'], }; const adUnitCode = 'adunit1'; + const adUnitsBids = [{ + bidder: 'smartadserver' + }, { + bidder: 'pubmatic' + }, { + bidder: 'appnexus' + }, { + bidder: 'rubicon' + }, { + bidder: 'other' + }]; const reqBidsConfigObj = { ortb2Fragments: { global: {}, @@ -181,17 +205,7 @@ describe('weboramaRtdProvider', function() { }, adUnits: [{ code: adUnitCode, - bids: [{ - bidder: 'smartadserver' - }, { - bidder: 'pubmatic' - }, { - bidder: 'appnexus' - }, { - bidder: 'rubicon' - }, { - bidder: 'other' - }] + bids: deepClone(adUnitsBids), }] }; @@ -216,20 +230,28 @@ describe('weboramaRtdProvider', function() { 'adunit1': data, }); - expect(reqBidsConfigObj.adUnits[0].bids.length).to.equal(5); - expect(reqBidsConfigObj.adUnits[0].bids[0].params).to.be.undefined; - expect(reqBidsConfigObj.adUnits[0].bids[1].params).to.be.undefined; - expect(reqBidsConfigObj.adUnits[0].bids[2].params.keywords).to.deep.equal(data); - expect(reqBidsConfigObj.adUnits[0].bids[3].params).to.be.undefined; - ['smartadserver', 'pubmatic', 'appnexus', 'rubicon', 'other'].forEach((v) => { - expect(reqBidsConfigObj.ortb2Fragments.bidder[v]).to.deep.equal({ + reqBidsConfigObj.adUnits.forEach(adUnit => { + expect(adUnit.bids).to.deep.equal(adUnitsBids); + }); + + const bidders = Object.values(adUnitsBids).map(v => v.bidder); + const expectedORTB2BidderFragments = bidders.reduce((frag, bidder) => { + frag[bidder] = { site: { ext: { data: data }, } - }); - }) + }; + + return frag + }, {}); + + expect(reqBidsConfigObj.ortb2Fragments).to.deep.equal({ + global: {}, + bidder: expectedORTB2BidderFragments, + }); + expect(onDataResponse).to.deep.equal({ data: data, meta: { @@ -261,6 +283,17 @@ describe('weboramaRtdProvider', function() { webo_vctx: ['foo', 'bar'], }; const adUnitCode = 'adunit1'; + const adUnitsBids = [{ + bidder: 'smartadserver' + }, { + bidder: 'pubmatic' + }, { + bidder: 'appnexus' + }, { + bidder: 'rubicon' + }, { + bidder: 'other' + }]; const reqBidsConfigObj = { ortb2Fragments: { global: {}, @@ -268,17 +301,7 @@ describe('weboramaRtdProvider', function() { }, adUnits: [{ code: adUnitCode, - bids: [{ - bidder: 'smartadserver' - }, { - bidder: 'pubmatic' - }, { - bidder: 'appnexus' - }, { - bidder: 'rubicon' - }, { - bidder: 'other' - }] + bids: deepClone(adUnitsBids), }] }; @@ -303,20 +326,28 @@ describe('weboramaRtdProvider', function() { 'adunit1': data, }); - expect(reqBidsConfigObj.adUnits[0].bids.length).to.equal(5); - expect(reqBidsConfigObj.adUnits[0].bids[0].params).to.be.undefined; - expect(reqBidsConfigObj.adUnits[0].bids[1].params).to.be.undefined; - expect(reqBidsConfigObj.adUnits[0].bids[2].params.keywords).to.deep.equal(data); - expect(reqBidsConfigObj.adUnits[0].bids[3].params).to.be.undefined; - ['smartadserver', 'pubmatic', 'appnexus', 'rubicon', 'other'].forEach((v) => { - expect(reqBidsConfigObj.ortb2Fragments.bidder[v]).to.deep.equal({ + reqBidsConfigObj.adUnits.forEach(adUnit => { + expect(adUnit.bids).to.deep.equal(adUnitsBids); + }); + + const bidders = Object.values(adUnitsBids).map(v => v.bidder); + const expectedORTB2BidderFragments = bidders.reduce((frag, bidder) => { + frag[bidder] = { site: { ext: { data: data }, } - }); - }) + }; + + return frag + }, {}); + + expect(reqBidsConfigObj.ortb2Fragments).to.deep.equal({ + global: {}, + bidder: expectedORTB2BidderFragments, + }); + expect(onDataResponse).to.deep.equal({ data: data, meta: { @@ -481,6 +512,18 @@ describe('weboramaRtdProvider', function() { const adUnitCode1 = 'adunit1'; const adUnitCode2 = 'adunit2'; + const adUnitsBids = [{ + bidder: 'smartadserver' + }, { + bidder: 'pubmatic' + }, { + bidder: 'appnexus' + }, { + bidder: 'rubicon' + }, { + bidder: 'other' + }]; + const reqBidsConfigObj = { ortb2Fragments: { global: {}, @@ -488,30 +531,10 @@ describe('weboramaRtdProvider', function() { }, adUnits: [{ code: adUnitCode1, - bids: [{ - bidder: 'smartadserver' - }, { - bidder: 'pubmatic' - }, { - bidder: 'appnexus' - }, { - bidder: 'rubicon' - }, { - bidder: 'other' - }] + bids: deepClone(adUnitsBids), }, { code: adUnitCode2, - bids: [{ - bidder: 'smartadserver' - }, { - bidder: 'pubmatic' - }, { - bidder: 'appnexus' - }, { - bidder: 'rubicon' - }, { - bidder: 'other' - }] + bids: deepClone(adUnitsBids), }] }; @@ -538,27 +561,24 @@ describe('weboramaRtdProvider', function() { }); reqBidsConfigObj.adUnits.forEach(adUnit => { - expect(adUnit.bids.length).to.equal(5); - expect(adUnit.bids[0].params).to.be.undefined; - expect(adUnit.bids[1].params).to.be.undefined; - expect(adUnit.bids[2].params.keywords).to.deep.equal(data); - expect(adUnit.bids[3].params).to.be.undefined; + expect(adUnit.bids).to.deep.equal(adUnitsBids); + }); + + const expectedORTB2BidderFragments = { + [APPNEXUS]: { + site: { + ext: { + data: data + }, + }, + }, + }; + + expect(reqBidsConfigObj.ortb2Fragments).to.deep.equal({ + global: {}, + bidder: expectedORTB2BidderFragments, }); - ['smartadserver', 'pubmatic', 'appnexus', 'rubicon', 'other'].forEach((v) => { - if (v == 'appnexus') { - expect(reqBidsConfigObj.ortb2Fragments.bidder[v]).to.deep.equal({ - site: { - ext: { - data: data - }, - } - }); - - return; - } - expect(reqBidsConfigObj.ortb2Fragments.bidder[v]).to.be.undefined; - }) expect(onDataResponse).to.deep.equal({ data: data, meta: { @@ -606,6 +626,17 @@ describe('weboramaRtdProvider', function() { }; const adUnitCode1 = 'adunit1'; const adUnitCode2 = 'adunit2'; + const adUnitsBids = [{ + bidder: 'smartadserver' + }, { + bidder: 'pubmatic' + }, { + bidder: 'appnexus' + }, { + bidder: 'rubicon' + }, { + bidder: 'other' + }]; const reqBidsConfigObj = { ortb2Fragments: { @@ -614,30 +645,10 @@ describe('weboramaRtdProvider', function() { }, adUnits: [{ code: adUnitCode1, - bids: [{ - bidder: 'smartadserver' - }, { - bidder: 'pubmatic' - }, { - bidder: 'appnexus' - }, { - bidder: 'rubicon' - }, { - bidder: 'other' - }] + bids: deepClone(adUnitsBids), }, { code: adUnitCode2, - bids: [{ - bidder: 'smartadserver' - }, { - bidder: 'pubmatic' - }, { - bidder: 'appnexus' - }, { - bidder: 'rubicon' - }, { - bidder: 'other' - }] + bids: deepClone(adUnitsBids), }] }; @@ -664,16 +675,9 @@ describe('weboramaRtdProvider', function() { }); reqBidsConfigObj.adUnits.forEach(adUnit => { - expect(adUnit.bids.length).to.equal(5); - expect(adUnit.bids[0].params).to.be.undefined; - expect(adUnit.bids[1].params).to.be.undefined; - expect(adUnit.bids[3].params).to.be.undefined; - expect(adUnit.bids[4].ortb2).to.be.undefined; + expect(adUnit.bids).to.deep.equal(adUnitsBids); }); - expect(reqBidsConfigObj.adUnits[0].bids[2].params.keywords).to.deep.equal(data); - expect(reqBidsConfigObj.adUnits[1].bids[2].params).to.be.undefined; - expect(onDataResponse).to.deep.equal({ data: data, meta: { @@ -714,6 +718,36 @@ describe('weboramaRtdProvider', function() { }; const adUnitCode1 = 'adunit1'; const adUnitCode2 = 'adunit2'; + const adUnitsBids = [{ + bidder: 'smartadserver', + params: { + target: 'foo=bar' + } + }, { + bidder: 'pubmatic', + params: { + dctr: 'foo=bar' + } + }, { + bidder: 'appnexus', + params: { + keywords: { + foo: ['bar'] + } + } + }, { + bidder: 'rubicon', + params: { + inventory: { + foo: 'bar', + }, + visitor: { + baz: 'bam', + } + } + }, { + bidder: 'other', + }]; const reqBidsConfigObj = { ortb2Fragments: { global: {}, @@ -721,68 +755,10 @@ describe('weboramaRtdProvider', function() { }, adUnits: [{ code: adUnitCode1, - bids: [{ - bidder: 'smartadserver', - params: { - target: 'foo=bar' - } - }, { - bidder: 'pubmatic', - params: { - dctr: 'foo=bar' - } - }, { - bidder: 'appnexus', - params: { - keywords: { - foo: ['bar'] - } - } - }, { - bidder: 'rubicon', - params: { - inventory: { - foo: 'bar', - }, - visitor: { - baz: 'bam', - } - } - }, { - bidder: 'other', - }] + bids: deepClone(adUnitsBids), }, { code: adUnitCode2, - bids: [{ - bidder: 'smartadserver', - params: { - target: 'foo=bar' - } - }, { - bidder: 'pubmatic', - params: { - dctr: 'foo=bar' - } - }, { - bidder: 'appnexus', - params: { - keywords: { - foo: ['bar'] - } - } - }, { - bidder: 'rubicon', - params: { - inventory: { - foo: 'bar', - }, - visitor: { - baz: 'bam', - } - } - }, { - bidder: 'other', - }] + bids: deepClone(adUnitsBids), }] }; const onDoneSpy = sinon.spy(); @@ -808,24 +784,13 @@ describe('weboramaRtdProvider', function() { }); reqBidsConfigObj.adUnits.forEach(adUnit => { - expect(adUnit.bids.length).to.equal(5); - expect(adUnit.bids[0].params.target).to.equal('foo=bar'); - expect(adUnit.bids[1].params.dctr).to.equal('foo=bar'); - expect(adUnit.bids[2].params.keywords).to.deep.equal({ - foo: ['bar'] - }); - expect(adUnit.bids[3].params).to.deep.equal({ - inventory: { - foo: 'bar', - }, - visitor: { - baz: 'bam', - } - }); + expect(adUnit.bids).to.deep.equal(adUnitsBids); + }); + + expect(reqBidsConfigObj.ortb2Fragments).to.deep.equal({ + global: {}, + bidder: {}, }); - ['smartadserver', 'pubmatic', 'appnexus', 'rubicon', 'other'].forEach((v) => { - expect(reqBidsConfigObj.ortb2Fragments.bidder[v]).to.be.undefined; - }) }); }); }); @@ -857,6 +822,36 @@ describe('weboramaRtdProvider', function() { }; const adUnitCode1 = 'adunit1'; const adUnitCode2 = 'adunit2'; + const adUnitsBids = [{ + bidder: 'smartadserver', + params: { + target: 'foo=bar' + } + }, { + bidder: 'pubmatic', + params: { + dctr: 'foo=bar' + } + }, { + bidder: 'appnexus', + params: { + keywords: { + foo: ['bar'] + } + } + }, { + bidder: 'rubicon', + params: { + inventory: { + foo: 'bar', + }, + visitor: { + baz: 'bam', + } + } + }, { + bidder: 'other', + }]; const reqBidsConfigObj = { ortb2Fragments: { global: {}, @@ -864,68 +859,10 @@ describe('weboramaRtdProvider', function() { }, adUnits: [{ code: adUnitCode1, - bids: [{ - bidder: 'smartadserver', - params: { - target: 'foo=bar' - } - }, { - bidder: 'pubmatic', - params: { - dctr: 'foo=bar' - } - }, { - bidder: 'appnexus', - params: { - keywords: { - foo: ['bar'] - } - } - }, { - bidder: 'rubicon', - params: { - inventory: { - foo: 'bar', - }, - visitor: { - baz: 'bam', - } - } - }, { - bidder: 'other', - }] + bids: deepClone(adUnitsBids), }, { code: adUnitCode2, - bids: [{ - bidder: 'smartadserver', - params: { - target: 'foo=bar' - } - }, { - bidder: 'pubmatic', - params: { - dctr: 'foo=bar' - } - }, { - bidder: 'appnexus', - params: { - keywords: { - foo: ['bar'] - } - } - }, { - bidder: 'rubicon', - params: { - inventory: { - foo: 'bar', - }, - visitor: { - baz: 'bam', - } - } - }, { - bidder: 'other', - }] + bids: deepClone(adUnitsBids), }] }; const onDoneSpy = sinon.spy(); @@ -951,24 +888,13 @@ describe('weboramaRtdProvider', function() { }); reqBidsConfigObj.adUnits.forEach(adUnit => { - expect(adUnit.bids.length).to.equal(5); - expect(adUnit.bids[0].params.target).to.equal('foo=bar'); - expect(adUnit.bids[1].params.dctr).to.equal('foo=bar'); - expect(adUnit.bids[2].params.keywords).to.deep.equal({ - foo: ['bar'] - }); - expect(adUnit.bids[3].params).to.deep.equal({ - inventory: { - foo: 'bar', - }, - visitor: { - baz: 'bam', - } - }); + expect(adUnit.bids).to.deep.equal(adUnitsBids); + }); + + expect(reqBidsConfigObj.ortb2Fragments).to.deep.equal({ + global: {}, + bidder: {}, }); - ['smartadserver', 'pubmatic', 'appnexus', 'rubicon', 'other'].forEach((v) => { - expect(reqBidsConfigObj.ortb2Fragments.bidder[v]).to.be.undefined; - }) }); }); }); @@ -1059,6 +985,36 @@ describe('weboramaRtdProvider', function() { webo_ds: ['baz'], }; const adUnitCode = 'adunit1'; + const adUnitsBids = [{ + bidder: 'smartadserver', + params: { + target: 'foo=bar' + } + }, { + bidder: 'pubmatic', + params: { + dctr: 'foo=bar' + } + }, { + bidder: 'appnexus', + params: { + keywords: { + foo: ['bar'] + } + } + }, { + bidder: 'rubicon', + params: { + inventory: { + foo: 'bar', + }, + visitor: { + baz: 'bam', + } + } + }, { + bidder: 'other', + }]; const reqBidsConfigObj = { ortb2Fragments: { global: {}, @@ -1066,36 +1022,7 @@ describe('weboramaRtdProvider', function() { }, adUnits: [{ code: adUnitCode, - bids: [{ - bidder: 'smartadserver', - params: { - target: 'foo=bar' - } - }, { - bidder: 'pubmatic', - params: { - dctr: 'foo=bar' - } - }, { - bidder: 'appnexus', - params: { - keywords: { - foo: ['bar'] - } - } - }, { - bidder: 'rubicon', - params: { - inventory: { - foo: 'bar', - }, - visitor: { - baz: 'bam', - } - } - }, { - bidder: 'other', - }] + bids: deepClone(adUnitsBids), }] } const onDoneSpy = sinon.spy(); @@ -1119,31 +1046,27 @@ describe('weboramaRtdProvider', function() { 'adunit1': {}, }); - expect(reqBidsConfigObj.adUnits[0].bids.length).to.equal(5); - expect(reqBidsConfigObj.adUnits[0].bids[0].params.target).to.equal('foo=bar'); - expect(reqBidsConfigObj.adUnits[0].bids[1].params.dctr).to.equal('foo=bar'); - expect(reqBidsConfigObj.adUnits[0].bids[2].params.keywords).to.deep.equal({ - foo: ['bar'], - webo_ctx: ['foo', 'bar'], - webo_ds: ['baz'], - }); - expect(reqBidsConfigObj.adUnits[0].bids[3].params).to.deep.equal({ - inventory: { - foo: 'bar', - }, - visitor: { - baz: 'bam', - } + reqBidsConfigObj.adUnits.forEach(adUnit => { + expect(adUnit.bids).to.deep.equal(adUnitsBids); }); - ['smartadserver', 'pubmatic', 'appnexus', 'rubicon', 'other'].forEach((v) => { - expect(reqBidsConfigObj.ortb2Fragments.bidder[v]).to.deep.equal({ + + const bidders = Object.values(adUnitsBids).map(v => v.bidder); + const expectedORTB2BidderFragments = bidders.reduce((frag, bidder) => { + frag[bidder] = { site: { ext: { data: data }, } - }); - }) + }; + + return frag + }, {}); + + expect(reqBidsConfigObj.ortb2Fragments).to.deep.equal({ + global: {}, + bidder: expectedORTB2BidderFragments, + }); }); it('should use default profile in case of api error', function() { @@ -1169,6 +1092,17 @@ describe('weboramaRtdProvider', function() { }; const adUnitCode = 'adunit1'; + const adUnitsBids = [{ + bidder: 'smartadserver' + }, { + bidder: 'pubmatic' + }, { + bidder: 'appnexus' + }, { + bidder: 'rubicon' + }, { + bidder: 'other' + }]; const reqBidsConfigObj = { ortb2Fragments: { global: {}, @@ -1176,17 +1110,7 @@ describe('weboramaRtdProvider', function() { }, adUnits: [{ code: adUnitCode, - bids: [{ - bidder: 'smartadserver' - }, { - bidder: 'pubmatic' - }, { - bidder: 'appnexus' - }, { - bidder: 'rubicon' - }, { - bidder: 'other' - }] + bids: deepClone(adUnitsBids), }] }; const onDoneSpy = sinon.spy(); @@ -1210,20 +1134,28 @@ describe('weboramaRtdProvider', function() { 'adunit1': defaultProfile, }); - expect(reqBidsConfigObj.adUnits[0].bids.length).to.equal(5); - expect(reqBidsConfigObj.adUnits[0].bids[0].params).to.be.undefined; - expect(reqBidsConfigObj.adUnits[0].bids[1].params).to.be.undefined; - expect(reqBidsConfigObj.adUnits[0].bids[2].params.keywords).to.deep.equal(defaultProfile); - expect(reqBidsConfigObj.adUnits[0].bids[3].params).to.be.undefined; - ['smartadserver', 'pubmatic', 'appnexus', 'rubicon', 'other'].forEach((v) => { - expect(reqBidsConfigObj.ortb2Fragments.bidder[v]).to.deep.equal({ + reqBidsConfigObj.adUnits.forEach(adUnit => { + expect(adUnit.bids).to.deep.equal(adUnitsBids); + }); + + const bidders = Object.values(adUnitsBids).map(v => v.bidder); + const expectedORTB2BidderFragments = bidders.reduce((frag, bidder) => { + frag[bidder] = { site: { ext: { data: defaultProfile }, } - }); - }) + }; + + return frag + }, {}); + + expect(reqBidsConfigObj.ortb2Fragments).to.deep.equal({ + global: {}, + bidder: expectedORTB2BidderFragments, + }); + expect(onDataResponse).to.deep.equal({ data: defaultProfile, meta: { @@ -1269,6 +1201,17 @@ describe('weboramaRtdProvider', function() { }; const adUnitCode1 = 'adunit1'; const adUnitCode2 = 'adunit2'; + const adUnitsBids = [{ + bidder: 'smartadserver' + }, { + bidder: 'pubmatic' + }, { + bidder: 'appnexus' + }, { + bidder: 'rubicon' + }, { + bidder: 'other' + }]; const reqBidsConfigObj = { ortb2Fragments: { global: {}, @@ -1276,30 +1219,10 @@ describe('weboramaRtdProvider', function() { }, adUnits: [{ code: adUnitCode1, - bids: [{ - bidder: 'smartadserver' - }, { - bidder: 'pubmatic' - }, { - bidder: 'appnexus' - }, { - bidder: 'rubicon' - }, { - bidder: 'other' - }] + bids: deepClone(adUnitsBids), }, { code: adUnitCode2, - bids: [{ - bidder: 'smartadserver' - }, { - bidder: 'pubmatic' - }, { - bidder: 'appnexus' - }, { - bidder: 'rubicon' - }, { - bidder: 'other' - }] + bids: deepClone(adUnitsBids), }] }; @@ -1330,42 +1253,36 @@ describe('weboramaRtdProvider', function() { }); reqBidsConfigObj.adUnits.forEach(adUnit => { - expect(adUnit.bids.length).to.equal(5); - expect(adUnit.bids[0].params).to.be.undefined; - expect(adUnit.bids[1].params).to.be.undefined; - expect(adUnit.bids[3].params).to.be.undefined; + expect(adUnit.bids).to.deep.equal(adUnitsBids); }); - ['smartadserver', 'pubmatic', 'appnexus', 'rubicon', 'other'].forEach((v) => { - if (v == 'appnexus') { - expect(reqBidsConfigObj.ortb2Fragments.bidder[v]).to.deep.equal({ - site: { - ext: { - data: { - webo_ctx: ['foo', 'bar'], - webo_ds: ['baz'], - webo_bar: ['baz'], - } - }, - } - }); - return - } - - expect(reqBidsConfigObj.ortb2Fragments.bidder[v]).to.deep.equal({ + const bidders = Object.values(adUnitsBids).map(v => v.bidder); + const expectedORTB2BidderFragments = bidders.reduce((frag, bidder) => { + frag[bidder] = { site: { ext: { data: data }, } - }); - }) - expect(reqBidsConfigObj.adUnits[0].bids[2].params.keywords).to.deep.equal({ - webo_ctx: ['foo', 'bar'], - webo_ds: ['baz'], - webo_bar: ['baz'], + }; + + return frag + }, {}); + + expectedORTB2BidderFragments[APPNEXUS].site = { + ext: { + data: { + webo_ctx: ['foo', 'bar'], + webo_ds: ['baz'], + webo_bar: ['baz'], + } + }, + }; + + expect(reqBidsConfigObj.ortb2Fragments).to.deep.equal({ + global: {}, + bidder: expectedORTB2BidderFragments, }); - expect(reqBidsConfigObj.adUnits[1].bids[2].params.keywords).to.deep.equal(data); expect(onDataResponse).to.deep.equal({ data: data, @@ -1410,6 +1327,17 @@ describe('weboramaRtdProvider', function() { .returns(JSON.stringify(entry)); const adUnitCode = 'adunit1'; + const adUnitsBids = [{ + bidder: 'smartadserver' + }, { + bidder: 'pubmatic' + }, { + bidder: 'appnexus' + }, { + bidder: 'rubicon' + }, { + bidder: 'other' + }]; const reqBidsConfigObj = { ortb2Fragments: { global: {}, @@ -1417,17 +1345,7 @@ describe('weboramaRtdProvider', function() { }, adUnits: [{ code: adUnitCode, - bids: [{ - bidder: 'smartadserver' - }, { - bidder: 'pubmatic' - }, { - bidder: 'appnexus' - }, { - bidder: 'rubicon' - }, { - bidder: 'other' - }] + bids: deepClone(adUnitsBids), }] }; const onDoneSpy = sinon.spy(); @@ -1443,20 +1361,28 @@ describe('weboramaRtdProvider', function() { 'adunit1': data, }); - expect(reqBidsConfigObj.adUnits[0].bids.length).to.equal(5); - expect(reqBidsConfigObj.adUnits[0].bids[0].params).to.be.undefined; - expect(reqBidsConfigObj.adUnits[0].bids[1].params).to.be.undefined; - expect(reqBidsConfigObj.adUnits[0].bids[2].params.keywords).to.deep.equal(data); - expect(reqBidsConfigObj.adUnits[0].bids[3].params).to.be.undefined; - ['smartadserver', 'pubmatic', 'appnexus', 'rubicon', 'other'].forEach((v) => { - expect(reqBidsConfigObj.ortb2Fragments.bidder[v]).to.deep.equal({ + reqBidsConfigObj.adUnits.forEach(adUnit => { + expect(adUnit.bids).to.deep.equal(adUnitsBids); + }); + + const bidders = Object.values(adUnitsBids).map(v => v.bidder); + const expectedORTB2BidderFragments = bidders.reduce((frag, bidder) => { + frag[bidder] = { user: { ext: { data: data }, } - }); - }) + }; + + return frag + }, {}); + + expect(reqBidsConfigObj.ortb2Fragments).to.deep.equal({ + global: {}, + bidder: expectedORTB2BidderFragments, + }); + expect(onDataResponse).to.deep.equal({ data: data, meta: { @@ -1521,6 +1447,17 @@ describe('weboramaRtdProvider', function() { const adUnitCode1 = 'adunit1'; const adUnitCode2 = 'adunit2'; + const adUnitsBids = [{ + bidder: 'smartadserver' + }, { + bidder: 'pubmatic' + }, { + bidder: 'appnexus' + }, { + bidder: 'rubicon' + }, { + bidder: 'other' + }]; const reqBidsConfigObj = { ortb2Fragments: { global: {}, @@ -1528,30 +1465,10 @@ describe('weboramaRtdProvider', function() { }, adUnits: [{ code: adUnitCode1, - bids: [{ - bidder: 'smartadserver' - }, { - bidder: 'pubmatic' - }, { - bidder: 'appnexus' - }, { - bidder: 'rubicon' - }, { - bidder: 'other' - }] + bids: deepClone(adUnitsBids), }, { code: adUnitCode2, - bids: [{ - bidder: 'smartadserver' - }, { - bidder: 'pubmatic' - }, { - bidder: 'appnexus' - }, { - bidder: 'rubicon' - }, { - bidder: 'other' - }] + bids: deepClone(adUnitsBids), }] }; const onDoneSpy = sinon.spy(); @@ -1569,27 +1486,24 @@ describe('weboramaRtdProvider', function() { }); reqBidsConfigObj.adUnits.forEach(adUnit => { - expect(adUnit.bids.length).to.equal(5); - expect(adUnit.bids[0].params).to.be.undefined; - expect(adUnit.bids[1].params).to.be.undefined; - expect(adUnit.bids[2].params.keywords).to.deep.equal(data); - expect(adUnit.bids[3].params).to.be.undefined; + expect(adUnit.bids).to.deep.equal(adUnitsBids); + }); + + const expectedORTB2BidderFragments = { + [APPNEXUS]: { + user: { + ext: { + data: data, + }, + }, + }, + }; + + expect(reqBidsConfigObj.ortb2Fragments).to.deep.equal({ + global: {}, + bidder: expectedORTB2BidderFragments, }); - ['smartadserver', 'pubmatic', 'appnexus', 'rubicon', 'other'].forEach((v) => { - if (v == 'appnexus') { - expect(reqBidsConfigObj.ortb2Fragments.bidder[v]).to.deep.equal({ - user: { - ext: { - data: data - }, - } - }); - - return - } - expect(reqBidsConfigObj.ortb2Fragments.bidder[v]).to.be.undefined; - }) expect(onDataResponse).to.deep.equal({ data: data, meta: { @@ -1647,6 +1561,17 @@ describe('weboramaRtdProvider', function() { const adUnitCode1 = 'adunit1'; const adUnitCode2 = 'adunit2'; + const adUnitsBids = [{ + bidder: 'smartadserver' + }, { + bidder: 'pubmatic' + }, { + bidder: 'appnexus' + }, { + bidder: 'rubicon' + }, { + bidder: 'other' + }]; const reqBidsConfigObj = { ortb2Fragments: { global: {}, @@ -1654,30 +1579,10 @@ describe('weboramaRtdProvider', function() { }, adUnits: [{ code: adUnitCode1, - bids: [{ - bidder: 'smartadserver' - }, { - bidder: 'pubmatic' - }, { - bidder: 'appnexus' - }, { - bidder: 'rubicon' - }, { - bidder: 'other' - }] + bids: deepClone(adUnitsBids), }, { code: adUnitCode2, - bids: [{ - bidder: 'smartadserver' - }, { - bidder: 'pubmatic' - }, { - bidder: 'appnexus' - }, { - bidder: 'rubicon' - }, { - bidder: 'other' - }] + bids: deepClone(adUnitsBids), }] }; const onDoneSpy = sinon.spy(); @@ -1695,29 +1600,23 @@ describe('weboramaRtdProvider', function() { }); reqBidsConfigObj.adUnits.forEach(adUnit => { - expect(adUnit.bids.length).to.equal(5); - expect(adUnit.bids[0].params).to.be.undefined; - expect(adUnit.bids[1].params).to.be.undefined; - expect(adUnit.bids[3].params).to.be.undefined; + expect(adUnit.bids).to.deep.equal(adUnitsBids); }); - ['smartadserver', 'pubmatic', 'appnexus', 'rubicon', 'other'].forEach((v) => { - if (v == 'appnexus') { - expect(reqBidsConfigObj.ortb2Fragments.bidder[v]).to.deep.equal({ - user: { - ext: { - data: data - }, - } - }); - - return - } - expect(reqBidsConfigObj.ortb2Fragments.bidder[v]).to.be.undefined; - }) + const expectedORTB2BidderFragments = { + [APPNEXUS]: { + user: { + ext: { + data: data, + }, + }, + }, + }; - expect(reqBidsConfigObj.adUnits[0].bids[2].params.keywords).to.deep.equal(data); - expect(reqBidsConfigObj.adUnits[1].bids[2].params).to.be.undefined; + expect(reqBidsConfigObj.ortb2Fragments).to.deep.equal({ + global: {}, + bidder: expectedORTB2BidderFragments, + }); expect(onDataResponse).to.deep.equal({ data: data, @@ -1769,6 +1668,36 @@ describe('weboramaRtdProvider', function() { const adUnitCode1 = 'adunit1'; const adUnitCode2 = 'adunit2'; + const adUnitsBids = [{ + bidder: 'smartadserver', + params: { + target: 'foo=bar' + } + }, { + bidder: 'pubmatic', + params: { + dctr: 'foo=bar' + } + }, { + bidder: 'appnexus', + params: { + keywords: { + foo: ['bar'] + } + } + }, { + bidder: 'rubicon', + params: { + inventory: { + foo: 'bar' + }, + visitor: { + baz: 'bam' + } + } + }, { + bidder: 'other' + }]; const reqBidsConfigObj = { ortb2Fragments: { global: {}, @@ -1776,68 +1705,10 @@ describe('weboramaRtdProvider', function() { }, adUnits: [{ code: adUnitCode1, - bids: [{ - bidder: 'smartadserver', - params: { - target: 'foo=bar' - } - }, { - bidder: 'pubmatic', - params: { - dctr: 'foo=bar' - } - }, { - bidder: 'appnexus', - params: { - keywords: { - foo: ['bar'] - } - } - }, { - bidder: 'rubicon', - params: { - inventory: { - foo: 'bar' - }, - visitor: { - baz: 'bam' - } - } - }, { - bidder: 'other' - }] + bids: deepClone(adUnitsBids), }, { code: adUnitCode2, - bids: [{ - bidder: 'smartadserver', - params: { - target: 'foo=bar' - } - }, { - bidder: 'pubmatic', - params: { - dctr: 'foo=bar' - } - }, { - bidder: 'appnexus', - params: { - keywords: { - foo: ['bar'] - } - } - }, { - bidder: 'rubicon', - params: { - inventory: { - foo: 'bar' - }, - visitor: { - baz: 'bam' - } - } - }, { - bidder: 'other' - }] + bids: deepClone(adUnitsBids), }] }; const onDoneSpy = sinon.spy(); @@ -1855,24 +1726,13 @@ describe('weboramaRtdProvider', function() { }); reqBidsConfigObj.adUnits.forEach(adUnit => { - expect(adUnit.bids.length).to.equal(5); - expect(adUnit.bids[0].params.target).to.equal('foo=bar'); - expect(adUnit.bids[1].params.dctr).to.equal('foo=bar'); - expect(adUnit.bids[2].params.keywords).to.deep.equal({ - foo: ['bar'] - }); - expect(adUnit.bids[3].params).to.deep.equal({ - inventory: { - foo: 'bar' - }, - visitor: { - baz: 'bam' - } - }); + expect(adUnit.bids).to.deep.equal(adUnitsBids); + }); + + expect(reqBidsConfigObj.ortb2Fragments).to.deep.equal({ + global: {}, + bidder: {}, }); - ['smartadserver', 'pubmatic', 'appnexus', 'rubicon', 'other'].forEach((v) => { - expect(reqBidsConfigObj.ortb2Fragments.bidder[v]).to.be.undefined; - }) }); }); }); @@ -1914,6 +1774,36 @@ describe('weboramaRtdProvider', function() { const adUnitCode1 = 'adunit1'; const adUnitCode2 = 'adunit2'; + const adUnitsBids = [{ + bidder: 'smartadserver', + params: { + target: 'foo=bar' + } + }, { + bidder: 'pubmatic', + params: { + dctr: 'foo=bar' + } + }, { + bidder: 'appnexus', + params: { + keywords: { + foo: ['bar'] + } + } + }, { + bidder: 'rubicon', + params: { + inventory: { + foo: 'bar' + }, + visitor: { + baz: 'bam' + } + } + }, { + bidder: 'other' + }]; const reqBidsConfigObj = { ortb2Fragments: { global: {}, @@ -1921,68 +1811,10 @@ describe('weboramaRtdProvider', function() { }, adUnits: [{ code: adUnitCode1, - bids: [{ - bidder: 'smartadserver', - params: { - target: 'foo=bar' - } - }, { - bidder: 'pubmatic', - params: { - dctr: 'foo=bar' - } - }, { - bidder: 'appnexus', - params: { - keywords: { - foo: ['bar'] - } - } - }, { - bidder: 'rubicon', - params: { - inventory: { - foo: 'bar' - }, - visitor: { - baz: 'bam' - } - } - }, { - bidder: 'other' - }] + bids: deepClone(adUnitsBids), }, { code: adUnitCode2, - bids: [{ - bidder: 'smartadserver', - params: { - target: 'foo=bar' - } - }, { - bidder: 'pubmatic', - params: { - dctr: 'foo=bar' - } - }, { - bidder: 'appnexus', - params: { - keywords: { - foo: ['bar'] - } - } - }, { - bidder: 'rubicon', - params: { - inventory: { - foo: 'bar' - }, - visitor: { - baz: 'bam' - } - } - }, { - bidder: 'other' - }] + bids: deepClone(adUnitsBids), }] }; const onDoneSpy = sinon.spy(); @@ -2000,24 +1832,13 @@ describe('weboramaRtdProvider', function() { }); reqBidsConfigObj.adUnits.forEach(adUnit => { - expect(adUnit.bids.length).to.equal(5); - expect(adUnit.bids[0].params.target).to.equal('foo=bar'); - expect(adUnit.bids[1].params.dctr).to.equal('foo=bar'); - expect(adUnit.bids[2].params.keywords).to.deep.equal({ - foo: ['bar'] - }); - expect(adUnit.bids[3].params).to.deep.equal({ - inventory: { - foo: 'bar' - }, - visitor: { - baz: 'bam' - } - }); + expect(adUnit.bids).to.deep.equal(adUnitsBids); + }); + + expect(reqBidsConfigObj.ortb2Fragments).to.deep.equal({ + global: {}, + bidder: {}, }); - ['smartadserver', 'pubmatic', 'appnexus', 'rubicon', 'other'].forEach((v) => { - expect(reqBidsConfigObj.ortb2Fragments.bidder[v]).to.be.undefined; - }) }); }); }); @@ -2117,6 +1938,36 @@ describe('weboramaRtdProvider', function() { .returns(JSON.stringify(entry)); const adUnitCode = 'adunit1'; + const adUnitsBids = [{ + bidder: 'smartadserver', + params: { + target: 'foo=bar' + } + }, { + bidder: 'pubmatic', + params: { + dctr: 'foo=bar' + } + }, { + bidder: 'appnexus', + params: { + keywords: { + foo: ['bar'] + } + } + }, { + bidder: 'rubicon', + params: { + inventory: { + foo: 'bar', + }, + visitor: { + baz: 'bam', + } + } + }, { + bidder: 'other' + }]; const reqBidsConfigObj = { ortb2Fragments: { global: {}, @@ -2124,36 +1975,7 @@ describe('weboramaRtdProvider', function() { }, adUnits: [{ code: adUnitCode, - bids: [{ - bidder: 'smartadserver', - params: { - target: 'foo=bar' - } - }, { - bidder: 'pubmatic', - params: { - dctr: 'foo=bar' - } - }, { - bidder: 'appnexus', - params: { - keywords: { - foo: ['bar'] - } - } - }, { - bidder: 'rubicon', - params: { - inventory: { - foo: 'bar', - }, - visitor: { - baz: 'bam', - } - } - }, { - bidder: 'other' - }] + bids: deepClone(adUnitsBids), }] }; const onDoneSpy = sinon.spy(); @@ -2169,31 +1991,27 @@ describe('weboramaRtdProvider', function() { 'adunit1': {}, }); - expect(reqBidsConfigObj.adUnits[0].bids.length).to.equal(5); - expect(reqBidsConfigObj.adUnits[0].bids[0].params.target).to.equal('foo=bar'); - expect(reqBidsConfigObj.adUnits[0].bids[1].params.dctr).to.equal('foo=bar'); - expect(reqBidsConfigObj.adUnits[0].bids[2].params.keywords).to.deep.equal({ - foo: ['bar'], - webo_cs: ['foo', 'bar'], - webo_audiences: ['baz'], - }); - expect(reqBidsConfigObj.adUnits[0].bids[3].params).to.deep.equal({ - inventory: { - foo: 'bar', - }, - visitor: { - baz: 'bam', - } + reqBidsConfigObj.adUnits.forEach(adUnit => { + expect(adUnit.bids).to.deep.equal(adUnitsBids); }); - ['smartadserver', 'pubmatic', 'appnexus', 'rubicon', 'other'].forEach((v) => { - expect(reqBidsConfigObj.ortb2Fragments.bidder[v]).to.deep.equal({ + + const bidders = Object.values(adUnitsBids).map(v => v.bidder); + const expectedORTB2BidderFragments = bidders.reduce((frag, bidder) => { + frag[bidder] = { user: { ext: { data: data }, } - }); - }) + }; + + return frag + }, {}); + + expect(reqBidsConfigObj.ortb2Fragments).to.deep.equal({ + global: {}, + bidder: expectedORTB2BidderFragments, + }); }); it('should use default profile in case of nothing on local storage', function() { @@ -2214,6 +2032,17 @@ describe('weboramaRtdProvider', function() { sandbox.stub(storage, 'localStorageIsEnabled').returns(true); const adUnitCode = 'adunit1'; + const adUnitsBids = [{ + bidder: 'smartadserver' + }, { + bidder: 'pubmatic' + }, { + bidder: 'appnexus' + }, { + bidder: 'rubicon' + }, { + bidder: 'other' + }]; const reqBidsConfigObj = { ortb2Fragments: { global: {}, @@ -2221,17 +2050,7 @@ describe('weboramaRtdProvider', function() { }, adUnits: [{ code: adUnitCode, - bids: [{ - bidder: 'smartadserver' - }, { - bidder: 'pubmatic' - }, { - bidder: 'appnexus' - }, { - bidder: 'rubicon' - }, { - bidder: 'other' - }] + bids: deepClone(adUnitsBids), }] }; const onDoneSpy = sinon.spy(); @@ -2247,20 +2066,27 @@ describe('weboramaRtdProvider', function() { 'adunit1': defaultProfile, }); - expect(reqBidsConfigObj.adUnits[0].bids.length).to.equal(5); - expect(reqBidsConfigObj.adUnits[0].bids[0].params).to.be.undefined; - expect(reqBidsConfigObj.adUnits[0].bids[1].params).to.be.undefined; - expect(reqBidsConfigObj.adUnits[0].bids[2].params.keywords).to.deep.equal(defaultProfile); - expect(reqBidsConfigObj.adUnits[0].bids[3].params).to.be.undefined; - ['smartadserver', 'pubmatic', 'appnexus', 'rubicon', 'other'].forEach((v) => { - expect(reqBidsConfigObj.ortb2Fragments.bidder[v]).to.deep.equal({ + reqBidsConfigObj.adUnits.forEach(adUnit => { + expect(adUnit.bids).to.deep.equal(adUnitsBids); + }); + + const bidders = Object.values(adUnitsBids).map(v => v.bidder); + const expectedORTB2BidderFragments = bidders.reduce((frag, bidder) => { + frag[bidder] = { user: { ext: { - data: defaultProfile + data: defaultProfile, }, } - }); - }) + }; + + return frag + }, {}); + + expect(reqBidsConfigObj.ortb2Fragments).to.deep.equal({ + global: {}, + bidder: expectedORTB2BidderFragments, + }); }); it('should use default profile if cant read from local storage', function() { @@ -2288,6 +2114,17 @@ describe('weboramaRtdProvider', function() { sandbox.stub(storage, 'localStorageIsEnabled').returns(false); const adUnitCode = 'adunit1'; + const adUnitsBids = [{ + bidder: 'smartadserver' + }, { + bidder: 'pubmatic' + }, { + bidder: 'appnexus' + }, { + bidder: 'rubicon' + }, { + bidder: 'other' + }]; const reqBidsConfigObj = { ortb2Fragments: { global: {}, @@ -2295,17 +2132,7 @@ describe('weboramaRtdProvider', function() { }, adUnits: [{ code: adUnitCode, - bids: [{ - bidder: 'smartadserver' - }, { - bidder: 'pubmatic' - }, { - bidder: 'appnexus' - }, { - bidder: 'rubicon' - }, { - bidder: 'other' - }] + bids: deepClone(adUnitsBids), }] }; const onDoneSpy = sinon.spy(); @@ -2321,20 +2148,28 @@ describe('weboramaRtdProvider', function() { 'adunit1': defaultProfile, }); - expect(reqBidsConfigObj.adUnits[0].bids.length).to.equal(5); - expect(reqBidsConfigObj.adUnits[0].bids[0].params).to.be.undefined; - expect(reqBidsConfigObj.adUnits[0].bids[1].params).to.be.undefined; - expect(reqBidsConfigObj.adUnits[0].bids[2].params.keywords).to.deep.equal(defaultProfile); - expect(reqBidsConfigObj.adUnits[0].bids[3].params).to.be.undefined; - ['smartadserver', 'pubmatic', 'appnexus', 'rubicon', 'other'].forEach((v) => { - expect(reqBidsConfigObj.ortb2Fragments.bidder[v]).to.deep.equal({ + reqBidsConfigObj.adUnits.forEach(adUnit => { + expect(adUnit.bids).to.deep.equal(adUnitsBids); + }); + + const bidders = Object.values(adUnitsBids).map(v => v.bidder); + const expectedORTB2BidderFragments = bidders.reduce((frag, bidder) => { + frag[bidder] = { user: { ext: { - data: defaultProfile + data: defaultProfile, }, } - }); - }) + }; + + return frag + }, {}); + + expect(reqBidsConfigObj.ortb2Fragments).to.deep.equal({ + global: {}, + bidder: expectedORTB2BidderFragments, + }); + expect(onDataResponse).to.deep.equal({ data: defaultProfile, meta: { @@ -2390,6 +2225,17 @@ describe('weboramaRtdProvider', function() { const adUnitCode1 = 'adunit1'; const adUnitCode2 = 'adunit2'; + const adUnitsBids = [{ + bidder: 'smartadserver' + }, { + bidder: 'pubmatic' + }, { + bidder: 'appnexus' + }, { + bidder: 'rubicon' + }, { + bidder: 'other' + }]; const reqBidsConfigObj = { ortb2Fragments: { global: {}, @@ -2397,30 +2243,10 @@ describe('weboramaRtdProvider', function() { }, adUnits: [{ code: adUnitCode1, - bids: [{ - bidder: 'smartadserver' - }, { - bidder: 'pubmatic' - }, { - bidder: 'appnexus' - }, { - bidder: 'rubicon' - }, { - bidder: 'other' - }] + bids: deepClone(adUnitsBids), }, { code: adUnitCode2, - bids: [{ - bidder: 'smartadserver' - }, { - bidder: 'pubmatic' - }, { - bidder: 'appnexus' - }, { - bidder: 'rubicon' - }, { - bidder: 'other' - }] + bids: deepClone(adUnitsBids), }] }; @@ -2448,31 +2274,34 @@ describe('weboramaRtdProvider', function() { expect(adUnit.bids[1].params).to.be.undefined; expect(adUnit.bids[3].params).to.be.undefined; }); - ['smartadserver', 'pubmatic', 'appnexus', 'rubicon', 'other'].forEach((v) => { - if (v == 'appnexus') { - expect(reqBidsConfigObj.ortb2Fragments.bidder[v]).to.deep.equal({ - user: { - ext: { - data: { - webo_cs: ['foo', 'bar'], - webo_audiences: ['baz'], - webo_bar: ['baz'], - } - }, - } - }); - - return - } - expect(reqBidsConfigObj.ortb2Fragments.bidder[v]).to.deep.equal({ + const bidders = Object.values(adUnitsBids).map(v => v.bidder); + const expectedORTB2BidderFragments = bidders.reduce((frag, bidder) => { + frag[bidder] = { user: { ext: { - data: data + data: data, }, } - }); - }) + }; + + return frag + }, {}); + + expectedORTB2BidderFragments[APPNEXUS].user = { + ext: { + data: { + webo_cs: ['foo', 'bar'], + webo_audiences: ['baz'], + webo_bar: ['baz'], + } + }, + }; + + expect(reqBidsConfigObj.ortb2Fragments).to.deep.equal({ + global: {}, + bidder: expectedORTB2BidderFragments, + }); expect(onDataResponse).to.deep.equal({ data: data, @@ -2516,6 +2345,17 @@ describe('weboramaRtdProvider', function() { .returns(JSON.stringify(entry)); const adUnitCode = 'adunit1'; + const adUnitsBids = [{ + bidder: 'smartadserver' + }, { + bidder: 'pubmatic' + }, { + bidder: 'appnexus' + }, { + bidder: 'rubicon' + }, { + bidder: 'other' + }]; const reqBidsConfigObj = { ortb2Fragments: { global: {}, @@ -2523,17 +2363,7 @@ describe('weboramaRtdProvider', function() { }, adUnits: [{ code: adUnitCode, - bids: [{ - bidder: 'smartadserver' - }, { - bidder: 'pubmatic' - }, { - bidder: 'appnexus' - }, { - bidder: 'rubicon' - }, { - bidder: 'other' - }] + bids: deepClone(adUnitsBids), }] }; const onDoneSpy = sinon.spy(); @@ -2549,20 +2379,28 @@ describe('weboramaRtdProvider', function() { 'adunit1': data, }); - expect(reqBidsConfigObj.adUnits[0].bids.length).to.equal(5); - expect(reqBidsConfigObj.adUnits[0].bids[0].params).to.be.undefined; - expect(reqBidsConfigObj.adUnits[0].bids[1].params).to.be.undefined; - expect(reqBidsConfigObj.adUnits[0].bids[2].params.keywords).to.deep.equal(data); - expect(reqBidsConfigObj.adUnits[0].bids[3].params).to.be.undefined; - ['smartadserver', 'pubmatic', 'appnexus', 'rubicon', 'other'].forEach((v) => { - expect(reqBidsConfigObj.ortb2Fragments.bidder[v]).to.deep.equal({ + reqBidsConfigObj.adUnits.forEach(adUnit => { + expect(adUnit.bids).to.deep.equal(adUnitsBids); + }); + + const bidders = Object.values(adUnitsBids).map(v => v.bidder); + const expectedORTB2BidderFragments = bidders.reduce((frag, bidder) => { + frag[bidder] = { site: { ext: { data: data }, } - }); - }) + }; + + return frag + }, {}); + + expect(reqBidsConfigObj.ortb2Fragments).to.deep.equal({ + global: {}, + bidder: expectedORTB2BidderFragments, + }); + expect(onDataResponse).to.deep.equal({ data: data, meta: { @@ -2626,6 +2464,17 @@ describe('weboramaRtdProvider', function() { const adUnitCode1 = 'adunit1'; const adUnitCode2 = 'adunit2'; + const adUnitsBids = [{ + bidder: 'smartadserver' + }, { + bidder: 'pubmatic' + }, { + bidder: 'appnexus' + }, { + bidder: 'rubicon' + }, { + bidder: 'other' + }]; const reqBidsConfigObj = { ortb2Fragments: { global: {}, @@ -2633,30 +2482,10 @@ describe('weboramaRtdProvider', function() { }, adUnits: [{ code: adUnitCode1, - bids: [{ - bidder: 'smartadserver' - }, { - bidder: 'pubmatic' - }, { - bidder: 'appnexus' - }, { - bidder: 'rubicon' - }, { - bidder: 'other' - }] + bids: deepClone(adUnitsBids), }, { code: adUnitCode2, - bids: [{ - bidder: 'smartadserver' - }, { - bidder: 'pubmatic' - }, { - bidder: 'appnexus' - }, { - bidder: 'rubicon' - }, { - bidder: 'other' - }] + bids: deepClone(adUnitsBids), }] }; const onDoneSpy = sinon.spy(); @@ -2674,27 +2503,21 @@ describe('weboramaRtdProvider', function() { }); reqBidsConfigObj.adUnits.forEach(adUnit => { - expect(adUnit.bids.length).to.equal(5); - expect(adUnit.bids[0].params).to.be.undefined; - expect(adUnit.bids[1].params).to.be.undefined; - expect(adUnit.bids[2].params.keywords).to.deep.equal(data); - expect(adUnit.bids[3].params).to.be.undefined; + expect(adUnit.bids).to.deep.equal(adUnitsBids); }); - ['smartadserver', 'pubmatic', 'appnexus', 'rubicon', 'other'].forEach((v) => { - if (v == 'appnexus') { - expect(reqBidsConfigObj.ortb2Fragments.bidder[v]).to.deep.equal({ - site: { - ext: { - data: data - }, - } - }); - - return - } - expect(reqBidsConfigObj.ortb2Fragments.bidder[v]).to.be.undefined; - }) + const bidders = Object.values(adUnitsBids).map(v => v.bidder); + const expectedORTB2BidderFragments = bidders.reduce((frag, bidder) => { + frag[bidder] = { + site: { + ext: { + data: data + }, + } + }; + + return frag + }, {}); expect(onDataResponse).to.deep.equal({ data: data, @@ -2752,6 +2575,17 @@ describe('weboramaRtdProvider', function() { const adUnitCode1 = 'adunit1'; const adUnitCode2 = 'adunit2'; + const adUnitsBids = [{ + bidder: 'smartadserver' + }, { + bidder: 'pubmatic' + }, { + bidder: 'appnexus' + }, { + bidder: 'rubicon' + }, { + bidder: 'other' + }]; const reqBidsConfigObj = { ortb2Fragments: { global: {}, @@ -2759,30 +2593,10 @@ describe('weboramaRtdProvider', function() { }, adUnits: [{ code: adUnitCode1, - bids: [{ - bidder: 'smartadserver' - }, { - bidder: 'pubmatic' - }, { - bidder: 'appnexus' - }, { - bidder: 'rubicon' - }, { - bidder: 'other' - }] + bids: deepClone(adUnitsBids), }, { code: adUnitCode2, - bids: [{ - bidder: 'smartadserver' - }, { - bidder: 'pubmatic' - }, { - bidder: 'appnexus' - }, { - bidder: 'rubicon' - }, { - bidder: 'other' - }] + bids: deepClone(adUnitsBids), }] }; const onDoneSpy = sinon.spy(); @@ -2800,30 +2614,21 @@ describe('weboramaRtdProvider', function() { }); reqBidsConfigObj.adUnits.forEach(adUnit => { - expect(adUnit.bids.length).to.equal(5); - expect(adUnit.bids[0].params).to.be.undefined; - expect(adUnit.bids[1].params).to.be.undefined; - expect(adUnit.bids[3].params).to.be.undefined; + expect(adUnit.bids).to.deep.equal(adUnitsBids); }); - expect(reqBidsConfigObj.adUnits[0].bids[2].params.keywords).to.deep.equal(data); - expect(reqBidsConfigObj.adUnits[1].bids[2].params).to.be.undefined; - - ['smartadserver', 'pubmatic', 'appnexus', 'rubicon', 'other'].forEach((v) => { - if (v == 'appnexus') { - expect(reqBidsConfigObj.ortb2Fragments.bidder[v]).to.deep.equal({ - site: { - ext: { - data: data - }, - } - }); - - return - } + const bidders = Object.values(adUnitsBids).map(v => v.bidder); + const expectedORTB2BidderFragments = bidders.reduce((frag, bidder) => { + frag[bidder] = { + site: { + ext: { + data: data + }, + } + }; - expect(reqBidsConfigObj.ortb2Fragments.bidder[v]).to.be.undefined; - }) + return frag + }, {}); expect(onDataResponse).to.deep.equal({ data: data, @@ -2874,6 +2679,36 @@ describe('weboramaRtdProvider', function() { const adUnitCode1 = 'adunit1'; const adUnitCode2 = 'adunit2'; + const adUnitsBids = [{ + bidder: 'smartadserver', + params: { + target: 'foo=bar' + } + }, { + bidder: 'pubmatic', + params: { + dctr: 'foo=bar' + } + }, { + bidder: 'appnexus', + params: { + keywords: { + foo: ['bar'] + } + } + }, { + bidder: 'rubicon', + params: { + inventory: { + foo: 'bar' + }, + visitor: { + baz: 'bam' + } + } + }, { + bidder: 'other' + }]; const reqBidsConfigObj = { ortb2Fragments: { global: {}, @@ -2881,68 +2716,10 @@ describe('weboramaRtdProvider', function() { }, adUnits: [{ code: adUnitCode1, - bids: [{ - bidder: 'smartadserver', - params: { - target: 'foo=bar' - } - }, { - bidder: 'pubmatic', - params: { - dctr: 'foo=bar' - } - }, { - bidder: 'appnexus', - params: { - keywords: { - foo: ['bar'] - } - } - }, { - bidder: 'rubicon', - params: { - inventory: { - foo: 'bar' - }, - visitor: { - baz: 'bam' - } - } - }, { - bidder: 'other' - }] + bids: deepClone(adUnitsBids), }, { code: adUnitCode2, - bids: [{ - bidder: 'smartadserver', - params: { - target: 'foo=bar' - } - }, { - bidder: 'pubmatic', - params: { - dctr: 'foo=bar' - } - }, { - bidder: 'appnexus', - params: { - keywords: { - foo: ['bar'] - } - } - }, { - bidder: 'rubicon', - params: { - inventory: { - foo: 'bar' - }, - visitor: { - baz: 'bam' - } - } - }, { - bidder: 'other' - }] + bids: deepClone(adUnitsBids), }] }; const onDoneSpy = sinon.spy(); @@ -2960,24 +2737,13 @@ describe('weboramaRtdProvider', function() { }); reqBidsConfigObj.adUnits.forEach(adUnit => { - expect(adUnit.bids.length).to.equal(5); - expect(adUnit.bids[0].params.target).to.equal('foo=bar'); - expect(adUnit.bids[1].params.dctr).to.equal('foo=bar'); - expect(adUnit.bids[2].params.keywords).to.deep.equal({ - foo: ['bar'] - }); - expect(adUnit.bids[3].params).to.deep.equal({ - inventory: { - foo: 'bar' - }, - visitor: { - baz: 'bam' - } - }); + expect(adUnit.bids).to.deep.equal(adUnitsBids); + }); + + expect(reqBidsConfigObj.ortb2Fragments).to.deep.equal({ + global: {}, + bidder: {}, }); - ['smartadserver', 'pubmatic', 'appnexus', 'rubicon', 'other'].forEach((v) => { - expect(reqBidsConfigObj.ortb2Fragments.bidder[v]).to.be.undefined; - }) }); }); }); @@ -3018,6 +2784,36 @@ describe('weboramaRtdProvider', function() { const adUnitCode1 = 'adunit1'; const adUnitCode2 = 'adunit2'; + const adUnitsBids = [{ + bidder: 'smartadserver', + params: { + target: 'foo=bar' + } + }, { + bidder: 'pubmatic', + params: { + dctr: 'foo=bar' + } + }, { + bidder: 'appnexus', + params: { + keywords: { + foo: ['bar'] + } + } + }, { + bidder: 'rubicon', + params: { + inventory: { + foo: 'bar' + }, + visitor: { + baz: 'bam' + } + } + }, { + bidder: 'other' + }]; const reqBidsConfigObj = { ortb2Fragments: { global: {}, @@ -3025,68 +2821,10 @@ describe('weboramaRtdProvider', function() { }, adUnits: [{ code: adUnitCode1, - bids: [{ - bidder: 'smartadserver', - params: { - target: 'foo=bar' - } - }, { - bidder: 'pubmatic', - params: { - dctr: 'foo=bar' - } - }, { - bidder: 'appnexus', - params: { - keywords: { - foo: ['bar'] - } - } - }, { - bidder: 'rubicon', - params: { - inventory: { - foo: 'bar' - }, - visitor: { - baz: 'bam' - } - } - }, { - bidder: 'other' - }] + bids: deepClone(adUnitsBids), }, { code: adUnitCode2, - bids: [{ - bidder: 'smartadserver', - params: { - target: 'foo=bar' - } - }, { - bidder: 'pubmatic', - params: { - dctr: 'foo=bar' - } - }, { - bidder: 'appnexus', - params: { - keywords: { - foo: ['bar'] - } - } - }, { - bidder: 'rubicon', - params: { - inventory: { - foo: 'bar' - }, - visitor: { - baz: 'bam' - } - } - }, { - bidder: 'other' - }] + bids: deepClone(adUnitsBids), }] }; const onDoneSpy = sinon.spy(); @@ -3104,24 +2842,13 @@ describe('weboramaRtdProvider', function() { }); reqBidsConfigObj.adUnits.forEach(adUnit => { - expect(adUnit.bids.length).to.equal(5); - expect(adUnit.bids[0].params.target).to.equal('foo=bar'); - expect(adUnit.bids[1].params.dctr).to.equal('foo=bar'); - expect(adUnit.bids[2].params.keywords).to.deep.equal({ - foo: ['bar'] - }); - expect(adUnit.bids[3].params).to.deep.equal({ - inventory: { - foo: 'bar' - }, - visitor: { - baz: 'bam' - } - }); + expect(adUnit.bids).to.deep.equal(adUnitsBids); + }); + + expect(reqBidsConfigObj.ortb2Fragments).to.deep.equal({ + global: {}, + bidder: {}, }); - ['smartadserver', 'pubmatic', 'appnexus', 'rubicon', 'other'].forEach((v) => { - expect(reqBidsConfigObj.ortb2Fragments.bidder[v]).to.be.undefined; - }) }); }); }); @@ -3223,6 +2950,36 @@ describe('weboramaRtdProvider', function() { .returns(JSON.stringify(entry)); const adUnitCode = 'adunit1'; + const adUnitsBids = [{ + bidder: 'smartadserver', + params: { + target: 'foo=bar' + } + }, { + bidder: 'pubmatic', + params: { + dctr: 'foo=bar' + } + }, { + bidder: 'appnexus', + params: { + keywords: { + foo: ['bar'] + } + } + }, { + bidder: 'rubicon', + params: { + inventory: { + foo: 'bar', + }, + visitor: { + baz: 'bam', + } + } + }, { + bidder: 'other' + }]; const reqBidsConfigObj = { ortb2Fragments: { global: {}, @@ -3230,36 +2987,7 @@ describe('weboramaRtdProvider', function() { }, adUnits: [{ code: adUnitCode, - bids: [{ - bidder: 'smartadserver', - params: { - target: 'foo=bar' - } - }, { - bidder: 'pubmatic', - params: { - dctr: 'foo=bar' - } - }, { - bidder: 'appnexus', - params: { - keywords: { - foo: ['bar'] - } - } - }, { - bidder: 'rubicon', - params: { - inventory: { - foo: 'bar', - }, - visitor: { - baz: 'bam', - } - } - }, { - bidder: 'other' - }] + bids: deepClone(adUnitsBids), }] }; const onDoneSpy = sinon.spy(); @@ -3275,31 +3003,27 @@ describe('weboramaRtdProvider', function() { 'adunit1': {}, }); - expect(reqBidsConfigObj.adUnits[0].bids.length).to.equal(5); - expect(reqBidsConfigObj.adUnits[0].bids[0].params.target).to.equal('foo=bar'); - expect(reqBidsConfigObj.adUnits[0].bids[1].params.dctr).to.equal('foo=bar'); - expect(reqBidsConfigObj.adUnits[0].bids[2].params.keywords).to.deep.equal({ - foo: ['bar'], - lite_occupation: ['gérant', 'bénévole'], - lite_hobbies: ['sport', 'cinéma'], - }); - expect(reqBidsConfigObj.adUnits[0].bids[3].params).to.deep.equal({ - inventory: { - foo: 'bar', - }, - visitor: { - baz: 'bam', - } + reqBidsConfigObj.adUnits.forEach(adUnit => { + expect(adUnit.bids).to.deep.equal(adUnitsBids); }); - ['smartadserver', 'pubmatic', 'appnexus', 'rubicon', 'other'].forEach((v) => { - expect(reqBidsConfigObj.ortb2Fragments.bidder[v]).to.deep.equal({ + + const bidders = Object.values(adUnitsBids).map(v => v.bidder); + const expectedORTB2BidderFragments = bidders.reduce((frag, bidder) => { + frag[bidder] = { site: { ext: { data: data }, } - }); - }) + }; + + return frag + }, {}); + + expect(reqBidsConfigObj.ortb2Fragments).to.deep.equal({ + global: {}, + bidder: expectedORTB2BidderFragments, + }); }); it('should use default profile in case of nothing on local storage', function() { @@ -3319,6 +3043,17 @@ describe('weboramaRtdProvider', function() { sandbox.stub(storage, 'localStorageIsEnabled').returns(true); const adUnitCode = 'adunit1'; + const adUnitsBids = [{ + bidder: 'smartadserver' + }, { + bidder: 'pubmatic' + }, { + bidder: 'appnexus' + }, { + bidder: 'rubicon' + }, { + bidder: 'other' + }]; const reqBidsConfigObj = { ortb2Fragments: { global: {}, @@ -3326,17 +3061,7 @@ describe('weboramaRtdProvider', function() { }, adUnits: [{ code: adUnitCode, - bids: [{ - bidder: 'smartadserver' - }, { - bidder: 'pubmatic' - }, { - bidder: 'appnexus' - }, { - bidder: 'rubicon' - }, { - bidder: 'other' - }] + bids: deepClone(adUnitsBids), }] }; const onDoneSpy = sinon.spy(); @@ -3352,20 +3077,27 @@ describe('weboramaRtdProvider', function() { 'adunit1': defaultProfile, }); - expect(reqBidsConfigObj.adUnits[0].bids.length).to.equal(5); - expect(reqBidsConfigObj.adUnits[0].bids[0].params).to.be.undefined; - expect(reqBidsConfigObj.adUnits[0].bids[1].params).to.be.undefined; - expect(reqBidsConfigObj.adUnits[0].bids[2].params.keywords).to.deep.equal(defaultProfile); - expect(reqBidsConfigObj.adUnits[0].bids[3].params).to.be.undefined; - ['smartadserver', 'pubmatic', 'appnexus', 'rubicon', 'other'].forEach((v) => { - expect(reqBidsConfigObj.ortb2Fragments.bidder[v]).to.deep.equal({ + reqBidsConfigObj.adUnits.forEach(adUnit => { + expect(adUnit.bids).to.deep.equal(adUnitsBids); + }); + + const bidders = Object.values(adUnitsBids).map(v => v.bidder); + const expectedORTB2BidderFragments = bidders.reduce((frag, bidder) => { + frag[bidder] = { site: { ext: { data: defaultProfile }, } - }); - }) + }; + + return frag + }, {}); + + expect(reqBidsConfigObj.ortb2Fragments).to.deep.equal({ + global: {}, + bidder: expectedORTB2BidderFragments, + }); }); it('should use default profile if cant read from local storage', function() { @@ -3392,6 +3124,17 @@ describe('weboramaRtdProvider', function() { sandbox.stub(storage, 'localStorageIsEnabled').returns(false); const adUnitCode = 'adunit1'; + const adUnitsBids = [{ + bidder: 'smartadserver' + }, { + bidder: 'pubmatic' + }, { + bidder: 'appnexus' + }, { + bidder: 'rubicon' + }, { + bidder: 'other' + }]; const reqBidsConfigObj = { ortb2Fragments: { global: {}, @@ -3399,17 +3142,7 @@ describe('weboramaRtdProvider', function() { }, adUnits: [{ code: adUnitCode, - bids: [{ - bidder: 'smartadserver' - }, { - bidder: 'pubmatic' - }, { - bidder: 'appnexus' - }, { - bidder: 'rubicon' - }, { - bidder: 'other' - }] + bids: deepClone(adUnitsBids), }] }; const onDoneSpy = sinon.spy(); @@ -3425,27 +3158,28 @@ describe('weboramaRtdProvider', function() { 'adunit1': defaultProfile, }); - expect(reqBidsConfigObj.adUnits[0].bids.length).to.equal(5); - expect(reqBidsConfigObj.adUnits[0].bids[0].params).to.be.undefined; - expect(reqBidsConfigObj.adUnits[0].bids[1].params).to.be.undefined; - expect(reqBidsConfigObj.adUnits[0].bids[2].params.keywords).to.deep.equal(defaultProfile); - expect(reqBidsConfigObj.adUnits[0].bids[3].params).to.be.undefined; - expect(reqBidsConfigObj.ortb2Fragments.bidder.other).to.deep.equal({ - site: { - ext: { - data: defaultProfile, - }, - }, + reqBidsConfigObj.adUnits.forEach(adUnit => { + expect(adUnit.bids).to.deep.equal(adUnitsBids); }); - ['smartadserver', 'pubmatic', 'appnexus', 'rubicon', 'other'].forEach((v) => { - expect(reqBidsConfigObj.ortb2Fragments.bidder[v]).to.deep.equal({ + + const bidders = Object.values(adUnitsBids).map(v => v.bidder); + const expectedORTB2BidderFragments = bidders.reduce((frag, bidder) => { + frag[bidder] = { site: { ext: { - data: defaultProfile, + data: defaultProfile }, } - }); - }) + }; + + return frag + }, {}); + + expect(reqBidsConfigObj.ortb2Fragments).to.deep.equal({ + global: {}, + bidder: expectedORTB2BidderFragments, + }); + expect(onDataResponse).to.deep.equal({ data: defaultProfile, meta: { @@ -3479,6 +3213,17 @@ describe('weboramaRtdProvider', function() { sandbox.stub(storage, 'hasLocalStorage').returns(false); const adUnitCode = 'adunit1'; + const adUnitsBids = [{ + bidder: 'smartadserver' + }, { + bidder: 'pubmatic' + }, { + bidder: 'appnexus' + }, { + bidder: 'rubicon' + }, { + bidder: 'other' + }]; const reqBidsConfigObj = { ortb2Fragments: { global: {}, @@ -3486,17 +3231,7 @@ describe('weboramaRtdProvider', function() { }, adUnits: [{ code: adUnitCode, - bids: [{ - bidder: 'smartadserver' - }, { - bidder: 'pubmatic' - }, { - bidder: 'appnexus' - }, { - bidder: 'rubicon' - }, { - bidder: 'other' - }] + bids: deepClone(adUnitsBids), }] }; const onDoneSpy = sinon.spy(); @@ -3512,20 +3247,28 @@ describe('weboramaRtdProvider', function() { 'adunit1': defaultProfile, }); - expect(reqBidsConfigObj.adUnits[0].bids.length).to.equal(5); - expect(reqBidsConfigObj.adUnits[0].bids[0].params).to.be.undefined; - expect(reqBidsConfigObj.adUnits[0].bids[1].params).to.be.undefined; - expect(reqBidsConfigObj.adUnits[0].bids[2].params.keywords).to.deep.equal(defaultProfile); - expect(reqBidsConfigObj.adUnits[0].bids[3].params).to.be.undefined; - ['smartadserver', 'pubmatic', 'appnexus', 'rubicon', 'other'].forEach((v) => { - expect(reqBidsConfigObj.ortb2Fragments.bidder[v]).to.deep.equal({ + reqBidsConfigObj.adUnits.forEach(adUnit => { + expect(adUnit.bids).to.deep.equal(adUnitsBids); + }); + + const bidders = Object.values(adUnitsBids).map(v => v.bidder); + const expectedORTB2BidderFragments = bidders.reduce((frag, bidder) => { + frag[bidder] = { site: { ext: { data: defaultProfile }, } - }); - }) + }; + + return frag + }, {}); + + expect(reqBidsConfigObj.ortb2Fragments).to.deep.equal({ + global: {}, + bidder: expectedORTB2BidderFragments, + }); + expect(onDataResponse).to.deep.equal({ data: defaultProfile, meta: { @@ -3535,6 +3278,7 @@ describe('weboramaRtdProvider', function() { }, }); }); + it('should be possible update profile from callbacks for a given bidder/adUnitCode', function() { let onDataResponse = {}; const moduleConfig = { @@ -3579,6 +3323,17 @@ describe('weboramaRtdProvider', function() { const adUnitCode1 = 'adunit1'; const adUnitCode2 = 'adunit2'; + const adUnitsBids = [{ + bidder: 'smartadserver' + }, { + bidder: 'pubmatic' + }, { + bidder: 'appnexus' + }, { + bidder: 'rubicon' + }, { + bidder: 'other' + }]; const reqBidsConfigObj = { ortb2Fragments: { global: {}, @@ -3586,30 +3341,10 @@ describe('weboramaRtdProvider', function() { }, adUnits: [{ code: adUnitCode1, - bids: [{ - bidder: 'smartadserver' - }, { - bidder: 'pubmatic' - }, { - bidder: 'appnexus' - }, { - bidder: 'rubicon' - }, { - bidder: 'other' - }] + bids: deepClone(adUnitsBids), }, { code: adUnitCode2, - bids: [{ - bidder: 'smartadserver' - }, { - bidder: 'pubmatic' - }, { - bidder: 'appnexus' - }, { - bidder: 'rubicon' - }, { - bidder: 'other' - }] + bids: deepClone(adUnitsBids), }] }; @@ -3632,43 +3367,36 @@ describe('weboramaRtdProvider', function() { }); reqBidsConfigObj.adUnits.forEach(adUnit => { - expect(adUnit.bids.length).to.equal(5); - expect(adUnit.bids[0].params).to.be.undefined; - expect(adUnit.bids[1].params).to.be.undefined; - expect(adUnit.bids[3].params).to.be.undefined; + expect(adUnit.bids).to.deep.equal(adUnitsBids); }); - ['smartadserver', 'pubmatic', 'appnexus', 'rubicon', 'other'].forEach((v) => { - if (v == 'appnexus') { - expect(reqBidsConfigObj.ortb2Fragments.bidder[v]).to.deep.equal({ - site: { - ext: { - data: { - lite_occupation: ['gérant', 'bénévole'], - lite_hobbies: ['sport', 'cinéma'], - lito_bar: ['baz'], - }, - }, - } - }); - return - } - - expect(reqBidsConfigObj.ortb2Fragments.bidder[v]).to.deep.equal({ + const bidders = Object.values(adUnitsBids).map(v => v.bidder); + const expectedORTB2BidderFragments = bidders.reduce((frag, bidder) => { + frag[bidder] = { site: { ext: { - data: data, + data: data }, } - }); - }) + }; - expect(reqBidsConfigObj.adUnits[0].bids[2].params.keywords).to.deep.equal({ - lite_occupation: ['gérant', 'bénévole'], - lite_hobbies: ['sport', 'cinéma'], - lito_bar: ['baz'], + return frag + }, {}); + + expectedORTB2BidderFragments[APPNEXUS].site = { + ext: { + data: { + lite_occupation: ['gérant', 'bénévole'], + lite_hobbies: ['sport', 'cinéma'], + lito_bar: ['baz'], + }, + }, + }; + + expect(reqBidsConfigObj.ortb2Fragments).to.deep.equal({ + global: {}, + bidder: expectedORTB2BidderFragments, }); - expect(reqBidsConfigObj.adUnits[1].bids[2].params.keywords).to.deep.equal(data); expect(onDataResponse).to.deep.equal({ data: data,