Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debugging module: fix bug where mocked bidders always time out with auctions #12177

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions modules/debugging/debugging.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,13 @@ export function bidderBidInterceptor(next, interceptBids, spec, bids, bidRequest
({bids, bidRequest} = interceptBids({
bids,
bidRequest,
addBid: cbs.onBid,
addPaapiConfig: (config, bidRequest) => cbs.onPaapi({bidId: bidRequest.bidId, ...config}),
addBid: wrapCallback(cbs.onBid),
addPaapiConfig: wrapCallback((config, bidRequest) => cbs.onPaapi({bidId: bidRequest.bidId, ...config})),
done
}));
if (bids.length === 0) {
// eslint-disable-next-line no-unused-expressions
cbs.onResponse?.({}); // trigger onResponse so that the bidder may be marked as "timely" if necessary
done();
} else {
next(spec, bids, bidRequest, ajax, wrapCallback, {...cbs, onCompletion: done});
Expand Down
40 changes: 36 additions & 4 deletions test/spec/modules/debugging_mod_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,31 +354,57 @@ describe('Debugging config', () => {
});

describe('bidderBidInterceptor', () => {
let next, interceptBids, onCompletion, interceptResult, done, addBid;
let next, interceptBids, onCompletion, interceptResult, done, addBid, wrapCallback, addPaapiConfig, wrapped;

function interceptorArgs({spec = {}, bids = [], bidRequest = {}, ajax = {}, wrapCallback = {}, cbs = {}} = {}) {
function interceptorArgs({spec = {}, bids = [], bidRequest = {}, ajax = {}, cbs = {}} = {}) {
return [next, interceptBids, spec, bids, bidRequest, ajax, wrapCallback, Object.assign({onCompletion}, cbs)];
}

beforeEach(() => {
next = sinon.spy();
wrapped = false;
wrapCallback = sinon.stub().callsFake(cb => {
if (cb == null) return cb;
return function () {
wrapped = true;
try {
return cb.apply(this, arguments)
} finally {
wrapped = false;
}
}
});
interceptBids = sinon.stub().callsFake((opts) => {
done = opts.done;
addBid = opts.addBid;
addPaapiConfig = opts.addPaapiConfig;
return interceptResult;
});
onCompletion = sinon.spy();
interceptResult = {bids: [], bidRequest: {}};
});

it('should pass to interceptBid an addBid that triggers onBid', () => {
const onBid = sinon.spy();
const onBid = sinon.stub().callsFake(() => {
expect(wrapped).to.be.true;
});
bidderBidInterceptor(...interceptorArgs({cbs: {onBid}}));
const bid = {};
const bid = {
bidder: 'bidder'
};
addBid(bid);
expect(onBid.calledWith(sinon.match.same(bid))).to.be.true;
});

it('should pass addPaapiConfig that triggers onPaapi', () => {
const onPaapi = sinon.stub().callsFake(() => {
expect(wrapped).to.be.true;
});
bidderBidInterceptor(...interceptorArgs({cbs: {onPaapi}}));
addPaapiConfig({paapi: 'config'}, {bidId: 'bidId'});
sinon.assert.calledWith(onPaapi, {paapi: 'config', bidId: 'bidId'})
})

describe('with no remaining bids', () => {
it('should pass a done callback that triggers onCompletion', () => {
bidderBidInterceptor(...interceptorArgs());
Expand All @@ -387,6 +413,12 @@ describe('bidderBidInterceptor', () => {
expect(onCompletion.calledOnce).to.be.true;
});

it('should call onResponse', () => {
const onResponse = sinon.stub();
bidderBidInterceptor(...interceptorArgs({cbs: {onResponse}}));
sinon.assert.called(onResponse);
})

it('should not call next()', () => {
bidderBidInterceptor(...interceptorArgs());
expect(next.called).to.be.false;
Expand Down