Skip to content

Commit 59109b1

Browse files
drdmitryPedro López Jiménez
authored and
Pedro López Jiménez
committed
Fixes prebid#3197 - call auctionDone() when 'No valid bid requests returned 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
1 parent b15ee8b commit 59109b1

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/auction.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ export function newAuction({adUnits, adUnitCodes, callback, cbTimeout, labels})
201201

202202
if (bidRequests.length < 1) {
203203
utils.logWarn('No valid bid requests returned for auction');
204+
auctionDone();
204205
} else {
205206
let call = {
206207
bidRequests,

test/spec/unit/pbjs_api_spec.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,6 +1193,39 @@ describe('Unit: Prebid Module', function () {
11931193
});
11941194
})
11951195

1196+
describe('requestBids', function () {
1197+
let sandbox;
1198+
beforeEach(function () {
1199+
sandbox = sinon.sandbox.create();
1200+
});
1201+
afterEach(function () {
1202+
sandbox.restore();
1203+
});
1204+
describe('bidRequests is empty', function () {
1205+
it('should log warning message and execute callback if bidRequests is empty', function () {
1206+
let bidsBackHandler = function bidsBackHandlerCallback() {};
1207+
let spyExecuteCallback = sinon.spy(bidsBackHandler);
1208+
let logWarnSpy = sandbox.spy(utils, 'logWarn');
1209+
1210+
$$PREBID_GLOBAL$$.requestBids({
1211+
adUnits: [
1212+
{
1213+
code: 'test1',
1214+
bids: [],
1215+
}, {
1216+
code: 'test2',
1217+
bids: [],
1218+
}
1219+
],
1220+
bidsBackHandler: spyExecuteCallback
1221+
});
1222+
1223+
assert.ok(logWarnSpy.calledWith('No valid bid requests returned for auction'), 'expected warning message was logged');
1224+
assert.ok(spyExecuteCallback.calledOnce, 'callback executed when bidRequests is empty');
1225+
});
1226+
});
1227+
});
1228+
11961229
describe('requestBids', function () {
11971230
let xhr;
11981231
let requests;

0 commit comments

Comments
 (0)