Skip to content

Commit

Permalink
Adhese Bid Adapter: Per adunit targets (prebid#6256)
Browse files Browse the repository at this point in the history
* adpod category support test

* Revert "adpod category support test"
  • Loading branch information
mefjush authored and icflournoy committed Feb 5, 2021
1 parent beefa7a commit 2825a70
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
13 changes: 9 additions & 4 deletions modules/adheseBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,19 @@ export const spec = {
}
const { gdprConsent, refererInfo } = bidderRequest;

const targets = validBidRequests.map(bid => bid.params.data).reduce(mergeTargets, {});
const gdprParams = (gdprConsent && gdprConsent.consentString) ? { xt: [gdprConsent.consentString] } : {};
const refererParams = (refererInfo && refererInfo.referer) ? { xf: [base64urlEncode(refererInfo.referer)] } : {};
const id5Params = (getId5Id(validBidRequests)) ? { x5: [getId5Id(validBidRequests)] } : {};
const slots = validBidRequests.map(bid => ({ slotname: bidToSlotName(bid) }));
const commonParams = { ...gdprParams, ...refererParams, ...id5Params };

const slots = validBidRequests.map(bid => ({
slotname: bidToSlotName(bid),
parameters: cleanTargets(bid.params.data)
}));

const payload = {
slots: slots,
parameters: { ...targets, ...gdprParams, ...refererParams, ...id5Params }
parameters: commonParams
}

const account = getAccount(validBidRequests);
Expand Down Expand Up @@ -110,7 +114,8 @@ function adResponse(bid, ad) {
return bidResponse;
}

function mergeTargets(targets, target) {
function cleanTargets(target) {
const targets = {};
if (target) {
Object.keys(target).forEach(function (key) {
const val = target[key];
Expand Down
14 changes: 8 additions & 6 deletions test/spec/modules/adheseBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,31 +74,33 @@ describe('AdheseAdapter', function () {
it('should include requested slots', function () {
let req = spec.buildRequests([ minimalBid() ], bidderRequest);

expect(JSON.parse(req.data).slots).to.deep.include({ 'slotname': '_main_page_-leaderboard' });
expect(JSON.parse(req.data).slots[0].slotname).to.equal('_main_page_-leaderboard');
});

it('should include all extra bid params', function () {
let req = spec.buildRequests([ bidWithParams({ 'ag': '25' }) ], bidderRequest);

expect(JSON.parse(req.data).parameters).to.deep.include({ 'ag': [ '25' ] });
expect(JSON.parse(req.data).slots[0].parameters).to.deep.include({ 'ag': [ '25' ] });
});

it('should include duplicate bid params once', function () {
it('should assign bid params per slot', function () {
let req = spec.buildRequests([ bidWithParams({ 'ag': '25' }), bidWithParams({ 'ag': '25', 'ci': 'gent' }) ], bidderRequest);

expect(JSON.parse(req.data).parameters).to.deep.include({'ag': ['25']}).and.to.deep.include({ 'ci': [ 'gent' ] });
expect(JSON.parse(req.data).slots[0].parameters).to.deep.include({ 'ag': [ '25' ] }).and.not.to.deep.include({ 'ci': [ 'gent' ] });
expect(JSON.parse(req.data).slots[1].parameters).to.deep.include({ 'ag': [ '25' ] }).and.to.deep.include({ 'ci': [ 'gent' ] });
});

it('should split multiple target values', function () {
let req = spec.buildRequests([ bidWithParams({ 'ci': 'london' }), bidWithParams({ 'ci': 'gent' }) ], bidderRequest);

expect(JSON.parse(req.data).parameters).to.deep.include({ 'ci': [ 'london', 'gent' ] });
expect(JSON.parse(req.data).slots[0].parameters).to.deep.include({ 'ci': [ 'london' ] });
expect(JSON.parse(req.data).slots[1].parameters).to.deep.include({ 'ci': [ 'gent' ] });
});

it('should filter out empty params', function () {
let req = spec.buildRequests([ bidWithParams({ 'aa': [], 'bb': null, 'cc': '', 'dd': [ '', '' ], 'ee': [ 0, 1, null ], 'ff': 0, 'gg': [ 'x', 'y', '' ] }) ], bidderRequest);

let params = JSON.parse(req.data).parameters;
let params = JSON.parse(req.data).slots[0].parameters;
expect(params).to.not.have.any.keys('aa', 'bb', 'cc', 'dd');
expect(params).to.deep.include({ 'ee': [ 0, 1 ], 'ff': [ 0 ], 'gg': [ 'x', 'y' ] });
});
Expand Down

0 comments on commit 2825a70

Please sign in to comment.