Skip to content

Commit

Permalink
vpmt as array of numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysztofequativ committed Dec 6, 2023
1 parent 2795791 commit dd0e886
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 17 deletions.
12 changes: 5 additions & 7 deletions modules/smartadserverBidAdapter.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 } : {};
},

Expand Down
52 changes: 42 additions & 10 deletions test/spec/modules/smartadserverBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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');
});
});
});

Expand Down Expand Up @@ -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({});
Expand Down

0 comments on commit dd0e886

Please sign in to comment.