diff --git a/modules/adtelligentBidAdapter.js b/modules/adtelligentBidAdapter.js index e0a65c7a0d8..daa43799edb 100644 --- a/modules/adtelligentBidAdapter.js +++ b/modules/adtelligentBidAdapter.js @@ -20,26 +20,36 @@ export const spec = { getUserSyncs: function (syncOptions, serverResponses) { var syncs = []; - function addSyncs(_s) { - if (_s && _s.length) { - _s.forEach(s => { + function addSyncs(bid) { + const uris = bid.cookieURLs; + const types = bid.cookieURLSTypes || []; + + if (uris && uris.length) { + uris.forEach((uri, i) => { + let type = types[i] || 'image'; + + if ((!syncOptions.pixelEnabled && type == 'image') || + (!syncOptions.iframeEnabled && type == 'iframe')) { + return; + } + syncs.push({ - type: 'image', - url: s + type: type, + url: uri }) }) } } - if (syncOptions.pixelEnabled) { + if (syncOptions.pixelEnabled || syncOptions.iframeEnabled) { serverResponses && serverResponses.length && serverResponses.forEach((response) => { if (response.body) { if (utils.isArray(response.body)) { response.body.forEach(b => { - addSyncs(b.cookieURLs); + addSyncs(b); }) } else { - addSyncs(response.body.cookieURLs) + addSyncs(response.body) } } }) diff --git a/test/spec/modules/adtelligentBidAdapter_spec.js b/test/spec/modules/adtelligentBidAdapter_spec.js index 0ee2bb2726f..9187d779145 100644 --- a/test/spec/modules/adtelligentBidAdapter_spec.js +++ b/test/spec/modules/adtelligentBidAdapter_spec.js @@ -61,6 +61,21 @@ const SERVER_DISPLAY_RESPONSE = { }], 'cookieURLs': ['link1', 'link2'] }; +const SERVER_DISPLAY_RESPONSE_WITH_MIXED_SYNCS = { + 'source': {'aid': 12345, 'pubId': 54321}, + 'bids': [{ + 'ad': '', + 'requestId': '2e41f65424c87c', + 'creative_id': 342516, + 'cmpId': 342516, + 'height': 250, + 'cur': 'USD', + 'width': 300, + 'cpm': 0.9 + }], + 'cookieURLs': ['link1', 'link2'], + 'cookieURLSTypes': ['image', 'iframe'] +}; const videoBidderRequest = { bidderCode: 'bidderCode', @@ -109,17 +124,39 @@ const displayEqResponse = [{ describe('adtelligentBidAdapter', function () { // todo remove only const adapter = newBidder(spec); - describe('user syncs', function () { + describe('user syncs as image', function () { it('should be returned if pixel enabled', function () { - const syncs = spec.getUserSyncs({pixelEnabled: true}, [{body: SERVER_DISPLAY_RESPONSE}]); + const syncs = spec.getUserSyncs({pixelEnabled: true}, [{body: SERVER_DISPLAY_RESPONSE_WITH_MIXED_SYNCS}]); + + expect(syncs.map(s => s.url)).to.deep.equal([SERVER_DISPLAY_RESPONSE_WITH_MIXED_SYNCS.cookieURLs[0]]); + expect(syncs.map(s => s.type)).to.deep.equal(['image']); + }) + }) + + describe('user syncs as iframe', function () { + it('should be returned if iframe enabled', function () { + const syncs = spec.getUserSyncs({iframeEnabled: true}, [{body: SERVER_DISPLAY_RESPONSE_WITH_MIXED_SYNCS}]); + + expect(syncs.map(s => s.url)).to.deep.equal([SERVER_DISPLAY_RESPONSE_WITH_MIXED_SYNCS.cookieURLs[1]]); + expect(syncs.map(s => s.type)).to.deep.equal(['iframe']); + }) + }) + + describe('user syncs with both types', function () { + it('should be returned if pixel and iframe enabled', function () { + const syncs = spec.getUserSyncs({ + iframeEnabled: true, + pixelEnabled: true + }, [{body: SERVER_DISPLAY_RESPONSE_WITH_MIXED_SYNCS}]); - expect(syncs.map(s => s.url)).to.deep.equal(SERVER_DISPLAY_RESPONSE.cookieURLs); + expect(syncs.map(s => s.url)).to.deep.equal(SERVER_DISPLAY_RESPONSE_WITH_MIXED_SYNCS.cookieURLs); + expect(syncs.map(s => s.type)).to.deep.equal(SERVER_DISPLAY_RESPONSE_WITH_MIXED_SYNCS.cookieURLSTypes); }) }) describe('user syncs', function () { it('should not be returned if pixel not set', function () { - const syncs = spec.getUserSyncs({}, [{body: SERVER_DISPLAY_RESPONSE}]); + const syncs = spec.getUserSyncs({}, [{body: SERVER_DISPLAY_RESPONSE_WITH_MIXED_SYNCS}]); expect(syncs).to.be.empty; })