diff --git a/src/auction.js b/src/auction.js index 60892e5d7a2..2befb363e95 100644 --- a/src/auction.js +++ b/src/auction.js @@ -579,8 +579,8 @@ export function addBidToAuction(auctionInstance, bidResponse) { setupBidTargeting(bidResponse); useMetrics(bidResponse.metrics).timeSince('addBidResponse', 'addBidResponse.total'); - events.emit(CONSTANTS.EVENTS.BID_RESPONSE, bidResponse); auctionInstance.addBidReceived(bidResponse); + events.emit(CONSTANTS.EVENTS.BID_RESPONSE, bidResponse); doCallbacksIfTimedout(auctionInstance, bidResponse); } diff --git a/test/spec/auctionmanager_spec.js b/test/spec/auctionmanager_spec.js index 3e5a39e5ee5..5d9dcecb31d 100644 --- a/test/spec/auctionmanager_spec.js +++ b/test/spec/auctionmanager_spec.js @@ -874,6 +874,17 @@ describe('auctionmanager.js', function () { assert.equal(registeredBid.adserverTargeting[CONSTANTS.TARGETING_KEYS.BIDDER], BIDDER_CODE); assert.equal(registeredBid.adserverTargeting.extra, 'stuff'); }); + it('should add the bidResponse to the collection before calling BID_RESPONSE', function () { + let hasBid = false; + const eventHandler = function(bid) { + const storedBid = auction.getBidsReceived().pop(); + hasBid = storedBid === bid; + } + events.on(CONSTANTS.EVENTS.BID_RESPONSE, eventHandler); + auction.callBids(); + events.off(CONSTANTS.EVENTS.BID_RESPONSE, eventHandler); + assert.ok(hasBid, 'Bid not available'); + }); describe('install publisher-defined renderers', () => { Object.entries({