Skip to content

Commit

Permalink
Merge branch 'master' of ssh://stash.corp.synacor.com:7999/sa/prebid …
Browse files Browse the repository at this point in the history
…into feature/CAP-2516
  • Loading branch information
ecammit committed Jan 25, 2022
2 parents 282740f + 00a11e4 commit fe450e6
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 7 deletions.
16 changes: 15 additions & 1 deletion modules/synacormediaBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const BLOCKED_AD_SIZES = [
'1x1',
'1x2'
];
const DEFAULT_MAX_TTL = 420; // 7 minutes
export const spec = {
code: 'synacormedia',
supportedMediaTypes: [ BANNER, VIDEO ],
Expand Down Expand Up @@ -232,6 +233,19 @@ export const spec = {
}
});
}

let maxTtl = DEFAULT_MAX_TTL;
if (bid.ext && bid.ext['imds.tv'] && bid.ext['imds.tv'].ttl) {
const bidTtlMax = parseInt(bid.ext['imds.tv'].ttl, 10);
maxTtl = !isNaN(bidTtlMax) && bidTtlMax > 0 ? bidTtlMax : DEFAULT_MAX_TTL;
}

let ttl = maxTtl;
if (bid.exp) {
const bidTtl = parseInt(bid.exp, 10);
ttl = !isNaN(bidTtl) && bidTtl > 0 ? Math.min(bidTtl, maxTtl) : maxTtl;
}

