Skip to content

Commit

Permalink
[Synacormedia] Fix bug with regex regarding ad size (#5561)
Browse files Browse the repository at this point in the history
* CAP-1614 - updated docs to show correct size for banner and some other small fixes

* CAP-1636 support schain object in prebid

* CAP-1636 updated the review comments

* CAP-1849 - split up banner and video impressions to use format

* CAP-1879 - added adapter support for consent management module

* CAP-1879 - updates for pr

* CAP-1879 - remove unneeded checks

* CAP-1920 - fixed size bug

* CAP-1920 - update tests and banner

* CAP-1920 - fix a comparison, and height setting

Co-authored-by: Corey Kress <[email protected]>
Co-authored-by: Rajkumar Natarajan <[email protected]>
  • Loading branch information
3 people authored Aug 4, 2020
1 parent d048f27 commit 22f0974
Show file tree
Hide file tree
Showing 2 changed files with 209 additions and 16 deletions.
31 changes: 28 additions & 3 deletions modules/synacormediaBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export const spec = {
.filter(param => includes(VIDEO_PARAMS, param) && sourceObj[param] !== null && (!isNaN(parseInt(sourceObj[param], 10)) || !(sourceObj[param].length < 1)))
.forEach(param => destObj[param] = Array.isArray(sourceObj[param]) ? sourceObj[param] : parseInt(sourceObj[param], 10));
},
interpretResponse: function(serverResponse) {
interpretResponse: function(serverResponse, bidRequest) {
const updateMacros = (bid, r) => {
return r ? r.replace(/\${AUCTION_PRICE}/g, bid.price) : r;
};
Expand All @@ -189,8 +189,33 @@ export const spec = {
seatbid.bid.forEach(bid => {
const creative = updateMacros(bid, bid.adm);
const nurl = updateMacros(bid, bid.nurl);
const [, impType, impid, width, height] = bid.impid.match(/^([vb])(.*)-(.*)x(.*)$/);
const isVideo = impType == 'v';
const [, impType, impid] = bid.impid.match(/^([vb])(.*)$/);
let height = bid.h;
let width = bid.w;
const isVideo = impType === 'v';
const isBanner = impType === 'b';
if ((!height || !width) && bidRequest.data && bidRequest.data.imp && bidRequest.data.imp.length > 0) {
bidRequest.data.imp.forEach(req => {
if (bid.impid === req.id) {
if (isVideo) {
height = req.video.h;
width = req.video.w;
} else if (isBanner) {
let bannerHeight = 1;
let bannerWidth = 1;
if (req.banner.format && req.banner.format.length > 0) {
bannerHeight = req.banner.format[0].h;
bannerWidth = req.banner.format[0].w;
}
height = bannerHeight;
width = bannerWidth;
} else {
height = 1;
width = 1;
}
}
});
}
const bidObj = {
requestId: impid,
adId: bid.id.replace(/~/g, '-'),
Expand Down
194 changes: 181 additions & 13 deletions test/spec/modules/synacormediaBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -688,21 +688,50 @@ describe('synacormediaBidAdapter ', function () {
describe('interpretResponse', function () {
let bidResponse = {
id: '10865933907263896~9998~0',
impid: 'b9876abcd-300x250',
impid: 'b9876abcd',
price: 0.13,
crid: '1022-250',
adm: '<script src=\"//uat-net.technoratimedia.com/openrtb/tags?ID=k5JkFVQ1RJT05fSU1QX0lEPXYyZjczN&AUCTION_PRICE=${AUCTION_PRICE}\"></script>',
nurl: 'https://uat-net.technoratimedia.com/openrtb/tags?ID=k5JkFVQ1RJT05fSU1QX0lEPXYyZjczN&AUCTION_PRICE=${AUCTION_PRICE}'
nurl: 'https://uat-net.technoratimedia.com/openrtb/tags?ID=k5JkFVQ1RJT05fSU1QX0lEPXYyZjczN&AUCTION_PRICE=${AUCTION_PRICE}',
w: 300,
h: 250
};
let bidResponse2 = {
id: '10865933907263800~9999~0',
impid: 'b9876abcd-300x600',
impid: 'b9876abcd',
price: 1.99,
crid: '9993-013',
adm: '<script src=\"//uat-net.technoratimedia.com/openrtb/tags?ID=OTk5OX4wJkFVQ1RJT05fU0VBVF9JR&AUCTION_PRICE=${AUCTION_PRICE}\"></script>',
nurl: 'https://uat-net.technoratimedia.com/openrtb/tags?ID=OTk5OX4wJkFVQ1RJT05fU0VBVF9JR&AUCTION_PRICE=${AUCTION_PRICE}'
nurl: 'https://uat-net.technoratimedia.com/openrtb/tags?ID=OTk5OX4wJkFVQ1RJT05fU0VBVF9JR&AUCTION_PRICE=${AUCTION_PRICE}',
w: 300,
h: 600
};

let bidRequest = {
data: {
id: '',
imp: [
{
id: 'abc123',
banner: {
format: [
{
w: 400,
h: 350
}
],
pos: 1
}
}
],
},
method: 'POST',
options: {
contentType: 'application/json',
withCredentials: true
},
url: 'https://prebid.technoratimedia.com/openrtb/bids/prebid?src=prebid_prebid_3.27.0-pre'
};
let serverResponse;
beforeEach(function() {
serverResponse = {
Expand All @@ -717,6 +746,26 @@ describe('synacormediaBidAdapter ', function () {
});

it('should return 1 video bid when 1 bid is in the video response', function () {
bidRequest = {
data: {
id: 'abcd1234',
imp: [
{
video: {
w: 640,
h: 480
},
id: 'v2da7322b2df61f'
}
]
},
method: 'POST',
options: {
contentType: 'application/json',
withCredentials: true
},
url: 'https://prebid.technoratimedia.com/openrtb/bids/prebid?src=prebid_prebid_3.27.0-pre'
};
let serverRespVideo = {
body: {
id: 'abcd1234',
Expand All @@ -725,14 +774,16 @@ describe('synacormediaBidAdapter ', function () {
bid: [
{
id: '11339128001692337~9999~0',
impid: 'v2da7322b2df61f-640x480',
impid: 'v2da7322b2df61f',
price: 0.45,
nurl: 'https://uat-net.technoratimedia.com/openrtb/tags?ID=QVVDVElPTl9JRD1lOTBhYWU1My1hZDkwLTRkNDEtYTQxMC1lZDY1MjIxMDc0ZGMmQVVDVElPTl9CSURfSUQ9MTEzMzkxMjgwMDE2OTIzMzd-OTk5OX4wJkFVQ1RJT05fU0VBVF9JRD05OTk5JkFVQ1RJT05fSU1QX0lEPXYyZGE3MzIyYjJkZjYxZi02NDB4NDgwJkFDVE9SX1JFRj1ha2thLnRjcDovL2F3cy1lYXN0MUBhZHMxMy5jYXAtdXNlMS5zeW5hY29yLmNvbToyNTUxL3VzZXIvJGNMYmZiIy0xOTk4NTIzNTk3JlNFQVRfSUQ9cHJlYmlk&AUCTION_PRICE=${AUCTION_PRICE}',
adm: '<?xml version="1.0" encoding="UTF-8"?>\n<VAST version="3.0">\n<Ad id="11339128001692337~9999~0">\n<Wrapper>\n<AdSystem>Synacor Media Ad Server - 9999</AdSystem>\n<VASTAdTagURI>https://uat-net.technoratimedia.com/openrtb/tags?ID=QVVDVElPTl9JRD1lOTBhYWU1My1hZDkwLTRkNDEtYTQxMC1lZDY1MjIxMDc0ZGMmQVVDVElPTl9CSURfSUQ9MTEzMzkxMjgwMDE2OTIzMzd-OTk5OX4wJkFVQ1RJT05fU0VBVF9JRD05OTk5JkFVQ1RJT05fSU1QX0lEPXYyZGE3MzIyYjJkZjYxZi02NDB4NDgwJkFDVE9SX1JFRj1ha2thLnRjcDovL2F3cy1lYXN0MUBhZHMxMy5jYXAtdXNlMS5zeW5hY29yLmNvbToyNTUxL3VzZXIvJGNMYmZiIy0xOTk4NTIzNTk3JlNFQVRfSUQ9cHJlYmlk&AUCTION_PRICE=${AUCTION_PRICE}</VASTAdTagURI>\n</Wrapper>\n</Ad>\n</VAST>',
adomain: [ 'psacentral.org' ],
cid: 'bidder-crid',
crid: 'bidder-cid',
cat: []
cat: [],
w: 640,
h: 480
}
],
seat: '9999'
Expand All @@ -742,7 +793,7 @@ describe('synacormediaBidAdapter ', function () {
};

// serverResponse.body.seatbid[0].bid.push(bidResponse);
let resp = spec.interpretResponse(serverRespVideo);
let resp = spec.interpretResponse(serverRespVideo, bidRequest);
expect(resp).to.be.an('array').to.have.lengthOf(1);
expect(resp[0]).to.eql({
requestId: '2da7322b2df61f',
Expand All @@ -763,7 +814,7 @@ describe('synacormediaBidAdapter ', function () {

it('should return 1 bid when 1 bid is in the response', function () {
serverResponse.body.seatbid[0].bid.push(bidResponse);
let resp = spec.interpretResponse(serverResponse);
let resp = spec.interpretResponse(serverResponse, bidRequest);
expect(resp).to.be.an('array').to.have.lengthOf(1);
expect(resp[0]).to.eql({
requestId: '9876abcd',
Expand All @@ -786,7 +837,7 @@ describe('synacormediaBidAdapter ', function () {
seat: '9999',
bid: [bidResponse2],
});
let resp = spec.interpretResponse(serverResponse);
let resp = spec.interpretResponse(serverResponse, bidRequest);
expect(resp).to.be.an('array').to.have.lengthOf(2);
expect(resp[0]).to.eql({
requestId: '9876abcd',
Expand Down Expand Up @@ -818,7 +869,7 @@ describe('synacormediaBidAdapter ', function () {
});

it('should not return a bid when no bid is in the response', function () {
let resp = spec.interpretResponse(serverResponse);
let resp = spec.interpretResponse(serverResponse, bidRequest);
expect(resp).to.be.an('array').that.is.empty;
});

Expand All @@ -837,14 +888,16 @@ describe('synacormediaBidAdapter ', function () {
bid: [
{
id: '11339128001692337~9999~0',
impid: 'v2da7322b2df61f-640x480',
impid: 'v2da7322b2df61f',
price: 0.45,
nurl: 'https://uat-net.technoratimedia.com/openrtb/tags?ID=QVVDVElPTl9JRD1lOTBhYWU1My1hZDkwLTRkNDEtYTQxMC1lZDY1MjIxMDc0ZGMmQVVDVElPTl9CSURfSUQ9MTEzMzkxMjgwMDE2OTIzMzd-OTk5OX4wJkFVQ1RJT05fU0VBVF9JRD05OTk5JkFVQ1RJT05fSU1QX0lEPXYyZGE3MzIyYjJkZjYxZi02NDB4NDgwJkFDVE9SX1JFRj1ha2thLnRjcDovL2F3cy1lYXN0MUBhZHMxMy5jYXAtdXNlMS5zeW5hY29yLmNvbToyNTUxL3VzZXIvJGNMYmZiIy0xOTk4NTIzNTk3JlNFQVRfSUQ9cHJlYmlk&AUCTION_PRICE=${AUCTION_PRICE}',
adm: '<?xml version="1.0" encoding="UTF-8"?>\n<VAST version="3.0">\n<Ad id="11339128001692337~9999~0">\n<Wrapper>\n<AdSystem>Synacor Media Ad Server - 9999</AdSystem>\n<VASTAdTagURI>https://uat-net.technoratimedia.com/openrtb/tags?ID=QVVDVElPTl9JRD1lOTBhYWU1My1hZDkwLTRkNDEtYTQxMC1lZDY1MjIxMDc0ZGMmQVVDVElPTl9CSURfSUQ9MTEzMzkxMjgwMDE2OTIzMzd-OTk5OX4wJkFVQ1RJT05fU0VBVF9JRD05OTk5JkFVQ1RJT05fSU1QX0lEPXYyZGE3MzIyYjJkZjYxZi02NDB4NDgwJkFDVE9SX1JFRj1ha2thLnRjcDovL2F3cy1lYXN0MUBhZHMxMy5jYXAtdXNlMS5zeW5hY29yLmNvbToyNTUxL3VzZXIvJGNMYmZiIy0xOTk4NTIzNTk3JlNFQVRfSUQ9cHJlYmlk&AUCTION_PRICE=${AUCTION_PRICE}</VASTAdTagURI>\n</Wrapper>\n</Ad>\n</VAST>',
adomain: [ 'psacentral.org' ],
cid: 'bidder-crid',
crid: 'bidder-cid',
cat: []
cat: [],
w: 640,
h: 480
}
],
seat: '9999'
Expand All @@ -860,10 +913,125 @@ describe('synacormediaBidAdapter ', function () {
return config[key];
});

let resp = spec.interpretResponse(serverRespVideo);
let resp = spec.interpretResponse(serverRespVideo, bidRequest);
sandbox.restore();
expect(resp[0].videoCacheKey).to.not.exist;
});

it('should use video bid request height and width if not present in response', function () {
bidRequest = {
data: {
id: 'abcd1234',
imp: [
{
video: {
w: 300,
h: 250
},
id: 'v2da7322b2df61f'
}
]
},
method: 'POST',
options: {
contentType: 'application/json',
withCredentials: true
},
url: 'https://prebid.technoratimedia.com/openrtb/bids/prebid?src=prebid_prebid_3.27.0-pre'
};

let serverRespVideo = {
body: {
id: 'abcd1234',
seatbid: [
{
bid: [
{
id: '11339128001692337~9999~0',
impid: 'v2da7322b2df61f',
price: 0.45,
nurl: 'https://uat-net.technoratimedia.com/openrtb/tags?ID=QVVDVElPTl9JRD1lOTBhYWU1My1hZDkwLTRkNDEtYTQxMC1lZDY1MjIxMDc0ZGMmQVVDVElPTl9CSURfSUQ9MTEzMzkxMjgwMDE2OTIzMzd-OTk5OX4wJkFVQ1RJT05fU0VBVF9JRD05OTk5JkFVQ1RJT05fSU1QX0lEPXYyZGE3MzIyYjJkZjYxZi02NDB4NDgwJkFDVE9SX1JFRj1ha2thLnRjcDovL2F3cy1lYXN0MUBhZHMxMy5jYXAtdXNlMS5zeW5hY29yLmNvbToyNTUxL3VzZXIvJGNMYmZiIy0xOTk4NTIzNTk3JlNFQVRfSUQ9cHJlYmlk&AUCTION_PRICE=${AUCTION_PRICE}',
adm: '<?xml version="1.0" encoding="UTF-8"?>\n<VAST version="3.0">\n<Ad id="11339128001692337~9999~0">\n<Wrapper>\n<AdSystem>Synacor Media Ad Server - 9999</AdSystem>\n<VASTAdTagURI>https://uat-net.technoratimedia.com/openrtb/tags?ID=QVVDVElPTl9JRD1lOTBhYWU1My1hZDkwLTRkNDEtYTQxMC1lZDY1MjIxMDc0ZGMmQVVDVElPTl9CSURfSUQ9MTEzMzkxMjgwMDE2OTIzMzd-OTk5OX4wJkFVQ1RJT05fU0VBVF9JRD05OTk5JkFVQ1RJT05fSU1QX0lEPXYyZGE3MzIyYjJkZjYxZi02NDB4NDgwJkFDVE9SX1JFRj1ha2thLnRjcDovL2F3cy1lYXN0MUBhZHMxMy5jYXAtdXNlMS5zeW5hY29yLmNvbToyNTUxL3VzZXIvJGNMYmZiIy0xOTk4NTIzNTk3JlNFQVRfSUQ9cHJlYmlk&AUCTION_PRICE=${AUCTION_PRICE}</VASTAdTagURI>\n</Wrapper>\n</Ad>\n</VAST>',
adomain: [ 'psacentral.org' ],
cid: 'bidder-crid',
crid: 'bidder-cid',
cat: []
}
],
seat: '9999'
}
]
}
};
let resp = spec.interpretResponse(serverRespVideo, bidRequest);
expect(resp).to.be.an('array').to.have.lengthOf(1);
expect(resp[0]).to.eql({
requestId: '2da7322b2df61f',
adId: '11339128001692337-9999-0',
cpm: 0.45,
width: 300,
height: 250,
creativeId: '9999_bidder-cid',
currency: 'USD',
netRevenue: true,
mediaType: 'video',
ad: '<?xml version="1.0" encoding="UTF-8"?>\n<VAST version="3.0">\n<Ad id="11339128001692337~9999~0">\n<Wrapper>\n<AdSystem>Synacor Media Ad Server - 9999</AdSystem>\n<VASTAdTagURI>https://uat-net.technoratimedia.com/openrtb/tags?ID=QVVDVElPTl9JRD1lOTBhYWU1My1hZDkwLTRkNDEtYTQxMC1lZDY1MjIxMDc0ZGMmQVVDVElPTl9CSURfSUQ9MTEzMzkxMjgwMDE2OTIzMzd-OTk5OX4wJkFVQ1RJT05fU0VBVF9JRD05OTk5JkFVQ1RJT05fSU1QX0lEPXYyZGE3MzIyYjJkZjYxZi02NDB4NDgwJkFDVE9SX1JFRj1ha2thLnRjcDovL2F3cy1lYXN0MUBhZHMxMy5jYXAtdXNlMS5zeW5hY29yLmNvbToyNTUxL3VzZXIvJGNMYmZiIy0xOTk4NTIzNTk3JlNFQVRfSUQ9cHJlYmlk&AUCTION_PRICE=0.45</VASTAdTagURI>\n</Wrapper>\n</Ad>\n</VAST>',
ttl: 60,
videoCacheKey: 'QVVDVElPTl9JRD1lOTBhYWU1My1hZDkwLTRkNDEtYTQxMC1lZDY1MjIxMDc0ZGMmQVVDVElPTl9CSURfSUQ9MTEzMzkxMjgwMDE2OTIzMzd-OTk5OX4wJkFVQ1RJT05fU0VBVF9JRD05OTk5JkFVQ1RJT05fSU1QX0lEPXYyZGE3MzIyYjJkZjYxZi02NDB4NDgwJkFDVE9SX1JFRj1ha2thLnRjcDovL2F3cy1lYXN0MUBhZHMxMy5jYXAtdXNlMS5zeW5hY29yLmNvbToyNTUxL3VzZXIvJGNMYmZiIy0xOTk4NTIzNTk3JlNFQVRfSUQ9cHJlYmlk',
vastUrl: 'https://uat-net.technoratimedia.com/openrtb/tags?ID=QVVDVElPTl9JRD1lOTBhYWU1My1hZDkwLTRkNDEtYTQxMC1lZDY1MjIxMDc0ZGMmQVVDVElPTl9CSURfSUQ9MTEzMzkxMjgwMDE2OTIzMzd-OTk5OX4wJkFVQ1RJT05fU0VBVF9JRD05OTk5JkFVQ1RJT05fSU1QX0lEPXYyZGE3MzIyYjJkZjYxZi02NDB4NDgwJkFDVE9SX1JFRj1ha2thLnRjcDovL2F3cy1lYXN0MUBhZHMxMy5jYXAtdXNlMS5zeW5hY29yLmNvbToyNTUxL3VzZXIvJGNMYmZiIy0xOTk4NTIzNTk3JlNFQVRfSUQ9cHJlYmlk&AUCTION_PRICE=0.45'
});
});

it('should use banner bid request height and width if not present in response', function () {
bidRequest = {
data: {
id: 'abc123',
imp: [
{
banner: {
format: [{
w: 400,
h: 350
}]
},
id: 'babc123'
}
]
},
method: 'POST',
options: {
contentType: 'application/json',
withCredentials: true
},
url: 'https://prebid.technoratimedia.com/openrtb/bids/prebid?src=prebid_prebid_3.27.0-pre'
};

bidResponse = {
id: '10865933907263896~9998~0',
impid: 'babc123',
price: 0.13,
crid: '1022-250',
adm: '<script src=\"//uat-net.technoratimedia.com/openrtb/tags?ID=k5JkFVQ1RJT05fSU1QX0lEPXYyZjczN&AUCTION_PRICE=${AUCTION_PRICE}\"></script>',
nurl: 'https://uat-net.technoratimedia.com/openrtb/tags?ID=k5JkFVQ1RJT05fSU1QX0lEPXYyZjczN&AUCTION_PRICE=${AUCTION_PRICE}',
};

serverResponse.body.seatbid[0].bid.push(bidResponse);
let resp = spec.interpretResponse(serverResponse, bidRequest);
expect(resp).to.be.an('array').to.have.lengthOf(1);
expect(resp[0]).to.eql({
requestId: 'abc123',
adId: '10865933907263896-9998-0',
cpm: 0.13,
width: 400,
height: 350,
creativeId: '9998_1022-250',
currency: 'USD',
netRevenue: true,
mediaType: BANNER,
ad: '<script src=\"//uat-net.technoratimedia.com/openrtb/tags?ID=k5JkFVQ1RJT05fSU1QX0lEPXYyZjczN&AUCTION_PRICE=0.13\"></script>',
ttl: 60
});
});
});
describe('getUserSyncs', function () {
it('should return a usersync when iframes is enabled', function () {
Expand Down

0 comments on commit 22f0974

Please sign in to comment.