Skip to content

Commit

Permalink
Pass timedOut as argument to bidsBackHandler function (prebid#2772)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Karson authored and AdSpacesDevelopers committed Jan 30, 2019
1 parent f77cb0e commit fb14768
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/auction.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ export function newAuction({adUnits, adUnitCodes, callback, cbTimeout, labels})
try {
_auctionStatus = AUCTION_COMPLETED;
const adUnitCodes = _adUnitCodes;
const bids = [_bidsReceived
const bids = _bidsReceived
.filter(adUnitsFilter.bind(this, adUnitCodes))
.reduce(groupByPlacement, {})];
_callback.apply($$PREBID_GLOBAL$$, bids);
.reduce(groupByPlacement, {});
_callback.apply($$PREBID_GLOBAL$$, [bids, timedOut]);
} catch (e) {
utils.logError('Error executing bidsBackHandler', null, e);
} finally {
Expand Down
13 changes: 11 additions & 2 deletions test/spec/unit/pbjs_api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,7 @@ describe('Unit: Prebid Module', function () {
let xhr;
let adUnits;
let clock;
let bidsBackHandlerStub = sinon.stub();

const BIDDER_CODE = 'sampleBidder';
let bids = [{
Expand Down Expand Up @@ -1140,7 +1141,12 @@ describe('Unit: Prebid Module', function () {
]
}];
let adUnitCodes = ['adUnit-code'];
let auction = auctionModule.newAuction({adUnits, adUnitCodes, callback: function() {}, cbTimeout: 2000});
let auction = auctionModule.newAuction({
adUnits,
adUnitCodes,
callback: bidsBackHandlerStub,
cbTimeout: 2000
});
let createAuctionStub = sinon.stub(auctionModule, 'newAuction');
createAuctionStub.returns(auction);
});
Expand Down Expand Up @@ -1169,7 +1175,7 @@ describe('Unit: Prebid Module', function () {

clock = sinon.useFakeTimers();
let requestObj = {
bidsBackHandler: function bidsBackHandlerCallback() {},
bidsBackHandler: null, // does not need to be defined because of newAuction mock in beforeEach
timeout: 2000,
adUnits: adUnits
};
Expand All @@ -1181,6 +1187,9 @@ describe('Unit: Prebid Module', function () {

clock.tick(1);
assert.ok(logMessageSpy.calledWith(sinon.match(re)), 'executeCallback called');

expect(bidsBackHandlerStub.getCall(0).args[1]).to.equal(true,
'bidsBackHandler should be called with timedOut=true');
});
})

Expand Down

0 comments on commit fb14768

Please sign in to comment.