const bidObj = {
requestId: impid,
cpm: parseFloat(bid.price),
Expand All @@ -242,7 +256,7 @@ export const spec = {
netRevenue: true,
mediaType: isVideo ? VIDEO : BANNER,
ad: creative,
ttl: 60
ttl,
};

if (bid.adomain != undefined || bid.adomain != null) {
Expand Down
66 changes: 60 additions & 6 deletions test/spec/modules/synacormediaBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ describe('synacormediaBidAdapter ', function () {
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/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lYXN0MUBhZHMxMy5jYXAtdXNlMS5zeW5hY29yLmNvbToyNTUxL3VzZXIvJGNMYmZiIy0xOTk4NTIzNTk3JlNFQVRfSUQ9cHJlYmlk&AUCTION_PRICE=0.45'
Expand All @@ -1017,7 +1017,7 @@ describe('synacormediaBidAdapter ', function () {
netRevenue: true,
mediaType: BANNER,
ad: '<script src=\"//uat-net.technoratimedia.com/openrtb/tags?ID=k5JkFVQ1RJT05fSU1QX0lEPXYyZjczN&AUCTION_PRICE=0.13\"></script>',
ttl: 60
ttl: 420
});
});

Expand All @@ -1039,7 +1039,7 @@ describe('synacormediaBidAdapter ', function () {
netRevenue: true,
mediaType: BANNER,
ad: '<script src=\"//uat-net.technoratimedia.com/openrtb/tags?ID=k5JkFVQ1RJT05fSU1QX0lEPXYyZjczN&AUCTION_PRICE=0.13\"></script>',
ttl: 60
ttl: 420
});

expect(resp[1]).to.eql({
Expand All @@ -1052,7 +1052,7 @@ describe('synacormediaBidAdapter ', function () {
netRevenue: true,
mediaType: BANNER,
ad: '<script src=\"//uat-net.technoratimedia.com/openrtb/tags?ID=OTk5OX4wJkFVQ1RJT05fU0VBVF9JR&AUCTION_PRICE=1.99\"></script>',
ttl: 60
ttl: 420
});
});

Expand Down Expand Up @@ -1163,7 +1163,7 @@ describe('synacormediaBidAdapter ', function () {
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,
ttl: 420,
meta: { advertiserDomains: ['psacentral.org'] },
videoCacheKey: 'QVVDVElPTl9JRD1lOTBhYWU1My1hZDkwLTRkNDEtYTQxMC1lZDY1MjIxMDc0ZGMmQVVDVElPTl9CSURfSUQ9MTEzMzkxMjgwMDE2OTIzMzd-OTk5OX4wJkFVQ1RJT05fU0VBVF9JRD05OTk5JkFVQ1RJT05fSU1QX0lEPXYyZGE3MzIyYjJkZjYxZi02NDB4NDgwJkFDVE9SX1JFRj1ha2thLnRjcDovL2F3cy1lYXN0MUBhZHMxMy5jYXAtdXNlMS5zeW5hY29yLmNvbToyNTUxL3VzZXIvJGNMYmZiIy0xOTk4NTIzNTk3JlNFQVRfSUQ9cHJlYmlk',
vastUrl: 'https://uat-net.technoratimedia.com/openrtb/tags?ID=QVVDVElPTl9JRD1lOTBhYWU1My1hZDkwLTRkNDEtYTQxMC1lZDY1MjIxMDc0ZGMmQVVDVElPTl9CSURfSUQ9MTEzMzkxMjgwMDE2OTIzMzd-OTk5OX4wJkFVQ1RJT05fU0VBVF9JRD05OTk5JkFVQ1RJT05fSU1QX0lEPXYyZGE3MzIyYjJkZjYxZi02NDB4NDgwJkFDVE9SX1JFRj1ha2thLnRjcDovL2F3cy1lYXN0MUBhZHMxMy5jYXAtdXNlMS5zeW5hY29yLmNvbToyNTUxL3VzZXIvJGNMYmZiIy0xOTk4NTIzNTk3JlNFQVRfSUQ9cHJlYmlk&AUCTION_PRICE=0.45'
Expand Down Expand Up @@ -1216,9 +1216,63 @@ describe('synacormediaBidAdapter ', function () {
netRevenue: true,
mediaType: BANNER,
ad: '<script src=\"//uat-net.technoratimedia.com/openrtb/tags?ID=k5JkFVQ1RJT05fSU1QX0lEPXYyZjczN&AUCTION_PRICE=0.13\"></script>',
ttl: 60
ttl: 420
});
});

it('should return ttl equal to DEFAULT_TTL_MAX if bid.exp and bid.ext["imds.tv"].ttl are both undefined', function() {
const br = { ...bidResponse };
serverResponse.body.seatbid[0].bid.push(br);
const resp = spec.interpretResponse(serverResponse, bidRequest);
expect(resp).to.be.an('array').to.have.lengthOf(1);
expect(resp[0]).to.have.property('ttl');
expect(resp[0].ttl).to.equal(420);
});

it('should return ttl equal to bid.ext["imds.tv"].ttl if it is defined but bid.exp is undefined', function() {
let br = { ext: { 'imds.tv': { ttl: 4321 } }, ...bidResponse };
serverResponse.body.seatbid[0].bid.push(br);
let resp = spec.interpretResponse(serverResponse, bidRequest);
expect(resp).to.be.an('array').to.have.lengthOf(1);
expect(resp[0]).to.have.property('ttl');
expect(resp[0].ttl).to.equal(4321);
});

it('should return ttl equal to bid.exp if bid.exp is less than or equal to DEFAULT_TTL_MAX and bid.ext["imds.tv"].ttl is undefined', function() {
const br = { exp: 123, ...bidResponse };
serverResponse.body.seatbid[0].bid.push(br);
const resp = spec.interpretResponse(serverResponse, bidRequest);
expect(resp).to.be.an('array').to.have.lengthOf(1);
expect(resp[0]).to.have.property('ttl');
expect(resp[0].ttl).to.equal(123);
});

it('should return ttl equal to DEFAULT_TTL_MAX if bid.exp is greater than DEFAULT_TTL_MAX and bid.ext["imds.tv"].ttl is undefined', function() {
const br = { exp: 4321, ...bidResponse };
serverResponse.body.seatbid[0].bid.push(br);
const resp = spec.interpretResponse(serverResponse, bidRequest);
expect(resp).to.be.an('array').to.have.lengthOf(1);
expect(resp[0]).to.have.property('ttl');
expect(resp[0].ttl).to.equal(420);
});

it('should return ttl equal to bid.exp if bid.exp is less than or equal to bid.ext["imds.tv"].ttl', function() {
const br = { exp: 1234, ext: { 'imds.tv': { ttl: 4321 } }, ...bidResponse };
serverResponse.body.seatbid[0].bid.push(br);
const resp = spec.interpretResponse(serverResponse, bidRequest);
expect(resp).to.be.an('array').to.have.lengthOf(1);
expect(resp[0]).to.have.property('ttl');
expect(resp[0].ttl).to.equal(1234);
});

it('should return ttl equal to bid.ext["imds.tv"].ttl if bid.exp is greater than bid.ext["imds.tv"].ttl', function() {
const br = { exp: 4321, ext: { 'imds.tv': { ttl: 1234 } }, ...bidResponse };
serverResponse.body.seatbid[0].bid.push(br);
const resp = spec.interpretResponse(serverResponse, bidRequest);
expect(resp).to.be.an('array').to.have.lengthOf(1);
expect(resp[0]).to.have.property('ttl');
expect(resp[0].ttl).to.equal(1234);
});
});
describe('getUserSyncs', function () {
it('should return a usersync when iframes is enabled', function () {
Expand Down

0 comments on commit fe450e6

Please sign in to comment.