From 7f7f6ed715e1e4aa9a72dfc83ec91551d59c9b18 Mon Sep 17 00:00:00 2001 From: Anand Venkatraman Date: Fri, 8 Nov 2019 09:58:11 -0500 Subject: [PATCH] PulsePoint Bid Adapter: Support for schain (#4433) * ET-1691: Pulsepoint Analytics adapter for Prebid. (#1) * ET-1691: Adding pulsepoint analytics and tests for pulsepoint adapter * ET-1691: Adding pulsepoint analytics and tests for pulsepoint adapter * ET-1691: cleanup * ET-1691: minor * ET-1691: revert package.json change * Adding bidRequest to bidFactory.createBid method as per https://github.com/prebid/Prebid.js/issues/509 * ET-1765: Adding support for additional params in PulsePoint adapter (#2) * ET-1850: Fixing https://github.com/prebid/Prebid.js/issues/866 * Minor fix * Adding mandatory parameters to Bid * ET-5938 SupplyChain Object Support * Formatting * Code review * Code review * Fix to currency parsing on response --- modules/pulsepointBidAdapter.js | 15 ++++- .../spec/modules/pulsepointBidAdapter_spec.js | 56 +++++++++++++++++-- 2 files changed, 66 insertions(+), 5 deletions(-) diff --git a/modules/pulsepointBidAdapter.js b/modules/pulsepointBidAdapter.js index 3cdbd559614..c3fd1fa5eaf 100644 --- a/modules/pulsepointBidAdapter.js +++ b/modules/pulsepointBidAdapter.js @@ -47,6 +47,7 @@ export const spec = { badv: bidRequests[0].params.badv, user: user(bidRequests[0], bidderRequest), regs: regs(bidderRequest), + source: source(bidRequests[0].schain), }; return { method: 'POST', @@ -116,7 +117,7 @@ function bidResponseAvailable(request, response) { adId: id, ttl: idToBidMap[id].exp || DEFAULT_BID_TTL, netRevenue: DEFAULT_NET_REVENUE, - currency: idToBidMap[id].cur || DEFAULT_CURRENCY + currency: bidResponse.cur || DEFAULT_CURRENCY }; if (idToImpMap[id]['native']) { bid['native'] = nativeResponse(idToImpMap[id], idToBidMap[id]); @@ -428,6 +429,18 @@ function regs(bidderRequest) { return null; } +/** + * Creates source object with supply chain + */ +function source(schain) { + if (schain) { + return { + ext: { schain } + }; + } + return null; +} + /** * Parses the native response from the Bid given. */ diff --git a/test/spec/modules/pulsepointBidAdapter_spec.js b/test/spec/modules/pulsepointBidAdapter_spec.js index 6d5400de216..b62b799c8a0 100644 --- a/test/spec/modules/pulsepointBidAdapter_spec.js +++ b/test/spec/modules/pulsepointBidAdapter_spec.js @@ -138,6 +138,35 @@ describe('PulsePoint Adapter Tests', function () { } } }]; + + const schainParamsSlotConfig = [{ + placementCode: '/DfpAccount1/slot1', + bidId: 'bid12345', + params: { + cp: 'p10000', + ct: 't10000', + cf: '1x1', + bcat: ['IAB-1', 'IAB-20'], + battr: [1, 2, 3], + bidfloor: 1.5, + badv: ['cocacola.com', 'lays.com'] + }, + schain: { + 'ver': '1.0', + 'complete': 1, + 'nodes': [ + { + 'asi': 'exchange1.com', + 'sid': '1234', + 'hp': 1, + 'rid': 'bid-request-1', + 'name': 'publisher', + 'domain': 'publisher.com' + } + ] + }, + }]; + const bidderRequest = { refererInfo: { referer: 'https://publisher.com/home' @@ -210,15 +239,15 @@ describe('PulsePoint Adapter Tests', function () { price: 1.25, adm: 'This is an Ad#1', crid: 'Creative#123', - exp: 50, - cur: 'GBP' + exp: 50 }, { impid: ortbRequest.imp[1].id, price: 1.25, adm: 'This is an Ad#2', crid: 'Creative#123' }] - }] + }], + cur: 'GBP' }; const bids = spec.interpretResponse({ body: ortbResponse }, request); expect(bids).to.have.lengthOf(2); @@ -232,7 +261,7 @@ describe('PulsePoint Adapter Tests', function () { expect(secondBid.cpm).to.equal(1.25); expect(secondBid.ad).to.equal('This is an Ad#2'); expect(secondBid.ttl).to.equal(20); - expect(secondBid.currency).to.equal('USD'); + expect(secondBid.currency).to.equal('GBP'); }); it('Verify full passback', function () { @@ -485,6 +514,25 @@ describe('PulsePoint Adapter Tests', function () { expect(ortbRequest.imp[1].ext).to.be.null; }); + it('Verify schain parameters', function () { + const request = spec.buildRequests(schainParamsSlotConfig, bidderRequest); + const ortbRequest = request.data; + expect(ortbRequest).to.not.equal(null); + expect(ortbRequest.source).to.not.equal(null); + expect(ortbRequest.source.ext).to.not.equal(null); + expect(ortbRequest.source.ext.schain).to.not.equal(null); + expect(ortbRequest.source.ext.schain.complete).to.equal(1); + expect(ortbRequest.source.ext.schain.ver).to.equal('1.0'); + expect(ortbRequest.source.ext.schain.nodes).to.not.equal(null); + expect(ortbRequest.source.ext.schain.nodes).to.lengthOf(1); + expect(ortbRequest.source.ext.schain.nodes[0].asi).to.equal('exchange1.com'); + expect(ortbRequest.source.ext.schain.nodes[0].sid).to.equal('1234'); + expect(ortbRequest.source.ext.schain.nodes[0].hp).to.equal(1); + expect(ortbRequest.source.ext.schain.nodes[0].rid).to.equal('bid-request-1'); + expect(ortbRequest.source.ext.schain.nodes[0].name).to.equal('publisher'); + expect(ortbRequest.source.ext.schain.nodes[0].domain).to.equal('publisher.com'); + }); + it('Verify outstream renderer', function () { const bidderRequestOutstream = Object.assign({}, bidderRequest, {bids: [outstreamSlotConfig[0]]}); const request = spec.buildRequests(outstreamSlotConfig, bidderRequestOutstream);