Skip to content

Commit

Permalink
core: allow bid adapters to return null fledgeAuctionConfigs
Browse files Browse the repository at this point in the history
  • Loading branch information
dgirardi committed Mar 28, 2024
1 parent f072634 commit b0ce604
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 17 deletions.
18 changes: 12 additions & 6 deletions src/adapters/bidderFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,15 +422,21 @@ export const processBidderRequests = hook('sync', function (spec, bids, bidderRe
return;
}

let bids;
// Extract additional data from a structured {BidderAuctionResponse} response
if (response && isArray(response.fledgeAuctionConfigs)) {
response.fledgeAuctionConfigs.forEach(onPaapi);
bids = response.bids;
// adapters can reply with:
// a single bid
// an array of bids
// an object with {bids: [*], fledgeAuctionConfigs: [*]}

const RESPONSE_PROPS = ['bids', 'fledgeAuctionConfigs'];
let bids, fledgeAuctionConfigs;
if (response && Object.keys(response).every(key => RESPONSE_PROPS.includes(key))) {
[bids, fledgeAuctionConfigs] = RESPONSE_PROPS.map(k => response[k]);
} else {
bids = response;
}

if (isArray(fledgeAuctionConfigs)) {
response.fledgeAuctionConfigs.forEach(onPaapi);
}
if (bids) {
if (isArray(bids)) {
bids.forEach(addBid);
Expand Down
31 changes: 20 additions & 11 deletions test/spec/unit/core/bidderFactory_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1462,6 +1462,26 @@ describe('bidderFactory', () => {
foo: 'bar'
}
}

it('should unwrap bids', function() {
const bidder = newBidder(spec);
spec.interpretResponse.returns({
bids: bids,
});
bidder.callBids(bidRequest, addBidResponseStub, doneStub, ajaxStub, onTimelyResponseStub, wrappedCallback);
sinon.assert.calledWith(addBidResponseStub, 'mock/placement', sinon.match(bids[0]));
});

it('does not unwrap bids from a bid that happens to have a "bids" property', () => {
const bidder = newBidder(spec);
const bid = Object.assign({
bids: ['a', 'b']
}, bids[0]);
spec.interpretResponse.returns(bid);
bidder.callBids(bidRequest, addBidResponseStub, doneStub, ajaxStub, onTimelyResponseStub, wrappedCallback);
sinon.assert.calledWith(addBidResponseStub, 'mock/placement', sinon.match(bid));
})

describe('when response has FLEDGE auction config', function() {
let fledgeStub;

Expand All @@ -1481,17 +1501,6 @@ describe('bidderFactory', () => {
fledgeStub = sinon.stub();
});

it('should unwrap bids', function() {
const bidder = newBidder(spec);
spec.interpretResponse.returns({
bids: bids,
fledgeAuctionConfigs: []
});
bidder.callBids(bidRequest, addBidResponseStub, doneStub, ajaxStub, onTimelyResponseStub, wrappedCallback);
expect(addBidResponseStub.calledOnce).to.equal(true);
expect(addBidResponseStub.firstCall.args[0]).to.equal('mock/placement');
});

it('should call fledgeManager with FLEDGE configs', function() {
const bidder = newBidder(spec);
spec.interpretResponse.returns({
Expand Down

0 comments on commit b0ce604

Please sign in to comment.