From 4f771506b3a264f29118a995626d73a74f846f6e Mon Sep 17 00:00:00 2001 From: Kuldeep Kapade Date: Fri, 11 May 2018 14:24:12 -0700 Subject: [PATCH 01/13] Added Polymorph adapter --- modules/polymorphBidAdapter.js | 105 ++++++++++ modules/polymorphBidAdapter.md | 43 +++++ test/spec/modules/polymorphBidAdapter_spec.js | 182 ++++++++++++++++++ 3 files changed, 330 insertions(+) create mode 100644 modules/polymorphBidAdapter.js create mode 100644 modules/polymorphBidAdapter.md create mode 100644 test/spec/modules/polymorphBidAdapter_spec.js diff --git a/modules/polymorphBidAdapter.js b/modules/polymorphBidAdapter.js new file mode 100644 index 00000000000..f1f1aa65de1 --- /dev/null +++ b/modules/polymorphBidAdapter.js @@ -0,0 +1,105 @@ +import * as utils from 'src/utils'; +import { registerBidder } from 'src/adapters/bidderFactory'; +import { BANNER, NATIVE, VIDEO } from 'src/mediaTypes'; + +const BIDDER_CODE = 'polymorph'; +const URL = '//api.adsnative.com/v1/ad-template.json'; + +export const polymorphAdapterSpec = { + code: BIDDER_CODE, + aliases: ['adsnative'], + supportedMediaTypes: [BANNER, VIDEO, NATIVE], + + /** + * Determines whether or not the given bid request is valid. + * + * @param {object} bid The bid to validate. + * @return boolean True if this is a valid bid, and false otherwise. + */ + isBidRequestValid: function(bid) { + return !!(bid.params.placementId); + }, + + /** + * Make a server request from the list of BidRequests. + * + * @param {BidRequest[]} bidRequests A non-empty list of bid requests which should be sent to the Server. + * @return ServerRequest Info describing the request to the server. + */ + buildRequests: function(bidRequests, bidderRequest) { + return bidRequests.map(bid => { + var payload = { + url: utils.getTopWindowUrl(), + ref: utils.getTopFrameReferrer(), + zid: bid.params.placementId, + sizes: bid.sizes, + hb: 1, + hb_source: 'prebid' + }; + Object.keys(bid.params).forEach(function(key) { + if (key != 'defaultWidth' && key != 'defaultHeight') { + payload[key] = bid.params[key]; + } + }); + const payloadString = utils.parseQueryStringParameters(payload); + return { + method: 'GET', + url: URL, + data: payloadString, + bidderRequest: bid + }; + }); + }, + + /** + * Unpack the response from the server into a list of bids. + * + * @param {*} serverResponse A successful response from the server. + * @return {Bid[]} An array of bids which were nested inside the server. + */ + interpretResponse: function(serverResponse, { bidderRequest }) { + const bidResponses = []; + try { + serverResponse = serverResponse.body; + if (!serverResponse || typeof serverResponse.status === 'undefined') { + utils.logError('HTTP Connection Error'); + return bidResponses + } + if (serverResponse.status != 'OK' || (typeof serverResponse.ad === 'undefined' && typeof serverResponse.ads === 'undefined')) { + utils.logError('API No Response: ' + serverResponse.message); + return bidResponses + } + var width = bidderRequest.params.defaultWidth || bidderRequest.sizes[0][0]; + var height = bidderRequest.params.defaultHeight || bidderRequest.sizes[0][1]; + var theHTML = ''; + var crid = ''; + if (typeof serverResponse.ad !== 'undefined') { + crid = serverResponse.crid; + theHTML = serverResponse.ad.html; + width = serverResponse.ad.width || width + height = serverResponse.ad.height || height + } else { + crid = serverResponse.ads[0].crid; + theHTML = serverResponse.html; + } + + const bidResp = { + requestId: bidderRequest.bidId, + cpm: serverResponse.ecpm, + width: width, + height: height, + ad: theHTML, + ttl: 3600, + creativeId: crid, + netRevenue: false, + currency: 'USD' + }; + bidResponses.push(bidResp); + } catch (e) { + utils.logError(e); + } + return bidResponses; + } +} + +registerBidder(polymorphAdapterSpec); diff --git a/modules/polymorphBidAdapter.md b/modules/polymorphBidAdapter.md new file mode 100644 index 00000000000..e778b312e56 --- /dev/null +++ b/modules/polymorphBidAdapter.md @@ -0,0 +1,43 @@ +# Overview + +``` +Module Name: Polymorph Bidder Adapter +Module Type: Bidder Adapter +Maintainer: kuldeep@getpolymorph.com +``` + +# Description + +Connects to Polymorph Demand Cloud (s2s header-bidding) + +# Test Parameters +``` + var adUnits = [ + { + code: 'test-div-1', + sizes: [[300, 250]], + bids: [ + { + bidder: "polymorph", + params: { + placementId: 'ping' + } + } + ] + },{ + code: 'test-div-2', + sizes: [[300, 250], [300,600]] + bids: [ + { + bidder: "polymorph", + params: { + placementId: 'ping', + // In case multiple ad sizes are supported, it's recommended to specify default height and width for native ad (in case native ad is chose as a winner). In case of banner or outstream ad any one of the above sizes can be chosen depending on the highest bid. + defaultWidth: 300, + defaultHeight: 600 + } + } + ] + } + ]; +``` \ No newline at end of file diff --git a/test/spec/modules/polymorphBidAdapter_spec.js b/test/spec/modules/polymorphBidAdapter_spec.js new file mode 100644 index 00000000000..d699a177467 --- /dev/null +++ b/test/spec/modules/polymorphBidAdapter_spec.js @@ -0,0 +1,182 @@ +import { expect } from 'chai'; +import { polymorphAdapterSpec } from 'modules/polymorphBidAdapter'; +import { newBidder } from 'src/adapters/bidderFactory'; + +const BIDDER_CODE = 'polymorph'; +const ENDPOINT_URL = '//api.adsnative.com/v1/ad-template.json'; +const PLACEMENT_ID = 'ping'; + +const spec = newBidder(polymorphAdapterSpec).getSpec(); + +const bidRequests = [{ + 'bidder': BIDDER_CODE, + 'params': { + 'placementId': PLACEMENT_ID + }, + 'adUnitCode': 'adunit-code', + 'sizes': [[300, 250], [300, 600]], + 'bidId': '30b31c1838de1e', + 'bidderRequestId': '22edbae2733bf6', + 'auctionId': '1d1a030790a475', +}, +{ + 'bidder': BIDDER_CODE, + 'params': { + 'placementId': PLACEMENT_ID, + 'defaultWidth': 300, + 'defaultHeight': 600, + }, + 'adUnitCode': 'adunit-code', + 'sizes': [[700, 250], [300, 600]], + 'bidId': '30b31c1838de1d', + 'bidderRequestId': '22edbae2733bf7', + 'auctionId': '1d1a030790a476', +}]; + +describe('Polymorph adapter test', () => { + describe('.code', () => { + it('should return a bidder code of polymorph', () => { + expect(spec.code).to.eql(BIDDER_CODE); + }); + }); + + describe('isBidRequestValid', () => { + + it('should return true when required params found', () => { + expect(spec.isBidRequestValid(bidRequests[0])).to.equal(true); + }); + + it('should return false if req has no placementId', () => { + const invalidBidRequest = { + bidder: BIDDER_CODE, + params: { + someKey: 'abc123' + } + }; + expect(spec.isBidRequestValid(invalidBidRequest)).to.eql(false); + }); + + it('should return false if req has wrong bidder code', () => { + const invalidBidRequest = { + bidder: 'something', + params: { + someKey: 'abc123' + } + }; + expect(spec.isBidRequestValid(invalidBidRequest)).to.eql(false); + }); + }); + + describe('buildRequests', () => { + it('payload test', () => { + const requests = spec.buildRequests(bidRequests); + var payload1 = {}; + requests[0].data.replace(/([^=&]+)=([^&]*)/g, function(m, key, value) { + payload1[decodeURIComponent(key)] = decodeURIComponent(value); + }); + expect(payload1.ref).to.not.be.undefined; + expect(payload1.url).to.not.be.undefined; + expect(payload1.hb).to.equal('1'); + expect(payload1.hb_source).to.equal('prebid'); + expect(payload1.zid).to.equal(PLACEMENT_ID); + expect(payload1.sizes).to.equal('300,250,300,600'); + + var payload2 = {}; + requests[1].data.replace(/([^=&]+)=([^&]*)/g, function(m, key, value) { + payload2[decodeURIComponent(key)] = decodeURIComponent(value); + }); + //expect(requests[1].data).to.equal('1'); + expect(payload2.ref).to.not.be.undefined; + expect(payload2.url).to.not.be.undefined; + expect(payload2.hb).to.equal('1'); + expect(payload2.hb_source).to.equal('prebid'); + expect(payload2.zid).to.equal(PLACEMENT_ID); + expect(payload2.sizes).to.equal('700,250,300,600'); + }); + + it('sends bid request to ENDPOINT via GET', () => { + const requests = spec.buildRequests(bidRequests); + expect(requests[0].url).to.equal(ENDPOINT_URL); + expect(requests[0].method).to.equal('GET'); + }); + }); + + describe('interpretResponse', () => { + const response = { + body: { + 'status': 'OK', + 'crid': '5ISP4995', + 'ecpm': 10, + 'ad': { + 'html': '
', + 'height': 250, + 'width': 300 + } + } + }; + + const response2 = { + body: { + 'status': 'OK', + 'ecpm': 10, + 'html': '', + 'ads': [{ + 'crid': '5ISP4995', + 'ad': { + 'html': '
' + } + },{ + 'crid': '5ISP4996', + 'ad': { + 'html': '
' + } + }] + } + }; + + it('should get correct bid response', () => { + const body = response.body; + const expectedResponse = [{ + requestId: bidRequests[0].bidId, + cpm: body.ecpm, + width: body.ad.width, + height: body.ad.height, + ad: body.ad.html, + ttl: 3600, + creativeId: body.crid, + netRevenue: false, + currency: 'USD' + }]; + + let result = spec.interpretResponse(response, { 'bidderRequest': bidRequests[0] }); + expect(result).to.deep.equal(expectedResponse); + }); + + it('widget use case', () => { + const body = response2.body; + const expectedResponse = [ + { + requestId: bidRequests[1].bidId, + cpm: body.ecpm, + width: 300, + height: 600, + ad: body.html, + ttl: 3600, + creativeId: body.ads[0].crid, + netRevenue: false, + currency: 'USD' + } + ]; + + let result = spec.interpretResponse(response2, { 'bidderRequest': bidRequests[1] }); + expect(result).to.deep.equal(expectedResponse); + }); + + it('handles nobid responses', () => { + let response = []; + + let result = spec.interpretResponse(response, { 'bidderRequest': bidRequests[0] }); + expect(result.length).to.equal(0); + }); + }); +}); From 000c0cda0391815e27078162e118e3782e9026ba Mon Sep 17 00:00:00 2001 From: Kuldeep Kapade Date: Fri, 11 May 2018 16:08:55 -0700 Subject: [PATCH 02/13] Cleaned up code --- test/spec/modules/polymorphBidAdapter_spec.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/test/spec/modules/polymorphBidAdapter_spec.js b/test/spec/modules/polymorphBidAdapter_spec.js index d699a177467..1948afd6ab4 100644 --- a/test/spec/modules/polymorphBidAdapter_spec.js +++ b/test/spec/modules/polymorphBidAdapter_spec.js @@ -41,7 +41,6 @@ describe('Polymorph adapter test', () => { }); describe('isBidRequestValid', () => { - it('should return true when required params found', () => { expect(spec.isBidRequestValid(bidRequests[0])).to.equal(true); }); @@ -70,10 +69,10 @@ describe('Polymorph adapter test', () => { describe('buildRequests', () => { it('payload test', () => { const requests = spec.buildRequests(bidRequests); - var payload1 = {}; + var payload1 = {}; requests[0].data.replace(/([^=&]+)=([^&]*)/g, function(m, key, value) { - payload1[decodeURIComponent(key)] = decodeURIComponent(value); - }); + payload1[decodeURIComponent(key)] = decodeURIComponent(value); + }); expect(payload1.ref).to.not.be.undefined; expect(payload1.url).to.not.be.undefined; expect(payload1.hb).to.equal('1'); @@ -81,11 +80,10 @@ describe('Polymorph adapter test', () => { expect(payload1.zid).to.equal(PLACEMENT_ID); expect(payload1.sizes).to.equal('300,250,300,600'); - var payload2 = {}; + var payload2 = {}; requests[1].data.replace(/([^=&]+)=([^&]*)/g, function(m, key, value) { - payload2[decodeURIComponent(key)] = decodeURIComponent(value); - }); - //expect(requests[1].data).to.equal('1'); + payload2[decodeURIComponent(key)] = decodeURIComponent(value); + }); expect(payload2.ref).to.not.be.undefined; expect(payload2.url).to.not.be.undefined; expect(payload2.hb).to.equal('1'); @@ -125,7 +123,8 @@ describe('Polymorph adapter test', () => { 'ad': { 'html': '
' } - },{ + }, + { 'crid': '5ISP4996', 'ad': { 'html': '
' From 19aeab9224ce815b9d8f6c5f74e52f709fbca1fc Mon Sep 17 00:00:00 2001 From: Kuldeep Kapade Date: Fri, 8 Jun 2018 17:43:19 -0700 Subject: [PATCH 03/13] Updated var to let --- modules/polymorphBidAdapter.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/polymorphBidAdapter.js b/modules/polymorphBidAdapter.js index f1f1aa65de1..d051910c9f5 100644 --- a/modules/polymorphBidAdapter.js +++ b/modules/polymorphBidAdapter.js @@ -69,10 +69,10 @@ export const polymorphAdapterSpec = { utils.logError('API No Response: ' + serverResponse.message); return bidResponses } - var width = bidderRequest.params.defaultWidth || bidderRequest.sizes[0][0]; - var height = bidderRequest.params.defaultHeight || bidderRequest.sizes[0][1]; - var theHTML = ''; - var crid = ''; + let width = bidderRequest.params.defaultWidth || bidderRequest.sizes[0][0]; + let height = bidderRequest.params.defaultHeight || bidderRequest.sizes[0][1]; + let theHTML = ''; + let crid = ''; if (typeof serverResponse.ad !== 'undefined') { crid = serverResponse.crid; theHTML = serverResponse.ad.html; From 9744569c8991d90f9f5391f25a9e0a995f165994 Mon Sep 17 00:00:00 2001 From: Kuldeep Kapade Date: Tue, 26 Jun 2018 13:43:16 -0700 Subject: [PATCH 04/13] Updated with mediaType --- modules/polymorphBidAdapter.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/polymorphBidAdapter.js b/modules/polymorphBidAdapter.js index d051910c9f5..2341eb6ef36 100644 --- a/modules/polymorphBidAdapter.js +++ b/modules/polymorphBidAdapter.js @@ -8,7 +8,7 @@ const URL = '//api.adsnative.com/v1/ad-template.json'; export const polymorphAdapterSpec = { code: BIDDER_CODE, aliases: ['adsnative'], - supportedMediaTypes: [BANNER, VIDEO, NATIVE], + supportedMediaTypes: [BANNER], /** * Determines whether or not the given bid request is valid. @@ -92,7 +92,8 @@ export const polymorphAdapterSpec = { ttl: 3600, creativeId: crid, netRevenue: false, - currency: 'USD' + currency: 'USD', + mediaType: 'banner' }; bidResponses.push(bidResp); } catch (e) { From d8d3658a580f3b8febcf2b95bbd9613774808a66 Mon Sep 17 00:00:00 2001 From: Kuldeep Kapade Date: Tue, 26 Jun 2018 13:51:31 -0700 Subject: [PATCH 05/13] Updated tests --- test/spec/modules/polymorphBidAdapter_spec.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/spec/modules/polymorphBidAdapter_spec.js b/test/spec/modules/polymorphBidAdapter_spec.js index 1948afd6ab4..cf20cdfaf22 100644 --- a/test/spec/modules/polymorphBidAdapter_spec.js +++ b/test/spec/modules/polymorphBidAdapter_spec.js @@ -144,7 +144,8 @@ describe('Polymorph adapter test', () => { ttl: 3600, creativeId: body.crid, netRevenue: false, - currency: 'USD' + currency: 'USD', + mediaType: 'banner' }]; let result = spec.interpretResponse(response, { 'bidderRequest': bidRequests[0] }); @@ -163,7 +164,8 @@ describe('Polymorph adapter test', () => { ttl: 3600, creativeId: body.ads[0].crid, netRevenue: false, - currency: 'USD' + currency: 'USD', + mediaType: 'banner' } ]; From 35671aa51a6fdc0f6079f1596c2bd3aa5b5dea3c Mon Sep 17 00:00:00 2001 From: Kuldeep Kapade Date: Tue, 26 Jun 2018 13:59:46 -0700 Subject: [PATCH 06/13] Fixed tests --- modules/polymorphBidAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/polymorphBidAdapter.js b/modules/polymorphBidAdapter.js index 2341eb6ef36..8d07a66d0da 100644 --- a/modules/polymorphBidAdapter.js +++ b/modules/polymorphBidAdapter.js @@ -1,6 +1,6 @@ import * as utils from 'src/utils'; import { registerBidder } from 'src/adapters/bidderFactory'; -import { BANNER, NATIVE, VIDEO } from 'src/mediaTypes'; +import { BANNER } from 'src/mediaTypes'; const BIDDER_CODE = 'polymorph'; const URL = '//api.adsnative.com/v1/ad-template.json'; From 4141bada2a2938d594dd7585378d27832f9beb4f Mon Sep 17 00:00:00 2001 From: Kuldeep Kapade Date: Thu, 13 Sep 2018 11:49:20 -0700 Subject: [PATCH 07/13] Updated polymorph adapter to support cookie syncing and network key integration --- modules/polymorphBidAdapter.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/modules/polymorphBidAdapter.js b/modules/polymorphBidAdapter.js index 8d07a66d0da..51af1fa3c04 100644 --- a/modules/polymorphBidAdapter.js +++ b/modules/polymorphBidAdapter.js @@ -2,8 +2,18 @@ import * as utils from 'src/utils'; import { registerBidder } from 'src/adapters/bidderFactory'; import { BANNER } from 'src/mediaTypes'; +const PROTOCOL = getProtocol(); const BIDDER_CODE = 'polymorph'; const URL = '//api.adsnative.com/v1/ad-template.json'; +const USER_SYNC_URL = PROTOCOL + '//rudy.adsnative.com/cm.gif'; + +function getProtocol() { + if (location.protocol && location.protocol.indexOf('https') === 0) { + return 'https:'; + } else { + return 'http:'; + } +} export const polymorphAdapterSpec = { code: BIDDER_CODE, @@ -17,7 +27,7 @@ export const polymorphAdapterSpec = { * @return boolean True if this is a valid bid, and false otherwise. */ isBidRequestValid: function(bid) { - return !!(bid.params.placementId); + return !!(bid.params.placementId) || ( !!(bid.params.network_key) && !!(bid.params.widget_id) && !!(bid.params.cat) ); }, /** @@ -100,6 +110,14 @@ export const polymorphAdapterSpec = { utils.logError(e); } return bidResponses; + }, + getUserSyncs: function(syncOptions) { + if (syncOptions.pixelEnabled) { + return [{ + type: 'image', + url: USER_SYNC_URL + }]; + } } } From 2abba8cb48aeddfbb4a211a0d74e6c8f7a58a9df Mon Sep 17 00:00:00 2001 From: Kuldeep Kapade Date: Thu, 13 Sep 2018 12:06:32 -0700 Subject: [PATCH 08/13] Fixed parens for lint --- modules/polymorphBidAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/polymorphBidAdapter.js b/modules/polymorphBidAdapter.js index 51af1fa3c04..c8a71a8f7a2 100644 --- a/modules/polymorphBidAdapter.js +++ b/modules/polymorphBidAdapter.js @@ -27,7 +27,7 @@ export const polymorphAdapterSpec = { * @return boolean True if this is a valid bid, and false otherwise. */ isBidRequestValid: function(bid) { - return !!(bid.params.placementId) || ( !!(bid.params.network_key) && !!(bid.params.widget_id) && !!(bid.params.cat) ); + return !!(bid.params.placementId) || (!!(bid.params.network_key) && !!(bid.params.widget_id) && !!(bid.params.cat)); }, /** From c96cfc099f9cef331f96ffae3f2206ec9ceed473 Mon Sep 17 00:00:00 2001 From: Kuldeep Kapade Date: Fri, 14 Sep 2018 10:55:14 -0700 Subject: [PATCH 09/13] Fixed a bug related to network_key approach --- modules/polymorphBidAdapter.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/polymorphBidAdapter.js b/modules/polymorphBidAdapter.js index c8a71a8f7a2..e13ca44ffdc 100644 --- a/modules/polymorphBidAdapter.js +++ b/modules/polymorphBidAdapter.js @@ -41,11 +41,17 @@ export const polymorphAdapterSpec = { var payload = { url: utils.getTopWindowUrl(), ref: utils.getTopFrameReferrer(), - zid: bid.params.placementId, sizes: bid.sizes, hb: 1, hb_source: 'prebid' }; + if (!!(bid.params.placementId)) { + payload.zid = bid.params.placementId; + } else if (!!(bid.params.network_key) && !!(bid.params.widget_id) && !!(bid.params.cat)) { + payload.network_key = bid.params.network_key; + payload.widget_id = bid.params.widget_id; + payload.cat = bid.params.cat; + } Object.keys(bid.params).forEach(function(key) { if (key != 'defaultWidth' && key != 'defaultHeight') { payload[key] = bid.params[key]; From b7d7d751c0647e17dfb3f5c95730114320e95e90 Mon Sep 17 00:00:00 2001 From: Kuldeep Kapade Date: Fri, 14 Sep 2018 11:51:08 -0700 Subject: [PATCH 10/13] Fixed double negation warning --- modules/polymorphBidAdapter.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/polymorphBidAdapter.js b/modules/polymorphBidAdapter.js index e13ca44ffdc..84347c53ca6 100644 --- a/modules/polymorphBidAdapter.js +++ b/modules/polymorphBidAdapter.js @@ -45,9 +45,9 @@ export const polymorphAdapterSpec = { hb: 1, hb_source: 'prebid' }; - if (!!(bid.params.placementId)) { + if (bid.params.placementId) { payload.zid = bid.params.placementId; - } else if (!!(bid.params.network_key) && !!(bid.params.widget_id) && !!(bid.params.cat)) { + } else if (bid.params.network_key && bid.params.widget_id && bid.params.cat) { payload.network_key = bid.params.network_key; payload.widget_id = bid.params.widget_id; payload.cat = bid.params.cat; From 464d4c063b0fa22abeebedacb5b580dce412cc60 Mon Sep 17 00:00:00 2001 From: Kuldeep Kapade Date: Fri, 28 Sep 2018 11:16:16 -0700 Subject: [PATCH 11/13] Updated tests for network_key --- test/spec/modules/polymorphBidAdapter_spec.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/spec/modules/polymorphBidAdapter_spec.js b/test/spec/modules/polymorphBidAdapter_spec.js index e2df44e8cfc..bbd5541b309 100644 --- a/test/spec/modules/polymorphBidAdapter_spec.js +++ b/test/spec/modules/polymorphBidAdapter_spec.js @@ -31,6 +31,19 @@ const bidRequests = [{ 'bidId': '30b31c1838de1d', 'bidderRequestId': '22edbae2733bf7', 'auctionId': '1d1a030790a476', +}, +{ + 'bidder': BIDDER_CODE, + 'params': { + 'network_key': 'abcd1234', + 'widget_id': 'xyz', + 'cat': 'IAB1,IAB2' + }, + 'adUnitCode': 'adunit-code', + 'sizes': [[700, 250], [300, 600]], + 'bidId': '30b31c1838de1d', + 'bidderRequestId': '22edbae2733bf7', + 'auctionId': '1d1a030790a476', }]; describe('Polymorph adapter test', function () { @@ -45,6 +58,10 @@ describe('Polymorph adapter test', function () { expect(spec.isBidRequestValid(bidRequests[0])).to.equal(true); }); + it('should return true when required params found', function () { + expect(spec.isBidRequestValid(bidRequests[2])).to.equal(true); + }); + it('should return false if req has no placementId', function () { const invalidBidRequest = { bidder: BIDDER_CODE, From e31d2018bdc2240978e4ceb741263a7e26bf2fda Mon Sep 17 00:00:00 2001 From: Kuldeep Kapade Date: Thu, 4 Oct 2018 10:46:07 -0700 Subject: [PATCH 12/13] Added bidId as cache buster and updated tests --- modules/polymorphBidAdapter.js | 3 ++- test/spec/modules/polymorphBidAdapter_spec.js | 25 ++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/modules/polymorphBidAdapter.js b/modules/polymorphBidAdapter.js index 84347c53ca6..da5f7f711ec 100644 --- a/modules/polymorphBidAdapter.js +++ b/modules/polymorphBidAdapter.js @@ -43,7 +43,8 @@ export const polymorphAdapterSpec = { ref: utils.getTopFrameReferrer(), sizes: bid.sizes, hb: 1, - hb_source: 'prebid' + hb_source: 'prebid', + bid_id: bid.bidId, }; if (bid.params.placementId) { payload.zid = bid.params.placementId; diff --git a/test/spec/modules/polymorphBidAdapter_spec.js b/test/spec/modules/polymorphBidAdapter_spec.js index bbd5541b309..0cdc4ba4c1e 100644 --- a/test/spec/modules/polymorphBidAdapter_spec.js +++ b/test/spec/modules/polymorphBidAdapter_spec.js @@ -5,6 +5,9 @@ import { newBidder } from 'src/adapters/bidderFactory'; const BIDDER_CODE = 'polymorph'; const ENDPOINT_URL = '//api.adsnative.com/v1/ad-template.json'; const PLACEMENT_ID = 'ping'; +const NETWORK_KEY = 'abcd1234'; +const WIDGET_ID = 'xyz'; +const CATEGORIES = 'IAB1,IAB2'; const spec = newBidder(polymorphAdapterSpec).getSpec(); @@ -35,9 +38,9 @@ const bidRequests = [{ { 'bidder': BIDDER_CODE, 'params': { - 'network_key': 'abcd1234', - 'widget_id': 'xyz', - 'cat': 'IAB1,IAB2' + 'network_key': NETWORK_KEY, + 'widget_id': WIDGET_ID, + 'cat': CATEGORIES }, 'adUnitCode': 'adunit-code', 'sizes': [[700, 250], [300, 600]], @@ -96,6 +99,7 @@ describe('Polymorph adapter test', function () { expect(payload1.hb_source).to.equal('prebid'); expect(payload1.zid).to.equal(PLACEMENT_ID); expect(payload1.sizes).to.equal('300,250,300,600'); + expect(payload1.bid_id).to.equal(requests[0].bidId); var payload2 = {}; requests[1].data.replace(/([^=&]+)=([^&]*)/g, function(m, key, value) { @@ -107,6 +111,21 @@ describe('Polymorph adapter test', function () { expect(payload2.hb_source).to.equal('prebid'); expect(payload2.zid).to.equal(PLACEMENT_ID); expect(payload2.sizes).to.equal('700,250,300,600'); + expect(payload2.bid_id).to.equal(requests[1].bidId); + + var payload3 = {}; + requests[2].data.replace(/([^=&]+)=([^&]*)/g, function(m, key, value) { + payload3[decodeURIComponent(key)] = decodeURIComponent(value); + }); + expect(payload3.ref).to.not.be.undefined; + expect(payload3.url).to.not.be.undefined; + expect(payload3.hb).to.equal('1'); + expect(payload3.hb_source).to.equal('prebid'); + expect(payload3.network_key).to.equal(NETWORK_KEY); + expect(payload3.widget_id).to.equal(WIDGET_ID); + expect(payload3.cat).to.equal(CATEGORIES); + expect(payload3.sizes).to.equal('700,250,300,600'); + expect(payload3.bid_id).to.equal(requests[1].bidId); }); it('sends bid request to ENDPOINT via GET', function () { From 697c2b9f3ffff94f589f94210f4873ceaf383be8 Mon Sep 17 00:00:00 2001 From: Kuldeep Kapade Date: Thu, 4 Oct 2018 12:00:02 -0700 Subject: [PATCH 13/13] Fixed tests --- test/spec/modules/polymorphBidAdapter_spec.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/spec/modules/polymorphBidAdapter_spec.js b/test/spec/modules/polymorphBidAdapter_spec.js index 0cdc4ba4c1e..6fd4bd90288 100644 --- a/test/spec/modules/polymorphBidAdapter_spec.js +++ b/test/spec/modules/polymorphBidAdapter_spec.js @@ -44,7 +44,7 @@ const bidRequests = [{ }, 'adUnitCode': 'adunit-code', 'sizes': [[700, 250], [300, 600]], - 'bidId': '30b31c1838de1d', + 'bidId': '30b31c1838de1f', 'bidderRequestId': '22edbae2733bf7', 'auctionId': '1d1a030790a476', }]; @@ -99,7 +99,7 @@ describe('Polymorph adapter test', function () { expect(payload1.hb_source).to.equal('prebid'); expect(payload1.zid).to.equal(PLACEMENT_ID); expect(payload1.sizes).to.equal('300,250,300,600'); - expect(payload1.bid_id).to.equal(requests[0].bidId); + expect(payload1.bid_id).to.equal('30b31c1838de1e'); var payload2 = {}; requests[1].data.replace(/([^=&]+)=([^&]*)/g, function(m, key, value) { @@ -111,7 +111,7 @@ describe('Polymorph adapter test', function () { expect(payload2.hb_source).to.equal('prebid'); expect(payload2.zid).to.equal(PLACEMENT_ID); expect(payload2.sizes).to.equal('700,250,300,600'); - expect(payload2.bid_id).to.equal(requests[1].bidId); + expect(payload2.bid_id).to.equal('30b31c1838de1d'); var payload3 = {}; requests[2].data.replace(/([^=&]+)=([^&]*)/g, function(m, key, value) { @@ -125,7 +125,7 @@ describe('Polymorph adapter test', function () { expect(payload3.widget_id).to.equal(WIDGET_ID); expect(payload3.cat).to.equal(CATEGORIES); expect(payload3.sizes).to.equal('700,250,300,600'); - expect(payload3.bid_id).to.equal(requests[1].bidId); + expect(payload3.bid_id).to.equal('30b31c1838de1f'); }); it('sends bid request to ENDPOINT via GET', function () {