Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TL-19850 Finished log error logic around floors functionality #47

Merged
merged 2 commits into from
Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
22 changes: 22 additions & 0 deletions test/spec/modules/tripleliftBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,28 @@ describe('triplelift adapter', function () {
size: '*'
})).to.be.true;
});
it('should not set bid floor if currency is not USD', function() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@patrickloughrey The title is a little misleading from what's being tested.

We hardcode currency and size into how getFloor gets called.
image

So we'll never call getFloor (which is what calledWith is testing) with EUR or CAD. We could add that check though and add it under the existing 'should call getFloor with the correct parameters based on mediaType' test.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider a test like this instead:

it('should catch error if getFloor throws error', function() {
      let logErrorSpy = sinon.spy(utils, 'logError');

      bidRequests[0].getFloor = () => {
        throw new Error('An exception!');
      };

      tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest);

      expect(logErrorSpy.calledOnce).to.equal(true); <-- I've tested up to here and it works
      expect(logErrorSpy.message).to.eql('Triplelift: getFloor threw an error:') <--- This I've not tested but would be a nice to have
    });

Copy link
Author

@patrickloughrey patrickloughrey Apr 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking back at this PR - good catch. I changed the tests to what you suggested. Currently unable to get the second expect statement to occur but working through that.

bidRequests.forEach(request => {
request.getFloor = () => {};
sinon.spy(request, 'getFloor')
});

tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest);

// banner request with non-USD currency
expect(bidRequests[0].getFloor.calledWith({
currency: 'EUR',
mediaType: 'banner',
size: '*'
})).to.be.false;

// banner request with non-USD currency
expect(bidRequests[1].getFloor.calledWith({
currency: 'CAD',
mediaType: 'video',
size: '*'
})).to.be.false;
});
it('should send global config fpd if kvps are available', function() {
const sens = null;
const category = ['news', 'weather', 'hurricane'];
Expand Down