Skip to content

Commit 48d8766

Browse files
AdFusionPrebidŁukaszChrisHuie
authored
AdFusion Bid Adapter : currency support (prebid#10938)
* adfusion bid adapter test * Add adapter and docs * add currency support * kick of integration tests --------- Co-authored-by: Łukasz <[email protected]> Co-authored-by: Chris Huie <[email protected]>
1 parent a8d36a6 commit 48d8766

File tree

2 files changed

+65
-2
lines changed

2 files changed

+65
-2
lines changed

modules/adfusionBidAdapter.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as utils from '../src/utils.js';
55

66
const adpterVersion = '1.0';
77
export const REQUEST_URL = 'https://spicyrtb.com/auction/prebid';
8+
export const DEFAULT_CURRENCY = 'USD';
89

910
export const spec = {
1011
code: 'adfusion',
@@ -23,6 +24,17 @@ const converter = ortbConverter({
2324
context: {
2425
netRevenue: true,
2526
ttl: 300,
27+
currency: DEFAULT_CURRENCY,
28+
},
29+
imp(buildImp, bidRequest, context) {
30+
const imp = buildImp(bidRequest, context);
31+
const floor = getBidFloor(bidRequest);
32+
if (floor) {
33+
imp.bidfloor = floor;
34+
imp.bidfloorcur = DEFAULT_CURRENCY;
35+
}
36+
37+
return imp;
2638
},
2739
request(buildRequest, imps, bidderRequest, context) {
2840
const req = buildRequest(imps, bidderRequest, context);
@@ -88,3 +100,21 @@ function isBannerBid(bid) {
88100
function interpretResponse(resp, req) {
89101
return converter.fromORTB({ request: req.data, response: resp.body });
90102
}
103+
104+
function getBidFloor(bid) {
105+
if (utils.isFn(bid.getFloor)) {
106+
let floor = bid.getFloor({
107+
currency: DEFAULT_CURRENCY,
108+
mediaType: '*',
109+
size: '*',
110+
});
111+
if (
112+
utils.isPlainObject(floor) &&
113+
!isNaN(floor.floor) &&
114+
floor.currency === DEFAULT_CURRENCY
115+
) {
116+
return floor.floor;
117+
}
118+
}
119+
return null;
120+
}

test/spec/modules/adfusionBidAdapter_spec.js

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { expect } from 'chai';
22
import { spec } from 'modules/adfusionBidAdapter';
33
import 'modules/priceFloors.js';
4+
import 'modules/currency.js';
45
import { newBidder } from 'src/adapters/bidderFactory';
56

67
describe('adfusionBidAdapter', function () {
@@ -24,7 +25,7 @@ describe('adfusionBidAdapter', function () {
2425
transactionId: 'test-transactionId-1',
2526
};
2627

27-
it('should return true when required params found', function () {
28+
it('should return true when required params are found', function () {
2829
expect(spec.isBidRequestValid(bid)).to.equal(true);
2930
});
3031

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

3839
describe('buildRequests', function () {
39-
let bidRequests, bidderRequest;
40+
let bidRequests, bannerBidRequest, bidderRequest;
4041
beforeEach(function () {
4142
bidRequests = [
4243
{
@@ -75,6 +76,25 @@ describe('adfusionBidAdapter', function () {
7576
transactionId: 'test-transactionId-2',
7677
},
7778
];
79+
bannerBidRequest = {
80+
bidder: 'adfusion',
81+
params: {
82+
accountId: 1234,
83+
},
84+
mediaTypes: {
85+
banner: {
86+
sizes: [
87+
[300, 250],
88+
[300, 600],
89+
],
90+
},
91+
},
92+
adUnitCode: '/adunit-code/test-path',
93+
bidId: 'test-bid-id-1',
94+
bidderRequestId: 'test-bid-request-1',
95+
auctionId: 'test-auction-1',
96+
transactionId: 'test-transactionId-1',
97+
};
7898
bidderRequest = { refererInfo: {} };
7999
});
80100

@@ -89,9 +109,22 @@ describe('adfusionBidAdapter', function () {
89109
expect(request).to.be.an('array');
90110
expect(request[0].data).to.be.an('object');
91111
expect(request[0].method).to.equal('POST');
112+
expect(request[0].currency).to.not.equal('USD');
92113
expect(request[0].url).to.not.equal('');
93114
expect(request[0].url).to.not.equal(undefined);
94115
expect(request[0].url).to.not.equal(null);
95116
});
117+
118+
it('should add bid floor', function () {
119+
let bidRequest = Object.assign({}, bannerBidRequest);
120+
let payload = spec.buildRequests([bidRequest], bidderRequest)[0].data;
121+
expect(payload.imp[0].bidfloorcur).to.not.exist;
122+
123+
let getFloorResponse = { currency: 'USD', floor: 3 };
124+
bidRequest.getFloor = () => getFloorResponse;
125+
payload = spec.buildRequests([bidRequest], bidderRequest)[0].data;
126+
expect(payload.imp[0].bidfloor).to.equal(3);
127+
expect(payload.imp[0].bidfloorcur).to.equal('USD');
128+
});
96129
});
97130
});

0 commit comments

Comments
 (0)