From 5c14e9c92c05bd8df0862c8a1704690cffd57c72 Mon Sep 17 00:00:00 2001 From: Bill Newman Date: Thu, 26 Apr 2018 21:56:51 +0300 Subject: [PATCH] Added new types of traffic Colossus SSP adapter (#2281) * add video&native traffic colossus ssp * Native obj validation * Native obj validation #2 * Added size field in requests * fixed test --- modules/colossussspBidAdapter.js | 71 +++++++------------ modules/colossussspBidAdapter.md | 3 +- .../modules/colossussspBidAdapter_spec.js | 13 ++-- 3 files changed, 33 insertions(+), 54 deletions(-) diff --git a/modules/colossussspBidAdapter.js b/modules/colossussspBidAdapter.js index df011bc102d..22b0415936c 100644 --- a/modules/colossussspBidAdapter.js +++ b/modules/colossussspBidAdapter.js @@ -1,44 +1,31 @@ import { registerBidder } from 'src/adapters/bidderFactory'; +import { BANNER, NATIVE, VIDEO } from 'src/mediaTypes'; import * as utils from 'src/utils'; const BIDDER_CODE = 'colossusssp'; const URL = '//colossusssp.com/?c=o&m=multi'; const URL_SYNC = '//colossusssp.com/?c=o&m=cookie'; -let sizeObj = { - '468x60': 1, - '728x90': 2, - '300x600': 10, - '300x250': 15, - '300x100': 19, - '320x50': 43, - '300x50': 44, - '300x300': 48, - '300x1050': 54, - '970x90': 55, - '970x250': 57, - '1000x90': 58, - '320x80': 59, - '640x480': 65, - '320x480': 67, - '320x320': 72, - '320x160': 73, - '480x300': 83, - '970x310': 94, - '970x210': 96, - '480x320': 101, - '768x1024': 102, - '1000x300': 113, - '320x100': 117, - '800x250': 118, - '200x600': 119 -}; +function isBidResponseValid(bid) { + if (!bid.requestId || !bid.cpm || !bid.creativeId || !bid.ttl || !bid.currency) { + return false; + } -utils._each(sizeObj, (item, key) => sizeObj[item] = key); + switch (bid.mediaType) { + case BANNER: + return Boolean(bid.width && bid.height && bid.ad); + case VIDEO: + return Boolean(bid.vastUrl); + case NATIVE: + return Boolean(bid.native); + default: + return false; + } +} export const spec = { code: BIDDER_CODE, - + supportedMediaTypes: [BANNER, VIDEO, NATIVE], /** * Determines whether or not the given bid request is valid. * @@ -46,9 +33,7 @@ export const spec = { * @return boolean True if this is a valid bid, and false otherwise. */ isBidRequestValid: (bid) => { - return (!isNaN(bid.params.placement_id) && - ((bid.params.sizes !== undefined && bid.params.sizes.length > 0 && bid.params.sizes.some((sizeIndex) => sizeObj[sizeIndex] !== undefined)) || - (bid.sizes !== undefined && bid.sizes.length > 0 && bid.sizes.map((size) => `${size[0]}x${size[1]}`).some((size) => sizeObj[size] !== undefined)))); + return Boolean(bid.bidId && bid.params && !isNaN(bid.params.placement_id)); }, /** @@ -78,10 +63,12 @@ export const spec = { }; for (let i = 0; i < validBidRequests.length; i++) { let bid = validBidRequests[i]; - let placement = {}; - placement['placementId'] = bid.params.placement_id; - placement['bidId'] = bid.bidId; - placement['sizes'] = bid.sizes; + let placement = { + placementId: bid.params.placement_id, + bidId: bid.bidId, + sizes: bid.sizes, + traffic: bid.params.traffic || BANNER + }; placements.push(placement); } return { @@ -103,15 +90,7 @@ export const spec = { serverResponse = serverResponse.body; for (let i = 0; i < serverResponse.length; i++) { let resItem = serverResponse[i]; - if (resItem.width && !isNaN(resItem.width) && - resItem.height && !isNaN(resItem.height) && - resItem.requestId && typeof resItem.requestId === 'string' && - resItem.cpm && !isNaN(resItem.cpm) && - resItem.ad && typeof resItem.ad === 'string' && - resItem.ttl && !isNaN(resItem.ttl) && - resItem.creativeId && typeof resItem.creativeId === 'string' && - resItem.netRevenue && typeof resItem.netRevenue === 'boolean' && - resItem.currency && typeof resItem.currency === 'string') { + if (isBidResponseValid(resItem)) { response.push(resItem); } } diff --git a/modules/colossussspBidAdapter.md b/modules/colossussspBidAdapter.md index 9a5b9a0fe39..4760002f0db 100644 --- a/modules/colossussspBidAdapter.md +++ b/modules/colossussspBidAdapter.md @@ -18,7 +18,8 @@ Module that connects to Colossus SSP demand sources bids: [{ bidder: 'colossusssp', params: { - placement_id: 0 + placement_id: 0, + traffic: 'banner' } }] } diff --git a/test/spec/modules/colossussspBidAdapter_spec.js b/test/spec/modules/colossussspBidAdapter_spec.js index e14d2f27b42..54952fbf4b5 100644 --- a/test/spec/modules/colossussspBidAdapter_spec.js +++ b/test/spec/modules/colossussspBidAdapter_spec.js @@ -16,17 +16,13 @@ describe('ColossussspAdapter', () => { }; describe('isBidRequestValid', () => { - it('Should return true when placement_id can be cast to a number, and when at least one of the sizes passed is allowed', () => { + it('Should return true when placement_id can be cast to a number', () => { expect(spec.isBidRequestValid(bid)).to.be.true; }); it('Should return false when placement_id is not a number', () => { bid.params.placement_id = 'aaa'; expect(spec.isBidRequestValid(bid)).to.be.false; }); - it('Should return false when the sizes are not allowed', () => { - bid.sizes = [[1, 1]]; - expect(spec.isBidRequestValid(bid)).to.be.false; - }); }); describe('buildRequests', () => { @@ -56,9 +52,10 @@ describe('ColossussspAdapter', () => { let placements = data['placements']; for (let i = 0; i < placements.length; i++) { let placement = placements[i]; - expect(placement).to.have.all.keys('placementId', 'bidId', 'sizes'); + expect(placement).to.have.all.keys('placementId', 'bidId', 'traffic', 'sizes'); expect(placement.placementId).to.be.a('number'); expect(placement.bidId).to.be.a('string'); + expect(placement.traffic).to.be.a('string'); expect(placement.sizes).to.be.an('array'); } }); @@ -72,6 +69,7 @@ describe('ColossussspAdapter', () => { let resObject = { body: [ { requestId: '123', + mediaType: 'banner', cpm: 0.3, width: 320, height: 50, @@ -88,7 +86,7 @@ describe('ColossussspAdapter', () => { for (let i = 0; i < serverResponses.length; i++) { let dataItem = serverResponses[i]; expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', - 'netRevenue', 'currency'); + 'netRevenue', 'currency', 'mediaType'); expect(dataItem.requestId).to.be.a('string'); expect(dataItem.cpm).to.be.a('number'); expect(dataItem.width).to.be.a('number'); @@ -98,6 +96,7 @@ describe('ColossussspAdapter', () => { expect(dataItem.creativeId).to.be.a('string'); expect(dataItem.netRevenue).to.be.a('boolean'); expect(dataItem.currency).to.be.a('string'); + expect(dataItem.mediaType).to.be.a('string'); } it('Returns an empty array if invalid response is passed', () => { serverResponses = spec.interpretResponse('invalid_response');