Skip to content

Commit

Permalink
add bidResponse before emitting the event BID_RESPONSE, so that the b…
Browse files Browse the repository at this point in the history
…id is stored in the auction instance when the event is triggered (#9847)
  • Loading branch information
olafbuitelaar authored May 22, 2023
1 parent ca5646c commit 9b335cf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/auction.js
Original file line number Diff line number Diff line change
Expand Up @@ -581,8 +581,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);
}
Expand Down
11 changes: 11 additions & 0 deletions test/spec/auctionmanager_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 9b335cf

Please sign in to comment.