From d8dc8f1333c25e1d6a8fac8a6a85c16a5d6f8528 Mon Sep 17 00:00:00 2001 From: LeoWu Date: Mon, 23 Apr 2018 12:28:31 +0800 Subject: [PATCH] [FEAT] support mediaTypes.banner.sizes --- modules/bridgewellBidAdapter.js | 60 ++-- modules/bridgewellBidAdapter.md | 83 +++--- .../spec/modules/bridgewellBidAdapter_spec.js | 275 ++++++++++++------ 3 files changed, 281 insertions(+), 137 deletions(-) diff --git a/modules/bridgewellBidAdapter.js b/modules/bridgewellBidAdapter.js index 2a7dc0b35c3..712b00ec51a 100644 --- a/modules/bridgewellBidAdapter.js +++ b/modules/bridgewellBidAdapter.js @@ -3,7 +3,7 @@ import {registerBidder} from 'src/adapters/bidderFactory'; import find from 'core-js/library/fn/array/find'; const BIDDER_CODE = 'bridgewell'; -const REQUEST_ENDPOINT = '//rec.scupio.com/recweb/prebid.aspx'; +const REQUEST_ENDPOINT = '//rec.scupio.com/recweb/prebid.aspx?cb=' + Math.random(); export const spec = { code: BIDDER_CODE, @@ -43,17 +43,23 @@ export const spec = { * @return ServerRequest Info describing the request to the server. */ buildRequests: function(validBidRequests) { - const channelIDs = []; - + const adUnits = []; utils._each(validBidRequests, function(bid) { - channelIDs.push(bid.params.ChannelID); + adUnits.push({ + ChannelID: bid.params.ChannelID, + mediaTypes: bid.mediaTypes || { + banner: { + sizes: bid.sizes + } + } + }); }); return { - method: 'GET', + method: 'POST', url: REQUEST_ENDPOINT, data: { - 'ChannelID': channelIDs.join(',') + adUnits: adUnits }, validBidRequests: validBidRequests }; @@ -77,15 +83,35 @@ export const spec = { return; } - const anotherFormatSize = []; // for store width and height let matchedResponse = find(serverResponse.body, function(res) { - return !!res && !res.consumed && find(req.sizes, function(size) { - let width = res.width; - let height = res.height; - if (typeof size === 'number') anotherFormatSize.push(size); // if sizes format is Array[Number], push width and height into anotherFormatSize - return (width === size[0] && height === size[1]) || // for format Array[Array[Number]] check - (width === anotherFormatSize[0] && height === anotherFormatSize[1]); // for foramt Array[Number] check - }); + let valid = false; + + if (!!res && !res.consumed) { // response exists and not consumed + if (res.width && res.height) { + let mediaTypes = req.mediaTypes; + // for prebid 1.0 and later usage, mediaTypes.banner.sizes + let sizes = mediaTypes && mediaTypes.banner && mediaTypes.banner.sizes ? mediaTypes.banner.sizes : req.sizes; + if (sizes) { + let sizeValid; + let width = res.width; + let height = res.height; + // check response size validation + if (typeof sizes[0] === 'number') { // for foramt Array[Number] check + sizeValid = width === sizes[0] && height === sizes[1]; + } else { // for format Array[Array[Number]] check + sizeValid = find(sizes, function(size) { + return (width === size[0] && height === size[1]); + }); + } + + if (sizeValid) { // dont care native sizes + valid = true; + } + } + } + } + + return valid; }); if (matchedResponse) { @@ -94,11 +120,9 @@ export const spec = { // check required parameters if (typeof matchedResponse.cpm !== 'number') { return; - } else if (typeof matchedResponse.width !== 'number' || typeof matchedResponse.height !== 'number') { - return; } else if (typeof matchedResponse.ad !== 'string') { return; - } else if (typeof matchedResponse.net_revenue === 'undefined') { + } else if (typeof matchedResponse.netRevenue !== 'boolean') { return; } else if (typeof matchedResponse.currency !== 'string') { return; @@ -111,7 +135,7 @@ export const spec = { bidResponse.ad = matchedResponse.ad; bidResponse.ttl = matchedResponse.ttl; bidResponse.creativeId = matchedResponse.id; - bidResponse.netRevenue = matchedResponse.net_revenue === 'true'; + bidResponse.netRevenue = matchedResponse.netRevenue; bidResponse.currency = matchedResponse.currency; bidResponses.push(bidResponse); diff --git a/modules/bridgewellBidAdapter.md b/modules/bridgewellBidAdapter.md index b9d065054fa..6e542af18a7 100644 --- a/modules/bridgewellBidAdapter.md +++ b/modules/bridgewellBidAdapter.md @@ -10,41 +10,50 @@ Module that connects to Bridgewell demand source to fetch bids. # Test Parameters ``` - var adUnits = [ - { - code: 'test-div', - sizes: [[300, 250]], - bids: [ - { - bidder: 'bridgewell', - params: { - ChannelID: 'CgUxMjMzOBIBNiIFcGVubnkqCQisAhD6ARoBOQ' - } - } - ] - },{ - code: 'test-div', - sizes: [[728, 90]], - bids: [ - { - bidder: 'bridgewell', - params: { - ChannelID: 'CgUxMjMzOBIBNiIGcGVubnkzKggI2AUQWhoBOQ', - cpmWeight: 1.5 - } - } - ] - },{ - code: 'test-div', - sizes: [728, 90], - bids: [ - { - bidder: 'bridgewell', - params: { - ChannelID: 'CgUxMjMzOBIBNiIGcGVubnkzKggI2AUQWhoBOQ' - } - } - ] - } - ]; + var adUnits = [{ + code: 'test-div', + sizes: [ + [300, 250] + ], + bids: [{ + bidder: 'bridgewell', + params: { + ChannelID: 'CgUxMjMzOBIBNiIFcGVubnkqCQisAhD6ARoBOQ' + } + }] + }, { + code: 'test-div', + sizes: [ + [728, 90] + ], + bids: [{ + bidder: 'bridgewell', + params: { + ChannelID: 'CgUxMjMzOBIBNiIGcGVubnkzKggI2AUQWhoBOQ', + cpmWeight: 1.5 + } + }] + }, { + code: 'test-div', + sizes: [728, 90], + bids: [{ + bidder: 'bridgewell', + params: { + ChannelID: 'CgUxMjMzOBIBNiIGcGVubnkzKggI2AUQWhoBOQ' + } + }] + }, { + code: 'test-div', + mediaTypes: { + banner: { + sizes: [728, 90] + } + }, + bids: [{ + bidder: 'bridgewell', + params: { + ChannelID: 'CgUxMjMzOBIBNiIGcGVubnkzKggI2AUQWhoBOQ' + } + }] + }]; ``` diff --git a/test/spec/modules/bridgewellBidAdapter_spec.js b/test/spec/modules/bridgewellBidAdapter_spec.js index 6b95b44dfe5..8615531f88f 100644 --- a/test/spec/modules/bridgewellBidAdapter_spec.js +++ b/test/spec/modules/bridgewellBidAdapter_spec.js @@ -72,6 +72,21 @@ describe('bridgewellBidAdapter', function () { 'bidId': '3150ccb55da321', 'bidderRequestId': '22edbae2733bf6', 'auctionId': '1d1a030790a475', + }, + { + 'bidder': 'bridgewell', + 'params': { + 'ChannelID': 'CgUxMjMzOBIBNiIGcGVubnkzKggI2AUQWhoBOQ', + }, + 'adUnitCode': 'adunit-code-2', + 'mediaTypes': { + 'banner': { + 'sizes': [728, 90] + } + }, + 'bidId': '3150ccb55da321', + 'bidderRequestId': '22edbae2733bf6', + 'auctionId': '1d1a030790a475', } ]; const adapter = newBidder(spec); @@ -141,6 +156,10 @@ describe('bridgewellBidAdapter', function () { expect(spec.isBidRequestValid(bidWithZeroCpmWeight)).to.equal(false); }); + it('should return false when required params not found', () => { + expect(spec.isBidRequestValid({})).to.equal(false); + }); + it('should return false when required params are not passed', () => { let bidWithoutCpmWeight = Object.assign({}, bidWithoutCpmWeight); let bidWithCorrectCpmWeight = Object.assign({}, bidWithCorrectCpmWeight); @@ -177,10 +196,16 @@ describe('bridgewellBidAdapter', function () { describe('buildRequests', () => { it('should attach valid params to the tag', () => { - const request = spec.buildRequests([bidRequests[0]]); + const request = spec.buildRequests(bidRequests); const payload = request.data; + const adUnits = payload.adUnits; + expect(payload).to.be.an('object'); - expect(payload).to.have.property('ChannelID').that.is.a('string'); + expect(adUnits).to.be.an('array'); + for (let i = 0, max_i = adUnits.length; i < max_i; i++) { + let adUnit = adUnits[i]; + expect(adUnit).to.have.property('ChannelID').that.is.a('string'); + } }); it('should attach validBidRequests to the tag', () => { @@ -188,79 +213,89 @@ describe('bridgewellBidAdapter', function () { const validBidRequests = request.validBidRequests; expect(validBidRequests).to.deep.equal(bidRequests); }); - - it('should attach valid params to the tag if multiple ChannelIDs are presented', () => { - const request = spec.buildRequests(bidRequests); - const payload = request.data; - expect(payload).to.be.an('object'); - expect(payload).to.have.property('ChannelID').that.is.a('string'); - expect(payload.ChannelID.split(',')).to.have.lengthOf(bidRequests.length); - }); }); describe('interpretResponse', () => { const request = spec.buildRequests(bidRequests); - const serverResponses = [{ - 'id': 'e5b10774-32bf-4931-85ee-05095e8cff21', - 'bidder_code': 'bridgewell', - 'cpm': 5.0, - 'width': 300, - 'height': 250, - 'ad': '
test 300x250
', - 'ttl': 360, - 'net_revenue': 'true', - 'currency': 'NTD' - }, { - 'id': '0e4048d3-5c74-4380-a21a-00ba35629f7d', - 'bidder_code': 'bridgewell', - 'cpm': 5.0, - 'width': 728, - 'height': 90, - 'ad': '
test 728x90
', - 'ttl': 360, - 'net_revenue': 'true', - 'currency': 'NTD' - }, { - 'id': '8f12c646-3b87-4326-a837-c2a76999f168', - 'bidder_code': 'bridgewell', - 'cpm': 5.0, - 'width': 300, - 'height': 250, - 'ad': '
test 300x250
', - 'ttl': 360, - 'net_revenue': 'true', - 'currency': 'NTD' - }, { - 'id': '8f12c646-3b87-4326-a837-c2a76999f168', - 'bidder_code': 'bridgewell', - 'cpm': 5.0, - 'width': 300, - 'height': 250, - 'ad': '
test 300x250
', - 'ttl': 360, - 'net_revenue': 'true', - 'currency': 'NTD' - }, { - 'id': '0e4048d3-5c74-4380-a21a-00ba35629f7d', - 'bidder_code': 'bridgewell', - 'cpm': 5.0, - 'width': 728, - 'height': 90, - 'ad': '
test 728x90
', - 'ttl': 360, - 'net_revenue': 'true', - 'currency': 'NTD' - }, { - 'id': '0e4048d3-5c74-4380-a21a-00ba35629f7d', - 'bidder_code': 'bridgewell', - 'cpm': 5.0, - 'width': 728, - 'height': 90, - 'ad': '
test 728x90
', - 'ttl': 360, - 'net_revenue': 'true', - 'currency': 'NTD' - }]; + const serverResponses = [ + { + 'id': 'e5b10774-32bf-4931-85ee-05095e8cff21', + 'bidder_code': 'bridgewell', + 'cpm': 5.0, + 'width': 300, + 'height': 250, + 'ad': '
test 300x250
', + 'ttl': 360, + 'netRevenue': true, + 'currency': 'NTD' + }, + { + 'id': '0e4048d3-5c74-4380-a21a-00ba35629f7d', + 'bidder_code': 'bridgewell', + 'cpm': 5.0, + 'width': 728, + 'height': 90, + 'ad': '
test 728x90
', + 'ttl': 360, + 'netRevenue': true, + 'currency': 'NTD' + }, + { + 'id': '8f12c646-3b87-4326-a837-c2a76999f168', + 'bidder_code': 'bridgewell', + 'cpm': 5.0, + 'width': 300, + 'height': 250, + 'ad': '
test 300x250
', + 'ttl': 360, + 'netRevenue': true, + 'currency': 'NTD' + }, + { + 'id': '8f12c646-3b87-4326-a837-c2a76999f168', + 'bidder_code': 'bridgewell', + 'cpm': 5.0, + 'width': 300, + 'height': 250, + 'ad': '
test 300x250
', + 'ttl': 360, + 'netRevenue': true, + 'currency': 'NTD' + }, + { + 'id': '0e4048d3-5c74-4380-a21a-00ba35629f7d', + 'bidder_code': 'bridgewell', + 'cpm': 5.0, + 'width': 728, + 'height': 90, + 'ad': '
test 728x90
', + 'ttl': 360, + 'netRevenue': true, + 'currency': 'NTD' + }, + { + 'id': '0e4048d3-5c74-4380-a21a-00ba35629f7d', + 'bidder_code': 'bridgewell', + 'cpm': 5.0, + 'width': 728, + 'height': 90, + 'ad': '
test 728x90
', + 'ttl': 360, + 'netRevenue': true, + 'currency': 'NTD' + }, + { + 'id': '0e4048d3-5c74-4380-a21a-00ba35629f7d', + 'bidder_code': 'bridgewell', + 'cpm': 5.0, + 'width': 728, + 'height': 90, + 'ad': '
test 728x90
', + 'ttl': 360, + 'netRevenue': true, + 'currency': 'NTD' + } + ]; it('should return all required parameters', () => { const result = spec.interpretResponse({'body': serverResponses}, request); @@ -278,38 +313,114 @@ describe('bridgewellBidAdapter', function () { expect(result).to.deep.equal([]); }); - it('should give up bid if cpm is missing', () => { + it('should give up bid if request sizes is missing', () => { let target = Object.assign({}, serverResponses[0]); - delete target.cpm; + target.consumed = false; + const result = spec.interpretResponse({'body': [target]}, spec.buildRequests([{ + 'bidder': 'bridgewell', + 'params': { + 'ChannelID': 'CLJgEAYYvxUiBXBlbm55KgkIrAIQ-gEaATk' + }, + 'adUnitCode': 'adunit-code-1', + 'bidId': '30b31c1838de1e', + 'bidderRequestId': '22edbae2733bf6', + 'auctionId': '1d1a030790a475', + }])); + expect(result).to.deep.equal([]); + }); + + it('should give up bid if response sizes is invalid', () => { + let target = { + 'id': 'e5b10774-32bf-4931-85ee-05095e8cff21', + 'bidder_code': 'bridgewell', + 'cpm': 5.0, + 'width': 1, + 'height': 1, + 'ad': '
test 300x250
', + 'ttl': 360, + 'netRevenue': true, + 'currency': 'NTD' + }; + + const result = spec.interpretResponse({'body': [target]}, request); + expect(result).to.deep.equal([]); + }); + + it('should give up bid if cpm is missing', () => { + let target = { + 'id': 'e5b10774-32bf-4931-85ee-05095e8cff21', + 'bidder_code': 'bridgewell', + 'width': 300, + 'height': 250, + 'ad': '
test 300x250
', + 'ttl': 360, + 'netRevenue': true, + 'currency': 'NTD' + }; + const result = spec.interpretResponse({'body': [target]}, request); expect(result).to.deep.equal([]); }); it('should give up bid if width or height is missing', () => { - let target = Object.assign({}, serverResponses[0]); - delete target.height; - delete target.width; + let target = { + 'id': 'e5b10774-32bf-4931-85ee-05095e8cff21', + 'bidder_code': 'bridgewell', + 'cpm': 5.0, + 'ad': '
test 300x250
', + 'ttl': 360, + 'netRevenue': true, + 'currency': 'NTD' + }; + const result = spec.interpretResponse({'body': [target]}, request); expect(result).to.deep.equal([]); }); it('should give up bid if ad is missing', () => { - let target = Object.assign({}, serverResponses[0]); - delete target.ad; + let target = { + 'id': 'e5b10774-32bf-4931-85ee-05095e8cff21', + 'bidder_code': 'bridgewell', + 'cpm': 5.0, + 'width': 300, + 'height': 250, + 'ttl': 360, + 'netRevenue': true, + 'currency': 'NTD' + }; + const result = spec.interpretResponse({'body': [target]}, request); expect(result).to.deep.equal([]); }); it('should give up bid if revenue mode is missing', () => { - let target = Object.assign({}, serverResponses[0]); - delete target.net_revenue; + let target = { + 'id': 'e5b10774-32bf-4931-85ee-05095e8cff21', + 'bidder_code': 'bridgewell', + 'cpm': 5.0, + 'width': 300, + 'height': 250, + 'ad': '
test 300x250
', + 'ttl': 360, + 'currency': 'NTD' + }; + const result = spec.interpretResponse({'body': [target]}, request); expect(result).to.deep.equal([]); }); it('should give up bid if currency is missing', () => { - let target = Object.assign({}, serverResponses[0]); - delete target.currency; + let target = { + 'id': 'e5b10774-32bf-4931-85ee-05095e8cff21', + 'bidder_code': 'bridgewell', + 'cpm': 5.0, + 'width': 300, + 'height': 250, + 'ad': '
test 300x250
', + 'ttl': 360, + 'netRevenue': true + }; + const result = spec.interpretResponse({'body': [target]}, request); expect(result).to.deep.equal([]); });