From 9a69bff155c73a26fbe36ff2f2e9599606abb7bf Mon Sep 17 00:00:00 2001 From: matthieularere-msq Date: Thu, 2 Nov 2023 12:15:43 +0100 Subject: [PATCH 1/3] new event before add bid response --- modules/rtdModule/index.js | 3 ++- src/auction.js | 2 +- src/constants.json | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/rtdModule/index.js b/modules/rtdModule/index.js index 633c4f4cdc1..f68a07067be 100644 --- a/modules/rtdModule/index.js +++ b/modules/rtdModule/index.js @@ -215,7 +215,8 @@ const setEventsListeners = (function () { [CONSTANTS.EVENTS.AUCTION_INIT]: ['onAuctionInitEvent'], [CONSTANTS.EVENTS.AUCTION_END]: ['onAuctionEndEvent', getAdUnitTargeting], [CONSTANTS.EVENTS.BID_RESPONSE]: ['onBidResponseEvent'], - [CONSTANTS.EVENTS.BID_REQUESTED]: ['onBidRequestEvent'] + [CONSTANTS.EVENTS.BID_REQUESTED]: ['onBidRequestEvent'], + [CONSTANTS.EVENTS.BEFORE_ADD_BID_RESPONSE]: ['onBeforeAddBidResponseEvent'] }).forEach(([ev, [handler, preprocess]]) => { events.on(ev, (args) => { preprocess && preprocess(args); diff --git a/src/auction.js b/src/auction.js index df1b2cdef55..69e554d1699 100644 --- a/src/auction.js +++ b/src/auction.js @@ -451,7 +451,7 @@ export function auctionCallbacks(auctionDone, auctionInstance, {index = auctionM function acceptBidResponse(adUnitCode, bid) { handleBidResponse(adUnitCode, bid, (done) => { let bidResponse = getPreparedBidForAuction(bid); - + events.emit(CONSTANTS.EVENTS.BEFORE_ADD_BID_RESPONSE, bidResponse); if (FEATURES.VIDEO && bidResponse.mediaType === VIDEO) { tryAddVideoBid(auctionInstance, bidResponse, done); } else { diff --git a/src/constants.json b/src/constants.json index c763090f6d0..ed3d86a7741 100644 --- a/src/constants.json +++ b/src/constants.json @@ -45,7 +45,8 @@ "AUCTION_DEBUG": "auctionDebug", "BID_VIEWABLE": "bidViewable", "STALE_RENDER": "staleRender", - "BILLABLE_EVENT": "billableEvent" + "BILLABLE_EVENT": "billableEvent", + "BEFORE_ADD_BID_RESPONSE": "beforeAddBidResponse" }, "AD_RENDER_FAILED_REASON": { "PREVENT_WRITING_ON_MAIN_DOCUMENT": "preventWritingOnMainDocument", From 949576904492b4c85f1ee0227a1926df9f8d937e Mon Sep 17 00:00:00 2001 From: matthieularere-msq Date: Tue, 14 Nov 2023 10:55:10 +0100 Subject: [PATCH 2/3] test new event is emit --- test/spec/unit/pbjs_api_spec.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/spec/unit/pbjs_api_spec.js b/test/spec/unit/pbjs_api_spec.js index 664f7ebb58f..9c0c8accf07 100644 --- a/test/spec/unit/pbjs_api_spec.js +++ b/test/spec/unit/pbjs_api_spec.js @@ -2736,6 +2736,13 @@ describe('Unit: Prebid Module', function () { events.on.restore(); }); + it('should emit event EFORE_ADD_BID_RESPONSE when invoked', function () { + var callback = sinon.spy(); + $$PREBID_GLOBAL$$.onEvent('beforeAddBidResponse', callback); + events.emit(CONSTANTS.EVENTS.BEFORE_ADD_BID_RESPONSE); + sinon.assert.calledOnce(callback); + }); + describe('beforeRequestBids', function () { let bidRequestedHandler; let beforeRequestBidsHandler; From 73eaa64b5ef6105269a660a8593b49f4ee1be7f9 Mon Sep 17 00:00:00 2001 From: matthieularere-msq Date: Wed, 22 Nov 2023 17:25:03 +0100 Subject: [PATCH 3/3] change new event name --- modules/rtdModule/index.js | 2 +- src/auction.js | 2 +- src/constants.json | 2 +- test/spec/unit/pbjs_api_spec.js | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/rtdModule/index.js b/modules/rtdModule/index.js index f68a07067be..fb6e65e8a65 100644 --- a/modules/rtdModule/index.js +++ b/modules/rtdModule/index.js @@ -216,7 +216,7 @@ const setEventsListeners = (function () { [CONSTANTS.EVENTS.AUCTION_END]: ['onAuctionEndEvent', getAdUnitTargeting], [CONSTANTS.EVENTS.BID_RESPONSE]: ['onBidResponseEvent'], [CONSTANTS.EVENTS.BID_REQUESTED]: ['onBidRequestEvent'], - [CONSTANTS.EVENTS.BEFORE_ADD_BID_RESPONSE]: ['onBeforeAddBidResponseEvent'] + [CONSTANTS.EVENTS.BID_ACCEPTED]: ['onBidAcceptedEvent'] }).forEach(([ev, [handler, preprocess]]) => { events.on(ev, (args) => { preprocess && preprocess(args); diff --git a/src/auction.js b/src/auction.js index 69e554d1699..25436ea212c 100644 --- a/src/auction.js +++ b/src/auction.js @@ -451,7 +451,7 @@ export function auctionCallbacks(auctionDone, auctionInstance, {index = auctionM function acceptBidResponse(adUnitCode, bid) { handleBidResponse(adUnitCode, bid, (done) => { let bidResponse = getPreparedBidForAuction(bid); - events.emit(CONSTANTS.EVENTS.BEFORE_ADD_BID_RESPONSE, bidResponse); + events.emit(CONSTANTS.EVENTS.BID_ACCEPTED, bidResponse); if (FEATURES.VIDEO && bidResponse.mediaType === VIDEO) { tryAddVideoBid(auctionInstance, bidResponse, done); } else { diff --git a/src/constants.json b/src/constants.json index ed3d86a7741..a17835a95cc 100644 --- a/src/constants.json +++ b/src/constants.json @@ -46,7 +46,7 @@ "BID_VIEWABLE": "bidViewable", "STALE_RENDER": "staleRender", "BILLABLE_EVENT": "billableEvent", - "BEFORE_ADD_BID_RESPONSE": "beforeAddBidResponse" + "BID_ACCEPTED": "bidAccepted" }, "AD_RENDER_FAILED_REASON": { "PREVENT_WRITING_ON_MAIN_DOCUMENT": "preventWritingOnMainDocument", diff --git a/test/spec/unit/pbjs_api_spec.js b/test/spec/unit/pbjs_api_spec.js index 9c0c8accf07..83abad44208 100644 --- a/test/spec/unit/pbjs_api_spec.js +++ b/test/spec/unit/pbjs_api_spec.js @@ -2736,10 +2736,10 @@ describe('Unit: Prebid Module', function () { events.on.restore(); }); - it('should emit event EFORE_ADD_BID_RESPONSE when invoked', function () { + it('should emit event BID_ACCEPTED when invoked', function () { var callback = sinon.spy(); - $$PREBID_GLOBAL$$.onEvent('beforeAddBidResponse', callback); - events.emit(CONSTANTS.EVENTS.BEFORE_ADD_BID_RESPONSE); + $$PREBID_GLOBAL$$.onEvent('bidAccepted', callback); + events.emit(CONSTANTS.EVENTS.BID_ACCEPTED); sinon.assert.calledOnce(callback); });