Skip to content

Commit

Permalink
Fix uncahced video bids from multi-response array triggering callback…
Browse files Browse the repository at this point in the history
… early (#2219)
  • Loading branch information
matthewlane authored and jaiminpanchal27 committed Mar 6, 2018
1 parent 7904c5b commit 768cb62
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/adapters/bidderFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,16 @@ export function newBidder(spec) {
// register any required usersync pixels.
const responses = [];
function afterAllResponses(bids) {
const videoBid = bids && bids[0] && bids[0].mediaType && bids[0].mediaType === 'video';
const bidsArray = bids ? (bids[0] ? bids : [bids]) : [];

const videoBid = bidsArray.some(bid => bid.mediaType === 'video');
const cacheEnabled = config.getConfig('cache.url');

// video bids with cache enabled need to be cached first before they are considered done
if (!(videoBid && cacheEnabled)) {
done();
}

registerSyncs(responses);
}

Expand Down
25 changes: 25 additions & 0 deletions test/spec/auctionmanager_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -801,5 +801,30 @@ describe('auctionmanager.js', function () {
config.getConfig.restore();
store.store.restore();
});

it('runs auction after video responses with multiple bid objects have been cached', () => {
sinon.stub(store, 'store').callsArgWith(1, null, [{ uuid: 123 }]);
sinon.stub(config, 'getConfig').withArgs('cache.url').returns('cache-url');

const bidsCopy = [
Object.assign({}, bids[0], { mediaType: 'video' }),
Object.assign({}, bids[0], { mediaType: 'banner' }),
];
const bids1Copy = [
Object.assign({}, bids1[0], { mediaType: 'video' }),
Object.assign({}, bids1[0], { mediaType: 'video' }),
];

spec.interpretResponse.returns(bidsCopy);
spec1.interpretResponse.returns(bids1Copy);

auction.callBids();

assert.equal(auction.getBidsReceived().length, 4);
assert.equal(auction.getAuctionStatus(), 'completed');

config.getConfig.restore();
store.store.restore();
});
});
});

0 comments on commit 768cb62

Please sign in to comment.