Skip to content

Commit

Permalink
Sovrn: Add Support for Floor Module (#6155)
Browse files Browse the repository at this point in the history
* EX-2549 Pass segments parameter as imp.ext.dealids array

* EX-2549 Address Jon's feedback

* EX-2549 Reworked the solution

* EX-2549 Blackbird compatibility

* EX-2549 Address Jon's comments

* EX-2549 Addressed upstream PR comments

* added floor module support

* added function check

* rerun test

Co-authored-by: Egor Gordeev <egordeev@lineate.com>
Co-authored-by: Egor Gordeev <48566506+egsgordeev@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 14, 2021
1 parent c8665c5 commit 4b6ee78
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 7 deletions.
17 changes: 12 additions & 5 deletions modules/sovrnBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const spec = {
* @return boolean for whether or not a bid is valid
*/
isBidRequestValid: function(bid) {
return !!(bid.params.tagid && !isNaN(parseFloat(bid.params.tagid)) && isFinite(bid.params.tagid));
return !!(bid.params.tagid && !isNaN(parseFloat(bid.params.tagid)) && isFinite(bid.params.tagid))
},

/**
Expand Down Expand Up @@ -45,14 +45,21 @@ export const spec = {
}

if (bid.schain) {
schain = schain || bid.schain;
schain = schain || bid.schain
}
iv = iv || utils.getBidIdParameter('iv', bid.params);
iv = iv || utils.getBidIdParameter('iv', bid.params)

let bidSizes = (bid.mediaTypes && bid.mediaTypes.banner && bid.mediaTypes.banner.sizes) || bid.sizes;
let bidSizes = (bid.mediaTypes && bid.mediaTypes.banner && bid.mediaTypes.banner.sizes) || bid.sizes
bidSizes = ((utils.isArray(bidSizes) && utils.isArray(bidSizes[0])) ? bidSizes : [bidSizes])
bidSizes = bidSizes.filter(size => utils.isArray(size))
const processedSizes = bidSizes.map(size => ({w: parseInt(size[0], 10), h: parseInt(size[1], 10)}))
const floorInfo = (bid.getFloor && typeof bid.getFloor === 'function') ? bid.getFloor({
currency: 'USD',
mediaType: 'banner',
size: '*'
}) : {}
floorInfo.floor = floorInfo.floor || utils.getBidIdParameter('bidfloor', bid.params)

const imp = {
adunitcode: bid.adUnitCode,
id: bid.bidId,
Expand All @@ -62,7 +69,7 @@ export const spec = {
h: 1,
},
tagid: String(utils.getBidIdParameter('tagid', bid.params)),
bidfloor: utils.getBidIdParameter('bidfloor', bid.params)
bidfloor: floorInfo.floor
}

const segmentsString = utils.getBidIdParameter('segments', bid.params)
Expand Down
39 changes: 37 additions & 2 deletions test/spec/modules/sovrnBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,26 @@ import {newBidder} from 'src/adapters/bidderFactory.js';

const ENDPOINT = `https://ap.lijit.com/rtb/bid?src=$$REPO_AND_VERSION$$`;

const adUnitBidRequest = {
'bidder': 'sovrn',
'params': {
'tagid': '403370'
},
'adUnitCode': 'adunit-code',
'sizes': [
[300, 250],
[300, 600]
],
'bidId': '30b31c1838de1e',
'bidderRequestId': '22edbae2733bf6',
'auctionId': '1d1a030790a475',
}

describe('sovrnBidAdapter', function() {
const adapter = newBidder(spec);

describe('isBidRequestValid', function () {
let bid = {
const bid = {
'bidder': 'sovrn',
'params': {
'tagid': '403370'
Expand Down Expand Up @@ -296,12 +311,32 @@ describe('sovrnBidAdapter', function() {
'bidId': '30b31c1838de1e',
'bidderRequestId': '22edbae2733bf6',
'auctionId': '1d1a030790a475'
}];
}]
const request = spec.buildRequests(segmentsRequests, bidderRequest)
const payload = JSON.parse(request.data)
expect(payload.imp[0].ext.deals[0]).to.equal('test1')
expect(payload.imp[0].ext.deals[1]).to.equal('test2')
})
it('should use the floor provided from the floor module if present', function() {
const floorBid = {...adUnitBidRequest, getFloor: () => ({currency: 'USD', floor: 1.10})}
floorBid.params = {
tagid: 1234,
bidfloor: 2.00
}
const request = spec.buildRequests([floorBid], bidderRequest)
const payload = JSON.parse(request.data)
expect(payload.imp[0].bidfloor).to.equal(1.10)
})
it('should use the floor from the param if there is no floor from the floor module', function() {
const floorBid = {...adUnitBidRequest, getFloor: () => ({})}
floorBid.params = {
tagid: 1234,
bidfloor: 2.00
}
const request = spec.buildRequests([floorBid], bidderRequest)
const payload = JSON.parse(request.data)
expect(payload.imp[0].bidfloor).to.equal(2.00)
})
});

describe('interpretResponse', function () {
Expand Down

0 comments on commit 4b6ee78

Please sign in to comment.