diff --git a/modules/tappxBidAdapter.js b/modules/tappxBidAdapter.js index 1cf5a0f8be7..d8f6654a567 100644 --- a/modules/tappxBidAdapter.js +++ b/modules/tappxBidAdapter.js @@ -8,7 +8,7 @@ import { config } from '../src/config.js'; const BIDDER_CODE = 'tappx'; const TTL = 360; const CUR = 'USD'; -const TAPPX_BIDDER_VERSION = '0.1.10413'; +const TAPPX_BIDDER_VERSION = '0.1.10420'; const TYPE_CNN = 'prebidjs'; const VIDEO_SUPPORT = ['instream']; @@ -262,11 +262,29 @@ function buildOneRequest(validBidRequests, bidderRequest) { imp.secure = 1; imp.bidfloor = utils.deepAccess(validBidRequests, 'params.bidfloor'); + if (utils.isFn(validBidRequests.getFloor)) { + try { + let floor = validBidRequests.getFloor({ + currency: CUR, + mediaType: '*', + size: '*' + }); + if (utils.isPlainObject(floor) && !isNaN(floor.floor) && floor.currency === 'USD') { + imp.bidfloor = floor.floor; + } else { + utils.logWarn('[TAPPX]: ', 'Currency not valid. Use only USD with Tappx.'); + } + } catch (e) { + utils.logWarn('[TAPPX]: ', e); + imp.bidfloor = utils.deepAccess(validBidRequests, 'params.bidfloor'); // Be sure that we have an imp.bidfloor + } + } let bidder = {}; bidder.tappxkey = TAPPXKEY; bidder.endpoint = ENDPOINT; bidder.host = hostInfo.url; + bidder.bidfloor = BIDFLOOR; bidder.ext = (typeof BIDEXTRA == 'object') ? BIDEXTRA : undefined; imp.ext = {}; @@ -338,9 +356,7 @@ function buildOneRequest(validBidRequests, bidderRequest) { payload.params = params; payload.regs = regs; // < Payload - utils.logMessage('---------------------'); - utils.logMessage(JSON.stringify(payload)); - utils.logMessage('---------------------'); + return { method: 'POST', url: `https://${HOST}/${ENDPOINT}?type_cnn=${TYPE_CNN}&v=${TAPPX_BIDDER_VERSION}`, @@ -365,7 +381,7 @@ function getHostInfo(hostParam) { domainInfo.domain = hostParam.split('/', 1)[0]; domainInfo.url = hostParam; - let regexNewEndpoints = new RegExp(`^(zz.*|testing)\.ssp\.tappx\.com$`, 'i'); + let regexNewEndpoints = new RegExp(`^(vz.*|zz.*|testing)\.ssp\.tappx\.com$`, 'i'); let regexClassicEndpoints = new RegExp(`^[a-z]{3}\.[a-z]{3}\.tappx\.com$`, 'i'); if (regexNewEndpoints.test(domainInfo.domain)) { diff --git a/test/spec/modules/tappxBidAdapter_spec.js b/test/spec/modules/tappxBidAdapter_spec.js index 8197c4f44dd..54c4f8c9dca 100644 --- a/test/spec/modules/tappxBidAdapter_spec.js +++ b/test/spec/modules/tappxBidAdapter_spec.js @@ -293,4 +293,43 @@ describe('Tappx bid adapter', function () { expect(consent[0].url).to.match(/&type=iframe/); }); }) + + describe('module Floor implementation', function() { + let getFloorResponse, bidderRequest_f; + beforeEach(function() { + getFloorResponse = {}; + bidderRequest_f = c_BIDREQUEST; + }) + it('should correctly send hard floors when getFloor function is present and returns valid floor', function () { + // default getFloor response is empty object so should not break and not send hard_floor + bidderRequest_f.bids[0].getFloor = () => getFloorResponse; + let request = spec.buildRequests(bidderRequest_f.bids, bidderRequest_f); + let payload; + + getFloorResponse = undefined; + request = spec.buildRequests(bidderRequest_f.bids, bidderRequest_f); + + // without Module floor + payload = JSON.parse(request[0].data); + expect(payload.imp[0].bidfloor).to.equal(0.05); + + // make it respond with USD floor and string floor + getFloorResponse = {currency: 'USD', floor: '1.23'}; + request = spec.buildRequests(bidderRequest_f.bids, bidderRequest_f); + payload = JSON.parse(request[0].data); + expect(payload.imp[0].bidfloor).to.equal('1.23'); + + // make it respond with EUR floor (not valid) + getFloorResponse = {currency: 'EUR', floor: '1.23'}; + request = spec.buildRequests(bidderRequest_f.bids, bidderRequest_f); + payload = JSON.parse(request[0].data); + expect(payload.imp[0].bidfloor).to.equal(0.05); // Default value from tappx/bidder bidfloor + + // make it respond with USD floor and num floor + getFloorResponse = {currency: 'USD', floor: 1.23}; + request = spec.buildRequests(bidderRequest_f.bids, bidderRequest_f); + payload = JSON.parse(request[0].data); + expect(payload.imp[0].bidfloor).to.equal(1.23); + }); + }) });