From b6f5ff21b09c81442caba60eebe54e79fa828142 Mon Sep 17 00:00:00 2001 From: Teddy Pierre <33702256+pierreted90@users.noreply.github.com> Date: Mon, 16 May 2022 16:48:39 -0400 Subject: [PATCH] Remove districtm Dmx Bid Adapter (#8417) --- modules/districtmDMXBidAdapter.js | 433 ---------- modules/districtmDmxBidAdapter.md | 203 ----- .../modules/districtmDmxBidAdapter_spec.js | 815 ------------------ 3 files changed, 1451 deletions(-) delete mode 100644 modules/districtmDMXBidAdapter.js delete mode 100644 modules/districtmDmxBidAdapter.md delete mode 100644 test/spec/modules/districtmDmxBidAdapter_spec.js diff --git a/modules/districtmDMXBidAdapter.js b/modules/districtmDMXBidAdapter.js deleted file mode 100644 index f909a1f1329..00000000000 --- a/modules/districtmDMXBidAdapter.js +++ /dev/null @@ -1,433 +0,0 @@ -import { isArray, generateUUID, deepAccess, isStr } from '../src/utils.js'; -import { registerBidder } from '../src/adapters/bidderFactory.js'; -import { config } from '../src/config.js'; -import { BANNER, VIDEO } from '../src/mediaTypes.js'; - -const BIDDER_CODE = 'districtmDMX'; - -const DMXURI = 'https://dmx.districtm.io/b/v1'; - -const GVLID = 144; -const VIDEO_MAPPING = { - playback_method: { - 'auto_play_sound_on': 1, - 'auto_play_sound_off': 2, - 'click_to_play': 3, - 'mouse_over': 4, - 'viewport_sound_on': 5, - 'viewport_sound_off': 6 - } -}; -export const spec = { - code: BIDDER_CODE, - gvlid: GVLID, - aliases: ['dmx'], - supportedFormat: [BANNER, VIDEO], - supportedMediaTypes: [VIDEO, BANNER], - isBidRequestValid(bid) { - return !!(bid.params.memberid); - }, - interpretResponse(response, bidRequest) { - response = response.body || {}; - if (response.seatbid) { - if (isArray(response.seatbid)) { - const { seatbid } = response; - let winners = seatbid.reduce((bid, ads) => { - let ad = ads.bid.reduce(function (oBid, nBid) { - if (oBid.price < nBid.price) { - const bid = matchRequest(nBid.impid, bidRequest); - const { width, height } = defaultSize(bid); - nBid.cpm = parseFloat(nBid.price).toFixed(2); - nBid.bidId = nBid.impid; - nBid.requestId = nBid.impid; - nBid.width = nBid.w || width; - nBid.height = nBid.h || height; - nBid.ttl = 300; - nBid.mediaType = bid.mediaTypes && bid.mediaTypes.video ? 'video' : 'banner'; - if (nBid.mediaType === 'video') { - nBid.vastXml = cleanVast(nBid.adm, nBid.nurl); - nBid.ttl = 3600; - } - if (nBid.dealid) { - nBid.dealId = nBid.dealid; - } - nBid.uuid = nBid.bidId; - nBid.ad = nBid.adm; - nBid.netRevenue = true; - nBid.creativeId = nBid.crid; - nBid.currency = 'USD'; - nBid.meta = nBid.meta || {}; - if (nBid.adomain && nBid.adomain.length > 0) { - nBid.meta.advertiserDomains = nBid.adomain; - } - return nBid; - } else { - oBid.cpm = oBid.price; - return oBid; - } - }, { price: 0 }); - if (ad.adm) { - bid.push(ad) - } - return bid; - }, []) - let winnersClean = winners.filter(w => { - if (w.bidId) { - return true; - } - return false; - }); - return winnersClean; - } else { - return []; - } - } else { - return []; - } - }, - buildRequests(bidRequest, bidderRequest) { - let timeout = config.getConfig('bidderTimeout'); - let schain = null; - let dmxRequest = { - id: generateUUID(), - cur: ['USD'], - tmax: (timeout - 300), - test: this.test() || 0, - site: { - publisher: { id: String(bidRequest[0].params.memberid) || null } - } - } - - try { - let params = config.getConfig('dmx'); - dmxRequest.user = params.user || {}; - let site = params.site || {}; - dmxRequest.site = { ...dmxRequest.site, ...site } - } catch (e) { - - } - - let eids = []; - if (bidRequest[0] && bidRequest[0].userId) { - bindUserId(eids, deepAccess(bidRequest[0], `userId.idl_env`), 'liveramp.com', 1); - bindUserId(eids, deepAccess(bidRequest[0], `userId.id5id.uid`), 'id5-sync.com', 1); - bindUserId(eids, deepAccess(bidRequest[0], `userId.pubcid`), 'pubcid.org', 1); - bindUserId(eids, deepAccess(bidRequest[0], `userId.tdid`), 'adserver.org', 1); - bindUserId(eids, deepAccess(bidRequest[0], `userId.criteoId`), 'criteo.com', 1); - bindUserId(eids, deepAccess(bidRequest[0], `userId.britepoolid`), 'britepool.com', 1); - bindUserId(eids, deepAccess(bidRequest[0], `userId.lipb.lipbid`), 'liveintent.com', 1); - bindUserId(eids, deepAccess(bidRequest[0], `userId.intentiqid`), 'intentiq.com', 1); - bindUserId(eids, deepAccess(bidRequest[0], `userId.lotamePanoramaId`), 'lotame.com', 1); - bindUserId(eids, deepAccess(bidRequest[0], `userId.parrableId`), 'parrable.com', 1); - bindUserId(eids, deepAccess(bidRequest[0], `userId.netId`), 'netid.de', 1); - dmxRequest.user = dmxRequest.user || {}; - dmxRequest.user.ext = dmxRequest.user.ext || {}; - dmxRequest.user.ext.eids = eids; - } - if (!dmxRequest.test) { - delete dmxRequest.test; - } - if (bidderRequest.gdprConsent) { - dmxRequest.regs = {}; - dmxRequest.regs.ext = {}; - dmxRequest.regs.ext.gdpr = bidderRequest.gdprConsent.gdprApplies === true ? 1 : 0; - - if (bidderRequest.gdprConsent.gdprApplies === true) { - dmxRequest.user = {}; - dmxRequest.user.ext = {}; - dmxRequest.user.ext.consent = bidderRequest.gdprConsent.consentString; - } - } - dmxRequest.regs = dmxRequest.regs || {}; - dmxRequest.regs.coppa = config.getConfig('coppa') === true ? 1 : 0; - if (bidderRequest && bidderRequest.uspConsent) { - dmxRequest.regs = dmxRequest.regs || {}; - dmxRequest.regs.ext = dmxRequest.regs.ext || {}; - dmxRequest.regs.ext.us_privacy = bidderRequest.uspConsent; - } - try { - schain = bidRequest[0].schain; - dmxRequest.source = {}; - dmxRequest.source.ext = {}; - dmxRequest.source.ext.schain = schain || {} - } catch (e) { } - let tosendtags = bidRequest.map(dmx => { - var obj = {}; - obj.id = dmx.bidId; - obj.tagid = String(dmx.params.dmxid || dmx.adUnitCode); - obj.secure = 1; - obj.bidfloor = getFloor(dmx); - if (dmx.mediaTypes && dmx.mediaTypes.video) { - obj.video = { - topframe: 1, - skip: dmx.mediaTypes.video.skip || 0, - linearity: dmx.mediaTypes.video.linearity || 1, - minduration: dmx.mediaTypes.video.minduration || 5, - maxduration: dmx.mediaTypes.video.maxduration || 60, - playbackmethod: dmx.mediaTypes.video.playbackmethod || [2], - api: getApi(dmx.mediaTypes.video), - mimes: dmx.mediaTypes.video.mimes || ['video/mp4'], - protocols: getProtocols(dmx.mediaTypes.video), - h: dmx.mediaTypes.video.playerSize[0][1], - w: dmx.mediaTypes.video.playerSize[0][0] - }; - } else { - obj.banner = { - topframe: 1, - w: cleanSizes(dmx.sizes, 'w'), - h: cleanSizes(dmx.sizes, 'h'), - format: cleanSizes(dmx.sizes).map(s => { - return { w: s[0], h: s[1] }; - }).filter(obj => typeof obj.w === 'number' && typeof obj.h === 'number') - }; - } - return obj; - }); - - if (tosendtags.length <= 5) { - dmxRequest.imp = tosendtags; - return { - method: 'POST', - url: DMXURI, - data: JSON.stringify(dmxRequest), - bidderRequest - } - } else { - return upto5(tosendtags, dmxRequest, bidderRequest, DMXURI); - } - }, - test() { - return window.location.href.indexOf('dmTest=true') !== -1 ? 1 : 0; - }, - getUserSyncs(optionsType, serverResponses, gdprConsent, uspConsent) { - let query = []; - let url = 'https://cdn.districtm.io/ids/index.html' - if (gdprConsent && gdprConsent.gdprApplies && typeof gdprConsent.consentString === 'string') { - query.push(['gdpr', gdprConsent.consentString]) - } - if (uspConsent) { - query.push(['ccpa', uspConsent]) - } - if (query.length > 0) { - url += '?' + query.map(q => q.join('=')).join('&') - } - if (optionsType.iframeEnabled) { - return [{ - type: 'iframe', - url: url - }]; - } - } -} - -export function getFloor(bid) { - let floor = null; - if (typeof bid.getFloor === 'function') { - const floorInfo = bid.getFloor({ - currency: 'USD', - mediaType: bid.mediaTypes.video ? 'video' : 'banner', - size: bid.sizes.map(size => { - return { - w: size[0], - h: size[1] - } - }) - }); - if (typeof floorInfo === 'object' && - floorInfo.currency === 'USD' && !isNaN(parseFloat(floorInfo.floor))) { - floor = parseFloat(floorInfo.floor); - } - } - return floor !== null ? floor : bid.params.floor; -} - -export function cleanSizes(sizes, value) { - const supportedSize = [ - { - size: [300, 250], - s: 100 - }, - { - size: [728, 90], - s: 95 - }, - { - size: [320, 50], - s: 90 - }, - { - size: [160, 600], - s: 88 - }, - { - size: [300, 600], - s: 85 - }, - { - size: [300, 50], - s: 80 - }, - { - size: [970, 250], - s: 75 - }, - { - size: [970, 90], - s: 60 - }, - ]; - let newArray = shuffle(sizes, supportedSize); - switch (value) { - case 'w': - return newArray[0][0] || 0; - case 'h': - return newArray[0][1] || 0; - case 'size': - return newArray; - default: - return newArray; - } -} - -export function shuffle(sizes, list) { - let removeSizes = sizes.filter(size => { - return list.map(l => `${l.size[0]}x${l.size[1]}`).indexOf(`${size[0]}x${size[1]}`) === -1 - }) - let reOrder = sizes.reduce((results, current) => { - if (results.length === 0) { - results.push(current); - return results; - } - results.push(current); - results = list.filter(l => results.map(r => `${r[0]}x${r[1]}`).indexOf(`${l.size[0]}x${l.size[1]}`) !== -1); - results = results.sort(function (a, b) { - return b.s - a.s; - }) - return results.map(r => r.size); - }, []) - return removeDuplicate([...reOrder, ...removeSizes]); -} - -export function removeDuplicate(arrayValue) { - return arrayValue.filter((elem, index) => { - return arrayValue.map(e => `${e[0]}x${e[1]}`).indexOf(`${elem[0]}x${elem[1]}`) === index - }) -} - -export function upto5(allimps, dmxRequest, bidderRequest, DMXURI) { - let start = 0; - let step = 5; - let req = []; - while (allimps.length !== 0) { - if (allimps.length >= 5) { - req.push(allimps.splice(start, step)) - } else { - req.push(allimps.splice(start, allimps.length)) - } - } - return req.map(r => { - dmxRequest.imp = r; - return { - method: 'POST', - url: DMXURI, - data: JSON.stringify(dmxRequest), - bidderRequest - } - }) -} - -/** - * Function matchRequest(id: string, BidRequest: object) - * @param id - * @type string - * @param bidRequest - * @type Object - * @returns Object - * - */ -export function matchRequest(id, bidRequest) { - const { bids } = bidRequest.bidderRequest; - const [returnValue] = bids.filter(bid => bid.bidId === id); - return returnValue; -} -export function checkDeepArray(Arr) { - if (Array.isArray(Arr)) { - if (Array.isArray(Arr[0])) { - return Arr[0]; - } else { - return Arr; - } - } else { - return Arr; - } -} -export function defaultSize(thebidObj) { - const { sizes } = thebidObj; - const returnObject = {}; - returnObject.width = checkDeepArray(sizes)[0]; - returnObject.height = checkDeepArray(sizes)[1]; - return returnObject; -} - -export function bindUserId(eids, value, source, atype) { - if (isStr(value) && Array.isArray(eids)) { - eids.push({ - source, - uids: [ - { - id: value, - atype - } - ] - }) - } -} - -export function getApi({ api }) { - let defaultValue = [2]; - if (api && Array.isArray(api) && api.length > 0) { - return api - } else { - return defaultValue; - } -} -export function getPlaybackmethod(playback) { - if (Array.isArray(playback) && playback.length > 0) { - return playback.map(label => { - return VIDEO_MAPPING.playback_method[label] - }) - } - return [2] -} - -export function getProtocols({ protocols }) { - let defaultValue = [2, 3, 5, 6, 7, 8]; - if (protocols && Array.isArray(protocols) && protocols.length > 0) { - return protocols; - } else { - return defaultValue; - } -} - -export function cleanVast(str, nurl) { - try { - const toberemove = /]*?src\s*=\s*['\"]([^'\"]*?)['\"][^>]*?>/ - const [img, url] = str.match(toberemove) - str = str.replace(toberemove, '') - if (img) { - if (url) { - const insrt = `` - str = str.replace('', `${insrt}`) - } - } - return str; - } catch (e) { - if (!nurl) { - return str - } - const insrt = `` - str = str.replace('', `${insrt}`) - return str - } -} -registerBidder(spec); diff --git a/modules/districtmDmxBidAdapter.md b/modules/districtmDmxBidAdapter.md deleted file mode 100644 index 5d5dd2affe6..00000000000 --- a/modules/districtmDmxBidAdapter.md +++ /dev/null @@ -1,203 +0,0 @@ -``` -Module Name: district m Bid Adapter -Module Type: Bidder Adapter -Maintainer: Steve Alliance (steve@districtm.net) -``` - -# Overview - -The `districtmDmxAdapter` module allows publishers to include DMX Exchange demand using Prebid 1.0+. - -## Attributes - -* Single Request -* Multi-Size Support -* GDPR Compliant -* CCPA Compliant -* COPPA Compliant -* Bids returned in **NET** - - ## Media Types - -* Banner -* Video -## Bidder Parameters - -| Key | Scope | Type | Description -| --- | --- | --- | --- -| `dmxid` | Mandatory | Integer | Unique identifier of the placement, dmxid can be obtained in the district m Boost platform. -| `memberid` | Mandatory | Integer | Unique identifier for your account, memberid can be obtained in the district m Boost platform. -| `floor` | Optional | float | Most placement can have floor set in our platform, but this can now be set on the request too. - -# Ad Unit Configuration Example - -```javascript - var adUnits = [{ - code: 'div-gpt-ad-1460505748561-0', - mediaTypes: { - banner: { - sizes: [[300, 250], [300,600]], - } - }, - bids: [{ - bidder: 'districtmDMX', - params: { - dmxid: 100001, - memberid: 100003 - } - }] - }]; -``` - -# Ad Unit Configuration Example for video request - -```javascript - var videoAdUnit = { - code: 'video1', - sizes: [640,480], - mediaTypes: { video: {context: 'instream', //or 'outstream' - playerSize: [[640, 480]], - skipppable: true, - minduration: 5, - maxduration: 45, - playback_method: ['auto_play_sound_off', 'viewport_sound_off'], - mimes: ["application/javascript", - "video/mp4"], - - } }, - bids: [ - { - bidder: 'districtmDMX', - params: { - dmxid: '100001', - memberid: '100003', - } - } - - ] - }; -``` - - -# Ad Unit Configuration when COPPA is needed - - -# Quick Start Guide - -###### 1. Including the `districtmDmxAdapter` in your build process. - -Add the adapter as an argument to gulp build. - -``` -gulp build --modules=districtmDmxAdapter,ixBidAdapter,appnexusBidAdapter -``` - -*Adding `"districtmDmxAdapter"` as an entry in a JSON file with your bidders is also acceptable.* - -``` -[ - "districtmDmxAdapter", - "ixBidAdapter", - "appnexusBidAdapter" -] -``` - -*Proceed to build with the JSON file.* - -``` -gulp build --modules=bidderModules.json -``` - -###### 2. Configure the ad unit object - -Once Prebid is ready you may use the below example to create the adUnits object and begin building the configuration. - -```javascript -var adUnits = [{ - code: 'div-gpt-ad-1460505748561-0', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600], [728, 90]], - } - }, - bids: [] - } -]; -``` - -###### 3. Add the bidder - -Our demand and adapter supports multiple sizes per placement, as such a single dmxid may be used for all sizes of a single domain. - -```javascript - var adUnits = [{ - code: 'div-gpt-ad-1460505748561-0', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600], [728, 90]], - } - }, - bids: [{ - bidder: 'districtmDMX', - params: { - dmxid: 100001, - memberid: 100003 - } - }] - }]; -``` - -Our bidder only supports instream context at the moment and we strongly like to put the media types and setting in the ad unit settings. -If no value is set the default value will be applied. - -```javascript - var videoAdUnit = { - code: 'video1', - sizes: [640,480], - mediaTypes: { video: {context: 'instream', //or 'outstream' - playerSize: [[640, 480]], - skipppable: true, - minduration: 5, - maxduration: 45, - playback_method: ['auto_play_sound_off', 'viewport_sound_off'], - mimes: ["application/javascript", - "video/mp4"], - - } }, - bids: [ - { - bidder: 'districtmDMX', - params: { - dmxid: '250258', - memberid: '100600', - } - } - ] - }; -``` - -###### 4. Implementation Checking - -Once the bidder is live in your Prebid configuration you may confirm it is making requests to our end point by looking for requests to `https://dmx.districtm.io/b/v1`. - - -###### 5. Setting first party data - -```code -pbjs.setConfig({ - dmx: { - user: { - 'gender': 'M', - 'yob': 1992, - // keywords example - 'keywords': 'automotive,dodge,engine,car' - - }, - site: { - cat: ['IAB-12'], - pagecat: ['IAB-14'], - sectioncat: ['IAB-24'] - } - } -}); -``` diff --git a/test/spec/modules/districtmDmxBidAdapter_spec.js b/test/spec/modules/districtmDmxBidAdapter_spec.js deleted file mode 100644 index 4c060b1f5a4..00000000000 --- a/test/spec/modules/districtmDmxBidAdapter_spec.js +++ /dev/null @@ -1,815 +0,0 @@ -import { expect } from 'chai'; -import * as _ from 'lodash'; -import { spec, matchRequest, checkDeepArray, defaultSize, upto5, cleanSizes, shuffle, getApi, bindUserId, getPlaybackmethod, getProtocols, cleanVast } from '../../../modules/districtmDMXBidAdapter.js'; - -const sample_vast = ` - - - - - - - - - 00:00:15 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -` - -const supportedSize = [ - { - size: [300, 250], - s: 100 - }, - { - size: [728, 90], - s: 95 - }, - { - size: [300, 600], - s: 90 - }, - { - size: [160, 600], - s: 88 - }, - { - size: [320, 50], - s: 85 - }, - { - size: [300, 50], - s: 80 - }, - { - size: [970, 250], - s: 75 - }, - { - size: [970, 90], - s: 60 - }, -]; -const bidRequest = [{ - 'bidder': 'districtmDMX', - 'params': { - 'dmxid': 100001, - 'memberid': 100003, - }, - 'userId': { - idl_env: {}, - digitrustid: { - data: { - id: {} - } - }, - id5id: { - uid: '' - }, - pubcid: {}, - tdid: {}, - criteoId: {}, - britepoolid: {}, - intentiqid: {}, - lotamePanoramaId: {}, - parrableId: {}, - netId: {}, - lipb: { - lipbid: {} - }, - - }, - 'adUnitCode': 'div-gpt-ad-12345678-1', - 'transactionId': 'f6d13fa6-ebc1-41ac-9afa-d8171d22d2c2', - 'sizes': [ - [300, 250], - [300, 600] - ], - 'bidId': '29a28a1bbc8a8d', - 'bidderRequestId': '124b579a136515', - 'auctionId': '3d62f2d3-56a2-4991-888e-f7754619ddcf' -}]; - -const bidRequestVideo = [{ - 'bidder': 'districtmDMX', - 'params': { - 'dmxid': 100001, - 'memberid': 100003, - 'video': { - id: 123, - skipppable: true, - playback_method: ['auto_play_sound_off', 'viewport_sound_off'], - mimes: ['application/javascript', - 'video/mp4'], - } - }, - 'mediaTypes': { - video: { - context: 'instream', // or 'outstream' - playerSize: [[640, 480]] - } - }, - 'adUnitCode': 'div-gpt-ad-12345678-1', - 'transactionId': 'f6d13fa6-ebc1-41ac-9afa-d8171d22d2c2', - 'sizes': [ - [300, 250], - [300, 600] - ], - 'bidId': '29a28a1bbc8a8d', - 'bidderRequestId': '124b579a136515', - 'auctionId': '3d62f2d3-56a2-4991-888e-f7754619ddcf' -}]; -const bidRequestNoCoppa = [{ - 'bidder': 'districtmDMX', - 'params': { - 'dmxid': 100001, - 'memberid': 100003 - }, - 'adUnitCode': 'div-gpt-ad-12345678-1', - 'transactionId': 'f6d13fa6-ebc1-41ac-9afa-d8171d22d2c2', - 'sizes': [ - [300, 250], - [300, 600] - ], - 'bidId': '29a28a1bbc8a8d', - 'bidderRequestId': '124b579a136515', - 'auctionId': '3d62f2d3-56a2-4991-888e-f7754619ddcf' -}]; -const bidderRequest = { - 'bidderCode': 'districtmDMX', - 'auctionId': '3d62f2d3-56a2-4991-888e-f7754619ddcf', - 'bidderRequestId': '124b579a136515', - 'bids': [{ - 'bidder': 'districtmDMX', - 'params': { - 'dmxid': 100001, - 'memberid': 100003, - }, - 'adUnitCode': 'div-gpt-ad-12345678-1', - 'transactionId': 'f6d13fa6-ebc1-41ac-9afa-d8171d22d2c2', - 'sizes': [ - [300, 250], - [300, 600] - ], - 'bidId': '29a28a1bbc8a8d', - 'bidderRequestId': '124b579a136515', - 'auctionId': '3d62f2d3-56a2-4991-888e-f7754619ddcf' - }], - 'auctionStart': 1529511035677, - 'timeout': 700, - 'uspConsent': '1NY', - 'gdprConsent': { - 'consentString': 'BOPqNzUOPqNzUAHABBAAA5AAAAAAAA', - 'vendorData': { - 'metadata': 'BOPqNzUOPqNzUAHABBAAA5AAAAAAAA', - 'hasGlobalScope': false, - 'gdprApplies': true, - 'purposeConsents': { - '1': false, - '2': false, - '3': false, - '4': false, - '5': false - }, - 'vendorConsents': { - '1': false, - '2': false, - '3': false, - '4': false, - '6': false, - '7': false, - '8': false, - '9': false, - '10': false, - '11': false, - '12': false, - '13': false, - '14': false, - '15': false, - '16': false, - '17': false, - '18': false, - '19': false, - '20': false, - '21': false, - '22': false, - '23': false, - '24': false, - '25': false, - '26': false, - '27': false, - '28': false, - '29': false, - '30': false, - '31': false, - '32': false, - '33': false, - '34': false, - '35': false, - '36': false, - '37': false, - '38': false, - '39': false, - '40': false, - '41': false, - '42': false, - '43': false, - '44': false, - '45': false, - '46': false, - '47': false, - '48': false, - '49': false, - '50': false, - '51': false, - '52': false, - '53': false, - '55': false, - '56': false, - '57': false, - '58': false, - '59': false, - '60': false, - '61': false, - '62': false, - '63': false, - '64': false, - '65': false, - '66': false, - '67': false, - '68': false, - '69': false, - '70': false, - '71': false, - '72': false, - '73': false, - '74': false, - '75': false, - '76': false, - '77': false, - '78': false, - '79': false, - '80': false, - '81': false, - '82': false, - '83': false, - '84': false, - '85': false, - '86': false, - '87': false, - '88': false, - '89': false, - '90': false, - '91': false, - '92': false, - '93': false, - '94': false, - '95': false, - '97': false, - '98': false, - '100': false, - '101': false, - '102': false, - '104': false, - '105': false, - '108': false, - '109': false, - '110': false, - '111': false, - '112': false, - '113': false, - '114': false, - '115': false, - '119': false, - '120': false, - '122': false, - '124': false, - '125': false, - '126': false, - '127': false, - '128': false, - '129': false, - '130': false, - '131': false, - '132': false, - '133': false, - '134': false, - '136': false, - '138': false, - '139': false, - '140': false, - '141': false, - '142': false, - '143': false, - '144': false, - '145': false, - '147': false, - '148': false, - '149': false, - '150': false, - '151': false, - '152': false, - '153': false, - '154': false, - '155': false, - '156': false, - '157': false, - '158': false, - '159': false, - '160': false, - '161': false, - '162': false, - '163': false, - '164': false, - '165': false, - '167': false, - '168': false, - '169': false, - '170': false, - '171': false, - '173': false, - '174': false, - '175': false, - '177': false, - '178': false, - '179': false, - '180': false, - '182': false, - '183': false, - '184': false, - '185': false, - '188': false, - '189': false, - '190': false, - '191': false, - '192': false, - '193': false, - '194': false, - '195': false, - '197': false, - '198': false, - '199': false, - '200': false, - '201': false, - '202': false, - '203': false, - '205': false, - '206': false, - '208': false, - '209': false, - '210': false, - '211': false, - '212': false, - '213': false, - '214': false, - '215': false, - '216': false, - '217': false, - '218': false, - '223': false, - '224': false, - '225': false, - '226': false, - '227': false, - '228': false, - '229': false, - '230': false, - '231': false, - '232': false, - '234': false, - '235': false, - '236': false, - '237': false, - '238': false, - '239': false, - '240': false, - '241': false, - '242': false, - '244': false, - '245': false, - '246': false, - '248': false, - '249': false, - '250': false, - '251': false, - '252': false, - '253': false, - '254': false, - '255': false, - '256': false, - '257': false, - '258': false, - '259': false, - '260': false, - '261': false, - '262': false, - '263': false, - '264': false, - '265': false, - '266': false, - '269': false, - '270': false, - '272': false, - '273': false, - '274': false, - '275': false, - '276': false, - '277': false, - '278': false, - '279': false, - '280': false, - '281': false, - '282': false, - '284': false, - '285': false, - '288': false, - '289': false, - '290': false, - '291': false, - '294': false, - '295': false, - '297': false, - '299': false, - '301': false, - '302': false, - '303': false, - '304': false, - '308': false, - '309': false, - '310': false, - '311': false, - '312': false, - '314': false, - '315': false, - '316': false, - '317': false, - '318': false, - '319': false, - '320': false, - '323': false, - '325': false, - '326': false, - '328': false, - '329': false, - '330': false, - '331': false, - '333': false, - '337': false, - '339': false, - '341': false, - '343': false, - '344': false, - '345': false, - '347': false, - '349': false, - '350': false, - '351': false, - '354': false, - '358': false, - '359': false, - '360': false, - '361': false, - '368': false, - '369': false, - '371': false, - '373': false, - '376': false, - '377': false, - '378': false, - '380': false, - '382': false, - '384': false, - '385': false, - '387': false, - '388': false, - '389': false, - '390': false, - '391': false, - '398': false, - '400': false, - '402': false, - '403': false, - '404': false, - '413': false, - '415': false, - '421': false, - '422': false - } - }, - 'gdprApplies': true - }, - 'start': 1529511035686, - 'doneCbCallCount': 0 -}; - -const bidderRequestNoCoppa = { - 'bidderCode': 'districtmDMX', - 'auctionId': '3d62f2d3-56a2-4991-888e-f7754619ddcf', - 'bidderRequestId': '124b579a136515', - 'bids': [{ - 'bidder': 'districtmDMX', - 'params': { - 'dmxid': 100001, - 'memberid': 100003, - }, - 'adUnitCode': 'div-gpt-ad-12345678-1', - 'transactionId': 'f6d13fa6-ebc1-41ac-9afa-d8171d22d2c2', - 'sizes': [ - [300, 250], - [300, 600] - ], - 'bidId': '29a28a1bbc8a8d', - 'bidderRequestId': '124b579a136515', - 'auctionId': '3d62f2d3-56a2-4991-888e-f7754619ddcf' - }], - 'auctionStart': 1529511035677, - 'timeout': 700, - 'start': 1529511035686, - 'doneCbCallCount': 0 -}; - -const responses = { - 'body': { - 'id': '1f45b37c-5298-4934-b517-4d911aadabfd', - 'cur': 'USD', - 'seatbid': [{ - 'bid': [{ - 'id': '29a28a1bbc8a8d', - 'impid': '29a28a1bbc8a8d', - 'price': '6.42', - 'adm': '
' - }] - }] - }, - 'headers': {} -}; - -const responsesNegative = { - 'body': { - 'id': '1f45b37c-5298-4934-b517-4d911aadabfd', - 'cur': 'USD', - 'seatbid': [{ - 'bid': [{ - 'id': '29a28a1bbc8a8d', - 'impid': '29a28a1bbc8a8d', - 'price': '-0.10', - 'adm': '
' - }] - }] - }, - 'headers': {} -}; - -const emptyResponse = { body: {} }; -const emptyResponseSeatBid = { body: { seatbid: [] } }; - -describe('DistrictM Adaptor', function () { - const districtm = spec; - describe('verification of upto5', function () { - it('upto5 function should always break 12 imps into 3 request same for 15', function () { - expect(upto5([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], bidRequest, bidderRequest, 'https://google').length).to.be.equal(3) - expect(upto5([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], bidRequest, bidderRequest, 'https://google').length).to.be.equal(3) - }) - }) - - describe('test vast tag', function () { - it('img tag should not be present', function () { - expect(cleanVast(sample_vast).indexOf('img') !== -1).to.be.equal(false) - }) - }) - describe('Test getApi function', function () { - const data = { - api: [1] - } - it('Will return 1 for vpaid version 1', function () { - expect(getApi(data)[0]).to.be.equal(1) - }) - it('Will return 2 for vpaid default', function () { - expect(getApi({})[0]).to.be.equal(2) - }) - }) - - describe('Test cleanSizes function', function () { - it('sequence will be respected', function () { - expect(cleanSizes(bidderRequest.bids[0].sizes).toString()).to.be.equal('300,250,300,600') - }) - it('sequence will be respected', function () { - expect(cleanSizes([[728, 90], [970, 90], [300, 600], [320, 50]]).toString()).to.be.equal('728,90,320,50,300,600,970,90') - }) - }) - - describe('Test getPlaybackmethod function', function () { - it('getPlaybackmethod will return 2', function () { - expect(getPlaybackmethod([])[0]).to.be.equal(2) - }) - it('getPlaybackmethod will return 6', function () { - expect(getPlaybackmethod(['viewport_sound_off'])[0]).to.be.equal(6) - }) - }) - - describe('Test getProtocols function', function () { - it('getProtocols will return 3', function () { - expect(getProtocols({ protocols: [3] })[0]).to.be.equal(3) - }) - it('getProtocols will return 6', function () { - expect(_.isEqual(getProtocols({}), [2, 3, 5, 6, 7, 8])).to.be.equal(true) - }) - }) - - describe('All needed functions are available', function () { - it(`isBidRequestValid is present and type function`, function () { - expect(districtm.isBidRequestValid).to.exist.and.to.be.a('function') - }); - - it(`BuildRequests is present and type function`, function () { - expect(districtm.buildRequests).to.exist.and.to.be.a('function') - }); - - it(`interpretResponse is present and type function`, function () { - expect(districtm.interpretResponse).to.exist.and.to.be.a('function') - }); - - it(`getUserSyncs is present and type function`, function () { - expect(districtm.getUserSyncs).to.exist.and.to.be.a('function') - }); - }); - - describe(`these properties are available or not`, function () { - it(`code should have a value of districtmDMX`, function () { - expect(districtm.code).to.be.equal('districtmDMX'); - }); - - it(`timeout should not be defined`, function () { - expect(districtm.onTimeout).to.be.an('undefined'); - }); - }); - - describe(`isBidRequestValid test response`, function () { - let params = { - dmxid: 10001, // optional - memberid: 10003, - }; - it(`function should return true`, function () { - expect(districtm.isBidRequestValid({ params })).to.be.equal(true); - }); - it(`function should return false`, function () { - expect(districtm.isBidRequestValid({ params: {} })).to.be.equal(false); - }); - it(`expect to have memberid`, function () { - expect(params).to.have.property('memberid'); - }); - }); - - describe(`getUserSyncs test usage`, function () { - it(`return value should be an array`, function () { - expect(districtm.getUserSyncs({ iframeEnabled: true })).to.be.an('array'); - }); - it(`array should have only one object and it should have a property type = 'iframe'`, function () { - expect(districtm.getUserSyncs({ iframeEnabled: true }).length).to.be.equal(1); - let [userSync] = districtm.getUserSyncs({ iframeEnabled: true }); - expect(userSync).to.have.property('type'); - expect(userSync.type).to.be.equal('iframe'); - }); - }); - - describe(`buildRequests test usage`, function () { - const buildRequestResults = districtm.buildRequests(bidRequest, bidderRequest); - const buildRequestResultsNoCoppa = districtm.buildRequests(bidRequestNoCoppa, bidderRequestNoCoppa); - it(`the function should return an array`, function () { - expect(buildRequestResults).to.be.an('object'); - }); - it(`contain gdpr consent & ccpa`, function () { - const bidr = JSON.parse(buildRequestResults.data) - expect(bidr.regs.ext.gdpr).to.be.equal(1); - expect(bidr.regs.ext.us_privacy).to.be.equal('1NY'); - expect(bidr.user.ext.consent).to.be.an('string'); - }); - it(`test contain COPPA`, function () { - const bidr = JSON.parse(buildRequestResults.data) - bidr.regs = bidr.regs || {}; - bidr.regs.coppa = 1; - expect(bidr.regs.coppa).to.be.equal(1) - }) - it(`test should not contain COPPA`, function () { - const bidr = JSON.parse(buildRequestResultsNoCoppa.data) - expect(bidr.regs.coppa).to.be.equal(0) - }) - it(`the function should return array length of 1`, function () { - expect(buildRequestResults.data).to.be.a('string'); - }); - }); - - describe('bidRequest Video testing', function () { - const request = districtm.buildRequests(bidRequestVideo, bidRequestVideo); - const data = JSON.parse(request.data) - expect(data instanceof Object).to.be.equal(true) - }) - - describe(`interpretResponse test usage`, function () { - const responseResults = districtm.interpretResponse(responses, { bidderRequest }); - const emptyResponseResults = districtm.interpretResponse(emptyResponse, { bidderRequest }); - const emptyResponseResultsNegation = districtm.interpretResponse(responsesNegative, { bidderRequest }); - const emptyResponseResultsEmptySeat = districtm.interpretResponse(emptyResponseSeatBid, { bidderRequest }); - it(`the function should return an array`, function () { - expect(responseResults).to.be.an('array'); - }); - it(`the function should return array length of 1`, function () { - expect(responseResults.length).to.be.equal(1); - }); - it(`the response return nothing`, function () { - expect(emptyResponseResults.length).to.be.equal(0); - }); - it(`the response seatbid return nothing`, function () { - expect(emptyResponseResultsEmptySeat.length).to.be.equal(0); - }); - - it(`on invalid CPM`, function () { - expect(emptyResponseResultsNegation.length).to.be.equal(0); - }); - }); - - describe(`check validation for id sync gdpr ccpa`, () => { - let allin = spec.getUserSyncs({ iframeEnabled: true }, {}, bidderRequest.gdprConsent, bidderRequest.uspConsent)[0] - let noCCPA = spec.getUserSyncs({ iframeEnabled: true }, {}, bidderRequest.gdprConsent, null)[0] - let noGDPR = spec.getUserSyncs({ iframeEnabled: true }, {}, null, bidderRequest.uspConsent)[0] - let nothing = spec.getUserSyncs({ iframeEnabled: true }, {}, null, null)[0] - - /* - - 'uspConsent': '1NY', - 'gdprConsent': { - 'consentString': 'BOPqNzUOPqNzUAHABBAAA5AAAAAAAA', - */ - it(`gdpr & ccpa should be present`, () => { - expect(allin.url).to.be.equal('https://cdn.districtm.io/ids/index.html?gdpr=BOPqNzUOPqNzUAHABBAAA5AAAAAAAA&ccpa=1NY') - }) - it(`ccpa should be present`, () => { - expect(noGDPR.url).to.be.equal('https://cdn.districtm.io/ids/index.html?ccpa=1NY') - }) - it(`gdpr should be present`, () => { - expect(noCCPA.url).to.be.equal('https://cdn.districtm.io/ids/index.html?gdpr=BOPqNzUOPqNzUAHABBAAA5AAAAAAAA') - }) - it(`gdpr & ccpa shouldn't be present`, () => { - expect(nothing.url).to.be.equal('https://cdn.districtm.io/ids/index.html') - }) - }) - - describe(`Helper function testing`, function () { - const bid = matchRequest('29a28a1bbc8a8d', { bidderRequest }); - const { width, height } = defaultSize(bid); - it(`test matchRequest`, function () { - expect(matchRequest('29a28a1bbc8a8d', { bidderRequest })).to.be.an('object'); - }); - it(`test checkDeepArray`, function () { - expect(_.isEqual(checkDeepArray([728, 90]), [728, 90])).to.be.equal(true); - expect(_.isEqual(checkDeepArray([[728, 90]]), [728, 90])).to.be.equal(true); - expect(_.isEqual(checkDeepArray([[728, 90], [300, 250]]), [728, 90])).to.be.equal(true); - expect(_.isEqual(checkDeepArray([[300, 250], [300, 250]]), [728, 90])).to.be.equal(false); - expect(_.isEqual(checkDeepArray([300, 250]), [300, 250])).to.be.equal(true); - }); - it(`test defaultSize`, function () { - expect(width).to.be.equal(300); - expect(height).to.be.equal(250); - }); - }); -});