From 778167bc7ab21771c5fab654562bab06b34e52f1 Mon Sep 17 00:00:00 2001 From: Elad Yosifon Date: Thu, 12 Aug 2021 18:03:31 +0300 Subject: [PATCH 1/4] emitting BEFORE_BIDDER_REQUEST event per bidder network request --- src/adapters/bidderFactory.js | 1 + src/constants.json | 1 + test/spec/unit/core/bidderFactory_spec.js | 24 +++++++++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/src/adapters/bidderFactory.js b/src/adapters/bidderFactory.js index c71c4ee355b..0800611fa1d 100644 --- a/src/adapters/bidderFactory.js +++ b/src/adapters/bidderFactory.js @@ -230,6 +230,7 @@ export function newBidder(spec) { // Server requests have returned and been processed. Since `ajax` accepts a single callback, // we need to rig up a function which only executes after all the requests have been responded. const onResponse = delayExecution(configEnabledCallback(afterAllResponses), requests.length) + requests.forEach(_ => events.emit(CONSTANTS.EVENTS.BEFORE_BIDDER_REQUEST, bidderRequest)); requests.forEach(processRequest); function formatGetParameters(data) { diff --git a/src/constants.json b/src/constants.json index 77d87e056d9..fc39767dcde 100644 --- a/src/constants.json +++ b/src/constants.json @@ -34,6 +34,7 @@ "BIDDER_DONE": "bidderDone", "SET_TARGETING": "setTargeting", "BEFORE_REQUEST_BIDS": "beforeRequestBids", + "BEFORE_BIDDER_REQUEST": "beforeBidderRequest", "REQUEST_BIDS": "requestBids", "ADD_AD_UNITS": "addAdUnits", "AD_RENDER_FAILED": "adRenderFailed", diff --git a/test/spec/unit/core/bidderFactory_spec.js b/test/spec/unit/core/bidderFactory_spec.js index a7e8a0d7871..9b442fa0e58 100644 --- a/test/spec/unit/core/bidderFactory_spec.js +++ b/test/spec/unit/core/bidderFactory_spec.js @@ -6,6 +6,8 @@ import { userSync } from 'src/userSync.js' import * as utils from 'src/utils.js'; import { config } from 'src/config.js'; import { server } from 'test/mocks/xhr.js'; +import CONSTANTS from 'src/constants.json'; +import events from 'src/events.js'; const CODE = 'sampleBidder'; const MOCK_BIDS_REQUEST = { @@ -314,6 +316,28 @@ describe('bidders created by newBidder', function () { expect(addBidResponseStub.callCount).to.equal(0); }); + + it('should emit BEFORE_BIDDER_REQUEST events before network requests', function () { + const bidder = newBidder(spec); + const req = { + method: 'POST', + url: 'test.url.com', + data: { arg: 2 } + }; + + spec.isBidRequestValid.returns(true); + spec.buildRequests.returns([req, req]); + + const eventEmitterSpy = sinon.spy(events, 'emit'); + bidder.callBids(MOCK_BIDS_REQUEST, addBidResponseStub, doneStub, ajaxStub, onTimelyResponseStub, wrappedCallback); + + expect(ajaxStub.calledTwice).to.equal(true); + expect(eventEmitterSpy.getCalls() + .filter(call => call.args[0] === CONSTANTS.EVENTS.BEFORE_BIDDER_REQUEST) + ).to.length(2); + + eventEmitterSpy.restore(); + }); }); describe('when the ajax call succeeds', function () { From 38d1f3603c08da4832aca5409f168ce9a30dee1f Mon Sep 17 00:00:00 2001 From: Chris Huie Date: Tue, 17 Aug 2021 08:29:30 -0700 Subject: [PATCH 2/4] kick off circleci tests From 1afd290ee5aaa97947d6a45e7f8e9c7b5949a96a Mon Sep 17 00:00:00 2001 From: Elad Yosifon Date: Thu, 26 Aug 2021 11:16:08 +0300 Subject: [PATCH 3/4] renaming BEFORE_BIDDER_REQUEST to BEFORE_BIDDER_HTTP Signed-off-by: Elad Yosifon --- src/adapters/bidderFactory.js | 2 +- src/constants.json | 2 +- test/spec/unit/core/bidderFactory_spec.js | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/adapters/bidderFactory.js b/src/adapters/bidderFactory.js index 0800611fa1d..a9bcebfdafc 100644 --- a/src/adapters/bidderFactory.js +++ b/src/adapters/bidderFactory.js @@ -230,7 +230,7 @@ export function newBidder(spec) { // Server requests have returned and been processed. Since `ajax` accepts a single callback, // we need to rig up a function which only executes after all the requests have been responded. const onResponse = delayExecution(configEnabledCallback(afterAllResponses), requests.length) - requests.forEach(_ => events.emit(CONSTANTS.EVENTS.BEFORE_BIDDER_REQUEST, bidderRequest)); + requests.forEach(_ => events.emit(CONSTANTS.EVENTS.BEFORE_BIDDER_HTTP, bidderRequest)); requests.forEach(processRequest); function formatGetParameters(data) { diff --git a/src/constants.json b/src/constants.json index fc39767dcde..114cedf112b 100644 --- a/src/constants.json +++ b/src/constants.json @@ -34,7 +34,7 @@ "BIDDER_DONE": "bidderDone", "SET_TARGETING": "setTargeting", "BEFORE_REQUEST_BIDS": "beforeRequestBids", - "BEFORE_BIDDER_REQUEST": "beforeBidderRequest", + "BEFORE_BIDDER_HTTP": "beforeBidderHttp", "REQUEST_BIDS": "requestBids", "ADD_AD_UNITS": "addAdUnits", "AD_RENDER_FAILED": "adRenderFailed", diff --git a/test/spec/unit/core/bidderFactory_spec.js b/test/spec/unit/core/bidderFactory_spec.js index 9b442fa0e58..48c17a90398 100644 --- a/test/spec/unit/core/bidderFactory_spec.js +++ b/test/spec/unit/core/bidderFactory_spec.js @@ -317,7 +317,7 @@ describe('bidders created by newBidder', function () { expect(addBidResponseStub.callCount).to.equal(0); }); - it('should emit BEFORE_BIDDER_REQUEST events before network requests', function () { + it('should emit BEFORE_BIDDER_HTTP events before network requests', function () { const bidder = newBidder(spec); const req = { method: 'POST', @@ -333,7 +333,7 @@ describe('bidders created by newBidder', function () { expect(ajaxStub.calledTwice).to.equal(true); expect(eventEmitterSpy.getCalls() - .filter(call => call.args[0] === CONSTANTS.EVENTS.BEFORE_BIDDER_REQUEST) + .filter(call => call.args[0] === CONSTANTS.EVENTS.BEFORE_BIDDER_HTTP) ).to.length(2); eventEmitterSpy.restore(); From baf36afde44048f6fbeca7841f3351b5e4028bf4 Mon Sep 17 00:00:00 2001 From: Chris Huie Date: Fri, 27 Aug 2021 05:31:46 -0700 Subject: [PATCH 4/4] kick off CircleCI tests manually --- src/adapters/bidderFactory.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/adapters/bidderFactory.js b/src/adapters/bidderFactory.js index a9bcebfdafc..fa0ad36e7ff 100644 --- a/src/adapters/bidderFactory.js +++ b/src/adapters/bidderFactory.js @@ -278,8 +278,8 @@ export function newBidder(spec) { } // If the server responds successfully, use the adapter code to unpack the Bids from it. - // If the adapter code fails, no bids should be added. After all the bids have been added, make - // sure to call the `onResponse` function so that we're one step closer to calling done(). + // If the adapter code fails, no bids should be added. After all the bids have been added, + // make sure to call the `onResponse` function so that we're one step closer to calling done(). function onSuccess(response, responseObj) { onTimelyResponse(spec.code);