diff --git a/src/auction.js b/src/auction.js index a77708486f2..a96bfadeb06 100644 --- a/src/auction.js +++ b/src/auction.js @@ -456,17 +456,17 @@ export function getStandardBidderSettings(mediaType) { if (!bidderSettings[CONSTANTS.JSON_MAPPING.BD_SETTING_STANDARD][CONSTANTS.JSON_MAPPING.ADSERVER_TARGETING]) { bidderSettings[CONSTANTS.JSON_MAPPING.BD_SETTING_STANDARD][CONSTANTS.JSON_MAPPING.ADSERVER_TARGETING] = [ { - key: 'hb_bidder', + key: CONSTANTS.TARGETING_KEYS.BIDDER, val: function (bidResponse) { return bidResponse.bidderCode; } }, { - key: 'hb_adid', + key: CONSTANTS.TARGETING_KEYS.AD_ID, val: function (bidResponse) { return bidResponse.adId; } }, { - key: 'hb_pb', + key: CONSTANTS.TARGETING_KEYS.PRICE_BUCKET, val: function (bidResponse) { if (granularity === CONSTANTS.GRANULARITY_OPTIONS.AUTO) { return bidResponse.pbAg; @@ -483,24 +483,24 @@ export function getStandardBidderSettings(mediaType) { } } }, { - key: 'hb_size', + key: CONSTANTS.TARGETING_KEYS.SIZE, val: function (bidResponse) { return bidResponse.size; } }, { - key: 'hb_deal', + key: CONSTANTS.TARGETING_KEYS.DEAL, val: function (bidResponse) { return bidResponse.dealId; } }, { - key: 'hb_source', + key: CONSTANTS.TARGETING_KEYS.SOURCE, val: function (bidResponse) { return bidResponse.source; } }, { - key: 'hb_format', + key: CONSTANTS.TARGETING_KEYS.FORMAT, val: function (bidResponse) { return bidResponse.mediaType; } @@ -561,7 +561,7 @@ function setKeys(keyValues, bidderSettings, custBidObj) { if ( ((typeof bidderSettings.suppressEmptyKeys !== 'undefined' && bidderSettings.suppressEmptyKeys === true) || - key === 'hb_deal') && // hb_deal is suppressed automatically if not set + key === CONSTANTS.TARGETING_KEYS.DEAL) && // hb_deal is suppressed automatically if not set ( utils.isEmptyStr(value) || value === null || diff --git a/src/constants.json b/src/constants.json index 3bbad70585a..9ec51e4047b 100644 --- a/src/constants.json +++ b/src/constants.json @@ -55,15 +55,24 @@ "DENSE": "dense", "CUSTOM": "custom" }, - "TARGETING_KEYS": [ - "hb_bidder", - "hb_adid", - "hb_pb", - "hb_size", - "hb_deal", - "hb_source", - "hb_format" - ], + "TARGETING_KEYS": { + "BIDDER": "hb_bidder", + "AD_ID": "hb_adid", + "PRICE_BUCKET": "hb_pb", + "SIZE": "hb_size", + "DEAL": "hb_deal", + "SOURCE": "hb_source", + "FORMAT": "hb_format" + }, + "NATIVE_KEYS": { + "title": "hb_native_title", + "body": "hb_native_body", + "sponsoredBy": "hb_native_brand", + "image": "hb_native_image", + "icon": "hb_native_icon", + "clickUrl": "hb_native_linkurl", + "cta": "hb_native_cta" + }, "S2S" : { "SRC" : "s2s", "DEFAULT_ENDPOINT" : "https://prebid.adnxs.com/pbs/v1/openrtb2/auction", diff --git a/src/native.js b/src/native.js index 3d2ec2fe688..b4d2d959b70 100644 --- a/src/native.js +++ b/src/native.js @@ -1,20 +1,12 @@ import { deepAccess, getBidRequest, logError, triggerPixel, insertHtmlIntoIframe } from './utils'; import includes from 'core-js/library/fn/array/includes'; -export const nativeAdapters = []; +const CONSTANTS = require('./constants.json'); -export const NATIVE_KEYS = { - title: 'hb_native_title', - body: 'hb_native_body', - sponsoredBy: 'hb_native_brand', - image: 'hb_native_image', - icon: 'hb_native_icon', - clickUrl: 'hb_native_linkurl', - cta: 'hb_native_cta', -}; +export const nativeAdapters = []; -export const NATIVE_TARGETING_KEYS = Object.keys(NATIVE_KEYS).map( - key => NATIVE_KEYS[key] +export const NATIVE_TARGETING_KEYS = Object.keys(CONSTANTS.NATIVE_KEYS).map( + key => CONSTANTS.NATIVE_KEYS[key] ); const IMAGE = { @@ -163,7 +155,7 @@ export function getNativeTargeting(bid) { let keyValues = {}; Object.keys(bid['native']).forEach(asset => { - const key = NATIVE_KEYS[asset]; + const key = CONSTANTS.NATIVE_KEYS[asset]; let value = bid['native'][asset]; // native image-type assets can be a string or an object with a url prop diff --git a/src/targeting.js b/src/targeting.js index 4bd3adbd9fc..8cb567001d5 100644 --- a/src/targeting.js +++ b/src/targeting.js @@ -15,6 +15,10 @@ export const RENDERED = 'rendered'; const MAX_DFP_KEYLENGTH = 20; const TTL_BUFFER = 1000; +export const TARGETING_KEYS = Object.keys(CONSTANTS.TARGETING_KEYS).map( + key => CONSTANTS.TARGETING_KEYS[key] +); + // return unexpired bids export const isBidNotExpired = (bid) => (bid.responseTimestamp + bid.ttl * 1000 + TTL_BUFFER) > timestamp(); @@ -262,7 +266,7 @@ export function newTargeting(auctionManager) { .reduce((acc, key) => { const targetingValue = [winner.adserverTargeting[key]]; const targeting = { [key.substring(0, MAX_DFP_KEYLENGTH)]: targetingValue }; - if (key === 'hb_deal') { + if (key === CONSTANTS.TARGETING_KEYS.DEAL) { const bidderCodeTargetingKey = `${key}_${winner.bidderCode}`.substring(0, MAX_DFP_KEYLENGTH); const bidderCodeTargeting = { [bidderCodeTargetingKey]: targetingValue }; return [...acc, targeting, bidderCodeTargeting]; @@ -278,7 +282,7 @@ export function newTargeting(auctionManager) { function getStandardKeys() { return auctionManager.getStandardBidderAdServerTargeting() // in case using a custom standard key set .map(targeting => targeting.key) - .concat(CONSTANTS.TARGETING_KEYS).filter(uniques); // standard keys defined in the library. + .concat(TARGETING_KEYS).filter(uniques); // standard keys defined in the library. } /** @@ -360,7 +364,7 @@ export function newTargeting(auctionManager) { * @return {targetingArray} all non-winning bids targeting */ function getBidLandscapeTargeting(adUnitCodes, bidsReceived) { - const standardKeys = CONSTANTS.TARGETING_KEYS.concat(NATIVE_TARGETING_KEYS); + const standardKeys = TARGETING_KEYS.concat(NATIVE_TARGETING_KEYS); const bids = getHighestCpmBidsFromBidPool(bidsReceived, getHighestCpm); diff --git a/test/fixtures/fixtures.js b/test/fixtures/fixtures.js index 75d998d4a09..816363f5eea 100644 --- a/test/fixtures/fixtures.js +++ b/test/fixtures/fixtures.js @@ -1,4 +1,33 @@ // jscs:disable +import CONSTANTS from 'src/constants.json'; +const utils = require('src/utils.js'); + +function convertTargetingsFromOldToNew(targetings) { + var mapOfOldToNew = { + 'hb_bidder': CONSTANTS.TARGETING_KEYS.BIDDER, + 'hb_adid': CONSTANTS.TARGETING_KEYS.AD_ID, + 'hb_pb': CONSTANTS.TARGETING_KEYS.PRICE_BUCKET, + 'hb_size': CONSTANTS.TARGETING_KEYS.SIZE, + 'hb_deal': CONSTANTS.TARGETING_KEYS.DEAL, + 'hb_source': CONSTANTS.TARGETING_KEYS.SOURCE, + 'hb_format': CONSTANTS.TARGETING_KEYS.FORMAT + }; + var newTargetings = {}; + utils._each(targetings, function(value, currentKey) { + var replaced = false; + utils._each(mapOfOldToNew, function(newKey, oldKey) { + if (currentKey.indexOf(oldKey) === 0 && oldKey !== newKey) { + var updatedKey = currentKey.replace(oldKey, newKey); + newTargetings[updatedKey] = targetings[currentKey]; + replaced = true; + } + }); + if (!replaced) { + newTargetings[currentKey] = targetings[currentKey]; + } + }) + return newTargetings; +} export function getBidRequests() { return [ @@ -311,13 +340,13 @@ export function getBidResponses() { 'pbAg': '0.10', 'size': '0x0', 'auctionId': 123456, - 'adserverTargeting': { + 'adserverTargeting': convertTargetingsFromOldToNew({ 'hb_bidder': 'triplelift', 'hb_adid': '222bb26f9e8bd', 'hb_pb': '10.00', 'hb_size': '0x0', 'foobar': '0x0' - }, + }), 'netRevenue': true, 'currency': 'USD', 'ttl': 300 @@ -343,13 +372,13 @@ export function getBidResponses() { 'size': '300x250', 'alwaysUseBid': true, 'auctionId': 123456, - 'adserverTargeting': { + 'adserverTargeting': convertTargetingsFromOldToNew({ 'hb_bidder': 'appnexus', 'hb_adid': '233bcbee889d46d', 'hb_pb': '10.00', 'hb_size': '300x250', 'foobar': '300x250' - }, + }), 'netRevenue': true, 'currency': 'USD', 'ttl': 300 @@ -375,13 +404,13 @@ export function getBidResponses() { 'size': '728x90', 'alwaysUseBid': true, 'auctionId': 123456, - 'adserverTargeting': { + 'adserverTargeting': convertTargetingsFromOldToNew({ 'hb_bidder': 'appnexus', 'hb_adid': '24bd938435ec3fc', 'hb_pb': '10.00', 'hb_size': '728x90', 'foobar': '728x90' - }, + }), 'netRevenue': true, 'currency': 'USD', 'ttl': 300 @@ -406,13 +435,13 @@ export function getBidResponses() { 'pbAg': '0.50', 'size': '300x250', 'auctionId': 123456, - 'adserverTargeting': { + 'adserverTargeting': convertTargetingsFromOldToNew({ 'hb_bidder': 'pagescience', 'hb_adid': '25bedd4813632d7', 'hb_pb': '10.00', 'hb_size': '300x250', 'foobar': '300x250' - }, + }), 'netRevenue': true, 'currency': 'USD', 'ttl': 300 @@ -436,13 +465,13 @@ export function getBidResponses() { 'pbAg': '0.15', 'size': '300x250', 'auctionId': 654321, - 'adserverTargeting': { + 'adserverTargeting': convertTargetingsFromOldToNew({ 'hb_bidder': 'brightcom', 'hb_adid': '26e0795ab963896', 'hb_pb': '10.00', 'hb_size': '300x250', 'foobar': '300x250' - }, + }), 'netRevenue': true, 'currency': 'USD', 'ttl': 300 @@ -467,13 +496,13 @@ export function getBidResponses() { 'pbAg': '0.50', 'size': '300x250', 'auctionId': 654321, - 'adserverTargeting': { + 'adserverTargeting': convertTargetingsFromOldToNew({ 'hb_bidder': 'brealtime', 'hb_adid': '275bd666f5a5a5d', 'hb_pb': '10.00', 'hb_size': '300x250', 'foobar': '300x250' - }, + }), 'netRevenue': true, 'currency': 'USD', 'ttl': 300 @@ -499,13 +528,13 @@ export function getBidResponses() { 'pbAg': '5.90', 'size': '300x250', 'auctionId': 654321, - 'adserverTargeting': { + 'adserverTargeting': convertTargetingsFromOldToNew({ 'hb_bidder': 'pubmatic', 'hb_adid': '28f4039c636b6a7', 'hb_pb': '10.00', 'hb_size': '300x250', 'foobar': '300x250' - }, + }), 'netRevenue': true, 'currency': 'USD', 'ttl': 300 @@ -529,13 +558,13 @@ export function getBidResponses() { 'pbAg': '2.70', 'size': '300x600', 'auctionId': 654321, - 'adserverTargeting': { + 'adserverTargeting': convertTargetingsFromOldToNew({ 'hb_bidder': 'rubicon', 'hb_adid': '29019e2ab586a5a', 'hb_pb': '10.00', 'hb_size': '300x600', 'foobar': '300x600' - }, + }), 'netRevenue': true, 'currency': 'USD', 'ttl': 300 @@ -546,26 +575,26 @@ export function getBidResponses() { export function getSlotTargeting() { return { '/19968336/header-bid-tag-0': [ - { + convertTargetingsFromOldToNew({ 'hb_bidder': [ 'appnexus' ] - }, - { + }), + convertTargetingsFromOldToNew({ 'hb_adid': [ '233bcbee889d46d' ] - }, - { + }), + convertTargetingsFromOldToNew({ 'hb_pb': [ '10.00' ] - }, - { + }), + convertTargetingsFromOldToNew({ 'hb_size': [ '300x250' ] - }, + }), { 'foobar': [ '300x250' @@ -1033,13 +1062,13 @@ export function getBidResponsesFromAPI() { 'pbAg': '0.15', 'size': '300x250', 'auctionId': 654321, - 'adserverTargeting': { + 'adserverTargeting': convertTargetingsFromOldToNew({ 'hb_bidder': 'brightcom', 'hb_adid': '26e0795ab963896', 'hb_pb': '10.00', 'hb_size': '300x250', 'foobar': '300x250' - }, + }), 'netRevenue': true, 'currency': 'USD', 'ttl': 300 @@ -1064,13 +1093,13 @@ export function getBidResponsesFromAPI() { 'pbAg': '0.50', 'size': '300x250', 'auctionId': 654321, - 'adserverTargeting': { + 'adserverTargeting': convertTargetingsFromOldToNew({ 'hb_bidder': 'brealtime', 'hb_adid': '275bd666f5a5a5d', 'hb_pb': '10.00', 'hb_size': '300x250', 'foobar': '300x250' - }, + }), 'netRevenue': true, 'currency': 'USD', 'ttl': 300 @@ -1096,13 +1125,13 @@ export function getBidResponsesFromAPI() { 'pbAg': '5.90', 'size': '300x250', 'auctionId': 654321, - 'adserverTargeting': { + 'adserverTargeting': convertTargetingsFromOldToNew({ 'hb_bidder': 'pubmatic', 'hb_adid': '28f4039c636b6a7', 'hb_pb': '10.00', 'hb_size': '300x250', 'foobar': '300x250' - }, + }), 'netRevenue': true, 'currency': 'USD', 'ttl': 300 @@ -1126,13 +1155,13 @@ export function getBidResponsesFromAPI() { 'pbAg': '2.70', 'size': '300x600', 'auctionId': 654321, - 'adserverTargeting': { + 'adserverTargeting': convertTargetingsFromOldToNew({ 'hb_bidder': 'rubicon', 'hb_adid': '29019e2ab586a5a', 'hb_pb': '10.00', 'hb_size': '300x600', 'foobar': '300x600' - }, + }), 'netRevenue': true, 'currency': 'USD', 'ttl': 300 @@ -1145,7 +1174,7 @@ export function getBidResponsesFromAPI() { // Ad server targeting when `setConfig({ enableSendAllBids: true })` is set. export function getAdServerTargeting() { return { - '/19968336/header-bid-tag-0': { + '/19968336/header-bid-tag-0': convertTargetingsFromOldToNew({ 'foobar': '0x0,300x250,300x600', 'hb_size': '300x250', 'hb_pb': '10.00', @@ -1179,8 +1208,8 @@ export function getAdServerTargeting() { 'hb_pb_rubicon': '10.00', 'hb_adid_rubicon': '29019e2ab586a5a', 'hb_bidder_rubicon': 'rubicon' - }, - '/19968336/header-bid-tag1': { + }), + '/19968336/header-bid-tag1': convertTargetingsFromOldToNew({ 'foobar': '728x90', 'hb_size': '728x90', 'hb_pb': '10.00', @@ -1190,7 +1219,7 @@ export function getAdServerTargeting() { 'hb_pb_appnexus': '10.00', 'hb_adid_appnexus': '24bd938435ec3fc', 'hb_bidder_appnexus': 'appnexus' - } + }) }; } @@ -1198,19 +1227,19 @@ export function getAdServerTargeting() { export function getTargetingKeys() { return [ [ - 'hb_bidder', + CONSTANTS.TARGETING_KEYS.BIDDER, 'appnexus' ], [ - 'hb_adid', + CONSTANTS.TARGETING_KEYS.AD_ID, '233bcbee889d46d' ], [ - 'hb_pb', + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET, '10.00' ], [ - 'hb_size', + CONSTANTS.TARGETING_KEYS.SIZE, '300x250' ], [ @@ -1225,19 +1254,19 @@ export function getTargetingKeys() { export function getTargetingKeysBidLandscape() { return [ [ - 'hb_bidder', + CONSTANTS.TARGETING_KEYS.BIDDER, 'appnexus' ], [ - 'hb_adid_appnexus', + CONSTANTS.TARGETING_KEYS.AD_ID + '_appnexus', '233bcbee889d46d' ], [ - 'hb_pb', + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET, '10.00' ], [ - 'hb_size', + CONSTANTS.TARGETING_KEYS.SIZE, '300x250' ], [ @@ -1245,111 +1274,111 @@ export function getTargetingKeysBidLandscape() { ['0x0', '300x250', '300x600'] ], [ - 'hb_bidder_triplelift', + CONSTANTS.TARGETING_KEYS.BIDDER + '_triplelift', 'triplelift' ], [ - 'hb_adid_triplelift', + CONSTANTS.TARGETING_KEYS.AD_ID + '_triplelift', '222bb26f9e8bd' ], [ - 'hb_pb_triplelift', + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_triplelift', '10.00' ], [ - 'hb_size_triplelift', + CONSTANTS.TARGETING_KEYS.SIZE + '_triplelift', '0x0' ], [ - 'hb_bidder_appnexus', + CONSTANTS.TARGETING_KEYS.BIDDER + '_appnexus', 'appnexus' ], [ - 'hb_pb_appnexus', + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_appnexus', '10.00' ], [ - 'hb_size_appnexus', + CONSTANTS.TARGETING_KEYS.SIZE + '_appnexus', '300x250' ], [ - 'hb_bidder_pagescienc', + CONSTANTS.TARGETING_KEYS.BIDDER + '_pagescienc', 'pagescience' ], [ - 'hb_adid_pagescience', + CONSTANTS.TARGETING_KEYS.AD_ID + '_pagescience', '25bedd4813632d7' ], [ - 'hb_pb_pagescience', + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_pagescience', '10.00' ], [ - 'hb_size_pagescience', + CONSTANTS.TARGETING_KEYS.SIZE + '_pagescience', '300x250' ], [ - 'hb_bidder_brightcom', + CONSTANTS.TARGETING_KEYS.BIDDER + '_brightcom', 'brightcom' ], [ - 'hb_adid_brightcom', + CONSTANTS.TARGETING_KEYS.AD_ID + '_brightcom', '26e0795ab963896' ], [ - 'hb_pb_brightcom', + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_brightcom', '10.00' ], [ - 'hb_size_brightcom', + CONSTANTS.TARGETING_KEYS.SIZE + '_brightcom', '300x250' ], [ - 'hb_bidder_brealtime', + CONSTANTS.TARGETING_KEYS.BIDDER + '_brealtime', 'brealtime' ], [ - 'hb_adid_brealtime', + CONSTANTS.TARGETING_KEYS.AD_ID + '_brealtime', '275bd666f5a5a5d' ], [ - 'hb_pb_brealtime', + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_brealtime', '10.00' ], [ - 'hb_size_brealtime', + CONSTANTS.TARGETING_KEYS.SIZE + '_brealtime', '300x250' ], [ - 'hb_bidder_pubmatic', + CONSTANTS.TARGETING_KEYS.BIDDER + '_pubmatic', 'pubmatic' ], [ - 'hb_adid_pubmatic', + CONSTANTS.TARGETING_KEYS.AD_ID + '_pubmatic', '28f4039c636b6a7' ], [ - 'hb_pb_pubmatic', + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_pubmatic', '10.00' ], [ - 'hb_size_pubmatic', + CONSTANTS.TARGETING_KEYS.SIZE + '_pubmatic', '300x250' ], [ - 'hb_bidder_rubicon', + CONSTANTS.TARGETING_KEYS.BIDDER + '_rubicon', 'rubicon' ], [ - 'hb_adid_rubicon', + CONSTANTS.TARGETING_KEYS.AD_ID + '_rubicon', '29019e2ab586a5a' ], [ - 'hb_pb_rubicon', + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_rubicon', '10.00' ], [ - 'hb_size_rubicon', + CONSTANTS.TARGETING_KEYS.SIZE + '_rubicon', '300x600' ] ]; @@ -1426,12 +1455,12 @@ export function createBidReceived({bidder, cpm, auctionId, responseTimestamp, ad 'adUnitCode': adUnitCode, 'bidder': bidder, 'size': '300x250', - 'adserverTargeting': { + 'adserverTargeting': convertTargetingsFromOldToNew({ 'hb_bidder': bidder, 'hb_adid': adId, 'hb_pb': cpm, 'foobar': '300x250' - }, + }), 'netRevenue': true, 'currency': 'USD', 'ttl': (!ttl) ? 300 : ttl diff --git a/test/spec/auctionmanager_spec.js b/test/spec/auctionmanager_spec.js index fa21050e78e..f4c6fc22cb7 100644 --- a/test/spec/auctionmanager_spec.js +++ b/test/spec/auctionmanager_spec.js @@ -138,14 +138,13 @@ describe('auctionmanager.js', function () { /* return the expected response for a given bid, filter by keys if given */ function getDefaultExpected(bid, keys) { - var expected = { - 'hb_bidder': bid.bidderCode, - 'hb_adid': bid.adId, - 'hb_pb': bid.pbMg, - 'hb_size': bid.getSize(), - 'hb_source': bid.source, - 'hb_format': bid.mediaType, - }; + var expected = {}; + expected[ CONSTANTS.TARGETING_KEYS.BIDDER ] = bid.bidderCode; + expected[ CONSTANTS.TARGETING_KEYS.AD_ID ] = bid.adId; + expected[ CONSTANTS.TARGETING_KEYS.PRICE_BUCKET ] = bid.pbMg; + expected[ CONSTANTS.TARGETING_KEYS.SIZE ] = bid.getSize(); + expected[ CONSTANTS.TARGETING_KEYS.SOURCE ] = bid.source; + expected[ CONSTANTS.TARGETING_KEYS.FORMAT ] = bid.mediaType; if (!keys) { return expected; @@ -175,35 +174,35 @@ describe('auctionmanager.js', function () { standard: { adserverTargeting: [ { - key: 'hb_bidder', + key: CONSTANTS.TARGETING_KEYS.BIDDER, val: function (bidResponse) { return bidResponse.bidderCode; } }, { - key: 'hb_adid', + key: CONSTANTS.TARGETING_KEYS.AD_ID, val: function (bidResponse) { return bidResponse.adId; } }, { - key: 'hb_pb', + key: CONSTANTS.TARGETING_KEYS.PRICE_BUCKET, val: function (bidResponse) { // change default here return bidResponse.pbHg; } }, { - key: 'hb_size', + key: CONSTANTS.TARGETING_KEYS.SIZE, val: function (bidResponse) { return bidResponse.size; } }, { - key: 'hb_source', + key: CONSTANTS.TARGETING_KEYS.SOURCE, val: function (bidResponse) { return bidResponse.source; } }, { - key: 'hb_format', + key: CONSTANTS.TARGETING_KEYS.FORMAT, val: function (bidResponse) { return bidResponse.mediaType; } @@ -214,7 +213,7 @@ describe('auctionmanager.js', function () { }; var expected = getDefaultExpected(bid); - expected.hb_pb = bid.pbHg; + expected[CONSTANTS.TARGETING_KEYS.PRICE_BUCKET] = bid.pbHg; var response = getKeyValueTargetingPairs(bid.bidderCode, bid); assert.deepEqual(response, expected); @@ -226,23 +225,23 @@ describe('auctionmanager.js', function () { appnexus: { adserverTargeting: [ { - key: 'hb_bidder', + key: CONSTANTS.TARGETING_KEYS.BIDDER, val: function (bidResponse) { return bidResponse.bidderCode; } }, { - key: 'hb_adid', + key: CONSTANTS.TARGETING_KEYS.AD_ID, val: function (bidResponse) { return bidResponse.adId; } }, { - key: 'hb_pb', + key: CONSTANTS.TARGETING_KEYS.PRICE_BUCKET, val: function (bidResponse) { // change default here return bidResponse.pbHg; } }, { - key: 'hb_size', + key: CONSTANTS.TARGETING_KEYS.SIZE, val: function (bidResponse) { return bidResponse.size; } @@ -253,7 +252,7 @@ describe('auctionmanager.js', function () { }; var expected = getDefaultExpected(bid); - expected.hb_pb = bid.pbHg; + expected[CONSTANTS.TARGETING_KEYS.PRICE_BUCKET] = bid.pbHg; var response = getKeyValueTargetingPairs(bid.bidderCode, bid); assert.deepEqual(response, expected); @@ -265,23 +264,23 @@ describe('auctionmanager.js', function () { nonExistentBidder: { adserverTargeting: [ { - key: 'hb_bidder', + key: CONSTANTS.TARGETING_KEYS.BIDDER, val: function (bidResponse) { return bidResponse.bidderCode; } }, { - key: 'hb_adid', + key: CONSTANTS.TARGETING_KEYS.AD_ID, val: function (bidResponse) { return bidResponse.adId; } }, { - key: 'hb_pb', + key: CONSTANTS.TARGETING_KEYS.PRICE_BUCKET, val: function (bidResponse) { // change default here return bidResponse.pbHg; } }, { - key: 'hb_size', + key: CONSTANTS.TARGETING_KEYS.SIZE, val: function (bidResponse) { return bidResponse.size; } @@ -310,17 +309,17 @@ describe('auctionmanager.js', function () { }, adserverTargeting: [ { - key: 'hb_bidder', + key: CONSTANTS.TARGETING_KEYS.BIDDER, val: function (bidResponse) { return bidResponse.bidderCode; } }, { - key: 'hb_adid', + key: CONSTANTS.TARGETING_KEYS.AD_ID, val: function (bidResponse) { return bidResponse.adId; } }, { - key: 'hb_pb', + key: CONSTANTS.TARGETING_KEYS.PRICE_BUCKET, val: function (bidResponse) { // change default here return 10.00; @@ -330,8 +329,8 @@ describe('auctionmanager.js', function () { } }; - var expected = getDefaultExpected(bid, ['hb_bidder', 'hb_adid']); - expected.hb_pb = 10.0; + var expected = getDefaultExpected(bid, [CONSTANTS.TARGETING_KEYS.BIDDER, CONSTANTS.TARGETING_KEYS.AD_ID]); + expected[CONSTANTS.TARGETING_KEYS.PRICE_BUCKET] = 10.0; var response = getKeyValueTargetingPairs(bid.bidderCode, bid); assert.deepEqual(response, expected); @@ -367,17 +366,17 @@ describe('auctionmanager.js', function () { }, adserverTargeting: [ { - key: 'hb_bidder', + key: CONSTANTS.TARGETING_KEYS.BIDDER, val: function (bidResponse) { return bidResponse.bidderCode; } }, { - key: 'hb_adid', + key: CONSTANTS.TARGETING_KEYS.AD_ID, val: function (bidResponse) { return bidResponse.adId; } }, { - key: 'hb_pb', + key: CONSTANTS.TARGETING_KEYS.PRICE_BUCKET, val: function (bidResponse) { // change default here return 15.00; @@ -388,24 +387,24 @@ describe('auctionmanager.js', function () { standard: { adserverTargeting: [ { - key: 'hb_bidder', + key: CONSTANTS.TARGETING_KEYS.BIDDER, val: function (bidResponse) { return bidResponse.bidderCode; } }, { - key: 'hb_adid', + key: CONSTANTS.TARGETING_KEYS.AD_ID, val: function (bidResponse) { return bidResponse.adId; } }, { - key: 'hb_pb', + key: CONSTANTS.TARGETING_KEYS.PRICE_BUCKET, val: function (bidResponse) { // change default here return 10.00; }, }, { - key: 'hb_size', + key: CONSTANTS.TARGETING_KEYS.SIZE, val: function (bidResponse) { return bidResponse.size; } @@ -414,8 +413,8 @@ describe('auctionmanager.js', function () { } }; - var expected = getDefaultExpected(bid, ['hb_bidder', 'hb_adid', 'hb_size']); - expected.hb_pb = 15.0; + var expected = getDefaultExpected(bid, [CONSTANTS.TARGETING_KEYS.BIDDER, CONSTANTS.TARGETING_KEYS.AD_ID, CONSTANTS.TARGETING_KEYS.SIZE]); + expected[CONSTANTS.TARGETING_KEYS.PRICE_BUCKET] = 15.0; var response = getKeyValueTargetingPairs(bid.bidderCode, bid); assert.deepEqual(response, expected); @@ -428,17 +427,17 @@ describe('auctionmanager.js', function () { sendStandardTargeting: false, adserverTargeting: [ { - key: 'hb_bidder', + key: CONSTANTS.TARGETING_KEYS.BIDDER, val: function (bidResponse) { return bidResponse.bidderCode; } }, { - key: 'hb_adid', + key: CONSTANTS.TARGETING_KEYS.AD_ID, val: function (bidResponse) { return bidResponse.adId; } }, { - key: 'hb_pb', + key: CONSTANTS.TARGETING_KEYS.PRICE_BUCKET, val: function (bidResponse) { return bidResponse.pbHg; } @@ -447,7 +446,7 @@ describe('auctionmanager.js', function () { } }; var expected = getDefaultExpected(bid); - expected.hb_pb = 5.57; + expected[CONSTANTS.TARGETING_KEYS.PRICE_BUCKET] = 5.57; var response = getKeyValueTargetingPairs(bid.bidderCode, bid); assert.deepEqual(response, expected); @@ -608,7 +607,7 @@ describe('auctionmanager.js', function () { auction.callBids(); let registeredBid = auction.getBidsReceived().pop(); - assert.equal(registeredBid.adserverTargeting[`hb_deal`], 'test deal', 'dealId placed in adserverTargeting'); + assert.equal(registeredBid.adserverTargeting[CONSTANTS.TARGETING_KEYS.DEAL], 'test deal', 'dealId placed in adserverTargeting'); }); it('should pass through default adserverTargeting sent from adapter', function () { @@ -617,7 +616,7 @@ describe('auctionmanager.js', function () { auction.callBids(); let registeredBid = auction.getBidsReceived().pop(); - assert.equal(registeredBid.adserverTargeting.hb_bidder, BIDDER_CODE); + assert.equal(registeredBid.adserverTargeting[CONSTANTS.TARGETING_KEYS.BIDDER], BIDDER_CODE); assert.equal(registeredBid.adserverTargeting.extra, 'stuff'); }); diff --git a/test/spec/native_spec.js b/test/spec/native_spec.js index dc70592877e..91b96cac281 100644 --- a/test/spec/native_spec.js +++ b/test/spec/native_spec.js @@ -1,5 +1,6 @@ import { expect } from 'chai'; import { fireNativeTrackers, getNativeTargeting, nativeBidIsValid } from 'src/native'; +import CONSTANTS from 'src/constants.json'; const utils = require('src/utils'); const bid = { @@ -31,9 +32,9 @@ describe('native.js', function () { it('gets native targeting keys', function () { const targeting = getNativeTargeting(bid); - expect(targeting.hb_native_title).to.equal(bid.native.title); - expect(targeting.hb_native_body).to.equal(bid.native.body); - expect(targeting.hb_native_linkurl).to.equal(bid.native.clickUrl); + expect(targeting[CONSTANTS.NATIVE_KEYS.title]).to.equal(bid.native.title); + expect(targeting[CONSTANTS.NATIVE_KEYS.body]).to.equal(bid.native.body); + expect(targeting[CONSTANTS.NATIVE_KEYS.clickUrl]).to.equal(bid.native.clickUrl); }); it('fires impression trackers', function () { diff --git a/test/spec/unit/core/targeting_spec.js b/test/spec/unit/core/targeting_spec.js index a72992e099d..9910645be09 100644 --- a/test/spec/unit/core/targeting_spec.js +++ b/test/spec/unit/core/targeting_spec.js @@ -27,11 +27,11 @@ const bid1 = { 'bidder': 'rubicon', 'size': '300x250', 'adserverTargeting': { - 'hb_bidder': 'rubicon', - 'hb_adid': '148018fe5e', - 'hb_pb': '0.53', - 'hb_deal': '1234', - 'foobar': '300x250' + 'foobar': '300x250', + [CONSTANTS.TARGETING_KEYS.BIDDER]: 'rubicon', + [CONSTANTS.TARGETING_KEYS.AD_ID]: '148018fe5e', + [CONSTANTS.TARGETING_KEYS.PRICE_BUCKET]: '0.53', + [CONSTANTS.TARGETING_KEYS.DEAL]: '1234' }, 'netRevenue': true, 'currency': 'USD', @@ -58,10 +58,10 @@ const bid2 = { 'bidder': 'rubicon', 'size': '300x250', 'adserverTargeting': { - 'hb_bidder': 'rubicon', - 'hb_adid': '5454545', - 'hb_pb': '0.25', - 'foobar': '300x250' + 'foobar': '300x250', + [CONSTANTS.TARGETING_KEYS.BIDDER]: 'rubicon', + [CONSTANTS.TARGETING_KEYS.AD_ID]: '5454545', + [CONSTANTS.TARGETING_KEYS.PRICE_BUCKET]: '0.25' }, 'netRevenue': true, 'currency': 'USD', @@ -88,10 +88,10 @@ const bid3 = { 'bidder': 'rubicon', 'size': '300x600', 'adserverTargeting': { - 'hb_bidder': 'rubicon', - 'hb_adid': '48747745', - 'hb_pb': '0.75', - 'foobar': '300x600' + 'foobar': '300x600', + [CONSTANTS.TARGETING_KEYS.BIDDER]: 'rubicon', + [CONSTANTS.TARGETING_KEYS.AD_ID]: '48747745', + [CONSTANTS.TARGETING_KEYS.PRICE_BUCKET]: '0.75' }, 'netRevenue': true, 'currency': 'USD', @@ -140,12 +140,12 @@ describe('targeting tests', function () { // we should only get the targeting data for the one requested adunit expect(Object.keys(targeting).length).to.equal(1); - let sendAllBidCpm = Object.keys(targeting['/123456/header-bid-tag-0']).filter(key => key.indexOf('hb_pb_') != -1); + let sendAllBidCpm = Object.keys(targeting['/123456/header-bid-tag-0']).filter(key => key.indexOf(CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_') != -1) // we shouldn't get more than 1 key for hb_pb_${bidder} expect(sendAllBidCpm.length).to.equal(1); // expect the winning CPM to be equal to the sendAllBidCPM - expect(targeting['/123456/header-bid-tag-0']['hb_pb_rubicon']).to.deep.equal(targeting['/123456/header-bid-tag-0']['hb_pb']); + expect(targeting['/123456/header-bid-tag-0'][CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_rubicon']).to.deep.equal(targeting['/123456/header-bid-tag-0'][CONSTANTS.TARGETING_KEYS.PRICE_BUCKET]); }); }); // end getAllTargeting tests diff --git a/test/spec/unit/pbjs_api_spec.js b/test/spec/unit/pbjs_api_spec.js index 41e40100011..96f02e7f8f2 100644 --- a/test/spec/unit/pbjs_api_spec.js +++ b/test/spec/unit/pbjs_api_spec.js @@ -166,7 +166,7 @@ describe('Unit: Prebid Module', function () { it('should return targeting info as a string', function () { const adUnitCode = config.adUnitCodes[0]; $$PREBID_GLOBAL$$.setConfig({ enableSendAllBids: true }); - var expected = 'foobar=0x0%2C300x250%2C300x600&hb_size=300x250&hb_pb=10.00&hb_adid=233bcbee889d46d&hb_bidder=appnexus&hb_size_triplelift=0x0&hb_pb_triplelift=10.00&hb_adid_triplelift=222bb26f9e8bd&hb_bidder_triplelift=triplelift&hb_size_appnexus=300x250&hb_pb_appnexus=10.00&hb_adid_appnexus=233bcbee889d46d&hb_bidder_appnexus=appnexus&hb_size_pagescience=300x250&hb_pb_pagescience=10.00&hb_adid_pagescience=25bedd4813632d7&hb_bidder_pagescienc=pagescience&hb_size_brightcom=300x250&hb_pb_brightcom=10.00&hb_adid_brightcom=26e0795ab963896&hb_bidder_brightcom=brightcom&hb_size_brealtime=300x250&hb_pb_brealtime=10.00&hb_adid_brealtime=275bd666f5a5a5d&hb_bidder_brealtime=brealtime&hb_size_pubmatic=300x250&hb_pb_pubmatic=10.00&hb_adid_pubmatic=28f4039c636b6a7&hb_bidder_pubmatic=pubmatic&hb_size_rubicon=300x600&hb_pb_rubicon=10.00&hb_adid_rubicon=29019e2ab586a5a&hb_bidder_rubicon=rubicon'; + var expected = 'foobar=0x0%2C300x250%2C300x600&' + CONSTANTS.TARGETING_KEYS.SIZE + '=300x250&' + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '=10.00&' + CONSTANTS.TARGETING_KEYS.AD_ID + '=233bcbee889d46d&' + CONSTANTS.TARGETING_KEYS.BIDDER + '=appnexus&' + CONSTANTS.TARGETING_KEYS.SIZE + '_triplelift=0x0&' + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_triplelift=10.00&' + CONSTANTS.TARGETING_KEYS.AD_ID + '_triplelift=222bb26f9e8bd&' + CONSTANTS.TARGETING_KEYS.BIDDER + '_triplelift=triplelift&' + CONSTANTS.TARGETING_KEYS.SIZE + '_appnexus=300x250&' + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_appnexus=10.00&' + CONSTANTS.TARGETING_KEYS.AD_ID + '_appnexus=233bcbee889d46d&' + CONSTANTS.TARGETING_KEYS.BIDDER + '_appnexus=appnexus&' + CONSTANTS.TARGETING_KEYS.SIZE + '_pagescience=300x250&' + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_pagescience=10.00&' + CONSTANTS.TARGETING_KEYS.AD_ID + '_pagescience=25bedd4813632d7&' + CONSTANTS.TARGETING_KEYS.BIDDER + '_pagescienc=pagescience&' + CONSTANTS.TARGETING_KEYS.SIZE + '_brightcom=300x250&' + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_brightcom=10.00&' + CONSTANTS.TARGETING_KEYS.AD_ID + '_brightcom=26e0795ab963896&' + CONSTANTS.TARGETING_KEYS.BIDDER + '_brightcom=brightcom&' + CONSTANTS.TARGETING_KEYS.SIZE + '_brealtime=300x250&' + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_brealtime=10.00&' + CONSTANTS.TARGETING_KEYS.AD_ID + '_brealtime=275bd666f5a5a5d&' + CONSTANTS.TARGETING_KEYS.BIDDER + '_brealtime=brealtime&' + CONSTANTS.TARGETING_KEYS.SIZE + '_pubmatic=300x250&' + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_pubmatic=10.00&' + CONSTANTS.TARGETING_KEYS.AD_ID + '_pubmatic=28f4039c636b6a7&' + CONSTANTS.TARGETING_KEYS.BIDDER + '_pubmatic=pubmatic&' + CONSTANTS.TARGETING_KEYS.SIZE + '_rubicon=300x600&' + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_rubicon=10.00&' + CONSTANTS.TARGETING_KEYS.AD_ID + '_rubicon=29019e2ab586a5a&' + CONSTANTS.TARGETING_KEYS.BIDDER + '_rubicon=rubicon'; var result = $$PREBID_GLOBAL$$.getAdserverTargetingForAdUnitCodeStr(adUnitCode); assert.equal(expected, result, 'returns expected string of ad targeting info'); }); @@ -212,17 +212,17 @@ describe('Unit: Prebid Module', function () { var expected = { '/19968336/header-bid-tag-0': { foobar: '0x0,300x250,300x600', - hb_size: '300x250', - hb_pb: '10.00', - hb_adid: '233bcbee889d46d', - hb_bidder: 'appnexus' + [CONSTANTS.TARGETING_KEYS.SIZE]: '300x250', + [CONSTANTS.TARGETING_KEYS.PRICE_BUCKET]: '10.00', + [CONSTANTS.TARGETING_KEYS.AD_ID]: '233bcbee889d46d', + [CONSTANTS.TARGETING_KEYS.BIDDER]: 'appnexus' }, '/19968336/header-bid-tag1': { foobar: '728x90', - hb_size: '728x90', - hb_pb: '10.00', - hb_adid: '24bd938435ec3fc', - hb_bidder: 'appnexus' + [CONSTANTS.TARGETING_KEYS.SIZE]: '728x90', + [CONSTANTS.TARGETING_KEYS.PRICE_BUCKET]: '10.00', + [CONSTANTS.TARGETING_KEYS.AD_ID]: '24bd938435ec3fc', + [CONSTANTS.TARGETING_KEYS.BIDDER]: 'appnexus' } }; assert.deepEqual(targeting, expected); @@ -259,18 +259,18 @@ describe('Unit: Prebid Module', function () { var expected = { '/19968336/header-bid-tag-0': { foobar: '300x250,300x600', - hb_size: '300x250', - hb_pb: '10.00', - hb_adid: '233bcbee889d46d', - hb_bidder: 'appnexus', - always_use_me: 'abc' + always_use_me: 'abc', + [CONSTANTS.TARGETING_KEYS.SIZE]: '300x250', + [CONSTANTS.TARGETING_KEYS.PRICE_BUCKET]: '10.00', + [CONSTANTS.TARGETING_KEYS.AD_ID]: '233bcbee889d46d', + [CONSTANTS.TARGETING_KEYS.BIDDER]: 'appnexus' }, '/19968336/header-bid-tag1': { foobar: '728x90', - hb_size: '728x90', - hb_pb: '10.00', - hb_adid: '24bd938435ec3fc', - hb_bidder: 'appnexus' + [CONSTANTS.TARGETING_KEYS.SIZE]: '728x90', + [CONSTANTS.TARGETING_KEYS.PRICE_BUCKET]: '10.00', + [CONSTANTS.TARGETING_KEYS.AD_ID]: '24bd938435ec3fc', + [CONSTANTS.TARGETING_KEYS.BIDDER]: 'appnexus' } }; assert.deepEqual(targeting, expected); @@ -289,7 +289,7 @@ describe('Unit: Prebid Module', function () { $$PREBID_GLOBAL$$.bidderSettings = { 'standard': { adserverTargeting: [{ - key: 'hb_bidder', + key: CONSTANTS.TARGETING_KEYS.BIDDER, val: function(bidResponse) { return bidResponse.bidderCode; } @@ -299,7 +299,7 @@ describe('Unit: Prebid Module', function () { return bidResponse.adId; } }, { - key: 'hb_pb', + key: CONSTANTS.TARGETING_KEYS.PRICE_BUCKET, val: function(bidResponse) { return bidResponse.pbMg; } @@ -317,22 +317,21 @@ describe('Unit: Prebid Module', function () { var expected = { '/19968336/header-bid-tag-0': { foobar: '300x250', - hb_size: '300x250', - hb_pb: '10.00', - hb_adid: '233bcbee889d46d', - hb_bidder: 'appnexus', - custom_ad_id: '233bcbee889d46d' + custom_ad_id: '233bcbee889d46d', + [CONSTANTS.TARGETING_KEYS.SIZE]: '300x250', + [CONSTANTS.TARGETING_KEYS.PRICE_BUCKET]: '10.00', + [CONSTANTS.TARGETING_KEYS.AD_ID]: '233bcbee889d46d', + [CONSTANTS.TARGETING_KEYS.BIDDER]: 'appnexus' }, '/19968336/header-bid-tag1': { foobar: '728x90', - hb_size: '728x90', - hb_pb: '10.00', - hb_adid: '24bd938435ec3fc', - hb_bidder: 'appnexus', + [CONSTANTS.TARGETING_KEYS.SIZE]: '728x90', + [CONSTANTS.TARGETING_KEYS.PRICE_BUCKET]: '10.00', + [CONSTANTS.TARGETING_KEYS.AD_ID]: '24bd938435ec3fc', + [CONSTANTS.TARGETING_KEYS.BIDDER]: 'appnexus', custom_ad_id: '24bd938435ec3fc' } }; - assert.deepEqual(targeting, expected); $$PREBID_GLOBAL$$.bidderSettings = {}; }); @@ -480,32 +479,32 @@ describe('Unit: Prebid Module', function () { ajaxStub.restore(); }); - it('should get correct hb_pb when using bid.cpm is between 0 to 5', function () { + it('should get correct ' + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + ' when using bid.cpm is between 0 to 5', function() { RESPONSE.tags[0].ads[0].cpm = 2.1234; auction.callBids(cbTimeout); let bidTargeting = targeting.getAllTargeting(); - expect(bidTargeting['div-gpt-ad-1460505748561-0']['hb_pb']).to.equal('2.12'); + expect(bidTargeting['div-gpt-ad-1460505748561-0'][CONSTANTS.TARGETING_KEYS.PRICE_BUCKET]).to.equal('2.12'); }); - it('should get correct hb_pb when using bid.cpm is between 5 to 8', function () { + it('should get correct ' + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + ' when using bid.cpm is between 5 to 8', function() { RESPONSE.tags[0].ads[0].cpm = 6.78; auction.callBids(cbTimeout); let bidTargeting = targeting.getAllTargeting(); - expect(bidTargeting['div-gpt-ad-1460505748561-0']['hb_pb']).to.equal('6.75'); + expect(bidTargeting['div-gpt-ad-1460505748561-0'][CONSTANTS.TARGETING_KEYS.PRICE_BUCKET]).to.equal('6.75'); }); - it('should get correct hb_pb when using bid.cpm is between 8 to 20', function () { + it('should get correct ' + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + ' when using bid.cpm is between 8 to 20', function() { RESPONSE.tags[0].ads[0].cpm = 19.5234; auction.callBids(cbTimeout); let bidTargeting = targeting.getAllTargeting(); - expect(bidTargeting['div-gpt-ad-1460505748561-0']['hb_pb']).to.equal('19.50'); + expect(bidTargeting['div-gpt-ad-1460505748561-0'][CONSTANTS.TARGETING_KEYS.PRICE_BUCKET]).to.equal('19.50'); }); - it('should get correct hb_pb when using bid.cpm is between 20 to 25', function () { + it('should get correct ' + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + ' when using bid.cpm is between 20 to 25', function() { RESPONSE.tags[0].ads[0].cpm = 21.5234; auction.callBids(cbTimeout); let bidTargeting = targeting.getAllTargeting(); - expect(bidTargeting['div-gpt-ad-1460505748561-0']['hb_pb']).to.equal('21.00'); + expect(bidTargeting['div-gpt-ad-1460505748561-0'][CONSTANTS.TARGETING_KEYS.PRICE_BUCKET]).to.equal('21.00'); }); }); @@ -720,7 +719,7 @@ describe('Unit: Prebid Module', function () { ajaxStub.restore(); }); - it('should get correct hb_pb with cpm between 0 - 5', function () { + it('should get correct ' + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + ' with cpm between 0 - 5', function() { initTestConfig({ adUnits: [createAdUnit('div-gpt-ad-1460505748561-0')], adUnitCodes: ['div-gpt-ad-1460505748561-0'] @@ -731,10 +730,10 @@ describe('Unit: Prebid Module', function () { auction.callBids(cbTimeout); let bidTargeting = targeting.getAllTargeting(); - expect(bidTargeting['div-gpt-ad-1460505748561-0']['hb_pb']).to.equal('3.25'); + expect(bidTargeting['div-gpt-ad-1460505748561-0'][CONSTANTS.TARGETING_KEYS.PRICE_BUCKET]).to.equal('3.25'); }); - it('should get correct hb_pb with cpm between 21 - 100', function () { + it('should get correct ' + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + ' with cpm between 21 - 100', function() { initTestConfig({ adUnits: [createAdUnit('div-gpt-ad-1460505748561-0')], adUnitCodes: ['div-gpt-ad-1460505748561-0'] @@ -745,7 +744,7 @@ describe('Unit: Prebid Module', function () { auction.callBids(cbTimeout); let bidTargeting = targeting.getAllTargeting(); - expect(bidTargeting['div-gpt-ad-1460505748561-0']['hb_pb']).to.equal('43.00'); + expect(bidTargeting['div-gpt-ad-1460505748561-0'][CONSTANTS.TARGETING_KEYS.PRICE_BUCKET]).to.equal('43.00'); }); it('should only apply price granularity if bid media type matches', function () { @@ -759,7 +758,7 @@ describe('Unit: Prebid Module', function () { auction.callBids(cbTimeout); let bidTargeting = targeting.getAllTargeting(); - expect(bidTargeting['div-gpt-ad-1460505748561-0']['hb_pb']).to.equal('3.00'); + expect(bidTargeting['div-gpt-ad-1460505748561-0'][CONSTANTS.TARGETING_KEYS.PRICE_BUCKET]).to.equal('3.00'); }); }); @@ -821,7 +820,7 @@ describe('Unit: Prebid Module', function () { $$PREBID_GLOBAL$$.setConfig({ enableSendAllBids: true }); $$PREBID_GLOBAL$$.setTargetingForGPTAsync('/19968336/header-bid-tag-0'); - expect(slots[0].spySetTargeting.args).to.deep.contain.members([['hb_bidder', 'appnexus'], ['hb_adid_appnexus', '233bcbee889d46d'], ['hb_pb_appnexus', '10.00']]); + expect(slots[0].spySetTargeting.args).to.deep.contain.members([[CONSTANTS.TARGETING_KEYS.BIDDER, 'appnexus'], [CONSTANTS.TARGETING_KEYS.AD_ID + '_appnexus', '233bcbee889d46d'], [CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_appnexus', '10.00']]); }); it('should set targeting when passed an array of ad unit codes with enableSendAllBids', function () { @@ -830,7 +829,7 @@ describe('Unit: Prebid Module', function () { $$PREBID_GLOBAL$$.setConfig({ enableSendAllBids: true }); $$PREBID_GLOBAL$$.setTargetingForGPTAsync(['/19968336/header-bid-tag-0']); - expect(slots[0].spySetTargeting.args).to.deep.contain.members([['hb_bidder', 'appnexus'], ['hb_adid_appnexus', '233bcbee889d46d'], ['hb_pb_appnexus', '10.00']]); + expect(slots[0].spySetTargeting.args).to.deep.contain.members([[CONSTANTS.TARGETING_KEYS.BIDDER, 'appnexus'], [CONSTANTS.TARGETING_KEYS.AD_ID + '_appnexus', '233bcbee889d46d'], [CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_appnexus', '10.00']]); }); it('should set targeting from googletag data', function () { @@ -877,19 +876,19 @@ describe('Unit: Prebid Module', function () { var expected = [ [ - 'hb_bidder', + CONSTANTS.TARGETING_KEYS.BIDDER, 'appnexus' ], [ - 'hb_adid', + CONSTANTS.TARGETING_KEYS.AD_ID, '233bcbee889d46d' ], [ - 'hb_pb', + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET, '10.00' ], [ - 'hb_size', + CONSTANTS.TARGETING_KEYS.SIZE, '300x250' ], [ @@ -1527,16 +1526,16 @@ describe('Unit: Prebid Module', function () { let expected = { '/19968336/header-bid-tag-0': { 'foobar': '0x0,300x250,300x600', - 'hb_size': '300x250', - 'hb_pb': '10.00', - 'hb_adid': '233bcbee889d46d', - 'hb_bidder': 'appnexus' + [CONSTANTS.TARGETING_KEYS.SIZE]: '300x250', + [CONSTANTS.TARGETING_KEYS.PRICE_BUCKET]: '10.00', + [CONSTANTS.TARGETING_KEYS.AD_ID]: '233bcbee889d46d', + [CONSTANTS.TARGETING_KEYS.BIDDER]: 'appnexus' }, '/19968336/header-bid-tag1': { - 'hb_bidder': 'appnexus', - 'hb_adid': '24bd938435ec3fc', - 'hb_pb': '10.00', - 'hb_size': '728x90', + [CONSTANTS.TARGETING_KEYS.BIDDER]: 'appnexus', + [CONSTANTS.TARGETING_KEYS.AD_ID]: '24bd938435ec3fc', + [CONSTANTS.TARGETING_KEYS.PRICE_BUCKET]: '10.00', + [CONSTANTS.TARGETING_KEYS.SIZE]: '728x90', 'foobar': '728x90' } } @@ -1793,12 +1792,12 @@ describe('Unit: Prebid Module', function () { 'alwaysUseBid': true, 'auctionId': 123456, 'adserverTargeting': { - 'hb_bidder': 'appnexus', - 'hb_adid': '233bcbee889d46d', - 'hb_pb': '10.00', - 'hb_size': '300x250', 'foobar': '300x250', - 'hb_deal_appnexusDummyName': '1234' + [CONSTANTS.TARGETING_KEYS.BIDDER]: 'appnexus', + [CONSTANTS.TARGETING_KEYS.AD_ID]: '233bcbee889d46d', + [CONSTANTS.TARGETING_KEYS.PRICE_BUCKET]: '10.00', + [CONSTANTS.TARGETING_KEYS.SIZE]: '300x250', + [CONSTANTS.TARGETING_KEYS.DEAL + '_appnexusDummyName']: '1234' } } ]; @@ -1952,11 +1951,11 @@ describe('Unit: Prebid Module', function () { expect(newAdserverTargeting).to.deep.equal(window.apntag.tags[adUnitCode].keywords); }); - it('should not find hb_adid key in lowercase for all bidders', function () { + it('should not find ' + CONSTANTS.TARGETING_KEYS.AD_ID + ' key in lowercase for all bidders', function() { const adUnitCode = '/19968336/header-bid-tag-0'; $$PREBID_GLOBAL$$.setConfig({ enableSendAllBids: true }); targeting.setTargetingForAst(); - const keywords = Object.keys(window.apntag.tags[adUnitCode].keywords).filter(keyword => (keyword.substring(0, 'hb_adid'.length) === 'hb_adid')); + const keywords = Object.keys(window.apntag.tags[adUnitCode].keywords).filter(keyword => (keyword.substring(0, CONSTANTS.TARGETING_KEYS.AD_ID.length) === CONSTANTS.TARGETING_KEYS.AD_ID)); expect(keywords.length).to.equal(0); }); }); diff --git a/test/spec/utils_spec.js b/test/spec/utils_spec.js index 7891eff5f33..952c6791056 100755 --- a/test/spec/utils_spec.js +++ b/test/spec/utils_spec.js @@ -1,5 +1,6 @@ import { getAdServerTargeting } from 'test/fixtures/fixtures'; import { expect } from 'chai'; +import CONSTANTS from 'src/constants.json'; var assert = require('assert'); var utils = require('src/utils'); @@ -101,7 +102,7 @@ describe('Utils', function () { var obj = getAdServerTargeting(); var output = utils.transformAdServerTargetingObj(obj[Object.keys(obj)[0]]); - var expected = 'foobar=0x0%2C300x250%2C300x600&hb_size=300x250&hb_pb=10.00&hb_adid=233bcbee889d46d&hb_bidder=appnexus&hb_size_triplelift=0x0&hb_pb_triplelift=10.00&hb_adid_triplelift=222bb26f9e8bd&hb_bidder_triplelift=triplelift&hb_size_appnexus=300x250&hb_pb_appnexus=10.00&hb_adid_appnexus=233bcbee889d46d&hb_bidder_appnexus=appnexus&hb_size_pagescience=300x250&hb_pb_pagescience=10.00&hb_adid_pagescience=25bedd4813632d7&hb_bidder_pagescienc=pagescience&hb_size_brightcom=300x250&hb_pb_brightcom=10.00&hb_adid_brightcom=26e0795ab963896&hb_bidder_brightcom=brightcom&hb_size_brealtime=300x250&hb_pb_brealtime=10.00&hb_adid_brealtime=275bd666f5a5a5d&hb_bidder_brealtime=brealtime&hb_size_pubmatic=300x250&hb_pb_pubmatic=10.00&hb_adid_pubmatic=28f4039c636b6a7&hb_bidder_pubmatic=pubmatic&hb_size_rubicon=300x600&hb_pb_rubicon=10.00&hb_adid_rubicon=29019e2ab586a5a&hb_bidder_rubicon=rubicon'; + var expected = 'foobar=0x0%2C300x250%2C300x600&' + CONSTANTS.TARGETING_KEYS.SIZE + '=300x250&' + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '=10.00&' + CONSTANTS.TARGETING_KEYS.AD_ID + '=233bcbee889d46d&' + CONSTANTS.TARGETING_KEYS.BIDDER + '=appnexus&' + CONSTANTS.TARGETING_KEYS.SIZE + '_triplelift=0x0&' + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_triplelift=10.00&' + CONSTANTS.TARGETING_KEYS.AD_ID + '_triplelift=222bb26f9e8bd&' + CONSTANTS.TARGETING_KEYS.BIDDER + '_triplelift=triplelift&' + CONSTANTS.TARGETING_KEYS.SIZE + '_appnexus=300x250&' + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_appnexus=10.00&' + CONSTANTS.TARGETING_KEYS.AD_ID + '_appnexus=233bcbee889d46d&' + CONSTANTS.TARGETING_KEYS.BIDDER + '_appnexus=appnexus&' + CONSTANTS.TARGETING_KEYS.SIZE + '_pagescience=300x250&' + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_pagescience=10.00&' + CONSTANTS.TARGETING_KEYS.AD_ID + '_pagescience=25bedd4813632d7&' + CONSTANTS.TARGETING_KEYS.BIDDER + '_pagescienc=pagescience&' + CONSTANTS.TARGETING_KEYS.SIZE + '_brightcom=300x250&' + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_brightcom=10.00&' + CONSTANTS.TARGETING_KEYS.AD_ID + '_brightcom=26e0795ab963896&' + CONSTANTS.TARGETING_KEYS.BIDDER + '_brightcom=brightcom&' + CONSTANTS.TARGETING_KEYS.SIZE + '_brealtime=300x250&' + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_brealtime=10.00&' + CONSTANTS.TARGETING_KEYS.AD_ID + '_brealtime=275bd666f5a5a5d&' + CONSTANTS.TARGETING_KEYS.BIDDER + '_brealtime=brealtime&' + CONSTANTS.TARGETING_KEYS.SIZE + '_pubmatic=300x250&' + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_pubmatic=10.00&' + CONSTANTS.TARGETING_KEYS.AD_ID + '_pubmatic=28f4039c636b6a7&' + CONSTANTS.TARGETING_KEYS.BIDDER + '_pubmatic=pubmatic&' + CONSTANTS.TARGETING_KEYS.SIZE + '_rubicon=300x600&' + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_rubicon=10.00&' + CONSTANTS.TARGETING_KEYS.AD_ID + '_rubicon=29019e2ab586a5a&' + CONSTANTS.TARGETING_KEYS.BIDDER + '_rubicon=rubicon'; assert.equal(output, expected); });