From 6e15c6a6b46f0e5355f897ab3e281a2ad9281cbb Mon Sep 17 00:00:00 2001 From: andrey_ka_97 Date: Fri, 13 Aug 2021 14:41:35 +0300 Subject: [PATCH] update AFP Adapter and add page examples --- integrationExamples/gpt/afpExample.html | 115 +++++++ integrationExamples/gpt/afpGamExample.html | 152 ++++++++++ modules/afpBidAdapter.js | 170 +++++++++++ modules/afpBidAdapter.md | 215 +++++++++++++ modules/astraoneBidAdapter.js | 137 --------- modules/astraoneBidAdapter.md | 202 ------------- test/spec/modules/afpBidAdapter_spec.js | 302 +++++++++++++++++++ test/spec/modules/astraoneBidAdapter_spec.js | 212 ------------- 8 files changed, 954 insertions(+), 551 deletions(-) create mode 100644 integrationExamples/gpt/afpExample.html create mode 100644 integrationExamples/gpt/afpGamExample.html create mode 100644 modules/afpBidAdapter.js create mode 100644 modules/afpBidAdapter.md delete mode 100644 modules/astraoneBidAdapter.js delete mode 100644 modules/astraoneBidAdapter.md create mode 100644 test/spec/modules/afpBidAdapter_spec.js delete mode 100644 test/spec/modules/astraoneBidAdapter_spec.js diff --git a/integrationExamples/gpt/afpExample.html b/integrationExamples/gpt/afpExample.html new file mode 100644 index 00000000000..e3782e93c89 --- /dev/null +++ b/integrationExamples/gpt/afpExample.html @@ -0,0 +1,115 @@ + + + + + Prebid.js Banner Example + + + + +

In-image

+
+
+ +
+ +
+ +

In-content Video

+
+
+ +
+ +

Action Scroller

+
+
+ +
+ + diff --git a/integrationExamples/gpt/afpGamExample.html b/integrationExamples/gpt/afpGamExample.html new file mode 100644 index 00000000000..48d79cc812b --- /dev/null +++ b/integrationExamples/gpt/afpGamExample.html @@ -0,0 +1,152 @@ + + + + + Prebid.js Banner Example + + + + + +

In-image

+
+
+ +
+
+ +
+
+ +

In-content Video

+
+
+
+ +
+
+ +

Action Scroller

