diff --git a/modules/rhythmoneBidAdapter.js b/modules/rhythmoneBidAdapter.js index 29572c228fe..6e7a935c71c 100644 --- a/modules/rhythmoneBidAdapter.js +++ b/modules/rhythmoneBidAdapter.js @@ -15,12 +15,12 @@ function RhythmOneBidAdapter() { let SUPPORTED_VIDEO_API = [1, 2, 5]; let slotsToBids = {}; let that = this; - let version = '1.0.2.1'; + let version = '2.0.0.0'; let loadStart = Date.now(); var win = typeof window !== 'undefined' ? window : {}; this.isBidRequestValid = function (bid) { - return true; + return !!(bid.params && bid.params.placementId); }; this.getUserSyncs = function (syncOptions, responses, gdprConsent) { @@ -90,6 +90,7 @@ function RhythmOneBidAdapter() { impObj.id = BRs[i].adUnitCode; impObj.bidfloor = parseFloat(utils.deepAccess(BRs[i], 'params.floor')) || 0; impObj.secure = win.location.protocol === 'https:' ? 1 : 0; + if (utils.deepAccess(BRs[i], 'mediaTypes.banner') || utils.deepAccess(BRs[i], 'mediaType') === 'banner') { impObj.banner = frameBanner(BRs[i]); } @@ -139,21 +140,58 @@ function RhythmOneBidAdapter() { } } - function frameBanner(bid) { - var sizes = utils.parseSizesInput(bid.sizes).map(size => size.split('x')); - return { - w: parseInt(sizes[0][0]), - h: parseInt(sizes[0][1]) + function getValidSizeSet(dimensionList) { + let w = parseInt(dimensionList[0]); + let h = parseInt(dimensionList[1]); + // clever check for NaN + if (! (w !== w || h !== h)) { // eslint-disable-line + return [w, h]; + } + return false; + } + + function frameBanner(adUnit) { + // adUnit.sizes is scheduled to be deprecated, continue its support but prefer adUnit.mediaTypes.banner + var sizeList = adUnit.sizes; + if (adUnit.mediaTypes && adUnit.mediaTypes.banner) { + sizeList = adUnit.mediaTypes.banner.sizes; + } + var sizeStringList = utils.parseSizesInput(sizeList); + if (!Array.isArray(sizeStringList)) { + return {}; } + + var format = []; + sizeStringList.forEach(function(size) { + if (!size) { + return; + } + var dimensionList = getValidSizeSet(size.split('x')); + if (dimensionList) { + format.push({ + 'w': dimensionList[0], + 'h': dimensionList[1], + }); + } + }); + if (format.length) { + return { + 'format': format + }; + } + return {}; } function frameVideo(bid) { var size = []; if (utils.deepAccess(bid, 'mediaTypes.video.playerSize')) { + var dimensionSet = bid.mediaTypes.video.playerSize; if (utils.isArray(bid.mediaTypes.video.playerSize[0])) { - size = bid.mediaTypes.video.playerSize[0]; - } else if (utils.isNumber(bid.mediaTypes.video.playerSize[0])) { - size = bid.mediaTypes.video.playerSize; + dimensionSet = bid.mediaTypes.video.playerSize[0]; + } + var validSize = getValidSizeSet(dimensionSet) + if (validSize) { + size = validSize; } } return { @@ -172,7 +210,7 @@ function RhythmOneBidAdapter() { function frameExt(bid) { return { bidder: { - placementId: (bid.params && bid.params['placementId']) ? bid.params['placementId'] : '', + placementId: bid.params['placementId'], zone: (bid.params && bid.params['zone']) ? bid.params['zone'] : '1r', path: (bid.params && bid.params['path']) ? bid.params['path'] : 'mvo' } diff --git a/modules/rhythmoneBidAdapter.md b/modules/rhythmoneBidAdapter.md index ec3ee4852e5..df657ed2651 100644 --- a/modules/rhythmoneBidAdapter.md +++ b/modules/rhythmoneBidAdapter.md @@ -14,15 +14,41 @@ This module relays Prebid bids from Rhythm Exchange, RhythmOne's ad exchange. ```js const adUnits = [{ - code: 'uuddlrlrbass', - sizes: [ - [300, 250] - ], + code: 'adSlot-1', + mediaTypes: { + banner: { + sizes: [ + [300, 250], + [300, 600] + ] + } + }, bids: [ { bidder: 'rhythmone', - params: - { + params: + { + placementId: '80184', // REQUIRED + zone: '1r', // OPTIONAL + path: 'mvo', // OPTIONAL + endpoint: "//tag.1rx.io/rmp/80184/0/mvo?z=1r" // OPTIONAL, only required for testing. this api guarantees no 204 responses + } + } + ] +}, +{ + code: 'adSlot-2', + mediaTypes: { + video: { + context: "instream", + playerSize: [640, 480] + } + }, + bids: [ + { + bidder: 'rhythmone', + params: + { placementId: '80184', // REQUIRED zone: '1r', // OPTIONAL path: 'mvo', // OPTIONAL @@ -31,4 +57,4 @@ const adUnits = [{ } ] }]; -``` \ No newline at end of file +``` diff --git a/test/spec/modules/rhythmoneBidAdapter_spec.js b/test/spec/modules/rhythmoneBidAdapter_spec.js index 98a7731c324..e909827b2df 100644 --- a/test/spec/modules/rhythmoneBidAdapter_spec.js +++ b/test/spec/modules/rhythmoneBidAdapter_spec.js @@ -1,64 +1,73 @@ import {spec} from '../../../modules/rhythmoneBidAdapter'; -var assert = require('assert'); +import * as utils from '../../../src/utils'; +import * as sinon from 'sinon'; + +var r1adapter = spec; describe('rhythmone adapter tests', function () { - describe('rhythmoneResponse', function () { - var z = spec; + beforeEach(function() { + this.defaultBidderRequest = { + 'refererInfo': { + 'referer': 'Reference Page' + } + }; + }); - var rmpBannerRequest = z.buildRequests( - [ + describe('Verify 1.0 POST Banner Bid Request', function () { + it('buildRequests works', function () { + var bidRequestList = [ { 'bidder': 'rhythmone', 'params': { - 'placementId': 'abc', - 'keywords': '', - 'categories': [], - 'trace': true, - 'zone': '2345', - 'path': 'mvo', - 'method': 'POST' + 'placementId': 'myplacement', + 'zone': 'myzone', + 'path': 'mypath' }, 'mediaType': 'banner', 'adUnitCode': 'div-gpt-ad-1438287399331-0', - 'sizes': [[300, 250]] + 'sizes': [[300, 250]], + 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', + 'bidderRequestId': '418b37f85e772c', + 'auctionId': '18fd8b8b0bd757', + 'bidRequestsCount': 1, + 'bidId': '51ef8751f9aead' } - ], { 'refererInfo': { 'referer': 'Reference Page' } } - ); - - it('Verify POST Banner Bid Request', function () { - expect(rmpBannerRequest.url).to.have.string('//tag.1rx.io/rmp/abc/0/mvo?z=2345&hbv='); - expect(rmpBannerRequest.method).to.equal('POST'); - const bidRequest = JSON.parse(rmpBannerRequest.data); - expect(bidRequest.site).to.not.equal(null); - expect(bidRequest.site.ref).to.equal('Reference Page'); - expect(bidRequest.device).to.not.equal(null); - expect(bidRequest.device.ua).to.equal(navigator.userAgent); - expect(bidRequest.device).to.have.property('dnt'); - expect(bidRequest.imp[0].banner).to.not.equal(null); - expect(bidRequest.imp[0].banner.w).to.equal(300); - expect(bidRequest.imp[0].banner.h).to.equal(250); - expect(bidRequest.imp[0].ext.bidder.zone).to.equal('2345'); - expect(bidRequest.imp[0].ext.bidder.path).to.equal('mvo'); - }); + ]; - var bannerBids = z.interpretResponse({ - body: [ - { - 'impid': 'div-gpt-ad-1438287399331-0', - 'w': 300, - 'h': 250, - 'adm': '
My ad4 with cpm of a4ab3485f434f74f
', - 'price': 1, - 'crid': 'cr-cfy24' - } - ] - }); + var bidRequest = r1adapter.buildRequests(bidRequestList, this.defaultBidderRequest); - it('should register one bid', function() { - assert.equal(bannerBids.length, 1); + expect(bidRequest.url).to.have.string('//tag.1rx.io/rmp/myplacement/0/mypath?z=myzone&hbv='); + expect(bidRequest.method).to.equal('POST'); + const openrtbRequest = JSON.parse(bidRequest.data); + expect(openrtbRequest.site).to.not.equal(null); + expect(openrtbRequest.site.ref).to.equal('Reference Page'); + expect(openrtbRequest.device).to.not.equal(null); + expect(openrtbRequest.device.ua).to.equal(navigator.userAgent); + expect(openrtbRequest.device.dnt).to.equal(0); + expect(openrtbRequest.imp[0].banner).to.not.equal(null); + expect(openrtbRequest.imp[0].banner.format[0].w).to.equal(300); + expect(openrtbRequest.imp[0].banner.format[0].h).to.equal(250); + expect(openrtbRequest.imp[0].ext.bidder.zone).to.equal('myzone'); + expect(openrtbRequest.imp[0].ext.bidder.path).to.equal('mypath'); }); - it('Verify parse banner response', function() { + it('interpretResponse works', function() { + var bidList = { + 'body': [ + { + 'impid': 'div-gpt-ad-1438287399331-0', + 'w': 300, + 'h': 250, + 'adm': '
My Compelling Ad
', + 'price': 1, + 'crid': 'cr-cfy24' + } + ] + }; + + var bannerBids = r1adapter.interpretResponse(bidList); + + expect(bannerBids.length).to.equal(1); const bid = bannerBids[0]; expect(bid.width).to.equal(300); expect(bid.height).to.equal(250); @@ -68,70 +77,80 @@ describe('rhythmone adapter tests', function () { expect(bid.cpm).to.equal(1.0); expect(bid.ttl).to.equal(350); }); + }); - var rmpVideoRequest = z.buildRequests( - [ + describe('Verify POST Video Bid Request', function() { + it('buildRequests works', function () { + var bidRequestList = [ { 'bidder': 'rhythmone', 'params': { - 'placementId': 'xyz', - 'keywords': '', - 'categories': [], - 'trace': true, - 'method': 'POST' + 'placementId': 'myplacement', + 'zone': 'myzone', + 'path': 'mypath' }, 'mediaTypes': { 'video': { - 'playerSize': [[640, 480]], + 'playerSize': [ + [640, 480] + ], 'context': 'instream' } }, - 'placementCode': 'div-gpt-ad-1438287399331-1', - 'sizes': [[300, 250]] + 'adUnitCode': 'div-gpt-ad-1438287399331-1', + 'sizes': [ + [300, 250] + ], + 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', + 'bidderRequestId': '418b37f85e772c', + 'auctionId': '18fd8b8b0bd757', + 'bidRequestsCount': 1, + 'bidId': '51ef8751f9aead' } - ], { 'refererInfo': { 'referer': 'Reference Page' } } - ); - - it('Verify POST Video Bid Request', function () { - expect(rmpVideoRequest.url).to.have.string('//tag.1rx.io/rmp/xyz/0/mvo?z=1r&hbv='); - expect(rmpVideoRequest.method).to.equal('POST'); - const bidRequest = JSON.parse(rmpVideoRequest.data); - expect(bidRequest.site).to.not.equal(null); - expect(bidRequest.device).to.not.equal(null); - expect(bidRequest.device.ua).to.equal(navigator.userAgent); - expect(bidRequest.device).to.have.property('dnt'); - expect(bidRequest.imp[0].video).to.not.equal(null); - expect(bidRequest.imp[0].video.w).to.equal(640); - expect(bidRequest.imp[0].video.h).to.equal(480); - expect(bidRequest.imp[0].video.mimes[0]).to.equal('video/mp4'); - expect(bidRequest.imp[0].video.protocols).to.eql([2, 3, 5, 6]); - expect(bidRequest.imp[0].video.startdelay).to.equal(0); - expect(bidRequest.imp[0].video.skip).to.equal(0); - expect(bidRequest.imp[0].video.playbackmethod).to.eql([1, 2, 3, 4]); - expect(bidRequest.imp[0].video.delivery[0]).to.equal(1); - expect(bidRequest.imp[0].video.api).to.eql([1, 2, 5]); - }); + ]; - var videoBids = z.interpretResponse({ - body: [ - { - 'impid': 'div-gpt-ad-1438287399331-1', - 'price': 1, - 'nurl': 'http://testdomain/rmp/placementid/0/path?reqId=1636037', - 'adomain': ['test.com'], - 'cid': '467415', - 'crid': 'cr-vid', - 'w': 800, - 'h': 600 - } - ] - }); + var bidRequest = r1adapter.buildRequests(bidRequestList, this.defaultBidderRequest); - it('should register one bid', function() { - assert.equal(videoBids.length, 1); + expect(bidRequest.url).to.have.string('//tag.1rx.io/rmp/myplacement/0/mypath?z=myzone&hbv='); + expect(bidRequest.method).to.equal('POST'); + const openrtbRequest = JSON.parse(bidRequest.data); + expect(openrtbRequest.site).to.not.equal(null); + expect(openrtbRequest.device).to.not.equal(null); + expect(openrtbRequest.device.ua).to.equal(navigator.userAgent); + expect(openrtbRequest.device).to.have.property('dnt'); + expect(openrtbRequest.imp[0].video).to.not.equal(null); + expect(openrtbRequest.imp[0].video.w).to.equal(640); + expect(openrtbRequest.imp[0].video.h).to.equal(480); + expect(openrtbRequest.imp[0].video.mimes[0]).to.equal('video/mp4'); + expect(openrtbRequest.imp[0].video.protocols).to.eql([2, 3, 5, 6]); + expect(openrtbRequest.imp[0].video.startdelay).to.equal(0); + expect(openrtbRequest.imp[0].video.skip).to.equal(0); + expect(openrtbRequest.imp[0].video.playbackmethod).to.eql([1, 2, 3, 4]); + expect(openrtbRequest.imp[0].video.delivery[0]).to.equal(1); + expect(openrtbRequest.imp[0].video.api).to.eql([1, 2, 5]); }); - it('Verify parse video response', function() { + it('interpretResponse works', function() { + var bidList = { + 'body': [ + { + 'impid': 'div-gpt-ad-1438287399331-1', + 'price': 1, + 'nurl': 'http://testdomain/rmp/placementid/0/path?reqId=1636037', + 'adomain': [ + 'test.com' + ], + 'cid': '467415', + 'crid': 'cr-vid', + 'w': 800, + 'h': 600 + } + ] + }; + + var videoBids = r1adapter.interpretResponse(bidList); + + expect(videoBids.length).to.equal(1); const bid = videoBids[0]; expect(bid.width).to.equal(800); expect(bid.height).to.equal(600); @@ -143,47 +162,23 @@ describe('rhythmone adapter tests', function () { expect(bid.cpm).to.equal(1.0); expect(bid.ttl).to.equal(600); }); + }); - it('should send GDPR Consent data to RhythmOne tag', function () { - let _consentString = 'testConsentString'; - var request = z.buildRequests( - [ - { - 'bidder': 'rhythmone', - 'params': { - 'placementId': 'xyz', - 'keywords': '', - 'categories': [], - 'trace': true, - 'method': 'POST' - }, - 'adUnitCode': 'div-gpt-ad-1438287399331-3', - 'sizes': [[300, 250]] - } - ], {'gdprConsent': {'gdprApplies': true, 'consentString': _consentString}, 'refererInfo': { 'referer': 'Reference Page' }} - ); - const bidRequest = JSON.parse(request.data); - expect(bidRequest.user.ext.consent).to.equal(_consentString); - expect(bidRequest.regs.ext.gdpr).to.equal(true); - }); - - var rmpMultiFormatRequest = z.buildRequests( - [ + describe('Verify Multi-Format ads and Multiple Size Bid Request', function() { + it('buildRequests works', function () { + var bidRequestList = [ { 'bidder': 'rhythmone', 'params': { - 'placementId': 'xyz', - 'keywords': '', - 'categories': [], - 'trace': true, - 'zone': '2345', - 'path': 'mvo', - 'method': 'POST' + 'placementId': 'myplacement', + 'zone': 'myzone', + 'path': 'mypath', }, 'mediaTypes': { 'banner': { 'sizes': [ - [300, 250] + [300, 250], + [300, 600] ] }, 'video': { @@ -192,58 +187,69 @@ describe('rhythmone adapter tests', function () { } }, 'adUnitCode': 'div-gpt-ad-1438287399331-5', - 'sizes': [[300, 250]] + 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', + 'bidderRequestId': '418b37f85e772c', + 'auctionId': '18fd8b8b0bd757', + 'bidRequestsCount': 1, + 'bidId': '51ef8751f9aead' } - ], { 'refererInfo': { 'referer': 'Reference Page' } } - ); - - it('Verify Multi-Format ads Bid Request', function () { - const bidRequest = JSON.parse(rmpMultiFormatRequest.data); - expect(bidRequest.site).to.not.equal(null); - expect(bidRequest.site.ref).to.equal('Reference Page'); - expect(bidRequest.device).to.not.equal(null); - expect(bidRequest.device.ua).to.equal(navigator.userAgent); - expect(bidRequest.device).to.have.property('dnt'); - expect(bidRequest.imp[0].video).to.not.equal(null); - expect(bidRequest.imp[0].video.w).to.equal(640); - expect(bidRequest.imp[0].video.h).to.equal(480); - expect(bidRequest.imp[0].video.mimes[0]).to.equal('video/mp4'); - expect(bidRequest.imp[0].video.protocols).to.eql([2, 3, 5, 6]); - expect(bidRequest.imp[0].video.startdelay).to.equal(0); - expect(bidRequest.imp[0].video.skip).to.equal(0); - expect(bidRequest.imp[0].video.playbackmethod).to.eql([1, 2, 3, 4]); - expect(bidRequest.imp[0].video.delivery[0]).to.equal(1); - expect(bidRequest.imp[0].video.api).to.eql([1, 2, 5]); - expect(bidRequest.imp[0].banner).to.not.equal(null); - expect(bidRequest.imp[0].banner.w).to.equal(300); - expect(bidRequest.imp[0].banner.h).to.equal(250); - expect(bidRequest.imp[0].ext.bidder.zone).to.equal('2345'); - expect(bidRequest.imp[0].ext.bidder.path).to.equal('mvo'); - }); + ]; - var forRMPMultiFormatResponse = z.interpretResponse({ - body: { - 'id': '1e810245dd1779', - 'seatbid': [ { - 'bid': [ { - 'impid': 'div-gpt-ad-1438287399331-5', - 'price': 1, - 'nurl': 'http://testdomain/rmp/placementid/0/path?reqId=1636037', - 'adomain': ['test.com'], - 'cid': '467415', - 'crid': 'cr-vid', - 'w': 800, - 'h': 600 - } ] - } ] - } - }); + var bidRequest = r1adapter.buildRequests(bidRequestList, this.defaultBidderRequest); - it('should register one bid', function() { - assert.equal(forRMPMultiFormatResponse.length, 1); + const openrtbRequest = JSON.parse(bidRequest.data); + expect(openrtbRequest.site).to.not.equal(null); + expect(openrtbRequest.site.ref).to.equal('Reference Page'); + expect(openrtbRequest.device).to.not.equal(null); + expect(openrtbRequest.device.ua).to.equal(navigator.userAgent); + expect(openrtbRequest.device).to.have.property('dnt'); + expect(openrtbRequest.imp[0].video).to.not.equal(null); + expect(openrtbRequest.imp[0].video.w).to.equal(640); + expect(openrtbRequest.imp[0].video.h).to.equal(480); + expect(openrtbRequest.imp[0].video.mimes[0]).to.equal('video/mp4'); + expect(openrtbRequest.imp[0].video.protocols).to.eql([2, 3, 5, 6]); + expect(openrtbRequest.imp[0].video.startdelay).to.equal(0); + expect(openrtbRequest.imp[0].video.skip).to.equal(0); + expect(openrtbRequest.imp[0].video.playbackmethod).to.eql([1, 2, 3, 4]); + expect(openrtbRequest.imp[0].video.delivery[0]).to.equal(1); + expect(openrtbRequest.imp[0].video.api).to.eql([1, 2, 5]); + expect(openrtbRequest.imp[0].banner).to.not.equal(null); + expect(openrtbRequest.imp[0].banner.format[0].w).to.equal(300); + expect(openrtbRequest.imp[0].banner.format[0].h).to.equal(250); + expect(openrtbRequest.imp[0].banner.format[1].w).to.equal(300); + expect(openrtbRequest.imp[0].banner.format[1].h).to.equal(600); + expect(openrtbRequest.imp[0].ext.bidder.zone).to.equal('myzone'); + expect(openrtbRequest.imp[0].ext.bidder.path).to.equal('mypath'); }); - it('Verify parse for multi format ad response', function() { + it('interpretResponse works', function() { + var bidList = { + 'body': { + 'id': '1e810245dd1779', + 'seatbid': [ + { + 'bid': [ + { + 'impid': 'div-gpt-ad-1438287399331-5', + 'price': 1, + 'nurl': 'http://testdomain/rmp/placementid/0/path?reqId=1636037', + 'adomain': [ + 'test.com' + ], + 'cid': '467415', + 'crid': 'cr-vid', + 'w': 800, + 'h': 600 + } + ] + } + ] + } + }; + + var forRMPMultiFormatResponse = r1adapter.interpretResponse(bidList); + + expect(forRMPMultiFormatResponse.length).to.equal(1); const bid = forRMPMultiFormatResponse[0]; expect(bid.width).to.equal(800); expect(bid.height).to.equal(600); @@ -255,65 +261,394 @@ describe('rhythmone adapter tests', function () { expect(bid.cpm).to.equal(1.0); expect(bid.ttl).to.equal(600); }); + }); + + describe('misc buildRequests', function() { + it('should send GDPR Consent data to RhythmOne tag', function () { + var bidRequestList = [ + { + 'bidder': 'rhythmone', + 'params': { + 'placementId': 'myplacement', + 'zone': 'myzone', + 'path': 'mypath' + }, + 'mediaTypes': { + 'banner': { + 'sizes': [[300, 250]] + } + }, + 'adUnitCode': 'div-gpt-ad-1438287399331-3', + 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', + 'bidderRequestId': '418b37f85e772c', + 'auctionId': '18fd8b8b0bd757', + 'bidRequestsCount': 1, + 'bidId': '51ef8751f9aead' + } + ]; + + var consentString = 'testConsentString'; + var gdprBidderRequest = this.defaultBidderRequest; + gdprBidderRequest.gdprConsent = { + 'gdprApplies': true, + 'consentString': consentString + }; + + var bidRequest = r1adapter.buildRequests(bidRequestList, gdprBidderRequest); + + const openrtbRequest = JSON.parse(bidRequest.data); + expect(openrtbRequest.user.ext.consent).to.equal(consentString); + expect(openrtbRequest.regs.ext.gdpr).to.equal(true); + }); + + it('prefer 2.0 sizes', function () { + var bidRequestList = [ + { + 'bidder': 'rhythmone', + 'params': { + 'placementId': 'myplacement', + 'zone': 'myzone', + 'path': 'mypath' + }, + 'mediaTypes': { + 'banner': { + 'sizes': [[300, 600]] + } + }, + 'adUnitCode': 'div-gpt-ad-1438287399331-0', + 'sizes': [[300, 250]], + 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', + 'bidderRequestId': '418b37f85e772c', + 'auctionId': '18fd8b8b0bd757', + 'bidRequestsCount': 1, + 'bidId': '51ef8751f9aead' + } + ]; - var noBidResponse = z.interpretResponse({ - body: '' + var bidRequest = r1adapter.buildRequests(bidRequestList, this.defaultBidderRequest); + + const openrtbRequest = JSON.parse(bidRequest.data); + expect(openrtbRequest.imp[0].banner.format[0].w).to.equal(300); + expect(openrtbRequest.imp[0].banner.format[0].h).to.equal(600); }); - it('No bid response', function() { - assert.equal(noBidResponse.length, 0); + it('survives size misconfiguration', function () { + var bidRequestList = [ + { + 'bidder': 'rhythmone', + 'params': { + 'placementId': 'myplacement', + 'zone': 'myzone', + 'path': 'mypath' + }, + 'mediaTypes': { + 'banner': { + 'sizes': [[300]] + } + }, + 'adUnitCode': 'div-gpt-ad-1438287399331-0', + 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', + 'bidderRequestId': '418b37f85e772c', + 'auctionId': '18fd8b8b0bd757', + 'bidRequestsCount': 1, + 'bidId': '51ef8751f9aead' + } + ]; + + var bidRequest = r1adapter.buildRequests(bidRequestList, this.defaultBidderRequest); + + const openrtbRequest = JSON.parse(bidRequest.data); + expect(openrtbRequest.imp[0].banner.format).to.be.undefined; + }); + + it('dnt is correctly set to 1', function () { + var bidRequestList = [ + { + 'bidder': 'rhythmone', + 'params': { + 'placementId': 'myplacement', + }, + 'mediaTypes': { + 'banner': { + 'sizes': [[300, 600]] + } + }, + 'adUnitCode': 'div-gpt-ad-1438287399331-0', + 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', + 'bidderRequestId': '418b37f85e772c', + 'auctionId': '18fd8b8b0bd757', + 'bidRequestsCount': 1, + 'bidId': '51ef8751f9aead' + } + ]; + + var dntStub = sinon.stub(utils, 'getDNT').returns(1); + + var bidRequest = r1adapter.buildRequests(bidRequestList, this.defaultBidderRequest); + + dntStub.restore(); + + const openrtbRequest = JSON.parse(bidRequest.data); + expect(openrtbRequest.device.dnt).to.equal(1); }); - describe('isRequiredParamPresent', function () { - var rmpBannerRequest = z.buildRequests( - [ - { - 'bidder': 'rhythmone', - 'params': { - 'keywords': '', - 'categories': [], - 'trace': true, - 'zone': '2345', - 'path': 'mvo', - 'method': 'POST' - }, - 'mediaType': 'banner', - 'adUnitCode': 'div-gpt-ad-1438287399331-0', - 'sizes': [[300, 250]] - } - ], { 'refererInfo': { 'referer': 'Reference Page' } } - ); - it('should return empty when required params not found', function () { - expect(rmpBannerRequest).to.be.empty; + it('sets floor', function () { + var bidRequestList = [ + { + 'bidder': 'rhythmone', + 'params': { + 'placementId': 'myplacement', + 'floor': 100.0 + }, + 'mediaTypes': { + 'banner': { + 'sizes': [[300, 600]] + } + }, + 'adUnitCode': 'div-gpt-ad-1438287399331-0', + 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', + 'bidderRequestId': '418b37f85e772c', + 'auctionId': '18fd8b8b0bd757', + 'bidRequestsCount': 1, + 'bidId': '51ef8751f9aead' + } + ]; + + var bidRequest = r1adapter.buildRequests(bidRequestList, this.defaultBidderRequest); + + const openrtbRequest = JSON.parse(bidRequest.data); + expect(openrtbRequest.imp[0].bidfloor).to.equal(100.0); + }); + + it('support for correct video size definition', function () { + var bidRequestList = [ + { + 'bidder': 'rhythmone', + 'params': { + 'placementId': 'myplacement', + }, + 'mediaTypes': { + 'video': { + 'playerSize': [640, 480], + 'context': 'instream' + } + }, + 'adUnitCode': 'div-gpt-ad-1438287399331-1', + 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', + 'bidderRequestId': '418b37f85e772c', + 'auctionId': '18fd8b8b0bd757', + 'bidRequestsCount': 1, + 'bidId': '51ef8751f9aead' + } + ]; + + var bidRequest = r1adapter.buildRequests(bidRequestList, this.defaultBidderRequest); + + const openrtbRequest = JSON.parse(bidRequest.data); + expect(openrtbRequest.imp[0].video.w).to.equal(640); + expect(openrtbRequest.imp[0].video.h).to.equal(480); + }); + + it('supports string video sizes', function () { + var bidRequestList = [ + { + 'bidder': 'rhythmone', + 'params': { + 'placementId': 'myplacement', + }, + 'mediaTypes': { + 'video': { + 'context': 'instream', + 'playerSize': ['600', '300'] + } + }, + 'adUnitCode': 'div-gpt-ad-1438287399331-1', + 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', + 'bidderRequestId': '418b37f85e772c', + 'auctionId': '18fd8b8b0bd757', + 'bidRequestsCount': 1, + 'bidId': '51ef8751f9aead' + } + ]; + + var bidRequest = r1adapter.buildRequests(bidRequestList, this.defaultBidderRequest); + + const openrtbRequest = JSON.parse(bidRequest.data); + expect(openrtbRequest.imp[0].video.w).to.equal(600); + expect(openrtbRequest.imp[0].video.h).to.equal(300); + }); + + it('rejects bad video sizes', function () { + var bidRequestList = [ + { + 'bidder': 'rhythmone', + 'params': { + 'placementId': 'myplacement', + }, + 'mediaTypes': { + 'video': { + 'context': 'instream', + 'playerSize': ['badWidth', 'badHeight'] + } + }, + 'adUnitCode': 'div-gpt-ad-1438287399331-1', + 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', + 'bidderRequestId': '418b37f85e772c', + 'auctionId': '18fd8b8b0bd757', + 'bidRequestsCount': 1, + 'bidId': '51ef8751f9aead' + } + ]; + + var bidRequest = r1adapter.buildRequests(bidRequestList, this.defaultBidderRequest); + + const openrtbRequest = JSON.parse(bidRequest.data); + expect(openrtbRequest.imp[0].video.w).to.be.undefined; + expect(openrtbRequest.imp[0].video.h).to.be.undefined; + }); + + it('supports missing video size', function () { + var bidRequestList = [ + { + 'bidder': 'rhythmone', + 'params': { + 'placementId': 'myplacement', + }, + 'mediaTypes': { + 'video': { + 'context': 'instream' + } + }, + 'adUnitCode': 'div-gpt-ad-1438287399331-1', + 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', + 'bidderRequestId': '418b37f85e772c', + 'auctionId': '18fd8b8b0bd757', + 'bidRequestsCount': 1, + 'bidId': '51ef8751f9aead' + } + ]; + + var bidRequest = r1adapter.buildRequests(bidRequestList, this.defaultBidderRequest); + + const openrtbRequest = JSON.parse(bidRequest.data); + expect(openrtbRequest.imp[0].video.w).to.be.undefined; + expect(openrtbRequest.imp[0].video.h).to.be.undefined; + }); + + it('uses default zone and path', function () { + var bidRequestList = [ + { + 'bidder': 'rhythmone', + 'params': { + 'placementId': 'myplacement' + }, + 'mediaTypes': { + 'banner': { + 'sizes': [ + [300, 600] + ] + } + }, + 'adUnitCode': 'div-gpt-ad-1438287399331-0', + 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', + 'bidderRequestId': '418b37f85e772c', + 'auctionId': '18fd8b8b0bd757', + 'bidRequestsCount': 1, + 'bidId': '51ef8751f9aead' + } + ]; + + var bidRequest = r1adapter.buildRequests(bidRequestList, this.defaultBidderRequest); + + const openrtbRequest = JSON.parse(bidRequest.data); + expect(openrtbRequest.imp[0].ext.bidder.zone).to.equal('1r'); + expect(openrtbRequest.imp[0].ext.bidder.path).to.equal('mvo'); + }); + + it('should return empty when required params not found', function () { + var bidRequestList = [ + { + 'bidder': 'rhythmone', + 'params': { + 'zone': 'myzone', + 'path': 'mypath' + }, + 'mediaTypes': { + 'banner': { + 'sizes': [ + [300, 250] + ] + } + }, + 'adUnitCode': 'div-gpt-ad-1438287399331-3', + 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', + 'bidderRequestId': '418b37f85e772c', + 'auctionId': '18fd8b8b0bd757', + 'bidRequestsCount': 1, + 'bidId': '51ef8751f9aead' + } + ]; + + var bidRequest = r1adapter.buildRequests(bidRequestList, this.defaultBidderRequest); + + expect(bidRequest).to.be.empty; + }); + }); + + describe('misc interpretResponse', function () { + it('No bid response', function() { + var noBidResponse = r1adapter.interpretResponse({ + 'body': '' }); + expect(noBidResponse.length).to.equal(0); }); }); - describe('auditBeacon', function() { - var z = spec; - var beaconURL = z.getUserSyncs({pixelEnabled: true})[0]; + describe('auditBeacon', function() { it('should contain the correct path', function() { - var u = '//hbevents.1rx.io/audit?'; - assert.equal(beaconURL.url.substring(0, u.length), u); + var syncList = r1adapter.getUserSyncs({pixelEnabled: true}); + expect(syncList.length).to.equal(1); + var syncData = syncList[0]; + var expectedURL = '//hbevents.1rx.io/audit?'; + assert.equal(syncData.url.substring(0, expectedURL.length), expectedURL); }); - beaconURL = z.getUserSyncs({pixelEnabled: true}, null, {'gdprApplies': true, 'consentString': 'testConsentString'})[0]; it('should send GDPR Consent data to Sync pixel', function () { - expect(beaconURL.url).to.have.string('&gdpr=true&gdpr_consent=testConsentString'); + var syncList = r1adapter.getUserSyncs({pixelEnabled: true}, null, {'gdprApplies': true, 'consentString': 'testConsentString'}); + expect(syncList.length).to.equal(1); + var syncData = syncList[0]; + expect(syncData.url).to.have.string('&gdpr=true&gdpr_consent=testConsentString'); + }); + + it('should not return anything when pixelEnabled is false', function () { + var syncList = r1adapter.getUserSyncs({pixelEnabled: false}, null, {'gdprApplies': true, 'consentString': 'testConsentString'}); + expect(syncList).to.be.undefined; }); }); + describe('isBidRequestValid', function () { - let bid = { + var bid = { 'bidder': 'rhythmone', 'params': { - 'placementId': '469127' + 'placementId': 'myplacement', + 'path': 'mypath', + 'zone': 'myzone' }, - 'adUnitCode': 'bannerDiv', - 'sizes': [[300, 250]] + 'mediaTypes': { + 'banner': { + 'sizes': [[300, 250]] + } + }, + 'adUnitCode': 'bannerDiv' }; it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); + expect(r1adapter.isBidRequestValid(bid)).to.equal(true); + }); + + it('should return false when placementId missing', function () { + delete bid.params.placementId; + expect(r1adapter.isBidRequestValid(bid)).to.equal(false); }); }); });