diff --git a/modules/justpremiumBidAdapter.js b/modules/justpremiumBidAdapter.js index d1ca62cd8e4..df577aca320 100644 --- a/modules/justpremiumBidAdapter.js +++ b/modules/justpremiumBidAdapter.js @@ -1,274 +1,208 @@ -import bidfactory from 'src/bidfactory'; -import bidmanager from 'src/bidmanager'; -import adloader from 'src/adloader'; -import * as utils from 'src/utils'; -import adaptermanager from 'src/adaptermanager'; - -const CONSTANTS = require('src/constants.json'); - -const JustpremiumAdapter = function JustpremiumAdapter() { - const top = window.top; - let d; - let bids; - let cookieLoaded = false; - let adManagerLoaded = false; - let jPAM; - let dConfig; - let toLoad; - let server; - - function isCrossOriginIframe() { - try { - return !top.document; - } catch (e) { - return true; +import { registerBidder } from 'src/adapters/bidderFactory' +import { getTopWindowLocation } from 'src/utils' + +const BIDDER_CODE = 'justpremium' +const ENDPOINT_URL = getTopWindowLocation().protocol + '//pre.ads.justpremium.com/v/2.0/t/xhr' +const pixels = [] + +export const spec = { + code: BIDDER_CODE, + time: 60000, + + isBidRequestValid: (bid) => { + return !!(bid && bid.params && bid.params.zone) + }, + + buildRequests: (validBidRequests) => { + const c = preparePubCond(validBidRequests) + const dim = getWebsiteDim() + const payload = { + zone: [...new Set(validBidRequests.map(b => { + return parseInt(b.params.zone) + }))].join(','), + hostname: getTopWindowLocation().hostname, + protocol: getTopWindowLocation().protocol.replace(':', ''), + sw: dim.screenWidth, + sh: dim.screenHeight, + ww: dim.innerWidth, + wh: dim.innerHeight, + c: c, + id: validBidRequests[0].params.zone, + sizes: {} } - } - - function arrayUnique(array) { - const a = array.concat(); - for (let i = 0; i < a.length; ++i) { - for (let j = i + 1; j < a.length; ++j) { - if (a[i] === a[j]) { - a.splice(j--, 1); + validBidRequests.forEach(b => { + const zone = b.params.zone + const sizes = payload.sizes + sizes[zone] = sizes[zone] || [] + sizes[zone].push.apply(sizes[zone], b.sizes) + }) + const payloadString = JSON.stringify(payload) + + return { + method: 'POST', + url: ENDPOINT_URL + '?i=' + (+new Date()), + data: payloadString, + bids: validBidRequests + } + }, + + interpretResponse: (serverResponse, bidRequests) => { + const body = serverResponse.body + let bidResponses = [] + bidRequests.bids.forEach(adUnit => { + let bid = findBid(adUnit.params, body.bid) + if (bid) { + let size = (adUnit.sizes && adUnit.sizes.length && adUnit.sizes[0]) || [] + let bidResponse = { + requestId: adUnit.bidId, + creativeId: bid.id, + width: size[0] || bid.width, + height: size[1] || bid.height, + ad: bid.adm, + cpm: bid.price, + netRevenue: true, + currency: bid.currency || 'USD', + ttl: bid.ttl || spec.time } + bidResponses.push(bidResponse) } - } + }) - return a; - } + return bidResponses + }, - function readCookie(name) { - const nameEQ = name + '='; - const ca = document.cookie.split(';'); - for (let i = 0; i < ca.length; i++) { - let c = ca[i]; - while (c.charAt(0) == ' ') c = c.substring(1, c.length); - if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length); + getUserSyncs: (syncOptions) => { + if (syncOptions.iframeEnabled) { + pixels.push({ + type: 'iframe', + src: '//us-u.openx.net/w/1.0/pd?plm=10&ph=26e53f82-d199-49df-9eca-7b350c0f9646' + }) } - return null; - } - - function isOldBrowser() { - const isPromisse = typeof Promise !== 'undefined' && Promise.toString().indexOf('[native code]') !== -1; - const isWeakMap = typeof WeakMap !== 'undefined' && WeakMap.toString().indexOf('[native code]') !== -1; - return (!Array.prototype.find || !Array.prototype.sort || !Array.prototype.map || !Array.prototype.filter || !Array.prototype.keys || !isPromisse || !isWeakMap); - } - - function setupVar() { - d = top.document; - jPAM = top.jPAM = top.jPAM || window.jPAM || {}; - dConfig = jPAM._dev || - { - toLoad: null, - server: null - }; - const libVer = readCookie('jpxhbjs') || null; - toLoad = dConfig.toLoad || [d.location.protocol + '//cdn-cf.justpremium.com/js/' + (libVer ? libVer + '/' : '') + (isOldBrowser() ? 'jpxp.js' : 'jpx.js')]; - server = dConfig.server || d.location.protocol + '//pre.ads.justpremium.com/v/1.4'; + return pixels } +} - function loadCookie() { - if (cookieLoaded) return; - cookieLoaded = true; - adloader.loadScript(d.location.protocol + '//ox-d.justpremium.com/w/1.0/cj'); - } - - function loadTag(params, callback) { - const keys = Object.keys(params || {}); - const url = `${server}${keys.length ? '/?' : ''}${keys.map(key => `${key}=${params[key]}`).join('&')}`; - adloader.loadScript(url, callback); - } - - function onLoad() { - jPAM = top.jPAM = Jpx.JAM.instance({ - plugins: ['bidder'] - }); - } - - function loadResources() { - if (toLoad.length > 0) { - adloader.loadScript(toLoad.shift(), function () { - loadResources(); - }); - } else { - onLoad(); - } - } - - function loadAdManager() { - if (adManagerLoaded) return; - if (managerAlreadyDefined()) { - if (!jPAM.hasPlugin('bidder')) { - return jPAM.addPlugin('bidder'); +function findBid (params, bids) { + const tagId = params.zone + if (bids[tagId]) { + let len = bids[tagId].length + while (len--) { + if (passCond(params, bids[tagId][len])) { + return bids[tagId].splice(len, 1).pop() } - return; } - adManagerLoaded = true; - loadResources(); } - function managerAlreadyDefined() { - return top.jPAM && top.jPAM.initialized; - } + return false +} - function findBid(zone, bids) { - let len = bids.length; - while (len--) { - if (parseInt(bids[len].params.zone) === parseInt(zone)) { - const rec = bids.splice(len, 1); - return rec.length ? rec.pop() : false; - } - } - return false; - } +function passCond (params, bid) { + const format = bid.format - function handleError(err, zone, reqBids) { - let bid = findBid(zone, reqBids); - while (bid) { - const bidObject = bidfactory.createBid(CONSTANTS.STATUS.NO_BID, bid); - bidObject.bidderCode = 'justpremium'; - bidmanager.addBidResponse(bid.placementCode, bidObject); - bid = findBid(zone, reqBids); - } - utils.logError(err); + if (params.allow && params.allow.length) { + return params.allow.indexOf(format) > -1 } - function addBidResponse(zone, reqBids) { - const jPAM = window.top.jPAM = window.top.jPAM || window.jPAM || {}; - const c = jPAM.cb = jPAM.cb || {}; + if (params.exclude && params.exclude.length) { + return params.exclude.indexOf(format) < 0 + } - reqBids - .filter(r => parseInt(r.params.zone) === parseInt(zone)) - .forEach(bid => { - const bidder = c[`bidder${zone}`]; + return true +} - bidmanager.addBidResponse(bid.placementCode, bidder.createBid(function (ad) { - let bidObject; - if (!ad) { - bidObject = bidfactory.createBid(CONSTANTS.STATUS.NO_BID, bid); - bidObject.bidderCode = 'justpremium'; - return bidObject; - } - bidObject = bidfactory.createBid(CONSTANTS.STATUS.GOOD, bid); - bidObject.bidderCode = 'justpremium'; - bidObject.adSlot = bid.adSlot; - return bidObject; - }, bid)); - }); - } +function preparePubCond (bids) { + const cond = {} + const count = {} - function requestBids(bids) { - const pubCond = preparePubCond(bids); - const reqBids = bids.concat(); + bids.forEach((bid) => { + const params = bid.params + const zone = params.zone - Object.keys(pubCond).forEach(zone => { - loadTag( - { - zone: zone, - hostname: d.location.hostname, - protocol: d.location.protocol.replace(':', ''), - sw: top.screen.width, - sh: top.screen.height, - ww: top.innerWidth, - wh: top.innerHeight, - c: encodeURIComponent(JSON.stringify(pubCond[zone])), - id: zone, - i: (+new Date()) - }, - function (err) { - if (err) { - handleError(err, zone, reqBids); - } - addBidResponse(zone, reqBids); - }, - true - ); - }); - } + if (cond[zone] === 1) { + return + } - function preparePubCond(bids) { - const cond = {}; - const count = {}; + const allow = params.allow || params.formats || [] + const exclude = params.exclude || [] - bids.forEach(function (bid) { - const params = bid.params || {}; - const zone = params.zone; + if (allow.length === 0 && exclude.length === 0) { + return cond[params.zone] = 1 + } - if (!zone) { - throw new Error('JustPremium: Bid should contains zone id.'); + cond[zone] = cond[zone] || [[], {}] + cond[zone][0] = arrayUnique(cond[zone][0].concat(allow)) + exclude.forEach((e) => { + if (!cond[zone][1][e]) { + cond[zone][1][e] = 1 + } else { + cond[zone][1][e]++ } + }) - if (cond[zone] === 1) { - return; - } + count[zone] = count[zone] || 0 + if (exclude.length) { + count[zone]++ + } + }) - const allow = params.allow || params.formats || []; - const exclude = params.exclude || []; + Object.keys(count).forEach((zone) => { + if (cond[zone] === 1) return - if (allow.length === 0 && exclude.length === 0) { - return cond[params.zone] = 1; + const exclude = [] + Object.keys(cond[zone][1]).forEach((format) => { + if (cond[zone][1][format] === count[zone]) { + exclude.push(format) } + }) + cond[zone][1] = exclude + }) + + Object.keys(cond).forEach((zone) => { + if (cond[zone] !== 1 && cond[zone][1].length) { + cond[zone][0].forEach((r) => { + let idx = cond[zone][1].indexOf(r) + if (idx > -1) { + cond[zone][1].splice(idx, 1) + } + }) + cond[zone][0].length = 0 + } - cond[zone] = cond[zone] || [[], {}]; - cond[zone][0] = arrayUnique(cond[zone][0].concat(allow)); - exclude.forEach(function (e) { - if (!cond[zone][1][e]) { - cond[zone][1][e] = 1; - } else cond[zone][1][e]++; - }); - - count[zone] = count[zone] || 0; - if (exclude.length) count[zone]++; - }); - - Object.keys(count).forEach(zone => { - if (cond[zone] === 1) return; + if (cond[zone] !== 1 && !cond[zone][0].length && !cond[zone][1].length) { + cond[zone] = 1 + } + }) - const exclude = []; - Object.keys(cond[zone][1]).forEach(format => { - if (cond[zone][1][format] === count[zone]) exclude.push(format); - }); - cond[zone][1] = exclude; - }); + return cond +} - Object.keys(cond).forEach(zone => { - if (cond[zone] !== 1 && cond[zone][1].length) { - cond[zone][0].forEach(r => { - var idx = cond[zone][1].indexOf(r); - if (idx > -1) { - cond[zone][1].splice(idx, 1); - } - }); - cond[zone][0].length = 0; +function arrayUnique (array) { + const a = array.concat() + for (let i = 0; i < a.length; ++i) { + for (let j = i + 1; j < a.length; ++j) { + if (a[i] === a[j]) { + a.splice(j--, 1) } - - if (cond[zone] !== 1 && !cond[zone][0].length && !cond[zone][1].length) cond[zone] = 1; - }); - - return cond; + } } - function callBids(params) { - bids = params.bids || []; + return a +} - if (!isCrossOriginIframe()) { - setupVar(); - loadCookie(); - loadAdManager(); - requestBids(bids); - } else { - bids.forEach(bid => { - handleError(new Error('Justpremium: Adapter does not support cross origin iframe.'), bid.params.zone, bids); - }); - } +function getWebsiteDim () { + let top + try { + top = window.top + } catch (e) { + top = window } return { - callBids: callBids - }; -}; - -adaptermanager.registerBidAdapter(new JustpremiumAdapter(), 'justpremium'); + screenWidth: top.screen.width, + screenHeight: top.screen.height, + innerWidth: top.innerWidth, + innerHeight: top.innerHeight + } +} -module.exports = JustpremiumAdapter; +registerBidder(spec) diff --git a/modules/justpremiumBidAdapter.md b/modules/justpremiumBidAdapter.md new file mode 100644 index 00000000000..bc81f2f17b1 --- /dev/null +++ b/modules/justpremiumBidAdapter.md @@ -0,0 +1,41 @@ +# Overview + +**Module Name**: Justpremium Bidder Adapter +**Module Type**: Bidder Adapter +**Maintainer**: info@justpremium.com + +# Description + +To get more information or your unique zone id please contact Justpremium. + +# Test Parameters +``` + var adUnits = [ + { + sizes: [[1, 1]], + code: 'div-gpt-ad-1471513102552-0', + bids: [ + { + bidder: 'justpremium', + params: { + zone: 34364, + allow : ['wp'] + } + }, + ] + }, + { + sizes: [[300, 600]], + code: 'div-gpt-ad-1471513102552-1', + bids: [ + { + bidder: 'justpremium', + params: { + zone: 34364, + exclude : ['wp'] + } + } + ] + } + ]; +``` diff --git a/test/spec/modules/justpremiumBidAdapter_spec.js b/test/spec/modules/justpremiumBidAdapter_spec.js index 8416d662572..226a5788cef 100644 --- a/test/spec/modules/justpremiumBidAdapter_spec.js +++ b/test/spec/modules/justpremiumBidAdapter_spec.js @@ -1,386 +1,127 @@ -import { expect, assert } from 'chai'; -import Adapter from 'modules/justpremiumBidAdapter'; -import bidmanager from 'src/bidmanager'; -import adLoader from 'src/adloader'; -import PREBID_CONSTANTS from 'src/constants.json'; -import * as utils from 'src/utils'; - -const CONST = { - COOKIE: '//ox-d.justpremium.com/w/1.0/cj', - LIB: '//cdn-cf.justpremium.com/js/jpx.js' -}; - -function createCookie(name, value, days) { - var expires = ''; - if (days) { - var date = new Date(); - date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); - expires = '; expires=' + date.toUTCString(); - } - document.cookie = name + '=' + value + expires + '; path=/'; -} +import { expect } from 'chai' +import { spec } from 'modules/justpremiumBidAdapter' describe('justpremium adapter', () => { - describe('setup', () => { - let sandbox; - let factory; - - beforeEach(() => { - factory = { - JAM: { - instance: () => { - } - } - }; - sandbox = sinon.sandbox.create(); - sandbox.stub(adLoader, 'loadScript', (url, callback) => { - if (url === window.location.protocol + CONST.LIB) { - window.Jpx = factory; - callback(); - } - }); - sandbox.stub(factory.JAM, 'instance', () => { - return {}; - }) - }); - - afterEach(() => { - sandbox.restore(); - }); - - it('callBids should exists and be a function', () => { - const adapter = new Adapter(); - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - - it('should request script to sync cookies and download jpx ad manager lib', () => { - const adapter = new Adapter(); - const _request = adLoader.loadScript; - const _instance = factory.JAM.instance; - - adapter.callBids({}); - - assert(_request.calledTwice); - assert.lengthOf(_request.args[0], 1); - assert.lengthOf(_request.args[1], 2); - assert.equal(_request.args[0][0], window.location.protocol + CONST.COOKIE); - assert.equal(_request.args[1][0], window.location.protocol + CONST.LIB); - expect(_request.args[1][1]).to.exist.and.to.be.a('function'); - assert(_instance.calledOnce); - }); - - it('should request proper version of jpx ad manager', () => { - createCookie('jpxhbjs', 'v2.0.0', 1); - - const adapter = new Adapter(); - const _request = adLoader.loadScript; - const parts = CONST.LIB.split('/'); - parts.splice(parts.length - 1, 0, 'v2.0.0'); - - adapter.callBids({}); - - assert.equal(_request.args[1][0], window.location.protocol + parts.join('/')); - expect(_request.args[1][1]).to.exist.and.to.be.a('function'); - - createCookie('jpxhbjs', '', 0); - }); - }); - - describe('callBids', () => { - let sandbox; - let adapter; - let jPAM; - let bidder; - beforeEach(() => { - sandbox = sinon.sandbox.create(); - window.top.jPAM = jPAM = { - initialized: true, - cmd: [], - cb: { - bidder20000: { - createBid: () => { - } - } + let adUnits = [ + { + bidder: 'justpremium', + params: { + zone: 28313, + allow: ['lb', 'wp'] + } + }, + { + bidder: 'justpremium', + params: { + zone: 32831, + exclude: ['sa'] + } + }, + ] + + describe('isBidRequestValid', () => { + it('Verifies bidder code', () => { + expect(spec.code).to.equal('justpremium') + }) + + it('Verify build request', () => { + expect(spec.isBidRequestValid({bidder: 'justpremium', params: {}})).to.equal(false) + expect(spec.isBidRequestValid({})).to.equal(false) + expect(spec.isBidRequestValid(adUnits[0])).to.equal(true) + expect(spec.isBidRequestValid(adUnits[1])).to.equal(true) + }) + }) + + describe('buildRequests', () => { + it('Verify build request and parameters', () => { + const request = spec.buildRequests(adUnits) + expect(request.method).to.equal('POST') + expect(request.url).to.match(/pre.ads.justpremium.com\/v\/2.0\/t\/xhr/) + + const jpxRequest = JSON.parse(request.data) + expect(jpxRequest).to.not.equal(null) + expect(jpxRequest.zone).to.not.equal('undefined') + expect(jpxRequest.hostname).to.equal(top.document.location.hostname) + expect(jpxRequest.protocol).to.equal(top.document.location.protocol.replace(':', '')) + expect(jpxRequest.sw).to.equal(window.top.screen.width) + expect(jpxRequest.sh).to.equal(window.top.screen.height) + expect(jpxRequest.ww).to.equal(window.top.innerWidth) + expect(jpxRequest.wh).to.equal(window.top.innerHeight) + expect(jpxRequest.c).to.not.equal('undefined') + expect(jpxRequest.id).to.equal(adUnits[0].params.zone) + expect(jpxRequest.sizes).to.not.equal('undefined') + }) + }) + + describe('interpretResponse', () => { + const request = spec.buildRequests(adUnits) + it('Verify server response', () => { + let response = { + 'bid': { + '28313': [{ + 'id': 3213123, + 'height': 250, + 'width': 970, + 'price': 0.52, + 'format': 'lb', + 'adm': 'creative code' + }] }, - listeners: {}, - hasPlugin: () => { - return true; + 'pass': { + '28313': false }, - getPlugin: () => { - return bidder; - } - }; - sandbox.stub(adLoader, 'loadScript'); - sandbox.spy(jPAM, 'hasPlugin'); - adapter = new Adapter(); - }); - - afterEach(() => { - sandbox.restore(); - }); - - it('should detect that jpx manager is ready', () => { - const _request = adLoader.loadScript; - const _check = jPAM.hasPlugin; - - adapter.callBids({}); - - expect(_check.callCount).to.be.equal(1); - assert(_request.calledOnce); - }); - - it('should throw an error', () => { - const _request = adLoader.loadScript; - const req = { - bidderCode: 'justpremium', - bids: [ - { - bidId: 'bidId1', - bidder: 'justpremium', - params: {}, - sizes: [[1, 1]], - placementCode: 'div-gpt-ad-1471513102552-1' - } - ] - }; - - try { - adapter.callBids(req); - } catch (e) { - assert.instanceOf(e, Error); + 'deals': {} } - assert(_request.calledOnce); - }); - - it('should request bids and send proper arguments', () => { - const _request = adLoader.loadScript; - const req = { - bidderCode: 'justpremium', - bids: [ - { - bidId: 'bidId1', - bidder: 'justpremium', - params: { - zone: 20000 - }, - sizes: [[1, 1]], - placementCode: 'div-gpt-ad-1471513102552-1' - } - ] - }; - - adapter.callBids(req); - const params = {}; - _request.getCall(1).args[0].split('?').pop().split('&').forEach(keypair => { - const kp = keypair.split('='); - params[kp[0]] = kp[1]; - }); - - assert(_request.calledTwice); - assert.equal(req.bids[0].params.zone, parseInt(params['zone'])); - assert.equal(req.bids[0].params.zone, parseInt(params['id'])); - assert.equal('1', params['c']); - assert.equal(window.top.innerHeight, parseInt(params['wh'])); - assert.equal(window.top.innerWidth, parseInt(params['ww'])); - assert.equal(window.top.screen.width, parseInt(params['sw'])); - assert.equal(window.top.screen.height, parseInt(params['sh'])); - }); - - it('should parse bid allow param and send proper arguments to the server', () => { - const _request = adLoader.loadScript; - const req = { - bidderCode: 'justpremium', - bids: [ - { - bidId: 'bidId1', - bidder: 'justpremium', - params: { - zone: 20000, - allow: ['wp'] - }, - sizes: [[1, 1]], - placementCode: 'div-gpt-ad-1471513102552-1' - } - ] - }; - - adapter.callBids(req); - - const params = {}; - _request.getCall(1).args[0].split('?').pop().split('&').forEach(keypair => { - const kp = keypair.split('='); - params[kp[0]] = kp[1]; - }); - - assert(_request.calledTwice); - assert.equal(encodeURIComponent('[["wp"],[]]'), params['c']); - }); - - it('should parse bid exclude param and send proper arguments to the server', () => { - const _request = adLoader.loadScript; - const req = { - bidderCode: 'justpremium', - bids: [ - { - bidId: 'bidId1', - bidder: 'justpremium', - params: { - zone: 20000, - exclude: ['wp', 'lb'] - }, - sizes: [[1, 1]], - placementCode: 'div-gpt-ad-1471513102552-1' - } - ] - }; - - adapter.callBids(req); - - const params = {}; - _request.getCall(1).args[0].split('?').pop().split('&').forEach(keypair => { - const kp = keypair.split('='); - params[kp[0]] = kp[1]; - }); - - assert(_request.calledTwice); - assert.equal(encodeURIComponent('[[],["wp","lb"]]'), params['c']); - }); - - it('should add empty bid if there was no valid response', () => { - adLoader.loadScript.restore(); - const stubLoadScript = sandbox.stub(adLoader, 'loadScript', (url, callback) => { - if (callback) { - callback(new Error('test')); + let expectedResponse = [ + { + requestId: '319a5029c362f4', + creativeId: 3213123, + width: 970, + height: 250, + ad: 'creative code', + cpm: 0.52, + netRevenue: true, + currency: 'USD', + ttl: 60000 } - }); - const stubUtilLogError = sandbox.stub(utils, 'logError'); - const stubAddBidResponse = sandbox.stub(bidmanager, 'addBidResponse'); - const req = { - bidderCode: 'justpremium', - bids: [ - { - bidId: 'bidId1', - bidder: 'justpremium', - params: { - zone: 20000, - allow: ['wp'] - }, - sizes: [[1, 1]], - placementCode: 'div-gpt-ad-1471513102552-1' - } - ] - }; - - adapter.callBids(req); - - const bidPlacementCode = stubAddBidResponse.getCall(0).args[0]; - const bidResponse = stubAddBidResponse.getCall(0).args[1]; - - assert(stubLoadScript.calledTwice); - assert(stubUtilLogError.calledOnce); - assert(stubAddBidResponse.calledOnce); - expect(bidPlacementCode).to.equal('div-gpt-ad-1471513102552-1'); - expect(bidResponse.getStatusCode()).to.equal(PREBID_CONSTANTS.STATUS.NO_BID); - expect(bidResponse.bidderCode).to.equal('justpremium'); - }); - - it('should add empty bid if response was empty', () => { - adLoader.loadScript.restore(); - const req = { - bidderCode: 'justpremium', - bids: [ - { - bidId: 'bidId1', - bidder: 'justpremium', - params: { - zone: 20000, - allow: ['wp'] - }, - sizes: [[1, 1]], - placementCode: 'div-gpt-ad-1471513102552-1' - } - ] - }; - - const stubLoadScript = sandbox.stub(adLoader, 'loadScript', (url, callback) => { - if (callback) { - callback(); - } - }); - const stubAddBidResponse = sandbox.stub(bidmanager, 'addBidResponse'); - const stubCreateBid = sandbox.stub(jPAM.cb.bidder20000, 'createBid', (factory) => { - return factory(); - }); - - adapter.callBids(req); - - const bidPlacementCode = stubAddBidResponse.getCall(0).args[0]; - const bidResponse = stubAddBidResponse.getCall(0).args[1]; - - assert(stubAddBidResponse.calledOnce); - expect(stubLoadScript.callCount).to.be.equal(2); - expect(stubCreateBid.callCount).to.be.equal(1); - expect(bidPlacementCode).to.equal('div-gpt-ad-1471513102552-1'); - expect(bidResponse.getStatusCode()).to.equal(PREBID_CONSTANTS.STATUS.NO_BID); - expect(bidResponse.bidderCode).to.equal('justpremium'); - }); - - it('should add bid if tag contains any', () => { - adLoader.loadScript.restore(); - const req = { - bidderCode: 'justpremium', - bids: [ - { - bidId: 'bidId1', - bidder: 'justpremium', - params: { - zone: 20000, - allow: ['wp'] - }, - sizes: [[1, 1]], - placementCode: 'div-gpt-ad-1471513102552-2' - } - ] - }; - const responseData = { - width: 1, - height: 1, - ad: ``, - cpm: 5.98, - format: 'wp' - }; - - const stubLoadScript = sandbox.stub(adLoader, 'loadScript', (url, callback) => { - if (callback) { - callback(); + ] + + let result = spec.interpretResponse({body: response}, request) + expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse[0])) + + expect(result[0]).to.not.equal(null) + expect(result[0].width).to.equal(970) + expect(result[0].height).to.equal(250) + expect(result[0].ad).to.equal('creative code') + expect(result[0].cpm).to.equal(0.52) + expect(result[0].currency).to.equal('USD') + expect(result[0].ttl).to.equal(60000) + expect(result[0].creativeId).to.equal(3213123) + expect(result[0].netRevenue).to.equal(true) + }) + + it('Verify wrong server response', () => { + let response = { + 'bid': { + '28313': [] + }, + 'pass': { + '28313': true } - }); - const stubAddBidResponse = sandbox.stub(bidmanager, 'addBidResponse'); - const stubCreateBid = sandbox.stub(jPAM.cb.bidder20000, 'createBid', (factory) => { - const bid = factory({}); - - Object.assign(bid, responseData); - - return bid; - }); - - adapter.callBids(req); - - const bidPlacementCode1 = stubAddBidResponse.getCall(0).args[0]; - const bidResponse1 = stubAddBidResponse.getCall(0).args[1]; + } - assert(stubAddBidResponse.calledOnce); - expect(stubLoadScript.callCount).to.be.equal(2); - expect(stubCreateBid.callCount).to.be.equal(1); - expect(bidPlacementCode1).to.equal('div-gpt-ad-1471513102552-2'); - expect(bidResponse1.getStatusCode()).to.equal(PREBID_CONSTANTS.STATUS.GOOD); - expect(bidResponse1.bidderCode).to.equal('justpremium'); - expect(bidResponse1.width).to.equal(responseData.width); - expect(bidResponse1.height).to.equal(responseData.height); - expect(bidResponse1.cpm).to.equal(responseData.cpm); - expect(bidResponse1.format).to.equal(responseData.format); - expect(bidResponse1.ad).to.equal(responseData.ad); - }); - }); -}); + let result = spec.interpretResponse({body: response}, request) + expect(result.length).to.equal(0) + }) + }) + + describe('getUserSyncs', () => { + it('Verifies sync options', () => { + const options = spec.getUserSyncs({iframeEnabled: true}) + expect(options).to.not.be.undefined + expect(options[0].type).to.equal('iframe') + expect(options[0].src).to.match(/\/\/us-u.openx.net\/w\/1.0/) + }) + }) +})