diff --git a/modules/stroeerCoreBidAdapter.js b/modules/stroeerCoreBidAdapter.js index b23d148b243..909dcc9db13 100644 --- a/modules/stroeerCoreBidAdapter.js +++ b/modules/stroeerCoreBidAdapter.js @@ -332,7 +332,7 @@ export const spec = { function getGlobalKeyValues() { try { - return win.SDG.Publisher.getConfig().getFilteredKeyValues(); + return getValidKeyValues(win.SDG.Publisher.getConfig().getFilteredKeyValues()); } catch (e) { return undefined; } @@ -340,11 +340,20 @@ export const spec = { function getLocalKeyValues(position) { try { - return win.SDG.getCN().getSlotByPosition(position).getFilteredKeyValues(); + return getValidKeyValues(win.SDG.getCN().getSlotByPosition(position).getFilteredKeyValues()); } catch (e) { return undefined; } } + + function getValidKeyValues(allKeyValues) { + const validKeys = Object.keys(allKeyValues).filter((key) => isValidValuesForKeyValue(allKeyValues[key])) + return validKeys.reduce((keyValues, key) => ({...keyValues, [key]: allKeyValues[key]}), {}); + } + + function isValidValuesForKeyValue(values) { + return Array.isArray(values) && values.every((v) => typeof v === 'string' || typeof v === 'number'); + } }, interpretResponse: function (serverResponse) { diff --git a/test/spec/modules/stroeerCoreBidAdapter_spec.js b/test/spec/modules/stroeerCoreBidAdapter_spec.js index bc36644431a..d6f4c0b0ac3 100644 --- a/test/spec/modules/stroeerCoreBidAdapter_spec.js +++ b/test/spec/modules/stroeerCoreBidAdapter_spec.js @@ -594,27 +594,55 @@ describe('stroeerCore bid adapter', function () { assert.deepEqual(actualJsonPayload, expectedJsonPayload); }); - it('should have expected global key values', () => { - win.SDG = buildFakeSDGForGlobalKeyValues({ - adset: ['brsl'], - browserapp: ['chrome'], + describe('and metatag is available', () => { + it('should have expected global key values', () => { + win.SDG = buildFakeSDGForGlobalKeyValues({ + adset: ['brsl'], + browserapp: ['chrome'], + }); + + const bidReq = buildBidderRequest(); + + const serverRequestInfo = spec.buildRequests(bidReq.bids, bidReq)[0]; + + assert.deepEqual(serverRequestInfo.data.kvg, { + adset: ['brsl'], + browserapp: ['chrome'], + }); }); - const bidReq = buildBidderRequest(); + it('should filter out invalid global key values', () => { + win.SDG = buildFakeSDGForGlobalKeyValues({ + validString: ['brsl'], + validNumber: [1], + validMixed: ['brsl', 1], + invalidOne: [true], + invalidTwo: [['string']], + invalidThree: [[1]], + invalidFour: {a: 1}, + invalidFive: [{a: 1}], + invalidSix: true, + invalidSeven: 'string', + invalidEight: 1, + }); - const serverRequestInfo = spec.buildRequests(bidReq.bids, bidReq)[0]; + const bidReq = buildBidderRequest(); + + const serverRequestInfo = spec.buildRequests(bidReq.bids, bidReq)[0]; - assert.deepEqual(serverRequestInfo.data.kvg, { - adset: ['brsl'], - browserapp: ['chrome'], + assert.deepEqual(serverRequestInfo.data.kvg, { + validString: ['brsl'], + validNumber: [1], + validMixed: ['brsl', 1], + }); }); function buildFakeSDGForGlobalKeyValues(keyValues) { return { Publisher: { - getConfig: function() { + getConfig: function () { return { - getFilteredKeyValues: function() { + getFilteredKeyValues: function () { return keyValues; } } @@ -622,35 +650,62 @@ describe('stroeerCore bid adapter', function () { } } } - }); - it('should have expected local key values', () => { - win.SDG = buildFakeSDGForLocalKeyValues({ - 'div-1': { + it('should have expected local key values', () => { + win.SDG = buildFakeSDGForLocalKeyValues({ + 'div-1': { + as: ['banner'], + hb_unit: ['banner'], + pc: ['1'], + }, + 'div-2': { + as: ['bannerer'], + hb_unit: ['bannerer'], + pc: ['2'], + } + }); + + const bidReq = buildBidderRequest(); + const serverRequestInfo = spec.buildRequests(bidReq.bids, bidReq)[0]; + + assert.deepEqual(serverRequestInfo.data.bids[0].kvl, { as: ['banner'], hb_unit: ['banner'], pc: ['1'], - }, - 'div-2': { + }); + + assert.deepEqual(serverRequestInfo.data.bids[1].kvl, { as: ['bannerer'], hb_unit: ['bannerer'], pc: ['2'], - } + }); }); - const bidReq = buildBidderRequest(); - const serverRequestInfo = spec.buildRequests(bidReq.bids, bidReq)[0]; + it('should filter out invalid local key values', () => { + win.SDG = buildFakeSDGForLocalKeyValues({ + 'div-1': { + validString: ['brsl'], + validNumber: [1], + validMixed: ['brsl', 1], + invalidOne: [true], + invalidTwo: [['string']], + invalidThree: [[1]], + invalidFour: {a: 1}, + invalidFive: [{a: 1}], + invalidSix: true, + invalidSeven: 'string', + invalidEight: 1, + } + }); - assert.deepEqual(serverRequestInfo.data.bids[0].kvl, { - as: ['banner'], - hb_unit: ['banner'], - pc: ['1'], - }); + const bidReq = buildBidderRequest(); + const serverRequestInfo = spec.buildRequests(bidReq.bids, bidReq)[0]; - assert.deepEqual(serverRequestInfo.data.bids[1].kvl, { - as: ['bannerer'], - hb_unit: ['bannerer'], - pc: ['2'], + assert.deepEqual(serverRequestInfo.data.bids[0].kvl, { + validString: ['brsl'], + validNumber: [1], + validMixed: ['brsl', 1], + }); }); function buildFakeSDGForLocalKeyValues(localTargeting) { @@ -666,60 +721,60 @@ describe('stroeerCore bid adapter', function () { } } } - }); - it('should have expected context', () => { - win.SDG = buildFakeSDGContext({ - 'div-1': { - adUnits: ['adUnit-1', 'adUnit-2'], - zone: 'zone-1', - pageType: 'pageType-1' - }, - 'div-2': { - adUnits: ['adUnit-3', 'adUnit-4', 'adUnit-5'], - zone: 'zone-2', - pageType: 'pageType-2' - } - }); - const bidReq = buildBidderRequest(); + it('should have expected context', () => { + win.SDG = buildFakeSDGContext({ + 'div-1': { + adUnits: ['adUnit-1', 'adUnit-2'], + zone: 'zone-1', + pageType: 'pageType-1' + }, + 'div-2': { + adUnits: ['adUnit-3', 'adUnit-4', 'adUnit-5'], + zone: 'zone-2', + pageType: 'pageType-2' + } + }); + const bidReq = buildBidderRequest(); - const serverRequestInfo = spec.buildRequests(bidReq.bids, bidReq)[0]; + const serverRequestInfo = spec.buildRequests(bidReq.bids, bidReq)[0]; - assert.deepEqual(serverRequestInfo.data.bids[0].ctx, { - 'position': 'div-1', - 'adUnits': ['adUnit-1', 'adUnit-2'], - 'zone': 'zone-1', - 'pageType': 'pageType-1' - }); + assert.deepEqual(serverRequestInfo.data.bids[0].ctx, { + 'position': 'div-1', + 'adUnits': ['adUnit-1', 'adUnit-2'], + 'zone': 'zone-1', + 'pageType': 'pageType-1' + }); - assert.deepEqual(serverRequestInfo.data.bids[1].ctx, { - 'position': 'div-2', - 'adUnits': ['adUnit-3', 'adUnit-4', 'adUnit-5'], - 'zone': 'zone-2', - 'pageType': 'pageType-2' - }); + assert.deepEqual(serverRequestInfo.data.bids[1].ctx, { + 'position': 'div-2', + 'adUnits': ['adUnit-3', 'adUnit-4', 'adUnit-5'], + 'zone': 'zone-2', + 'pageType': 'pageType-2' + }); - function buildFakeSDGContext(config) { - return { - getCN: function () { - return { - getSlotByPosition: function (position) { - return { - getAdUnits: function () { - return config[position].adUnits; - }, - getZone: function () { - return config[position].zone; - }, - getPageType: function () { - return config[position].pageType; - }, - }; - } - }; + function buildFakeSDGContext(config) { + return { + getCN: function () { + return { + getSlotByPosition: function (position) { + return { + getAdUnits: function () { + return config[position].adUnits; + }, + getZone: function () { + return config[position].zone; + }, + getPageType: function () { + return config[position].pageType; + }, + }; + } + }; + } } } - } + }); }); it('should handle banner sizes for pre version 3', () => {