+
+
+
+ +
+
+ + diff --git a/modules/afpBidAdapter.js b/modules/afpBidAdapter.js new file mode 100644 index 00000000000..a61cc430ec9 --- /dev/null +++ b/modules/afpBidAdapter.js @@ -0,0 +1,170 @@ +import { registerBidder } from '../src/adapters/bidderFactory.js' +import { Renderer } from '../src/Renderer.js' +import { BANNER, VIDEO } from '../src/mediaTypes.js' + +export const IS_DEV = location.hostname === 'localhost' +export const BIDDER_CODE = 'afp' +export const SSP_ENDPOINT = 'https://ssp.afp.ai/api/prebid' +export const REQUEST_METHOD = 'POST' +export const TEST_PAGE_URL = 'https://rtbinsight.ru/smiert-bolshikh-dannykh-kto-na-novienkogo/' +const SDK_PATH = 'https://cdn.afp.ai/ssp/sdk.js?auto_initialization=false&deploy_to_parent_window=true' +const TTL = 60 +export const IN_IMAGE_BANNER_TYPE = 'In-image' +export const IN_IMAGE_MAX_BANNER_TYPE = 'In-image Max' +export const IN_CONTENT_BANNER_TYPE = 'In-content Banner' +export const IN_CONTENT_VIDEO_TYPE = 'In-content Video' +export const OUT_CONTENT_VIDEO_TYPE = 'Out-content Video' +export const IN_CONTENT_STORY_TYPE = 'In-content Stories' +export const ACTION_SCROLLER_TYPE = 'Action Scroller' +export const ACTION_SCROLLER_LIGHT_TYPE = 'Action Scroller Light' + +export const mediaTypeByPlaceType = { + [IN_IMAGE_BANNER_TYPE]: BANNER, + [IN_IMAGE_MAX_BANNER_TYPE]: BANNER, + [IN_CONTENT_BANNER_TYPE]: BANNER, + [IN_CONTENT_STORY_TYPE]: BANNER, + [ACTION_SCROLLER_TYPE]: BANNER, + [ACTION_SCROLLER_LIGHT_TYPE]: BANNER, + [IN_CONTENT_VIDEO_TYPE]: VIDEO, + [OUT_CONTENT_VIDEO_TYPE]: VIDEO, +} + +const wrapAd = (dataToCreatePlace) => { + return ` + + + + + + + + + + ` +} + +const bidRequestMap = {} + +const createRenderer = (bid, dataToCreatePlace) => { + const renderer = new Renderer({ + targetId: bid.adUnitCode, + url: SDK_PATH, + callback() { + renderer.loaded = true + window.afp.createPlaceByData(dataToCreatePlace) + } + }) + + return renderer +} + +export const spec = { + code: BIDDER_CODE, + supportedMediaTypes: [BANNER, VIDEO], + isBidRequestValid({mediaTypes, params}) { + if (typeof params !== 'object' || typeof mediaTypes !== 'object') { + return false + } + + const {placeId, placeType, imageUrl, imageWidth, imageHeight} = params + const media = mediaTypes[mediaTypeByPlaceType[placeType]] + + if (placeId && media) { + if (mediaTypeByPlaceType[placeType] === VIDEO) { + if (!media.playerSize) { + return false + } + } else if (mediaTypeByPlaceType[placeType] === BANNER) { + if (!media.sizes) { + return false + } + } + if ([IN_IMAGE_BANNER_TYPE, IN_IMAGE_MAX_BANNER_TYPE].includes(placeType)) { + if (imageUrl && imageWidth && imageHeight) { + return true + } + } else { + return true + } + } + return false + }, + buildRequests(validBidRequests, {refererInfo, gdprConsent}) { + const payload = { + pageUrl: IS_DEV ? TEST_PAGE_URL : refererInfo.referer, + gdprConsent: gdprConsent, + bidRequests: validBidRequests.map(validBidRequest => { + const {bidId, transactionId, sizes, params: { + placeId, placeType, imageUrl, imageWidth, imageHeight + }} = validBidRequest + bidRequestMap[bidId] = validBidRequest + const bidRequest = { + bidId, + transactionId, + sizes, + placeId, + } + if ([IN_IMAGE_BANNER_TYPE, IN_IMAGE_MAX_BANNER_TYPE].includes(placeType)) { + Object.assign(bidRequest, { + imageUrl, + imageWidth: Math.floor(imageWidth), + imageHeight: Math.floor(imageHeight), + }) + } + return bidRequest + }) + } + + return { + method: REQUEST_METHOD, + url: SSP_ENDPOINT, + data: payload, + options: { + contentType: 'application/json' + } + } + }, + interpretResponse(serverResponse) { + let bids = serverResponse.body && serverResponse.body.bids + bids = Array.isArray(bids) ? bids : [] + + return bids.map(({bidId, cpm, width, height, creativeId, currency, netRevenue, adSettings, placeSettings}, index) => { + const bid = { + requestId: bidId, + cpm, + width, + height, + creativeId, + currency, + netRevenue, + meta: { + mediaType: mediaTypeByPlaceType[placeSettings.placeType], + }, + ttl: TTL + } + + const bidRequest = bidRequestMap[bidId] + const placeContainer = bidRequest.params.placeContainer + const dataToCreatePlace = { adSettings, placeSettings, placeContainer, isPrebid: true } + + if ([ + IN_IMAGE_BANNER_TYPE, + IN_IMAGE_MAX_BANNER_TYPE, + IN_CONTENT_BANNER_TYPE, + IN_CONTENT_STORY_TYPE, + ACTION_SCROLLER_TYPE, + ACTION_SCROLLER_LIGHT_TYPE, + ].includes(placeSettings.placeType)) { + bid.ad = wrapAd(dataToCreatePlace) + } else if ([IN_CONTENT_VIDEO_TYPE, OUT_CONTENT_VIDEO_TYPE].includes(placeSettings.placeType)) { + bid.vastXml = adSettings.content + bid.renderer = createRenderer(bid, dataToCreatePlace) + } + return bid + }) + } +} + +registerBidder(spec); diff --git a/modules/afpBidAdapter.md b/modules/afpBidAdapter.md new file mode 100644 index 00000000000..a1b05a1cd08 --- /dev/null +++ b/modules/afpBidAdapter.md @@ -0,0 +1,215 @@ +# Overview + + +**Module Name**: AstraLab Bidder Adapter +**Module Type**: Bidder Adapter +**Maintainer**: devops@astraone.io + +# Description + +You can use this adapter to get a bid from AstraLab. +Please reach out to your AstraLab account team before using this plugin to get placeId. +The code below returns a demo ad. + +About us: https://astralab.ai, https://afp.ai + +# Test Parameters +```js +var adUnits = [{ + code: 'iib-target', + mediaTypes: { + banner: { + sizes: [[0, 0]], + } + }, + bids: [{ + bidder: "afp", + params: { + placeType: "In-image", // or "In-image Max" + placeId: "60e7039918047b3fae304850", + placeContainer: '#iib-container', + imageUrl: "https://rtbinsight.ru/content/images/size/w1000/2021/05/ximage-30.png.pagespeed.ic.IfuX4zAEPP.png", + imageWidth: 1000, + imageHeight: 524, + } + }] +}]; + +var adUnits = [{ + code: 'iib-target', + mediaTypes: { + banner: { + sizes: [[0, 0]], + } + }, + bids: [{ + bidder: "afp", + params: { + placeType: "In-content Banner", // or "In-content Stories" or "Action Scroller" or "Action Scroller Light" + placeId: "60e7039918047b3fae304850", + placeContainer: '#iib-container', + } + }] +}]; + +var adUnits = [{ + code: 'iib-target', + mediaTypes: { + video: { + playerSize: [[480, 320]], + } + }, + bids: [{ + bidder: "afp", + params: { + placeType: "In-content Video", // or "Out-content Video" + placeId: "60e7039918047b3fae304850", + placeContainer: '#iib-container', + } + }] +}]; +``` + +# Example page + +```html + + + + + Prebid.js In-image Example + + + + +

