Skip to content

Commit

Permalink
[Triplelift] Fix FPD key-value pairs logic (#6065)
Browse files Browse the repository at this point in the history
* follow spec to parse fpd
* ad unit support stub
* adunit method
* ad unit etc
* typo
* fix test
* typo
* change to const
  • Loading branch information
Brandon Ling authored Dec 9, 2020
1 parent cbd1169 commit 478e045
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 10 deletions.
31 changes: 28 additions & 3 deletions modules/tripleliftBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ function _buildPostBody(bidRequests) {
} else if (bidRequest.mediaTypes.banner) {
imp.banner = { format: _sizes(bidRequest.sizes) };
};
if (!utils.isEmpty(bidRequest.fpd)) {
imp.fpd = _getAdUnitFpd(bidRequest.fpd);
}
return imp;
});

Expand Down Expand Up @@ -183,12 +186,34 @@ function _getFloor (bid) {
}

function _getGlobalFpd() {
let fpd = {};
const fpd = {};
const context = {}
const user = {};

const fpdContext = Object.assign({}, config.getConfig('fpd.context'));
const fpdUser = Object.assign({}, config.getConfig('fpd.user'));

_addEntries(fpd, fpdContext);
_addEntries(fpd, fpdUser);
_addEntries(context, fpdContext);
_addEntries(user, fpdUser);

if (!utils.isEmpty(context)) {
fpd.context = context;
}
if (!utils.isEmpty(user)) {
fpd.user = user;
}
return fpd;
}

function _getAdUnitFpd(adUnitFpd) {
const fpd = {};
const context = {};

_addEntries(context, adUnitFpd.context);

if (!utils.isEmpty(context)) {
fpd.context = context;
}

return fpd;
}
Expand Down
31 changes: 24 additions & 7 deletions test/spec/modules/tripleliftBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ describe('triplelift adapter', function () {
auctionId: '1d1a030790a475',
userId: {},
schain,
fpd: {
context: {
pbAdSlot: 'homepage-top-rect',
data: {
adUnitSpecificAttribute: 123
}
}
}
},
{
bidder: 'triplelift',
Expand Down Expand Up @@ -597,17 +605,19 @@ describe('triplelift adapter', function () {
const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest);
expect(request.data.imp[0].floor).to.equal(1.99);
});
it('should send fpd on root level ext if kvps are available', function() {
it('should send global config fpd if kvps are available', function() {
const sens = null;
const category = ['news', 'weather', 'hurricane'];
const pmp_elig = 'true';
const fpd = {
context: {
pmp_elig,
category,
pmp_elig: pmp_elig,
data: {
category: category
}
},
user: {
sens,
sens: sens,
}
}
sandbox.stub(config, 'getConfig').callsFake(key => {
Expand All @@ -618,9 +628,16 @@ describe('triplelift adapter', function () {
});
const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest);
const { data: payload } = request;
expect(payload.ext.fpd).to.not.haveOwnProperty('sens');
expect(payload.ext.fpd).to.haveOwnProperty('category');
expect(payload.ext.fpd).to.haveOwnProperty('pmp_elig');
expect(payload.ext.fpd.user).to.not.exist;
expect(payload.ext.fpd.context.data).to.haveOwnProperty('category');
expect(payload.ext.fpd.context).to.haveOwnProperty('pmp_elig');
});
it('should send ad unit fpd if kvps are available', function() {
const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest);
expect(request.data.imp[0].fpd.context).to.haveOwnProperty('pbAdSlot');
expect(request.data.imp[0].fpd.context).to.haveOwnProperty('data');
expect(request.data.imp[0].fpd.context.data).to.haveOwnProperty('adUnitSpecificAttribute');
expect(request.data.imp[1].fpd).to.not.exist;
});
});

Expand Down

0 comments on commit 478e045

Please sign in to comment.