Skip to content

Commit

Permalink
OpenXOrtb Bid Adapter: fix multiformat requests (prebid#9790)
Browse files Browse the repository at this point in the history
* OpenXOrtb: fix multiformat requests

* pay attention to feature tags

* refactor & cleanup
  • Loading branch information
dgirardi authored and jorgeluisrocha committed May 18, 2023
1 parent 33a337d commit 1ca00e9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
24 changes: 13 additions & 11 deletions modules/openxOrtbBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ const converter = ortbConverter({
},
imp(buildImp, bidRequest, context) {
const imp = buildImp(bidRequest, context);
if (bidRequest.mediaTypes[VIDEO]?.context === 'outstream') {
imp.video.placement = imp.video.placement || 4;
}
mergeDeep(imp, {
tagid: bidRequest.params.unit,
ext: {
Expand Down Expand Up @@ -132,15 +129,20 @@ const converter = ortbConverter({
}
},
video(orig, imp, bidRequest, context) {
// `orig` is the video imp processor, which looks at bidRequest.mediaTypes[VIDEO]
// to populate imp.video
// alter its input `bidRequest` to also pick up parameters from `bidRequest.params`
let videoParams = bidRequest.mediaTypes[VIDEO];
if (videoParams) {
videoParams = Object.assign({}, videoParams, bidRequest.params.video);
bidRequest = {...bidRequest, mediaTypes: {[VIDEO]: videoParams}}
if (FEATURES.VIDEO) {
// `orig` is the video imp processor, which looks at bidRequest.mediaTypes[VIDEO]
// to populate imp.video
// alter its input `bidRequest` to also pick up parameters from `bidRequest.params`
let videoParams = bidRequest.mediaTypes[VIDEO];
if (videoParams) {
videoParams = Object.assign({}, videoParams, bidRequest.params.video);
bidRequest = {...bidRequest, mediaTypes: {[VIDEO]: videoParams}}
}
orig(imp, bidRequest, context);
if (imp.video && videoParams?.context === 'outstream') {
imp.video.placement = imp.video.placement || 4;
}
}
orig(imp, bidRequest, context);
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions test/spec/modules/openxOrtbBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,18 @@ describe('OpenxRtbAdapter', function () {
});

context('common requests checks', function() {
it('should be able to handle multiformat requests', () => {
const multiformat = utils.deepClone(bidRequestsWithMediaTypes[0]);
multiformat.mediaTypes.video = {
context: 'outstream',
playerSize: [640, 480]
}
const requests = spec.buildRequests([multiformat], mockBidderRequest);
const outgoingFormats = requests.flatMap(rq => rq.data.imp.flatMap(imp => ['banner', 'video'].filter(k => imp[k] != null)));
const expected = FEATURES.VIDEO ? ['banner', 'video'] : ['banner']
expect(outgoingFormats).to.have.members(expected);
})

it('should send bid request to openx url via POST', function () {
const request = spec.buildRequests(bidRequestsWithMediaTypes, mockBidderRequest);
expect(request[0].url).to.equal(REQUEST_URL);
Expand Down

0 comments on commit 1ca00e9

Please sign in to comment.