diff --git a/modules/aduptechBidAdapter.js b/modules/aduptechBidAdapter.js index 1186e0410ab..913b96ad47c 100644 --- a/modules/aduptechBidAdapter.js +++ b/modules/aduptechBidAdapter.js @@ -113,6 +113,30 @@ export const internal = { return null; }, + /** + * Extracts the floor price params from given bidRequest + * + * @param {BidRequest} bidRequest + * @returns {undefined|float} + */ + extractFloorPrice: (bidRequest) => { + let floorPrice; + if (bidRequest && bidRequest.params && bidRequest.params.floor) { + // if there is a manual floorPrice set + floorPrice = !isNaN(parseInt(bidRequest.params.floor)) ? bidRequest.params.floor : undefined; + } + if (typeof bidRequest.getFloor === 'function') { + // use prebid floor module + let floorInfo; + try { + floorInfo = bidRequest.getFloor(); + } catch (e) {} + floorPrice = typeof floorInfo === 'object' && !isNaN(parseInt(floorInfo.floor)) ? floorInfo.floor : floorPrice; + } + + return floorPrice; + }, + /** * Group given array of bidRequests by params.publisher * @@ -248,6 +272,12 @@ export const spec = { bid.native = nativeConfig; } + // add floor price + const floorPrice = internal.extractFloorPrice(bidRequest); + if (floorPrice) { + bid.floorPrice = floorPrice; + } + request.data.imp.push(bid); }); diff --git a/test/spec/modules/aduptechBidAdapter_spec.js b/test/spec/modules/aduptechBidAdapter_spec.js index 362cd3e506a..5d6060be021 100644 --- a/test/spec/modules/aduptechBidAdapter_spec.js +++ b/test/spec/modules/aduptechBidAdapter_spec.js @@ -545,6 +545,71 @@ describe('AduptechBidAdapter', () => { } ]); }); + + it('should build a request with floorPrices', () => { + const bidderRequest = { + auctionId: 'auctionId123', + refererInfo: { + canonicalUrl: 'http://crazy.canonical.url', + referer: 'http://crazy.referer.url' + }, + gdprConsent: { + consentString: 'consentString123', + gdprApplies: true + } + }; + + const getFloorResponse = { + currency: 'USD', + floor: '1.23' + }; + + const validBidRequests = [ + { + bidId: 'bidId1', + adUnitCode: 'adUnitCode1', + transactionId: 'transactionId1', + mediaTypes: { + banner: { + sizes: [[100, 200], [300, 400]] + } + }, + params: { + publisher: 'publisher1', + placement: 'placement1' + }, + getFloor: () => { + return getFloorResponse + } + } + ]; + + expect(spec.buildRequests(validBidRequests, bidderRequest)).to.deep.equal([ + { + url: internal.buildEndpointUrl(validBidRequests[0].params.publisher), + method: ENDPOINT_METHOD, + data: { + auctionId: bidderRequest.auctionId, + pageUrl: bidderRequest.refererInfo.canonicalUrl, + referrer: bidderRequest.refererInfo.referer, + gdpr: { + consentString: bidderRequest.gdprConsent.consentString, + consentRequired: bidderRequest.gdprConsent.gdprApplies + }, + imp: [ + { + bidId: validBidRequests[0].bidId, + transactionId: validBidRequests[0].transactionId, + adUnitCode: validBidRequests[0].adUnitCode, + params: validBidRequests[0].params, + banner: validBidRequests[0].mediaTypes.banner, + floorPrice: getFloorResponse.floor + } + ] + } + } + ]); + }); }); describe('interpretResponse', () => {