Skip to content

Commit

Permalink
CAP-2116 updated the placementId property to tagId (prebid#6171)
Browse files Browse the repository at this point in the history
Co-authored-by: Rajkumar Natarajan <rajkumar.natarajan@synacor.com>
  • Loading branch information
2 people authored and stsepelin committed May 28, 2021
1 parent 992ee49 commit d0d4d12
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 31 deletions.
16 changes: 8 additions & 8 deletions modules/synacormediaBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const spec = {
bid.mediaTypes.hasOwnProperty('video');
},
isBidRequestValid: function(bid) {
const hasRequiredParams = bid && bid.params && bid.params.hasOwnProperty('placementId') && bid.params.hasOwnProperty('seatId');
const hasRequiredParams = bid && bid.params && (bid.params.hasOwnProperty('placementId') || bid.params.hasOwnProperty('tagId')) && bid.params.hasOwnProperty('seatId');
const hasAdSizes = bid && getAdUnitSizes(bid).filter(size => BLOCKED_AD_SIZES.indexOf(size.join('x')) === -1).length > 0
return !!(hasRequiredParams && hasAdSizes);
},
Expand Down Expand Up @@ -61,7 +61,7 @@ export const spec = {
} else {
seatId = bid.params.seatId;
}
const placementId = bid.params.placementId;
const tagIdOrplacementId = bid.params.tagId || bid.params.placementId;
const bidFloor = bid.params.bidfloor ? parseFloat(bid.params.bidfloor) : null;
if (isNaN(bidFloor)) {
logWarn(`Synacormedia: there is an invalid bid floor: ${bid.params.bidfloor}`);
Expand All @@ -77,9 +77,9 @@ export const spec = {

let imps = [];
if (videoOrBannerKey === 'banner') {
imps = this.buildBannerImpressions(adSizes, bid, placementId, pos, bidFloor, videoOrBannerKey);
imps = this.buildBannerImpressions(adSizes, bid, tagIdOrplacementId, pos, bidFloor, videoOrBannerKey);
} else if (videoOrBannerKey === 'video') {
imps = this.buildVideoImpressions(adSizes, bid, placementId, pos, bidFloor, videoOrBannerKey);
imps = this.buildVideoImpressions(adSizes, bid, tagIdOrplacementId, pos, bidFloor, videoOrBannerKey);
}
if (imps.length > 0) {
imps.forEach(i => openRtbBidRequest.imp.push(i));
Expand All @@ -104,7 +104,7 @@ export const spec = {
}
},

buildBannerImpressions: function(adSizes, bid, placementId, pos, bidFloor, videoOrBannerKey) {
buildBannerImpressions: function (adSizes, bid, tagIdOrPlacementId, pos, bidFloor, videoOrBannerKey) {
let format = [];
let imps = [];
adSizes.forEach((size, i) => {
Expand All @@ -125,7 +125,7 @@ export const spec = {
format,
pos
},
tagid: placementId,
tagid: tagIdOrPlacementId,
};
if (bidFloor !== null && !isNaN(bidFloor)) {
imp.bidfloor = bidFloor;
Expand All @@ -135,7 +135,7 @@ export const spec = {
return imps;
},

buildVideoImpressions: function(adSizes, bid, placementId, pos, bidFloor, videoOrBannerKey) {
buildVideoImpressions: function(adSizes, bid, tagIdOrPlacementId, pos, bidFloor, videoOrBannerKey) {
let imps = [];
adSizes.forEach((size, i) => {
if (!size || size.length != 2) {
Expand All @@ -145,7 +145,7 @@ export const spec = {
const size1 = size[1];
const imp = {
id: `${videoOrBannerKey.substring(0, 1)}${bid.bidId}-${size0}x${size1}`,
tagid: placementId
tagid: tagIdOrPlacementId
};
if (bidFloor !== null && !isNaN(bidFloor)) {
imp.bidfloor = bidFloor;
Expand Down
4 changes: 2 additions & 2 deletions modules/synacormediaBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ https://track.technoratimedia.com/openrtb/tags?ID=%%PATTERN:hb_cache_id_synacorm
bidder: "synacormedia",
params: {
seatId: "prebid",
placementId: "demo1",
tagId: "demo1",
bidfloor: 0.10,
pos: 1
}
Expand All @@ -52,7 +52,7 @@ https://track.technoratimedia.com/openrtb/tags?ID=%%PATTERN:hb_cache_id_synacorm
bidder: "synacormedia",
params: {
seatId: "prebid",
placementId: "demo1",
tagId: "demo1",
bidfloor: 0.20,
pos: 1,
video: {
Expand Down
112 changes: 91 additions & 21 deletions test/spec/modules/synacormediaBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@ describe('synacormediaBidAdapter ', function () {
sizes: [300, 250],
params: {
seatId: 'prebid',
placementId: '1234'
tagId: '1234'
}
};
});

it('should return true when params placementId and seatId are truthy', function () {
bid.params.placementId = bid.params.tagId;
delete bid.params.tagId;
assert(spec.isBidRequestValid(bid));
});

it('should return true when params tagId and seatId are truthy', function () {
delete bid.params.placementId;
assert(spec.isBidRequestValid(bid));
});

Expand All @@ -35,8 +42,9 @@ describe('synacormediaBidAdapter ', function () {
assert.isFalse(spec.isBidRequestValid(bid));
});

it('should return false when placementId param is missing', function () {
it('should return false when both placementId param and tagId param are missing', function () {
delete bid.params.placementId;
delete bid.params.tagId;
assert.isFalse(spec.isBidRequestValid(bid));
});

Expand All @@ -53,7 +61,7 @@ describe('synacormediaBidAdapter ', function () {
sizes: [[300, 250], [300, 600]],
params: {
seatId: 'prebid',
placementId: '1234',
tagId: '1234',
bidfloor: '0.50'
}
};
Expand All @@ -63,7 +71,7 @@ describe('synacormediaBidAdapter ', function () {
sizes: [[300, 250], [300, 600]],
params: {
seatId: 'prebid',
placementId: '1234',
tagId: '1234',
bidfloor: '0.50'
},
mediaTypes: {
Expand All @@ -84,7 +92,7 @@ describe('synacormediaBidAdapter ', function () {
sizes: [[640, 480]],
params: {
seatId: 'prebid',
placementId: '1234',
tagId: '1234',
bidfloor: '0.50'
},
mediaTypes: {
Expand All @@ -110,7 +118,7 @@ describe('synacormediaBidAdapter ', function () {
bidder: 'synacormedia',
params: {
seatId: 'prebid',
placementId: '1234',
tagId: '1234',
video: {
minduration: 30
}
Expand Down Expand Up @@ -163,7 +171,7 @@ describe('synacormediaBidAdapter ', function () {
sizes: [[300, 250], [300, 600]],
params: {
seatId: 'prebid',
placementId: '1234',
tagId: '1234',
bidfloor: '0.50'
}
};
Expand Down Expand Up @@ -230,7 +238,7 @@ describe('synacormediaBidAdapter ', function () {
sizes: [[300, 600]],
params: {
seatId: validBidRequest.params.seatId,
placementId: '5678',
tagId: '5678',
bidfloor: '0.50'
}
};
Expand Down Expand Up @@ -262,7 +270,7 @@ describe('synacormediaBidAdapter ', function () {
sizes: [[300, 250]],
params: {
seatId: 'somethingelse',
placementId: '5678',
tagId: '5678',
bidfloor: '0.50'
}
};
Expand Down Expand Up @@ -295,7 +303,7 @@ describe('synacormediaBidAdapter ', function () {
sizes: [[300, 250]],
params: {
seatId: 'prebid',
placementId: '1234',
tagId: '1234',
bidfloor: 'abcd'
}
};
Expand Down Expand Up @@ -327,7 +335,7 @@ describe('synacormediaBidAdapter ', function () {
sizes: [[300, 250]],
params: {
seatId: 'prebid',
placementId: '1234'
tagId: '1234'
}
};
let req = spec.buildRequests([badFloorBidRequest], bidderRequest);
Expand Down Expand Up @@ -358,7 +366,7 @@ describe('synacormediaBidAdapter ', function () {
sizes: [[300, 250]],
params: {
seatId: 'prebid',
placementId: '1234',
tagId: '1234',
pos: 1
}
};
Expand Down Expand Up @@ -390,7 +398,7 @@ describe('synacormediaBidAdapter ', function () {
sizes: [[300, 250]],
params: {
seatId: 'prebid',
placementId: '1234',
tagId: '1234',
}
};
let req = spec.buildRequests([newPosBidRequest], bidderRequest);
Expand Down Expand Up @@ -425,7 +433,7 @@ describe('synacormediaBidAdapter ', function () {
sizes: [],
params: {
seatId: 'prebid',
placementId: '1234',
tagId: '1234',
bidfloor: '0.50'
}
};
Expand All @@ -435,7 +443,7 @@ describe('synacormediaBidAdapter ', function () {
sizes: [[300]],
params: {
seatId: 'prebid',
placementId: '1234',
tagId: '1234',
bidfloor: '0.50'
}
};
Expand All @@ -457,7 +465,7 @@ describe('synacormediaBidAdapter ', function () {
bidder: 'synacormedia',
params: {
seatId: 'prebid',
placementId: '1234',
tagId: '1234',
video: {
minduration: 30,
maxduration: 45,
Expand Down Expand Up @@ -515,7 +523,7 @@ describe('synacormediaBidAdapter ', function () {
bidder: 'synacormedia',
params: {
seatId: 'prebid',
placementId: '1234',
tagId: '1234',
video: {
minduration: 30,
maxduration: 45,
Expand Down Expand Up @@ -582,12 +590,74 @@ describe('synacormediaBidAdapter ', function () {
})
});

describe('Bid Requests with placementId should be backward compatible ', function () {
let validVideoBidReq = {
bidder: 'synacormedia',
params: {
seatId: 'prebid',
placementId: 'demo1',
pos: 1,
video: {}
},
renderer: {
url: '../syncOutstreamPlayer.js'
},
mediaTypes: {
video: {
playerSize: [[300, 250]],
context: 'outstream'
}
},
adUnitCode: 'div-1',
transactionId: '0869f34e-090b-4b20-84ee-46ff41405a39',
sizes: [[300, 250]],
bidId: '22b3a2268d9f0e',
bidderRequestId: '1d195910597e13',
auctionId: '3375d336-2aea-4ee7-804c-6d26b621ad20',
src: 'client',
bidRequestsCount: 1,
bidderRequestsCount: 1,
bidderWinsCount: 0
};

let validBannerBidRequest = {
bidId: '9876abcd',
sizes: [[300, 250]],
params: {
seatId: 'prebid',
placementId: '1234',
}
};

let bidderRequest = {
refererInfo: {
referer: 'http://localhost:9999/'
},
bidderCode: 'synacormedia',
auctionId: 'f8a75621-d672-4cbb-9275-3db7d74fb110'
};

it('should return valid bid request for banner impression', function () {
let req = spec.buildRequests([validBannerBidRequest], bidderRequest);
expect(req).to.have.property('method', 'POST');
expect(req).to.have.property('url');
expect(req.url).to.contain('//prebid.technoratimedia.com/openrtb/bids/prebid?src=$$REPO_AND_VERSION$$');
});

it('should return valid bid request for video impression', function () {
let req = spec.buildRequests([validVideoBidReq], bidderRequest);
expect(req).to.have.property('method', 'POST');
expect(req).to.have.property('url');
expect(req.url).to.contain('//prebid.technoratimedia.com/openrtb/bids/prebid?src=$$REPO_AND_VERSION$$');
});
});

describe('Bid Requests with schain object ', function() {
let validBidReq = {
bidder: 'synacormedia',
params: {
seatId: 'prebid',
placementId: 'demo1',
tagId: 'demo1',
pos: 1,
video: {}
},
Expand Down Expand Up @@ -634,7 +704,7 @@ describe('synacormediaBidAdapter ', function () {
bidder: 'synacormedia',
params: {
seatId: 'prebid',
placementId: 'demo1',
tagId: 'demo1',
pos: 1,
video: {}
},
Expand Down Expand Up @@ -914,8 +984,8 @@ describe('synacormediaBidAdapter ', function () {
});

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

it('should use video bid request height and width if not present in response', function () {
Expand Down

0 comments on commit d0d4d12

Please sign in to comment.