From 32aef56972c9c5a1581bd4ef89df9b752b4a1c8e Mon Sep 17 00:00:00 2001 From: Margaret Liu Date: Tue, 3 Dec 2019 13:12:28 -0600 Subject: [PATCH] Add schain support for LockerDome adapter (#4360) --- modules/lockerdomeBidAdapter.js | 23 ++++++--- .../spec/modules/lockerdomeBidAdapter_spec.js | 51 ++++++++++++++++++- 2 files changed, 64 insertions(+), 10 deletions(-) diff --git a/modules/lockerdomeBidAdapter.js b/modules/lockerdomeBidAdapter.js index 3832ed20d57..97c540a7a40 100644 --- a/modules/lockerdomeBidAdapter.js +++ b/modules/lockerdomeBidAdapter.js @@ -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) || ''; @@ -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); @@ -58,5 +65,5 @@ export const spec = { }; }); }, -} +}; registerBidder(spec); diff --git a/test/spec/modules/lockerdomeBidAdapter_spec.js b/test/spec/modules/lockerdomeBidAdapter_spec.js index a108b25e2ff..fdc2b3530eb 100644 --- a/test/spec/modules/lockerdomeBidAdapter_spec.js +++ b/test/spec/modules/lockerdomeBidAdapter_spec.js @@ -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: { @@ -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 () { @@ -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: {} });