Skip to content

Commit

Permalink
Add schain support for LockerDome adapter (#4360)
Browse files Browse the repository at this point in the history
  • Loading branch information
margsliu authored and jsnellbaker committed Dec 3, 2019
1 parent 94233d4 commit 32aef56
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 10 deletions.
23 changes: 15 additions & 8 deletions modules/lockerdomeBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ export const spec = {
return !!bid.params.adUnitId;
},
buildRequests: function(bidRequests, bidderRequest) {
let schain;

const adUnitBidRequests = bidRequests.map(function (bid) {
if (bid.schain) schain = schain || bid.schain;
return {
requestId: bid.bidId,
adUnitCode: bid.adUnitCode,
adUnitId: utils.getBidIdParameter('adUnitId', bid.params),
sizes: bid.mediaTypes && bid.mediaTypes.banner && bid.mediaTypes.banner.sizes
}
};
});

const bidderRequestCanonicalUrl = (bidderRequest && bidderRequest.refererInfo && bidderRequest.refererInfo.canonicalUrl) || '';
Expand All @@ -25,12 +28,16 @@ export const spec = {
url: encodeURIComponent(bidderRequestCanonicalUrl),
referrer: encodeURIComponent(bidderRequestReferer)
};

if (bidderRequest && bidderRequest.gdprConsent) {
payload.gdpr = {
applies: bidderRequest.gdprConsent.gdprApplies,
consent: bidderRequest.gdprConsent.consentString
};
if (schain) {
payload.schain = schain;
}
if (bidderRequest) {
if (bidderRequest.gdprConsent) {
payload.gdpr = {
applies: bidderRequest.gdprConsent.gdprApplies,
consent: bidderRequest.gdprConsent.consentString
};
}
}

const payloadString = JSON.stringify(payload);
Expand Down Expand Up @@ -58,5 +65,5 @@ export const spec = {
};
});
},
}
};
registerBidder(spec);
51 changes: 49 additions & 2 deletions test/spec/modules/lockerdomeBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,18 @@ describe('LockerDomeAdapter', function () {
transactionId: 'b55e97d7-792c-46be-95a5-3df40b115734',
bidId: '2652ca954bce9',
bidderRequestId: '14a54fade69854',
auctionId: 'd4c83108-615d-4c2c-9384-dac9ffd4fd72'
auctionId: 'd4c83108-615d-4c2c-9384-dac9ffd4fd72',
schain: {
ver: '1.0',
complete: 1,
nodes: [
{
asi: 'indirectseller.com',
sid: '00001',
hp: 1
}
]
}
}, {
bidder: 'lockerdome',
params: {
Expand All @@ -32,7 +43,18 @@ describe('LockerDomeAdapter', function () {
transactionId: '73459f05-c482-4706-b2b7-72e6f6264ce6',
bidId: '4510f2834773ce',
bidderRequestId: '14a54fade69854',
auctionId: 'd4c83108-615d-4c2c-9384-dac9ffd4fd72'
auctionId: 'd4c83108-615d-4c2c-9384-dac9ffd4fd72',
schain: {
ver: '1.0',
complete: 1,
nodes: [
{
asi: 'indirectseller.com',
sid: '00001',
hp: 1
}
]
}
}];

describe('isBidRequestValid', function () {
Expand Down Expand Up @@ -103,6 +125,31 @@ describe('LockerDomeAdapter', function () {
});
});

it('should add schain to request if available', function () {
const bidderRequest = {
refererInfo: {
canonicalUrl: 'https://example.com/canonical',
referer: 'https://example.com'
}
};
const schainExpected = {
ver: '1.0',
complete: 1,
nodes: [
{
asi: 'indirectseller.com',
sid: '00001',
hp: 1
}
]
};

const request = spec.buildRequests(bidRequests, bidderRequest);
const requestData = JSON.parse(request.data);
expect(requestData.schain).to.be.an('object');
expect(requestData.schain).to.deep.equal(schainExpected);
});

describe('interpretResponse', function () {
it('should return an empty array if an invalid response is passed', function () {
const interpretedResponse = spec.interpretResponse({ body: {} });
Expand Down

0 comments on commit 32aef56

Please sign in to comment.