Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Synacormedia] Fix bug with regex regarding ad size #5561

Merged
merged 23 commits into from
Aug 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
25c5ad3
CAP-1614 - updated docs to show correct size for banner and some othe…
Feb 5, 2020
b6dfbc9
CAP-1636 support schain object in prebid
Feb 6, 2020
f430418
Merge pull request #15 in SA/prebid from CAP-1614 to master
Feb 7, 2020
d6932f3
Merge pull request #14 in SA/prebid from CAP-1636 to master
Feb 7, 2020
9359953
Merge branch 'master' of https://github.com/prebid/Prebid.js
Feb 13, 2020
c934f2d
CAP-1636 updated the review comments
Feb 13, 2020
1e489b0
Merge pull request #16 in SA/prebid from CAP-1636 to master
Feb 18, 2020
144ba4a
Merge branch 'master' of https://github.com/prebid/Prebid.js
Jun 4, 2020
a26077f
CAP-1849 - split up banner and video impressions to use format
Jun 5, 2020
a70f560
Merge pull request #18 in SA/prebid from CAP-1849 to master
Jun 10, 2020
585573d
Merge branch 'master' of https://github.com/prebid/Prebid.js
Jun 22, 2020
30378e8
Merge branch 'master' of https://github.com/prebid/Prebid.js
Jul 7, 2020
c70d8fc
CAP-1879 - added adapter support for consent management module
Jul 7, 2020
bcf6bc3
Merge pull request #19 in SA/prebid from CAP-1879 to master
Jul 8, 2020
cd80003
Merge branch 'master' of https://github.com/prebid/Prebid.js
Jul 16, 2020
fa60070
CAP-1879 - updates for pr
Jul 21, 2020
801603e
CAP-1879 - remove unneeded checks
Jul 21, 2020
d45d6fc
CAP-1920 - fixed size bug
Jul 23, 2020
7e27c52
CAP-1920 - update tests and banner
Jul 23, 2020
6fa31a1
CAP-1920 - fix a comparison, and height setting
Jul 27, 2020
0658a28
Merge pull request #20 in SA/prebid from CAP-1920 to master
Jul 27, 2020
39e26ff
Merge branch 'master' of https://github.com/prebid/Prebid.js
Jul 30, 2020
476ed93
Merge branch 'master' of https://github.com/prebid/Prebid.js
Jul 31, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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