From 27957919b0f846b43897cee777244aecb048fd96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Sok=C3=B3=C5=82?= Date: Fri, 1 Dec 2023 14:04:11 +0100 Subject: [PATCH 1/2] Support additional video params --- modules/smartadserverBidAdapter.js | 45 +++++++++-- .../modules/smartadserverBidAdapter_spec.js | 76 ++++++++++++++++++- 2 files changed, 114 insertions(+), 7 deletions(-) diff --git a/modules/smartadserverBidAdapter.js b/modules/smartadserverBidAdapter.js index ca43c26ffd7..afafd9b9ce1 100644 --- a/modules/smartadserverBidAdapter.js +++ b/modules/smartadserverBidAdapter.js @@ -59,16 +59,51 @@ export const spec = { */ fillPayloadForVideoBidRequest: function(payload, videoMediaType, videoParams) { const playerSize = videoMediaType.playerSize[0]; - payload.isVideo = videoMediaType.context === 'instream'; + const map = { + maxbitrate: 'vbrmax', + maxduration: 'vdmax', + minbitrate: 'vbrmin', + minduration: 'vdmin', + placement: 'vpt', + plcmt: 'vplcmt', + skip: 'skip' + }; + payload.mediaType = VIDEO; + payload.isVideo = videoMediaType.context === 'instream'; + payload.videoData = {}; + + for (const [key, value] of Object.entries(map)) { + payload.videoData = { + ...payload.videoData, + ...this.getValuableProperty(value, videoMediaType[key]) + }; + } + payload.videoData = { - videoProtocol: this.getProtocolForVideoBidRequest(videoMediaType, videoParams), - playerWidth: playerSize[0], - playerHeight: playerSize[1], - adBreak: this.getStartDelayForVideoBidRequest(videoMediaType, videoParams) + ...payload.videoData, + ...this.getValuableProperty('playerWidth', playerSize[0]), + ...this.getValuableProperty('playerHeight', playerSize[1]), + ...this.getValuableProperty('adBreak', this.getStartDelayForVideoBidRequest(videoMediaType, videoParams)), + ...this.getValuableProperty('videoProtocol', this.getProtocolForVideoBidRequest(videoMediaType, videoParams)), + ...this.getValuableProperty('iabframeworks', videoMediaType.api && videoMediaType.api.toString()), + ...this.getValuableProperty('vpmt', videoMediaType.playbackmethod && videoMediaType.playbackmethod[0]) }; }, + /** + * Gets a property object if the value not falsy + * @param {string} property + * @param {number | string} value + * @returns object with the property or empty + */ + getValuableProperty: function(property, value) { + const type = typeof value; + + return typeof property === 'string' && (type === 'number' || type === 'string') && value + ? { [property]: value } : {}; + }, + /** * Gets the protocols from either videoParams or VideoMediaType * @param {*} videoMediaType diff --git a/test/spec/modules/smartadserverBidAdapter_spec.js b/test/spec/modules/smartadserverBidAdapter_spec.js index 9daa6a87826..e8cefff7709 100644 --- a/test/spec/modules/smartadserverBidAdapter_spec.js +++ b/test/spec/modules/smartadserverBidAdapter_spec.js @@ -786,7 +786,7 @@ describe('Smart bid adapter tests', function () { expect(request[0]).to.have.property('method').and.to.equal('POST'); const requestContent = JSON.parse(request[0].data); expect(requestContent).to.have.property('videoData'); - expect(requestContent.videoData).to.have.property('videoProtocol').and.to.equal(null); + expect(requestContent.videoData).not.to.have.property('videoProtocol').eq(true); expect(requestContent.videoData).to.have.property('adBreak').and.to.equal(2); }); @@ -833,6 +833,41 @@ describe('Smart bid adapter tests', function () { expect(requestContent.videoData).to.have.property('videoProtocol').and.to.equal(6); expect(requestContent.videoData).to.have.property('adBreak').and.to.equal(3); }); + + it('should pass additional parameters', function () { + const request = spec.buildRequests([{ + bidder: 'smartadserver', + mediaTypes: { + video: { + context: 'instream', + api: [1, 2, 3], + maxbitrate: 20, + minbitrate: 50, + maxduration: 30, + minduration: 5, + placement: 3, + playbackmethod: [2, 4], + playerSize: [[640, 480]], + plcmt: 1, + skip: 0 + } + }, + params: { + siteId: '123' + } + }]); + const requestContent = JSON.parse(request[0].data); + + expect(requestContent.videoData).to.have.property('iabframeworks').and.to.equal('1,2,3'); + expect(requestContent.videoData).not.to.have.property('skip'); + expect(requestContent.videoData).to.have.property('vbrmax').and.to.equal(20); + expect(requestContent.videoData).to.have.property('vbrmin').and.to.equal(50); + expect(requestContent.videoData).to.have.property('vdmax').and.to.equal(30); + expect(requestContent.videoData).to.have.property('vdmin').and.to.equal(5); + expect(requestContent.videoData).to.have.property('vplcmt').and.to.equal(1); + expect(requestContent.videoData).to.have.property('vpmt').and.to.equal(2); + expect(requestContent.videoData).to.have.property('vpt').and.to.equal(3); + }); }); }); @@ -1029,7 +1064,7 @@ describe('Smart bid adapter tests', function () { expect(request[0]).to.have.property('method').and.to.equal('POST'); const requestContent = JSON.parse(request[0].data); expect(requestContent).to.have.property('videoData'); - expect(requestContent.videoData).to.have.property('videoProtocol').and.to.equal(null); + expect(requestContent.videoData).not.to.have.property('videoProtocol').eq(true); expect(requestContent.videoData).to.have.property('adBreak').and.to.equal(2); }); @@ -1393,4 +1428,41 @@ describe('Smart bid adapter tests', function () { expect(requestContent).to.have.property('gpid').and.to.equal(gpid); }); }); + + describe('#getValuableProperty method', function () { + it('should return an object when calling with a string value', () => { + const obj = spec.getValuableProperty('prop', 'str'); + expect(obj).to.deep.equal({ prop: 'str' }); + }); + + it('should return an object when calling with a number value', () => { + const obj = spec.getValuableProperty('prop', 3); + expect(obj).to.deep.equal({ prop: 3 }); + }); + + it('should return an empty object when calling with a number property', () => { + const obj = spec.getValuableProperty(7, 'str'); + expect(obj).to.deep.equal({}); + }); + + it('should return an empty object when calling with a null value', () => { + const obj = spec.getValuableProperty('prop', null); + expect(obj).to.deep.equal({}); + }); + + it('should return an empty object when calling with an object value', () => { + const obj = spec.getValuableProperty('prop', {}); + expect(obj).to.deep.equal({}); + }); + + it('should return an empty object when calling with a 0 value', () => { + const obj = spec.getValuableProperty('prop', 0); + expect(obj).to.deep.equal({}); + }); + + it('should return an empty object when calling without the value argument', () => { + const obj = spec.getValuableProperty('prop'); + expect(obj).to.deep.equal({}); + }); + }); }); From dd0e8863ac77dfb15f31d5aa523d4694a6e6432a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Sok=C3=B3=C5=82?= Date: Wed, 6 Dec 2023 17:36:09 +0100 Subject: [PATCH 2/2] vpmt as array of numbers --- modules/smartadserverBidAdapter.js | 12 ++--- .../modules/smartadserverBidAdapter_spec.js | 52 +++++++++++++++---- 2 files changed, 47 insertions(+), 17 deletions(-) diff --git a/modules/smartadserverBidAdapter.js b/modules/smartadserverBidAdapter.js index afafd9b9ce1..53045cd7fc2 100644 --- a/modules/smartadserverBidAdapter.js +++ b/modules/smartadserverBidAdapter.js @@ -1,4 +1,4 @@ -import { deepAccess, deepClone, logError, isFn, isPlainObject } from '../src/utils.js'; +import { deepAccess, deepClone, isArrayOfNums, isFn, isInteger, isPlainObject, logError } from '../src/utils.js'; import { BANNER, VIDEO } from '../src/mediaTypes.js'; import { config } from '../src/config.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; @@ -86,21 +86,19 @@ export const spec = { ...this.getValuableProperty('playerHeight', playerSize[1]), ...this.getValuableProperty('adBreak', this.getStartDelayForVideoBidRequest(videoMediaType, videoParams)), ...this.getValuableProperty('videoProtocol', this.getProtocolForVideoBidRequest(videoMediaType, videoParams)), - ...this.getValuableProperty('iabframeworks', videoMediaType.api && videoMediaType.api.toString()), - ...this.getValuableProperty('vpmt', videoMediaType.playbackmethod && videoMediaType.playbackmethod[0]) + ...(isArrayOfNums(videoMediaType.api) && videoMediaType.api.length ? { iabframeworks: videoMediaType.api.toString() } : {}), + ...(isArrayOfNums(videoMediaType.playbackmethod) && videoMediaType.playbackmethod.length ? { vpmt: videoMediaType.playbackmethod } : {}) }; }, /** * Gets a property object if the value not falsy * @param {string} property - * @param {number | string} value + * @param {number} value * @returns object with the property or empty */ getValuableProperty: function(property, value) { - const type = typeof value; - - return typeof property === 'string' && (type === 'number' || type === 'string') && value + return typeof property === 'string' && isInteger(value) && value ? { [property]: value } : {}; }, diff --git a/test/spec/modules/smartadserverBidAdapter_spec.js b/test/spec/modules/smartadserverBidAdapter_spec.js index e8cefff7709..58b4cd8c0d0 100644 --- a/test/spec/modules/smartadserverBidAdapter_spec.js +++ b/test/spec/modules/smartadserverBidAdapter_spec.js @@ -841,8 +841,8 @@ describe('Smart bid adapter tests', function () { video: { context: 'instream', api: [1, 2, 3], - maxbitrate: 20, - minbitrate: 50, + maxbitrate: 50, + minbitrate: 20, maxduration: 30, minduration: 5, placement: 3, @@ -860,14 +860,46 @@ describe('Smart bid adapter tests', function () { expect(requestContent.videoData).to.have.property('iabframeworks').and.to.equal('1,2,3'); expect(requestContent.videoData).not.to.have.property('skip'); - expect(requestContent.videoData).to.have.property('vbrmax').and.to.equal(20); - expect(requestContent.videoData).to.have.property('vbrmin').and.to.equal(50); + expect(requestContent.videoData).to.have.property('vbrmax').and.to.equal(50); + expect(requestContent.videoData).to.have.property('vbrmin').and.to.equal(20); expect(requestContent.videoData).to.have.property('vdmax').and.to.equal(30); expect(requestContent.videoData).to.have.property('vdmin').and.to.equal(5); expect(requestContent.videoData).to.have.property('vplcmt').and.to.equal(1); - expect(requestContent.videoData).to.have.property('vpmt').and.to.equal(2); + expect(requestContent.videoData).to.have.property('vpmt').and.to.have.lengthOf(2); + expect(requestContent.videoData.vpmt[0]).to.equal(2); + expect(requestContent.videoData.vpmt[1]).to.equal(4); expect(requestContent.videoData).to.have.property('vpt').and.to.equal(3); }); + + it('should not pass not valuable parameters', function () { + const request = spec.buildRequests([{ + bidder: 'smartadserver', + mediaTypes: { + video: { + context: 'instream', + maxbitrate: 20, + minbitrate: null, + maxduration: 0, + playbackmethod: [], + playerSize: [[640, 480]], + plcmt: 1 + } + }, + params: { + siteId: '123' + } + }]); + const requestContent = JSON.parse(request[0].data); + + expect(requestContent.videoData).not.to.have.property('iabframeworks'); + expect(requestContent.videoData).to.have.property('vbrmax').and.to.equal(20); + expect(requestContent.videoData).not.to.have.property('vbrmin'); + expect(requestContent.videoData).not.to.have.property('vdmax'); + expect(requestContent.videoData).not.to.have.property('vdmin'); + expect(requestContent.videoData).to.have.property('vplcmt').and.to.equal(1); + expect(requestContent.videoData).not.to.have.property('vpmt'); + expect(requestContent.videoData).not.to.have.property('vpt'); + }); }); }); @@ -1430,16 +1462,16 @@ describe('Smart bid adapter tests', function () { }); describe('#getValuableProperty method', function () { - it('should return an object when calling with a string value', () => { - const obj = spec.getValuableProperty('prop', 'str'); - expect(obj).to.deep.equal({ prop: 'str' }); - }); - it('should return an object when calling with a number value', () => { const obj = spec.getValuableProperty('prop', 3); expect(obj).to.deep.equal({ prop: 3 }); }); + it('should return an empty object when calling with a string value', () => { + const obj = spec.getValuableProperty('prop', 'str'); + expect(obj).to.deep.equal({}); + }); + it('should return an empty object when calling with a number property', () => { const obj = spec.getValuableProperty(7, 'str'); expect(obj).to.deep.equal({});