Skip to content

Commit

Permalink
Adtelligent support both userSync types (#3444)
Browse files Browse the repository at this point in the history
* Add user sync pixel logic in Adtelligent adapter

* Add gdpr support

* Add gdpr support

* Update tests

* Support both types of user syncs

* More logical code with syncs

* Remove "only" from test

* Update test messages
  • Loading branch information
GeneGenie authored and bretg committed Jan 31, 2019
1 parent 69c4caf commit 596af88
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 12 deletions.
26 changes: 18 additions & 8 deletions modules/adtelligentBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
})
Expand Down
45 changes: 41 additions & 4 deletions test/spec/modules/adtelligentBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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': '<!-- Creative -->',
'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',
Expand Down Expand Up @@ -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;
})
Expand Down

0 comments on commit 596af88

Please sign in to comment.