In-image

+
+
+ +
+ +
+ + + +``` +# Example page with GPT + +```html + + + + + Prebid.js In-image Example + + + + + +

In-image

+
+
+ +
+
+ +
+
+ + +``` diff --git a/modules/astraoneBidAdapter.js b/modules/astraoneBidAdapter.js deleted file mode 100644 index 2fec3892d27..00000000000 --- a/modules/astraoneBidAdapter.js +++ /dev/null @@ -1,137 +0,0 @@ -import * as utils from '../src/utils.js' -import { registerBidder } from '../src/adapters/bidderFactory.js' -import { BANNER } from '../src/mediaTypes.js' - -const BIDDER_CODE = 'astraone'; -const SSP_ENDPOINT = 'https://ssp.astraone.io/auction/prebid'; -const TTL = 60; - -function buildBidRequests(validBidRequests) { - return utils._map(validBidRequests, function(validBidRequest) { - const params = validBidRequest.params; - const bidRequest = { - bidId: validBidRequest.bidId, - transactionId: validBidRequest.transactionId, - sizes: validBidRequest.sizes, - placement: params.placement, - placeId: params.placeId, - imageUrl: params.imageUrl - }; - - return bidRequest; - }) -} - -function buildBid(bidData) { - const bid = { - requestId: bidData.bidId, - cpm: bidData.price, - width: bidData.width, - height: bidData.height, - creativeId: bidData.content.seanceId, - currency: bidData.currency, - netRevenue: true, - meta: { - mediaType: BANNER, - }, - ttl: TTL, - content: bidData.content - }; - - bid.ad = wrapAd(bid, bidData); - - return bid; -} - -function getMediaTypeFromBid(bid) { - return bid.mediaTypes && Object.keys(bid.mediaTypes)[0] -} - -function wrapAd(bid, bidData) { - return ` - - - - - - - - -
- - - `; -} - -export const spec = { - code: BIDDER_CODE, - supportedMediaTypes: [BANNER], - - /** - * Determines whether or not the given bid request is valid. - * - * @param {BidRequest} bid The bid params to validate. - * @return boolean True if this is a valid bid, and false otherwise. - */ - isBidRequestValid(bid) { - return ( - getMediaTypeFromBid(bid) === BANNER && - !!bid.params.placeId && - !!bid.params.imageUrl && - !!bid.params.placement && - (bid.params.placement === 'inImage') - ); - }, - - /** - * Make a server request from the list of BidRequests. - * - * @param {validBidRequests[]} - an array of bids - * @return ServerRequest Info describing the request to the server. - */ - buildRequests(validBidRequests, bidderRequest) { - const payload = { - url: bidderRequest.refererInfo.referer, - cmp: !!bidderRequest.gdprConsent, - bidRequests: buildBidRequests(validBidRequests) - }; - - if (payload.cmp) { - const gdprApplies = bidderRequest.gdprConsent.gdprApplies; - if (gdprApplies !== undefined) payload['ga'] = gdprApplies; - payload['cs'] = bidderRequest.gdprConsent.consentString; - } - - const payloadString = JSON.stringify(payload); - return { - method: 'POST', - url: SSP_ENDPOINT, - data: payloadString, - options: { - contentType: 'application/json' - } - } - }, - - /** - * Unpack the response from the server into a list of bids. - * - * @param {ServerResponse} serverResponse A successful response from the server. - * @return {Bid[]} An array of bids which were nested inside the server. - */ - interpretResponse: function(serverResponse) { - const bids = serverResponse.body && serverResponse.body.bids; - - return Array.isArray(bids) ? bids.map(bid => buildBid(bid)) : [] - } - -} -registerBidder(spec); diff --git a/modules/astraoneBidAdapter.md b/modules/astraoneBidAdapter.md deleted file mode 100644 index e090cfe1e54..00000000000 --- a/modules/astraoneBidAdapter.md +++ /dev/null @@ -1,202 +0,0 @@ -# Overview - - -**Module Name**: AstraOne Bidder Adapter -**Module Type**: Bidder Adapter -**Maintainer**: prebid@astraone.io - -# Description - -You can use this adapter to get a bid from AstraOne. -Please reach out to your AstraOne account team before using this plugin to get placeId. -The code below returns a demo ad. - -About us: https://astraone.io - -# Test Parameters -```js -var adUnits = [{ - code: 'test-div', - mediaTypes: { - banner: { - sizes: [1, 1], - } - }, - bids: [{ - bidder: "astraone", - params: { - placement: "inImage", - placeId: "5f477bf94d506ebe2c4240f3", - imageUrl: "https://creative.astraone.io/files/default_image-1-600x400.jpg" - } - }] -}]; -``` - -# Example page - -```html - - - - - Prebid.js Banner Example - - - - - - -

