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

don't calculate TTR if request not found #1575

Merged
merged 1 commit into from
Sep 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 7 additions & 0 deletions src/bidmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ exports.addBidResponse = function (adUnitCode, bid) {
utils.logError(errorMessage('No adUnitCode was supplied to addBidResponse.'));
return false;
}

const bidRequest = getBidderRequest(bid.bidderCode, adUnitCode);
if (!bidRequest.start) {
Copy link
Member

Choose a reason for hiding this comment

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

if you trying to check for no bid request, I think this condition should be just if (!bidRequest) otherwise you'll get an undefined error.

utils.logError(errorMessage('Cannot find valid matching bid request.'));
return false;
}

if (bid.mediaType === 'native' && !nativeBidIsValid(bid)) {
utils.logError(errorMessage('Native bid missing some required properties.'));
return false;
Expand Down
15 changes: 13 additions & 2 deletions test/spec/bidmanager_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ var bidmanager = require('../../src/bidmanager');
var bidfactory = require('../../src/bidfactory');
var fixtures = require('../fixtures/fixtures');

function timestamp() {
return new Date().getTime();
}

describe('replaceTokenInString', function () {
it('should replace all given tokens in a String', function () {
var tokensToReplace = {
Expand Down Expand Up @@ -502,6 +506,7 @@ describe('bidmanager.js', function () {

it('should add banner bids that have no width or height but single adunit size', () => {
sinon.stub(utils, 'getBidderRequest', () => ({
start: timestamp(),
bids: [{
sizes: [[300, 250]],
}]
Expand All @@ -528,6 +533,7 @@ describe('bidmanager.js', function () {

it('should not add native bids that do not have required assets', () => {
sinon.stub(utils, 'getBidRequest', () => ({
start: timestamp(),
bidder: 'appnexusAst',
nativeParams: {
title: {'required': true},
Expand All @@ -552,13 +558,16 @@ describe('bidmanager.js', function () {
});

it('should add native bids that do have required assets', () => {
sinon.stub(utils, 'getBidRequest', () => ({
const bidRequest = () => ({
start: timestamp(),
bidder: 'appnexusAst',
nativeParams: {
title: {'required': true},
},
mediaType: 'native',
}));
});
sinon.stub(utils, 'getBidRequest', bidRequest);
sinon.stub(utils, 'getBidderRequest', bidRequest);

const bid = Object.assign({},
bidfactory.createBid(1),
Expand All @@ -574,10 +583,12 @@ describe('bidmanager.js', function () {
assert.equal(bidsRecCount + 1, $$PREBID_GLOBAL$$._bidsReceived.length);

utils.getBidRequest.restore();
utils.getBidderRequest.restore();
});

it('installs publisher-defined renderers on bids', () => {
sinon.stub(utils, 'getBidderRequest', () => ({
start: timestamp(),
bids: [{
renderer: {
url: 'renderer.js',
Expand Down
1 change: 1 addition & 0 deletions test/spec/modules/trionBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const BID_REQUEST_BASE_URL = 'https://in-appadvertising.com/api/bidRequest?';
const USER_SYNC_URL = 'https://in-appadvertising.com/api/userSync.js';

const TRION_BID_REQUEST = {
start: new Date().getTime(),
bidderCode: 'trion',
bids: [
{
Expand Down
2 changes: 1 addition & 1 deletion test/spec/unit/bidmanager_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ describe('The Bid Manager', () => {
return `${this.height}x${this.width}`;
};
delete copy.cpm;
bidManager.addBidResponse('mock/code', copy);
bidManager.addBidResponse(adUnit.code, copy);
expect(copy).to.have.property('hadCpmDuringBidAdjustment', true);
expect(copy).to.have.property('hadAdUnitCodeDuringBidAdjustment', true);
expect(copy).to.have.property('hadTimeToRespondDuringBidAdjustment', true);
Expand Down