From bd8d8bae5ecdee4216b7b49c1862c3df835e744e Mon Sep 17 00:00:00 2001 From: Anand Venkatraman Date: Tue, 14 Nov 2017 08:41:18 -0500 Subject: [PATCH] Pulsepoint adapter: fixing bid rejection due to missing mandatory bid params. (#1823) * 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 * Fixing review comment * Applying values from "ext" as applicable --- modules/pulsepointLiteBidAdapter.js | 16 ++++++++++ .../modules/pulsepointLiteBidAdapter_spec.js | 29 +++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/modules/pulsepointLiteBidAdapter.js b/modules/pulsepointLiteBidAdapter.js index 99a83871dd8..d851245402c 100644 --- a/modules/pulsepointLiteBidAdapter.js +++ b/modules/pulsepointLiteBidAdapter.js @@ -10,6 +10,10 @@ const NATIVE_DEFAULTS = { ICON_MIN: 50, }; +const DEFAULT_BID_TTL = 20; +const DEFAULT_CURRENCY = 'USD'; +const DEFAULT_NET_REVENUE = true; + /** * PulsePoint "Lite" Adapter. This adapter implementation is lighter than the * alternative/original PulsePointAdapter because it has no external @@ -89,6 +93,9 @@ function bidResponseAvailable(bidRequest, bidResponse) { creative_id: id, creativeId: id, adId: id, + ttl: DEFAULT_BID_TTL, + netRevenue: DEFAULT_NET_REVENUE, + currency: DEFAULT_CURRENCY }; if (idToImpMap[id]['native']) { bid['native'] = nativeResponse(idToImpMap[id], idToBidMap[id]); @@ -98,12 +105,21 @@ function bidResponseAvailable(bidRequest, bidResponse) { bid.width = idToImpMap[id].banner.w; bid.height = idToImpMap[id].banner.h; } + applyExt(bid, idToBidMap[id]) bids.push(bid); } }); return bids; } +function applyExt(bid, ortbBid) { + if (ortbBid && ortbBid.ext) { + bid.ttl = ortbBid.ext.ttl || bid.ttl; + bid.currency = ortbBid.ext.currency || bid.currency; + bid.netRevenue = ortbBid.ext.netRevenue != null ? ortbBid.ext.netRevenue : bid.netRevenue; + } +} + /** * Produces an OpenRTBImpression from a slot config. */ diff --git a/test/spec/modules/pulsepointLiteBidAdapter_spec.js b/test/spec/modules/pulsepointLiteBidAdapter_spec.js index 9731164cd50..2c6f5f0681f 100644 --- a/test/spec/modules/pulsepointLiteBidAdapter_spec.js +++ b/test/spec/modules/pulsepointLiteBidAdapter_spec.js @@ -100,6 +100,35 @@ describe('PulsePoint Lite Adapter Tests', () => { expect(bid.adId).to.equal('bid12345'); expect(bid.creative_id).to.equal('bid12345'); expect(bid.creativeId).to.equal('bid12345'); + expect(bid.netRevenue).to.equal(true); + expect(bid.currency).to.equal('USD'); + expect(bid.ttl).to.equal(20); + }); + + it('Verify use ttl in ext', () => { + const request = spec.buildRequests(slotConfigs); + const ortbRequest = JSON.parse(request.data); + const ortbResponse = { + seatbid: [{ + bid: [{ + impid: ortbRequest.imp[0].id, + price: 1.25, + adm: 'This is an Ad', + ext: { + ttl: 30, + netRevenue: false, + currency: 'INR' + } + }] + }] + }; + const bids = spec.interpretResponse({ body: ortbResponse }, request); + expect(bids).to.have.lengthOf(1); + // verify first bid + const bid = bids[0]; + expect(bid.ttl).to.equal(30); + expect(bid.netRevenue).to.equal(false); + expect(bid.currency).to.equal('INR'); }); it('Verify full passback', () => {