Skip to content

Commit

Permalink
Fixes prebid#3197 - call auctionDone() when 'No valid bid requests re…
Browse files Browse the repository at this point in the history
…turned for auction' (prebid#3198)

* Fixes prebid#3197 - call auctionDone() when 'No valid bid requests returned for auction'

* prebid#3197 Added unit test to check if callback is called when bidRequests is empty
  • Loading branch information
drdmitry authored and Pedro López Jiménez committed Mar 18, 2019
1 parent b15ee8b commit 59109b1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/auction.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ export function newAuction({adUnits, adUnitCodes, callback, cbTimeout, labels})

if (bidRequests.length < 1) {
utils.logWarn('No valid bid requests returned for auction');
auctionDone();
} else {
let call = {
bidRequests,
Expand Down
33 changes: 33 additions & 0 deletions test/spec/unit/pbjs_api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1193,6 +1193,39 @@ describe('Unit: Prebid Module', function () {
});
})

describe('requestBids', function () {
let sandbox;
beforeEach(function () {
sandbox = sinon.sandbox.create();
});
afterEach(function () {
sandbox.restore();
});
describe('bidRequests is empty', function () {
it('should log warning message and execute callback if bidRequests is empty', function () {
let bidsBackHandler = function bidsBackHandlerCallback() {};
let spyExecuteCallback = sinon.spy(bidsBackHandler);
let logWarnSpy = sandbox.spy(utils, 'logWarn');

$$PREBID_GLOBAL$$.requestBids({
adUnits: [
{
code: 'test1',
bids: [],
}, {
code: 'test2',
bids: [],
}
],
bidsBackHandler: spyExecuteCallback
});

assert.ok(logWarnSpy.calledWith('No valid bid requests returned for auction'), 'expected warning message was logged');
assert.ok(spyExecuteCallback.calledOnce, 'callback executed when bidRequests is empty');
});
});
});

describe('requestBids', function () {
let xhr;
let requests;
Expand Down

0 comments on commit 59109b1

Please sign in to comment.