Skip to content

Commit

Permalink
Triplelift Bid Adapter: Updating Prebid floors logic and unit test co…
Browse files Browse the repository at this point in the history
…verage (#8348)

* TL-19850 Finished log error logic around floors functionality

* deprecates getlegacyFpd

* remove console log

* TL-19850 Changed functionlity of tests

* restore logErrorSpy aftereach

Co-authored-by: Dan Goldin <dgoldin@triplelift.com>
Co-authored-by: nllerandi3lift <75995508+nllerandi3lift@users.noreply.github.com>
Co-authored-by: Patrick Loughrey <patrickloughrey@patrickhreysmbp.mynetworksettings.com>
Co-authored-by: Nick Llerandi <nllerandi@triplelift.com>
  • Loading branch information
5 people authored Apr 29, 2022
1 parent 0095646 commit 75b8f20
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
22 changes: 13 additions & 9 deletions modules/tripleliftBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { tryAppendQueryString, logMessage, isEmpty, isStr, isPlainObject, isArray, logWarn } from '../src/utils.js';
import { tryAppendQueryString, logMessage, logError, isEmpty, isStr, isPlainObject, isArray, logWarn } from '../src/utils.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { config } from '../src/config.js';
Expand Down Expand Up @@ -175,14 +175,18 @@ function _getORTBVideo(bidRequest) {
function _getFloor (bid) {
let floor = null;
if (typeof bid.getFloor === 'function') {
const floorInfo = bid.getFloor({
currency: 'USD',
mediaType: _isInstreamBidRequest(bid) ? 'video' : 'banner',
size: '*'
});
if (typeof floorInfo === 'object' &&
floorInfo.currency === 'USD' && !isNaN(parseFloat(floorInfo.floor))) {
floor = parseFloat(floorInfo.floor);
try {
const floorInfo = bid.getFloor({
currency: 'USD',
mediaType: _isInstreamBidRequest(bid) ? 'video' : 'banner',
size: '*'
});
if (typeof floorInfo === 'object' &&
floorInfo.currency === 'USD' && !isNaN(parseFloat(floorInfo.floor))) {
floor = parseFloat(floorInfo.floor);
}
} catch (err) {
logError('Triplelift: getFloor threw an error: ', err);
}
}
return floor !== null ? floor : bid.params.floor;
Expand Down
14 changes: 12 additions & 2 deletions test/spec/modules/tripleliftBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ const GDPR_CONSENT_STR = 'BOONm0NOONm0NABABAENAa-AAAARh7______b9_3__7_9uz_Kv_K7V

describe('triplelift adapter', function () {
const adapter = newBidder(tripleliftAdapterSpec);
let bid, instreamBid;
let sandbox;
let bid, instreamBid, sandbox, logErrorSpy;

this.beforeEach(() => {
bid = {
Expand Down Expand Up @@ -379,9 +378,11 @@ describe('triplelift adapter', function () {
},
};
sandbox = sinon.sandbox.create();
logErrorSpy = sinon.spy(utils, 'logError');
});
afterEach(() => {
sandbox.restore();
utils.logError.restore();
});

it('exists and is an object', function () {
Expand Down Expand Up @@ -787,6 +788,15 @@ describe('triplelift adapter', function () {
size: '*'
})).to.be.true;
});
it('should catch error if getFloor throws error', function() {
bidRequests[0].getFloor = () => {
throw new Error('An exception!');
};

tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest);

expect(logErrorSpy.calledOnce).to.equal(true);
});
it('should send global config fpd if kvps are available', function() {
const sens = null;
const category = ['news', 'weather', 'hurricane'];
Expand Down

0 comments on commit 75b8f20

Please sign in to comment.