Skip to content

Commit

Permalink
Getintent adapter: support multisize bids (#2453)
Browse files Browse the repository at this point in the history
* GetIntent adapter - added support for multi size bids

* GetIntent adapter - add test case

* GetIntent adapter - check malformed sizes in bid request
  • Loading branch information
kprokopchik authored and idettman committed Apr 30, 2018
1 parent 12cf662 commit b1f8741
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
27 changes: 21 additions & 6 deletions modules/getintentBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const spec = {
* Callback for bids, after the call to DSP completes.
* Parse the response from the server into a list of bids.
*
* @param {object} serverResponse A response from the server.
* @param {object} serverResponse A response from the GetIntent's server.
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function(serverResponse) {
Expand Down Expand Up @@ -127,16 +127,31 @@ function addOptional(params, request, props) {
}
}

/**
* @param {String} s The string representing a size (e.g. "300x250").
* @return {Number[]} An array with two elements: [width, height] (e.g.: [300, 250]).
* */
function parseSize(s) {
return s.split('x').map(Number);
}

function produceSize(sizes) {
// TODO: add support for multiple sizes
if (Array.isArray(sizes[0])) {
return sizes[0].join('x');
/**
* @param {Array} sizes An array of sizes/numbers to be joined into single string.
* May be an array (e.g. [300, 250]) or array of arrays (e.g. [[300, 250], [640, 480]].
* @return {String} The string with sizes, e.g. array of sizes [[50, 50], [80, 80]] becomes "50x50,80x80" string.
* */
function produceSize (sizes) {
function sizeToStr(s) {
if (Array.isArray(s) && s.length === 2 && Number.isInteger(s[0]) && Number.isInteger(s[1])) {
return s.join('x');
} else {
throw "Malformed parameter 'sizes'";
}
}
if (Array.isArray(sizes) && Array.isArray(sizes[0])) {
return sizes.map(sizeToStr).join(',');
} else {
return sizes.join('x');
return sizeToStr(sizes);
}
}

Expand Down
13 changes: 12 additions & 1 deletion test/spec/modules/getintentBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ describe('GetIntent Adapter Tests:', () => {
tid: 't1000'
},
sizes: [[300, 250]]
}];
},
{
bidId: 'bid54321',
params: {
pid: 'p1000',
tid: 't1000'
},
sizes: [[50, 50], [100, 100]]
}]
const videoBidRequest = {
bidId: 'bid789',
params: {
Expand All @@ -36,6 +44,8 @@ describe('GetIntent Adapter Tests:', () => {
expect(serverRequest.data.tid).to.equal('t1000');
expect(serverRequest.data.size).to.equal('300x250');
expect(serverRequest.data.is_video).to.equal(false);
serverRequest = serverRequests[1];
expect(serverRequest.data.size).to.equal('50x50,100x100');
});

it('Verify build video request', () => {
Expand Down Expand Up @@ -123,6 +133,7 @@ describe('GetIntent Adapter Tests:', () => {

it('Verify if bid request valid', () => {
expect(spec.isBidRequestValid(bidRequests[0])).to.equal(true);
expect(spec.isBidRequestValid(bidRequests[1])).to.equal(true);
expect(spec.isBidRequestValid({})).to.equal(false);
expect(spec.isBidRequestValid({ params: {} })).to.equal(false);
expect(spec.isBidRequestValid({ params: { test: 123 } })).to.equal(false);
Expand Down

0 comments on commit b1f8741

Please sign in to comment.