From 75b8f20c2e3002de7520881403ecba020ee8d571 Mon Sep 17 00:00:00 2001 From: Patrick Loughrey Date: Fri, 29 Apr 2022 13:59:13 -0400 Subject: [PATCH] Triplelift Bid Adapter: Updating Prebid floors logic and unit test coverage (#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 Co-authored-by: nllerandi3lift <75995508+nllerandi3lift@users.noreply.github.com> Co-authored-by: Patrick Loughrey Co-authored-by: Nick Llerandi --- modules/tripleliftBidAdapter.js | 22 +++++++++++-------- .../spec/modules/tripleliftBidAdapter_spec.js | 14 ++++++++++-- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/modules/tripleliftBidAdapter.js b/modules/tripleliftBidAdapter.js index 830d26eda61..7e964661db6 100644 --- a/modules/tripleliftBidAdapter.js +++ b/modules/tripleliftBidAdapter.js @@ -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'; @@ -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; diff --git a/test/spec/modules/tripleliftBidAdapter_spec.js b/test/spec/modules/tripleliftBidAdapter_spec.js index 164188804a3..fc33a7cd676 100644 --- a/test/spec/modules/tripleliftBidAdapter_spec.js +++ b/test/spec/modules/tripleliftBidAdapter_spec.js @@ -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 = { @@ -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 () { @@ -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'];