Skip to content

Commit

Permalink
AdFusion Bid Adapter : currency support (#10938)
Browse files Browse the repository at this point in the history
* adfusion bid adapter test

* Add adapter and docs

* add currency support

* kick of integration tests

---------

Co-authored-by: Łukasz <lukasz.kakol@spicymobile.pl>
Co-authored-by: Chris Huie <phoenixtechnerd@gmail.com>
  • Loading branch information
3 people authored Jan 23, 2024
1 parent a8d36a6 commit 48d8766
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
30 changes: 30 additions & 0 deletions modules/adfusionBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
37 changes: 35 additions & 2 deletions test/spec/modules/adfusionBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -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 () {
Expand All @@ -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);
});

Expand All @@ -36,7 +37,7 @@ describe('adfusionBidAdapter', function () {
});

describe('buildRequests', function () {
let bidRequests, bidderRequest;
let bidRequests, bannerBidRequest, bidderRequest;
beforeEach(function () {
bidRequests = [
{
Expand Down Expand Up @@ -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: {} };
});

Expand All @@ -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');
});
});
});

0 comments on commit 48d8766

Please sign in to comment.