Skip to content

Commit

Permalink
Prebid Core: emitting BEFORE_BIDDER_HTTP event per bidder network req…
Browse files Browse the repository at this point in the history
…uest (prebid#7296)

* emitting BEFORE_BIDDER_REQUEST event per bidder network request

* kick off circleci tests

* renaming BEFORE_BIDDER_REQUEST to BEFORE_BIDDER_HTTP

Signed-off-by: Elad Yosifon <elad@kueez.com>

* kick off CircleCI tests manually

Co-authored-by: Chris Huie <phoenixtechnerd@gmail.com>
  • Loading branch information
2 people authored and Chris Pabst committed Jan 10, 2022
1 parent ce1349f commit be19ba4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/adapters/bidderFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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_HTTP, bidderRequest));
requests.forEach(processRequest);

function formatGetParameters(data) {
Expand Down Expand Up @@ -277,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);

Expand Down
1 change: 1 addition & 0 deletions src/constants.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"BIDDER_DONE": "bidderDone",
"SET_TARGETING": "setTargeting",
"BEFORE_REQUEST_BIDS": "beforeRequestBids",
"BEFORE_BIDDER_HTTP": "beforeBidderHttp",
"REQUEST_BIDS": "requestBids",
"ADD_AD_UNITS": "addAdUnits",
"AD_RENDER_FAILED": "adRenderFailed",
Expand Down
24 changes: 24 additions & 0 deletions test/spec/unit/core/bidderFactory_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -314,6 +316,28 @@ describe('bidders created by newBidder', function () {

expect(addBidResponseStub.callCount).to.equal(0);
});

it('should emit BEFORE_BIDDER_HTTP 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_HTTP)
).to.length(2);

eventEmitterSpy.restore();
});
});

describe('when the ajax call succeeds', function () {
Expand Down

0 comments on commit be19ba4

Please sign in to comment.