From 64eac46ee586b01572bd1681a92bfb2984518d47 Mon Sep 17 00:00:00 2001 From: Andrew Muraco Date: Thu, 10 Jan 2019 23:29:15 -0500 Subject: [PATCH] Updated synacormedia bid adaptor to assign a unique adId to each bid returned, and submit bid requests for every sizes instead of just the first size of an ad unit. Added test cases for multi-bid/multi-size --- modules/synacormediaBidAdapter.js | 30 ++++---- .../modules/synacormediaBidAdapter_spec.js | 76 ++++++++++++++++--- 2 files changed, 80 insertions(+), 26 deletions(-) diff --git a/modules/synacormediaBidAdapter.js b/modules/synacormediaBidAdapter.js index d987979e1fa..8dd23b5048f 100644 --- a/modules/synacormediaBidAdapter.js +++ b/modules/synacormediaBidAdapter.js @@ -40,18 +40,19 @@ export const spec = { seatId = bid.params.seatId; } let placementId = bid.params.placementId; - let size = getAdUnitSizes(bid)[0]; - this.sizeMap[bid.bidId] = size; - openRtbBidRequest.imp.push({ - id: bid.bidId, - tagid: placementId, - banner: { - w: size[0], - h: size[1], - pos: 0 - } + getAdUnitSizes(bid).forEach((size, i) => { + openRtbBidRequest.imp.push({ + id: bid.bidId + '~' + size[0] + 'x' + size[1], + tagid: placementId, + banner: { + w: size[0], + h: size[1], + pos: 0 + } + }); }); }); + if (openRtbBidRequest.imp.length && seatId) { return { method: 'POST', @@ -74,7 +75,6 @@ export const spec = { if (id && seatbids) { seatbids.forEach(seatbid => { seatbid.bid.forEach(bid => { - let size = this.sizeMap[bid.impid] || [0, 0]; let price = parseFloat(bid.price); let creative = bid.adm.replace(/\${([^}]*)}/g, (match, key) => { switch (key) { @@ -87,11 +87,13 @@ export const spec = { } return match; }); + let [, impid, width, height] = bid.impid.match(/^(.*)~(.*)x(.*)$/); bids.push({ - requestId: bid.impid, + requestId: impid, + adId: bid.id.replace(/~/g, '-'), cpm: price, - width: size[0], - height: size[1], + width: parseInt(width, 10), + height: parseInt(height, 10), creativeId: seatbid.seat + '~' + bid.crid, currency: 'USD', netRevenue: true, diff --git a/test/spec/modules/synacormediaBidAdapter_spec.js b/test/spec/modules/synacormediaBidAdapter_spec.js index 9a95d1377e8..17bad3317e8 100644 --- a/test/spec/modules/synacormediaBidAdapter_spec.js +++ b/test/spec/modules/synacormediaBidAdapter_spec.js @@ -35,7 +35,7 @@ describe('synacormediaBidAdapter ', function () { describe('buildRequests', function () { let validBidRequest = { bidId: '9876abcd', - sizes: [[300, 250]], + sizes: [[300, 250], [300, 600]], params: { seatId: 'prebid', placementId: '1234' @@ -49,13 +49,22 @@ describe('synacormediaBidAdapter ', function () { } }; - let expectedDataImp = { + let expectedDataImp1 = { banner: { h: 250, pos: 0, w: 300, }, - id: '9876abcd', + id: '9876abcd~300x250', + tagid: '1234' + }; + let expectedDataImp2 = { + banner: { + h: 600, + pos: 0, + w: 300, + }, + id: '9876abcd~300x600', tagid: '1234' }; @@ -67,7 +76,7 @@ describe('synacormediaBidAdapter ', function () { expect(req.url).to.contain('//prebid.technoratimedia.com/openrtb/bids/prebid?'); expect(req.data).to.exist.and.to.be.an('object'); expect(req.data.id).to.equal('xyz123'); - expect(req.data.imp).to.eql([expectedDataImp]); + expect(req.data.imp).to.eql([expectedDataImp1, expectedDataImp2]); }); it('should return multiple bids when multiple valid requests with the same seatId are used', function () { @@ -85,13 +94,13 @@ describe('synacormediaBidAdapter ', function () { expect(req).to.have.property('url'); expect(req.url).to.contain('//prebid.technoratimedia.com/openrtb/bids/prebid?'); expect(req.data.id).to.equal('xyz123'); - expect(req.data.imp).to.eql([expectedDataImp, { + expect(req.data.imp).to.eql([expectedDataImp1, expectedDataImp2, { banner: { h: 600, pos: 0, w: 300, }, - id: 'foobar', + id: 'foobar~300x600', tagid: '5678' }]); }); @@ -117,7 +126,7 @@ describe('synacormediaBidAdapter ', function () { pos: 0, w: 300, }, - id: 'foobar', + id: 'foobar~300x250', tagid: '5678' } ]); @@ -132,12 +141,18 @@ describe('synacormediaBidAdapter ', function () { describe('interpretResponse', function () { let bidResponse = { id: '10865933907263896~9998~0', - impid: '9876abcd', + impid: '9876abcd~300x250', price: 0.13, crid: '1022-250', adm: '' }; - spec.sizeMap['9876abcd'] = [300, 250]; + let bidResponse2 = { + id: '10865933907263800~9999~0', + impid: '9876abcd~300x600', + price: 1.99, + crid: '9993-013', + adm: '' + }; let serverResponse; beforeEach(function() { @@ -151,12 +166,13 @@ describe('synacormediaBidAdapter ', function () { } }; }); - it('should return a bid when bid is in the response', 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); - expect(resp).to.be.an('array').that.is.not.empty; + expect(resp).to.be.an('array').to.have.lengthOf(1); expect(resp[0]).to.eql({ requestId: '9876abcd', + adId: '10865933907263896-9998-0', cpm: 0.13, width: 300, height: 250, @@ -164,7 +180,43 @@ describe('synacormediaBidAdapter ', function () { currency: 'USD', netRevenue: true, mediaType: BANNER, - ad: '', + ad: '', + ttl: 60 + }); + }); + + it('should return 2 bids when 2 bids are in the response', function () { + serverResponse.body.seatbid[0].bid.push(bidResponse); + serverResponse.body.seatbid.push({ + seat: '9999', + bid: [bidResponse2], + }); + let resp = spec.interpretResponse(serverResponse); + expect(resp).to.be.an('array').to.have.lengthOf(2); + expect(resp[0]).to.eql({ + requestId: '9876abcd', + adId: '10865933907263896-9998-0', + cpm: 0.13, + width: 300, + height: 250, + creativeId: '9998~1022-250', + currency: 'USD', + netRevenue: true, + mediaType: BANNER, + ad: '', + ttl: 60 + }); + expect(resp[1]).to.eql({ + requestId: '9876abcd', + adId: '10865933907263800-9999-0', + cpm: 1.99, + width: 300, + height: 600, + creativeId: '9999~9993-013', + currency: 'USD', + netRevenue: true, + mediaType: BANNER, + ad: '', ttl: 60 }); });