From 14d3031d5f754faf556d13b01e2f368bed4ba906 Mon Sep 17 00:00:00 2001 From: Dmitry Fedotov <4129726+drdmitry@users.noreply.github.com> Date: Tue, 23 Oct 2018 15:59:37 +0200 Subject: [PATCH] Fixes #3197 - call auctionDone() when 'No valid bid requests returned for auction' (#3198) * Fixes #3197 - call auctionDone() when 'No valid bid requests returned for auction' * #3197 Added unit test to check if callback is called when bidRequests is empty --- src/auction.js | 1 + test/spec/unit/pbjs_api_spec.js | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) 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, 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;