Prebid.js InImage Banner Test

- -
- - -
- - - -``` -# Example page with GPT - -```html - - - - - Prebid.js Banner gpt Example - - - - - - -

Prebid.js InImage Banner gpt Test

- -
- - - -
- - -``` diff --git a/test/spec/modules/afpBidAdapter_spec.js b/test/spec/modules/afpBidAdapter_spec.js new file mode 100644 index 00000000000..c220d052ead --- /dev/null +++ b/test/spec/modules/afpBidAdapter_spec.js @@ -0,0 +1,302 @@ +import cloneDeep from 'lodash/cloneDeep' +import unset from 'lodash/unset' +import { expect } from 'chai' +import { BANNER, VIDEO } from '../../../src/mediaTypes.js' +import { + spec, + IN_IMAGE_BANNER_TYPE, + IN_IMAGE_MAX_BANNER_TYPE, + IN_CONTENT_BANNER_TYPE, + IN_CONTENT_VIDEO_TYPE, + OUT_CONTENT_VIDEO_TYPE, + IN_CONTENT_STORY_TYPE, + ACTION_SCROLLER_TYPE, + ACTION_SCROLLER_LIGHT_TYPE, + BIDDER_CODE, + SSP_ENDPOINT, + REQUEST_METHOD, + TEST_PAGE_URL, + IS_DEV, mediaTypeByPlaceType +} from 'modules/afpBidAdapter.js' + +const placeId = '60e7039918047b3fae304850' +const bidId = '2a67c5577ff6a5' +const transactionId = '7e8515a2-2ed9-4733-b976-6c2596a03287' +const imageUrl = 'https://rtbinsight.ru/content/images/size/w1000/2021/05/ximage-30.png.pagespeed.ic.IfuX4zAEPP.png' +const placeContainer = '#container' +const imageWidth = 600 +const imageHeight = 400 +const pageUrl = IS_DEV ? TEST_PAGE_URL : 'referer' +const sizes = [[imageWidth, imageHeight]] +const bidderRequest = { + refererInfo: { referer: pageUrl }, +} +const mediaTypeBanner = { [BANNER]: {sizes: [[imageWidth, imageHeight]]} } +const mediaTypeVideo = { [VIDEO]: {playerSize: [[imageWidth, imageHeight]]} } +const commonParams = { + placeId, + placeContainer, +} +const commonParamsForInImage = Object.assign({}, commonParams, { + imageUrl, + imageWidth, + imageHeight, +}) +const configByPlaceType = { + get [IN_IMAGE_BANNER_TYPE]() { + return cloneDeep({ + mediaTypes: mediaTypeBanner, + params: Object.assign({}, commonParamsForInImage, { + placeType: IN_IMAGE_BANNER_TYPE + }), + }) + }, + get [IN_IMAGE_MAX_BANNER_TYPE]() { + return cloneDeep({ + mediaTypes: mediaTypeBanner, + params: Object.assign({}, commonParamsForInImage, { + placeType: IN_IMAGE_MAX_BANNER_TYPE + }), + }) + }, + get [IN_CONTENT_BANNER_TYPE]() { + return cloneDeep({ + mediaTypes: mediaTypeBanner, + params: Object.assign({}, commonParams, { + placeType: IN_CONTENT_BANNER_TYPE + }), + }) + }, + get [IN_CONTENT_VIDEO_TYPE]() { + return cloneDeep({ + mediaTypes: mediaTypeVideo, + params: Object.assign({}, commonParams, { + placeType: IN_CONTENT_VIDEO_TYPE + }), + }) + }, + get [OUT_CONTENT_VIDEO_TYPE]() { + return cloneDeep({ + mediaTypes: mediaTypeVideo, + params: Object.assign({}, commonParams, { + placeType: OUT_CONTENT_VIDEO_TYPE + }), + }) + }, + get [IN_CONTENT_STORY_TYPE]() { + return cloneDeep({ + mediaTypes: mediaTypeBanner, + params: Object.assign({}, commonParams, { + placeType: IN_CONTENT_STORY_TYPE + }), + }) + }, + get [ACTION_SCROLLER_TYPE]() { + return cloneDeep({ + mediaTypes: mediaTypeBanner, + params: Object.assign({}, commonParams, { + placeType: ACTION_SCROLLER_TYPE + }), + }) + }, + get [ACTION_SCROLLER_LIGHT_TYPE]() { + return cloneDeep({ + mediaTypes: mediaTypeBanner, + params: Object.assign({}, commonParams, { + placeType: ACTION_SCROLLER_LIGHT_TYPE + }), + }) + }, +} +const getTransformedConfig = ({mediaTypes, params}) => { + return { + params: params, + sizes, + bidId, + bidder: BIDDER_CODE, + mediaTypes: mediaTypes, + transactionId, + } +} +const validBidRequests = Object.values(configByPlaceType).map(config => getTransformedConfig(config)) + +describe('AFP Adapter', function() { + describe('isBidRequestValid method', function() { + describe('returns true', function() { + describe('when config has all mandatory params', () => { + Object.entries(configByPlaceType).forEach(([placeType, config]) => { + it(`and ${placeType} config has the correct value`, function() { + const isBidRequestValid = spec.isBidRequestValid(config) + expect(isBidRequestValid).to.equal(true) + }) + }) + }) + }) + describe('returns false', function() { + const checkMissingParams = (placesTypes, missingParams) => + placesTypes.forEach(placeType => + missingParams.forEach(missingParam => { + const config = configByPlaceType[placeType] + it(`${placeType} does not have the ${missingParam}.`, function() { + unset(config, missingParam) + const isBidRequestValid = spec.isBidRequestValid(config) + expect(isBidRequestValid).to.equal(false) + }) + }) + ) + + describe('when params are not correct', function() { + checkMissingParams(Object.keys(configByPlaceType), ['params.placeId', 'params.placeType']) + checkMissingParams([IN_IMAGE_BANNER_TYPE, IN_IMAGE_MAX_BANNER_TYPE], + ['params.imageUrl', 'params.imageWidth', 'params.imageHeight']) + + it('does not have a the correct placeType.', function() { + const config = configByPlaceType[IN_IMAGE_BANNER_TYPE] + config.params.placeType = 'something' + const isBidRequestValid = spec.isBidRequestValid(config) + expect(isBidRequestValid).to.equal(false) + }) + }) + describe('when video mediaType object is not correct.', function() { + checkMissingParams([IN_CONTENT_VIDEO_TYPE, OUT_CONTENT_VIDEO_TYPE], + [`mediaTypes.${VIDEO}.playerSize`, `mediaTypes.${VIDEO}`]) + checkMissingParams([ + IN_IMAGE_BANNER_TYPE, + IN_IMAGE_MAX_BANNER_TYPE, + IN_CONTENT_BANNER_TYPE, + IN_CONTENT_STORY_TYPE, + ACTION_SCROLLER_TYPE, + ACTION_SCROLLER_LIGHT_TYPE + ], [`mediaTypes.${BANNER}.sizes`, `mediaTypes.${BANNER}`]) + }) + }) + }) + + describe('buildRequests method', function() { + const request = spec.buildRequests(validBidRequests, bidderRequest) + + it('Url should be correct', function() { + expect(request.url).to.equal(SSP_ENDPOINT) + }) + + it('Method should be correct', function() { + expect(request.method).to.equal(REQUEST_METHOD) + }) + + describe('Common data request should be correct', function() { + it('pageUrl should be correct', function() { + expect(request.data.pageUrl).to.equal(pageUrl) + }) + it('bidRequests should be array', function() { + expect(Array.isArray(request.data.bidRequests)).to.equal(true) + }) + + request.data.bidRequests.forEach((bid, index) => { + describe(`bid with ${validBidRequests[index].params.placeType} should be correct`, function() { + it('bidId should be correct', function() { + expect(bid.bidId).to.equal(bidId) + }) + it('placeId should be correct', function() { + expect(bid.placeId).to.equal(placeId) + }) + it('transactionId should be correct', function() { + expect(bid.transactionId).to.equal(transactionId) + }) + it('sizes should be correct', function() { + expect(bid.sizes).to.equal(sizes) + }) + + if ([IN_IMAGE_BANNER_TYPE, IN_IMAGE_MAX_BANNER_TYPE].includes(validBidRequests[index].params.placeType)) { + it('imageUrl should be correct', function() { + expect(bid.imageUrl).to.equal(imageUrl) + }) + it('imageWidth should be correct', function() { + expect(bid.imageWidth).to.equal(Math.floor(imageWidth)) + }) + it('imageHeight should be correct', function() { + expect(bid.imageHeight).to.equal(Math.floor(imageHeight)) + }) + } + }) + }) + }) + }) + + describe('interpretResponse method', function() { + it('should return a void array, when the server response are not correct.', function() { + const request = { data: JSON.stringify({}) } + const serverResponse = { + body: {} + } + const bids = spec.interpretResponse(serverResponse, request) + expect(Array.isArray(bids)).to.equal(true) + expect(bids.length).to.equal(0) + }) + it('should return a void array, when the server response have not got bids.', function() { + const request = { data: JSON.stringify({}) } + const serverResponse = { body: { bids: [] } } + const bids = spec.interpretResponse(serverResponse, request) + expect(Array.isArray(bids)).to.equal(true) + expect(bids.length).to.equal(0) + }) + describe('when the server response return a bids', function() { + Object.keys(configByPlaceType).forEach(placeType => { + it(`should return a bid with ${placeType} placeType`, function() { + const cpm = 10 + const currency = 'RUB' + const creativeId = '123' + const netRevenue = true + const width = sizes[0][0] + const height = sizes[0][1] + const adSettings = { + content: 'html' + } + const placeSettings = { + placeType, + } + const request = spec.buildRequests([validBidRequests[0]], bidderRequest) + const serverResponse = { + body: { + bids: [ + { + bidId, + cpm, + currency, + creativeId, + netRevenue, + width, + height, + adSettings, + placeSettings, + } + ] + } + } + const bids = spec.interpretResponse(serverResponse, request) + expect(bids.length).to.equal(1) + expect(bids[0].requestId).to.equal(bidId) + expect(bids[0].meta.mediaType).to.equal(mediaTypeByPlaceType[placeSettings.placeType]) + expect(bids[0].cpm).to.equal(cpm) + expect(bids[0].width).to.equal(width) + expect(bids[0].height).to.equal(height) + expect(bids[0].currency).to.equal(currency) + expect(bids[0].netRevenue).to.equal(netRevenue) + + if ([ + IN_IMAGE_BANNER_TYPE, + IN_IMAGE_MAX_BANNER_TYPE, + IN_CONTENT_BANNER_TYPE, + IN_CONTENT_STORY_TYPE, + ACTION_SCROLLER_TYPE, + ACTION_SCROLLER_LIGHT_TYPE, + ].includes(placeSettings.placeType)) { + expect(typeof bids[0].ad).to.equal('string') + } else if ([IN_CONTENT_VIDEO_TYPE, OUT_CONTENT_VIDEO_TYPE].includes(placeSettings.placeType)) { + expect(typeof bids[0].vastXml).to.equal('string') + expect(typeof bids[0].renderer).to.equal('object') + } + }) + }) + }) + }) +}) diff --git a/test/spec/modules/astraoneBidAdapter_spec.js b/test/spec/modules/astraoneBidAdapter_spec.js deleted file mode 100644 index 0e545081869..00000000000 --- a/test/spec/modules/astraoneBidAdapter_spec.js +++ /dev/null @@ -1,212 +0,0 @@ -import { expect } from 'chai' -import { spec } from 'modules/astraoneBidAdapter.js' - -function getSlotConfigs(mediaTypes, params) { - return { - params: params, - sizes: [], - bidId: '2df8c0733f284e', - bidder: 'astraone', - mediaTypes: mediaTypes, - transactionId: '31a58515-3634-4e90-9c96-f86196db1459' - } -} - -describe('AstraOne Adapter', function() { - describe('isBidRequestValid method', function() { - const PLACE_ID = '5f477bf94d506ebe2c4240f3'; - const IMAGE_URL = 'https://creative.astraone.io/files/default_image-1-600x400.jpg'; - - describe('returns true', function() { - describe('when banner slot config has all mandatory params', () => { - describe('and placement has the correct value', function() { - const createBannerSlotConfig = placement => { - return getSlotConfigs( - { banner: {} }, - { - placeId: PLACE_ID, - imageUrl: IMAGE_URL, - placement - } - ) - } - const placements = ['inImage']; - placements.forEach(placement => { - it('should be ' + placement, function() { - const isBidRequestValid = spec.isBidRequestValid( - createBannerSlotConfig(placement) - ) - expect(isBidRequestValid).to.equal(true) - }) - }) - }) - }) - }) - describe('returns false', function() { - describe('when params are not correct', function() { - function createSlotconfig(params) { - return getSlotConfigs({ banner: {} }, params) - } - it('does not have the placeId.', function() { - const isBidRequestValid = spec.isBidRequestValid( - createSlotconfig({ - imageUrl: IMAGE_URL, - placement: 'inImage' - }) - ) - expect(isBidRequestValid).to.equal(false) - }) - it('does not have the imageUrl.', function() { - const isBidRequestValid = spec.isBidRequestValid( - createSlotconfig({ - placeId: PLACE_ID, - placement: 'inImage' - }) - ) - expect(isBidRequestValid).to.equal(false) - }) - it('does not have the placement.', function() { - const isBidRequestValid = spec.isBidRequestValid( - createSlotconfig({ - placeId: PLACE_ID, - imageUrl: IMAGE_URL, - }) - ) - expect(isBidRequestValid).to.equal(false) - }) - it('does not have a the correct placement.', function() { - const isBidRequestValid = spec.isBidRequestValid( - createSlotconfig({ - placeId: PLACE_ID, - imageUrl: IMAGE_URL, - placement: 'something' - }) - ) - expect(isBidRequestValid).to.equal(false) - }) - }) - }) - }) - - describe('buildRequests method', function() { - const bidderRequest = { - refererInfo: { referer: 'referer' } - } - const mandatoryParams = { - placeId: '5af45ad34d506ee7acad0c26', - imageUrl: 'https://creative.astraone.io/files/default_image-1-600x400.jpg', - placement: 'inImage' - } - const validBidRequests = [ - getSlotConfigs({ banner: {} }, mandatoryParams) - ] - it('Url params should be correct ', function() { - const request = spec.buildRequests(validBidRequests, bidderRequest) - expect(request.method).to.equal('POST') - expect(request.url).to.equal('https://ssp.astraone.io/auction/prebid') - }) - - it('Common data request should be correct', function() { - const request = spec.buildRequests(validBidRequests, bidderRequest) - const data = JSON.parse(request.data) - expect(Array.isArray(data.bidRequests)).to.equal(true) - data.bidRequests.forEach(bid => { - expect(bid.placeId).to.equal('5af45ad34d506ee7acad0c26') - expect(typeof bid.imageUrl).to.equal('string') - }) - }) - - describe('GDPR params', function() { - describe('when there are not consent management platform', function() { - it('cmp should be false', function() { - const request = spec.buildRequests(validBidRequests, bidderRequest) - const data = JSON.parse(request.data) - expect(data.cmp).to.equal(false) - }) - }) - describe('when there are consent management platform', function() { - it('cmps should be true and ga should not sended, when gdprApplies is undefined', function() { - bidderRequest['gdprConsent'] = { - gdprApplies: undefined, - consentString: 'consentString' - } - const request = spec.buildRequests(validBidRequests, bidderRequest) - const data = JSON.parse(request.data) - expect(data.cmp).to.equal(true) - expect(Object.keys(data).indexOf('data')).to.equal(-1) - expect(data.cs).to.equal('consentString') - }) - it('cmps should be true and all gdpr parameters should be sended, when there are gdprApplies', function() { - bidderRequest['gdprConsent'] = { - gdprApplies: true, - consentString: 'consentString' - } - const request = spec.buildRequests(validBidRequests, bidderRequest) - const data = JSON.parse(request.data) - expect(data.cmp).to.equal(true) - expect(data.ga).to.equal(true) - expect(data.cs).to.equal('consentString') - }) - }) - }) - - describe('BidRequests params', function() { - const request = spec.buildRequests(validBidRequests, bidderRequest) - const data = JSON.parse(request.data) - const bidRequests = data.bidRequests - it('should request a Banner', function() { - const bannerBid = bidRequests[0] - expect(bannerBid.bidId).to.equal('2df8c0733f284e') - expect(bannerBid.transactionId).to.equal('31a58515-3634-4e90-9c96-f86196db1459') - expect(bannerBid.placeId).to.equal('5af45ad34d506ee7acad0c26') - }) - }) - }) - - describe('interpret response method', function() { - it('should return a void array, when the server response have not got bids.', function() { - const serverResponse = { - body: [] - } - const bids = spec.interpretResponse(serverResponse) - expect(Array.isArray(bids)).to.equal(true) - expect(bids.length).to.equal(0) - }) - describe('when the server response return a bid', function() { - describe('the bid is a banner', function() { - it('should return a banner bid', function() { - const serverResponse = { - body: { - bids: [ - { - bidId: '2df8c0733f284e', - price: 0.5, - currency: 'USD', - content: { - content: 'html', - actionUrls: {}, - seanceId: '123123' - }, - width: 100, - height: 100, - ttl: 360 - } - ] - } - } - const bids = spec.interpretResponse(serverResponse) - expect(bids.length).to.equal(1) - expect(bids[0].requestId).to.equal('2df8c0733f284e') - expect(bids[0].creativeId).to.equal('123123') - expect(bids[0].cpm).to.equal(0.5) - expect(bids[0].width).to.equal(100) - expect(bids[0].height).to.equal(100) - expect(bids[0].currency).to.equal('USD') - expect(bids[0].netRevenue).to.equal(true) - expect(typeof bids[0].ad).to.equal('string') - expect(typeof bids[0].content).to.equal('object') - }) - }) - }) - }) -})