diff --git a/integrationExamples/gpt/hello_world_adikteev.html b/integrationExamples/gpt/hello_world_emoteev.html similarity index 91% rename from integrationExamples/gpt/hello_world_adikteev.html rename to integrationExamples/gpt/hello_world_emoteev.html index 7372ff12d7f..5e4d0716d2b 100644 --- a/integrationExamples/gpt/hello_world_adikteev.html +++ b/integrationExamples/gpt/hello_world_emoteev.html @@ -21,12 +21,10 @@ } }, bids: [{ - bidder: 'adikteev', - params: { - placementId: 13144370, - stagingEnvironment: true, - bidFloorPrice: 0.1, - } + bidder: 'emoteev', + params: { + adSpaceId: 5084, + } }] }]; diff --git a/integrationExamples/gpt/pbjs_example_gpt.html b/integrationExamples/gpt/pbjs_example_gpt.html index 32452d33fd9..3a32eb5dbd6 100644 --- a/integrationExamples/gpt/pbjs_example_gpt.html +++ b/integrationExamples/gpt/pbjs_example_gpt.html @@ -314,12 +314,10 @@ height: '250', } }, - { - bidder: 'adikteev', + { + bidder: 'emoteev', params: { - placementId: 12345, - currency: 'EUR', - bidFloorPrice: 0.1, + adSpaceId: 5084, } }, ] diff --git a/modules/adikteevBidAdapter.js b/modules/adikteevBidAdapter.js deleted file mode 100644 index a0b0ed9cdcf..00000000000 --- a/modules/adikteevBidAdapter.js +++ /dev/null @@ -1,94 +0,0 @@ -import {registerBidder} from '../src/adapters/bidderFactory'; -import {BANNER} from '../src/mediaTypes'; -import * as utils from '../src/utils'; -import {config} from '../src/config'; - -export const BIDDER_CODE = 'adikteev'; -export const ENDPOINT_URL = 'https://serve-adserver.adikteev.com/api/prebid/bid'; -export const ENDPOINT_URL_STAGING = 'https://serve-adserver-staging.adikteev.com/api/prebid/bid'; -export const USER_SYNC_IFRAME_URL = 'https://serve-adserver.adikteev.com/api/prebid/sync-iframe'; -export const USER_SYNC_IFRAME_URL_STAGING = 'https://serve-adserver-staging.adikteev.com/api/prebid/sync-iframe'; -export const USER_SYNC_IMAGE_URL = 'https://serve-adserver.adikteev.com/api/prebid/sync-image'; -export const USER_SYNC_IMAGE_URL_STAGING = 'https://serve-adserver-staging.adikteev.com/api/prebid/sync-image'; - -export let stagingEnvironmentSwitch = false; // Don't use it. Allow us to make tests on staging - -export function setstagingEnvironmentSwitch(value) { - stagingEnvironmentSwitch = value; -} - -function validateSizes(sizes) { - if (!utils.isArray(sizes) || typeof sizes[0] === 'undefined') { - return false; - } - return sizes.every(size => utils.isArray(size) && size.length === 2); -} - -export const spec = { - code: BIDDER_CODE, - supportedMediaTypes: [BANNER], - - isBidRequestValid: (bid) => { - setstagingEnvironmentSwitch(stagingEnvironmentSwitch || !!bid.params.stagingEnvironment); - return !!( - bid && - bid.params && - bid.params.bidFloorPrice && - bid.params.placementId && - bid.bidder === BIDDER_CODE && - validateSizes(bid.mediaTypes.banner.sizes) - ); - }, - - buildRequests: (validBidRequests, bidderRequest) => { - const payload = { - validBidRequests, - bidderRequest, - refererInfo: bidderRequest.refererInfo, - currency: config.getConfig('currency'), - userAgent: navigator.userAgent, - screen: { - width: window.screen.width, - height: window.screen.height - }, - language: navigator.language, - cookies: document.cookie.split(';'), - prebidUpdateVersion: '1.29.0', - }; - return { - method: 'POST', - url: stagingEnvironmentSwitch ? ENDPOINT_URL_STAGING : ENDPOINT_URL, - data: JSON.stringify(payload), - }; - }, - - interpretResponse: (serverResponse, bidRequests) => { - const returnedBids = []; - const validBidRequests = JSON.parse(bidRequests.data).validBidRequests; - serverResponse.body.forEach((value, index) => { - const overrides = { - requestId: validBidRequests[index].bidId, - }; - returnedBids.push(Object.assign({}, value, overrides)); - }); - return returnedBids; - }, - - getUserSyncs: (syncOptions, serverResponses) => { - const syncs = []; - if (syncOptions.iframeEnabled) { - syncs.push({ - type: 'iframe', - url: stagingEnvironmentSwitch ? USER_SYNC_IFRAME_URL_STAGING : USER_SYNC_IFRAME_URL, - }); - } - if (syncOptions.pixelEnabled && serverResponses.length > 0) { - syncs.push({ - type: 'image', - url: stagingEnvironmentSwitch ? USER_SYNC_IMAGE_URL_STAGING : USER_SYNC_IMAGE_URL, - }); - } - return syncs; - }, -}; -registerBidder(spec); diff --git a/modules/adikteevBidAdapter.md b/modules/emokteevBidAdapter.md similarity index 55% rename from modules/adikteevBidAdapter.md rename to modules/emokteevBidAdapter.md index d5008f61b03..88b0b21a96f 100644 --- a/modules/adikteevBidAdapter.md +++ b/modules/emokteevBidAdapter.md @@ -1,14 +1,14 @@ # Overview ``` -Module Name: Adikteev Bidder Adapter +Module Name: Emoteev Bidder Adapter Module Type: Bidder Adapter -Maintainer: adnetwork@adikteev.com +Maintainer: engineering@emoteev.io ``` # Description -Module that connects to Adikteev's demand sources +Module that connects to Emoteev's demand sources # Test Parameters @@ -18,15 +18,14 @@ Module that connects to Adikteev's demand sources code: 'test-div', mediaTypes: { banner: { - sizes: [[750, 200]], // a display size + sizes: [[300, 250]], } }, bids: [ { - bidder: 'adikteev', + bidder: 'emoteev', params: { - placementId: 12345, - bidFloorPrice: 0.1, + adSpaceId: 5084 } } ] diff --git a/modules/emoteevBidAdapter.js b/modules/emoteevBidAdapter.js new file mode 100644 index 00000000000..9b03b357818 --- /dev/null +++ b/modules/emoteevBidAdapter.js @@ -0,0 +1,214 @@ +import {registerBidder} from '../src/adapters/bidderFactory'; +import {BANNER} from '../src/mediaTypes'; +import * as utils from '../src/utils'; +import {config} from '../src/config'; + +export const BIDDER_CODE = 'emoteev'; +export const AK_PBJS_VERSION = '1.35.0'; + +export const EMOTEEV_BASE_URL = 'https://prebid.emoteev.io'; +export const EMOTEEV_BASE_URL_STAGING = 'https://prebid-staging.emoteev.io'; +export const EMOTEEV_BASE_URL_DEVELOPMENT = 'http://localhost:3000'; + +export const ENDPOINT_PATH = '/api/prebid/bid'; +export const USER_SYNC_IFRAME_URL_PATH = '/api/prebid/sync-iframe'; +export const USER_SYNC_IMAGE_URL_PATH = '/api/prebid/sync-image'; + +export const PRODUCTION = 'production'; +export const STAGING = 'staging'; +export const DEVELOPMENT = 'development'; +export const DEFAULT_ENV = PRODUCTION; + +export const conformBidRequest = bidRequest => { + return { + params: bidRequest.params, + crumbs: bidRequest.crumbs, + sizes: bidRequest.sizes, + bidId: bidRequest.bidId, + bidderRequestId: bidRequest.bidderRequestId, + }; +}; + +export const emoteevDebug = (parameterDebug, configDebug) => { + if (parameterDebug && parameterDebug.length && parameterDebug.length > 0) return JSON.parse(parameterDebug); + else if (configDebug) return configDebug; + else return false; +}; + +export const emoteevEnv = (parameteremoteevEnv, configemoteevEnv) => { + if (utils.contains([PRODUCTION, STAGING, DEVELOPMENT], parameteremoteevEnv)) return parameteremoteevEnv; + else if (utils.contains([PRODUCTION, STAGING, DEVELOPMENT], configemoteevEnv)) return configemoteevEnv; + else return DEFAULT_ENV; +}; + +export const emoteevOverrides = (parameteremoteevOverrides, configemoteevOverrides) => { + if (parameteremoteevOverrides && parameteremoteevOverrides.length !== 0) { + let parsedParams = null; + try { + parsedParams = JSON.parse(parameteremoteevOverrides); + } catch (error) { + parsedParams = null; + } + if (parsedParams) return parsedParams; + } + if (configemoteevOverrides && Object.keys(configemoteevOverrides).length !== 0) return configemoteevOverrides; + else return {}; +}; + +export const akUrl = (environment) => { + switch (environment) { + case DEVELOPMENT: + return EMOTEEV_BASE_URL_DEVELOPMENT; + case STAGING: + return EMOTEEV_BASE_URL_STAGING; + default: + return EMOTEEV_BASE_URL; + } +}; + +export const endpointUrl = (parameteremoteevEnv, configemoteevEnv) => akUrl(emoteevEnv(parameteremoteevEnv, configemoteevEnv)).concat(ENDPOINT_PATH); +export const userSyncIframeUrl = (parameteremoteevEnv, configemoteevEnv) => akUrl(emoteevEnv(parameteremoteevEnv, configemoteevEnv)).concat(USER_SYNC_IFRAME_URL_PATH); +export const userSyncImageUrl = (parameteremoteevEnv, configemoteevEnv) => akUrl(emoteevEnv(parameteremoteevEnv, configemoteevEnv)).concat(USER_SYNC_IMAGE_URL_PATH); + +export const getViewDimensions = () => { + let w = window; + let prefix = 'inner'; + + if (window.innerWidth === undefined || window.innerWidth === null) { + w = document.documentElement || document.body; + prefix = 'client'; + } + + return { + width: w[`${prefix}Width`], + height: w[`${prefix}Height`], + }; +}; + +export const getDeviceDimensions = () => { + return { + width: window.screen ? window.screen.width : '', + height: window.screen ? window.screen.height : '', + }; +}; + +export const getDocumentDimensions = () => { + const de = document.documentElement; + const be = document.body; + + const bodyHeight = be ? Math.max(be.offsetHeight, be.scrollHeight) : 0; + + const w = Math.max(de.clientWidth, de.offsetWidth, de.scrollWidth); + const h = Math.max( + de.clientHeight, + de.offsetHeight, + de.scrollHeight, + bodyHeight + ); + + return { + width: isNaN(w) ? '' : w, + height: isNaN(h) ? '' : h, + }; +}; + +export const isWebGLEnabled = () => { + // Create test canvas + let canvas = document.createElement('canvas'); + + // The gl context + let gl = null; + + // Try to get the regular WebGL + try { + gl = canvas.getContext('webgl'); + } catch (ex) { + canvas = undefined; + return false; + } + + // No regular WebGL found + if (!gl) { + // Try experimental WebGL + try { + gl = canvas.getContext('experimental-webgl'); + } catch (ex) { + canvas = undefined; + return false; + } + } + + return !!gl; +}; + +export const getDeviceInfo = (deviceDimensions, viewDimensions, documentDimensions, webGL) => { + return { + browserWidth: viewDimensions.width, + browserHeight: viewDimensions.height, + deviceWidth: deviceDimensions.width, + deviceHeight: deviceDimensions.height, + documentWidth: documentDimensions.width, + documentHeight: documentDimensions.height, + webGL: webGL, + }; +}; + +const validateSizes = sizes => utils.isArray(sizes) && sizes.some(size => utils.isArray(size) && size.length === 2); + +export const spec = { + code: BIDDER_CODE, + supportedMediaTypes: [BANNER], + + isBidRequestValid: (bid) => { + return !!( + bid && + bid.params && + bid.params.adSpaceId && + bid.bidder === BIDDER_CODE && + validateSizes(bid.mediaTypes.banner.sizes) + ); + }, + + buildRequests: (validBidRequests, bidderRequest) => { + const payload = Object.assign({}, + { + akPbjsVersion: AK_PBJS_VERSION, + bidRequests: validBidRequests.map(conformBidRequest), + currency: config.getConfig('currency'), + debug: emoteevDebug(utils.getParameterByName('emoteevDebug'), config.getConfig('emoteev.debug')), + language: navigator.language, + refererInfo: bidderRequest.refererInfo, + deviceInfo: getDeviceInfo(getDeviceDimensions(), getViewDimensions(), getDocumentDimensions(), isWebGLEnabled()), + userAgent: navigator.userAgent, + }, + emoteevOverrides(utils.getParameterByName('emoteevOverrides'), config.getConfig('emoteev.overrides'))); + + return { + method: 'POST', + url: endpointUrl(utils.getParameterByName('emoteevEnv'), config.getConfig('emoteev.env')), + data: JSON.stringify(payload), + }; + }, + + interpretResponse: (serverResponse) => serverResponse.body, + + getUserSyncs: (syncOptions, serverResponses) => { + const parameteremoteevEnv = utils.getParameterByName('emoteev.env'); + const configemoteevEnv = config.getConfig('emoteev.env'); + const syncs = []; + if (syncOptions.iframeEnabled) { + syncs.push({ + type: 'iframe', + url: userSyncIframeUrl(parameteremoteevEnv, configemoteevEnv), + }); + } + if (syncOptions.pixelEnabled && serverResponses.length > 0) { + syncs.push({ + type: 'image', + url: userSyncImageUrl(parameteremoteevEnv, configemoteevEnv), + }); + } + return syncs; + }, +}; +registerBidder(spec); diff --git a/test/spec/modules/adikteevBidAdapter_spec.js b/test/spec/modules/adikteevBidAdapter_spec.js deleted file mode 100644 index 243cbe2a9c5..00000000000 --- a/test/spec/modules/adikteevBidAdapter_spec.js +++ /dev/null @@ -1,235 +0,0 @@ -import {expect} from 'chai'; -import { - ENDPOINT_URL, - ENDPOINT_URL_STAGING, - setstagingEnvironmentSwitch, - spec, - stagingEnvironmentSwitch, - USER_SYNC_IFRAME_URL, - USER_SYNC_IFRAME_URL_STAGING, - USER_SYNC_IMAGE_URL, - USER_SYNC_IMAGE_URL_STAGING, -} from 'modules/adikteevBidAdapter'; -import {newBidder} from 'src/adapters/bidderFactory'; -import * as utils from '../../../src/utils'; - -describe('adikteevBidAdapter', () => { - const adapter = newBidder(spec); - - describe('inherited functions', () => { - it('exists and is a function', () => { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - it('exists and is a function', () => { - expect(setstagingEnvironmentSwitch).to.exist.and.to.be.a('function'); - }); - it('exists and is correctly set', () => { - expect(stagingEnvironmentSwitch).to.exist.and.to.equal(false); - }); - }); - - describe('isBidRequestValid', () => { - it('should return true when required params found', () => { - const validBid = { - bidder: 'adikteev', - params: { - placementId: 12345, - bidFloorPrice: 0.1, - }, - mediaTypes: { - banner: { - sizes: [[750, 200]] - } - }, - }; - expect(spec.isBidRequestValid(validBid)).to.equal(true); - }); - - it('should mutate stagingEnvironmentSwitch when required params found', () => { - const withstagingEnvironmentSwitch = { - params: { - stagingEnvironment: true, - }, - }; - spec.isBidRequestValid(withstagingEnvironmentSwitch); - expect(stagingEnvironmentSwitch).to.equal(true); - setstagingEnvironmentSwitch(false); - }); - - it('should return false when required params are invalid', () => { - expect(spec.isBidRequestValid({ - bidder: '', // invalid bidder - params: { - placementId: 12345, - bidFloorPrice: 0.1, - }, - mediaTypes: { - banner: { - sizes: [[750, 200]] - } - }, - })).to.equal(false); - expect(spec.isBidRequestValid({ - bidder: 'adikteev', - params: { - placementId: '', // invalid placementId - bidFloorPrice: 0.1, - }, - mediaTypes: { - banner: { - sizes: [[750, 200]] - } - }, - })).to.equal(false); - expect(spec.isBidRequestValid({ - bidder: 'adikteev', - params: { - placementId: 12345, - bidFloorPrice: 0.1, - }, - mediaTypes: { - banner: { - sizes: [[750]] // invalid size - } - }, - })).to.equal(false); - }); - }); - - describe('buildRequests', () => { - const validBidRequests = []; - const bidderRequest = {}; - const serverRequest = spec.buildRequests(validBidRequests, bidderRequest); - it('creates a request object with correct method, url and data', () => { - expect(serverRequest).to.exist.and.have.all.keys( - 'method', - 'url', - 'data', - ); - expect(serverRequest.method).to.equal('POST'); - expect(serverRequest.url).to.equal(ENDPOINT_URL); - - let requestData = JSON.parse(serverRequest.data); - expect(requestData).to.exist.and.have.all.keys( - 'validBidRequests', - 'bidderRequest', - 'userAgent', - 'screen', - 'language', - 'cookies', - // 'refererInfo', - // 'currency', - 'prebidUpdateVersion', - ); - expect(requestData.validBidRequests).to.deep.equal(validBidRequests); - expect(requestData.bidderRequest).to.deep.equal(bidderRequest); - expect(requestData.userAgent).to.deep.equal(navigator.userAgent); - expect(requestData.screen.width).to.deep.equal(window.screen.width); - expect(requestData.screen.height).to.deep.equal(window.screen.height); - expect(requestData.language).to.deep.equal(navigator.language); - expect(requestData.prebidUpdateVersion).to.deep.equal('1.29.0'); - }); - - describe('staging environment', () => { - setstagingEnvironmentSwitch(true); - const serverRequest = spec.buildRequests(validBidRequests, bidderRequest); - expect(serverRequest.url).to.equal(ENDPOINT_URL_STAGING); - setstagingEnvironmentSwitch(false); - }); - }); - - describe('interpretResponse', () => { - it('bid objects from response', () => { - const serverResponse = - { - body: [ - { - cpm: 1, - width: 300, - height: 250, - ad: '
', - ttl: 360, - creativeId: 123, - netRevenue: false, - currency: 'EUR', - } - ] - }; - const payload = { - validBidRequests: [{ - bidId: '2ef7bb021ac847' - }], - }; - const bidRequests = { - method: 'POST', - url: stagingEnvironmentSwitch ? ENDPOINT_URL_STAGING : ENDPOINT_URL, - data: JSON.stringify(payload), - }; - const bidResponses = spec.interpretResponse(serverResponse, bidRequests); - expect(bidResponses).to.be.an('array').that.is.not.empty; // yes, syntax is correct - expect(bidResponses[0]).to.have.all.keys( - 'requestId', - 'cpm', - 'width', - 'height', - 'ad', - 'ttl', - 'creativeId', - 'netRevenue', - 'currency', - ); - - expect(bidResponses[0].requestId).to.equal(payload.validBidRequests[0].bidId); - expect(bidResponses[0].cpm).to.equal(serverResponse.body[0].cpm); - expect(bidResponses[0].width).to.equal(serverResponse.body[0].width); - expect(bidResponses[0].height).to.equal(serverResponse.body[0].height); - expect(bidResponses[0].ad).to.equal(serverResponse.body[0].ad); - expect(bidResponses[0].ttl).to.equal(serverResponse.body[0].ttl); - expect(bidResponses[0].creativeId).to.equal(serverResponse.body[0].creativeId); - expect(bidResponses[0].netRevenue).to.equal(serverResponse.body[0].netRevenue); - expect(bidResponses[0].currency).to.equal(serverResponse.body[0].currency); - }); - }); - - describe('getUserSyncs', () => { - expect(spec.getUserSyncs({ - iframeEnabled: true - }, [{}])).to.deep.equal([{ - type: 'iframe', - url: USER_SYNC_IFRAME_URL - }]); - - expect(spec.getUserSyncs({ - pixelEnabled: true - }, [{}])).to.deep.equal([{ - type: 'image', - url: USER_SYNC_IMAGE_URL - }]); - - expect(spec.getUserSyncs({ - iframeEnabled: true, - pixelEnabled: true - }, [{}])).to.deep.equal([{ - type: 'iframe', - url: USER_SYNC_IFRAME_URL - }, { - type: 'image', - url: USER_SYNC_IMAGE_URL - }]); - - describe('staging environment', () => { - setstagingEnvironmentSwitch(true); - expect(spec.getUserSyncs({ - iframeEnabled: true, - pixelEnabled: true - }, [{}])).to.deep.equal([{ - type: 'iframe', - url: USER_SYNC_IFRAME_URL_STAGING - }, { - type: 'image', - url: USER_SYNC_IMAGE_URL_STAGING - }]); - setstagingEnvironmentSwitch(false); - }); - }); -}); diff --git a/test/spec/modules/emoteevBidAdapter_spec.js b/test/spec/modules/emoteevBidAdapter_spec.js new file mode 100644 index 00000000000..a5f5c439e6f --- /dev/null +++ b/test/spec/modules/emoteevBidAdapter_spec.js @@ -0,0 +1,349 @@ +import {expect} from 'chai'; +import { + AK_PBJS_VERSION, + EMOTEEV_BASE_URL, + EMOTEEV_BASE_URL_STAGING, + emoteevDebug, + emoteevEnv, + emoteevOverrides, + akUrl, + conformBidRequest, + DEFAULT_ENV, + ENDPOINT_PATH, + endpointUrl, + PRODUCTION, + spec, + STAGING, + USER_SYNC_IFRAME_URL_PATH, + USER_SYNC_IMAGE_URL_PATH, + userSyncIframeUrl, + userSyncImageUrl, +} from 'modules/emoteevBidAdapter'; +import {newBidder} from 'src/adapters/bidderFactory'; +import {config} from 'src/config'; + +const cannedValidBidRequests = [{ + adUnitCode: '/19968336/header-bid-tag-1', + auctionId: 'fcbf2b27-a951-496f-b5bb-1324ce7c0558', + bidId: '2b8de6572e8193', + bidRequestsCount: 1, + bidder: 'emoteev', + bidderRequestId: '1203b39fecc6a5', + crumbs: {pubcid: 'f3371d16-4e8b-42b5-a770-7e5be1fdf03d'}, + params: {adSpaceId: 5084}, + sizes: [[300, 250], [250, 300], [300, 600]], + transactionId: '58dbd732-7a39-45f1-b23e-1c24051a941c', +}]; +const cannedBidderRequest = { + auctionId: 'fcbf2b27-a951-496f-b5bb-1324ce7c0558', + auctionStart: 1544200122837, + bidderCode: 'emoteev', + bidderRequestId: '1203b39fecc6a5', + doneCbCallCount: 0, + refererInfo: { + canonicalUrl: undefined, + numIframes: 0, + reachedTop: true, + referer: 'http://localhost:9999/integrationExamples/gpt/hello_world_emoteev.html', + stack: ['http://localhost:9999/integrationExamples/gpt/hello_world_emoteev.html'] + }, + start: 1544200012839, + timeout: 3000 +}; +const serverResponse = + { + body: [ + { + requestId: cannedValidBidRequests[0].bidId, + cpm: 1, + width: cannedValidBidRequests[0].sizes[0][0], + height: cannedValidBidRequests[0].sizes[0][1], + ad: '', + ttl: 360, + creativeId: 123, + netRevenue: false, + currency: 'EUR', + } + ] + }; + +describe('emoteevBidAdapter', function () { + const adapter = newBidder(spec); + + describe('inherited functions', function () { + it('exists and is a function', function () { + expect(adapter.callBids).to.exist.and.to.be.a('function'); + }); + }); + + describe('conformBidRequest', function () { + it('returns a bid-request', function () { + expect(conformBidRequest(cannedValidBidRequests[0])).to.deep.equal({ + params: cannedValidBidRequests[0].params, + crumbs: cannedValidBidRequests[0].crumbs, + sizes: cannedValidBidRequests[0].sizes, + bidId: cannedValidBidRequests[0].bidId, + bidderRequestId: cannedValidBidRequests[0].bidderRequestId, + }); + }) + }); + + describe('emoteevDebug', function () { + expect(emoteevDebug(null, null)).to.deep.equal(false) + }); + describe('emoteevDebug', function () { + expect(emoteevDebug(null, true)).to.deep.equal(true) + }); + describe('emoteevDebug', function () { + expect(emoteevDebug(JSON.stringify(true), null)).to.deep.equal(true) + }); + + describe('emoteevEnv', function () { + expect(emoteevEnv(null, null)).to.deep.equal(DEFAULT_ENV) + }); + describe('emoteevEnv', function () { + expect(emoteevEnv(null, STAGING)).to.deep.equal(STAGING) + }); + describe('emoteevEnv', function () { + expect(emoteevEnv(STAGING, null)).to.deep.equal(STAGING) + }); + + describe('emoteevOverrides', function () { + expect(emoteevOverrides(null, null)).to.deep.equal({}) + }); + describe('emoteevOverrides', function () { + expect(emoteevOverrides(JSON.stringify({a: 1}), null)).to.deep.equal({a: 1}) + }); + describe('emoteevOverrides', function () { + expect(emoteevOverrides('incorrect', null)).to.deep.equal({}) + }); // expect no exception + describe('emoteevOverrides', function () { + expect(emoteevOverrides(null, {a: 1})).to.deep.equal({a: 1}) + }); + + describe('akUrl', function () { + expect(akUrl(null)).to.deep.equal(EMOTEEV_BASE_URL) + }); + describe('akUrl', function () { + expect(akUrl('anything')).to.deep.equal(EMOTEEV_BASE_URL) + }); + describe('akUrl', function () { + expect(akUrl(STAGING)).to.deep.equal(EMOTEEV_BASE_URL_STAGING) + }); + describe('akUrl', function () { + expect(akUrl('production')).to.deep.equal(EMOTEEV_BASE_URL) + }); + + describe('endpointUrl', function () { + expect(endpointUrl(null, null)).to.deep.equal(EMOTEEV_BASE_URL.concat(ENDPOINT_PATH)) + }); + describe('endpointUrl', function () { + expect(endpointUrl(null, STAGING)).to.deep.equal(EMOTEEV_BASE_URL_STAGING.concat(ENDPOINT_PATH)) + }); + describe('endpointUrl', function () { + expect(endpointUrl(STAGING, null)).to.deep.equal(EMOTEEV_BASE_URL_STAGING.concat(ENDPOINT_PATH)) + }); + + describe('userSyncIframeUrl', function () { + expect(userSyncIframeUrl(null, null)).to.deep.equal(EMOTEEV_BASE_URL.concat(USER_SYNC_IFRAME_URL_PATH)) + }); + describe('userSyncIframeUrl', function () { + expect(userSyncIframeUrl(null, STAGING)).to.deep.equal(EMOTEEV_BASE_URL_STAGING.concat(USER_SYNC_IFRAME_URL_PATH)) + }); + describe('userSyncIframeUrl', function () { + expect(userSyncIframeUrl(STAGING, null)).to.deep.equal(EMOTEEV_BASE_URL_STAGING.concat(USER_SYNC_IFRAME_URL_PATH)) + }); + + describe('userSyncImageUrl', function () { + expect(userSyncImageUrl(null, null)).to.deep.equal(EMOTEEV_BASE_URL.concat(USER_SYNC_IMAGE_URL_PATH)) + }); + describe('userSyncImageUrl', function () { + expect(userSyncImageUrl(null, STAGING)).to.deep.equal(EMOTEEV_BASE_URL_STAGING.concat(USER_SYNC_IMAGE_URL_PATH)) + }); + describe('userSyncImageUrl', function () { + expect(userSyncImageUrl(STAGING, null)).to.deep.equal(EMOTEEV_BASE_URL_STAGING.concat(USER_SYNC_IMAGE_URL_PATH)) + }); + + describe('isBidRequestValid', function () { + it('should return true when required params found', function () { + const validBid = { + bidder: 'emoteev', + params: { + adSpaceId: 12345, + }, + mediaTypes: { + banner: { + sizes: [[750, 200]] + } + }, + }; + expect(spec.isBidRequestValid(validBid)).to.equal(true); + }); + + it('should return false when required params are invalid', function () { + expect(spec.isBidRequestValid({ + bidder: '', // invalid bidder + params: { + adSpaceId: 12345, + }, + mediaTypes: { + banner: { + sizes: [[750, 200]] + } + }, + })).to.equal(false); + expect(spec.isBidRequestValid({ + bidder: 'emoteev', + params: { + adSpaceId: '', // invalid adSpaceId + }, + mediaTypes: { + banner: { + sizes: [[750, 200]] + } + }, + })).to.equal(false); + expect(spec.isBidRequestValid({ + bidder: 'emoteev', + params: { + adSpaceId: 12345, + }, + mediaTypes: { + banner: { + sizes: [[750]] // invalid size + } + }, + })).to.equal(false); + }); + }); + + describe('buildRequests', function () { + const + currency = 'EUR', + emoteevEnv = STAGING, + emoteevDebug = true, + emoteevOverrides = { + iAmOverride: 'iAmOverride' + }; + config.setConfig({ // asynchronous + currency, + emoteev: { + env: STAGING, + debug: emoteevDebug, + overrides: emoteevOverrides + } + }); + + config.getConfig('emoteev', function () { + const request = spec.buildRequests(cannedValidBidRequests, cannedBidderRequest); + + it('creates a request object with correct method, url and data', function () { + expect(request).to.exist.and.have.all.keys( + 'method', + 'url', + 'data', + ); + expect(request.method).to.equal('POST'); + expect(request.url).to.equal(endpointUrl(emoteevEnv, emoteevEnv)); + + let requestData = JSON.parse(request.data); + expect(requestData).to.exist.and.have.all.keys( + 'akPbjsVersion', + 'bidRequests', + 'currency', + 'debug', + 'iAmOverride', + 'language', + 'refererInfo', + 'deviceInfo', + 'userAgent', + ); + + expect(requestData.bidRequests[0]).to.exist.and.have.all.keys( + 'params', + 'crumbs', + 'sizes', + 'bidId', + 'bidderRequestId', + ); + + expect(requestData.akPbjsVersion).to.deep.equal(AK_PBJS_VERSION); + expect(requestData.bidRequests[0].params).to.deep.equal(cannedValidBidRequests[0].params); + expect(requestData.bidRequests[0].crumbs).to.deep.equal(cannedValidBidRequests[0].crumbs); + expect(requestData.bidRequests[0].mediaTypes).to.deep.equal(cannedValidBidRequests[0].mediaTypes); + expect(requestData.bidRequests[0].bidId).to.deep.equal(cannedValidBidRequests[0].bidId); + expect(requestData.bidRequests[0].bidderRequestId).to.deep.equal(cannedValidBidRequests[0].bidderRequestId); + expect(requestData.currency).to.deep.equal(currency); + expect(requestData.debug).to.deep.equal(emoteevDebug); + expect(requestData.iAmOverride).to.deep.equal('iAmOverride'); + expect(requestData.language).to.deep.equal(navigator.language); + expect(requestData.deviceInfo).to.exist.and.have.all.keys( + 'browserWidth', + 'browserHeight', + 'deviceWidth', + 'deviceHeight', + 'documentWidth', + 'documentHeight', + 'webGL', + ); + expect(requestData.userAgent).to.deep.equal(navigator.userAgent); + }); + }); + }); + + describe('interpretResponse', function () { + it('bid objects from response', function () { + const bidResponses = spec.interpretResponse(serverResponse); + expect(bidResponses).to.be.an('array').that.is.not.empty; // yes, syntax is correct + expect(bidResponses[0]).to.have.all.keys( + 'requestId', + 'cpm', + 'width', + 'height', + 'ad', + 'ttl', + 'creativeId', + 'netRevenue', + 'currency', + ); + + expect(bidResponses[0].requestId).to.equal(cannedValidBidRequests[0].bidId); + expect(bidResponses[0].cpm).to.equal(serverResponse.body[0].cpm); + expect(bidResponses[0].width).to.equal(serverResponse.body[0].width); + expect(bidResponses[0].height).to.equal(serverResponse.body[0].height); + expect(bidResponses[0].ad).to.equal(serverResponse.body[0].ad); + expect(bidResponses[0].ttl).to.equal(serverResponse.body[0].ttl); + expect(bidResponses[0].creativeId).to.equal(serverResponse.body[0].creativeId); + expect(bidResponses[0].netRevenue).to.equal(serverResponse.body[0].netRevenue); + expect(bidResponses[0].currency).to.equal(serverResponse.body[0].currency); + }); + }); + + describe('getUserSyncs', function () { + config.setConfig({emoteevEnv: PRODUCTION}); + expect(spec.getUserSyncs({ + iframeEnabled: true + }, [{}])).to.deep.equal([{ + type: 'iframe', + url: EMOTEEV_BASE_URL.concat(USER_SYNC_IFRAME_URL_PATH) + }]); + + expect(spec.getUserSyncs({ + pixelEnabled: true + }, [{}])).to.deep.equal([{ + type: 'image', + url: EMOTEEV_BASE_URL.concat(USER_SYNC_IMAGE_URL_PATH) + }]); + + expect(spec.getUserSyncs({ + iframeEnabled: true, + pixelEnabled: true + }, [{}])).to.deep.equal([{ + type: 'iframe', + url: EMOTEEV_BASE_URL.concat(USER_SYNC_IFRAME_URL_PATH) + }, { + type: 'image', + url: EMOTEEV_BASE_URL.concat(USER_SYNC_IMAGE_URL_PATH) + }]); + }); +});