From 535ea0d813e549d0c5fce997e8db9d19b0f8d57b Mon Sep 17 00:00:00 2001 From: Dmitry Fedotov Date: Thu, 18 Oct 2018 12:32:08 +0200 Subject: [PATCH 1/2] Fixes #3197 - call auctionDone() when 'No valid bid requests returned for auction' --- src/auction.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/auction.js b/src/auction.js index 50b681d61a8..61c403e7ff5 100644 --- a/src/auction.js +++ b/src/auction.js @@ -196,6 +196,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, From 83228f7afe309add7cc9aad06b2af80f312e7fc0 Mon Sep 17 00:00:00 2001 From: Dmitry Fedotov Date: Tue, 23 Oct 2018 10:30:57 +0200 Subject: [PATCH 2/2] #3197 Added unit test to check if callback is called when bidRequests is empty --- test/spec/unit/pbjs_api_spec.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test/spec/unit/pbjs_api_spec.js b/test/spec/unit/pbjs_api_spec.js index 61e26891bac..a03339c76b3 100644 --- a/test/spec/unit/pbjs_api_spec.js +++ b/test/spec/unit/pbjs_api_spec.js @@ -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;