From 48d8766a40be2e8183310fc06fb7ce63d5622590 Mon Sep 17 00:00:00 2001 From: AdFusionPrebid <144114711+AdFusionPrebid@users.noreply.github.com> Date: Tue, 23 Jan 2024 12:11:29 +0100 Subject: [PATCH] AdFusion Bid Adapter : currency support (#10938) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * adfusion bid adapter test * Add adapter and docs * add currency support * kick of integration tests --------- Co-authored-by: Ɓukasz Co-authored-by: Chris Huie --- modules/adfusionBidAdapter.js | 30 ++++++++++++++++ test/spec/modules/adfusionBidAdapter_spec.js | 37 ++++++++++++++++++-- 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/modules/adfusionBidAdapter.js b/modules/adfusionBidAdapter.js index b3638159c2a..a206ee5e899 100644 --- a/modules/adfusionBidAdapter.js +++ b/modules/adfusionBidAdapter.js @@ -5,6 +5,7 @@ import * as utils from '../src/utils.js'; const adpterVersion = '1.0'; export const REQUEST_URL = 'https://spicyrtb.com/auction/prebid'; +export const DEFAULT_CURRENCY = 'USD'; export const spec = { code: 'adfusion', @@ -23,6 +24,17 @@ const converter = ortbConverter({ context: { netRevenue: true, ttl: 300, + currency: DEFAULT_CURRENCY, + }, + imp(buildImp, bidRequest, context) { + const imp = buildImp(bidRequest, context); + const floor = getBidFloor(bidRequest); + if (floor) { + imp.bidfloor = floor; + imp.bidfloorcur = DEFAULT_CURRENCY; + } + + return imp; }, request(buildRequest, imps, bidderRequest, context) { const req = buildRequest(imps, bidderRequest, context); @@ -88,3 +100,21 @@ function isBannerBid(bid) { function interpretResponse(resp, req) { return converter.fromORTB({ request: req.data, response: resp.body }); } + +function getBidFloor(bid) { + if (utils.isFn(bid.getFloor)) { + let floor = bid.getFloor({ + currency: DEFAULT_CURRENCY, + mediaType: '*', + size: '*', + }); + if ( + utils.isPlainObject(floor) && + !isNaN(floor.floor) && + floor.currency === DEFAULT_CURRENCY + ) { + return floor.floor; + } + } + return null; +} diff --git a/test/spec/modules/adfusionBidAdapter_spec.js b/test/spec/modules/adfusionBidAdapter_spec.js index 638831c33f3..82705b727b4 100644 --- a/test/spec/modules/adfusionBidAdapter_spec.js +++ b/test/spec/modules/adfusionBidAdapter_spec.js @@ -1,6 +1,7 @@ import { expect } from 'chai'; import { spec } from 'modules/adfusionBidAdapter'; import 'modules/priceFloors.js'; +import 'modules/currency.js'; import { newBidder } from 'src/adapters/bidderFactory'; describe('adfusionBidAdapter', function () { @@ -24,7 +25,7 @@ describe('adfusionBidAdapter', function () { transactionId: 'test-transactionId-1', }; - it('should return true when required params found', function () { + it('should return true when required params are found', function () { expect(spec.isBidRequestValid(bid)).to.equal(true); }); @@ -36,7 +37,7 @@ describe('adfusionBidAdapter', function () { }); describe('buildRequests', function () { - let bidRequests, bidderRequest; + let bidRequests, bannerBidRequest, bidderRequest; beforeEach(function () { bidRequests = [ { @@ -75,6 +76,25 @@ describe('adfusionBidAdapter', function () { transactionId: 'test-transactionId-2', }, ]; + bannerBidRequest = { + bidder: 'adfusion', + params: { + accountId: 1234, + }, + mediaTypes: { + banner: { + sizes: [ + [300, 250], + [300, 600], + ], + }, + }, + adUnitCode: '/adunit-code/test-path', + bidId: 'test-bid-id-1', + bidderRequestId: 'test-bid-request-1', + auctionId: 'test-auction-1', + transactionId: 'test-transactionId-1', + }; bidderRequest = { refererInfo: {} }; }); @@ -89,9 +109,22 @@ describe('adfusionBidAdapter', function () { expect(request).to.be.an('array'); expect(request[0].data).to.be.an('object'); expect(request[0].method).to.equal('POST'); + expect(request[0].currency).to.not.equal('USD'); expect(request[0].url).to.not.equal(''); expect(request[0].url).to.not.equal(undefined); expect(request[0].url).to.not.equal(null); }); + + it('should add bid floor', function () { + let bidRequest = Object.assign({}, bannerBidRequest); + let payload = spec.buildRequests([bidRequest], bidderRequest)[0].data; + expect(payload.imp[0].bidfloorcur).to.not.exist; + + let getFloorResponse = { currency: 'USD', floor: 3 }; + bidRequest.getFloor = () => getFloorResponse; + payload = spec.buildRequests([bidRequest], bidderRequest)[0].data; + expect(payload.imp[0].bidfloor).to.equal(3); + expect(payload.imp[0].bidfloorcur).to.equal('USD'); + }); }); });