diff --git a/.babelrc b/.babelrc deleted file mode 100644 index 5d42055cabb..00000000000 --- a/.babelrc +++ /dev/null @@ -1,19 +0,0 @@ -{ - "presets": [ - ["env", { - "targets": { - "browsers": [ - "chrome >= 61", - "safari >=8", - "edge >= 14", - "ff >= 57", - "ie >= 10", - "ios >= 8" - ] - } - }] - ], - "plugins": [ - "transform-object-assign" - ] -} diff --git a/.babelrc.js b/.babelrc.js new file mode 100644 index 00000000000..bece57ec4a5 --- /dev/null +++ b/.babelrc.js @@ -0,0 +1,34 @@ + +let path = require('path'); + +function useLocal(module) { + return require.resolve(module, { + paths: [ + __dirname + ] + }) +} + +module.exports = { + "presets": [ + [ + useLocal('@babel/preset-env'), + { + "targets": { + "browsers": [ + "chrome >= 61", + "safari >=8", + "edge >= 14", + "ff >= 57", + "ie >= 10", + "ios >= 8" + ] + } + } + ] + ], + "plugins": [ + path.resolve(__dirname, './plugins/pbjsGlobals.js'), + useLocal('babel-plugin-transform-object-assign') + ] +}; diff --git a/.circleci/config.yml b/.circleci/config.yml index 62c23390666..fbf7e77e10f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -33,7 +33,7 @@ jobs: - node_modules key: v1-dependencies-{{ checksum "package.json" }} - - run: sudo npm install -g gulp + - run: sudo npm install -g gulp-cli # Download and run BrowserStack local - run: name : Download BrowserStack Local binary and start it. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7f4127cf3ba..b82b249fa36 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -64,8 +64,8 @@ A test module might have the following general structure: import { expect } from 'chai'; // may prefer 'assert' in place of 'expect' import adapter from 'src/adapters/'; -describe('', () => { - it('', () => { +describe('', function () { + it('', function () { // Arrange - set up preconditions and inputs // Act - call or act on the code under test // Assert - use chai to check that expected results have occurred diff --git a/PREBID_VERSIONING_DEPRECATION.md b/PREBID_VERSIONING_DEPRECATION.md new file mode 100644 index 00000000000..f006922259b --- /dev/null +++ b/PREBID_VERSIONING_DEPRECATION.md @@ -0,0 +1,25 @@ +# Prebid versioning and deprecation policy + +## Goals +Provide clear definitions and policy around versioning and breaking changes to APIs that are both publisher and demand partner facing. + + - Limit the number of breaking changes. + - Ensure significant time for updates for breaking changes so that publisher or demand partners do not break. + - Provide a path to deprecation and reduce technical debt and increase security. + - Major versions should not be changed more than once per 30 days. + +## Versioning + +Follow semantic versioning so that all breaking changes occur within a major release. A breaking change includes both demand partner internal APIs* and publisher facing APIs (global APIs). + +*Demand partner APIs may be excluded from breaking change policy at the core teams discretion if the changes are made so to be transparent to the bidders (such as internal refactoring). + +## Deprecation process + + - Open an issue with an "intent to implement" and "API impact" labels. + - Allow 2 weeks for discussion. + - Announce breaking change to the mailing list (TBD needs to be created). + - At least 2 core members needs to provide explicit approval for the deprecation. + - Open a PR against current master for console warning for possible breakage. + - Support the previous major version for a minimum of 30 days. + - Coordinate with the core team to ensure clean merging into feature branch if applicable (future major version branch). diff --git a/PR_REVIEW.md b/PR_REVIEW.md index 012a2d8b501..d5799472377 100644 --- a/PR_REVIEW.md +++ b/PR_REVIEW.md @@ -18,6 +18,7 @@ For modules and core platform updates, the initial reviewer should request an ad - Once there is 2 `LGTM` on the PR, merge to master - Ask the submitter to add a PR for documentation if applicable. - Add a line into the [draft release](https://github.com/prebid/Prebid.js/releases) notes for this submission. If no draft release is available, create one using [this template]( https://gist.github.com/mkendall07/c3af6f4691bed8a46738b3675cb5a479) +- Add the PR to the appropriate project board (I.E. 1.23.0 Release) for the week, [see](https://github.com/prebid/Prebid.js/projects) ### New Adapter or updates to adapter process - Follow steps above for general review process. In addition, please verify the following: @@ -39,9 +40,9 @@ For modules and core platform updates, the initial reviewer should request an ad ## Ticket Coordinator Each week, Prebid Org assigns one person to keep an eye on incoming issues and PRs. That person should: -- Review issues and PRs at least once per weekday for new items. +- Review issues and PRs at least once per weekday for new items. Encourage a 48 "SLA" on PRs/issues assigned. Aim for touchpoint once every 48/hours. - For PRs: assign PRs to individuals on the PR review list. Try to be equitable -- not all PRs are created equally. Use the "Assigned" field and add the "Needs Review" label. -- For Issues: try to address questions and troubleshooting requests on your own, assigning them to others as needed. +- For Issues: try to address questions and troubleshooting requests on your own, assigning them to others as needed. Please add labels as appropriate (I.E. bug, question, backlog etc). - Issues that are questions or troubleshooting requests may be closed if the originator doesn't respond within a week to requests for confirmation or details. - Issues that are bug reports should be left open and assigned to someone in PR rotation to confirm or deny the bug status. - It's polite to check with others before assigning them large tasks. diff --git a/README.md b/README.md index fa3a11fbb88..62c835f8eb3 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ [![Code Climate](https://codeclimate.com/github/prebid/Prebid.js/badges/gpa.svg)](https://codeclimate.com/github/prebid/Prebid.js) [![Coverage Status](https://coveralls.io/repos/github/prebid/Prebid.js/badge.svg)](https://coveralls.io/github/prebid/Prebid.js) [![devDependencies Status](https://david-dm.org/prebid/Prebid.js/dev-status.svg)](https://david-dm.org/prebid/Prebid.js?type=dev) +[![Total Alerts](https://img.shields.io/lgtm/alerts/g/prebid/Prebid.js.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/prebid/Prebid.js/alerts/) # Prebid.js @@ -15,11 +16,94 @@ Working examples can be found in [the developer docs](http://prebid.org/dev-docs **Table of Contents** +- [Usage](#Usage) - [Install](#Install) - [Build](#Build) - [Run](#Run) - [Contribute](#Contribute) + + +## Usage (as a npm dependency) + +*Note:* Requires Prebid.js v1.38.0+ + +Prebid.js depends on Babel and some Babel Plugins in order to run correctly in the browser. Here are some examples for +configuring webpack to work with Prebid.js. + +With Babel 7: +```javascript +// webpack.conf.js +let path = require('path'); +module.exports = { + mode: 'production', + module: { + rules: [ + + // this rule can be excluded if you don't require babel-loader for your other application files + { + test: /\.m?js$/, + exclude: /node_modules/, + use: { + loader: 'babel-loader', + } + }, + + // this separate rule is required to make sure that the Prebid.js files are babel-ified. this rule will + // override the regular exclusion from above (for being inside node_modules). + { + test: /.js$/, + include: new RegExp(`\\${path.sep}prebid\.js`), + use: { + loader: 'babel-loader', + // presets and plugins for Prebid.js must be manually specified separate from your other babel rule. + // this can be accomplished by requiring prebid's .babelrc.js file (requires Babel 7 and Node v8.9.0+) + options: require('prebid.js/.babelrc.js') + } + } + ] + } +} +``` + +Or for Babel 6 and/or Node v8.6.0 and less: +```javascript + // you must manually install and specify the presets and plugins yourself + options: { + plugins: [ + "transform-object-assign", // required (for IE support) and "babel-plugin-transform-object-assign" + // must be installed as part of your package. + require('prebid.js/plugins/pbjsGlobals.js') // required! + ], + presets: [ + ["env", { // you can use other presets if you wish. + "targets": { // this example is using "babel-presets-env", which must be installed if you + "browsers": [ // follow this example. + ... // your browser targets. they should probably match the targets you're using for the rest + // of your application + ] + } + }] + ] + } +``` + +Then you can use Prebid.js as any other npm depedendency + +```javascript +import prebid from 'prebid.js'; +import 'prebid.js/modules/rubiconBidAdapter'; // imported modules will register themselves automatically with prebid +import 'prebid.js/modules/appnexusBidAdapter'; +prebid.processQueue(); // required to process existing pbjs.queue blocks and setup any further pbjs.queue execution + +prebid.requestBids({ + ... +}) + +``` + + + ## Install @@ -28,7 +112,16 @@ Working examples can be found in [the developer docs](http://prebid.org/dev-docs $ cd Prebid.js $ npm install -*Note:* You need to have `NodeJS` 4.x or greater installed. +*Note:* You need to have `NodeJS` 6.x or greater installed. + +*Note:* In the 1.24.0 release of Prebid.js we have transitioned to using gulp 4.0 from using gulp 3.9.1. To compily with gulp's recommended setup for 4.0, you'll need to have `gulp-cli` installed globally prior to running the general `npm install`. This shouldn't impact any other projects you may work on that use an earlier version of gulp in it's setup. + +If you have a previous version of `gulp` installed globally, you'll need to remove it before installing `gulp-cli`. You can check if this is installed by running `gulp -v` and seeing the version that's listed in the `CLI` field of the output. If you have the `gulp` package installd globally, it's likely the same version that you'll see in the `Local` field. If you already have `gulp-cli` installed, it should be a lower major version (it's at version `2.0.1` at the time of the transition). + +To remove the old package, you can use the command: `npm rm gulp -g` + +Once setup, run the following command to globally install the `gulp-cli` package: `npm install gulp-cli -g` + @@ -167,7 +260,7 @@ Many SSPs, bidders, and publishers have contributed to this project. [60+ Bidder For guidelines, see [Contributing](./CONTRIBUTING.md). -Our PR review process can be found [here](https://github.com/prebid/Prebid.js/tree/master/pr_review.md). +Our PR review process can be found [here](https://github.com/prebid/Prebid.js/tree/master/PR_REVIEW.md). ### Add a Bidder Adapter @@ -207,7 +300,7 @@ For instructions on writing tests for Prebid.js, see [Testing Prebid.js](http:// ### Supported Browsers -Prebid.js is supported on IE10+ and modern browsers. +Prebid.js is supported on IE11 and modern browsers. ### Governance Review our governance model [here](https://github.com/prebid/Prebid.js/tree/master/governance.md). diff --git a/RELEASE_SCHEDULE.md b/RELEASE_SCHEDULE.md index 0c424e76ed4..611a98473ff 100644 --- a/RELEASE_SCHEDULE.md +++ b/RELEASE_SCHEDULE.md @@ -17,13 +17,17 @@ Announcements regarding releases will be made to the #headerbidding-dev channel ## Release Process -1. Make Sure all browserstack tests are passing. On PR merge to master travis will run unit tests on browserstack. Checking the last travis build [here](https://travis-ci.org/prebid/Prebid.js/branches) for master branch will show you detailed results. +_Note: If `github.com/prebid/Prebid.js` is not configured as the git origin for your repo, all of the following git commands will have to be modified to reference the proper remote (e.g. `upstream`)_ + +1. Make Sure all browserstack tests are passing. On PR merge to master CircleCI will run unit tests on browserstack. Checking the last CircleCI build [here](https://circleci.com/gh/prebid/Prebid.js) for master branch will show you detailed results. In case of failure do following, - Try to fix the failing tests. - If you are not able to fix tests in time. Skip the test, create issue and tag contributor. #### How to run tests in browserstack + + _Note: the following browserstack information is only relevant for debugging purposes, if you will not be debugging then it can be skipped._ Set the environment variables. You may want to add these to your `~/.bashrc` for convenience. @@ -59,11 +63,12 @@ Announcements regarding releases will be made to the #headerbidding-dev channel Pull these changes locally by running command ``` git pull + git fetch --tags ``` and verify the tag. -5. Update coveralls +5. Update coveralls _(skip for legacy)_ We use https://coveralls.io/ to show parts of code covered by unit tests. @@ -75,7 +80,9 @@ Announcements regarding releases will be made to the #headerbidding-dev channel Run `gulp coveralls` to update code coverage history. -6. Distribute the code +6. Distribute the code + + _Note: do not go to step 7 until step 6 has been verified completed._ Reach out to any of the Appnexus folks to trigger the jenkins job. @@ -83,7 +90,7 @@ Announcements regarding releases will be made to the #headerbidding-dev channel Jenkins job is moving files to appnexus cdn, pushing prebid.js to npm, purging cache and sending notification to slack. Move all the files from Appnexus CDN to jsDelivr and create bash script to do above tasks. -7. Post Release Steps +7. Post Release Version Update the version Manually edit Prebid's package.json to become "1.x.x-pre" (using the values for the next release). Then commit your changes. @@ -91,6 +98,17 @@ Announcements regarding releases will be made to the #headerbidding-dev channel git commit -m "Increment pre version" git push ``` + +8. Create new release draft + + Go to [github releases](https://github.com/prebid/Prebid.js/releases) and add a new draft for the next version of Prebid.js with the following template: +``` +## 🚀New Features + +## 🛠Maintenance + +## 🐛Bug Fixes +``` ## Beta Releases diff --git a/gulpHelpers.js b/gulpHelpers.js index d4078aa3dbc..a7d4333fd64 100644 --- a/gulpHelpers.js +++ b/gulpHelpers.js @@ -66,7 +66,7 @@ module.exports = { try { var absoluteModulePath = path.join(__dirname, MODULE_PATH); internalModules = fs.readdirSync(absoluteModulePath) - .filter(file => !(/(^|\/)\.[^\/\.]/g).test(file)) + .filter(file => (/^[^\.]+(\.js)?$/).test(file)) .reduce((memo, file) => { var moduleName = file.split(new RegExp('[.\\' + path.sep + ']'))[0]; var modulePath = path.join(absoluteModulePath, file); diff --git a/gulpfile.js b/gulpfile.js index d2955f7d777..772f09e7493 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -5,18 +5,15 @@ var argv = require('yargs').argv; var gulp = require('gulp'); var gutil = require('gulp-util'); var connect = require('gulp-connect'); -var path = require('path'); var webpack = require('webpack'); var webpackStream = require('webpack-stream'); var uglify = require('gulp-uglify'); -var clean = require('gulp-clean'); +var gulpClean = require('gulp-clean'); var KarmaServer = require('karma').Server; var karmaConfMaker = require('./karma.conf.maker'); -var opens = require('open'); +var opens = require('opn'); var webpackConfig = require('./webpack.conf'); var helpers = require('./gulpHelpers'); -var del = require('del'); -var gulpDocumentation = require('gulp-documentation'); var concat = require('gulp-concat'); var header = require('gulp-header'); var footer = require('gulp-footer'); @@ -36,23 +33,136 @@ var banner = '/* <%= prebid.name %> v<%= prebid.version %>\n' + dateString + ' * var analyticsDirectory = '../analytics'; var port = 9999; -// Tasks -gulp.task('default', ['webpack']); +// these modules must be explicitly listed in --modules to be included in the build, won't be part of "all" modules +var explicitModules = [ + 'pre1api' +]; -gulp.task('serve', ['lint', 'build-bundle-dev', 'watch', 'test']); +// all the following functions are task functions +function bundleToStdout() { + nodeBundle().then(file => console.log(file)); +} +bundleToStdout.displayName = 'bundle-to-stdout'; -gulp.task('serve-nw', ['lint', 'watch', 'e2etest']); +function clean() { + return gulp.src(['build'], { + read: false, + allowEmpty: true + }) + .pipe(gulpClean()); +} -gulp.task('run-tests', ['lint', 'test-coverage']); +function e2etestReport() { + var reportPort = 9010; + var targetDestinationDir = './e2etest-report'; + helpers.createEnd2EndTestReport(targetDestinationDir); + connect.server({ + port: reportPort, + root: './', + livereload: true + }); + + setTimeout(function() { + opens('http://localhost:' + reportPort + '/' + targetDestinationDir.slice(2) + '/results.html'); + }, 5000); +}; +e2etestReport.displayName = 'e2etest-report'; -gulp.task('build', ['build-bundle-prod']); +// Dependant task for building postbid. It escapes postbid-config file. +function escapePostbidConfig() { + gulp.src('./integrationExamples/postbid/oas/postbid-config.js') + .pipe(jsEscape()) + .pipe(gulp.dest('build/postbid/')); +}; +escapePostbidConfig.displayName = 'escape-postbid-config'; -gulp.task('clean', function () { - return gulp.src(['build'], { - read: false - }) - .pipe(clean()); -}); +function lint(done) { + if (argv.nolint) { + return done(); + } + const isFixed = function(file) { + return file.eslint != null && file.eslint.fixed; + } + return gulp.src(['src/**/*.js', 'modules/**/*.js', 'test/**/*.js'], {base: './'}) + .pipe(eslint({fix: true})) + .pipe(eslint.format('stylish')) + .pipe(eslint.failAfterError()) + .pipe(gulpif(isFixed, gulp.dest('./'))); +}; + +// View the code coverage report in the browser. +function viewCoverage(done) { + var coveragePort = 1999; + + connect.server({ + port: coveragePort, + root: 'build/coverage/karma_html', + livereload: false + }); + opens('http://localhost:' + coveragePort); + done(); +}; + +viewCoverage.displayName = 'view-coverage'; + +// Watch Task with Live Reload +function watch(done) { + var mainWatcher = gulp.watch([ + 'src/**/*.js', + 'modules/**/*.js', + 'test/spec/**/*.js', + '!test/spec/loaders/**/*.js' + ]); + var loaderWatcher = gulp.watch([ + 'loaders/**/*.js', + 'test/spec/loaders/**/*.js' + ]); + + connect.server({ + https: argv.https, + port: port, + root: './', + livereload: true + }); + + mainWatcher.on('all', gulp.series(clean, gulp.parallel(lint, 'build-bundle-dev', test))); + loaderWatcher.on('all', gulp.series(lint)); + done(); +}; + +function makeDevpackPkg() { + var cloned = _.cloneDeep(webpackConfig); + cloned.devtool = 'source-map'; + var externalModules = helpers.getArgModules(); + + const analyticsSources = helpers.getAnalyticsSources(analyticsDirectory); + const moduleSources = helpers.getModulePaths(externalModules); + + return gulp.src([].concat(moduleSources, analyticsSources, 'src/prebid.js')) + .pipe(helpers.nameModules(externalModules)) + .pipe(webpackStream(cloned, webpack)) + .pipe(gulp.dest('build/dev')) + .pipe(connect.reload()); +} + +function makeWebpackPkg() { + var cloned = _.cloneDeep(webpackConfig); + + delete cloned.devtool; + + var externalModules = helpers.getArgModules(); + + const analyticsSources = helpers.getAnalyticsSources(analyticsDirectory); + const moduleSources = helpers.getModulePaths(externalModules); + + return gulp.src([].concat(moduleSources, analyticsSources, 'src/prebid.js')) + .pipe(helpers.nameModules(externalModules)) + .pipe(webpackStream(cloned, webpack)) + .pipe(uglify()) + .pipe(gulpif(file => file.basename === 'prebid-core.js', header(banner, { prebid: prebid }))) + .pipe(optimizejs()) + .pipe(gulp.dest('build/dist')); +} function gulpBundle(dev) { return bundle(dev).pipe(gulp.dest('build/' + (dev ? 'dev' : 'dist'))); @@ -71,20 +181,15 @@ function nodeBundle(modules) { }); } -// these modules must be explicitly listed in --modules to be included in the build, won't be part of "all" modules -var explicitModules = [ - 'pre1api' -]; - function bundle(dev, moduleArr) { - var modules = moduleArr || helpers.getArgModules(), - allModules = helpers.getModuleNames(modules); + var modules = moduleArr || helpers.getArgModules(); + var allModules = helpers.getModuleNames(modules); - if(modules.length === 0) { - modules = allModules.filter(module => !explicitModules.includes(module)); + if (modules.length === 0) { + modules = allModules.filter(module => explicitModules.indexOf(module) === -1); } else { var diff = _.difference(modules, allModules); - if(diff.length !== 0) { + if (diff.length !== 0) { throw new gutil.PluginError({ plugin: 'bundle', message: 'invalid modules: ' + diff.join(', ') @@ -106,13 +211,13 @@ function bundle(dev, moduleArr) { gutil.log('Generating bundle:', outputFileName); return gulp.src( - entries - ) + entries + ) .pipe(gulpif(dev, sourcemaps.init({loadMaps: true}))) .pipe(concat(outputFileName)) .pipe(gulpif(!argv.manualEnable, footer('\n<%= global %>.processQueue();', { - global: prebid.globalVarName - } + global: prebid.globalVarName + } ))) .pipe(gulpif(dev, sourcemaps.write('.'))); } @@ -124,60 +229,11 @@ function newKarmaCallback(done) { if (exitCode) { done(new Error('Karma tests failed with exit code ' + exitCode)); } else { - if (argv.browserstack) { - process.exit(0); - } else { - done(); - } + done(); } } } -gulp.task('build-bundle-dev', ['devpack'], gulpBundle.bind(null, true)); -gulp.task('build-bundle-prod', ['webpack'], gulpBundle.bind(null, false)); -gulp.task('bundle', gulpBundle.bind(null, false)); // used for just concatenating pre-built files with no build step - -gulp.task('bundle-to-stdout', function() { - nodeBundle().then(file => console.log(file)); -}); - -gulp.task('devpack', ['clean'], function () { - var cloned = _.cloneDeep(webpackConfig); - cloned.devtool = 'source-map'; - var externalModules = helpers.getArgModules(); - - const analyticsSources = helpers.getAnalyticsSources(analyticsDirectory); - const moduleSources = helpers.getModulePaths(externalModules); - - return gulp.src([].concat(moduleSources, analyticsSources, 'src/prebid.js')) - .pipe(helpers.nameModules(externalModules)) - .pipe(webpackStream(cloned, webpack)) - .pipe(replace('$prebid.version$', prebid.version)) - .pipe(gulp.dest('build/dev')) - .pipe(connect.reload()); -}); - -gulp.task('webpack', ['clean'], function () { - var cloned = _.cloneDeep(webpackConfig); - - delete cloned.devtool; - - var externalModules = helpers.getArgModules(); - - const analyticsSources = helpers.getAnalyticsSources(analyticsDirectory); - const moduleSources = helpers.getModulePaths(externalModules); - - return gulp.src([].concat(moduleSources, analyticsSources, 'src/prebid.js')) - .pipe(helpers.nameModules(externalModules)) - .pipe(webpackStream(cloned, webpack)) - .pipe(replace('$prebid.version$', prebid.version)) - .pipe(uglify()) - .pipe(gulpif(file => file.basename === 'prebid-core.js', header(banner, { prebid: prebid }))) - .pipe(optimizejs()) - .pipe(gulp.dest('build/dist')) - .pipe(connect.reload()); -}); - // Run the unit tests. // // By default, this runs in headless chrome. @@ -186,85 +242,37 @@ gulp.task('webpack', ['clean'], function () { // If --file "" is given, the task will only run tests in the specified file. // If --browserstack is given, it will run the full suite of currently supported browsers. // If --browsers is given, browsers can be chosen explicitly. e.g. --browsers=chrome,firefox,ie9 -gulp.task('test', ['clean'], function (done) { - var karmaConf = karmaConfMaker(false, argv.browserstack, argv.watch, argv.file); +// If --notest is given, it will immediately skip the test task (useful for developing changes with `gulp serve --notest`) +function test(done) { + if (argv.notest) { + done(); + } else { + var karmaConf = karmaConfMaker(false, argv.browserstack, argv.watch, argv.file); - var browserOverride = helpers.parseBrowserArgs(argv).map(helpers.toCapitalCase); - if (browserOverride.length > 0) { - karmaConf.browsers = browserOverride; - } + var browserOverride = helpers.parseBrowserArgs(argv).map(helpers.toCapitalCase); + if (browserOverride.length > 0) { + karmaConf.browsers = browserOverride; + } - new KarmaServer(karmaConf, newKarmaCallback(done)).start(); -}); + new KarmaServer(karmaConf, newKarmaCallback(done)).start(); + } +} // If --file "" is given, the task will only run tests in the specified file. -gulp.task('test-coverage', ['clean'], function(done) { +function testCoverage(done) { new KarmaServer(karmaConfMaker(true, false, false, argv.file), newKarmaCallback(done)).start(); -}); - -// View the code coverage report in the browser. -gulp.task('view-coverage', function (done) { - var coveragePort = 1999; - - connect.server({ - port: coveragePort, - root: 'build/coverage/karma_html', - livereload: false - }); - opens('http://localhost:' + coveragePort); - done(); -}); +} -gulp.task('coveralls', ['test-coverage'], function() { // 2nd arg is a dependency: 'test' must be finished +function coveralls() { // 2nd arg is a dependency: 'test' must be finished // first send results of istanbul's test coverage to coveralls.io. return gulp.src('gulpfile.js', { read: false }) // You have to give it a file, but you don't // have to read it. .pipe(shell('cat build/coverage/lcov.info | node_modules/coveralls/bin/coveralls.js')); -}); - -// Watch Task with Live Reload -gulp.task('watch', function () { - gulp.watch([ - 'src/**/*.js', - 'modules/**/*.js', - 'test/spec/**/*.js', - '!test/spec/loaders/**/*.js' - ], ['lint', 'build-bundle-dev', 'test']); - gulp.watch([ - 'loaders/**/*.js', - 'test/spec/loaders/**/*.js' - ], ['lint']); - connect.server({ - https: argv.https, - port: port, - root: './', - livereload: true - }); -}); +} -gulp.task('lint', () => { - return gulp.src(['src/**/*.js', 'modules/**/*.js', 'test/**/*.js']) - .pipe(eslint()) - .pipe(eslint.format('stylish')) - .pipe(eslint.failAfterError()); -}); - -gulp.task('clean-docs', function () { - del(['docs']); -}); - -gulp.task('docs', ['clean-docs'], function () { - return gulp.src('src/prebid.js') - .pipe(gulpDocumentation('md')) - .on('error', function (err) { - gutil.log('`gulp-documentation` failed:', err.message); - }) - .pipe(gulp.dest('docs')); -}); - -gulp.task('e2etest', ['devpack', 'webpack'], function() { +function e2eTest() { var cmdQueue = []; - if(argv.browserstack) { + if (argv.browserstack) { var browsers = require('./browsers.json'); delete browsers['bs_ie_9_windows_7']; @@ -276,11 +284,11 @@ gulp.task('e2etest', ['devpack', 'webpack'], function() { var startWith = 'bs'; - Object.keys(browsers).filter(function(v){ + Object.keys(browsers).filter(function(v) { return v.substring(0, startWith.length) === startWith && browsers[v].browser !== 'iphone'; - }).map(function(v,i,arr) { - var newArr = (i%2 === 0) ? arr.slice(i,i+2) : null; - if(newArr) { + }).map(function(v, i, arr) { + var newArr = (i % 2 === 0) ? arr.slice(i, i + 2) : null; + if (newArr) { var cmd = 'nightwatch --env ' + newArr.join(',') + cmdStr; cmdQueue.push(cmd); } @@ -289,38 +297,50 @@ gulp.task('e2etest', ['devpack', 'webpack'], function() { return gulp.src('') .pipe(shell(cmdQueue.join(';'))); -}); - -gulp.task('e2etest-report', function() { - var reportPort = 9010; - var targetDestinationDir = './e2etest-report'; - helpers.createEnd2EndTestReport(targetDestinationDir); - connect.server({ - port: reportPort, - root: './', - livereload: true - }); - - setTimeout(function() { - opens('http://localhost:' + reportPort + '/' + targetDestinationDir.slice(2) + '/results.html'); - }, 5000); -}); +} // This task creates postbid.js. Postbid setup is different from prebid.js // More info can be found here http://prebid.org/overview/what-is-post-bid.html -gulp.task('build-postbid', ['escape-postbid-config'], function() { + +function buildPostbid() { var fileContent = fs.readFileSync('./build/postbid/postbid-config.js', 'utf8'); return gulp.src('./integrationExamples/postbid/oas/postbid.js') .pipe(replace('\[%%postbid%%\]', fileContent)) .pipe(gulp.dest('build/postbid/')); -}); +} -// Dependant task for building postbid. It escapes postbid-config file. -gulp.task('escape-postbid-config', function() { - gulp.src('./integrationExamples/postbid/oas/postbid-config.js') - .pipe(jsEscape()) - .pipe(gulp.dest('build/postbid/')); -}); +// support tasks +gulp.task(lint); +gulp.task(watch); + +gulp.task(clean); + +gulp.task(escapePostbidConfig); + +gulp.task('build-bundle-dev', gulp.series(makeDevpackPkg, gulpBundle.bind(null, true))); +gulp.task('build-bundle-prod', gulp.series(makeWebpackPkg, gulpBundle.bind(null, false))); + +// public tasks (dependencies are needed for each task since they can be ran on their own) +gulp.task('test', gulp.series(clean, lint, test)); + +gulp.task('test-coverage', gulp.series(clean, testCoverage)); +gulp.task(viewCoverage); + +gulp.task('coveralls', gulp.series('test-coverage', coveralls)); + +gulp.task('build', gulp.series(clean, 'build-bundle-prod')); +gulp.task('build-postbid', gulp.series(escapePostbidConfig, buildPostbid)); + +gulp.task('serve', gulp.series(clean, lint, gulp.parallel('build-bundle-dev', watch, test))); +gulp.task('default', gulp.series(clean, makeWebpackPkg)); + +gulp.task(e2etestReport); +gulp.task('e2etest', gulp.series(clean, gulp.parallel(makeDevpackPkg, makeWebpackPkg), e2eTest)); + +// other tasks +gulp.task(bundleToStdout); +gulp.task('bundle', gulpBundle.bind(null, false)); // used for just concatenating pre-built files with no build step +gulp.task('serve-nw', gulp.parallel(lint, watch, 'e2etest')); module.exports = nodeBundle; diff --git a/integrationExamples/gpt/hello_world_adikteev.html b/integrationExamples/gpt/hello_world_adikteev.html new file mode 100644 index 00000000000..7372ff12d7f --- /dev/null +++ b/integrationExamples/gpt/hello_world_adikteev.html @@ -0,0 +1,93 @@ + + + + + + + + + + + +

Basic Prebid.js Example

+
Div-1
+
+ +
+ + + diff --git a/integrationExamples/gpt/pbjs_example_gpt.html b/integrationExamples/gpt/pbjs_example_gpt.html index 536bc5a655d..6852b9f680a 100644 --- a/integrationExamples/gpt/pbjs_example_gpt.html +++ b/integrationExamples/gpt/pbjs_example_gpt.html @@ -302,8 +302,25 @@ channelCode: 2264002816, //REQUIRED dimId: 9 //REQUIRED } - } - + }, + { + bidder: 'openxoutstream', + params: { + unit: '53943996499', + delDomain: 'se-demo-d.openx.net', + publisher_page_url: 'yieldmo.com', + width: '300', + height: '250', + } + }, + { + bidder: 'adikteev', + params: { + placementId: 12345, + currency: 'EUR', + bidFloorPrice: 0.1, + } + }, ] }, { code: 'div-gpt-ad-12345678-1', diff --git a/integrationExamples/gpt/prebidServer_example.html b/integrationExamples/gpt/prebidServer_example.html index 2f91c2b966f..f13c93963c6 100644 --- a/integrationExamples/gpt/prebidServer_example.html +++ b/integrationExamples/gpt/prebidServer_example.html @@ -4,7 +4,6 @@ var PREBID_TIMEOUT = 3000; var googletag = googletag || {}; - var sizes = [[728, 90],[300, 250], [300,600]]; googletag.cmd = googletag.cmd || []; function initAdserver() { @@ -37,12 +36,12 @@ pbjs.que.push(function() { var adUnits = [{ code: 'div-gpt-ad-1460505748561-0', - sizes: [[300, 250], [300,600]], + sizes: [[300, 250]], bids: [ { bidder: 'appnexus', params: { - placementId: '10433394' + placementId: '13144370' } } ] @@ -56,7 +55,7 @@ bidders : ['appnexus'], timeout : 1000, //default value is 1000 adapter : 'prebidServer', //if we have any other s2s adapter, default value is s2s - endpoint : 'https://prebid.adnxs.com/pbs/v1/auction?url_override=http%3A%2F%2Fwww.nytimes.com' + endpoint : 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction' } }); @@ -72,7 +71,7 @@ '; }, isOneMobileBidder: _isOneMobileBidder, isSecureProtocol() { diff --git a/modules/appierBidAdapter.js b/modules/appierBidAdapter.js new file mode 100644 index 00000000000..a8e05f8edac --- /dev/null +++ b/modules/appierBidAdapter.js @@ -0,0 +1,89 @@ +import { registerBidder } from '../src/adapters/bidderFactory'; +import { BANNER } from '../src/mediaTypes'; +import { config } from '../src/config'; + +export const ADAPTER_VERSION = '1.0.0'; +const SUPPORTED_AD_TYPES = [BANNER]; + +// we have different servers for different regions / farms +export const API_SERVERS_MAP = { + 'default': 'ad2.apx.appier.net', + 'tw': 'ad2.apx.appier.net', + 'jp': 'ad-jp.apx.appier.net' +}; + +const BIDDER_API_ENDPOINT = '/v1/prebid/bid'; + +export const spec = { + code: 'appier', + supportedMediaTypes: SUPPORTED_AD_TYPES, + + /** + * 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: function (bid) { + return typeof bid.params.hzid === 'string'; + }, + + /** + * Make a server request from the list of BidRequests. + * + * @param {bidRequests[]} - an array of bids + * @return ServerRequest Info describing the request to the server. + */ + buildRequests: function (bidRequests, bidderRequest) { + if (bidRequests.length === 0) { + return []; + } + const server = this.getApiServer(); + const bidderApiUrl = `//${server}${BIDDER_API_ENDPOINT}` + const payload = { + 'bids': bidRequests, + 'refererInfo': bidderRequest.refererInfo, + 'version': ADAPTER_VERSION + }; + return [{ + method: 'POST', + url: bidderApiUrl, + data: payload, + // keep the bidder request object for later use + bidderRequest: bidderRequest + }]; + }, + + /** + * 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, serverRequest) { + if (!Array.isArray(serverResponse.body)) { + return []; + } + // server response body is an array of bid results + const bidResults = serverResponse.body; + // our server directly returns the format needed by prebid.js so no more + // transformation is needed here. + return bidResults; + }, + + /** + * Get the hostname of the server we want to use. + */ + getApiServer() { + // we may use different servers for different farms (geographical regions) + // if a server is specified explicitly, use it. otherwise, use farm specific server. + let server = config.getConfig('appier.server'); + if (!server) { + const farm = config.getConfig('appier.farm'); + server = API_SERVERS_MAP[farm] || API_SERVERS_MAP['default']; + } + return server; + } +}; + +registerBidder(spec); diff --git a/modules/appierBidAdapter.md b/modules/appierBidAdapter.md new file mode 100644 index 00000000000..92fdaab1e40 --- /dev/null +++ b/modules/appierBidAdapter.md @@ -0,0 +1,57 @@ +# Overview + +``` +Module Name: Appier Bid Adapter +Module Type: Bidder Adapter +Maintainer: apn-dev@appier.com +``` + +# Description + +Connects to Appier exchange for bids. + +NOTE: +- Appier bid adapter only supports Banner at the moment. +- Multi-currency is not supported. Please make sure you have correct DFP currency settings according to your deal with Appier. + +# Sample Ad Unit Config +``` +var adUnits = [ + // Banner adUnit + { + code: 'banner-div', + mediaTypes: { + banner: { + sizes: [[300, 250], [300,600]] + } + }, + bids: [{ + bidder: 'appier', + params: { + hzid: 'WhM5WIOp' + } + }] + } +]; +``` + +# Additional Config (Optional) +Set the "farm" to use region-specific server +``` + // use the bid server in Taiwan (country code: tw) + pbjs.setConfig({ + appier: { + 'farm': 'tw' + } + }); +``` + +Explicitly override the bid server used for bidding +``` + // use the bid server specified and override the default + pbjs.setConfig({ + appier: { + 'server': '${HOST_NAME_OF_THE_SERVER}' + } + }); +``` diff --git a/modules/appnexusAnalyticsAdapter.js b/modules/appnexusAnalyticsAdapter.js index f9756de23e3..f0f5ece26e8 100644 --- a/modules/appnexusAnalyticsAdapter.js +++ b/modules/appnexusAnalyticsAdapter.js @@ -2,8 +2,8 @@ * appnexus.js - AppNexus Prebid Analytics Adapter */ -import adapter from 'src/AnalyticsAdapter'; -import adaptermanager from 'src/adaptermanager'; +import adapter from '../src/AnalyticsAdapter'; +import adapterManager from '../src/adapterManager'; var appnexusAdapter = adapter({ global: 'AppNexusPrebidAnalytics', @@ -11,7 +11,7 @@ var appnexusAdapter = adapter({ analyticsType: 'bundle' }); -adaptermanager.registerAnalyticsAdapter({ +adapterManager.registerAnalyticsAdapter({ adapter: appnexusAdapter, code: 'appnexus' }); diff --git a/modules/appnexusBidAdapter.js b/modules/appnexusBidAdapter.js index d5cb3ac2800..d330c09aa10 100644 --- a/modules/appnexusBidAdapter.js +++ b/modules/appnexusBidAdapter.js @@ -1,7 +1,7 @@ -import { Renderer } from 'src/Renderer'; -import * as utils from 'src/utils'; -import { registerBidder } from 'src/adapters/bidderFactory'; -import { BANNER, NATIVE, VIDEO } from 'src/mediaTypes'; +import { Renderer } from '../src/Renderer'; +import * as utils from '../src/utils'; +import { registerBidder } from '../src/adapters/bidderFactory'; +import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes'; import find from 'core-js/library/fn/array/find'; import includes from 'core-js/library/fn/array/includes'; @@ -10,8 +10,11 @@ const URL = '//ib.adnxs.com/ut/v3/prebid'; const VIDEO_TARGETING = ['id', 'mimes', 'minduration', 'maxduration', 'startdelay', 'skippable', 'playback_method', 'frameworks']; const USER_PARAMS = ['age', 'external_uid', 'segments', 'gender', 'dnt', 'language']; +const APP_DEVICE_PARAMS = ['geo', 'device_id']; // appid is collected separately +const DEBUG_PARAMS = ['enabled', 'dongle', 'member_id', 'debug_timeout']; const NATIVE_MAPPING = { body: 'description', + body2: 'desc2', cta: 'ctatext', image: { serverName: 'main_image', @@ -24,6 +27,9 @@ const NATIVE_MAPPING = { minimumParams: { sizes: [{}] }, }, sponsoredBy: 'sponsored_by', + privacyLink: 'privacy_link', + salePrice: 'saleprice', + displayUrl: 'displayurl' }; const SOURCE = 'pbjs'; @@ -59,6 +65,49 @@ export const spec = { .forEach(param => userObj[param] = userObjBid.params.user[param]); } + const appDeviceObjBid = find(bidRequests, hasAppDeviceInfo); + let appDeviceObj; + if (appDeviceObjBid && appDeviceObjBid.params && appDeviceObjBid.params.app) { + appDeviceObj = {}; + Object.keys(appDeviceObjBid.params.app) + .filter(param => includes(APP_DEVICE_PARAMS, param)) + .forEach(param => appDeviceObj[param] = appDeviceObjBid.params.app[param]); + } + + const appIdObjBid = find(bidRequests, hasAppId); + let appIdObj; + if (appIdObjBid && appIdObjBid.params && appDeviceObjBid.params.app && appDeviceObjBid.params.app.id) { + appIdObj = { + appid: appIdObjBid.params.app.id + }; + } + + let debugObj = {}; + let debugObjParams = {}; + const debugCookieName = 'apn_prebid_debug'; + const debugCookie = utils.getCookie(debugCookieName) || null; + + if (debugCookie) { + try { + debugObj = JSON.parse(debugCookie); + } catch (e) { + utils.logError('AppNexus Debug Auction Cookie Error:\n\n' + e); + } + } else { + const debugBidRequest = find(bidRequests, hasDebug); + if (debugBidRequest && debugBidRequest.debug) { + debugObj = debugBidRequest.debug; + } + } + + if (debugObj && debugObj.enabled) { + Object.keys(debugObj) + .filter(param => includes(DEBUG_PARAMS, param)) + .forEach(param => { + debugObjParams[param] = debugObj[param]; + }); + } + const memberIdBid = find(bidRequests, hasMemberId); const member = memberIdBid ? parseInt(memberIdBid.params.member, 10) : 0; @@ -74,6 +123,18 @@ export const spec = { payload.member_id = member; } + if (appDeviceObjBid) { + payload.device = appDeviceObj + } + if (appIdObjBid) { + payload.app = appIdObj; + } + + if (debugObjParams.enabled) { + payload.debug = debugObjParams; + utils.logInfo('AppNexus Debug Auction Settings:\n\n' + JSON.stringify(debugObjParams, null, 4)); + } + if (bidderRequest && bidderRequest.gdprConsent) { // note - objects for impbus use underscore instead of camelCase payload.gdpr_consent = { @@ -82,6 +143,16 @@ export const spec = { }; } + if (bidderRequest && bidderRequest.refererInfo) { + let refererinfo = { + rd_ref: encodeURIComponent(bidderRequest.refererInfo.referer), + rd_top: bidderRequest.refererInfo.reachedTop, + rd_ifs: bidderRequest.refererInfo.numIframes, + rd_stk: bidderRequest.refererInfo.stack.map((url) => encodeURIComponent(url)).join(',') + } + payload.referrer_detection = refererinfo; + } + const payloadString = JSON.stringify(payload); return { method: 'POST', @@ -119,6 +190,22 @@ export const spec = { } }); } + + if (serverResponse.debug && serverResponse.debug.debug_info) { + let debugHeader = 'AppNexus Debug Auction for Prebid\n\n' + let debugText = debugHeader + serverResponse.debug.debug_info + debugText = debugText + .replace(/(|)/gm, '\t') // Tables + .replace(/(<\/td>|<\/th>)/gm, '\n') // Tables + .replace(/^
/gm, '') // Remove leading
+ .replace(/(
\n|
)/gm, '\n') //
+ .replace(/

(.*)<\/h1>/gm, '\n\n===== $1 =====\n\n') // Header H1 + .replace(/(.*)<\/h[2-6]>/gm, '\n\n*** $1 ***\n\n') // Headers + .replace(/(<([^>]+)>)/igm, ''); // Remove any other tags + utils.logMessage('https://console.appnexus.com/docs/understanding-the-debug-auction'); + utils.logMessage(debugText); + } + return bids; }, @@ -143,6 +230,10 @@ export const spec = { params.use_pmt_rule = (typeof params.usePaymentRule === 'boolean') ? params.usePaymentRule : false; if (params.usePaymentRule) { delete params.usePaymentRule; } + if (isPopulatedArray(params.keywords)) { + params.keywords.forEach(deleteValues); + } + Object.keys(params).forEach(paramKey => { let convertedKey = utils.convertCamelToUnderscore(paramKey); if (convertedKey !== paramKey) { @@ -156,12 +247,23 @@ export const spec = { } } +function isPopulatedArray(arr) { + return !!(utils.isArray(arr) && arr.length > 0); +} + +function deleteValues(keyPairObj) { + if (isPopulatedArray(keyPairObj.value) && keyPairObj.value[0] === '') { + delete keyPairObj.value; + } +} + function newRenderer(adUnitCode, rtbBid, rendererOptions = {}) { const renderer = Renderer.install({ id: rtbBid.renderer_id, url: rtbBid.renderer_url, config: rendererOptions, loaded: false, + adUnitCode }); try { @@ -189,6 +291,7 @@ function newRenderer(adUnitCode, rtbBid, rendererOptions = {}) { * @return Bid */ function newBid(serverBid, rtbBid, bidderRequest) { + const bidRequest = utils.getBidRequest(serverBid.uuid, [bidderRequest]); const bid = { requestId: serverBid.uuid, cpm: rtbBid.cpm, @@ -197,8 +300,11 @@ function newBid(serverBid, rtbBid, bidderRequest) { currency: 'USD', netRevenue: true, ttl: 300, + adUnitCode: bidRequest.adUnitCode, appnexus: { - buyerMemberId: rtbBid.buyer_member_id + buyerMemberId: rtbBid.buyer_member_id, + dealPriority: rtbBid.deal_priority, + dealCode: rtbBid.deal_code } }; @@ -229,12 +335,22 @@ function newBid(serverBid, rtbBid, bidderRequest) { bid[NATIVE] = { title: nativeAd.title, body: nativeAd.desc, + body2: nativeAd.desc2, cta: nativeAd.ctatext, + rating: nativeAd.rating, sponsoredBy: nativeAd.sponsored, + privacyLink: nativeAd.privacy_link, + address: nativeAd.address, + downloads: nativeAd.downloads, + likes: nativeAd.likes, + phone: nativeAd.phone, + price: nativeAd.price, + salePrice: nativeAd.saleprice, clickUrl: nativeAd.link.url, + displayUrl: nativeAd.displayurl, clickTrackers: nativeAd.link.click_trackers, impressionTrackers: nativeAd.impression_trackers, - javascriptTrackers: nativeAd.javascript_trackers, + javascriptTrackers: nativeAd.javascript_trackers }; if (nativeAd.main_img) { bid['native'].image = { @@ -308,7 +424,12 @@ function bidToTag(bid) { tag.external_imp_id = bid.params.externalImpId; } if (!utils.isEmpty(bid.params.keywords)) { - tag.keywords = utils.transformBidderParamKeywords(bid.params.keywords); + let keywords = utils.transformBidderParamKeywords(bid.params.keywords); + + if (keywords.length > 0) { + keywords.forEach(deleteValues); + } + tag.keywords = keywords; } if (bid.mediaType === NATIVE || utils.deepAccess(bid, `mediaTypes.${NATIVE}`)) { @@ -381,6 +502,23 @@ function hasMemberId(bid) { return !!parseInt(bid.params.member, 10); } +function hasAppDeviceInfo(bid) { + if (bid.params) { + return !!bid.params.app + } +} + +function hasAppId(bid) { + if (bid.params && bid.params.app) { + return !!bid.params.app.id + } + return !!bid.params.app +} + +function hasDebug(bid) { + return !!bid.debug +} + function getRtbBid(tag) { return tag && tag.ads && tag.ads.length && find(tag.ads, ad => ad.rtb); } diff --git a/modules/appnexusBidAdapter.md b/modules/appnexusBidAdapter.md index 58f260cdfc8..a1d12243888 100644 --- a/modules/appnexusBidAdapter.md +++ b/modules/appnexusBidAdapter.md @@ -17,59 +17,64 @@ Appnexus bid adapter supports Banner, Video (instream and outstream) and Native. var adUnits = [ // Banner adUnit { - code: 'banner-div', - sizes: [[300, 250], [300,600]], - bids: [{ + code: 'banner-div', + mediaTypes: { + banner: { + sizes: [[300, 250], [300,600]] + } + }, + bids: [{ bidder: 'appnexus', params: { - placementId: '10433394' + placementId: 13144370 } }] }, // Native adUnit { code: 'native-div', - sizes: [[300, 250], [300,600]], + sizes: [[1, 1]], mediaTypes: { native: { title: { - required: true, - len: 80 - }, - body: { required: true }, - brand: { + body: { required: true }, image: { required: true }, - clickUrl: { + sponsoredBy: { required: true }, + icon: { + required: false + } } }, bids: [{ bidder: 'appnexus', params: { - placementId: '9880618' + placementId: 13232354, + allowSmallerSizes: true } }] }, // Video instream adUnit { code: 'video-instream', - sizes: [640, 480], + sizes: [[640, 480]], mediaTypes: { video: { + playerSize: [[640, 480]], context: 'instream' }, }, bids: [{ bidder: 'appnexus', params: { - placementId: '9333431', + placementId: 13232361, video: { skippable: true, playback_methods: ['auto_play_sound_off'] @@ -80,9 +85,10 @@ var adUnits = [ // Video outstream adUnit { code: 'video-outstream', - sizes: [[640, 480]], + sizes: [[300, 250]], mediaTypes: { video: { + playerSize: [[300, 250]], context: 'outstream' } }, @@ -90,7 +96,7 @@ var adUnits = [ { bidder: 'appnexus', params: { - placementId: '5768085', + placementId: 13232385, video: { skippable: true, playback_method: ['auto_play_sound_off'] @@ -98,6 +104,37 @@ var adUnits = [ } } ] + }, + // Banner adUnit in a App Webview + // Only use this for situations where prebid.js is in a webview of an App + // See Prebid Mobile for displaying ads via an SDK + { + code: 'banner-div', + mediaTypes: { + banner: { + sizes: [[300, 250], [300,600]] + } + } + bids: [{ + bidder: 'appnexus', + params: { + placementId: 13144370, + app: { + id: "B1O2W3M4AN.com.prebid.webview", + geo: { + lat: 40.0964439, + lng: -75.3009142 + }, + device_id: { + idfa: "4D12078D-3246-4DA4-AD5E-7610481E7AE", // Apple advertising identifier + aaid: "38400000-8cf0-11bd-b23e-10b96e40000d", // Android advertising identifier + md5udid: "5756ae9022b2ea1e47d84fead75220c8", // MD5 hash of the ANDROID_ID + sha1udid: "4DFAA92388699AC6539885AEF1719293879985BF", // SHA1 hash of the ANDROID_ID + windowsadid: "750c6be243f1c4b5c9912b95a5742fc5" // Windows advertising identifier + } + } + } + }] } ]; ``` diff --git a/modules/arteebeeBidAdapter.js b/modules/arteebeeBidAdapter.js index e8d319c8845..ddf728a143e 100644 --- a/modules/arteebeeBidAdapter.js +++ b/modules/arteebeeBidAdapter.js @@ -1,7 +1,7 @@ -import * as utils from 'src/utils'; -import {BANNER} from 'src/mediaTypes'; -import {registerBidder} from 'src/adapters/bidderFactory'; -import {config} from 'src/config'; +import * as utils from '../src/utils'; +import {BANNER} from '../src/mediaTypes'; +import {registerBidder} from '../src/adapters/bidderFactory'; +import {config} from '../src/config'; const BIDDER_CODE = 'arteebee'; diff --git a/modules/atomxBidAdapter.js b/modules/atomxBidAdapter.js index f946841dffc..f36419902a1 100644 --- a/modules/atomxBidAdapter.js +++ b/modules/atomxBidAdapter.js @@ -1,5 +1,5 @@ -import * as utils from 'src/utils'; -import {registerBidder} from 'src/adapters/bidderFactory'; +import * as utils from '../src/utils'; +import {registerBidder} from '../src/adapters/bidderFactory'; const BIDDER_CODE = 'atomx'; diff --git a/modules/audienceNetworkBidAdapter.js b/modules/audienceNetworkBidAdapter.js index 12810a960c1..e3f4688981d 100644 --- a/modules/audienceNetworkBidAdapter.js +++ b/modules/audienceNetworkBidAdapter.js @@ -1,10 +1,9 @@ /** * @file AudienceNetwork adapter. */ -import { registerBidder } from 'src/adapters/bidderFactory'; -import { config } from 'src/config'; -import { formatQS } from 'src/url'; -import { generateUUID, getTopWindowUrl, isSafariBrowser, convertTypes } from 'src/utils'; +import { registerBidder } from '../src/adapters/bidderFactory'; +import { formatQS } from '../src/url'; +import { generateUUID, getTopWindowUrl, convertTypes } from '../src/utils'; import findIndex from 'core-js/library/fn/array/find-index'; import includes from 'core-js/library/fn/array/includes'; @@ -15,9 +14,11 @@ const url = 'https://an.facebook.com/v2/placementbid.json'; const supportedMediaTypes = ['banner', 'video']; const netRevenue = true; const hbBidder = 'fan'; +const ttl = 600; +const videoTtl = 3600; const platver = '$prebid.version$'; const platform = '241394079772386'; -const adapterver = '1.0.0'; +const adapterver = '1.1.0'; /** * Does this bid request contain valid parameters? @@ -72,6 +73,22 @@ const isValidSizeAndFormat = (size, format) => isValidNonSizedFormat(format) || isValidSize(flattenSize(size)); +/** + * Find a preferred entry, if any, from an array of valid sizes. + * @param {Array} acc + * @param {String} cur + */ +const sortByPreferredSize = (acc, cur) => + (cur === '300x250') ? [cur, ...acc] : [...acc, cur]; + +/** + * Map any deprecated size/formats to new values. + * @param {String} size + * @param {String} format + */ +const mapDeprecatedSizeAndFormat = (size, format) => + isFullWidth(format) ? ['300x250', null] : [size, format]; + /** * Is this a video format? * @param {String} format @@ -93,6 +110,13 @@ const isFullWidth = format => format === 'fullwidth'; */ const sdkVersion = format => isVideo(format) ? '' : '5.5.web'; +/** + * Which platform identifier should be used? + * @param {Array} platforms Possible platform identifiers + * @returns {String} First valid platform found, or default if none found + */ +const findPlatform = platforms => [...platforms.filter(Boolean), platform][0]; + /** * Does the search part of the URL contain "anhb_testmode" * and therefore indicate testmode should be used? @@ -133,9 +157,10 @@ const getTopWindowUrlEncoded = () => encodeURIComponent(getTopWindowUrl()); * @param {String} bids[].placementCode - Prebid placement identifier * @param {Object} bids[].params * @param {String} bids[].params.placementId - Audience Network placement identifier - * @param {String} bids[].params.format - Optional format, one of 'video', 'native' or 'fullwidth' if set + * @param {String} bids[].params.platform - Audience Network platform identifier (optional) + * @param {String} bids[].params.format - Optional format, one of 'video' or 'native' if set * @param {Array} bids[].sizes - list of desired advert sizes - * @param {Array} bids[].sizes[] - Size arrays [h,w]: should include one of [300, 250], [320, 50]: first matched size is used + * @param {Array} bids[].sizes[] - Size arrays [h,w]: should include one of [300, 250], [320, 50] * @returns {Array} List of URLs to fetch, plus formats and sizes for later use with interpretResponse */ const buildRequests = bids => { @@ -144,17 +169,21 @@ const buildRequests = bids => { const adformats = []; const sizes = []; const sdk = []; + const platforms = []; const requestIds = []; bids.forEach(bid => bid.sizes .map(flattenSize) .filter(size => isValidSizeAndFormat(size, bid.params.format)) + .reduce(sortByPreferredSize, []) .slice(0, 1) - .forEach(size => { + .forEach(preferredSize => { + const [size, format] = mapDeprecatedSizeAndFormat(preferredSize, bid.params.format); placementids.push(bid.params.placementId); - adformats.push(bid.params.format || size); + adformats.push(format || size); sizes.push(size); - sdk.push(sdkVersion(bid.params.format)); + sdk.push(sdkVersion(format)); + platforms.push(bid.params.platform); requestIds.push(bid.bidId); }) ); @@ -162,6 +191,8 @@ const buildRequests = bids => { // Build URL const testmode = isTestmode(); const pageurl = getTopWindowUrlEncoded(); + const platform = findPlatform(platforms); + const cb = generateUUID(); const search = { placementids, adformats, @@ -170,15 +201,13 @@ const buildRequests = bids => { sdk, adapterver, platform, - platver + platver, + cb }; const video = findIndex(adformats, isVideo); if (video !== -1) { [search.playerwidth, search.playerheight] = expandSize(sizes[video]); } - if (isSafariBrowser()) { - search.cb = generateUUID(); - } const data = formatQS(search); return [{ adformats, data, method, requestIds, sizes, url }]; @@ -194,8 +223,6 @@ const buildRequests = bids => { * @returns {Array} A list of bid response objects */ const interpretResponse = ({ body }, { adformats, requestIds, sizes }) => { - const ttl = Number(config.getConfig().bidderTimeout); - const { bids = {} } = body; return Object.keys(bids) // extract Array of bid responses @@ -237,6 +264,7 @@ const interpretResponse = ({ body }, { adformats, requestIds, sizes }) => { const pageurl = getTopWindowUrlEncoded(); bidResponse.mediaType = 'video'; bidResponse.vastUrl = `https://an.facebook.com/v1/instream/vast.xml?placementid=${creativeId}&pageurl=${pageurl}&playerwidth=${width}&playerheight=${height}&bidid=${fbBidid}`; + bidResponse.ttl = videoTtl; } return bidResponse; }); diff --git a/modules/audienceNetworkBidAdapter.md b/modules/audienceNetworkBidAdapter.md index 72013c8610b..6147191f4b7 100644 --- a/modules/audienceNetworkBidAdapter.md +++ b/modules/audienceNetworkBidAdapter.md @@ -11,7 +11,7 @@ Maintainer: Lovell Fuller | Name | Scope | Description | Example | | :------------ | :------- | :---------------------------------------------- | :--------------------------------- | | `placementId` | required | The Placement ID from Audience Network | "555555555555555\_555555555555555" | -| `format` | optional | Format, one of "native", "fullwidth" or "video" | "native" | +| `format` | optional | Format, one of "native" or "video" | "native" | # Example ad units diff --git a/modules/beachfrontBidAdapter.js b/modules/beachfrontBidAdapter.js index 7ce1476627c..7944ac191aa 100644 --- a/modules/beachfrontBidAdapter.js +++ b/modules/beachfrontBidAdapter.js @@ -1,11 +1,13 @@ -import * as utils from 'src/utils'; -import { registerBidder } from 'src/adapters/bidderFactory'; -import { Renderer } from 'src/Renderer'; -import { VIDEO, BANNER } from 'src/mediaTypes'; +import * as utils from '../src/utils'; +import { parse as parseUrl } from '../src/url'; +import { config } from '../src/config'; +import { registerBidder } from '../src/adapters/bidderFactory'; +import { Renderer } from '../src/Renderer'; +import { VIDEO, BANNER } from '../src/mediaTypes'; import find from 'core-js/library/fn/array/find'; import includes from 'core-js/library/fn/array/includes'; -const ADAPTER_VERSION = '1.2'; +const ADAPTER_VERSION = '1.4'; const ADAPTER_NAME = 'BFIO_PREBID'; const OUTSTREAM = 'outstream'; @@ -13,7 +15,7 @@ export const VIDEO_ENDPOINT = '//reachms.bfmio.com/bid.json?exchange_id='; export const BANNER_ENDPOINT = '//display.bfmio.com/prebid_display'; export const OUTSTREAM_SRC = '//player-cdn.beachfrontmedia.com/playerapi/loader/outstream.js'; -export const VIDEO_TARGETING = ['mimes']; +export const VIDEO_TARGETING = ['mimes', 'playbackmethod', 'maxduration']; export const DEFAULT_MIMES = ['video/mp4', 'application/javascript']; let appId = ''; @@ -237,6 +239,19 @@ function isBannerBidValid(bid) { return isBannerBid(bid) && getBannerBidParam(bid, 'appId') && getBannerBidParam(bid, 'bidfloor'); } +function getTopWindowLocation(bidderRequest) { + let url = bidderRequest && bidderRequest.refererInfo && bidderRequest.refererInfo.referer; + return parseUrl(config.getConfig('pageUrl') || url, { decodeSearchAsString: true }); +} + +function getTopWindowReferrer() { + try { + return window.top.document.referrer; + } catch (e) { + return ''; + } +} + function getVideoTargetingParams(bid) { return Object.keys(Object(bid.params.video)) .filter(param => includes(VIDEO_TARGETING, param)) @@ -252,7 +267,7 @@ function createVideoRequestData(bid, bidderRequest) { let video = getVideoTargetingParams(bid); let appId = getVideoBidParam(bid, 'appId'); let bidfloor = getVideoBidParam(bid, 'bidfloor'); - let topLocation = utils.getTopWindowLocation(); + let topLocation = getTopWindowLocation(bidderRequest); let payload = { isPrebid: true, appId: appId, @@ -294,8 +309,8 @@ function createVideoRequestData(bid, bidderRequest) { } function createBannerRequestData(bids, bidderRequest) { - let topLocation = utils.getTopWindowLocation(); - let referrer = utils.getTopWindowReferrer(); + let topLocation = getTopWindowLocation(bidderRequest); + let topReferrer = getTopWindowReferrer(); let slots = bids.map(bid => { return { slot: bid.adUnitCode, @@ -309,8 +324,8 @@ function createBannerRequestData(bids, bidderRequest) { page: topLocation.href, domain: topLocation.hostname, search: topLocation.search, - secure: topLocation.protocol === 'https:' ? 1 : 0, - referrer: referrer, + secure: topLocation.protocol.indexOf('https') === 0 ? 1 : 0, + referrer: topReferrer, ua: navigator.userAgent, deviceOs: getOsVersion(), isMobile: isMobile() ? 1 : 0, diff --git a/modules/betweenBidAdapter.js b/modules/betweenBidAdapter.js index 98140fe68e6..d93c4433980 100644 --- a/modules/betweenBidAdapter.js +++ b/modules/betweenBidAdapter.js @@ -1,4 +1,4 @@ -import {registerBidder} from 'src/adapters/bidderFactory'; +import {registerBidder} from '../src/adapters/bidderFactory'; const BIDDER_CODE = 'between'; @@ -69,13 +69,13 @@ export const spec = { for (var i = 0; i < serverResponse.body.length; i++) { let bidResponse = { requestId: serverResponse.body[i].bidid, - cpm: serverResponse.body[i].cpm || 123, - width: serverResponse.body[i].w || 200, - height: serverResponse.body[i].h || 400, - ttl: serverResponse.body[i].ttl || 120, - creativeId: serverResponse.body[i].creativeid || 123, + cpm: serverResponse.body[i].cpm || 0, + width: serverResponse.body[i].w, + height: serverResponse.body[i].h, + ttl: serverResponse.body[i].ttl, + creativeId: serverResponse.body[i].creativeid, currency: serverResponse.body[i].currency || 'RUB', - netRevenue: serverResponse.body[i].netRevenue || false, + netRevenue: serverResponse.body[i].netRevenue || true, ad: serverResponse.body[i].ad }; bidResponses.push(bidResponse); @@ -106,10 +106,14 @@ export const spec = { }); } */ + // syncs.push({ + // type: 'iframe', + // url: '//acdn.adnxs.com/ib/static/usersync/v3/async_usersync.html' + // }); syncs.push({ type: 'iframe', - url: '//acdn.adnxs.com/ib/static/usersync/v3/async_usersync.html' - }) + url: 'http://ads.betweendigital.com/sspmatch-iframe' + }); return syncs; } } diff --git a/modules/betweenBidAdapter.md b/modules/betweenBidAdapter.md index 4ecd07e60bc..426d0aa2ed7 100644 --- a/modules/betweenBidAdapter.md +++ b/modules/betweenBidAdapter.md @@ -12,7 +12,7 @@ About us : http://betweendigital.com # Test Parameters -``` +```javascript var adUnits = [ { code: 'test-div', @@ -28,4 +28,69 @@ About us : http://betweendigital.com ] } ]; +``` + +Where: + +* s - the section id +* code - the id of the iframe tag to which the ads will be rendered + +# Example page + +```html + + + + + + + + + + +

Prebid.js BetweenBidAdapter Test

+ + + ``` \ No newline at end of file diff --git a/modules/bidfluenceBidAdapter.js b/modules/bidfluenceBidAdapter.js new file mode 100644 index 00000000000..4a9c4433ee0 --- /dev/null +++ b/modules/bidfluenceBidAdapter.js @@ -0,0 +1,128 @@ +import * as utils from '../src/utils'; +import { registerBidder } from '../src/adapters/bidderFactory'; +const BIDDER_CODE = 'bidfluence'; + +function stdTimezoneOffset(t) { + const jan = new Date(t.getFullYear(), 0, 1); + const jul = new Date(t.getFullYear(), 6, 1); + return Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset()); +} +function dst(t) { + return t.getTimezoneOffset() < stdTimezoneOffset(t); +} +function getBdfTz(d) { + let tz = d.getTimezoneOffset(); + if (dst(d)) { + tz += 60; + } + return tz.toString(); +} +function getUTCDate() { + var m = new Date(); + var dateString = m.getUTCFullYear() + '/' + + ('0' + (m.getUTCMonth() + 1)).slice(-2) + '/' + + ('0' + m.getUTCDate()).slice(-2) + ' ' + + ('0' + m.getUTCHours()).slice(-2) + ':' + + ('0' + m.getUTCMinutes()).slice(-2) + ':' + + ('0' + m.getUTCSeconds()).slice(-2); + + return dateString; +} + +export const spec = { + code: BIDDER_CODE, + isBidRequestValid: function (bid) { + return !!bid.params.placementId || !!bid.params.publisherId; + }, + + buildRequests: function (validBidRequests, bidderRequest) { + const body = document.getElementsByTagName('body')[0]; + const refInfo = bidderRequest.refererInfo; + const gdpr = bidderRequest.gdprConsent; + const vpW = Math.max(window.innerWidth || body.clientWidth || 0) + 2; + const vpH = Math.max(window.innerHeight || body.clientHeight || 0) + 2; + const sr = screen.height > screen.width ? screen.height + 'x' + screen.width + 'x' + screen.colorDepth : screen.width + 'x' + screen.height + 'x' + screen.colorDepth; + + var payload = { + v: '2.0', + azr: true, + ck: utils.cookiesAreEnabled(), + re: refInfo ? refInfo.referer : '', + st: refInfo ? refInfo.stack : [], + tz: getBdfTz(new Date()), + sr: sr, + tm: bidderRequest.timeout, + vp: vpW + 'x' + vpH, + sdt: getUTCDate(), + top: refInfo ? refInfo.reachedTop : false, + gdpr: gdpr ? gdpr.gdprApplies : false, + gdprc: gdpr ? gdpr.consentString : '', + bids: [] + }; + + utils._each(validBidRequests, function (bidRequest) { + var params = bidRequest.params; + var sizes = utils.parseSizesInput(bidRequest.sizes)[0]; + var width = sizes.split('x')[0]; + var height = sizes.split('x')[1]; + + var currentBidPayload = { + bid: bidRequest.bidId, + tid: params.placementId, + pid: params.publisherId, + rp: params.reservePrice || 0, + w: width, + h: height + }; + + payload.bids.push(currentBidPayload); + }); + + const payloadString = JSON.stringify(payload); + return { + method: 'POST', + url: `//bdf${payload.bids[0].pid}.bidfluence.com/Prebid`, + data: payloadString, + options: { contentType: 'text/plain' } + }; + }, + + interpretResponse: function (serverResponse, bidRequest) { + const bidResponses = []; + const response = serverResponse.body; + + utils._each(response.Bids, function (currentResponse) { + var cpm = currentResponse.Cpm || 0; + + if (cpm > 0) { + const bidResponse = { + requestId: currentResponse.BidId, + cpm: cpm, + width: currentResponse.Width, + height: currentResponse.Height, + creativeId: currentResponse.CreativeId, + ad: currentResponse.Ad, + currency: 'USD', + netRevenue: true, + ttl: 360 + }; + bidResponses.push(bidResponse); + } + }); + + return bidResponses; + }, + + getUserSyncs: function (serverResponses) { + if (serverResponses.userSyncs) { + const syncs = serverResponses.UserSyncs.map((sync) => { + return { + type: sync.Type === 'ifr' ? 'iframe' : 'image', + url: sync.Url + }; + }); + return syncs; + } + } +}; +registerBidder(spec); diff --git a/modules/bidfluenceBidAdapter.md b/modules/bidfluenceBidAdapter.md new file mode 100644 index 00000000000..34dbb3d3a1c --- /dev/null +++ b/modules/bidfluenceBidAdapter.md @@ -0,0 +1,31 @@ +# Overview + +``` +Module Name: Bidfluence Adapter +Module Type: Bidder Adapter +Maintainer: integrations@bidfluence.com +prebid_1_0_supported : true +gdpr_supported: true +``` + +# Description + +Bidfluence adapter for prebid. + +# Test Parameters + +``` +var adUnits = [ + { + code: 'test-prebid', + sizes: [[300, 250]], + bids: [{ + bidder: 'bidfluence', + params: { + placementId: '1000', + publisherId: '1000' + } + }] + } +] +``` diff --git a/modules/bizzclickBidAdapter.js b/modules/bizzclickBidAdapter.js index 62ada43b970..a9b202b4c97 100644 --- a/modules/bizzclickBidAdapter.js +++ b/modules/bizzclickBidAdapter.js @@ -1,6 +1,6 @@ -import { registerBidder } from 'src/adapters/bidderFactory'; -import { BANNER, NATIVE, VIDEO } from 'src/mediaTypes'; -import * as utils from 'src/utils'; +import { registerBidder } from '../src/adapters/bidderFactory'; +import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes'; +import * as utils from '../src/utils'; const BIDDER_CODE = 'bizzclick'; const URL = '//supply.bizzclick.com/?c=o&m=multi'; diff --git a/modules/brainyBidAdapter.js b/modules/brainyBidAdapter.js index e8e5bda9f37..a5d076d8fd0 100644 --- a/modules/brainyBidAdapter.js +++ b/modules/brainyBidAdapter.js @@ -1,6 +1,6 @@ -import * as utils from 'src/utils'; -import {registerBidder} from 'src/adapters/bidderFactory'; -import { BANNER } from 'src/mediaTypes'; +import * as utils from '../src/utils'; +import {registerBidder} from '../src/adapters/bidderFactory'; +import { BANNER } from '../src/mediaTypes'; const BIDDER_CODE = 'brainy'; const BASE_URL = '//proparm.jp/ssp/p/pbjs'; diff --git a/modules/bridgewellBidAdapter.js b/modules/bridgewellBidAdapter.js index 65fa49a25f8..cac827e5a5d 100644 --- a/modules/bridgewellBidAdapter.js +++ b/modules/bridgewellBidAdapter.js @@ -1,6 +1,6 @@ -import * as utils from 'src/utils'; -import {registerBidder} from 'src/adapters/bidderFactory'; -import {BANNER, NATIVE} from 'src/mediaTypes'; +import * as utils from '../src/utils'; +import {registerBidder} from '../src/adapters/bidderFactory'; +import {BANNER, NATIVE} from '../src/mediaTypes'; import find from 'core-js/library/fn/array/find'; const BIDDER_CODE = 'bridgewell'; diff --git a/modules/c1xBidAdapter.js b/modules/c1xBidAdapter.js index ff1b011f787..1e8d3cf2e0a 100644 --- a/modules/c1xBidAdapter.js +++ b/modules/c1xBidAdapter.js @@ -1,6 +1,6 @@ -import { registerBidder } from 'src/adapters/bidderFactory'; -import * as utils from 'src/utils'; -import { userSync } from 'src/userSync'; +import { registerBidder } from '../src/adapters/bidderFactory'; +import * as utils from '../src/utils'; +import { userSync } from '../src/userSync'; const BIDDER_CODE = 'c1x'; const URL = 'https://ht.c1exchange.com/ht'; diff --git a/modules/ccxBidAdapter.js b/modules/ccxBidAdapter.js index ee287592975..226ed44f6da 100644 --- a/modules/ccxBidAdapter.js +++ b/modules/ccxBidAdapter.js @@ -1,6 +1,6 @@ -import * as utils from 'src/utils' -import { registerBidder } from 'src/adapters/bidderFactory' -import { config } from 'src/config' +import * as utils from '../src/utils' +import { registerBidder } from '../src/adapters/bidderFactory' +import { config } from '../src/config' const BIDDER_CODE = 'ccx' const BID_URL = 'https://delivery.clickonometrics.pl/ortb/prebid/bid' const SUPPORTED_VIDEO_PROTOCOLS = [2, 3, 5, 6] diff --git a/modules/clickforceBidAdapter.js b/modules/clickforceBidAdapter.js index c9e54f9efac..16ecdf713d9 100644 --- a/modules/clickforceBidAdapter.js +++ b/modules/clickforceBidAdapter.js @@ -1,6 +1,6 @@ -import * as utils from 'src/utils'; -import {registerBidder} from 'src/adapters/bidderFactory'; -import {BANNER, NATIVE} from 'src/mediaTypes'; +import * as utils from '../src/utils'; +import {registerBidder} from '../src/adapters/bidderFactory'; +import {BANNER, NATIVE} from '../src/mediaTypes'; const BIDDER_CODE = 'clickforce'; const ENDPOINT_URL = '//ad.doublemax.net/adserver/prebid.json?cb=' + new Date().getTime() + '&hb=1&ver=1.21'; diff --git a/modules/coinzillaBidAdapter.js b/modules/coinzillaBidAdapter.js new file mode 100644 index 00000000000..6918d47eb10 --- /dev/null +++ b/modules/coinzillaBidAdapter.js @@ -0,0 +1,89 @@ +import * as utils from '../src/utils'; +import {config} from '../src/config'; +import {registerBidder} from '../src/adapters/bidderFactory'; + +const BIDDER_CODE = 'coinzilla'; +const ENDPOINT_URL = 'https://request.czilladx.com/serve/request.php'; + +export const spec = { + code: BIDDER_CODE, + aliases: ['czlla'], // short code + + /** + * 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: function (bid) { + return !!(bid.params.placementId); + }, + + /** + * Make a server request from the list of BidRequests. + * + * @return Array Info describing the request to the server. + * @param validBidRequests + * @param bidderRequest + */ + buildRequests: function (validBidRequests, bidderRequest) { + if (validBidRequests.length === 0) { + return []; + } + return validBidRequests.map(bidRequest => { + const sizes = utils.parseSizesInput(bidRequest.sizes)[0]; + const width = sizes.split('x')[0]; + const height = sizes.split('x')[1]; + const payload = { + placementId: bidRequest.params.placementId, + width: width, + height: height, + bidId: bidRequest.bidId, + referer: bidderRequest.refererInfo.referer, + }; + return { + method: 'POST', + url: ENDPOINT_URL, + data: payload + }; + }); + }, + + /** + * Unpack the response from the server into a list of bids. + * + * @param {ServerResponse} serverResponse A successful response from the server. + * @param bidRequest + * @return {Bid[]} An array of bids which were nested inside the server. + */ + interpretResponse: function (serverResponse, bidRequest) { + const bidResponses = []; + const response = serverResponse.body; + const creativeId = response.creativeId || 0; + const width = response.width || 0; + const height = response.height || 0; + const cpm = response.cpm || 0; + if (width !== 0 && height !== 0 && cpm !== 0 && creativeId !== 0) { + const dealId = response.dealid || ''; + const currency = response.currency || 'EUR'; + const netRevenue = (response.netRevenue === undefined) ? true : response.netRevenue; + const referrer = bidRequest.data.referer; + const bidResponse = { + requestId: response.requestId, + cpm: cpm, + width: response.width, + height: response.height, + creativeId: creativeId, + dealId: dealId, + currency: currency, + netRevenue: netRevenue, + ttl: config.getConfig('_bidderTimeout'), + referrer: referrer, + ad: response.ad + }; + bidResponses.push(bidResponse); + } + return bidResponses; + }, +}; +registerBidder(spec); diff --git a/modules/coinzillaBidAdapter.md b/modules/coinzillaBidAdapter.md new file mode 100644 index 00000000000..c7da4efb1a4 --- /dev/null +++ b/modules/coinzillaBidAdapter.md @@ -0,0 +1,24 @@ +# Overview + +``` +Module Name: Coinzilla Bidder Adapter +Module Type: Coinzilla Adapter +Maintainer: technical@sevio.com +``` + +# Description + +Our module helps you have an easier time implementing Coinzilla on your website. All you have to do is replace the ``placementId`` with your zoneID, depending on the required size in your account dashboard. If you need additional information please contact us at ``publishers@coinzilla.com``. +# Test Parameters +``` + var adUnits = [{ + code: 'test-ad-div', + sizes: [[300, 250]], + bids: [{ + bidder: 'coinzilla', + params: { + placementId: 'testPlacementId' + } + }] + }]; +``` \ No newline at end of file diff --git a/modules/collectcentBidAdapter.js b/modules/collectcentBidAdapter.js new file mode 100644 index 00000000000..50ac377788e --- /dev/null +++ b/modules/collectcentBidAdapter.js @@ -0,0 +1,93 @@ +import { registerBidder } from '../src/adapters/bidderFactory'; +import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes'; +import * as utils from '../src/utils'; + +const BIDDER_CODE = 'collectcent'; +const URL_MULTI = '//publishers.motionspots.com/?c=o&m=multi'; +const URL_SYNC = '//publishers.motionspots.com/?c=o&m=cookie'; + +export const spec = { + code: BIDDER_CODE, + supportedMediaTypes: [BANNER, VIDEO, NATIVE], + + /** + * Determines whether or not the given bid request is valid. + * + * @param {object} bid The bid to validate. + * @return boolean True if this is a valid bid, and false otherwise. + */ + isBidRequestValid: (bid) => { + return Boolean(bid.bidId && + bid.params && + !isNaN(bid.params.placementId) && + spec.supportedMediaTypes.indexOf(bid.params.traffic) !== -1 + ); + }, + + /** + * Make a server request from the list of BidRequests. + * + * @param {BidRequest[]} validBidRequests A non-empty list of valid bid requests that should be sent to the Server. + * @return ServerRequest Info describing the request to the server. + */ + buildRequests: (validBidRequests, bidderRequest) => { + let winTop; + try { + winTop = window.top; + } catch (e) { + utils.logMessage(e); + winTop = window; + }; + + const placements = []; + const location = bidderRequest ? new URL(bidderRequest.refererInfo.referer) : winTop.location; + const request = { + 'secure': (location.protocol === 'https:') ? 1 : 0, + 'deviceWidth': winTop.screen.width, + 'deviceHeight': winTop.screen.height, + 'host': location.host, + 'page': location.pathname, + 'placements': placements + }; + + for (let i = 0; i < validBidRequests.length; i++) { + const bid = validBidRequests[i]; + const params = bid.params; + placements.push({ + placementId: params.placementId, + bidId: bid.bidId, + sizes: bid.sizes, + traffic: params.traffic + }); + } + return { + method: 'POST', + url: URL_MULTI, + data: request + }; + }, + + /** + * Unpack the response from the server into a list of bids. + * + * @param {*} serverResponse A successful response from the server. + * @return {Bid[]} An array of bids which were nested inside the server. + */ + interpretResponse: (serverResponse) => { + try { + serverResponse = serverResponse.body; + } catch (e) { + utils.logMessage(e); + }; + return serverResponse; + }, + + getUserSyncs: () => { + return [{ + type: 'image', + url: URL_SYNC + }]; + } +}; + +registerBidder(spec); diff --git a/modules/collectcentBidAdapter.md b/modules/collectcentBidAdapter.md new file mode 100644 index 00000000000..938bdc420cd --- /dev/null +++ b/modules/collectcentBidAdapter.md @@ -0,0 +1,27 @@ +# Overview + +``` +Module Name: Collectcent SSP Bidder Adapter +Module Type: Bidder Adapter +Maintainer: dev.collectcent@gmail.com +``` + +# Description + +Module that connects to Collectcent SSP demand sources + +# Test Parameters +``` + var adUnits = [{ + code: 'placementCode', + sizes: [[300, 250]], + bids: [{ + bidder: 'collectcent', + params: { + placementId: 0, + traffic: 'banner' + } + }] + } + ]; +``` diff --git a/modules/colombiaBidAdapter.js b/modules/colombiaBidAdapter.js new file mode 100644 index 00000000000..e5ebc41ebfd --- /dev/null +++ b/modules/colombiaBidAdapter.js @@ -0,0 +1,72 @@ +import * as utils from '../src/utils'; +import {config} from '../src/config'; +import {registerBidder} from '../src/adapters/bidderFactory'; +const BIDDER_CODE = 'colombia'; +const ENDPOINT_URL = 'https://ade.clmbtech.com/cde/prebid.htm'; +const HOST_NAME = document.location.protocol + '//' + window.location.host; + +export const spec = { + code: BIDDER_CODE, + aliases: ['clmb'], + isBidRequestValid: function(bid) { + return !!(bid.params.placementId); + }, + buildRequests: function(validBidRequests) { + return validBidRequests.map(bidRequest => { + const params = bidRequest.params; + const sizes = utils.parseSizesInput(bidRequest.sizes)[0]; + const width = sizes.split('x')[0]; + const height = sizes.split('x')[1]; + const placementId = params.placementId; + const cb = Math.floor(Math.random() * 99999999999); + const referrer = encodeURIComponent(utils.getTopWindowUrl()); + const bidId = bidRequest.bidId; + const payload = { + v: 'hb1', + p: placementId, + w: width, + h: height, + cb: cb, + r: referrer, + uid: bidId, + t: 'i', + d: HOST_NAME, + }; + return { + method: 'POST', + url: ENDPOINT_URL, + data: payload, + } + }); + }, + interpretResponse: function(serverResponse, bidRequest) { + const bidResponses = []; + const response = serverResponse.body; + const crid = response.creativeId || 0; + const width = response.width || 0; + const height = response.height || 0; + const cpm = response.cpm || 0; + if (width !== 0 && height !== 0 && cpm !== 0 && crid !== 0) { + const dealId = response.dealid || ''; + const currency = response.currency || 'USD'; + const netRevenue = (response.netRevenue === undefined) ? true : response.netRevenue; + const referrer = utils.getTopWindowUrl(); + const bidResponse = { + requestId: bidRequest.data.uid, + cpm: cpm, + width: response.width, + height: response.height, + creativeId: crid, + dealId: dealId, + currency: currency, + netRevenue: netRevenue, + ttl: config.getConfig('_bidderTimeout'), + referrer: referrer, + ad: response.ad + }; + bidResponses.push(bidResponse); + } + return bidResponses; + } +} +registerBidder(spec); diff --git a/modules/colombiaBidAdapter.md b/modules/colombiaBidAdapter.md new file mode 100644 index 00000000000..2131fcb4c5a --- /dev/null +++ b/modules/colombiaBidAdapter.md @@ -0,0 +1,27 @@ +# Overview + +``` +Module Name: COLOMBIA Bidder Adapter +Module Type: Bidder Adapter +Maintainer: colombiaonline@timesinteret.in +``` + +# Description + +Connect to COLOMBIA for bids. + +THE COLOMBIA adapter requires setup and approval from the COLOMBIA team. Please reach out to your account team or colombiaonline@timesinteret.in for more information. + +# Test Parameters +``` + var adUnits = [{ + code: 'test-ad-div', + sizes: [[300, 250]], + bids: [{ + bidder: 'colombia', + params: { + placementId: '307466' + } + }] + }]; +``` diff --git a/modules/colossussspBidAdapter.js b/modules/colossussspBidAdapter.js index 22b0415936c..2ad320ede38 100644 --- a/modules/colossussspBidAdapter.js +++ b/modules/colossussspBidAdapter.js @@ -1,6 +1,6 @@ -import { registerBidder } from 'src/adapters/bidderFactory'; -import { BANNER, NATIVE, VIDEO } from 'src/mediaTypes'; -import * as utils from 'src/utils'; +import { registerBidder } from '../src/adapters/bidderFactory'; +import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes'; +import * as utils from '../src/utils'; const BIDDER_CODE = 'colossusssp'; const URL = '//colossusssp.com/?c=o&m=multi'; diff --git a/modules/consentManagement.js b/modules/consentManagement.js index 0618a3f752c..f0ec5ed3f6d 100644 --- a/modules/consentManagement.js +++ b/modules/consentManagement.js @@ -4,9 +4,9 @@ * and make it available for any GDPR supported adapters to read/pass this information to * their system. */ -import * as utils from 'src/utils'; -import { config } from 'src/config'; -import { gdprDataHandler } from 'src/adaptermanager'; +import * as utils from '../src/utils'; +import { config } from '../src/config'; +import { gdprDataHandler } from '../src/adapterManager'; import includes from 'core-js/library/fn/array/includes'; import strIncludes from 'core-js/library/fn/string/includes'; @@ -17,14 +17,27 @@ const DEFAULT_ALLOW_AUCTION_WO_CONSENT = true; export let userCMP; export let consentTimeout; export let allowAuction; +export let staticConsentData; let consentData; +let addedConsentHook = false; // add new CMPs here, with their dedicated lookup function const cmpCallMap = { - 'iab': lookupIabConsent + 'iab': lookupIabConsent, + 'static': lookupStaticConsentData }; +/** + * This function reads the consent string from the config to obtain the consent information of the user. + * @param {function(string)} cmpSuccess acts as a success callback when the value is read from config; pass along consentObject (string) from CMP + * @param {function(string)} cmpError acts as an error callback while interacting with the config string; pass along an error message (string) + * @param {object} hookConfig contains module related variables (see comment in requestBidsHook function) + */ +function lookupStaticConsentData(cmpSuccess, cmpError, hookConfig) { + cmpSuccess(staticConsentData, hookConfig); +} + /** * This function handles interacting with an IAB compliant CMP to obtain the consent information of the user. * Given the async nature of the CMP's API, we pass in acting success/error callback functions to exit this function @@ -44,11 +57,11 @@ function lookupIabConsent(cmpSuccess, cmpError, hookConfig) { } return { - consentDataCallback: function(consentResponse) { + consentDataCallback: function (consentResponse) { cmpResponse.getConsentData = consentResponse; afterEach(); }, - vendorConsentsCallback: function(consentResponse) { + vendorConsentsCallback: function (consentResponse) { cmpResponse.getVendorConsents = consentResponse; afterEach(); } @@ -70,7 +83,7 @@ function lookupIabConsent(cmpSuccess, cmpError, hookConfig) { // if the CMP is not found, the iframe function will call the cmpError exit callback to abort the rest of the CMP workflow try { cmpFunction = window.__cmp || utils.getWindowTop().__cmp; - } catch (e) {} + } catch (e) { } if (utils.isFn(cmpFunction)) { cmpFunction('getConsentData', null, callbackHandler.consentDataCallback); @@ -85,7 +98,7 @@ function lookupIabConsent(cmpSuccess, cmpError, hookConfig) { while (!cmpFrame) { try { if (f.frames['__cmpLocator']) cmpFrame = f; - } catch (e) {} + } catch (e) { } if (f === window.top) break; f = f.parent; } @@ -127,13 +140,15 @@ function lookupIabConsent(cmpSuccess, cmpError, hookConfig) { function callCmpWhileInIframe(commandName, cmpFrame, moduleCallback) { /* Setup up a __cmp function to do the postMessage and stash the callback. This function behaves (from the caller's perspective identicially to the in-frame __cmp call */ - window.__cmp = function(cmd, arg, callback) { + window.__cmp = function (cmd, arg, callback) { let callId = Math.random() + ''; - let msg = {__cmpCall: { - command: cmd, - parameter: arg, - callId: callId - }}; + let msg = { + __cmpCall: { + command: cmd, + parameter: arg, + callId: callId + } + }; cmpCallbacks[callId] = callback; cmpFrame.postMessage(msg, '*'); } @@ -170,7 +185,7 @@ function lookupIabConsent(cmpSuccess, cmpError, hookConfig) { /** * If consentManagement module is enabled (ie included in setConfig), this hook function will attempt to fetch the * user's encoded consent string from the supported CMP. Once obtained, the module will store this - * data as part of a gdprConsent object which gets transferred to adaptermanager's gdprDataHandler object. + * data as part of a gdprConsent object which gets transferred to adapterManager's gdprDataHandler object. * This information is later added into the bidRequest object for any supported adapters to read/pass along to their system. * @param {object} reqBidsConfigObj required; This is the same param that's used in pbjs.requestBids. * @param {function} fn required; The next function in the chain, used by hook.js @@ -348,7 +363,20 @@ export function setConfig(config) { allowAuction = DEFAULT_ALLOW_AUCTION_WO_CONSENT; utils.logInfo(`consentManagement config did not specify allowAuctionWithoutConsent. Using system default setting (${DEFAULT_ALLOW_AUCTION_WO_CONSENT}).`); } + utils.logInfo('consentManagement module has been activated...'); - $$PREBID_GLOBAL$$.requestBids.addHook(requestBidsHook, 50); + + if (userCMP === 'static') { + if (utils.isPlainObject(config.consentData)) { + staticConsentData = config.consentData; + consentTimeout = 0; + } else { + utils.logError(`consentManagement config with cmpApi: 'static' did not specify consentData. No consents will be available to adapters.`); + } + } + if (!addedConsentHook) { + $$PREBID_GLOBAL$$.requestBids.addHook(requestBidsHook, 50); + } + addedConsentHook = true; } config.getConfig('consentManagement', config => setConfig(config.consentManagement)); diff --git a/modules/consumableBidAdapter.js b/modules/consumableBidAdapter.js index 98ebf44d683..9374be62452 100644 --- a/modules/consumableBidAdapter.js +++ b/modules/consumableBidAdapter.js @@ -1,177 +1,205 @@ -import * as utils from 'src/utils'; -import { registerBidder } from 'src/adapters/bidderFactory'; -import { config } from 'src/config'; -import { EVENTS } from 'src/constants.json'; +import * as utils from '../src/utils'; +import { registerBidder } from '../src/adapters/bidderFactory'; -const CONSUMABLE_BIDDER_CODE = 'consumable' +const BIDDER_CODE = 'consumable'; -const SYNC_TYPES = { - IFRAME: { - TAG: 'iframe', - TYPE: 'iframe' - }, - IMAGE: { - TAG: 'img', - TYPE: 'image' - } -}; +const BASE_URI = 'https://e.serverbid.com/api/v2' -const pubapiTemplate = ({host, network, placement}) => `//${host}/pubapi/3.0/${network}/${placement}/0/0/ADTECH;v=2;cmd=bid;cors=yes;misc=${new Date().getTime()}` -const CONSUMABLE_URL = 'adserver-us.adtech.advertising.com'; -const CONSUMABLE_TTL = 60; -const CONSUMABLE_NETWORK = '10947.1'; +let siteId = 0; +let bidder = 'consumable'; -$$PREBID_GLOBAL$$.consumableGlobals = { - pixelsDropped: false -}; +export const spec = { + code: BIDDER_CODE, + + /** + * 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: function(bid) { + return !!(bid.params.networkId && bid.params.siteId && bid.params.unitId && bid.params.unitName); + }, -function parsePixelItems(pixels) { - let itemsRegExp = /<(img|iframe)[\s\S]*?src\s*=\s*("|')(.*?)\2/gi; - let tagNameRegExp = /\w*(?=\s)/; - let srcRegExp = /src=("|')(.*?)\1/; - let pixelsItems = []; - - if (pixels) { - let matchedItems = pixels.match(itemsRegExp); - if (matchedItems) { - matchedItems.forEach(item => { - let tagName = item.match(tagNameRegExp)[0]; - let url = item.match(srcRegExp)[2]; - - if (tagName && url) { - pixelsItems.push({ - type: tagName === SYNC_TYPES.IMAGE.TAG ? SYNC_TYPES.IMAGE.TYPE : SYNC_TYPES.IFRAME.TYPE, - url: url - }); - } - }); + /** + * 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: function(validBidRequests) { + // Do we need to group by bidder? i.e. to make multiple requests for + // different endpoints. + + let ret = { + method: 'POST', + url: '', + data: '', + bidRequest: [] + }; + + if (validBidRequests.length < 1) { + return ret; } - } - - return pixelsItems; -} - -function _buildConsumableUrl(bid) { - const params = bid.params; - return pubapiTemplate({ - host: CONSUMABLE_URL, - network: params.network || CONSUMABLE_NETWORK, - placement: parseInt(params.placement, 10) - }); -} - -function formatBidRequest(bid) { - let bidRequest; - - bidRequest = { - url: _buildConsumableUrl(bid), - method: 'GET' - }; - - bidRequest.bidderCode = bid.bidder; - bidRequest.bidId = bid.bidId; - bidRequest.userSyncOn = bid.params.userSyncOn; - bidRequest.unitId = bid.params.unitId; - bidRequest.unitName = bid.params.unitName; - bidRequest.zoneId = bid.params.zoneId; - bidRequest.network = bid.params.network || CONSUMABLE_NETWORK; + // These variables are used in creating the user sync URL. + siteId = validBidRequests[0].params.siteId; + bidder = validBidRequests[0].bidder; + + const data = Object.assign({ + placements: [], + time: Date.now(), + user: {}, + url: utils.getTopWindowUrl(), + referrer: document.referrer, + enableBotFiltering: true, + includePricingData: true, + parallel: true + }, validBidRequests[0].params); + + validBidRequests.map(bid => { + const placement = Object.assign({ + divName: bid.bidId, + adTypes: bid.adTypes || getSize(bid.sizes) + }, bid.params); + + if (placement.networkId && placement.siteId && placement.unitId && placement.unitName) { + data.placements.push(placement); + } + }); - return bidRequest; -} + ret.data = JSON.stringify(data); + ret.bidRequest = validBidRequests; + ret.url = BASE_URI; -function _parseBidResponse (response, bidRequest) { - let bidData; - try { - bidData = response.seatbid[0].bid[0]; - } catch (e) { - return; - } + return ret; + }, - let cpm; + /** + * Unpack the response from the server into a list of bids. + * + * @param {*} serverResponse A successful response from the server. + * @return {Bid[]} An array of bids which were nested inside the server. + */ + interpretResponse: function(serverResponse, bidRequest) { + let bid; + let bids; + let bidId; + let bidObj; + let bidResponses = []; + + bids = bidRequest.bidRequest; + + serverResponse = (serverResponse || {}).body; + for (let i = 0; i < bids.length; i++) { + bid = {}; + bidObj = bids[i]; + bidId = bidObj.bidId; + + if (serverResponse) { + const decision = serverResponse.decisions && serverResponse.decisions[bidId]; + const price = decision && decision.pricing && decision.pricing.clearPrice; + + if (decision && price) { + bid.requestId = bidId; + bid.cpm = price; + bid.width = decision.width; + bid.height = decision.height; + bid.unitId = bidObj.params.unitId; + bid.unitName = bidObj.params.unitName; + bid.ad = retrieveAd(decision, bid.unitId, bid.unitName); + bid.currency = 'USD'; + bid.creativeId = decision.adId; + bid.ttl = 30; + bid.netRevenue = true; + bid.referrer = utils.getTopWindowUrl(); + + bidResponses.push(bid); + } + } + } - if (bidData.ext && bidData.ext.encp) { - cpm = bidData.ext.encp; - } else { - cpm = bidData.price; + return bidResponses; + }, - if (cpm === null || isNaN(cpm)) { - utils.logError('Invalid cpm in bid response', CONSUMABLE_BIDDER_CODE, bid); - return; + getUserSyncs: function(syncOptions) { + if (syncOptions.iframeEnabled) { + return [{ + type: 'iframe', + url: '//sync.serverbid.com/ss/' + siteId + '.html' + }]; + } else { + utils.logWarn(bidder + ': Please enable iframe based user syncing.'); } } - cpm = cpm * (parseFloat(bidRequest.zoneId) / parseFloat(bidRequest.network)); +}; - let oad = bidData.adm; - let cb = bidRequest.network === '9599.1' ? 7654321 : Math.round(new Date().getTime()); - let ad = '' + oad; - ad += ''; - ad += ''; - ad += '' - if (response.ext && response.ext.pixels) { - if (config.getConfig('consumable.userSyncOn') !== EVENTS.BID_RESPONSE) { - ad += _formatPixels(response.ext.pixels); +const sizeMap = [ + null, + '120x90', + '120x90', + '468x60', + '728x90', + '300x250', + '160x600', + '120x600', + '300x100', + '180x150', + '336x280', + '240x400', + '234x60', + '88x31', + '120x60', + '120x240', + '125x125', + '220x250', + '250x250', + '250x90', + '0x0', + '200x90', + '300x50', + '320x50', + '320x480', + '185x185', + '620x45', + '300x125', + '800x250' +]; + +sizeMap[77] = '970x90'; +sizeMap[123] = '970x250'; +sizeMap[43] = '300x600'; +sizeMap[286] = '970x66'; +sizeMap[3230] = '970x280'; +sizeMap[429] = '486x60'; +sizeMap[374] = '700x500'; +sizeMap[934] = '300x1050'; +sizeMap[1578] = '320x100'; +sizeMap[331] = '320x250'; +sizeMap[3301] = '320x267'; +sizeMap[2730] = '728x250'; + +function getSize(sizes) { + const result = []; + sizes.forEach(function(size) { + const index = sizeMap.indexOf(size[0] + 'x' + size[1]); + if (index >= 0) { + result.push(index); } - } - - return { - bidderCode: bidRequest.bidderCode, - requestId: bidRequest.bidId, - ad: ad, - cpm: cpm, - width: bidData.w, - height: bidData.h, - creativeId: bidData.crid, - pubapiId: response.id, - currency: response.cur, - dealId: bidData.dealid, - netRevenue: true, - ttl: CONSUMABLE_TTL - }; + }); + return result; } -function _formatPixels (pixels) { - let formattedPixels = pixels.replace(/<\/?script( type=('|")text\/javascript('|")|)?>/g, ''); +function retrieveAd(decision, unitId, unitName) { + let oad = decision.contents && decision.contents[0] && decision.contents[0].body + utils.createTrackPixelHtml(decision.impressionUrl); + let cb = Math.round(new Date().getTime()); + let ad = '' + oad; + ad += ''; + ad += ''; + ad += '' - return ''; + return ad; } -export const spec = { - code: CONSUMABLE_BIDDER_CODE, - isBidRequestValid: function(bid) { - return bid.params && bid.params.placement - }, - buildRequests: function (bids) { - return bids.map(formatBidRequest); - }, - interpretResponse: function ({body}, bidRequest) { - if (!body) { - utils.logError('Empty bid response', bidRequest.bidderCode, body); - } else { - let bid = _parseBidResponse(body, bidRequest); - if (bid) { - return bid; - } - } - }, - getUserSyncs: function(options, bidResponses) { - let bidResponse = bidResponses[0]; - - if (config.getConfig('consumable.userSyncOn') === EVENTS.BID_RESPONSE) { - if (!$$PREBID_GLOBAL$$.consumableGlobals.pixelsDropped && bidResponse.ext && bidResponse.ext.pixels) { - $$PREBID_GLOBAL$$.consumableGlobals.pixelsDropped = true; - - return parsePixelItems(bidResponse.ext.pixels); - } - } - - return []; - } -}; - registerBidder(spec); diff --git a/modules/consumableBidAdapter.md b/modules/consumableBidAdapter.md index f6dfe8131c6..2189494ebd4 100644 --- a/modules/consumableBidAdapter.md +++ b/modules/consumableBidAdapter.md @@ -14,19 +14,35 @@ Module that connects to Consumable's demand sources ```javascript var adUnits = [ { - code: 'test-ad-div', + code: 'test-ad-1', sizes: [[300, 250]], bids: [ { bidder: 'consumable', params: { - placement: '1234567', - unitId: '1234', - unitName: 'cnsmbl-300x250', - zoneId: '13136.52' + networkId: '9969', + siteId: '980639', + unitId: '123456', + unitName: 'cnsmbl-unit' + } + } + ] + }, + { + code: 'test-ad-2', + sizes: [[300, 250]], + bids: [ + { + bidder: 'consumable', + params: { + networkId: '9969', + siteId: '980639', + unitId: '123456', + unitName: 'cnsmbl-unit', + zoneIds: [178503] } } ] } ]; -``` +``` \ No newline at end of file diff --git a/modules/contentigniteBidAdapter.js b/modules/contentigniteBidAdapter.js index 423ec0ba8da..2e3092114f6 100644 --- a/modules/contentigniteBidAdapter.js +++ b/modules/contentigniteBidAdapter.js @@ -1,6 +1,6 @@ -import { registerBidder } from 'src/adapters/bidderFactory'; -import { config } from 'src/config'; -import * as utils from 'src/utils'; +import { registerBidder } from '../src/adapters/bidderFactory'; +import { config } from '../src/config'; +import * as utils from '../src/utils'; const BIDDER_CODE = 'contentignite'; diff --git a/modules/conversantBidAdapter.js b/modules/conversantBidAdapter.js index aae892f4eed..cb0661c4417 100644 --- a/modules/conversantBidAdapter.js +++ b/modules/conversantBidAdapter.js @@ -1,10 +1,10 @@ -import * as utils from 'src/utils'; -import {registerBidder} from 'src/adapters/bidderFactory'; -import { BANNER, VIDEO } from 'src/mediaTypes'; +import * as utils from '../src/utils'; +import {registerBidder} from '../src/adapters/bidderFactory'; +import { BANNER, VIDEO } from '../src/mediaTypes'; const BIDDER_CODE = 'conversant'; const URL = '//web.hb.ad.cpe.dotomi.com/s2s/header/24'; -const VERSION = '2.2.3'; +const VERSION = '2.2.4'; export const spec = { code: BIDDER_CODE, @@ -62,8 +62,6 @@ export const spec = { siteId = utils.getBidIdParameter('site_id', bid.params); requestId = bid.auctionId; - const format = convertSizes(bid.sizes); - const imp = { id: bid.bidId, secure: secure, @@ -72,25 +70,31 @@ export const spec = { displaymanagerver: VERSION }; - copyOptProperty(bid.params, 'tag_id', imp, 'tagid'); + copyOptProperty(bid.params.tag_id, imp, 'tagid'); if (isVideoRequest(bid)) { - const video = { - w: format[0].w, - h: format[0].h - }; + const videoData = utils.deepAccess(bid, 'mediaTypes.video') || {}; + const format = convertSizes(videoData.playerSize || bid.sizes); + const video = {}; + + if (format && format[0]) { + copyOptProperty(format[0].w, video, 'w'); + copyOptProperty(format[0].h, video, 'h'); + } - copyOptProperty(bid.params, 'position', video, 'pos'); - copyOptProperty(bid.params, 'mimes', video); - copyOptProperty(bid.params, 'maxduration', video); - copyOptProperty(bid.params, 'protocols', video); - copyOptProperty(bid.params, 'api', video); + copyOptProperty(bid.params.position, video, 'pos'); + copyOptProperty(bid.params.mimes || videoData.mimes, video, 'mimes'); + copyOptProperty(bid.params.maxduration, video, 'maxduration'); + copyOptProperty(bid.params.protocols || videoData.protocols, video, 'protocols'); + copyOptProperty(bid.params.api || videoData.api, video, 'api'); imp.video = video; } else { + const bannerData = utils.deepAccess(bid, 'mediaTypes.banner') || {}; + const format = convertSizes(bannerData.sizes || bid.sizes); const banner = {format: format}; - copyOptProperty(bid.params, 'position', banner, 'pos'); + copyOptProperty(bid.params.position, banner, 'pos'); imp.banner = banner; } @@ -249,11 +253,12 @@ function getDevice() { */ function convertSizes(bidSizes) { let format; - - if (bidSizes.length === 2 && typeof bidSizes[0] === 'number' && typeof bidSizes[1] === 'number') { - format = [{w: bidSizes[0], h: bidSizes[1]}]; - } else { - format = utils._map(bidSizes, d => { return {w: d[0], h: d[1]}; }); + if (Array.isArray(bidSizes)) { + if (bidSizes.length === 2 && typeof bidSizes[0] === 'number' && typeof bidSizes[1] === 'number') { + format = [{w: bidSizes[0], h: bidSizes[1]}]; + } else { + format = utils._map(bidSizes, d => { return {w: d[0], h: d[1]}; }); + } } return format; @@ -272,16 +277,13 @@ function isVideoRequest(bid) { /** * Copy property if exists from src to dst * - * @param {object} src - * @param {string} srcName - * @param {object} dst - * @param {string} [dstName] - Optional. If not specified then srcName is used. + * @param {object} src - source object + * @param {object} dst - destination object + * @param {string} dstName - destination property name */ -function copyOptProperty(src, srcName, dst, dstName) { - dstName = dstName || srcName; - const obj = utils.getBidIdParameter(srcName, src); - if (obj !== '') { - dst[dstName] = obj; +function copyOptProperty(src, dst, dstName) { + if (src) { + dst[dstName] = src; } } diff --git a/modules/conversantBidAdapter.md b/modules/conversantBidAdapter.md index 1afdad6d544..3ce83d8c893 100644 --- a/modules/conversantBidAdapter.md +++ b/modules/conversantBidAdapter.md @@ -22,20 +22,20 @@ var adUnits = [ }] },{ code: 'video-test-div', - sizes: [640, 480], mediaTypes: { video: { - context: 'instream' + context: 'instream', + playerSize: [640, 480] } }, bids: [{ bidder: "conversant", params: { - site_id: '88563', + site_id: '108060', api: [2], protocols: [1, 2], mimes: ['video/mp4'] } }] }]; -``` \ No newline at end of file +``` diff --git a/modules/coxBidAdapter.js b/modules/coxBidAdapter.js deleted file mode 100644 index eac1b2081d2..00000000000 --- a/modules/coxBidAdapter.js +++ /dev/null @@ -1,165 +0,0 @@ -'use strict'; - -import * as utils from 'src/utils'; -import { BANNER } from 'src/mediaTypes'; -import { config } from 'src/config'; -import { registerBidder } from 'src/adapters/bidderFactory'; - -const helper = (() => { - let srTestCapabilities = () => { // Legacy - let plugins = navigator.plugins; - let flashVer = -1; - let sf = 'Shockwave Flash'; - - if (plugins && plugins.length > 0) { - if (plugins[sf + ' 2.0'] || plugins[sf]) { - var swVer2 = plugins[sf + ' 2.0'] ? ' 2.0' : ''; - var flashDescription = plugins[sf + swVer2].description; - flashVer = flashDescription.split(' ')[2].split('.')[0]; - } - } - if (flashVer > 4) return 15; else return 7; - }; - - let getRand = () => { - return Math.round(Math.random() * 100000000); - }; - - return { - ingest: function(rawBids = []) { - const adZoneAttributeKeys = ['id', 'size', 'thirdPartyClickUrl', 'dealId']; - const otherKeys = ['siteId', 'wrapper', 'referrerUrl']; - let state = this.createState(); - - rawBids.forEach(oneBid => { - let params = oneBid.params || {}; - - state.tag.auctionId = oneBid.auctionId; - state.tag.responseJSON = true; - - if (params.id && (/^\d+x\d+$/).test(params.size)) { - let adZoneKey = 'as' + params.id; - let zone = {}; - - zone.transactionId = oneBid.transactionId; - zone.bidId = oneBid.bidId; - state.tag.zones = state.tag.zones || {}; - state.tag.zones[adZoneKey] = zone; - - adZoneAttributeKeys.forEach(key => { if (params[key]) zone[key] = params[key]; }); - otherKeys.forEach(key => { if (params[key]) state.tag[key] = params[key]; }); - - // Check for an environment setting - if (params.env) state.env = params.env; - - // Update the placement map - let [x, y] = (params.size).split('x'); - state.placementMap[adZoneKey] = { - 'b': oneBid.bidId, - 'w': x, - 'h': y - }; - } - }); - return state; - }, - - transform: function(coxRawBids = {}, state) { - const pbjsBids = []; - - for (let adZoneKey in state.placementMap) { - let responded = coxRawBids[adZoneKey] - let ingested = state.placementMap[adZoneKey]; - - utils.logInfo('coxBidAdapter.transform', adZoneKey, responded, ingested); - - if (ingested && responded && responded['ad'] && responded['price'] > 0) { - pbjsBids.push({ - requestId: ingested['b'], - cpm: responded['price'], - width: ingested['w'], - height: ingested['h'], - creativeId: responded['adid'], - dealId: responded['dealid'], - currency: 'USD', - netRevenue: true, - ttl: 300, - ad: responded['ad'] - }); - } - } - return pbjsBids; - }, - - getUrl: state => { - // Bounce if the tag is invalid - if (!state.tag.zones) return null; - - let src = (document.location.protocol === 'https:' ? 'https://' : 'http://') + - (!state.env || state.env === 'PRD' ? '' : state.env === 'PPE' ? 'ppe-' : state.env === 'STG' ? 'staging-' : '') + - 'ad.afy11.net/ad?mode=11&nif=0&sf=0&sfd=0&ynw=0&hb=1' + - '&ct=' + srTestCapabilities() + - '&rand=' + getRand() + - '&rk1=' + getRand() + - '&rk2=' + new Date().valueOf() / 1000; - - state.tag.pageUrl = config.getConfig('pageUrl') || utils.getTopWindowUrl(); - state.tag.puTop = true; - - // Attach the serialized tag to our string - src += '&ab=' + encodeURIComponent(JSON.stringify(state.tag)); - - return src; - }, - - createState: () => ({ - env: '', - tag: {}, - placementMap: {} - }) - }; -})(); - -export const spec = { - code: 'cox', - supportedMediaTypes: [BANNER], - - isBidRequestValid: function(bid) { - return !!(bid.params && bid.params.id && bid.params.size); - }, - - buildRequests: function(validBidReqs) { - let state = helper.ingest(validBidReqs); - let url = helper.getUrl(state); - - return !url ? {} : { - method: 'GET', - url: url, - state - }; - }, - - interpretResponse: function({ body: { zones: coxRawBids } }, { state }) { - let bids = helper.transform(coxRawBids, state); - - utils.logInfo('coxBidAdapter.interpretResponse', bids); - return bids; - }, - - getUserSyncs: function(syncOptions, thing) { - try { - var [{ body: { tpCookieSync: urls = [] } }] = thing; - } catch (ignore) { - return []; - } - - let syncs = []; - if (syncOptions.pixelEnabled && urls.length > 0) { - syncs = urls.map((url) => ({ type: 'image', url: url })) - } - utils.logInfo('coxBidAdapter.getuserSyncs', syncs); - return syncs; - } -}; - -registerBidder(spec); diff --git a/modules/coxBidAdapter.md b/modules/coxBidAdapter.md deleted file mode 100644 index f4460b969ed..00000000000 --- a/modules/coxBidAdapter.md +++ /dev/null @@ -1,41 +0,0 @@ -# Overview - -``` -Module Name: Cox/COMET Bid Adapter -Module Type: Bidder Adapter -Maintainer: reynold@coxds.com -``` - -# Description - -Cox/COMET's adapter integration to the Prebid library. - -# Test Parameters - -``` -var adUnits = [ - { - code: 'test-leaderboard', - sizes: [[728, 90]], - bids: [{ - bidder: 'cox', - params: { - size: '728x90', - id: 2000005991607, - siteId: 2000100948180, - } - }] - }, { - code: 'test-banner', - sizes: [[300, 250]], - bids: [{ - bidder: 'cox', - params: { - size: '300x250', - id: 2000005991707, - siteId: 2000100948180, - } - }] - } -] -``` \ No newline at end of file diff --git a/modules/criteoBidAdapter.js b/modules/criteoBidAdapter.js index 0595fc890f0..ff612aff905 100755 --- a/modules/criteoBidAdapter.js +++ b/modules/criteoBidAdapter.js @@ -1,10 +1,12 @@ -import { loadExternalScript } from 'src/adloader'; -import { registerBidder } from 'src/adapters/bidderFactory'; -import { parse } from 'src/url'; -import * as utils from 'src/utils'; +import { loadExternalScript } from '../src/adloader'; +import { registerBidder } from '../src/adapters/bidderFactory'; +import { parse } from '../src/url'; +import * as utils from '../src/utils'; import find from 'core-js/library/fn/array/find'; +import JSEncrypt from 'jsencrypt/bin/jsencrypt'; +import sha256 from 'crypto-js/sha256'; -const ADAPTER_VERSION = 11; +const ADAPTER_VERSION = 16; const BIDDER_CODE = 'criteo'; const CDB_ENDPOINT = '//bidder.criteo.com/cdb'; const CRITEO_VENDOR_ID = 91; @@ -17,6 +19,13 @@ const PROFILE_ID_PUBLISHERTAG = 185; // Unminified source code can be found in: https://github.com/Prebid-org/prebid-js-external-js-criteo/blob/master/dist/prod.js const PUBLISHER_TAG_URL = '//static.criteo.net/js/ld/publishertag.prebid.js'; +export const FAST_BID_PUBKEY = `-----BEGIN PUBLIC KEY----- +MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDO1BjAITkFTtP0IMzmF7qsqhpu +y1dGaTPHnjMU9mRZsrnfR3C0sEN5pYEzEcFRPnkJjJuhH8Rnh5+CE+LcKg0Z8ZZ7 +OmOSj0/qnYTAYCu0cR5LiyWG79KlIgUyMbp92ulGg24gAyGrVn4+v/4c53WlOEUp +4YWvb82G0CD5NcDNpQIDAQAB +-----END PUBLIC KEY-----`; + /** @type {BidderSpec} */ export const spec = { code: BIDDER_CODE, @@ -89,6 +98,7 @@ export const spec = { const bidId = bidRequest.bidId; const bid = { requestId: bidId, + adId: slot.bidId || utils.getUniqueIdentifierStr(), cpm: slot.cpm, currency: slot.currency, netRevenue: true, @@ -118,6 +128,26 @@ export const spec = { adapter.handleBidTimeout(); } }, + + /** + * @param {Bid} bid + */ + onBidWon: (bid) => { + if (publisherTagAvailable()) { + const adapter = Criteo.PubTag.Adapters.Prebid.GetAdapter(bid.auctionId); + adapter.handleBidWon(bid); + } + }, + + /** + * @param {Bid} bid + */ + onSetTargeting: (bid) => { + if (publisherTagAvailable()) { + const adapter = Criteo.PubTag.Adapters.Prebid.GetAdapter(bid.auctionId); + adapter.handleSetTargeting(bid); + } + }, }; /** @@ -251,6 +281,34 @@ function createNativeAd(id, payload, callback) { `; } +export function cryptoVerify(key, hash, code) { + var jse = new JSEncrypt(); + jse.setPublicKey(key); + return jse.verify(code, hash, sha256); +} + +function validateFastBid(fastBid) { + // The value stored must contain the file's encrypted hash as first line + const firstLineEnd = fastBid.indexOf('\n'); + const firstLine = fastBid.substr(0, firstLineEnd).trim(); + if (firstLine.substr(0, 9) !== '// Hash: ') { + utils.logWarn('No hash found in FastBid'); + return false; + } + + // Remove the hash part from the locally stored value + const fileEncryptedHash = firstLine.substr(9); + const publisherTag = fastBid.substr(firstLineEnd + 1); + + // Verify the hash using cryptography + try { + return cryptoVerify(FAST_BID_PUBKEY, fileEncryptedHash, publisherTag); + } catch (e) { + utils.logWarn('Failed to verify Criteo FastBid'); + return undefined; + } +} + /** * @return {boolean} */ @@ -258,13 +316,17 @@ function tryGetCriteoFastBid() { try { const fastBid = localStorage.getItem('criteo_fast_bid'); if (fastBid !== null) { - eval(fastBid); // eslint-disable-line no-eval - return true; + if (validateFastBid(fastBid) === false) { + utils.logWarn('Invalid Criteo FastBid found'); + localStorage.removeItem('criteo_fast_bid'); + } else { + utils.logInfo('Using Criteo FastBid'); + eval(fastBid); // eslint-disable-line no-eval + } } } catch (e) { // Unable to get fast bid } - return false; } registerBidder(spec); diff --git a/modules/currency.js b/modules/currency.js index 25eddc5b993..2116e624449 100644 --- a/modules/currency.js +++ b/modules/currency.js @@ -1,16 +1,17 @@ -import bidfactory from 'src/bidfactory'; -import { STATUS } from 'src/constants'; -import { ajax } from 'src/ajax'; -import * as utils from 'src/utils'; -import { config } from 'src/config'; -import { hooks } from 'src/hook.js'; - -const DEFAULT_CURRENCY_RATE_URL = 'https://currency.prebid.org/latest.json'; +import { createBid } from '../src/bidfactory'; +import { STATUS } from '../src/constants'; +import { ajax } from '../src/ajax'; +import * as utils from '../src/utils'; +import { config } from '../src/config'; +import { hooks } from '../src/hook.js'; + +const DEFAULT_CURRENCY_RATE_URL = 'https://cdn.jsdelivr.net/gh/prebid/currency-file@1/latest.json?date=$$TODAY$$'; const CURRENCY_RATE_PRECISION = 4; var bidResponseQueue = []; var conversionCache = {}; var currencyRatesLoaded = false; +var needToCallForCurrencyFile = true; var adServerCurrency = 'USD'; export var currencySupportEnabled = false; @@ -34,7 +35,7 @@ var defaultRates; * { * rubicon: 'USD' * } - * @param {string} [config.conversionRateFile = 'http://currency.prebid.org/latest.json'] + * @param {string} [config.conversionRateFile = 'URL pointing to conversion file'] * Optional path to a file containing currency conversion data. Prebid.org hosts a file that is used as the default, * if not specified. * @param {object} [config.rates] @@ -56,10 +57,15 @@ export function setConfig(config) { if (typeof config.rates === 'object') { currencyRates.conversions = config.rates; currencyRatesLoaded = true; + needToCallForCurrencyFile = false; // don't call if rates are already specified } if (typeof config.defaultRates === 'object') { defaultRates = config.defaultRates; + + // set up the default rates to be used if the rate file doesn't get loaded in time + currencyRates.conversions = defaultRates; + currencyRatesLoaded = true; } if (typeof config.adServerCurrency === 'string') { @@ -70,6 +76,25 @@ export function setConfig(config) { utils.logInfo('currency using override conversionRateFile:', config.conversionRateFile); url = config.conversionRateFile; } + + // see if the url contains a date macro + // this is a workaround to the fact that jsdelivr doesn't currently support setting a 24-hour HTTP cache header + // So this is an approach to let the browser cache a copy of the file each day + // We should remove the macro once the CDN support a day-level HTTP cache setting + const macroLocation = url.indexOf('$$TODAY$$'); + if (macroLocation !== -1) { + // get the date to resolve the macro + const d = new Date(); + let month = `${d.getMonth() + 1}`; + let day = `${d.getDate()}`; + if (month.length < 2) month = `0${month}`; + if (day.length < 2) day = `0${day}`; + const todaysDate = `${d.getFullYear()}${month}${day}`; + + // replace $$TODAY$$ with todaysDate + url = `${url.substring(0, macroLocation)}${todaysDate}${url.substring(macroLocation + 9, url.length)}`; + } + initCurrency(url); } else { // currency support is disabled, setting defaults @@ -84,8 +109,6 @@ config.getConfig('currency', config => setConfig(config.currency)); function errorSettingsRates(msg) { if (defaultRates) { - currencyRates.conversions = defaultRates; - currencyRatesLoaded = true; utils.logWarn(msg); utils.logWarn('Currency failed loading rates, falling back to currency.defaultRates'); } else { @@ -101,7 +124,9 @@ function initCurrency(url) { hooks['addBidResponse'].addHook(addBidResponseHook, 100); - if (!currencyRates.conversions) { + // call for the file if we haven't already + if (needToCallForCurrencyFile) { + needToCallForCurrencyFile = false; ajax(url, { success: function (response) { @@ -129,6 +154,7 @@ function resetCurrency() { conversionCache = {}; currencySupportEnabled = false; currencyRatesLoaded = false; + needToCallForCurrencyFile = true; currencyRates = {}; bidderCurrencyDefault = {}; } @@ -154,6 +180,14 @@ export function addBidResponseHook(adUnitCode, bid, fn) { bid.currency = 'USD'; } + let fromCurrency = bid.currency; + let cpm = bid.cpm; + + // used for analytics + bid.getCpmInNewCurrency = function(toCurrency) { + return (parseFloat(cpm) * getCurrencyConversion(fromCurrency, toCurrency)).toFixed(3); + }; + // execute immediately if the bid is already in the desired currency if (bid.currency === adServerCurrency) { return fn.apply(this, arguments); @@ -178,19 +212,15 @@ function wrapFunction(fn, context, params) { let fromCurrency = bid.currency; try { let conversion = getCurrencyConversion(fromCurrency); - let cpm = bid.originalCpm = bid.cpm; + bid.originalCpm = bid.cpm; bid.originalCurrency = bid.currency; if (conversion !== 1) { bid.cpm = (parseFloat(bid.cpm) * conversion).toFixed(4); bid.currency = adServerCurrency; } - // used for analytics - bid.getCpmInNewCurrency = function(toCurrency) { - return (parseFloat(cpm) * getCurrencyConversion(fromCurrency, toCurrency)).toFixed(3); - }; } catch (e) { utils.logWarn('Returning NO_BID, getCurrencyConversion threw error: ', e); - params[1] = bidfactory.createBid(STATUS.NO_BID, { + params[1] = createBid(STATUS.NO_BID, { bidder: bid.bidderCode || bid.bidder, bidId: bid.adId }); diff --git a/modules/danmarketBidAdapter.js b/modules/danmarketBidAdapter.js index d851af424ce..77f90f43319 100644 --- a/modules/danmarketBidAdapter.js +++ b/modules/danmarketBidAdapter.js @@ -1,5 +1,5 @@ -import * as utils from 'src/utils'; -import {registerBidder} from 'src/adapters/bidderFactory'; +import * as utils from '../src/utils'; +import {registerBidder} from '../src/adapters/bidderFactory'; const BIDDER_CODE = 'danmarket'; const ENDPOINT_URL = '//ads.danmarketplace.com/hb'; const TIME_TO_LIVE = 360; diff --git a/modules/dgadsBidAdapter.js b/modules/dgadsBidAdapter.js index 7d47cc7acf6..c8a97d86990 100644 --- a/modules/dgadsBidAdapter.js +++ b/modules/dgadsBidAdapter.js @@ -1,8 +1,9 @@ -import {registerBidder} from 'src/adapters/bidderFactory'; -import * as utils from 'src/utils'; -import { BANNER, NATIVE } from 'src/mediaTypes'; +import {registerBidder} from '../src/adapters/bidderFactory'; +import * as utils from '../src/utils'; +import { BANNER, NATIVE } from '../src/mediaTypes'; const BIDDER_CODE = 'dgads'; +const UID_NAME = 'dgads_uid'; const ENDPOINT = 'https://ads-tr.bigmining.com/ad/p/bid'; export const spec = { @@ -27,13 +28,15 @@ export const spec = { const params = bidRequest.params; const data = {}; - data['location_id'] = params.location_id; - data['site_id'] = params.site_id; + data['_loc'] = params.location_id; + data['_medium'] = params.site_id; data['transaction_id'] = bidRequest.transactionId; data['bid_id'] = bidRequest.bidId; + data['referer'] = utils.getTopWindowUrl(); + data['_uid'] = getCookieUid(UID_NAME); return { - method: 'POST', + method: 'GET', url: ENDPOINT, data, }; @@ -84,5 +87,17 @@ function setNativeResponse(ad) { nativeResponce.impressionTrackers = ad.impressionTrackers || []; return nativeResponce; } +export function getCookieUid(uidName) { + if (utils.cookiesAreEnabled()) { + let cookies = document.cookie.split(';'); + for (let i = 0; i < cookies.length; i++) { + let value = cookies[i].split('='); + if (value[0].indexOf(uidName) > -1) { + return value[1]; + } + } + } + return ''; +} registerBidder(spec); diff --git a/modules/districtmDmxBidAdapter.js b/modules/districtmDMXBidAdapter.js similarity index 91% rename from modules/districtmDmxBidAdapter.js rename to modules/districtmDMXBidAdapter.js index 3ec0b72649e..12b7ac16c0c 100644 --- a/modules/districtmDmxBidAdapter.js +++ b/modules/districtmDMXBidAdapter.js @@ -1,6 +1,6 @@ -import * as utils from 'src/utils'; -import { registerBidder } from 'src/adapters/bidderFactory'; -import {config} from 'src/config'; +import * as utils from '../src/utils'; +import { registerBidder } from '../src/adapters/bidderFactory'; +import {config} from '../src/config'; const BIDDER_CODE = 'districtmDMX'; @@ -76,9 +76,9 @@ export const spec = { dmxRequest.regs = {}; dmxRequest.regs.ext = {}; dmxRequest.regs.ext.gdpr = bidderRequest.gdprConsent.gdprApplies === true ? 1 : 0; - if (dmxRequest.regs.ext.gdpr) { - dmxRequest.regs.ext.consent = bidderRequest.gdprConsent.consentString; - } + dmxRequest.user = {}; + dmxRequest.user.ext = {}; + dmxRequest.user.ext.consent = bidderRequest.gdprConsent.consentString; } let tosendtags = bidRequest.map(dmx => { var obj = {}; @@ -91,7 +91,7 @@ export const spec = { h: dmx.sizes[0][1] || 0, format: dmx.sizes.map(s => { return {w: s[0], h: s[1]}; - }) + }).filter(obj => typeof obj.w === 'number' && typeof obj.h === 'number') }; return obj; }); diff --git a/modules/districtmDmxBidAdapter.md b/modules/districtmDmxBidAdapter.md index a096029963c..2859bcfa19d 100644 --- a/modules/districtmDmxBidAdapter.md +++ b/modules/districtmDmxBidAdapter.md @@ -1,23 +1,105 @@ +``` +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 +* Bids returned in **NET** + + ## Media Types + +* Banner + +## 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. + +# 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 + } + }] + }]; +``` + + +# 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.* + ``` -Module Name: DistrictM Bid Adapter -Module Type: Bidder Adapter -Maintainer: steve@districtm.net +gulp build --modules=bidderModules.json ``` -# Description +###### 2. Configure the ad unit object -Adapter that connects to DistrictM's demand sources. -This version only support banner +Once Prebid is ready you may use the below example to create the adUnits object and begin building the configuration. -# Test Parameters +```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]], + sizes: [[300, 250], [300, 600], [728, 90]], } }, bids: [{ @@ -29,3 +111,7 @@ This version only support banner }] }]; ``` + +###### 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`. diff --git a/modules/divreachBidAdapter.md b/modules/divreachBidAdapter.md new file mode 100644 index 00000000000..643845782b8 --- /dev/null +++ b/modules/divreachBidAdapter.md @@ -0,0 +1,30 @@ +# Overview + +Module Name: DivReach Bidder Adapter +Module Type: Bidder Adapter +Maintainer: Zeke@divreach.com + +# Description + +Connects to DivReach demand source to fetch bids. +Please use ```divreach``` as the bidder code. + +# Test Parameters +``` + var adUnits = [ + { + code: 'desktop-banner-ad-div', + sizes: [[300, 250]], + bids: [ + { + bidder: "divreach", + params: { + accountID: '167283', + zoneID: '335105', + domain: 'ad.divreach.com', + } + } + ] + }, + ]; +``` diff --git a/modules/dspxBidAdapter.js b/modules/dspxBidAdapter.js new file mode 100644 index 00000000000..8b763202b7c --- /dev/null +++ b/modules/dspxBidAdapter.js @@ -0,0 +1,96 @@ +import * as utils from '../src/utils'; +import {config} from '../src/config'; +import {registerBidder} from '../src/adapters/bidderFactory'; + +const BIDDER_CODE = 'dspx'; +const ENDPOINT_URL = 'https://buyer.dspx.tv/request/'; + +export const spec = { + code: BIDDER_CODE, + aliases: ['dspx'], + isBidRequestValid: function(bid) { + return !!(bid.params.placement); + }, + buildRequests: function(validBidRequests, bidderRequest) { + return validBidRequests.map(bidRequest => { + const params = bidRequest.params; + const sizes = utils.parseSizesInput(bidRequest.sizes)[0]; + const width = sizes.split('x')[0]; + const height = sizes.split('x')[1]; + const placementId = params.placement; + + const rnd = Math.floor(Math.random() * 99999999999); + const referrer = encodeURIComponent(bidderRequest.refererInfo.referer); + const bidId = bidRequest.bidId; + const payload = { + _f: 'html', + alternative: 'prebid_js', + inventory_item_id: placementId, + srw: width, + srh: height, + idt: 100, + rnd: rnd, + ref: referrer, + bid_id: bidId, + }; + if (params.pfilter !== undefined) { + payload.pfilter = params.pfilter; + } + if (params.bcat !== undefined) { + payload.bcat = params.bcat; + } + if (params.dvt !== undefined) { + payload.dvt = params.dvt; + } + return { + method: 'GET', + url: ENDPOINT_URL, + data: objectToQueryString(payload), + } + }); + }, + interpretResponse: function(serverResponse, bidRequest) { + const bidResponses = []; + const response = serverResponse.body; + const crid = response.crid || 0; + const cpm = response.cpm / 1000000 || 0; + if (cpm !== 0 && crid !== 0) { + const dealId = response.dealid || ''; + const currency = response.currency || 'EUR'; + const netRevenue = (response.netRevenue === undefined) ? true : response.netRevenue; + const referrer = utils.getTopWindowUrl(); + const bidResponse = { + requestId: response.bid_id, + cpm: cpm, + width: response.width, + height: response.height, + creativeId: crid, + dealId: dealId, + currency: currency, + netRevenue: netRevenue, + ttl: config.getConfig('_bidderTimeout'), + referrer: referrer, + ad: response.adTag + }; + bidResponses.push(bidResponse); + } + return bidResponses; + } +} + +function objectToQueryString(obj, prefix) { + let str = []; + let p; + for (p in obj) { + if (obj.hasOwnProperty(p)) { + let k = prefix ? prefix + '[' + p + ']' : p; + let v = obj[p]; + str.push((v !== null && typeof v === 'object') + ? objectToQueryString(v, k) + : encodeURIComponent(k) + '=' + encodeURIComponent(v)); + } + } + return str.join('&'); +} + +registerBidder(spec); diff --git a/modules/dspxBidAdapter.md b/modules/dspxBidAdapter.md new file mode 100644 index 00000000000..362f4fbcb69 --- /dev/null +++ b/modules/dspxBidAdapter.md @@ -0,0 +1,73 @@ +# Overview + +``` +Module Name: Dspx Bidder Adapter +Module Type: Bidder Adapter +Maintainer: prebid@dspx.tv +``` + +# Description + +Dspx adapter for Prebid.js 1.0 + +# Test Parameters +``` + var adUnits = [ + { + code: 'test-div', + mediaTypes: { + banner: { + sizes: [ + [300, 250], + [300, 600], + ], // a display size + } + }, + bids: [ + { + bidder: "dspx", + params: { + placement: '101', + pfilter: { + floorprice: 1000000, // EUR * 1,000,000 + private_auction: 1, // Is private auction? 0 - no, 1 - yes + deals: [ + "666-9315-d58a7f9a-bdb9-4450-a3a2-046ba8ab2489;3;25000000;dspx-tv",// DEAL_ID;at;bidfloor;wseat1,wseat2;wadomain1,wadomain2" + "666-9315-d58a7f9a-bdb9-4450-a6a2-046ba8ab2489;3;25000000;dspx-tv",// DEAL_ID;at;bidfloor;wseat1,wseat2;wadomain1,wadomain2" + ], + geo: { // set client geo info manually (empty for auto detect) + lat: 52.52437, // Latitude from -90.0 to +90.0, where negative is south. + lon: 13.41053, // Longitude from -180.0 to +180.0, where negative is west + type: 1, // Source of location data: 1 - GPS/Location Services, 2 - IP Address, 3 - User provided (e.g. registration form) + country: 'DE', // Region of a country using FIPS 10-4 notation + region: 'DE-BE', // Region code using ISO-3166-2; 2-letter state code if USA. + regionfips104: 'GM', // Region of a country using FIPS 10-4 notation + city: 'BER', // City using United Nations Code for Trade and Transport Locations + zip: '10115' // Zip or postal code. + } + }, + bcat: "IAB2,IAB4", // List of Blocked Categories (IAB) - comma separated + dvt: "desktop|smartphone|tv|tablet" // DeVice Type (autodetect if not exists) + } + } + ] + },{ + code: 'test-div', + mediaTypes: { + banner: { + sizes: [[320, 50]], // a mobile size + } + }, + bids: [ + { + bidder: "dspx", + params: { + placement: 101 + } + } + ] + } + ]; +``` + +Required param field is only `placement`. \ No newline at end of file diff --git a/modules/ebdrBidAdapter.js b/modules/ebdrBidAdapter.js index f0f3d614a7d..79bf4bb1004 100644 --- a/modules/ebdrBidAdapter.js +++ b/modules/ebdrBidAdapter.js @@ -1,6 +1,6 @@ -import * as utils from 'src/utils'; -import { VIDEO, BANNER } from 'src/mediaTypes'; -import { registerBidder } from 'src/adapters/bidderFactory'; +import * as utils from '../src/utils'; +import { VIDEO, BANNER } from '../src/mediaTypes'; +import { registerBidder } from '../src/adapters/bidderFactory'; const BIDDER_CODE = 'ebdr'; export const spec = { code: BIDDER_CODE, diff --git a/modules/emx_digitalBidAdapter.js b/modules/emx_digitalBidAdapter.js new file mode 100644 index 00000000000..c42f98d4751 --- /dev/null +++ b/modules/emx_digitalBidAdapter.js @@ -0,0 +1,143 @@ +import * as utils from '../src/utils'; +import { + registerBidder +} from '../src/adapters/bidderFactory'; +import { + BANNER +} from '../src/mediaTypes'; +import { + config +} from '../src/config'; + +const BIDDER_CODE = 'emx_digital'; +const ENDPOINT = 'hb.emxdgt.com'; + +let emxAdapter = {}; + +emxAdapter.validateSizes = function(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: function (bid) { + return !!bid.params.tagid && + typeof bid.params.tagid === 'string' && + (typeof bid.params.bidfloor === 'undefined' || typeof bid.params.bidfloor === 'string') && + bid.bidder === BIDDER_CODE && + (emxAdapter.validateSizes(bid.mediaTypes.banner.sizes) || emxAdapter.validateSizes(bid.sizes)); + }, + buildRequests: function (validBidRequests, bidRequests) { + const {host, href, protocol} = utils.getTopWindowLocation(); + let emxData = {}; + let emxImps = []; + const auctionId = bidRequests.auctionId; + const timeout = config.getConfig('bidderTimeout'); + const timestamp = Date.now(); + const url = location.protocol + '//' + ENDPOINT + ('?t=' + timeout + '&ts=' + timestamp); + const networkProtocol = protocol.indexOf('https') > -1 ? 1 : 0; + + utils._each(validBidRequests, function (bid) { + let tagId = utils.getBidIdParameter('tagid', bid.params); + let bidFloor = parseFloat(utils.getBidIdParameter('bidfloor', bid.params)) || 0; + let sizes = bid.mediaTypes.banner.sizes; + if (!emxAdapter.validateSizes(sizes)) { + sizes = bid.sizes + } + let emxBid = { + id: bid.bidId, + tid: bid.transactionId, + tagid: tagId, + secure: networkProtocol, + banner: { + format: sizes.map(function (size) { + return { + w: size[0], + h: size[1] + }; + }), + w: sizes[0][0], + h: sizes[0][1] + } + } + if (bidFloor > 0) { + emxBid.bidfloor = bidFloor + } + emxImps.push(emxBid); + }); + emxData = { + id: auctionId, + imp: emxImps, + site: { + domain: host, + page: href + } + }; + if (bidRequests.gdprConsent) { + emxData.regs = { + ext: { + gdpr: bidRequests.gdprConsent.gdprApplies === true ? 1 : 0 + } + }; + } + if (bidRequests.gdprConsent && bidRequests.gdprConsent.gdprApplies) { + emxData.user = { + ext: { + consent: bidRequests.gdprConsent.consentString + } + }; + } + return { + method: 'POST', + url: url, + data: JSON.stringify(emxData), + options: { + withCredentials: true + } + }; + }, + interpretResponse: function (serverResponse) { + let emxBidResponses = []; + let response = serverResponse.body || {}; + if (response.seatbid && response.seatbid.length > 0 && response.seatbid[0].bid) { + response.seatbid.forEach(function (emxBid) { + emxBid = emxBid.bid[0]; + emxBidResponses.push({ + requestId: emxBid.id, + cpm: emxBid.price, + width: emxBid.w, + height: emxBid.h, + creativeId: emxBid.crid || emxBid.id, + dealId: emxBid.dealid || null, + currency: 'USD', + netRevenue: true, + mediaType: BANNER, + ad: decodeURIComponent(emxBid.adm), + ttl: emxBid.ttl + }); + }); + } + return emxBidResponses; + }, + getUserSyncs: function (syncOptions) { + const syncs = []; + if (syncOptions.iframeEnabled) { + syncs.push({ + type: 'iframe', + url: '//biddr.brealtime.com/check.html' + }); + } + if (syncOptions.pixelEnabled) { + syncs.push({ + type: 'image', + url: '//edba.brealtime.com/' + }); + } + return syncs; + } +}; +registerBidder(spec); diff --git a/modules/emx_digitalBidAdapter.md b/modules/emx_digitalBidAdapter.md new file mode 100644 index 00000000000..c9435e2f1d1 --- /dev/null +++ b/modules/emx_digitalBidAdapter.md @@ -0,0 +1,38 @@ +# Overview + +``` +Module Name: EMX Digital Adapter +Module Type: Bidder Adapter +Maintainer: git@emxdigital.com +``` + +# Description + +The EMX Digital adapter provides publishers with access to the EMX Marketplace. The adapter is GDPR compliant. Please note that the adapter supports Banner media type only. + +Note: The EMX Digital adapter requires approval and implementation guidelines from the EMX team, including existing publishers that work with EMX Digital. Please reach out to your account manager or prebid@emxdigital.com for more information. + +The bidder code should be ```emx_digital``` +The params used by the bidder are : +```tagid``` - string (mandatory) +```bidfloor``` - string (optional) + +# Test Parameters +``` +var adUnits = [{ + code: 'banner-div', + mediaTypes: { + banner: { + sizes: [ + [300, 250], [300, 600] + } + }, + bids: [ + { + bidder: 'emx_digital', + params: { + tagid: '25251', + } + }] +}]; +``` diff --git a/modules/eplanningAnalyticsAdapter.js b/modules/eplanningAnalyticsAdapter.js index 2fe26488ebe..21ecddfbc3a 100644 --- a/modules/eplanningAnalyticsAdapter.js +++ b/modules/eplanningAnalyticsAdapter.js @@ -1,9 +1,9 @@ -import {ajax} from 'src/ajax'; -import adapter from 'src/AnalyticsAdapter'; -import adaptermanager from 'src/adaptermanager'; -import * as utils from 'src/utils'; +import {ajax} from '../src/ajax'; +import adapter from '../src/AnalyticsAdapter'; +import adapterManager from '../src/adapterManager'; +import * as utils from '../src/utils'; -const CONSTANTS = require('src/constants.json'); +const CONSTANTS = require('../src/constants.json'); const analyticsType = 'endpoint'; const EPL_HOST = 'https://ads.us.e-planning.net/hba/1/'; @@ -123,7 +123,7 @@ eplAnalyticsAdapter.enableAnalytics = function (config) { eplAnalyticsAdapter.originEnableAnalytics(config); }; -adaptermanager.registerAnalyticsAdapter({ +adapterManager.registerAnalyticsAdapter({ adapter: eplAnalyticsAdapter, code: 'eplanning' }); diff --git a/modules/eplanningBidAdapter.js b/modules/eplanningBidAdapter.js index 6ead42d4b2d..01a956d1bd8 100644 --- a/modules/eplanningBidAdapter.js +++ b/modules/eplanningBidAdapter.js @@ -1,5 +1,5 @@ -import * as utils from 'src/utils'; -import { registerBidder } from 'src/adapters/bidderFactory'; +import * as utils from '../src/utils'; +import { registerBidder } from '../src/adapters/bidderFactory'; const BIDDER_CODE = 'eplanning'; const rnd = Math.random(); @@ -112,7 +112,7 @@ export const spec = { } function cleanName(name) { - return name.replace(/_|\.|-|\//g, '').replace(/\)\(|\(|\)/g, '_').replace(/^_+|_+$/g, ''); + return name.replace(/_|\.|-|\//g, '').replace(/\)\(|\(|\)|:/g, '_').replace(/^_+|_+$/g, ''); } function getUrlConfig(bidRequests) { if (isTestRequest(bidRequests)) { diff --git a/modules/etargetBidAdapter.js b/modules/etargetBidAdapter.js index 0804fa25e87..4b1c6b21d79 100644 --- a/modules/etargetBidAdapter.js +++ b/modules/etargetBidAdapter.js @@ -1,7 +1,7 @@ 'use strict'; -import {registerBidder} from 'src/adapters/bidderFactory'; -import { BANNER, VIDEO } from 'src/mediaTypes'; +import {registerBidder} from '../src/adapters/bidderFactory'; +import { BANNER, VIDEO } from '../src/mediaTypes'; const BIDDER_CODE = 'etarget'; const countryMap = { diff --git a/modules/express.js b/modules/express.js index 8a5dc095476..1249822f587 100644 --- a/modules/express.js +++ b/modules/express.js @@ -1,5 +1,5 @@ -import * as utils from 'src/utils'; +import * as utils from '../src/utils'; const MODULE_NAME = 'express'; diff --git a/modules/fairtradeBidAdapter.js b/modules/fairtradeBidAdapter.js index dde64d839ca..55f24ab8906 100644 --- a/modules/fairtradeBidAdapter.js +++ b/modules/fairtradeBidAdapter.js @@ -1,5 +1,5 @@ -import * as utils from 'src/utils'; -import {registerBidder} from 'src/adapters/bidderFactory'; +import * as utils from '../src/utils'; +import {registerBidder} from '../src/adapters/bidderFactory'; const BIDDER_CODE = 'fairtrade'; const ENDPOINT_URL = '//pool.fair-trademedia.com/hb'; const TIME_TO_LIVE = 360; diff --git a/modules/fidelityBidAdapter.js b/modules/fidelityBidAdapter.js index ca7dc9d6fd6..078e9d2fcce 100644 --- a/modules/fidelityBidAdapter.js +++ b/modules/fidelityBidAdapter.js @@ -1,13 +1,14 @@ -import * as utils from 'src/utils'; -import {registerBidder} from 'src/adapters/bidderFactory'; - -const BIDDER_CODE = 'fidelity'; -const BIDDER_SERVER = 'x.fidelity-media.com'; -export const spec = { - code: BIDDER_CODE, - isBidRequestValid: function(bid) { - return !!(bid && bid.params && bid.params.zoneid); - }, +import * as utils from '../src/utils'; +import {registerBidder} from '../src/adapters/bidderFactory'; + +const BIDDER_CODE = 'fidelity'; +const BIDDER_SERVER = 'x.fidelity-media.com'; +const FIDELITY_VENDOR_ID = 408; +export const spec = { + code: BIDDER_CODE, + isBidRequestValid: function(bid) { + return !!(bid && bid.params && bid.params.zoneid); + }, buildRequests: function(validBidRequests, bidderRequest) { return validBidRequests.map(bidRequest => { var server = bidRequest.params.server || BIDDER_SERVER; @@ -20,15 +21,13 @@ export const spec = { zoneid: bidRequest.params.zoneid, floor: parseFloat(bidRequest.params.floor) > 0 ? bidRequest.params.floor : 0, charset: document.charSet || document.characterSet, - defloc: utils.getTopWindowUrl(), - altloc: window.location.href, subid: 'hb', flashver: getFlashVersion(), tmax: bidderRequest.timeout, + defloc: utils.getTopWindowUrl(), + referrer: utils.getTopWindowReferrer(), }; - if (document.referrer) { - payload.referrer = document.referrer; - } + setConsentParams(bidderRequest.gdprConsent, payload); return { method: 'GET', @@ -37,13 +36,13 @@ export const spec = { }; }); }, - interpretResponse: function(serverResponse) { - serverResponse = serverResponse.body; + interpretResponse: function(serverResponse) { + serverResponse = serverResponse.body; const bidResponses = []; if (serverResponse && serverResponse.seatbid) { serverResponse.seatbid.forEach(seatBid => seatBid.bid.forEach(bid => { const bidResponse = { - requestId: bid.impid, + requestId: bid.impid, creativeId: bid.impid, cpm: bid.price, width: bid.width, @@ -51,24 +50,30 @@ export const spec = { ad: bid.adm, netRevenue: bid.netRevenue, currency: bid.cur, - ttl: bid.ttl, + ttl: bid.ttl, }; bidResponses.push(bidResponse); })); } - return bidResponses; + return bidResponses; }, - getUserSyncs: function getUserSyncs(syncOptions) { + getUserSyncs: function getUserSyncs(syncOptions, serverResponses, gdprConsent) { if (syncOptions.iframeEnabled) { - return [{ - type: 'iframe', - url: '//' + BIDDER_SERVER + '/delivery/matches.php?type=iframe', + var url = '//' + BIDDER_SERVER + '/delivery/matches.php'; + var payload = { + type: 'iframe' + }; + setConsentParams(gdprConsent, payload); + + return [{ + type: 'iframe', + url: url + '?' + utils.parseQueryStringParameters(payload).replace(/\&$/, '') }]; } - } -} - + } +} + function getFlashVersion() { var plugins, plugin, result; @@ -82,6 +87,23 @@ function getFlashVersion() { } } return result || ''; -} - -registerBidder(spec); +} + +function setConsentParams(gdprConsent, payload) { + if (gdprConsent) { + payload.gdpr = 0; + payload.consent_str = ''; + payload.consent_given = 0; + if (typeof gdprConsent.gdprApplies !== 'undefined') { + payload.gdpr = gdprConsent.gdprApplies ? 1 : 0; + } + if (typeof gdprConsent.consentString !== 'undefined') { + payload.consent_str = gdprConsent.consentString; + } + if (gdprConsent.vendorData && gdprConsent.vendorData.vendorConsents && typeof gdprConsent.vendorData.vendorConsents[FIDELITY_VENDOR_ID.toString(10)] !== 'undefined') { + payload.consent_given = gdprConsent.vendorData.vendorConsents[FIDELITY_VENDOR_ID.toString(10)] ? 1 : 0; + } + } +} + +registerBidder(spec); diff --git a/modules/freewheel-sspBidAdapter.js b/modules/freewheel-sspBidAdapter.js index 87c1979ac5d..f7d647e0569 100644 --- a/modules/freewheel-sspBidAdapter.js +++ b/modules/freewheel-sspBidAdapter.js @@ -1,6 +1,6 @@ -import * as utils from 'src/utils'; -import { registerBidder } from 'src/adapters/bidderFactory'; -// import { config } from 'src/config'; +import * as utils from '../src/utils'; +import { registerBidder } from '../src/adapters/bidderFactory'; +// import { config } from '../src/config'; const BIDDER_CODE = 'freewheel-ssp'; @@ -68,6 +68,18 @@ function getPricing(xmlNode) { return princingData; } +function hashcode(inputString) { + var hash = 0; + var char; + if (inputString.length == 0) return hash; + for (var i = 0; i < inputString.length; i++) { + char = inputString.charCodeAt(i); + hash = ((hash << 5) - hash) + char; + hash = hash & hash; // Convert to 32bit integer + } + return hash; +} + function getCreativeId(xmlNode) { var creaId = ''; var adNodes = xmlNode.querySelectorAll('Ad'); @@ -116,7 +128,7 @@ function getAPIName(componentId) { function formatAdHTML(bid, size) { var integrationType = bid.params.format; - var divHtml = '
'; + var divHtml = '
'; var script = ''; var libUrl = ''; @@ -161,13 +173,15 @@ var getInBannerScript = function(bid, size) { }; var getOutstreamScript = function(bid) { - var placementCode = bid.adUnitCode; - var config = bid.params; // default placement if no placement is set if (!config.hasOwnProperty('domId') && !config.hasOwnProperty('auto') && !config.hasOwnProperty('p') && !config.hasOwnProperty('article')) { - config.domId = placementCode; + if (config.format === 'intext-roll') { + config.iframeMode = 'dfp'; + } else { + config.domId = 'freewheelssp_prebid_target'; + } } var script = 'var config = {' + @@ -216,11 +230,17 @@ export const spec = { utils.logMessage('Prebid.JS - freewheel bid adapter: only one ad unit is required.'); } + var zone = currentBidRequest.params.zoneId; + var timeInMillis = new Date().getTime(); + var keyCode = hashcode(zone + '' + timeInMillis); + var requestParams = { reqType: 'AdsSetup', protocolVersion: '2.0', - zoneId: currentBidRequest.params.zoneId, - componentId: getComponentId(currentBidRequest.params.format) + zoneId: zone, + componentId: getComponentId(currentBidRequest.params.format), + timestamp: timeInMillis, + pKey: keyCode }; // Add GDPR flag and consent string @@ -330,6 +350,7 @@ export const spec = { url: USER_SYNC_URL }]; } - } + }, + } registerBidder(spec); diff --git a/modules/freewheel-sspBidAdapter.md b/modules/freewheel-sspBidAdapter.md index ba7915c87e1..70ab2415279 100644 --- a/modules/freewheel-sspBidAdapter.md +++ b/modules/freewheel-sspBidAdapter.md @@ -18,7 +18,7 @@ Module that connects to Freewheel ssp's demand sources { bidder: "freewheel-ssp", params: { - zoneId : '277225' + zoneId : '41852' } } ] diff --git a/modules/fyberBidAdapter.js b/modules/fyberBidAdapter.js index 8309b1996c3..3586d0775ac 100644 --- a/modules/fyberBidAdapter.js +++ b/modules/fyberBidAdapter.js @@ -1,7 +1,7 @@ -import {logError, getTopWindowUrl, getTopWindowReferrer, getTopWindowLocation, createTrackPixelHtml} from 'src/utils'; -import { registerBidder } from 'src/adapters/bidderFactory'; -import { formatQS } from 'src/url'; -import { config } from 'src/config'; +import {logError, getTopWindowUrl, getTopWindowReferrer, getTopWindowLocation, createTrackPixelHtml} from '../src/utils'; +import { registerBidder } from '../src/adapters/bidderFactory'; +import { formatQS } from '../src/url'; +import { config } from '../src/config'; /** * @type {{CODE: string, V: string, RECTANGLE_SIZE: {W: number, H: number}, SPOT_TYPES: {INTERSTITIAL: string, RECTANGLE: string, FLOATING: string, BANNER: string}, DISPLAY_AD: number, ENDPOINT_URL: string, EVENTS_ENDPOINT_URL: string, RESPONSE_HEADERS_NAME: {PRICING_VALUE: string, AD_H: string, AD_W: string}}} diff --git a/modules/gammaBidAdapter.js b/modules/gammaBidAdapter.js index add3aad520b..926dae14790 100644 --- a/modules/gammaBidAdapter.js +++ b/modules/gammaBidAdapter.js @@ -1,5 +1,5 @@ -import * as utils from 'src/utils'; -import { registerBidder } from 'src/adapters/bidderFactory'; +import * as utils from '../src/utils'; +import { registerBidder } from '../src/adapters/bidderFactory'; const ENDPOINT = 'hb.gammaplatform.com'; const BIDDER_CODE = 'gamma'; diff --git a/modules/gambidBidAdapter.js b/modules/gamoshiBidAdapter.js similarity index 58% rename from modules/gambidBidAdapter.js rename to modules/gamoshiBidAdapter.js index f7026f9c76f..fa6632f9abb 100644 --- a/modules/gambidBidAdapter.js +++ b/modules/gamoshiBidAdapter.js @@ -1,65 +1,70 @@ -import * as utils from 'src/utils'; -import { registerBidder } from 'src/adapters/bidderFactory'; -import { config } from 'src/config'; +import * as utils from '../src/utils'; +import { registerBidder } from '../src/adapters/bidderFactory'; +import { config } from '../src/config'; import { Renderer } from '../src/Renderer'; -function getTopFrame() { - try { - return window.top === window ? 1 : 0; - } catch (e) { +export const helper = { + + getTopFrame: function () { + try { + return window.top === window ? 1 : 0; + } catch (e) { + } return 0; - } -} + }, -function startsWith(str, search) { - return str.substr(0, search.length) === search; -} + startsWith: function (str, search) { + return str.substr(0, search.length) === search; + }, -function getTopWindowDomain() { - const url = utils.getTopWindowUrl(); - const domainStart = url.indexOf('://') + '://'.length; - return url.substring(domainStart, url.indexOf('/', domainStart) < 0 ? url.length : url.indexOf('/', domainStart)); -} + getTopWindowDomain: function (url) { + const domainStart = url.indexOf('://') + '://'.length; + return url.substring(domainStart, url.indexOf('/', domainStart) < 0 ? url.length : url.indexOf('/', domainStart)); + }, -function getTopWindowReferer() { - try { - return window.top.document.referrer; - } catch (e) { - utils.logMessage('Failed obtaining top window\'s referrer: ', e); + getTopWindowReferer: function () { try { - return window.document.referrer; + return window.top.document.referrer; } catch (e) { - utils.logMessage('Failed obtaining current window\'s referrer: ', e); - return ''; + utils.logMessage('Failed obtaining top window\'s referrer: ', e); + try { + return window.document.referrer; + } catch (e) { + utils.logMessage('Failed obtaining current window\'s referrer: ', e); + } } + return ''; } } export const spec = { - code: 'gambid', - aliases: [], - supportedMediaTypes: [ 'banner', 'video' ], + code: 'gamoshi', + aliases: ['gambid', 'cleanmedia'], + supportedMediaTypes: ['banner', 'video'], - isBidRequestValid: function(bid) { + isBidRequestValid: function (bid) { return !!bid.params.supplyPartnerId && typeof bid.params.supplyPartnerId === 'string' && - (typeof bid.params[ 'rtbEndpoint' ] === 'undefined' || typeof bid.params[ 'rtbEndpoint' ] === 'string') && - (typeof bid.params.bidfloor === 'undefined' || typeof bid.params.bidfloor === 'number') && - (typeof bid.params[ 'adpos' ] === 'undefined' || typeof bid.params[ 'adpos' ] === 'number') && - (typeof bid.params[ 'protocols' ] === 'undefined' || Array.isArray(bid.params[ 'protocols' ])) && - (typeof bid.params.instl === 'undefined' || bid.params.instl === 0 || bid.params.instl === 1); + (typeof bid.params['rtbEndpoint'] === 'undefined' || typeof bid.params['rtbEndpoint'] === 'string') && + (typeof bid.params.bidfloor === 'undefined' || typeof bid.params.bidfloor === 'number') && + (typeof bid.params['adpos'] === 'undefined' || typeof bid.params['adpos'] === 'number') && + (typeof bid.params['protocols'] === 'undefined' || Array.isArray(bid.params['protocols'])) && + (typeof bid.params.instl === 'undefined' || bid.params.instl === 0 || bid.params.instl === 1); }, - buildRequests: function(validBidRequests, bidderRequest) { + buildRequests: function (validBidRequests, bidderRequest) { return validBidRequests.map(bidRequest => { - const { adUnitCode, auctionId, mediaTypes, params, sizes, transactionId } = bidRequest; - const baseEndpoint = params[ 'rtbEndpoint' ] || 'https://rtb.gambid.io'; + const {adUnitCode, auctionId, mediaTypes, params, sizes, transactionId} = bidRequest; + const baseEndpoint = params['rtbEndpoint'] || 'https://rtb.gamoshi.io'; const rtbEndpoint = `${baseEndpoint}/r/${params.supplyPartnerId}/bidr?rformat=open_rtb&reqformat=rtb_json&bidder=prebid` + (params.query ? '&' + params.query : ''); + let referer = bidderRequest && bidderRequest.refererInfo && bidderRequest.refererInfo.referer; + let url = config.getConfig('pageUrl') || referer || utils.getTopWindowUrl(); + const rtbBidRequest = { 'id': auctionId, 'site': { - 'domain': getTopWindowDomain(), - 'page': config.getConfig('pageUrl') || utils.getTopWindowUrl(), - 'ref': getTopWindowReferer() + 'domain': helper.getTopWindowDomain(url), + 'page': url, + 'ref': helper.getTopWindowReferer() }, 'device': { 'ua': navigator.userAgent @@ -80,33 +85,33 @@ export const spec = { 'tagid': adUnitCode, 'bidfloor': params.bidfloor || 0, 'bidfloorcur': 'USD', - 'secure': startsWith(utils.getTopWindowUrl().toLowerCase(), 'http://') ? 0 : 1 + 'secure': helper.startsWith(utils.getTopWindowUrl().toLowerCase(), 'http://') ? 0 : 1 }; if (!mediaTypes || mediaTypes.banner) { imp.banner = { - w: sizes.length ? sizes[ 0 ][ 0 ] : 300, - h: sizes.length ? sizes[ 0 ][ 1 ] : 250, + w: sizes.length ? sizes[0][0] : 300, + h: sizes.length ? sizes[0][1] : 250, pos: params.pos || 0, - topframe: getTopFrame() + topframe: helper.getTopFrame() }; } else if (mediaTypes.video) { imp.video = { - w: sizes.length ? sizes[ 0 ][ 0 ] : 300, - h: sizes.length ? sizes[ 0 ][ 1 ] : 250, + w: sizes.length ? sizes[0][0] : 300, + h: sizes.length ? sizes[0][1] : 250, protocols: params.protocols || [1, 2, 3, 4, 5, 6], pos: params.pos || 0, - topframe: getTopFrame() + topframe: helper.getTopFrame() }; } else { return; } rtbBidRequest.imp.push(imp); - return { method: 'POST', url: rtbEndpoint, data: rtbBidRequest, bidRequest }; + return {method: 'POST', url: rtbEndpoint, data: rtbBidRequest, bidRequest}; }); }, - interpretResponse: function(serverResponse, bidRequest) { + interpretResponse: function (serverResponse, bidRequest) { const response = serverResponse && serverResponse.body; if (!response) { utils.logError('empty response'); @@ -127,7 +132,7 @@ export const spec = { currency: bid.cur || response.cur }; if (!bidRequest.bidRequest.mediaTypes || bidRequest.bidRequest.mediaTypes.banner) { - outBids.push(Object.assign({}, outBid, { mediaType: 'banner', ad: bid.adm })); + outBids.push(Object.assign({}, outBid, {mediaType: 'banner', ad: bid.adm})); } else if (bidRequest.bidRequest.mediaTypes.video) { const context = utils.deepAccess(bidRequest.bidRequest, 'mediaTypes.video.context'); outBids.push(Object.assign({}, outBid, { @@ -141,27 +146,27 @@ export const spec = { return outBids; }, - getUserSyncs: function(syncOptions, serverResponses, gdprConsent) { + getUserSyncs: function (syncOptions, serverResponses, gdprConsent) { const syncs = []; const gdprApplies = gdprConsent && (typeof gdprConsent.gdprApplies === 'boolean') ? gdprConsent.gdprApplies : false; const suffix = gdprApplies ? 'gc=' + encodeURIComponent(gdprConsent.consentString) : 'gc=missing'; serverResponses.forEach(resp => { if (resp.body) { const bidResponse = resp.body; - if (bidResponse.ext && Array.isArray(bidResponse.ext[ 'utrk' ])) { - bidResponse.ext[ 'utrk' ].forEach(pixel => { + if (bidResponse.ext && Array.isArray(bidResponse.ext['utrk'])) { + bidResponse.ext['utrk'].forEach(pixel => { const url = pixel.url + (pixel.url.indexOf('?') > 0 ? '&' + suffix : '?' + suffix); - return syncs.push({ type: pixel.type, url }); + return syncs.push({type: pixel.type, url}); }); } if (Array.isArray(bidResponse.seatbid)) { bidResponse.seatbid.forEach(seatBid => { if (Array.isArray(seatBid.bid)) { seatBid.bid.forEach(bid => { - if (bid.ext && Array.isArray(bid.ext[ 'utrk' ])) { - bid.ext[ 'utrk' ].forEach(pixel => { + if (bid.ext && Array.isArray(bid.ext['utrk'])) { + bid.ext['utrk'].forEach(pixel => { const url = pixel.url + (pixel.url.indexOf('?') > 0 ? '&' + suffix : '?' + suffix); - return syncs.push({ type: pixel.type, url }); + return syncs.push({type: pixel.type, url}); }); } }); diff --git a/modules/gambidBidAdapter.md b/modules/gamoshiBidAdapter.md similarity index 78% rename from modules/gambidBidAdapter.md rename to modules/gamoshiBidAdapter.md index b34d05070a9..f88248ef668 100644 --- a/modules/gambidBidAdapter.md +++ b/modules/gamoshiBidAdapter.md @@ -1,16 +1,16 @@ # Overview ``` -Module Name: Gamoshi's Gambid Bid Adapter +Module Name: Gamoshi Bid Adapter Module Type: Bidder Adapter -Maintainer: arik@gamoshi.com +Maintainer: moses@gamoshi.com ``` # Description -Connects to Gamoshi's Gambid platform & exchange for bids. +Connects to Gamoshi's Programmatic advertising platform as a service. -Gambid bid adapter supports Banner & Outstream Video. The *only* required parameter (in the `params` section) is the `supplyPartnerId` parameter. +Gamoshi bid adapter supports Banner & Outstream Video. The *only* required parameter (in the `params` section) is the `supplyPartnerId` parameter. # Test Parameters ``` @@ -21,10 +21,10 @@ var adUnits = [ code: 'banner-div', sizes: [[300, 250]], bids: [{ - bidder: 'gambid', + bidder: 'gamoshi', params: { - // ID of the supply partner you created in the Gambid dashboard + // ID of the supply partner you created in the Gamoshi dashboard supplyPartnerId: '1253', // OPTIONAL: if you have a whitelabel account on Gamoshi, specify it here @@ -55,10 +55,10 @@ var adUnits = [ } }, bids: [ { - bidder: 'gambid', + bidder: 'gamoshi', params: { - // ID of the supply partner you created in the Gambid dashboard + // ID of the supply partner you created in the dashboard supplyPartnerId: '1254', // OPTIONAL: if you have a whitelabel account on Gamoshi, specify it here diff --git a/modules/getintentBidAdapter.js b/modules/getintentBidAdapter.js index 2ac66731153..bc2ed093665 100644 --- a/modules/getintentBidAdapter.js +++ b/modules/getintentBidAdapter.js @@ -1,5 +1,5 @@ -import { registerBidder } from 'src/adapters/bidderFactory'; -import { isInteger } from 'src/utils'; +import { registerBidder } from '../src/adapters/bidderFactory'; +import { isInteger } from '../src/utils'; const BIDDER_CODE = 'getintent'; const IS_NET_REVENUE = true; diff --git a/modules/giantsBidAdapter.js b/modules/giantsBidAdapter.js index 6844cb684bc..e2693392578 100644 --- a/modules/giantsBidAdapter.js +++ b/modules/giantsBidAdapter.js @@ -1,343 +1,343 @@ -import * as utils from 'src/utils'; -import { registerBidder } from 'src/adapters/bidderFactory'; -import { BANNER, NATIVE, VIDEO } from 'src/mediaTypes'; -import includes from 'core-js/library/fn/array/includes'; - -const BIDDER_CODE = 'giants'; -const URL = '//d.admp.io/hb'; -const VIDEO_TARGETING = ['id', 'mimes', 'minduration', 'maxduration', - 'startdelay', 'skippable', 'playback_method', 'frameworks']; -const NATIVE_MAPPING = { - body: 'description', - cta: 'ctatext', - image: { - serverName: 'main_image', - requiredParams: { required: true }, - minimumParams: { sizes: [{}] }, - }, - icon: { - serverName: 'icon', - requiredParams: { required: true }, - minimumParams: { sizes: [{}] }, - }, - sponsoredBy: 'sponsored_by', -}; -const SOURCE = 'pbjs'; - -export const spec = { - code: BIDDER_CODE, - aliases: [], - supportedMediaTypes: [BANNER, VIDEO, NATIVE], - - /** - * Determines whether or not the given bid request is valid. - * - * @param {object} bid The bid to validate. - * @return boolean True if this is a valid bid, and false otherwise. - */ - isBidRequestValid: function(bid) { - return !!(bid.params.zoneId); - }, - - /** - * Make a server request from the list of BidRequests. - * - * @param {BidRequest[]} bidRequests A non-empty list of bid requests which should be sent to the Server. - * @return ServerRequest Info describing the request to the server. - */ - buildRequests: function(bidRequests, bidderRequest) { - const tags = bidRequests.map(bidToTag); - // const zoneIds = bidRequests.map(bidToZoneId); - // var firstBid = bidRequests[0]; - var ref = utils.getTopWindowUrl(); - const url = URL + '/multi?url=' + ref; - // + '&callback=window.$$PREBID_GLOBAL$$.giantsResponse&callback_uid=' + bid.bidId; - - const payload = { - tags: [...tags], - // user: userObj, - sdk: { - source: SOURCE, - version: '$prebid.version$' - } - }; - // if (member > 0) { - // payload.member_id = member; - // } - - if (bidderRequest && bidderRequest.gdprConsent) { - // note - objects for impbus use underscore instead of camelCase - payload.gdpr_consent = { - consent_string: bidderRequest.gdprConsent.consentString, - consent_required: bidderRequest.gdprConsent.gdprApplies - }; - } - - const payloadString = JSON.stringify(payload); - - return { - method: 'POST', - // url: URL, - url: url, - data: payloadString, - bidderRequest - }; - }, - - /** - * Unpack the response from the server into a list of bids. - * - * @param {*} serverResponse A successful response from the server. - * @return {Bid[]} An array of bids which were nested inside the server. - */ - interpretResponse: function(serverResponse, {bidderRequest}) { - serverResponse = serverResponse.body; - const bids = []; - if (!serverResponse || serverResponse.error) { - let errorMessage = `in response for ${bidderRequest.bidderCode} adapter`; - if (serverResponse && serverResponse.error) { errorMessage += `: ${serverResponse.error}`; } - utils.logError(errorMessage); - return bids; - } - if (serverResponse.tags) { - serverResponse.tags.forEach(serverBid => { - if (serverBid.cpm && serverBid.cpm !== 0) { - const bid = newBid(serverBid, bidderRequest); - bid.mediaType = BANNER; - bids.push(bid); - } - }); - } - return bids; - }, - - getUserSyncs: function(syncOptions) { - if (syncOptions.iframeEnabled) { - return [{ - type: 'iframe', - url: '//d.admp.io/ping' - }]; - } - } -} - -/* Turn keywords parameter into ut-compatible format */ -function getKeywords(keywords) { - let arrs = []; - - utils._each(keywords, (v, k) => { - if (utils.isArray(v)) { - let values = []; - utils._each(v, (val) => { - val = utils.getValueString('keywords.' + k, val); - if (val) { values.push(val); } - }); - v = values; - } else { - v = utils.getValueString('keywords.' + k, v); - if (utils.isStr(v)) { - v = [v]; - } else { - return; - } // unsuported types - don't send a key - } - arrs.push({key: k, value: v}); - }); - - return arrs; -} - -/** - * Unpack the Server's Bid into a Prebid-compatible one. - * @param serverBid - * @param rtbBid - * @param bidderRequest - * @return Bid - */ -function newBid(serverBid, bidderRequest) { - const bid = { - requestId: serverBid.uuid, - cpm: serverBid.cpm, - creativeId: serverBid.creative_id, - // dealId: rtbBid.deal_id, - currency: 'USD', - netRevenue: true, - ttl: 300 - }; - - Object.assign(bid, { - width: serverBid.width, - height: serverBid.height, - // ad: serverBid.ad - ad: _renderCreative(serverBid.adUrl, serverBid.width, serverBid.height) - }); - // try { - // const url = rtbBid.rtb.trackers[0].impression_urls[0]; - // const tracker = utils.createTrackPixelHtml(url); - // bid.ad += tracker; - // } catch (error) { - // utils.logError('Error appending tracking pixel', error); - // } - - return bid; -} - -function bidToTag(bid) { - const tag = {}; - tag.sizes = transformSizes(bid.sizes); - tag.primary_size = tag.sizes[0]; - tag.ad_types = []; - tag.uuid = bid.bidId; - if (bid.params.zoneId) { - tag.id = bid.params.zoneId; - } else { - tag.code = bid.params.invCode; - } - tag.allow_smaller_sizes = bid.params.allowSmallerSizes || false; - tag.use_pmt_rule = bid.params.usePaymentRule || false - tag.prebid = true; - tag.disable_psa = true; - if (bid.params.reserve) { - tag.reserve = bid.params.reserve; - } - if (bid.params.position) { - tag.position = {'above': 1, 'below': 2}[bid.params.position] || 0; - } - if (bid.params.trafficSourceCode) { - tag.traffic_source_code = bid.params.trafficSourceCode; - } - if (bid.params.privateSizes) { - tag.private_sizes = transformSizes(bid.params.privateSizes); - } - if (bid.params.supplyType) { - tag.supply_type = bid.params.supplyType; - } - if (bid.params.pubClick) { - tag.pubclick = bid.params.pubClick; - } - if (bid.params.extInvCode) { - tag.ext_inv_code = bid.params.extInvCode; - } - if (bid.params.externalImpId) { - tag.external_imp_id = bid.params.externalImpId; - } - if (!utils.isEmpty(bid.params.keywords)) { - tag.keywords = getKeywords(bid.params.keywords); - } - - if (bid.mediaType === NATIVE || utils.deepAccess(bid, `mediaTypes.${NATIVE}`)) { - tag.ad_types.push(NATIVE); - - if (bid.nativeParams) { - const nativeRequest = buildNativeRequest(bid.nativeParams); - tag[NATIVE] = {layouts: [nativeRequest]}; - } - } - - const videoMediaType = utils.deepAccess(bid, `mediaTypes.${VIDEO}`); - const context = utils.deepAccess(bid, 'mediaTypes.video.context'); - - if (bid.mediaType === VIDEO || videoMediaType) { - tag.ad_types.push(VIDEO); - } - - // instream gets vastUrl, outstream gets vastXml - if (bid.mediaType === VIDEO || (videoMediaType && context !== 'outstream')) { - tag.require_asset_url = true; - } - - if (bid.params.video) { - tag.video = {}; - // place any valid video params on the tag - Object.keys(bid.params.video) - .filter(param => includes(VIDEO_TARGETING, param)) - .forEach(param => tag.video[param] = bid.params.video[param]); - } - - if ( - (utils.isEmpty(bid.mediaType) && utils.isEmpty(bid.mediaTypes)) || - (bid.mediaType === BANNER || (bid.mediaTypes && bid.mediaTypes[BANNER])) - ) { - tag.ad_types.push(BANNER); - } - - return tag; -} - -// function bidToZoneId(bid) { -// return bid.params.zoneId; -// } - -/* Turn bid request sizes into ut-compatible format */ -function transformSizes(requestSizes) { - let sizes = []; - let sizeObj = {}; - - if (utils.isArray(requestSizes) && requestSizes.length === 2 && - !utils.isArray(requestSizes[0])) { - sizeObj.width = parseInt(requestSizes[0], 10); - sizeObj.height = parseInt(requestSizes[1], 10); - sizes.push(sizeObj); - } else if (typeof requestSizes === 'object') { - for (let i = 0; i < requestSizes.length; i++) { - let size = requestSizes[i]; - sizeObj = {}; - sizeObj.width = parseInt(size[0], 10); - sizeObj.height = parseInt(size[1], 10); - sizes.push(sizeObj); - } - } - - return sizes; -} - -function buildNativeRequest(params) { - const request = {}; - - // map standard prebid native asset identifier to /ut parameters - // e.g., tag specifies `body` but /ut only knows `description`. - // mapping may be in form {tag: ''} or - // {tag: {serverName: '', requiredParams: {...}}} - Object.keys(params).forEach(key => { - // check if one of the forms is used, otherwise - // a mapping wasn't specified so pass the key straight through - const requestKey = - (NATIVE_MAPPING[key] && NATIVE_MAPPING[key].serverName) || - NATIVE_MAPPING[key] || - key; - - // required params are always passed on request - const requiredParams = NATIVE_MAPPING[key] && NATIVE_MAPPING[key].requiredParams; - request[requestKey] = Object.assign({}, requiredParams, params[key]); - - // minimum params are passed if no non-required params given on adunit - const minimumParams = NATIVE_MAPPING[key] && NATIVE_MAPPING[key].minimumParams; - - if (requiredParams && minimumParams) { - // subtract required keys from adunit keys - const adunitKeys = Object.keys(params[key]); - const requiredKeys = Object.keys(requiredParams); - const remaining = adunitKeys.filter(key => !includes(requiredKeys, key)); - - // if none are left over, the minimum params needs to be sent - if (remaining.length === 0) { - request[requestKey] = Object.assign({}, request[requestKey], minimumParams); - } - } - }); - - return request; -} - -function _renderCreative(adUrl, width, height) { - return ` - - - - `; -}; +} /** * Returns iframe document in a browser agnostic way - * @param {object} iframe reference - * @return {object} iframe `document` reference + * @param {Object} iframe reference + * @return {Object} iframe `document` reference */ -exports.getIframeDocument = function (iframe) { +export function getIframeDocument(iframe) { if (!iframe) { return; } @@ -670,24 +722,24 @@ exports.getIframeDocument = function (iframe) { doc = iframe.contentDocument; } } catch (e) { - exports.logError('Cannot get iframe document', e); + internal.logError('Cannot get iframe document', e); } return doc; -}; +} -exports.getValueString = function(param, val, defaultValue) { +export function getValueString(param, val, defaultValue) { if (val === undefined || val === null) { return defaultValue; } - if (exports.isStr(val)) { + if (isStr(val)) { return val; } - if (exports.isNumber(val)) { + if (isNumber(val)) { return val.toString(); } - exports.logWarn('Unsuported type for param: ' + param + ' required type: String'); -}; + internal.logWarn('Unsuported type for param: ' + param + ' required type: String'); +} export function uniques(value, index, arry) { return arry.indexOf(value) === index; @@ -724,7 +776,7 @@ export function getBidderCodes(adUnits = $$PREBID_GLOBAL$$.adUnits) { } export function isGptPubadsDefined() { - if (window.googletag && exports.isFn(window.googletag.pubads) && exports.isFn(window.googletag.pubads().getSlots)) { + if (window.googletag && isFn(window.googletag.pubads) && isFn(window.googletag.pubads().getSlots)) { return true; } } @@ -795,7 +847,7 @@ export function deepClone(obj) { export function inIframe() { try { - return exports.getWindowSelf() !== exports.getWindowTop(); + return internal.getWindowSelf() !== internal.getWindowTop(); } catch (e) { return true; } @@ -820,13 +872,18 @@ export function checkCookieSupport() { } } export function cookiesAreEnabled() { - if (exports.checkCookieSupport()) { + if (internal.checkCookieSupport()) { return true; } window.document.cookie = 'prebid.cookieTest'; return window.document.cookie.indexOf('prebid.cookieTest') != -1; } +export function getCookie(name) { + let m = window.document.cookie.match('(^|;)\\s*' + name + '\\s*=\\s*([^;]*)\\s*(;|$)'); + return m ? decodeURIComponent(m[2]) : null; +} + /** * Given a function, return a function which only executes the original after * it's been called numRequiredCalls times. @@ -857,7 +914,7 @@ export function delayExecution(func, numRequiredCalls) { * @export * @param {array} xs * @param {string} key - * @returns {${key_value}: ${groupByArray}, key_value: {groupByArray}} + * @returns {Object} {${key_value}: ${groupByArray}, key_value: {groupByArray}} */ export function groupBy(xs, key) { return xs.reduce(function(rv, x) { @@ -868,7 +925,7 @@ export function groupBy(xs, key) { /** * deepAccess utility function useful for doing safe access (will not throw exceptions) of deep object paths. - * @param {object} obj The object containing the values you would like to access. + * @param {Object} obj The object containing the values you would like to access. * @param {string|number} path Object path to the value you would like to access. Non-strings are coerced to strings. * @returns {*} The value found at the specified object path, or undefined if path is not found. */ @@ -888,7 +945,7 @@ export function deepAccess(obj, path) { /** * Returns content for a friendly iframe to execute a URL in script tag - * @param {url} URL to be executed in a script tag in a friendly iframe + * @param {string} url URL to be executed in a script tag in a friendly iframe * and are macros left to be replaced if required */ export function createContentToExecuteExtScriptInFriendlyFrame(url) { @@ -902,9 +959,9 @@ export function createContentToExecuteExtScriptInFriendlyFrame(url) { /** * Build an object consisting of only defined parameters to avoid creating an * object with defined keys and undefined values. - * @param {object} object The object to pick defined params out of + * @param {Object} object The object to pick defined params out of * @param {string[]} params An array of strings representing properties to look for in the object - * @returns {object} An object containing all the specified values that are defined + * @returns {Object} An object containing all the specified values that are defined */ export function getDefinedParams(object, params) { return params @@ -949,8 +1006,8 @@ export function getBidderRequest(bidRequests, bidder, adUnitCode) { } /** * Returns user configured bidder params from adunit - * @param {object} adunits - * @param {string} adunit code + * @param {Object} adUnits + * @param {string} adUnitCode code * @param {string} bidder code * @return {Array} user configured param for the given bidder adunit configuration */ @@ -985,7 +1042,7 @@ const compareCodeAndSlot = (slot, adUnitCode) => slot.getAdUnitPath() === adUnit /** * Returns filter function to match adUnitCode in slot - * @param {object} slot GoogleTag slot + * @param {Object} slot GoogleTag slot * @return {function} filter function */ export function isAdUnitCodeMatchingSlot(slot) { @@ -1024,9 +1081,9 @@ export function unsupportedBidderMessage(adUnit, bidder) { * @return {Object} object */ export function deletePropertyFromObject(object, prop) { - let result = Object.assign({}, object) + let result = Object.assign({}, object); delete result[prop]; - return result + return result; } /** @@ -1035,7 +1092,7 @@ export function deletePropertyFromObject(object, prop) { * @return {Object} bid */ export function removeRequestId(bid) { - return exports.deletePropertyFromObject(bid, 'requestId'); + return deletePropertyFromObject(bid, 'requestId'); } /** @@ -1064,23 +1121,23 @@ export function convertCamelToUnderscore(value) { * normally read from bidder params * eg { foo: ['bar', 'baz'], fizz: ['buzz'] } * becomes [{ key: 'foo', value: ['bar', 'baz']}, {key: 'fizz', value: ['buzz']}] - * @param {Object{Arrays}} keywords object of arrays representing keyvalue pairs + * @param {Object} keywords object of arrays representing keyvalue pairs * @param {string} paramName name of parent object (eg 'keywords') containing keyword data, used in error handling */ export function transformBidderParamKeywords(keywords, paramName = 'keywords') { let arrs = []; - exports._each(keywords, (v, k) => { - if (exports.isArray(v)) { + _each(keywords, (v, k) => { + if (isArray(v)) { let values = []; - exports._each(v, (val) => { - val = exports.getValueString(paramName + '.' + k, val); - if (val) { values.push(val); } + _each(v, (val) => { + val = getValueString(paramName + '.' + k, val); + if (val || val === '') { values.push(val); } }); v = values; } else { - v = exports.getValueString(paramName + '.' + k, v); - if (exports.isStr(v)) { + v = getValueString(paramName + '.' + k, v); + if (isStr(v)) { v = [v]; } else { return; @@ -1112,7 +1169,7 @@ function tryConvertType(typeToConvert, value) { export function convertTypes(types, params) { Object.keys(types).forEach(key => { if (params[key]) { - if (exports.isFn(types[key])) { + if (isFn(types[key])) { params[key] = types[key](params[key]); } else { params[key] = tryConvertType(types[key], params[key]); diff --git a/src/video.js b/src/video.js index 8e0775a6d62..2c1d0ec1569 100644 --- a/src/video.js +++ b/src/video.js @@ -1,10 +1,10 @@ -import { videoAdapters } from './adaptermanager'; +import adapterManager from './adapterManager'; import { getBidRequest, deepAccess, logError } from './utils'; import { config } from '../src/config'; import includes from 'core-js/library/fn/array/includes'; const VIDEO_MEDIA_TYPE = 'video'; -const OUTSTREAM = 'outstream'; +export const OUTSTREAM = 'outstream'; /** * Helper functions for working with video-enabled adUnits @@ -14,7 +14,7 @@ export const videoAdUnit = adUnit => { const mediaTypes = deepAccess(adUnit, 'mediaTypes.video'); return mediaType || mediaTypes; }; -export const videoBidder = bid => includes(videoAdapters, bid.bidder); +export const videoBidder = bid => includes(adapterManager.videoAdapters, bid.bidder); export const hasNonVideoBidder = adUnit => adUnit.bids.filter(bid => !videoBidder(bid)).length; diff --git a/src/videoCache.js b/src/videoCache.js index cec2a3ec864..bc70397fc94 100644 --- a/src/videoCache.js +++ b/src/videoCache.js @@ -62,7 +62,8 @@ function toStorageRequest(bid) { const vastValue = bid.vastXml ? bid.vastXml : wrapURI(bid.vastUrl, bid.vastImpUrl); return { type: 'xml', - value: vastValue + value: vastValue, + ttlseconds: Number(bid.ttl) }; } diff --git a/test/fixtures/allAdapters.js b/test/fixtures/allAdapters.js deleted file mode 100644 index e2baa12cd10..00000000000 --- a/test/fixtures/allAdapters.js +++ /dev/null @@ -1,3 +0,0 @@ -exports.getAllAdaptersString = function () { - return `var AardvarkAdapter = require(\'./adapters/aardvark.js\');\n exports.registerBidAdapter(new AardvarkAdapter(), \'aardvark\');\nvar AdbladeAdapter = require(\'./adapters/adblade.js\');\n exports.registerBidAdapter(new AdbladeAdapter(), \'adblade\');\nvar AdbutlerAdapter = require(\'./adapters/adbutler.js\');\n exports.registerBidAdapter(new AdbutlerAdapter(), \'adbutler\');\nvar AdequantAdapter = require(\'./adapters/adequant.js\');\n exports.registerBidAdapter(new AdequantAdapter(), \'adequant\');\nvar AdformAdapter = require(\'./adapters/adform.js\');\n exports.registerBidAdapter(new AdformAdapter(), \'adform\');\nvar AdmediaAdapter = require(\'./adapters/admedia.js\');\n exports.registerBidAdapter(new AdmediaAdapter(), \'admedia\');\nvar AolAdapter = require(\'./adapters/aol.js\');\n exports.registerBidAdapter(new AolAdapter(), \'aol\');\nvar AppnexusAdapter = require(\'./adapters/appnexus.js\');\n exports.registerBidAdapter(new AppnexusAdapter(), \'appnexus\');\nvar AppnexusAstAdapter = require(\'./adapters/appnexusAst.js\');\n exports.registerBidAdapter(new AppnexusAstAdapter(), \'appnexusAst\');\nvar GetintentAdapter = require(\'./adapters/getintent.js\');\n exports.registerBidAdapter(new GetintentAdapter(), \'getintent\');\nvar HiromediaAdapter = require(\'./adapters/hiromedia.js\');\n exports.registerBidAdapter(new HiromediaAdapter(), \'hiromedia\');\nvar IndexExchangeAdapter = require(\'./adapters/indexExchange.js\');\n exports.registerBidAdapter(new IndexExchangeAdapter(), \'indexExchange\');\nvar KruxlinkAdapter = require(\'./adapters/kruxlink.js\');\n exports.registerBidAdapter(new KruxlinkAdapter(), \'kruxlink\');\nvar KomoonaAdapter = require(\'./adapters/komoona.js\');\n exports.registerBidAdapter(new KomoonaAdapter(), \'komoona\');\nvar OpenxAdapter = require(\'./adapters/openx.js\');\n exports.registerBidAdapter(new OpenxAdapter(), \'openx\');\nvar PiximediaAdapter = require(\'./adapters/piximedia.js\');\n exports.registerBidAdapter(new PiximediaAdapter(), \'piximedia\');\nvar PubmaticAdapter = require(\'./adapters/pubmatic.js\');\n exports.registerBidAdapter(new PubmaticAdapter(), \'pubmatic\');\nvar PulsepointAdapter = require(\'./adapters/pulsepoint.js\');\n exports.registerBidAdapter(new PulsepointAdapter(), \'pulsepoint\');\nvar RubiconAdapter = require(\'./adapters/rubicon.js\');\n exports.registerBidAdapter(new RubiconAdapter(), \'rubicon\');\nvar SonobiAdapter = require(\'./adapters/sonobi.js\');\n exports.registerBidAdapter(new SonobiAdapter(), \'sonobi\');\nvar SovrnAdapter = require(\'./adapters/sovrn.js\');\n exports.registerBidAdapter(new SovrnAdapter(), \'sovrn\');\nvar SpringserveAdapter = require(\'./adapters/springserve.js\');\n exports.registerBidAdapter(new SpringserveAdapter(), \'springserve\');\nvar ThoughtleadrAdapter = require('./adapters/thoughtleadr.js');\n exports.registerBidAdapter(new ThoughtleadrAdapter(), 'thoughtleadr');\nvar TripleliftAdapter = require(\'./adapters/triplelift.js\');\n exports.registerBidAdapter(new TripleliftAdapter(), \'triplelift\');\nvar TwengaAdapter = require(\'./adapters/twenga.js\');\n exports.registerBidAdapter(new TwengaAdapter(), \'twenga\');\nvar YieldbotAdapter = require(\'./adapters/yieldbot.js\');\n exports.registerBidAdapter(new YieldbotAdapter(), \'yieldbot\');\nvar NginadAdapter = require(\'./adapters/nginad.js\');\n exports.registerBidAdapter(new NginadAdapter(), \'nginad\');\nvar BrightcomAdapter = require(\'./adapters/brightcom.js\');\n exports.registerBidAdapter(new BrightcomAdapter(), \'brightcom\');\nvar WideorbitAdapter = require(\'./adapters/wideorbit.js\');\n exports.registerBidAdapter(new WideorbitAdapter(), \'wideorbit\');\nvar JcmAdapter = require(\'./adapters/jcm.js\');\n exports.registerBidAdapter(new JcmAdapter(), \'jcm\');\nvar UnderdogmediaAdapter = require(\'./adapters/underdogmedia.js\');\n exports.registerBidAdapter(new UnderdogmediaAdapter(), \'underdogmedia\');\nvar MemeglobalAdapter = require(\'./adapters/memeglobal.js\');\n exports.registerBidAdapter(new MemeglobalAdapter(), \'memeglobal\');\nvar CentroAdapter = require(\'./adapters/centro.js\');\n exports.registerBidAdapter(new CentroAdapter(), \'centro\');\nvar RoxotAdapter = require(\'./adapters/roxot.js\');\n exports.registerBidAdapter(new RoxotAdapter(), \'roxot\');\nexports.aliasBidAdapter(\'appnexus\',\'brealtime\');\nexports.aliasBidAdapter(\'appnexus\',\'pagescience\');\nexports.aliasBidAdapter(\'appnexus\',\'defymedia\');\nexports.videoAdapters = ["appnexusAst"];`; -}; diff --git a/test/fixtures/fixtures.js b/test/fixtures/fixtures.js index fc59d7eeab3..816363f5eea 100644 --- a/test/fixtures/fixtures.js +++ b/test/fixtures/fixtures.js @@ -1,4 +1,33 @@ // jscs:disable +import CONSTANTS from 'src/constants.json'; +const utils = require('src/utils.js'); + +function convertTargetingsFromOldToNew(targetings) { + var mapOfOldToNew = { + 'hb_bidder': CONSTANTS.TARGETING_KEYS.BIDDER, + 'hb_adid': CONSTANTS.TARGETING_KEYS.AD_ID, + 'hb_pb': CONSTANTS.TARGETING_KEYS.PRICE_BUCKET, + 'hb_size': CONSTANTS.TARGETING_KEYS.SIZE, + 'hb_deal': CONSTANTS.TARGETING_KEYS.DEAL, + 'hb_source': CONSTANTS.TARGETING_KEYS.SOURCE, + 'hb_format': CONSTANTS.TARGETING_KEYS.FORMAT + }; + var newTargetings = {}; + utils._each(targetings, function(value, currentKey) { + var replaced = false; + utils._each(mapOfOldToNew, function(newKey, oldKey) { + if (currentKey.indexOf(oldKey) === 0 && oldKey !== newKey) { + var updatedKey = currentKey.replace(oldKey, newKey); + newTargetings[updatedKey] = targetings[currentKey]; + replaced = true; + } + }); + if (!replaced) { + newTargetings[currentKey] = targetings[currentKey]; + } + }) + return newTargetings; +} export function getBidRequests() { return [ @@ -13,7 +42,7 @@ export function getBidRequests() { 'placementId': '4799418', 'test': 'me' }, - 'placementCode': '/19968336/header-bid-tag1', + 'adUnitCode': '/19968336/header-bid-tag1', 'sizes': [ [ 728, @@ -36,7 +65,7 @@ export function getBidRequests() { 'params': { 'placementId': '4799418' }, - 'placementCode': '/19968336/header-bid-tag-0', + 'adUnitCode': '/19968336/header-bid-tag-0', 'sizes': [ [ 300, @@ -68,7 +97,7 @@ export function getBidRequests() { 'publisherId': 39741, 'adSlot': '39620189@300x250' }, - 'placementCode': '/19968336/header-bid-tag-0', + 'adUnitCode': '/19968336/header-bid-tag-0', 'sizes': [ [ 300, @@ -117,7 +146,7 @@ export function getBidRequests() { 10 ], }, - 'placementCode': '/19968336/header-bid-tag-0', + 'adUnitCode': '/19968336/header-bid-tag-0', 'sizes': [ [ 300, @@ -146,7 +175,7 @@ export function getBidRequests() { 'params': { 'inventoryCode': 'sortable_all_right_sports' }, - 'placementCode': '/19968336/header-bid-tag-0', + 'adUnitCode': '/19968336/header-bid-tag-0', 'sizes': [ [ 300, @@ -176,7 +205,7 @@ export function getBidRequests() { 'params': { 'tagId': 16577 }, - 'placementCode': '/19968336/header-bid-tag-0', + 'adUnitCode': '/19968336/header-bid-tag-0', 'sizes': [ [ 300, @@ -206,7 +235,7 @@ export function getBidRequests() { 'params': { 'placementId': '4799418' }, - 'placementCode': '/19968336/header-bid-tag-0', + 'adUnitCode': '/19968336/header-bid-tag-0', 'sizes': [ [ 300, @@ -237,7 +266,7 @@ export function getBidRequests() { 'params': { 'placementId': '4799418' }, - 'placementCode': '/19968336/header-bid-tag-0', + 'adUnitCode': '/19968336/header-bid-tag-0', 'sizes': [ [ 300, @@ -268,7 +297,7 @@ export function getBidRequests() { 'params': { 'aId': 3080 }, - 'placementCode': '/19968336/header-bid-tag-0', + 'adUnitCode': '/19968336/header-bid-tag-0', 'sizes': [ [ 300, @@ -311,13 +340,13 @@ export function getBidResponses() { 'pbAg': '0.10', 'size': '0x0', 'auctionId': 123456, - 'adserverTargeting': { + 'adserverTargeting': convertTargetingsFromOldToNew({ 'hb_bidder': 'triplelift', 'hb_adid': '222bb26f9e8bd', 'hb_pb': '10.00', 'hb_size': '0x0', 'foobar': '0x0' - }, + }), 'netRevenue': true, 'currency': 'USD', 'ttl': 300 @@ -343,13 +372,13 @@ export function getBidResponses() { 'size': '300x250', 'alwaysUseBid': true, 'auctionId': 123456, - 'adserverTargeting': { + 'adserverTargeting': convertTargetingsFromOldToNew({ 'hb_bidder': 'appnexus', 'hb_adid': '233bcbee889d46d', 'hb_pb': '10.00', 'hb_size': '300x250', 'foobar': '300x250' - }, + }), 'netRevenue': true, 'currency': 'USD', 'ttl': 300 @@ -375,13 +404,13 @@ export function getBidResponses() { 'size': '728x90', 'alwaysUseBid': true, 'auctionId': 123456, - 'adserverTargeting': { + 'adserverTargeting': convertTargetingsFromOldToNew({ 'hb_bidder': 'appnexus', 'hb_adid': '24bd938435ec3fc', 'hb_pb': '10.00', 'hb_size': '728x90', 'foobar': '728x90' - }, + }), 'netRevenue': true, 'currency': 'USD', 'ttl': 300 @@ -406,13 +435,13 @@ export function getBidResponses() { 'pbAg': '0.50', 'size': '300x250', 'auctionId': 123456, - 'adserverTargeting': { + 'adserverTargeting': convertTargetingsFromOldToNew({ 'hb_bidder': 'pagescience', 'hb_adid': '25bedd4813632d7', 'hb_pb': '10.00', 'hb_size': '300x250', 'foobar': '300x250' - }, + }), 'netRevenue': true, 'currency': 'USD', 'ttl': 300 @@ -436,13 +465,13 @@ export function getBidResponses() { 'pbAg': '0.15', 'size': '300x250', 'auctionId': 654321, - 'adserverTargeting': { + 'adserverTargeting': convertTargetingsFromOldToNew({ 'hb_bidder': 'brightcom', 'hb_adid': '26e0795ab963896', 'hb_pb': '10.00', 'hb_size': '300x250', 'foobar': '300x250' - }, + }), 'netRevenue': true, 'currency': 'USD', 'ttl': 300 @@ -467,13 +496,13 @@ export function getBidResponses() { 'pbAg': '0.50', 'size': '300x250', 'auctionId': 654321, - 'adserverTargeting': { + 'adserverTargeting': convertTargetingsFromOldToNew({ 'hb_bidder': 'brealtime', 'hb_adid': '275bd666f5a5a5d', 'hb_pb': '10.00', 'hb_size': '300x250', 'foobar': '300x250' - }, + }), 'netRevenue': true, 'currency': 'USD', 'ttl': 300 @@ -499,13 +528,13 @@ export function getBidResponses() { 'pbAg': '5.90', 'size': '300x250', 'auctionId': 654321, - 'adserverTargeting': { + 'adserverTargeting': convertTargetingsFromOldToNew({ 'hb_bidder': 'pubmatic', 'hb_adid': '28f4039c636b6a7', 'hb_pb': '10.00', 'hb_size': '300x250', 'foobar': '300x250' - }, + }), 'netRevenue': true, 'currency': 'USD', 'ttl': 300 @@ -529,13 +558,13 @@ export function getBidResponses() { 'pbAg': '2.70', 'size': '300x600', 'auctionId': 654321, - 'adserverTargeting': { + 'adserverTargeting': convertTargetingsFromOldToNew({ 'hb_bidder': 'rubicon', 'hb_adid': '29019e2ab586a5a', 'hb_pb': '10.00', 'hb_size': '300x600', 'foobar': '300x600' - }, + }), 'netRevenue': true, 'currency': 'USD', 'ttl': 300 @@ -546,26 +575,26 @@ export function getBidResponses() { export function getSlotTargeting() { return { '/19968336/header-bid-tag-0': [ - { + convertTargetingsFromOldToNew({ 'hb_bidder': [ 'appnexus' ] - }, - { + }), + convertTargetingsFromOldToNew({ 'hb_adid': [ '233bcbee889d46d' ] - }, - { + }), + convertTargetingsFromOldToNew({ 'hb_pb': [ '10.00' ] - }, - { + }), + convertTargetingsFromOldToNew({ 'hb_size': [ '300x250' ] - }, + }), { 'foobar': [ '300x250' @@ -596,7 +625,7 @@ export function getAdUnits() { 'publisher_id': '1234567', 'bidfloor': 0.01 }, - 'placementCode': '/19968336/header-bid-tag1', + 'adUnitCode': '/19968336/header-bid-tag1', 'sizes': [ [ 728, @@ -617,7 +646,7 @@ export function getAdUnits() { 'placementId': '543221', 'test': 'me' }, - 'placementCode': '/19968336/header-bid-tag1', + 'adUnitCode': '/19968336/header-bid-tag1', 'sizes': [ [ 728, @@ -654,7 +683,7 @@ export function getAdUnits() { 'params': { 'placementId': '5324321' }, - 'placementCode': '/19968336/header-bid-tag-0', + 'adUnitCode': '/19968336/header-bid-tag-0', 'sizes': [ [ 300, @@ -676,7 +705,7 @@ export function getAdUnits() { 'publisher_id': '12353433', 'bidfloor': 0.01 }, - 'placementCode': '/19968336/header-bid-tag-0', + 'adUnitCode': '/19968336/header-bid-tag-0', 'sizes': [ [ 300, @@ -696,7 +725,7 @@ export function getAdUnits() { 'params': { 'inventoryCode': 'inv_code_here' }, - 'placementCode': '/19968336/header-bid-tag-0', + 'adUnitCode': '/19968336/header-bid-tag-0', 'sizes': [ [ 300, @@ -719,7 +748,7 @@ export function getAdUnits() { 'supplyPartnerId': 1, 'test': true }, - 'placementCode': '/19968336/header-bid-tag-0', + 'adUnitCode': '/19968336/header-bid-tag-0', 'sizes': [ [ 300, @@ -759,7 +788,7 @@ export function getAdUnits() { 10 ] }, - 'placementCode': '/19968336/header-bid-tag-0', + 'adUnitCode': '/19968336/header-bid-tag-0', 'sizes': [ [ 300, @@ -780,7 +809,7 @@ export function getAdUnits() { 'jstag_url': 'http://servedbyopenx.com/w/1.0/jstag?nc=account_key', 'unit': 2345677 }, - 'placementCode': '/19968336/header-bid-tag-0', + 'adUnitCode': '/19968336/header-bid-tag-0', 'sizes': [ [ 300, @@ -801,7 +830,7 @@ export function getAdUnits() { 'publisherId': 1234567, 'adSlot': '1234567@300x250' }, - 'placementCode': '/19968336/header-bid-tag-0', + 'adUnitCode': '/19968336/header-bid-tag-0', 'sizes': [ [ 300, @@ -821,7 +850,7 @@ export function getAdUnits() { 'params': { 'placementId': '1234567' }, - 'placementCode': '/19968336/header-bid-tag-0', + 'adUnitCode': '/19968336/header-bid-tag-0', 'sizes': [ [ 300, @@ -842,7 +871,7 @@ export function getAdUnits() { 'params': { 'placementId': '1234567' }, - 'placementCode': '/19968336/header-bid-tag-0', + 'adUnitCode': '/19968336/header-bid-tag-0', 'sizes': [ [ 300, @@ -865,7 +894,7 @@ export function getAdUnits() { 'siteID': 123456, 'timeout': 10000 }, - 'placementCode': '/19968336/header-bid-tag-0', + 'adUnitCode': '/19968336/header-bid-tag-0', 'sizes': [ [ 300, @@ -887,7 +916,7 @@ export function getAdUnits() { 'mid': 123456, 'test': 1 }, - 'placementCode': '/19968336/header-bid-tag-0', + 'adUnitCode': '/19968336/header-bid-tag-0', 'sizes': [ [ 300, @@ -907,7 +936,7 @@ export function getAdUnits() { 'params': { 'aId': 3080 }, - 'placementCode': '/19968336/header-bid-tag-0', + 'adUnitCode': '/19968336/header-bid-tag-0', 'sizes': [ [ 300, @@ -928,7 +957,7 @@ export function getAdUnits() { 'network': '112345.45', 'placement': 12345 }, - 'placementCode': '/19968336/header-bid-tag-0', + 'adUnitCode': '/19968336/header-bid-tag-0', 'sizes': [ [ 300, @@ -948,7 +977,7 @@ export function getAdUnits() { 'params': { 'tagid': '123556' }, - 'placementCode': '/19968336/header-bid-tag-0', + 'adUnitCode': '/19968336/header-bid-tag-0', 'sizes': [ [ 300, @@ -970,7 +999,7 @@ export function getAdUnits() { 'cp': 1233456, 'ct': 12357 }, - 'placementCode': '/19968336/header-bid-tag-0', + 'adUnitCode': '/19968336/header-bid-tag-0', 'sizes': [ [ 300, @@ -990,7 +1019,7 @@ export function getAdUnits() { 'params': { 'tagId': 75423 }, - 'placementCode': '/19968336/header-bid-tag-0', + 'adUnitCode': '/19968336/header-bid-tag-0', 'sizes': [ [ 300, @@ -1033,13 +1062,13 @@ export function getBidResponsesFromAPI() { 'pbAg': '0.15', 'size': '300x250', 'auctionId': 654321, - 'adserverTargeting': { + 'adserverTargeting': convertTargetingsFromOldToNew({ 'hb_bidder': 'brightcom', 'hb_adid': '26e0795ab963896', 'hb_pb': '10.00', 'hb_size': '300x250', 'foobar': '300x250' - }, + }), 'netRevenue': true, 'currency': 'USD', 'ttl': 300 @@ -1064,13 +1093,13 @@ export function getBidResponsesFromAPI() { 'pbAg': '0.50', 'size': '300x250', 'auctionId': 654321, - 'adserverTargeting': { + 'adserverTargeting': convertTargetingsFromOldToNew({ 'hb_bidder': 'brealtime', 'hb_adid': '275bd666f5a5a5d', 'hb_pb': '10.00', 'hb_size': '300x250', 'foobar': '300x250' - }, + }), 'netRevenue': true, 'currency': 'USD', 'ttl': 300 @@ -1096,13 +1125,13 @@ export function getBidResponsesFromAPI() { 'pbAg': '5.90', 'size': '300x250', 'auctionId': 654321, - 'adserverTargeting': { + 'adserverTargeting': convertTargetingsFromOldToNew({ 'hb_bidder': 'pubmatic', 'hb_adid': '28f4039c636b6a7', 'hb_pb': '10.00', 'hb_size': '300x250', 'foobar': '300x250' - }, + }), 'netRevenue': true, 'currency': 'USD', 'ttl': 300 @@ -1126,13 +1155,13 @@ export function getBidResponsesFromAPI() { 'pbAg': '2.70', 'size': '300x600', 'auctionId': 654321, - 'adserverTargeting': { + 'adserverTargeting': convertTargetingsFromOldToNew({ 'hb_bidder': 'rubicon', 'hb_adid': '29019e2ab586a5a', 'hb_pb': '10.00', 'hb_size': '300x600', 'foobar': '300x600' - }, + }), 'netRevenue': true, 'currency': 'USD', 'ttl': 300 @@ -1145,7 +1174,7 @@ export function getBidResponsesFromAPI() { // Ad server targeting when `setConfig({ enableSendAllBids: true })` is set. export function getAdServerTargeting() { return { - '/19968336/header-bid-tag-0': { + '/19968336/header-bid-tag-0': convertTargetingsFromOldToNew({ 'foobar': '0x0,300x250,300x600', 'hb_size': '300x250', 'hb_pb': '10.00', @@ -1179,8 +1208,8 @@ export function getAdServerTargeting() { 'hb_pb_rubicon': '10.00', 'hb_adid_rubicon': '29019e2ab586a5a', 'hb_bidder_rubicon': 'rubicon' - }, - '/19968336/header-bid-tag1': { + }), + '/19968336/header-bid-tag1': convertTargetingsFromOldToNew({ 'foobar': '728x90', 'hb_size': '728x90', 'hb_pb': '10.00', @@ -1190,7 +1219,7 @@ export function getAdServerTargeting() { 'hb_pb_appnexus': '10.00', 'hb_adid_appnexus': '24bd938435ec3fc', 'hb_bidder_appnexus': 'appnexus' - } + }) }; } @@ -1198,19 +1227,19 @@ export function getAdServerTargeting() { export function getTargetingKeys() { return [ [ - 'hb_bidder', + CONSTANTS.TARGETING_KEYS.BIDDER, 'appnexus' ], [ - 'hb_adid', + CONSTANTS.TARGETING_KEYS.AD_ID, '233bcbee889d46d' ], [ - 'hb_pb', + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET, '10.00' ], [ - 'hb_size', + CONSTANTS.TARGETING_KEYS.SIZE, '300x250' ], [ @@ -1225,19 +1254,19 @@ export function getTargetingKeys() { export function getTargetingKeysBidLandscape() { return [ [ - 'hb_bidder', + CONSTANTS.TARGETING_KEYS.BIDDER, 'appnexus' ], [ - 'hb_adid_appnexus', + CONSTANTS.TARGETING_KEYS.AD_ID + '_appnexus', '233bcbee889d46d' ], [ - 'hb_pb', + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET, '10.00' ], [ - 'hb_size', + CONSTANTS.TARGETING_KEYS.SIZE, '300x250' ], [ @@ -1245,111 +1274,111 @@ export function getTargetingKeysBidLandscape() { ['0x0', '300x250', '300x600'] ], [ - 'hb_bidder_triplelift', + CONSTANTS.TARGETING_KEYS.BIDDER + '_triplelift', 'triplelift' ], [ - 'hb_adid_triplelift', + CONSTANTS.TARGETING_KEYS.AD_ID + '_triplelift', '222bb26f9e8bd' ], [ - 'hb_pb_triplelift', + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_triplelift', '10.00' ], [ - 'hb_size_triplelift', + CONSTANTS.TARGETING_KEYS.SIZE + '_triplelift', '0x0' ], [ - 'hb_bidder_appnexus', + CONSTANTS.TARGETING_KEYS.BIDDER + '_appnexus', 'appnexus' ], [ - 'hb_pb_appnexus', + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_appnexus', '10.00' ], [ - 'hb_size_appnexus', + CONSTANTS.TARGETING_KEYS.SIZE + '_appnexus', '300x250' ], [ - 'hb_bidder_pagescienc', + CONSTANTS.TARGETING_KEYS.BIDDER + '_pagescienc', 'pagescience' ], [ - 'hb_adid_pagescience', + CONSTANTS.TARGETING_KEYS.AD_ID + '_pagescience', '25bedd4813632d7' ], [ - 'hb_pb_pagescience', + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_pagescience', '10.00' ], [ - 'hb_size_pagescience', + CONSTANTS.TARGETING_KEYS.SIZE + '_pagescience', '300x250' ], [ - 'hb_bidder_brightcom', + CONSTANTS.TARGETING_KEYS.BIDDER + '_brightcom', 'brightcom' ], [ - 'hb_adid_brightcom', + CONSTANTS.TARGETING_KEYS.AD_ID + '_brightcom', '26e0795ab963896' ], [ - 'hb_pb_brightcom', + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_brightcom', '10.00' ], [ - 'hb_size_brightcom', + CONSTANTS.TARGETING_KEYS.SIZE + '_brightcom', '300x250' ], [ - 'hb_bidder_brealtime', + CONSTANTS.TARGETING_KEYS.BIDDER + '_brealtime', 'brealtime' ], [ - 'hb_adid_brealtime', + CONSTANTS.TARGETING_KEYS.AD_ID + '_brealtime', '275bd666f5a5a5d' ], [ - 'hb_pb_brealtime', + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_brealtime', '10.00' ], [ - 'hb_size_brealtime', + CONSTANTS.TARGETING_KEYS.SIZE + '_brealtime', '300x250' ], [ - 'hb_bidder_pubmatic', + CONSTANTS.TARGETING_KEYS.BIDDER + '_pubmatic', 'pubmatic' ], [ - 'hb_adid_pubmatic', + CONSTANTS.TARGETING_KEYS.AD_ID + '_pubmatic', '28f4039c636b6a7' ], [ - 'hb_pb_pubmatic', + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_pubmatic', '10.00' ], [ - 'hb_size_pubmatic', + CONSTANTS.TARGETING_KEYS.SIZE + '_pubmatic', '300x250' ], [ - 'hb_bidder_rubicon', + CONSTANTS.TARGETING_KEYS.BIDDER + '_rubicon', 'rubicon' ], [ - 'hb_adid_rubicon', + CONSTANTS.TARGETING_KEYS.AD_ID + '_rubicon', '29019e2ab586a5a' ], [ - 'hb_pb_rubicon', + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_rubicon', '10.00' ], [ - 'hb_size_rubicon', + CONSTANTS.TARGETING_KEYS.SIZE + '_rubicon', '300x600' ] ]; @@ -1367,7 +1396,7 @@ export function getBidRequestedPayload() { 'publisher_id': '5000563', 'bidfloor': 0.01 }, - 'placementCode': '/19968336/header-bid-tag-1', + 'adUnitCode': '/19968336/header-bid-tag-1', 'sizes': [ [ 300, @@ -1426,12 +1455,12 @@ export function createBidReceived({bidder, cpm, auctionId, responseTimestamp, ad 'adUnitCode': adUnitCode, 'bidder': bidder, 'size': '300x250', - 'adserverTargeting': { + 'adserverTargeting': convertTargetingsFromOldToNew({ 'hb_bidder': bidder, 'hb_adid': adId, 'hb_pb': cpm, 'foobar': '300x250' - }, + }), 'netRevenue': true, 'currency': 'USD', 'ttl': (!ttl) ? 300 : ttl diff --git a/test/mocks/adloaderStub.js b/test/mocks/adloaderStub.js new file mode 100644 index 00000000000..9b9e62a4c3b --- /dev/null +++ b/test/mocks/adloaderStub.js @@ -0,0 +1,23 @@ + +import * as adloader from 'src/adloader'; + +let sandbox; + +export let loadScript; +export let loadExternalScript; +export let loadScriptStub; +export let loadExternalScriptStub; + +beforeEach(function() { + sandbox = sinon.sandbox.create(); + loadScript = adloader.loadScript; + loadExternalScript = adloader.loadExternalScript; + loadScriptStub = sandbox.stub(adloader, 'loadScript').callsFake((...args) => { + args[1](); + }); + loadExternalScriptStub = sandbox.stub(adloader, 'loadExternalScript'); +}); + +afterEach(function() { + sandbox.restore(); +}); diff --git a/test/mocks/videoCacheStub.js b/test/mocks/videoCacheStub.js index 4a1d8bca343..39f5d67b6a9 100644 --- a/test/mocks/videoCacheStub.js +++ b/test/mocks/videoCacheStub.js @@ -12,7 +12,7 @@ import * as videoCache from 'src/videoCache'; export default function useVideoCacheStub(responses) { let storeStub; - beforeEach(() => { + beforeEach(function () { storeStub = sinon.stub(videoCache, 'store'); if (responses.store instanceof Error) { @@ -22,7 +22,7 @@ export default function useVideoCacheStub(responses) { } }); - afterEach(() => { + afterEach(function () { videoCache.store.restore(); }); diff --git a/test/spec/AnalyticsAdapter_spec.js b/test/spec/AnalyticsAdapter_spec.js index c6c50f76ecd..39096c0c4a3 100644 --- a/test/spec/AnalyticsAdapter_spec.js +++ b/test/spec/AnalyticsAdapter_spec.js @@ -22,19 +22,19 @@ FEATURE: Analytics Adapters API let requests; let adapter; - beforeEach(() => { + beforeEach(function () { xhr = sinon.useFakeXMLHttpRequest(); requests = []; xhr.onCreate = (request) => requests.push(request); adapter = new AnalyticsAdapter(config); }); - afterEach(() => { + afterEach(function () { xhr.restore(); adapter.disableAnalytics(); }); - it(`SHOULD call the endpoint WHEN an event occurs that is to be tracked`, () => { + it(`SHOULD call the endpoint WHEN an event occurs that is to be tracked`, function () { const eventType = BID_REQUESTED; const args = { some: 'data' }; @@ -44,7 +44,7 @@ FEATURE: Analytics Adapters API expect(result).to.deep.equal({args: {some: 'data'}, eventType: 'bidRequested'}); }); - it(`SHOULD queue the event first and then track it WHEN an event occurs before tracking library is available`, () => { + it(`SHOULD queue the event first and then track it WHEN an event occurs before tracking library is available`, function () { const eventType = BID_RESPONSE; const args = { wat: 'wot' }; @@ -55,16 +55,16 @@ FEATURE: Analytics Adapters API expect(result).to.deep.equal({args: {wat: 'wot'}, eventType: 'bidResponse'}); }); - describe(`WHEN an event occurs after enable analytics\n`, () => { - beforeEach(() => { + describe(`WHEN an event occurs after enable analytics\n`, function () { + beforeEach(function () { sinon.stub(events, 'getEvents').returns([]); // these tests shouldn't be affected by previous tests }); - afterEach(() => { + afterEach(function () { events.getEvents.restore(); }); - it('SHOULD call global when a bidWon event occurs', () => { + it('SHOULD call global when a bidWon event occurs', function () { const eventType = BID_WON; const args = { more: 'info' }; @@ -75,7 +75,7 @@ FEATURE: Analytics Adapters API expect(result).to.deep.equal({args: {more: 'info'}, eventType: 'bidWon'}); }); - it('SHOULD call global when a adRenderFailed event occurs', () => { + it('SHOULD call global when a adRenderFailed event occurs', function () { const eventType = AD_RENDER_FAILED; const args = { call: 'adRenderFailed' }; @@ -86,7 +86,7 @@ FEATURE: Analytics Adapters API expect(result).to.deep.equal({args: {call: 'adRenderFailed'}, eventType: 'adRenderFailed'}); }); - it('SHOULD call global when a bidRequest event occurs', () => { + it('SHOULD call global when a bidRequest event occurs', function () { const eventType = BID_REQUESTED; const args = { call: 'request' }; @@ -97,7 +97,7 @@ FEATURE: Analytics Adapters API expect(result).to.deep.equal({args: {call: 'request'}, eventType: 'bidRequested'}); }); - it('SHOULD call global when a bidResponse event occurs', () => { + it('SHOULD call global when a bidResponse event occurs', function () { const eventType = BID_RESPONSE; const args = { call: 'response' }; @@ -108,7 +108,7 @@ FEATURE: Analytics Adapters API expect(result).to.deep.equal({args: {call: 'response'}, eventType: 'bidResponse'}); }); - it('SHOULD call global when a bidTimeout event occurs', () => { + it('SHOULD call global when a bidTimeout event occurs', function () { const eventType = BID_TIMEOUT; const args = { call: 'timeout' }; @@ -119,7 +119,7 @@ FEATURE: Analytics Adapters API expect(result).to.deep.equal({args: {call: 'timeout'}, eventType: 'bidTimeout'}); }); - it('SHOULD NOT call global again when adapter.enableAnalytics is called with previous timeout', () => { + it('SHOULD NOT call global again when adapter.enableAnalytics is called with previous timeout', function () { const eventType = BID_TIMEOUT; const args = { call: 'timeout' }; @@ -130,19 +130,19 @@ FEATURE: Analytics Adapters API expect(requests.length).to.equal(1); }); - describe(`AND sampling is enabled\n`, () => { + describe(`AND sampling is enabled\n`, function () { const eventType = BID_WON; const args = { more: 'info' }; - beforeEach(() => { + beforeEach(function () { sinon.stub(Math, 'random').returns(0.5); }); - afterEach(() => { + afterEach(function () { Math.random.restore(); }); - it(`THEN should enable analytics when random number is in sample range`, () => { + it(`THEN should enable analytics when random number is in sample range`, function () { adapter.enableAnalytics({ options: { sampling: 0.75 @@ -155,7 +155,7 @@ FEATURE: Analytics Adapters API expect(result).to.deep.equal({args: {more: 'info'}, eventType: 'bidWon'}); }); - it(`THEN should disable analytics when random number is outside sample range`, () => { + it(`THEN should disable analytics when random number is outside sample range`, function () { adapter.enableAnalytics({ options: { sampling: 0.25 diff --git a/test/spec/adloader_spec.js b/test/spec/adloader_spec.js index 55224cb0aab..27f574c9c42 100644 --- a/test/spec/adloader_spec.js +++ b/test/spec/adloader_spec.js @@ -1,28 +1,28 @@ import * as utils from 'src/utils'; -import * as adLoader from 'src/adloader'; +import * as adLoader from 'test/mocks/adloaderStub'; describe('adLoader', function () { let utilsinsertElementStub; let utilsLogErrorStub; - beforeEach(() => { + beforeEach(function () { utilsinsertElementStub = sinon.stub(utils, 'insertElement'); utilsLogErrorStub = sinon.stub(utils, 'logError'); }); - afterEach(() => { + afterEach(function () { utilsinsertElementStub.restore(); utilsLogErrorStub.restore(); }); - describe('loadExternalScript', () => { - it('requires moduleCode to be included on the request', () => { + describe('loadExternalScript', function () { + it('requires moduleCode to be included on the request', function () { adLoader.loadExternalScript('someURL'); expect(utilsLogErrorStub.called).to.be.true; expect(utilsinsertElementStub.called).to.be.false; }); - it('only allows whitelisted vendors to load scripts', () => { + it('only allows whitelisted vendors to load scripts', function () { adLoader.loadExternalScript('someURL', 'criteo'); expect(utilsLogErrorStub.called).to.be.false; expect(utilsinsertElementStub.called).to.be.true; diff --git a/test/spec/api_spec.js b/test/spec/api_spec.js index 41fafb080ad..a8987d3ed07 100755 --- a/test/spec/api_spec.js +++ b/test/spec/api_spec.js @@ -39,6 +39,10 @@ describe('Publisher API', function () { assert.isFunction($$PREBID_GLOBAL$$.getBidResponses); }); + it('should have function $$PREBID_GLOBAL$$.getBidResponses', function () { + assert.isFunction($$PREBID_GLOBAL$$.getNoBids); + }); + it('should have function $$PREBID_GLOBAL$$.getBidResponsesForAdUnitCode', function () { assert.isFunction($$PREBID_GLOBAL$$.getBidResponsesForAdUnitCode); }); diff --git a/test/spec/auctionmanager_spec.js b/test/spec/auctionmanager_spec.js index 6fbc48b3cdc..232ed04da25 100644 --- a/test/spec/auctionmanager_spec.js +++ b/test/spec/auctionmanager_spec.js @@ -1,30 +1,24 @@ -import { auctionManager, newAuctionManager } from 'src/auctionManager'; -import { getKeyValueTargetingPairs } from 'src/auction'; +import { getKeyValueTargetingPairs, auctionCallbacks } from 'src/auction'; import CONSTANTS from 'src/constants.json'; import { adjustBids } from 'src/auction'; import * as auctionModule from 'src/auction'; -import { newBidder, registerBidder } from 'src/adapters/bidderFactory'; +import { registerBidder } from 'src/adapters/bidderFactory'; +import { createBid } from 'src/bidfactory'; import { config } from 'src/config'; import * as store from 'src/videoCache'; import * as ajaxLib from 'src/ajax'; import find from 'core-js/library/fn/array/find'; -const adloader = require('../../src/adloader'); var assert = require('assert'); /* use this method to test individual files instead of the whole prebid.js project */ // TODO refactor to use the spec files var utils = require('../../src/utils'); -var bidfactory = require('../../src/bidfactory'); var fixtures = require('../fixtures/fixtures'); -var adaptermanager = require('src/adaptermanager'); +var adapterManager = require('src/adapterManager').default; var events = require('src/events'); -function timestamp() { - return new Date().getTime(); -} - const BIDDER_CODE = 'sampleBidder'; const BIDDER_CODE1 = 'sampleBidder1'; @@ -44,7 +38,8 @@ function mockBid(opts) { 'creativeId': 'id', 'currency': 'USD', 'netRevenue': true, - 'ttl': 360 + 'ttl': 360, + getSize: () => '300x250' }; } @@ -54,6 +49,12 @@ function mockBidRequest(bid, opts) { } let bidderCode = opts && opts.bidderCode; let adUnitCode = opts && opts.adUnitCode; + let defaultMediaType = { + banner: { + sizes: [[300, 250], [300, 600]] + } + } + let mediaType = (opts && opts.mediaType) ? opts.mediaType : defaultMediaType; let requestId = utils.getUniqueIdentifierStr(); @@ -71,7 +72,8 @@ function mockBidRequest(bid, opts) { 'sizes': [[300, 250], [300, 600]], 'bidId': bid.requestId, 'bidderRequestId': requestId, - 'auctionId': '20882439e3238c' + 'auctionId': '20882439e3238c', + 'mediaTypes': mediaType } ], 'auctionStart': 1505250713622, @@ -107,16 +109,6 @@ function mockAjaxBuilder() { } describe('auctionmanager.js', function () { - let xhr; - - before(() => { - xhr = sinon.useFakeXMLHttpRequest(); - }); - - after(() => { - xhr.restore(); - }); - describe('getKeyValueTargetingPairs', function () { const DEFAULT_BID = { cpm: 5.578, @@ -140,14 +132,13 @@ describe('auctionmanager.js', function () { /* return the expected response for a given bid, filter by keys if given */ function getDefaultExpected(bid, keys) { - var expected = { - 'hb_bidder': bid.bidderCode, - 'hb_adid': bid.adId, - 'hb_pb': bid.pbMg, - 'hb_size': bid.getSize(), - 'hb_source': bid.source, - 'hb_format': bid.mediaType, - }; + var expected = {}; + expected[ CONSTANTS.TARGETING_KEYS.BIDDER ] = bid.bidderCode; + expected[ CONSTANTS.TARGETING_KEYS.AD_ID ] = bid.adId; + expected[ CONSTANTS.TARGETING_KEYS.PRICE_BUCKET ] = bid.pbMg; + expected[ CONSTANTS.TARGETING_KEYS.SIZE ] = bid.getSize(); + expected[ CONSTANTS.TARGETING_KEYS.SOURCE ] = bid.source; + expected[ CONSTANTS.TARGETING_KEYS.FORMAT ] = bid.mediaType; if (!keys) { return expected; @@ -177,35 +168,35 @@ describe('auctionmanager.js', function () { standard: { adserverTargeting: [ { - key: 'hb_bidder', + key: CONSTANTS.TARGETING_KEYS.BIDDER, val: function (bidResponse) { return bidResponse.bidderCode; } }, { - key: 'hb_adid', + key: CONSTANTS.TARGETING_KEYS.AD_ID, val: function (bidResponse) { return bidResponse.adId; } }, { - key: 'hb_pb', + key: CONSTANTS.TARGETING_KEYS.PRICE_BUCKET, val: function (bidResponse) { // change default here return bidResponse.pbHg; } }, { - key: 'hb_size', + key: CONSTANTS.TARGETING_KEYS.SIZE, val: function (bidResponse) { return bidResponse.size; } }, { - key: 'hb_source', + key: CONSTANTS.TARGETING_KEYS.SOURCE, val: function (bidResponse) { return bidResponse.source; } }, { - key: 'hb_format', + key: CONSTANTS.TARGETING_KEYS.FORMAT, val: function (bidResponse) { return bidResponse.mediaType; } @@ -216,7 +207,7 @@ describe('auctionmanager.js', function () { }; var expected = getDefaultExpected(bid); - expected.hb_pb = bid.pbHg; + expected[CONSTANTS.TARGETING_KEYS.PRICE_BUCKET] = bid.pbHg; var response = getKeyValueTargetingPairs(bid.bidderCode, bid); assert.deepEqual(response, expected); @@ -228,23 +219,23 @@ describe('auctionmanager.js', function () { appnexus: { adserverTargeting: [ { - key: 'hb_bidder', + key: CONSTANTS.TARGETING_KEYS.BIDDER, val: function (bidResponse) { return bidResponse.bidderCode; } }, { - key: 'hb_adid', + key: CONSTANTS.TARGETING_KEYS.AD_ID, val: function (bidResponse) { return bidResponse.adId; } }, { - key: 'hb_pb', + key: CONSTANTS.TARGETING_KEYS.PRICE_BUCKET, val: function (bidResponse) { // change default here return bidResponse.pbHg; } }, { - key: 'hb_size', + key: CONSTANTS.TARGETING_KEYS.SIZE, val: function (bidResponse) { return bidResponse.size; } @@ -255,7 +246,7 @@ describe('auctionmanager.js', function () { }; var expected = getDefaultExpected(bid); - expected.hb_pb = bid.pbHg; + expected[CONSTANTS.TARGETING_KEYS.PRICE_BUCKET] = bid.pbHg; var response = getKeyValueTargetingPairs(bid.bidderCode, bid); assert.deepEqual(response, expected); @@ -267,23 +258,23 @@ describe('auctionmanager.js', function () { nonExistentBidder: { adserverTargeting: [ { - key: 'hb_bidder', + key: CONSTANTS.TARGETING_KEYS.BIDDER, val: function (bidResponse) { return bidResponse.bidderCode; } }, { - key: 'hb_adid', + key: CONSTANTS.TARGETING_KEYS.AD_ID, val: function (bidResponse) { return bidResponse.adId; } }, { - key: 'hb_pb', + key: CONSTANTS.TARGETING_KEYS.PRICE_BUCKET, val: function (bidResponse) { // change default here return bidResponse.pbHg; } }, { - key: 'hb_size', + key: CONSTANTS.TARGETING_KEYS.SIZE, val: function (bidResponse) { return bidResponse.size; } @@ -312,17 +303,17 @@ describe('auctionmanager.js', function () { }, adserverTargeting: [ { - key: 'hb_bidder', + key: CONSTANTS.TARGETING_KEYS.BIDDER, val: function (bidResponse) { return bidResponse.bidderCode; } }, { - key: 'hb_adid', + key: CONSTANTS.TARGETING_KEYS.AD_ID, val: function (bidResponse) { return bidResponse.adId; } }, { - key: 'hb_pb', + key: CONSTANTS.TARGETING_KEYS.PRICE_BUCKET, val: function (bidResponse) { // change default here return 10.00; @@ -332,8 +323,8 @@ describe('auctionmanager.js', function () { } }; - var expected = getDefaultExpected(bid, ['hb_bidder', 'hb_adid']); - expected.hb_pb = 10.0; + var expected = getDefaultExpected(bid, [CONSTANTS.TARGETING_KEYS.BIDDER, CONSTANTS.TARGETING_KEYS.AD_ID]); + expected[CONSTANTS.TARGETING_KEYS.PRICE_BUCKET] = 10.0; var response = getKeyValueTargetingPairs(bid.bidderCode, bid); assert.deepEqual(response, expected); @@ -341,7 +332,7 @@ describe('auctionmanager.js', function () { it('Standard bidCpmAdjustment changes the bid of any bidder', function () { const bid = Object.assign({}, - bidfactory.createBid(2), + createBid(2), fixtures.getBidResponses()[5] ); @@ -369,17 +360,17 @@ describe('auctionmanager.js', function () { }, adserverTargeting: [ { - key: 'hb_bidder', + key: CONSTANTS.TARGETING_KEYS.BIDDER, val: function (bidResponse) { return bidResponse.bidderCode; } }, { - key: 'hb_adid', + key: CONSTANTS.TARGETING_KEYS.AD_ID, val: function (bidResponse) { return bidResponse.adId; } }, { - key: 'hb_pb', + key: CONSTANTS.TARGETING_KEYS.PRICE_BUCKET, val: function (bidResponse) { // change default here return 15.00; @@ -390,24 +381,24 @@ describe('auctionmanager.js', function () { standard: { adserverTargeting: [ { - key: 'hb_bidder', + key: CONSTANTS.TARGETING_KEYS.BIDDER, val: function (bidResponse) { return bidResponse.bidderCode; } }, { - key: 'hb_adid', + key: CONSTANTS.TARGETING_KEYS.AD_ID, val: function (bidResponse) { return bidResponse.adId; } }, { - key: 'hb_pb', + key: CONSTANTS.TARGETING_KEYS.PRICE_BUCKET, val: function (bidResponse) { // change default here return 10.00; }, }, { - key: 'hb_size', + key: CONSTANTS.TARGETING_KEYS.SIZE, val: function (bidResponse) { return bidResponse.size; } @@ -416,8 +407,8 @@ describe('auctionmanager.js', function () { } }; - var expected = getDefaultExpected(bid, ['hb_bidder', 'hb_adid', 'hb_size']); - expected.hb_pb = 15.0; + var expected = getDefaultExpected(bid, [CONSTANTS.TARGETING_KEYS.BIDDER, CONSTANTS.TARGETING_KEYS.AD_ID, CONSTANTS.TARGETING_KEYS.SIZE]); + expected[CONSTANTS.TARGETING_KEYS.PRICE_BUCKET] = 15.0; var response = getKeyValueTargetingPairs(bid.bidderCode, bid); assert.deepEqual(response, expected); @@ -430,17 +421,17 @@ describe('auctionmanager.js', function () { sendStandardTargeting: false, adserverTargeting: [ { - key: 'hb_bidder', + key: CONSTANTS.TARGETING_KEYS.BIDDER, val: function (bidResponse) { return bidResponse.bidderCode; } }, { - key: 'hb_adid', + key: CONSTANTS.TARGETING_KEYS.AD_ID, val: function (bidResponse) { return bidResponse.adId; } }, { - key: 'hb_pb', + key: CONSTANTS.TARGETING_KEYS.PRICE_BUCKET, val: function (bidResponse) { return bidResponse.pbHg; } @@ -449,7 +440,7 @@ describe('auctionmanager.js', function () { } }; var expected = getDefaultExpected(bid); - expected.hb_pb = 5.57; + expected[CONSTANTS.TARGETING_KEYS.PRICE_BUCKET] = 5.57; var response = getKeyValueTargetingPairs(bid.bidderCode, bid); assert.deepEqual(response, expected); @@ -483,10 +474,10 @@ describe('auctionmanager.js', function () { }); }); - describe('adjustBids', () => { - it('should adjust bids if greater than zero and pass copy of bid object', () => { + describe('adjustBids', function () { + it('should adjust bids if greater than zero and pass copy of bid object', function () { const bid = Object.assign({}, - bidfactory.createBid(2), + createBid(2), fixtures.getBidResponses()[5] ); @@ -532,7 +523,7 @@ describe('auctionmanager.js', function () { }); }); - describe('addBidResponse', () => { + describe('addBidResponse', function () { let createAuctionStub; let adUnits; let adUnitCodes; @@ -542,23 +533,22 @@ describe('auctionmanager.js', function () { let bids = TEST_BIDS; let makeRequestsStub; - before(() => { - makeRequestsStub = sinon.stub(adaptermanager, 'makeBidRequests'); + before(function () { + makeRequestsStub = sinon.stub(adapterManager, 'makeBidRequests'); ajaxStub = sinon.stub(ajaxLib, 'ajaxBuilder').callsFake(mockAjaxBuilder); }); - after(() => { + after(function () { ajaxStub.restore(); - adaptermanager.makeBidRequests.restore(); + adapterManager.makeBidRequests.restore(); }); - describe('when auction timeout is 3000', () => { - let loadScriptStub; - before(() => { + describe('when auction timeout is 3000', function () { + before(function () { makeRequestsStub.returns(TEST_BID_REQS); }); - beforeEach(() => { + beforeEach(function () { adUnits = [{ code: ADUNIT_CODE, bids: [ @@ -570,17 +560,12 @@ describe('auctionmanager.js', function () { createAuctionStub = sinon.stub(auctionModule, 'newAuction'); createAuctionStub.returns(auction); - loadScriptStub = sinon.stub(adloader, 'loadScript').callsFake((...args) => { - args[1](); - }); - spec = mockBidder(BIDDER_CODE, bids); registerBidder(spec); }); - afterEach(() => { + afterEach(function () { auctionModule.newAuction.restore(); - loadScriptStub.restore(); }); function checkPbDg(cpm, expected, msg) { @@ -605,25 +590,25 @@ describe('auctionmanager.js', function () { it('should return proper price bucket increments for dense mode when cpm is 20+', checkPbDg('73.07', '20.00', '20+ caps at 20.00')); - it('should place dealIds in adserver targeting', () => { + it('should place dealIds in adserver targeting', function () { bids[0].dealId = 'test deal'; auction.callBids(); let registeredBid = auction.getBidsReceived().pop(); - assert.equal(registeredBid.adserverTargeting[`hb_deal`], 'test deal', 'dealId placed in adserverTargeting'); + assert.equal(registeredBid.adserverTargeting[CONSTANTS.TARGETING_KEYS.DEAL], 'test deal', 'dealId placed in adserverTargeting'); }); - it('should pass through default adserverTargeting sent from adapter', () => { + it('should pass through default adserverTargeting sent from adapter', function () { bids[0].adserverTargeting = {}; bids[0].adserverTargeting.extra = 'stuff'; auction.callBids(); let registeredBid = auction.getBidsReceived().pop(); - assert.equal(registeredBid.adserverTargeting.hb_bidder, BIDDER_CODE); + assert.equal(registeredBid.adserverTargeting[CONSTANTS.TARGETING_KEYS.BIDDER], BIDDER_CODE); assert.equal(registeredBid.adserverTargeting.extra, 'stuff'); }); - it('installs publisher-defined renderers on bids', () => { + it('installs publisher-defined renderers on bids', function () { let renderer = { url: 'renderer.js', render: (bid) => bid @@ -675,19 +660,17 @@ describe('auctionmanager.js', function () { }); }); - describe('when auction timeout is 20', () => { - let loadScriptStub; + describe('when auction timeout is 20', function () { let eventsEmitSpy; - let getBidderRequestStub; - before(() => { + before(function () { bids = [mockBid(), mockBid({ bidderCode: BIDDER_CODE1 })]; let bidRequests = bids.map(bid => mockBidRequest(bid)); makeRequestsStub.returns(bidRequests); }); - beforeEach(() => { + beforeEach(function () { adUnits = [{ code: ADUNIT_CODE, bids: [ @@ -700,10 +683,6 @@ describe('auctionmanager.js', function () { createAuctionStub = sinon.stub(auctionModule, 'newAuction'); createAuctionStub.returns(auction); - loadScriptStub = sinon.stub(adloader, 'loadScript').callsFake((...args) => { - args[1](); - }); - spec = mockBidder(BIDDER_CODE, [bids[0]]); registerBidder(spec); @@ -715,28 +694,25 @@ describe('auctionmanager.js', function () { eventsEmitSpy = sinon.spy(events, 'emit'); - let origGBR = utils.getBidderRequest; - getBidderRequestStub = sinon.stub(utils, 'getBidderRequest'); - getBidderRequestStub.callsFake((bidRequests, bidder, adUnitCode) => { - let req = origGBR(bidRequests, bidder, adUnitCode); - req.start = 1000; - return req; + // make all timestamp calls 5 minutes apart + let callCount = 0; + sinon.stub(utils, 'timestamp').callsFake(function() { + return new Date().getTime() + (callCount++ * 1000 * 60 * 5); }); }); - afterEach(() => { + afterEach(function () { auctionModule.newAuction.restore(); - loadScriptStub.restore(); events.emit.restore(); - getBidderRequestStub.restore(); + utils.timestamp.restore(); }); - it('should emit BID_TIMEOUT for timed out bids', () => { + it('should emit BID_TIMEOUT for timed out bids', function () { auction.callBids(); assert.ok(eventsEmitSpy.calledWith(CONSTANTS.EVENTS.BID_TIMEOUT), 'emitted events BID_TIMEOUT'); }); }); }); - describe('addBidResponse', () => { + describe('addBidResponse', function () { let createAuctionStub; let adUnits; let adUnitCodes; @@ -748,23 +724,23 @@ describe('auctionmanager.js', function () { let bids = TEST_BIDS; let bids1 = [mockBid({ bidderCode: BIDDER_CODE1 })]; - before(() => { + before(function () { let bidRequests = [ mockBidRequest(bids[0]), mockBidRequest(bids1[0], { adUnitCode: ADUNIT_CODE1 }) ]; - let makeRequestsStub = sinon.stub(adaptermanager, 'makeBidRequests'); + let makeRequestsStub = sinon.stub(adapterManager, 'makeBidRequests'); makeRequestsStub.returns(bidRequests); ajaxStub = sinon.stub(ajaxLib, 'ajaxBuilder').callsFake(mockAjaxBuilder); }); - after(() => { + after(function () { ajaxStub.restore(); - adaptermanager.makeBidRequests.restore(); + adapterManager.makeBidRequests.restore(); }); - beforeEach(() => { + beforeEach(function () { adUnits = [{ code: ADUNIT_CODE, bids: [ @@ -788,11 +764,11 @@ describe('auctionmanager.js', function () { registerBidder(spec1); }); - afterEach(() => { + afterEach(function () { auctionModule.newAuction.restore(); }); - it('should not alter bid adID', () => { + it('should not alter bid adID', function () { auction.callBids(); const addedBid2 = auction.getBidsReceived().pop(); @@ -801,7 +777,7 @@ describe('auctionmanager.js', function () { assert.equal(addedBid1.adId, bids[0].requestId); }); - it('should not add banner bids that have no width or height', () => { + it('should not add banner bids that have no width or height', function () { bids1[0].width = undefined; bids1[0].height = undefined; @@ -813,7 +789,7 @@ describe('auctionmanager.js', function () { assert.equal(length, 1); }); - it('should run auction after video bids have been cached', () => { + it('should run auction after video bids have been cached', function () { sinon.stub(store, 'store').callsArgWith(1, null, [{ uuid: 123 }]); sinon.stub(config, 'getConfig').withArgs('cache.url').returns('cache-url'); @@ -832,7 +808,7 @@ describe('auctionmanager.js', function () { store.store.restore(); }); - it('runs auction after video responses with multiple bid objects have been cached', () => { + it('runs auction after video responses with multiple bid objects have been cached', function () { sinon.stub(store, 'store').callsArgWith(1, null, [{ uuid: 123 }]); sinon.stub(config, 'getConfig').withArgs('cache.url').returns('cache-url'); @@ -857,4 +833,86 @@ describe('auctionmanager.js', function () { store.store.restore(); }); }); + + describe('auctionCallbacks', function() { + let bids = TEST_BIDS; + let bidRequests; + let xhr; + let requests; + let doneSpy; + let auction = { + getBidRequests: () => bidRequests, + getAuctionId: () => '1', + addBidReceived: () => true, + getTimeout: () => 1000 + } + + beforeEach(() => { + doneSpy = sinon.spy(); + xhr = sinon.useFakeXMLHttpRequest(); + requests = []; + xhr.onCreate = (request) => requests.push(request); + config.setConfig({ + cache: { + url: 'https://prebid.adnxs.com/pbc/v1/cache' + } + }) + }); + + afterEach(() => { + doneSpy.resetHistory(); + xhr.restore(); + config.resetConfig(); + }); + + it('should call auction done after bid is added to auction for mediaType banner', function () { + let ADUNIT_CODE2 = 'adUnitCode2'; + let BIDDER_CODE2 = 'sampleBidder2'; + + let bids1 = [mockBid({ bidderCode: BIDDER_CODE1 })]; + let bids2 = [mockBid({ bidderCode: BIDDER_CODE2 })]; + bidRequests = [ + mockBidRequest(bids[0]), + mockBidRequest(bids1[0], { adUnitCode: ADUNIT_CODE1 }), + mockBidRequest(bids2[0], { adUnitCode: ADUNIT_CODE2 }) + ]; + let cbs = auctionCallbacks(doneSpy, auction); + cbs.addBidResponse.call(bidRequests[0], ADUNIT_CODE, bids[0]); + cbs.adapterDone.call(bidRequests[0]); + cbs.addBidResponse.call(bidRequests[1], ADUNIT_CODE1, bids1[0]); + cbs.adapterDone.call(bidRequests[1]); + cbs.addBidResponse.call(bidRequests[2], ADUNIT_CODE2, bids2[0]); + cbs.adapterDone.call(bidRequests[2]); + assert.equal(doneSpy.callCount, 1); + }); + + it('should call auction done after prebid cache is complete for mediaType video', function() { + bids[0].mediaType = 'video'; + let bids1 = [mockBid({ bidderCode: BIDDER_CODE1 })]; + + let opts = { + mediaType: { + video: { + context: 'instream', + playerSize: [640, 480], + }, + } + }; + bidRequests = [ + mockBidRequest(bids[0], opts), + mockBidRequest(bids1[0], { adUnitCode: ADUNIT_CODE1 }), + ]; + + let cbs = auctionCallbacks(doneSpy, auction); + cbs.addBidResponse.call(bidRequests[0], ADUNIT_CODE, bids[0]); + cbs.adapterDone.call(bidRequests[0]); + cbs.addBidResponse.call(bidRequests[1], ADUNIT_CODE1, bids1[0]); + cbs.adapterDone.call(bidRequests[1]); + assert.equal(doneSpy.callCount, 0); + const uuid = 'c488b101-af3e-4a99-b538-00423e5a3371'; + const responseBody = `{"responses":[{"uuid":"${uuid}"}]}`; + requests[0].respond(200, { 'Content-Type': 'application/json' }, responseBody); + assert.equal(doneSpy.callCount, 1); + }) + }); }); diff --git a/test/spec/config_spec.js b/test/spec/config_spec.js index 6b26d7da76a..196e167420a 100644 --- a/test/spec/config_spec.js +++ b/test/spec/config_spec.js @@ -8,10 +8,10 @@ let getConfig; let setConfig; let setDefaults; -describe('config API', () => { +describe('config API', function () { let logErrorSpy; let logWarnSpy; - beforeEach(() => { + beforeEach(function () { const config = newConfig(); getConfig = config.getConfig; setConfig = config.setConfig; @@ -20,30 +20,30 @@ describe('config API', () => { logWarnSpy = sinon.spy(utils, 'logWarn'); }); - afterEach(() => { + afterEach(function () { utils.logError.restore(); utils.logWarn.restore(); }); - it('setConfig is a function', () => { + it('setConfig is a function', function () { expect(setConfig).to.be.a('function'); }); - it('getConfig returns an object', () => { + it('getConfig returns an object', function () { expect(getConfig()).to.be.a('object'); }); - it('sets and gets arbitrary configuarion properties', () => { + it('sets and gets arbitrary configuarion properties', function () { setConfig({ baz: 'qux' }); expect(getConfig('baz')).to.equal('qux'); }); - it('only accepts objects', () => { + it('only accepts objects', function () { setConfig('invalid'); expect(getConfig('0')).to.not.equal('i'); }); - it('sets multiple config properties', () => { + it('sets multiple config properties', function () { setConfig({ foo: 'bar' }); setConfig({ biz: 'buz' }); var config = getConfig(); @@ -51,28 +51,28 @@ describe('config API', () => { expect(config.biz).to.equal('buz'); }); - it('overwrites existing config properties', () => { + it('overwrites existing config properties', function () { setConfig({ foo: {biz: 'buz'} }); setConfig({ foo: {baz: 'qux'} }); expect(getConfig('foo')).to.eql({baz: 'qux'}); }); - it('sets debugging', () => { + it('sets debugging', function () { setConfig({ debug: true }); expect(getConfig('debug')).to.be.true; }); - it('sets bidderTimeout', () => { + it('sets bidderTimeout', function () { setConfig({ bidderTimeout: 1000 }); expect(getConfig('bidderTimeout')).to.be.equal(1000); }); - it('gets user-defined publisherDomain', () => { + it('gets user-defined publisherDomain', function () { setConfig({ publisherDomain: 'fc.kahuna' }); expect(getConfig('publisherDomain')).to.equal('fc.kahuna'); }); - it('gets default userSync config', () => { + it('gets default userSync config', function () { const DEFAULT_USERSYNC = { syncEnabled: true, pixelEnabled: true, @@ -83,7 +83,7 @@ describe('config API', () => { expect(getConfig('userSync')).to.eql(DEFAULT_USERSYNC); }); - it('has subscribe functionality for adding listeners to config updates', () => { + it('has subscribe functionality for adding listeners to config updates', function () { const listener = sinon.spy(); getConfig(listener); @@ -94,7 +94,7 @@ describe('config API', () => { sinon.assert.calledWith(listener, { foo: 'bar' }); }); - it('subscribers can unsubscribe', () => { + it('subscribers can unsubscribe', function () { const listener = sinon.spy(); const unsubscribe = getConfig(listener); @@ -106,7 +106,7 @@ describe('config API', () => { sinon.assert.notCalled(listener); }); - it('subscribers can subscribe to topics', () => { + it('subscribers can subscribe to topics', function () { const listener = sinon.spy(); getConfig('logging', listener); @@ -117,7 +117,7 @@ describe('config API', () => { sinon.assert.calledWithExactly(listener, { logging: true }); }); - it('topic subscribers are only called when that topic is changed', () => { + it('topic subscribers are only called when that topic is changed', function () { const listener = sinon.spy(); const wildcard = sinon.spy(); @@ -130,12 +130,12 @@ describe('config API', () => { sinon.assert.calledOnce(wildcard); }); - it('sets priceGranularity', () => { + it('sets priceGranularity', function () { setConfig({ priceGranularity: 'low' }); expect(getConfig('priceGranularity')).to.be.equal('low'); }); - it('set mediaTypePriceGranularity', () => { + it('set mediaTypePriceGranularity', function () { const customPriceGranularity = { 'buckets': [{ 'min': 0, @@ -158,7 +158,7 @@ describe('config API', () => { expect(configResult.native).to.be.equal('medium'); }); - it('sets priceGranularity and customPriceBucket', () => { + it('sets priceGranularity and customPriceBucket', function () { const goodConfig = { 'buckets': [{ 'min': 0, @@ -172,18 +172,18 @@ describe('config API', () => { expect(getConfig('customPriceBucket')).to.equal(goodConfig); }); - it('should log error for invalid priceGranularity', () => { + it('should log error for invalid priceGranularity', function () { setConfig({ priceGranularity: '' }); const error = 'Prebid Error: no value passed to `setPriceGranularity()`'; assert.ok(logErrorSpy.calledWith(error), 'expected error was logged'); }); - it('should log a warning on invalid values', () => { + it('should log a warning on invalid values', function () { setConfig({ bidderSequence: 'unrecognized sequence' }); expect(logWarnSpy.calledOnce).to.equal(true); }); - it('should not log warnings when given recognized values', () => { + it('should not log warnings when given recognized values', function () { setConfig({ bidderSequence: 'fixed' }); setConfig({ bidderSequence: 'random' }); expect(logWarnSpy.called).to.equal(false); diff --git a/test/spec/cpmBucketManager_spec.js b/test/spec/cpmBucketManager_spec.js index 55fae3bb869..88e04be9ad6 100644 --- a/test/spec/cpmBucketManager_spec.js +++ b/test/spec/cpmBucketManager_spec.js @@ -2,8 +2,8 @@ import { expect } from 'chai'; import {getPriceBucketString, isValidPriceConfig} from 'src/cpmBucketManager'; let cpmFixtures = require('test/fixtures/cpmInputsOutputs.json'); -describe('cpmBucketManager', () => { - it('getPriceBucketString function generates the correct price strings', () => { +describe('cpmBucketManager', function () { + it('getPriceBucketString function generates the correct price strings', function () { let input = cpmFixtures.cpmInputs; for (let i = 0; i < input.length; i++) { let output = getPriceBucketString(input[i]); @@ -12,7 +12,7 @@ describe('cpmBucketManager', () => { } }); - it('gets the correct custom bucket strings', () => { + it('gets the correct custom bucket strings', function () { let cpm = 16.50908; let customConfig = { 'buckets': [{ @@ -35,7 +35,7 @@ describe('cpmBucketManager', () => { expect(JSON.stringify(output)).to.deep.equal(expected); }); - it('gets the correct custom bucket strings with irregular increment', () => { + it('gets the correct custom bucket strings with irregular increment', function () { let cpm = 14.50908; let customConfig = { 'buckets': [{ @@ -58,7 +58,7 @@ describe('cpmBucketManager', () => { expect(JSON.stringify(output)).to.deep.equal(expected); }); - it('gets the correct custom bucket strings in non-USD currency', () => { + it('gets the correct custom bucket strings in non-USD currency', function () { let cpm = 16.50908 * 110.49; let customConfig = { 'buckets': [{ @@ -81,7 +81,7 @@ describe('cpmBucketManager', () => { expect(JSON.stringify(output)).to.deep.equal(expected); }); - it('gets the correct custom bucket strings with specific cpms that round oddly with certain increments', () => { + it('gets the correct custom bucket strings with specific cpms that round oddly with certain increments', function () { let customConfig = { 'buckets': [{ 'precision': 4, @@ -155,7 +155,7 @@ describe('cpmBucketManager', () => { expect(JSON.stringify(output)).to.deep.equal(expected); }); - it('gets custom bucket strings and it should honor 0', () => { + it('gets custom bucket strings and it should honor 0', function () { let cpm = 16.50908; let customConfig = { 'buckets': [ @@ -172,7 +172,7 @@ describe('cpmBucketManager', () => { expect(JSON.stringify(output)).to.deep.equal(expected); }); - it('gets the custom bucket strings without passing precision and it should honor the default precision', () => { + it('gets the custom bucket strings without passing precision and it should honor the default precision', function () { let cpm = 16.50908; let customConfig = { 'buckets': [ @@ -188,7 +188,7 @@ describe('cpmBucketManager', () => { expect(JSON.stringify(output)).to.deep.equal(expected); }); - it('checks whether custom config is valid', () => { + it('checks whether custom config is valid', function () { let badConfig = { 'buckets': [{ 'min': 0, diff --git a/test/spec/debugging_spec.js b/test/spec/debugging_spec.js index 286df26f7ba..b048382171b 100644 --- a/test/spec/debugging_spec.js +++ b/test/spec/debugging_spec.js @@ -4,28 +4,28 @@ import { sessionLoader, addBidResponseHook, getConfig, disableOverrides, boundHo import { addBidResponse } from 'src/auction'; import { config } from 'src/config'; -describe('bid overrides', () => { +describe('bid overrides', function () { let sandbox; - beforeEach(() => { + beforeEach(function () { sandbox = sinon.sandbox.create(); }); - afterEach(() => { + afterEach(function () { window.sessionStorage.clear(); sandbox.restore(); }); - describe('initialization', () => { - beforeEach(() => { + describe('initialization', function () { + beforeEach(function () { sandbox.stub(config, 'setConfig'); }); - afterEach(() => { + afterEach(function () { disableOverrides(); }); - it('should happen when enabled with setConfig', () => { + it('should happen when enabled with setConfig', function () { getConfig({ enabled: true }); @@ -33,14 +33,14 @@ describe('bid overrides', () => { expect(addBidResponse.hasHook(boundHook)).to.equal(true); }); - it('should happen when configuration found in sessionStorage', () => { + it('should happen when configuration found in sessionStorage', function () { sessionLoader({ getItem: () => ('{"enabled": true}') }); expect(addBidResponse.hasHook(boundHook)).to.equal(true); }); - it('should not throw if sessionStorage is inaccessible', () => { + it('should not throw if sessionStorage is inaccessible', function () { expect(() => { sessionLoader({ getItem() { @@ -51,11 +51,11 @@ describe('bid overrides', () => { }); }); - describe('hook', () => { + describe('hook', function () { let mockBids; let bids; - beforeEach(() => { + beforeEach(function () { let baseBid = { 'bidderCode': 'rubicon', 'width': 970, @@ -86,7 +86,7 @@ describe('bid overrides', () => { }); } - it('should allow us to exclude bidders', () => { + it('should allow us to exclude bidders', function () { run({ enabled: true, bidders: ['appnexus'] @@ -96,7 +96,7 @@ describe('bid overrides', () => { expect(bids[0].bidderCode).to.equal('appnexus'); }); - it('should allow us to override all bids', () => { + it('should allow us to override all bids', function () { run({ enabled: true, bids: [{ @@ -109,7 +109,7 @@ describe('bid overrides', () => { expect(bids[1].cpm).to.equal(2); }); - it('should allow us to override bids by bidder', () => { + it('should allow us to override bids by bidder', function () { run({ enabled: true, bids: [{ @@ -123,7 +123,7 @@ describe('bid overrides', () => { expect(bids[1].cpm).to.equal(0.5); }); - it('should allow us to override bids by adUnitCode', () => { + it('should allow us to override bids by adUnitCode', function () { mockBids[1].adUnitCode = 'test'; run({ diff --git a/test/spec/hook_spec.js b/test/spec/hook_spec.js index 1fab4ecd1b7..7536f8316d5 100644 --- a/test/spec/hook_spec.js +++ b/test/spec/hook_spec.js @@ -2,18 +2,18 @@ import { expect } from 'chai'; import { createHook, hooks } from 'src/hook'; -describe('the hook module', () => { +describe('the hook module', function () { let sandbox; - beforeEach(() => { + beforeEach(function () { sandbox = sinon.sandbox.create(); }); - afterEach(() => { + afterEach(function () { sandbox.restore(); }); - it('should call all sync hooks attached to a function', () => { + it('should call all sync hooks attached to a function', function () { let called = []; let calledWith; @@ -63,7 +63,7 @@ describe('the hook module', () => { ]); }); - it('should allow context to be passed to hooks, but keep bound contexts', () => { + it('should allow context to be passed to hooks, but keep bound contexts', function () { let context; let fn = function() { context = this; @@ -85,8 +85,8 @@ describe('the hook module', () => { expect(calledBoundContext).to.equal(boundContext); }); - describe('asyncSeries', () => { - it('should call function as normal if no hooks attached', () => { + describe('asyncSeries', function () { + it('should call function as normal if no hooks attached', function () { let fn = sandbox.spy(); let hookFn = createHook('asyncSeries', fn); @@ -96,7 +96,7 @@ describe('the hook module', () => { expect(fn.firstCall.args[0]).to.equal(1); }); - it('should call hooks correctly applied in asyncSeries', () => { + it('should call hooks correctly applied in asyncSeries', function () { let called = []; let testFn = (called) => { @@ -124,7 +124,7 @@ describe('the hook module', () => { ]); }); - it('should allow context to be passed to hooks, but keep bound contexts', () => { + it('should allow context to be passed to hooks, but keep bound contexts', function () { let context; let fn = function() { context = this; diff --git a/test/spec/modules/33acrossBidAdapter_spec.js b/test/spec/modules/33acrossBidAdapter_spec.js index 8ca2f3da902..1fc77a7e14d 100644 --- a/test/spec/modules/33acrossBidAdapter_spec.js +++ b/test/spec/modules/33acrossBidAdapter_spec.js @@ -1,23 +1,169 @@ -const { userSync } = require('../../../src/userSync'); -const { config } = require('../../../src/config'); +import { expect } from 'chai'; -const { expect } = require('chai'); -const { - isBidRequestValid, - buildRequests, - interpretResponse, - getUserSyncs -} = require('../../../modules/33acrossBidAdapter'); +import * as utils from 'src/utils'; +import { config } from 'src/config'; + +import { spec } from 'modules/33acrossBidAdapter'; describe('33acrossBidAdapter:', function () { const BIDDER_CODE = '33across'; const SITE_ID = 'pub1234'; const PRODUCT_ID = 'product1'; const END_POINT = 'https://ssc.33across.com/api/v1/hb'; - const SYNC_ENDPOINT = 'https://de.tynt.com/deb/v2?m=xch&rt=html'; + + let element, win; + let bidRequests; + let sandbox; + + function TtxRequestBuilder() { + const ttxRequest = { + imp: [{ + banner: { + format: [ + { + w: 300, + h: 250, + ext: {} + }, + { + w: 728, + h: 90, + ext: {} + } + ], + ext: { + ttx: { + viewability: { + amount: 100 + } + } + } + }, + ext: { + ttx: { + prod: PRODUCT_ID + } + } + }], + site: { + id: SITE_ID + }, + id: 'b1', + user: { + ext: { + consent: undefined + } + }, + regs: { + ext: { + gdpr: 0 + } + }, + ext: { + ttx: { + caller: [{ + 'name': 'prebidjs', + 'version': '$prebid.version$' + }] + } + } + }; + + this.withSizes = sizes => { + Object.assign(ttxRequest.imp[0].banner, { format: sizes }); + return this; + }; + + this.withViewabiliuty = viewability => { + Object.assign(ttxRequest.imp[0].banner, { + ext: { + ttx: { viewability } + } + }); + return this; + }; + + this.withGdprConsent = (consent, gdpr) => { + Object.assign(ttxRequest, { + user: { + ext: { consent } + } + }); + Object.assign(ttxRequest, { + regs: { + ext: { gdpr } + } + }); + return this; + }; + + this.withSite = site => { + Object.assign(ttxRequest, { site }); + return this; + }; + + this.build = () => ttxRequest; + } + + function ServerRequestBuilder() { + const serverRequest = { + 'method': 'POST', + 'url': END_POINT, + 'data': null, + 'options': { + 'contentType': 'text/plain', + 'withCredentials': true + } + }; + + this.withData = data => { + serverRequest['data'] = JSON.stringify(data); + return this; + }; + + this.withUrl = url => { + serverRequest['url'] = url; + return this; + }; + + this.withOptions = options => { + serverRequest['options'] = options; + return this; + }; + + this.build = () => serverRequest; + } beforeEach(function() { - this.bidRequests = [ + element = { + x: 0, + y: 0, + + width: 0, + height: 0, + + getBoundingClientRect: () => { + return { + width: element.width, + height: element.height, + + left: element.x, + top: element.y, + right: element.x + element.width, + bottom: element.y + element.height + }; + } + }; + win = { + document: { + visibilityState: 'visible' + }, + + innerWidth: 800, + innerHeight: 600 + }; + + bidRequests = [ { bidId: 'b1', bidder: '33across', @@ -29,20 +175,24 @@ describe('33acrossBidAdapter:', function () { adUnitCode: 'div-id', auctionId: 'r1', sizes: [ - [ 300, 250 ], - [ 728, 90 ] + [300, 250], + [728, 90] ], transactionId: 't1' } ]; - this.sandbox = sinon.sandbox.create(); + + sandbox = sinon.sandbox.create(); + sandbox.stub(document, 'getElementById').withArgs('div-id').returns(element); + sandbox.stub(utils, 'getWindowTop').returns(win); + sandbox.stub(utils, 'getWindowSelf').returns(win); }); afterEach(function() { - this.sandbox.restore(); + sandbox.restore(); }); - describe('isBidRequestValid:', function () { + describe('isBidRequestValid:', function() { it('returns true when valid bid request is sent', function() { const validBid = { bidder: BIDDER_CODE, @@ -50,9 +200,9 @@ describe('33acrossBidAdapter:', function () { siteId: SITE_ID, productId: PRODUCT_ID } - } + }; - expect(isBidRequestValid(validBid)).to.be.true; + expect(spec.isBidRequestValid(validBid)).to.be.true; }); it('returns true when valid test bid request is sent', function() { @@ -63,29 +213,29 @@ describe('33acrossBidAdapter:', function () { productId: PRODUCT_ID, test: 1 } - } + }; - expect(isBidRequestValid(validBid)).to.be.true; + expect(spec.isBidRequestValid(validBid)).to.be.true; }); - it('returns false when bidder not set to "33across"', function () { + it('returns false when bidder not set to "33across"', function() { const invalidBid = { bidder: 'foo', params: { siteId: SITE_ID, productId: PRODUCT_ID } - } + }; - expect(isBidRequestValid(invalidBid)).to.be.false; + expect(spec.isBidRequestValid(invalidBid)).to.be.false; }); it('returns false when params not set', function() { const invalidBid = { bidder: 'foo' - } + }; - expect(isBidRequestValid(invalidBid)).to.be.false; + expect(spec.isBidRequestValid(invalidBid)).to.be.false; }); it('returns false when site ID is not set in params', function() { @@ -94,9 +244,9 @@ describe('33acrossBidAdapter:', function () { params: { productId: PRODUCT_ID } - } + }; - expect(isBidRequestValid(invalidBid)).to.be.false; + expect(spec.isBidRequestValid(invalidBid)).to.be.false; }); it('returns false when product ID not set in params', function() { @@ -105,198 +255,214 @@ describe('33acrossBidAdapter:', function () { params: { siteId: SITE_ID } - } + }; - expect(isBidRequestValid(invalidBid)).to.be.false; + expect(spec.isBidRequestValid(invalidBid)).to.be.false; }); }); describe('buildRequests:', function() { - it('returns corresponding server requests for each valid bidRequest', function() { - const ttxRequest = { - imp: [ { - banner: { - format: [ - { - w: 300, - h: 250, - ext: {} - }, - { - w: 728, - h: 90, - ext: {} - } - ] - }, - ext: { - ttx: { - prod: PRODUCT_ID - } - } - } ], - site: { - id: SITE_ID - }, - id: 'b1' - }; - const serverRequest = { - 'method': 'POST', - 'url': END_POINT, - 'data': JSON.stringify(ttxRequest), - 'options': { - 'contentType': 'text/plain', - 'withCredentials': true - } - } - const builtServerRequests = buildRequests(this.bidRequests); - expect(builtServerRequests).to.deep.equal([ serverRequest ]); - expect(builtServerRequests.length).to.equal(1); + context('when element is fully in view', function() { + it('returns 100', function() { + const ttxRequest = new TtxRequestBuilder() + .withViewabiliuty({amount: 100}) + .build(); + const serverRequest = new ServerRequestBuilder() + .withData(ttxRequest) + .build(); + + Object.assign(element, { width: 600, height: 400 }); + + expect(spec.buildRequests(bidRequests)).to.deep.equal([ serverRequest ]); + }); }); - it('returns corresponding test server requests for each valid bidRequest', function() { - this.sandbox.stub(config, 'getConfig').callsFake(() => { - return { - 'url': 'https://foo.com/hb/' - } + context('when element is out of view', function() { + it('returns 0', function() { + const ttxRequest = new TtxRequestBuilder() + .withViewabiliuty({amount: 0}) + .build(); + const serverRequest = new ServerRequestBuilder() + .withData(ttxRequest) + .build(); + + Object.assign(element, { x: -300, y: 0, width: 207, height: 320 }); + + expect(spec.buildRequests(bidRequests)).to.deep.equal([ serverRequest ]); }); + }); - const ttxRequest = { - imp: [ { - banner: { - format: [ - { - w: 300, - h: 250, - ext: { } - }, - { - w: 728, - h: 90, - ext: { } - } - ] - }, - ext: { - ttx: { - prod: PRODUCT_ID - } - } - } ], - site: { - id: SITE_ID - }, - id: 'b1' - }; - const serverRequest = { - method: 'POST', - url: 'https://foo.com/hb/', - data: JSON.stringify(ttxRequest), - options: { - contentType: 'text/plain', - withCredentials: true - } - }; + context('when element is partially in view', function() { + it('returns percentage', function() { + const ttxRequest = new TtxRequestBuilder() + .withViewabiliuty({amount: 75}) + .build(); + const serverRequest = new ServerRequestBuilder() + .withData(ttxRequest) + .build(); + + Object.assign(element, { width: 800, height: 800 }); - const builtServerRequests = buildRequests(this.bidRequests); - expect(builtServerRequests).to.deep.equal([ serverRequest ]); - expect(builtServerRequests.length).to.equal(1); + expect(spec.buildRequests(bidRequests)).to.deep.equal([ serverRequest ]); + }); }); - it('returns corresponding test server requests for each valid bidRequest', function() { - this.sandbox.stub(config, 'getConfig').callsFake(() => { - return { - 'url': 'https://foo.com/hb/' - } + context('when width or height of the element is zero', function() { + it('try to use alternative values', function() { + const ttxRequest = new TtxRequestBuilder() + .withSizes([{ w: 800, h: 2400, ext: {} }]) + .withViewabiliuty({amount: 25}) + .build(); + const serverRequest = new ServerRequestBuilder() + .withData(ttxRequest) + .build(); + + Object.assign(element, { width: 0, height: 0 }); + bidRequests[0].sizes = [[800, 2400]]; + + expect(spec.buildRequests(bidRequests)).to.deep.equal([ serverRequest ]); }); - this.bidRequests[0].params.test = 1; - const ttxRequest = { - imp: [ { - banner: { - format: [ - { - w: 300, - h: 250, - ext: { } - }, - { - w: 728, - h: 90, - ext: { } - } - ] - }, - ext: { - ttx: { - prod: PRODUCT_ID - } + }); + + context('when nested iframes', function() { + it('returns \'nm\'', function() { + const ttxRequest = new TtxRequestBuilder() + .withViewabiliuty({amount: spec.NON_MEASURABLE}) + .build(); + const serverRequest = new ServerRequestBuilder() + .withData(ttxRequest) + .build(); + + Object.assign(element, { width: 600, height: 400 }); + + utils.getWindowTop.restore(); + utils.getWindowSelf.restore(); + sandbox.stub(utils, 'getWindowTop').returns(win); + sandbox.stub(utils, 'getWindowSelf').returns({}); + + expect(spec.buildRequests(bidRequests)).to.deep.equal([ serverRequest ]); + }); + }); + + context('when tab is inactive', function() { + it('returns 0', function() { + const ttxRequest = new TtxRequestBuilder() + .withViewabiliuty({amount: 0}) + .build(); + const serverRequest = new ServerRequestBuilder() + .withData(ttxRequest) + .build(); + + Object.assign(element, { width: 600, height: 400 }); + + utils.getWindowTop.restore(); + win.document.visibilityState = 'hidden'; + sandbox.stub(utils, 'getWindowTop').returns(win); + + expect(spec.buildRequests(bidRequests)).to.deep.equal([ serverRequest ]); + }); + }); + + context('when gdpr consent data exists', function() { + let bidderRequest; + + beforeEach(function() { + bidderRequest = { + gdprConsent: { + consentString: 'foobarMyPreference', + gdprApplies: true } - } ], - site: { - id: SITE_ID - }, - id: 'b1', - test: 1 - }; - const serverRequest = { - method: 'POST', - url: 'https://foo.com/hb/', - data: JSON.stringify(ttxRequest), - options: { - contentType: 'text/plain', - withCredentials: true } - }; + }); + + it('returns corresponding server requests with gdpr consent data', function() { + const ttxRequest = new TtxRequestBuilder() + .withGdprConsent('foobarMyPreference', 1) + .build(); + const serverRequest = new ServerRequestBuilder() + .withData(ttxRequest) + .build(); + const builtServerRequests = spec.buildRequests(bidRequests, bidderRequest); + + expect(builtServerRequests).to.deep.equal([serverRequest]); + }); - const builtServerRequests = buildRequests(this.bidRequests); - expect(builtServerRequests).to.deep.equal([ serverRequest ]); - expect(builtServerRequests.length).to.equal(1); + it('returns corresponding test server requests with gdpr consent data', function() { + sandbox.stub(config, 'getConfig').callsFake(() => { + return { + 'url': 'https://foo.com/hb/' + } + }); + + const ttxRequest = new TtxRequestBuilder() + .withGdprConsent('foobarMyPreference', 1) + .build(); + const serverRequest = new ServerRequestBuilder() + .withData(ttxRequest) + .withUrl('https://foo.com/hb/') + .build(); + const builtServerRequests = spec.buildRequests(bidRequests, bidderRequest); + + expect(builtServerRequests).to.deep.equal([serverRequest]); + }); }); - afterEach(function() { - delete this.bidRequests; - }) + context('when gdpr consent data does not exist', function() { + let bidderRequest; + + beforeEach(function() { + bidderRequest = {}; + }); + + it('returns corresponding server requests with default gdpr consent data', function() { + const ttxRequest = new TtxRequestBuilder() + .build(); + const serverRequest = new ServerRequestBuilder() + .withData(ttxRequest) + .build(); + const builtServerRequests = spec.buildRequests(bidRequests, bidderRequest); + + expect(builtServerRequests).to.deep.equal([serverRequest]); + }); + + it('returns corresponding test server requests with default gdpr consent data', function() { + sandbox.stub(config, 'getConfig').callsFake(() => { + return { + 'url': 'https://foo.com/hb/' + } + }); + + const ttxRequest = new TtxRequestBuilder() + .build(); + const serverRequest = new ServerRequestBuilder() + .withData(ttxRequest) + .withUrl('https://foo.com/hb/') + .build(); + const builtServerRequests = spec.buildRequests(bidRequests, bidderRequest); + + expect(builtServerRequests).to.deep.equal([serverRequest]); + }); + }); }); describe('interpretResponse', function() { + let ttxRequest, serverRequest; + beforeEach(function() { - this.ttxRequest = { - imp: [ { - banner: { - format: [ - { - w: 300, - h: 250, - ext: {} - }, - { - w: 728, - h: 90, - ext: {} - } - ] - }, - ext: { - ttx: { - prod: PRODUCT_ID - } - } - } ], - site: { + ttxRequest = new TtxRequestBuilder() + .withSite({ id: SITE_ID, page: 'http://test-url.com' - }, - id: 'b1' - }; - this.serverRequest = { - method: 'POST', - url: '//staging-ssc.33across.com/api/v1/hb', - data: JSON.stringify(this.ttxRequest), - options: { + }) + .build(); + serverRequest = new ServerRequestBuilder() + .withUrl('//staging-ssc.33across.com/api/v1/hb') + .withData(ttxRequest) + .withOptions({ contentType: 'text/plain', withCredentials: false - } - }; + }) + .build(); }); context('when exactly one bid is returned', function() { @@ -307,18 +473,17 @@ describe('33acrossBidAdapter:', function () { id: 'b1', seatbid: [ { - bid: [ { + bid: [{ id: '1', adm: '

I am an ad

', crid: 1, h: 250, w: 300, price: 0.0938 - } ] + }] } ] }; - const bidResponse = { requestId: 'b1', bidderCode: BIDDER_CODE, @@ -330,9 +495,9 @@ describe('33acrossBidAdapter:', function () { creativeId: 1, currency: 'USD', netRevenue: true - } + }; - expect(interpretResponse({ body: serverResponse }, this.serverRequest)).to.deep.equal([ bidResponse ]); + expect(spec.interpretResponse({ body: serverResponse }, serverRequest)).to.deep.equal([bidResponse]); }); }); @@ -345,7 +510,7 @@ describe('33acrossBidAdapter:', function () { seatbid: [] }; - expect(interpretResponse({ body: serverResponse }, this.serverRequest)).to.deep.equal([]); + expect(spec.interpretResponse({ body: serverResponse }, serverRequest)).to.deep.equal([]); }); }); @@ -357,7 +522,7 @@ describe('33acrossBidAdapter:', function () { id: 'b1', seatbid: [ { - bid: [ { + bid: [{ id: '1', adm: '

I am an ad

', crid: 1, @@ -376,18 +541,17 @@ describe('33acrossBidAdapter:', function () { ] }, { - bid: [ { + bid: [{ id: '3', adm: '

I am an ad

', crid: 3, h: 250, w: 300, price: 0.0938 - } ] + }] } ] }; - const bidResponse = { requestId: 'b1', bidderCode: BIDDER_CODE, @@ -401,14 +565,16 @@ describe('33acrossBidAdapter:', function () { netRevenue: true }; - expect(interpretResponse({ body: serverResponse }, this.serverRequest)).to.deep.equal([ bidResponse ]); + expect(spec.interpretResponse({ body: serverResponse }, serverRequest)).to.deep.equal([bidResponse]); }); }); }); describe('getUserSyncs', function() { + let syncs; + beforeEach(function() { - this.syncs = [ + syncs = [ { type: 'iframe', url: 'https://de.tynt.com/deb/v2?m=xch&rt=html&id=id1' @@ -418,7 +584,7 @@ describe('33acrossBidAdapter:', function () { url: 'https://de.tynt.com/deb/v2?m=xch&rt=html&id=id2' }, ]; - this.bidRequests = [ + bidRequests = [ { bidId: 'b1', bidder: '33across', @@ -430,7 +596,7 @@ describe('33acrossBidAdapter:', function () { adUnitCode: 'div-id', auctionId: 'r1', sizes: [ - [ 300, 250 ] + [300, 250] ], transactionId: 't1' }, @@ -445,30 +611,80 @@ describe('33acrossBidAdapter:', function () { adUnitCode: 'div-id', auctionId: 'r1', sizes: [ - [ 300, 250 ] + [300, 250] ], transactionId: 't2' } ]; }); - context('when iframe is not enabled', function() { - it('returns empty sync array', function() { - const syncOptions = {}; - buildRequests(this.bidRequests); - expect(getUserSyncs(syncOptions)).to.deep.equal([]); + context('when gdpr does not apply', function() { + let gdprConsent; + + beforeEach(function() { + gdprConsent = { + gdprApplies: false + }; + }); + + context('when iframe is not enabled', function() { + it('returns empty sync array', function() { + const syncOptions = {}; + + spec.buildRequests(bidRequests); + + expect(spec.getUserSyncs(syncOptions, {}, gdprConsent)).to.deep.equal([]); + }); + }); + + context('when iframe is enabled', function() { + it('returns sync array equal to number of unique siteIDs', function() { + const syncOptions = { + iframeEnabled: true + }; + + spec.buildRequests(bidRequests); + + expect(spec.getUserSyncs(syncOptions, {}, gdprConsent)).to.deep.equal(syncs); + }); }); }); - context('when iframe is enabled', function() { - it('returns sync array equal to number of unique siteIDs', function() { - const syncOptions = { - iframeEnabled: true - }; - buildRequests(this.bidRequests); - const syncs = getUserSyncs(syncOptions); - expect(syncs).to.deep.equal(this.syncs); + context('when consent data is not defined', function() { + context('when iframe is not enabled', function() { + it('returns empty sync array', function() { + const syncOptions = {}; + + spec.buildRequests(bidRequests); + + expect(spec.getUserSyncs(syncOptions)).to.deep.equal([]); + }); + }); + + context('when iframe is enabled', function() { + it('returns sync array equal to number of unique siteIDs', function() { + const syncOptions = { + iframeEnabled: true + }; + + spec.buildRequests(bidRequests); + + expect(spec.getUserSyncs(syncOptions)).to.deep.equal(syncs); + }); }); }); + + context('when gdpr applies', function() { + it('returns empty sync array', function() { + const syncOptions = {}; + const gdprConsent = { + gdprApplies: true + }; + + spec.buildRequests(bidRequests); + + expect(spec.getUserSyncs(syncOptions, {}, gdprConsent)).to.deep.equal([]); + }); + }) }); }); diff --git a/test/spec/modules/a4gBidAdapter_spec.js b/test/spec/modules/a4gBidAdapter_spec.js index 84346a1149f..4c7520d3b0c 100644 --- a/test/spec/modules/a4gBidAdapter_spec.js +++ b/test/spec/modules/a4gBidAdapter_spec.js @@ -1,9 +1,9 @@ import { expect } from 'chai'; import { spec } from 'modules/a4gBidAdapter'; -describe('a4gAdapterTests', () => { - describe('bidRequestValidity', () => { - it('bidRequest with zoneId and deliveryUrl params', () => { +describe('a4gAdapterTests', function () { + describe('bidRequestValidity', function () { + it('bidRequest with zoneId and deliveryUrl params', function () { expect(spec.isBidRequestValid({ bidder: 'a4g', params: { @@ -13,7 +13,7 @@ describe('a4gAdapterTests', () => { })).to.equal(true); }); - it('bidRequest with only zoneId', () => { + it('bidRequest with only zoneId', function () { expect(spec.isBidRequestValid({ bidder: 'a4g', params: { @@ -22,7 +22,7 @@ describe('a4gAdapterTests', () => { })).to.equal(true); }); - it('bidRequest with only deliveryUrl', () => { + it('bidRequest with only deliveryUrl', function () { expect(spec.isBidRequestValid({ bidder: 'a4g', params: { @@ -32,7 +32,7 @@ describe('a4gAdapterTests', () => { }); }); - describe('bidRequest', () => { + describe('bidRequest', function () { const bidRequests = [{ 'bidder': 'a4g', 'bidId': '51ef8751f9aead', @@ -58,27 +58,27 @@ describe('a4gAdapterTests', () => { 'auctionId': '18fd8b8b0bd757' }]; - it('bidRequest method', () => { + it('bidRequest method', function () { const request = spec.buildRequests(bidRequests); expect(request.method).to.equal('GET'); }); - it('bidRequest url', () => { + it('bidRequest url', function () { const request = spec.buildRequests(bidRequests); expect(request.url).to.match(new RegExp(`${bidRequests[1].params.deliveryUrl}`)); }); - it('bidRequest data', () => { + it('bidRequest data', function () { const request = spec.buildRequests(bidRequests); expect(request.data).to.exists; }); - it('bidRequest zoneIds', () => { + it('bidRequest zoneIds', function () { const request = spec.buildRequests(bidRequests); expect(request.data.zoneId).to.equal('59304;59354'); }); - it('bidRequest gdpr consent', () => { + it('bidRequest gdpr consent', function () { const consentString = 'consentString'; const bidderRequest = { bidderCode: 'a4g', @@ -99,7 +99,7 @@ describe('a4gAdapterTests', () => { }); }); - describe('interpretResponse', () => { + describe('interpretResponse', function () { const bidRequest = [{ 'bidder': 'a4g', 'bidId': '51ef8751f9aead', @@ -124,7 +124,7 @@ describe('a4gAdapterTests', () => { headers: {} }; - it('required keys', () => { + it('required keys', function () { const result = spec.interpretResponse(bidResponse, bidRequest); let requiredKeys = [ diff --git a/test/spec/modules/aardvarkBidAdapter_spec.js b/test/spec/modules/aardvarkBidAdapter_spec.js index 6d4649ea107..628f19f8fd2 100644 --- a/test/spec/modules/aardvarkBidAdapter_spec.js +++ b/test/spec/modules/aardvarkBidAdapter_spec.js @@ -1,9 +1,9 @@ import { expect } from 'chai'; import { spec } from 'modules/aardvarkBidAdapter'; -describe('aardvarkAdapterTest', () => { - describe('forming valid bidRequests', () => { - it('should accept valid bidRequests', () => { +describe('aardvarkAdapterTest', function () { + describe('forming valid bidRequests', function () { + it('should accept valid bidRequests', function () { expect(spec.isBidRequestValid({ bidder: 'aardvark', params: { @@ -14,7 +14,7 @@ describe('aardvarkAdapterTest', () => { })).to.equal(true); }); - it('should reject invalid bidRequests', () => { + it('should reject invalid bidRequests', function () { expect(spec.isBidRequestValid({ bidder: 'aardvark', params: { @@ -25,7 +25,7 @@ describe('aardvarkAdapterTest', () => { }); }); - describe('executing network requests', () => { + describe('executing network requests', function () { const bidRequests = [{ bidder: 'aardvark', params: { @@ -54,20 +54,20 @@ describe('aardvarkAdapterTest', () => { auctionId: 'e97cafd0-ebfc-4f5c-b7c9-baa0fd335a4a' }]; - it('should use HTTP GET method', () => { + it('should use HTTP GET method', function () { const requests = spec.buildRequests(bidRequests); requests.forEach(function(requestItem) { expect(requestItem.method).to.equal('GET'); }); }); - it('should call the correct bidRequest url', () => { + it('should call the correct bidRequest url', function () { const requests = spec.buildRequests(bidRequests); expect(requests.length).to.equal(1); expect(requests[0].url).to.match(new RegExp('^\/\/adzone.pub.com/xiby/TdAx_RAZd/aardvark\?')); }); - it('should have correct data', () => { + it('should have correct data', function () { const requests = spec.buildRequests(bidRequests); expect(requests.length).to.equal(1); expect(requests[0].data.version).to.equal(1); @@ -78,7 +78,7 @@ describe('aardvarkAdapterTest', () => { }); }); - describe('splitting multi-auction ad units into own requests', () => { + describe('splitting multi-auction ad units into own requests', function () { const bidRequests = [{ bidder: 'aardvark', params: { @@ -108,21 +108,21 @@ describe('aardvarkAdapterTest', () => { auctionId: 'e97cafd0-ebfc-4f5c-b7c9-baa0fd335a4a' }]; - it('should use HTTP GET method', () => { + it('should use HTTP GET method', function () { const requests = spec.buildRequests(bidRequests); requests.forEach(function(requestItem) { expect(requestItem.method).to.equal('GET'); }); }); - it('should call the correct bidRequest urls for each auction', () => { + it('should call the correct bidRequest urls for each auction', function () { const requests = spec.buildRequests(bidRequests); expect(requests[0].url).to.match(new RegExp('^\/\/bidder.rtk.io/Toby/TdAx/aardvark\?')); expect(requests[0].data.categories.length).to.equal(2); expect(requests[1].url).to.match(new RegExp('^\/\/adzone.pub.com/xiby/RAZd/aardvark\?')); }); - it('should have correct data', () => { + it('should have correct data', function () { const requests = spec.buildRequests(bidRequests); expect(requests.length).to.equal(2); expect(requests[0].data.version).to.equal(1); @@ -138,7 +138,7 @@ describe('aardvarkAdapterTest', () => { }); }); - describe('GDPR conformity', () => { + describe('GDPR conformity', function () { const bidRequests = [{ bidder: 'aardvark', params: { @@ -160,7 +160,7 @@ describe('aardvarkAdapterTest', () => { } }; - it('should transmit correct data', () => { + it('should transmit correct data', function () { const requests = spec.buildRequests(bidRequests, bidderRequest); expect(requests.length).to.equal(1); expect(requests[0].data.gdpr).to.equal(true); @@ -168,7 +168,7 @@ describe('aardvarkAdapterTest', () => { }); }); - describe('GDPR absence conformity', () => { + describe('GDPR absence conformity', function () { const bidRequests = [{ bidder: 'aardvark', params: { @@ -187,7 +187,7 @@ describe('aardvarkAdapterTest', () => { gdprConsent: undefined }; - it('should transmit correct data', () => { + it('should transmit correct data', function () { const requests = spec.buildRequests(bidRequests, bidderRequest); expect(requests.length).to.equal(1); expect(requests[0].data.gdpr).to.be.undefined; @@ -195,8 +195,8 @@ describe('aardvarkAdapterTest', () => { }); }); - describe('interpretResponse', () => { - it('should handle bid responses', () => { + describe('interpretResponse', function () { + it('should handle bid responses', function () { const serverResponse = { body: [ { @@ -245,7 +245,7 @@ describe('aardvarkAdapterTest', () => { expect(result[1].ad).to.not.be.undefined; }); - it('should handle nobid responses', () => { + it('should handle nobid responses', function () { var emptyResponse = [{ nurl: '', cid: '9e5a09319e18f1', diff --git a/test/spec/modules/adagioBidAdapter_spec.js b/test/spec/modules/adagioBidAdapter_spec.js new file mode 100644 index 00000000000..7437b45b6c1 --- /dev/null +++ b/test/spec/modules/adagioBidAdapter_spec.js @@ -0,0 +1,273 @@ +import { expect } from 'chai'; +import { newBidder } from 'src/adapters/bidderFactory'; +import { spec } from 'modules/adagioBidAdapter'; + +describe('adagioAdapter', () => { + const adapter = newBidder(spec); + const ENDPOINT = 'https://mp.4dex.io/prebid'; + + describe('inherited functions', () => { + it('exists and is a function', () => { + expect(adapter.callBids).to.exist.and.to.be.a('function'); + }); + }); + + describe('isBidRequestValid', () => { + let bid = { + 'bidder': 'adagio', + 'params': { + siteId: '123', + placementId: 4, + categories: ['IAB12', 'IAB12-2'] + }, + 'adUnitCode': 'adunit-code', + 'sizes': [[300, 250], [300, 600]], + 'bidId': 'c180kg4267tyqz', + 'bidderRequestId': '8vfscuixrovn8i', + 'auctionId': 'lel4fhp239i9km', + }; + + it('should return true when required params found', () => { + expect(spec.isBidRequestValid(bid)).to.equal(true); + }); + + it('should return false when site params is not passed', () => { + let bidTest = Object.assign({}, bid); + delete bidTest.params.siteId; + expect(spec.isBidRequestValid(bidTest)).to.equal(false); + }); + + it('should return false when placement params is not passed', () => { + let bidTest = Object.assign({}, bid); + delete bidTest.params.placementId; + expect(spec.isBidRequestValid(bidTest)).to.equal(false); + }); + }); + + describe('buildRequests', () => { + let bidRequests = [ + // siteId 123 + { + 'bidder': 'adagio', + 'params': { + siteId: '123', + placementId: 4, + pagetypeId: '232', + categories: ['IAB12'] + }, + 'adUnitCode': 'adunit-code1', + 'sizes': [[300, 250], [300, 600]], + 'bidId': 'c180kg4267tyqz', + 'bidderRequestId': '8vfscuixrovn8i', + 'auctionId': 'lel4fhp239i9km', + }, + { + 'bidder': 'adagio', + 'params': { + siteId: '123', + placementId: 3, + pagetypeId: '232', + categories: ['IAB12'] + }, + 'adUnitCode': 'adunit-code2', + 'sizes': [[300, 250], [300, 600]], + 'bidId': 'c180kg4267tyqz', + 'bidderRequestId': '8vfscuixrovn8i', + 'auctionId': 'lel4fhp239i9km', + }, + // siteId 456 + { + 'bidder': 'adagio', + 'params': { + siteId: '456', + placementId: 4, + pagetypeId: '232', + categories: ['IAB12'] + }, + 'adUnitCode': 'adunit-code3', + 'sizes': [[300, 250], [300, 600]], + 'bidId': 'c180kg4267tyqz', + 'bidderRequestId': '8vfscuixrovn8i', + 'auctionId': 'lel4fhp239i9km', + } + ]; + + let consentString = 'theConsentString'; + let bidderRequest = { + 'bidderCode': 'adagio', + 'auctionId': '12jejebn', + 'bidderRequestId': 'hehehehbeheh', + 'timeout': 3000, + 'gdprConsent': { + consentString: consentString, + gdprApplies: true, + allowAuctionWithoutConsent: true + } + }; + + it('groups requests by siteId', () => { + const requests = spec.buildRequests(bidRequests); + expect(requests).to.have.lengthOf(2); + + expect(requests[0].data.siteId).to.equal('123'); + expect(requests[0].data.adUnits).to.have.lengthOf(2); + + expect(requests[1].data.siteId).to.equal('456'); + expect(requests[1].data.adUnits).to.have.lengthOf(1); + }); + + it('sends bid request to ENDPOINT_PB via POST', () => { + const requests = spec.buildRequests(bidRequests); + expect(requests).to.have.lengthOf(2); + const request = requests[0]; + expect(request.method).to.equal('POST'); + expect(request.url).to.equal(ENDPOINT); + }); + + it('features params must be an empty object if featurejs is not loaded', () => { + const requests = spec.buildRequests(bidRequests); + expect(requests).to.have.lengthOf(2); + const request = requests[0]; + const expected = {}; + expect(request.data.adUnits[0].params.features).to.deep.equal(expected); + }); + + it('GDPR consent is applied', () => { + const requests = spec.buildRequests(bidRequests, bidderRequest); + expect(requests).to.have.lengthOf(2); + const request = requests[0]; + expect(request.data.gdpr).to.exist; + expect(request.data.gdpr.consentString).to.exist.and.to.equal(consentString); + expect(request.data.gdpr.consentRequired).to.exist.and.to.equal(1); + }); + + it('GDPR consent is not applied', () => { + bidderRequest.gdprConsent.gdprApplies = false; + const requests = spec.buildRequests(bidRequests, bidderRequest); + expect(requests).to.have.lengthOf(2); + const request = requests[0]; + expect(request.data.gdpr).to.exist; + expect(request.data.gdpr.consentString).to.exist.and.to.equal(consentString); + expect(request.data.gdpr.consentRequired).to.exist.and.to.equal(0); + }); + + it('GDPR consent is undefined', () => { + delete bidderRequest.gdprConsent.consentString; + delete bidderRequest.gdprConsent.gdprApplies; + delete bidderRequest.gdprConsent.allowAuctionWithoutConsent; + const requests = spec.buildRequests(bidRequests, bidderRequest); + expect(requests).to.have.lengthOf(2); + const request = requests[0]; + expect(request.data.gdpr).to.exist; + expect(request.data.gdpr).to.not.have.property('consentString'); + expect(request.data.gdpr).to.not.have.property('gdprApplies'); + expect(request.data.gdpr).to.not.have.property('allowAuctionWithoutConsent'); + }); + + it('GDPR consent bidderRequest does not have gdprConsent', () => { + delete bidderRequest.gdprConsent; + const requests = spec.buildRequests(bidRequests, bidderRequest); + expect(requests).to.have.lengthOf(2); + const request = requests[0]; + expect(request.data.gdpr).to.exist; + expect(request.data.gdpr).to.be.empty; + }); + }); + + describe('interpretResponse', () => { + let serverResponse = { + body: { + bids: [ + { + ad: '
', + cpm: 1, + creativeId: 'creativeId', + currency: 'EUR', + height: 250, + netRevenue: true, + requestId: 'c180kg4267tyqz', + ttl: 360, + width: 300 + } + ] + } + }; + + let bidRequest = { + 'data': { + 'adUnits': [ + { + 'bidder': 'adagio', + 'params': { + siteId: '666', + placementId: 4, + pagetypeId: '232', + categories: ['IAB12'] + }, + 'adUnitCode': 'adunit-code', + 'sizes': [[300, 250], [300, 600]], + 'bidId': 'c180kg4267tyqz', + 'bidderRequestId': '8vfscuixrovn8i', + 'auctionId': 'lel4fhp239i9km', + } + ] + } + }; + + it('should get correct bid response', () => { + let expectedResponse = [{ + ad: '
', + cpm: 1, + creativeId: 'creativeId', + currency: 'EUR', + height: 250, + netRevenue: true, + requestId: 'c180kg4267tyqz', + ttl: 360, + width: 300, + categories: [], + pagetypeId: '232', + placementId: 4, + }]; + expect(spec.interpretResponse(serverResponse, bidRequest)).to.be.an('array'); + expect(spec.interpretResponse(serverResponse, bidRequest)).to.deep.equal(expectedResponse); + }); + }); + + describe('getUserSyncs', () => { + const syncOptions = { + 'iframeEnabled': 'true' + } + const serverResponses = [ + { + body: { + userSyncs: [ + { + t: 'i', + u: 'https://test.url.com/setuid' + }, + { + t: 'p', + u: 'https://test.url.com/setuid' + } + ] + } + } + ]; + + const emptyServerResponses = [ + { + body: '' + } + ]; + + it('should handle correctly user syncs', () => { + let result = spec.getUserSyncs(syncOptions, serverResponses); + let emptyResult = spec.getUserSyncs(syncOptions, emptyServerResponses); + expect(result[0].type).to.equal('iframe'); + expect(result[0].url).contain('setuid'); + expect(result[1].type).to.equal('image'); + expect(emptyResult).to.equal(false); + }); + }); +}); diff --git a/test/spec/modules/adbutlerBidAdapter_spec.js b/test/spec/modules/adbutlerBidAdapter_spec.js index a46039402e6..cf6b52f70e5 100644 --- a/test/spec/modules/adbutlerBidAdapter_spec.js +++ b/test/spec/modules/adbutlerBidAdapter_spec.js @@ -1,10 +1,10 @@ import {expect} from 'chai'; import {spec} from 'modules/adbutlerBidAdapter'; -describe('AdButler adapter', () => { +describe('AdButler adapter', function () { let bidRequests; - beforeEach(() => { + beforeEach(function () { bidRequests = [ { bidder: 'adbutler', @@ -25,9 +25,9 @@ describe('AdButler adapter', () => { ]; }); - describe('implementation', () => { - describe('for requests', () => { - it('should accept valid bid', () => { + describe('implementation', function () { + describe('for requests', function () { + it('should accept valid bid', function () { let validBid = { bidder: 'adbutler', params: { @@ -40,7 +40,7 @@ describe('AdButler adapter', () => { expect(isValid).to.equal(true); }); - it('should reject invalid bid', () => { + it('should reject invalid bid', function () { let invalidBid = { bidder: 'adbutler', params: { @@ -52,7 +52,7 @@ describe('AdButler adapter', () => { expect(isValid).to.equal(false); }); - it('should use custom domain string', () => { + it('should use custom domain string', function () { let bidRequests = [ { bidId: '3c9408cdbf2f68', @@ -73,7 +73,7 @@ describe('AdButler adapter', () => { expect(requestURL).to.have.string('.dan.test'); }); - it('should set default domain', () => { + it('should set default domain', function () { let requests = spec.buildRequests(bidRequests), request = requests[0]; @@ -82,14 +82,14 @@ describe('AdButler adapter', () => { expect(domain).to.equal('http://servedbyadbutler.com'); }); - it('should set the keyword parameter', () => { + it('should set the keyword parameter', function () { let requests = spec.buildRequests(bidRequests), requestURL = requests[0].url; expect(requestURL).to.have.string(';kw=red;'); }); - it('should increment the count for the same zone', () => { + it('should increment the count for the same zone', function () { let bidRequests = [ { sizes: [[300, 250]], @@ -118,8 +118,8 @@ describe('AdButler adapter', () => { }); }); - describe('bid responses', () => { - it('should return complete bid response', () => { + describe('bid responses', function () { + it('should return complete bid response', function () { let serverResponse = { body: { status: 'SUCCESS', @@ -149,7 +149,7 @@ describe('AdButler adapter', () => { expect(bids[0].ad).to.have.string('http://tracking.pixel.com/params=info'); }); - it('should return empty bid response', () => { + it('should return empty bid response', function () { let serverResponse = { status: 'NO_ELIGIBLE_ADS', zone_id: 210083, @@ -162,7 +162,7 @@ describe('AdButler adapter', () => { expect(bids).to.be.lengthOf(0); }); - it('should return empty bid response on incorrect size', () => { + it('should return empty bid response on incorrect size', function () { let serverResponse = { status: 'SUCCESS', account_id: 167283, @@ -177,7 +177,7 @@ describe('AdButler adapter', () => { expect(bids).to.be.lengthOf(0); }); - it('should return empty bid response with CPM too low', () => { + it('should return empty bid response with CPM too low', function () { let serverResponse = { status: 'SUCCESS', account_id: 167283, @@ -192,7 +192,7 @@ describe('AdButler adapter', () => { expect(bids).to.be.lengthOf(0); }); - it('should return empty bid response with CPM too high', () => { + it('should return empty bid response with CPM too high', function () { let serverResponse = { status: 'SUCCESS', account_id: 167283, diff --git a/test/spec/modules/adformBidAdapter_spec.js b/test/spec/modules/adformBidAdapter_spec.js index d888b4b7a5b..d3054794485 100644 --- a/test/spec/modules/adformBidAdapter_spec.js +++ b/test/spec/modules/adformBidAdapter_spec.js @@ -3,10 +3,10 @@ import * as url from 'src/url'; import {spec} from 'modules/adformBidAdapter'; import { BANNER, VIDEO } from 'src/mediaTypes'; -describe('Adform adapter', () => { +describe('Adform adapter', function () { let serverResponse, bidRequest, bidResponses; let bids = []; - describe('isBidRequestValid', () => { + describe('isBidRequestValid', function () { let bid = { 'bidder': 'adform', 'params': { @@ -14,11 +14,11 @@ describe('Adform adapter', () => { } }; - it('should return true when required params found', () => { + it('should return true when required params found', function () { assert(spec.isBidRequestValid(bid)); }); - it('should return false when required params are missing', () => { + it('should return false when required params are missing', function () { bid.params = { adxDomain: 'adx.adform.net' }; @@ -26,14 +26,14 @@ describe('Adform adapter', () => { }); }); - describe('buildRequests', () => { - it('should pass multiple bids via single request', () => { + describe('buildRequests', function () { + it('should pass multiple bids via single request', function () { let request = spec.buildRequests(bids); let parsedUrl = parseUrl(request.url); assert.lengthOf(parsedUrl.items, 7); }); - it('should handle global request parameters', () => { + it('should handle global request parameters', function () { let parsedUrl = parseUrl(spec.buildRequests([bids[0]]).url); let query = parsedUrl.query; @@ -45,12 +45,12 @@ describe('Adform adapter', () => { assert.equal(query.url, encodeURIComponent('some// there')); }); - it('should set correct request method', () => { + it('should set correct request method', function () { let request = spec.buildRequests([bids[0]]); assert.equal(request.method, 'GET'); }); - it('should correctly form bid items', () => { + it('should correctly form bid items', function () { let bidList = bids; let request = spec.buildRequests(bidList); let parsedUrl = parseUrl(request.url); @@ -93,13 +93,13 @@ describe('Adform adapter', () => { ]); }); - it('should not change original validBidRequests object', () => { + it('should not change original validBidRequests object', function () { var resultBids = JSON.parse(JSON.stringify(bids[0])); let request = spec.buildRequests([bids[0]]); assert.deepEqual(resultBids, bids[0]); }); - it('should set gross to the request, if there is any gross priceType', () => { + it('should set gross to the request, if there is any gross priceType', function () { let request = spec.buildRequests([bids[5], bids[5]]); let parsedUrl = parseUrl(request.url); @@ -111,8 +111,8 @@ describe('Adform adapter', () => { assert.equal(parsedUrl.query.pt, 'gross'); }); - describe('gdpr', () => { - it('should send GDPR Consent data to adform if gdprApplies', () => { + describe('gdpr', function () { + it('should send GDPR Consent data to adform if gdprApplies', function () { let resultBids = JSON.parse(JSON.stringify(bids[0])); let request = spec.buildRequests([bids[0]], {gdprConsent: {gdprApplies: true, consentString: 'concentDataString'}}); let parsedUrl = parseUrl(request.url).query; @@ -121,7 +121,7 @@ describe('Adform adapter', () => { assert.equal(parsedUrl.gdpr_consent, 'concentDataString'); }); - it('should not send GDPR Consent data to adform if gdprApplies is false or undefined', () => { + it('should not send GDPR Consent data to adform if gdprApplies is false or undefined', function () { let resultBids = JSON.parse(JSON.stringify(bids[0])); let request = spec.buildRequests([bids[0]], {gdprConsent: {gdprApplies: false, consentString: 'concentDataString'}}); let parsedUrl = parseUrl(request.url).query; @@ -134,7 +134,7 @@ describe('Adform adapter', () => { assert.ok(!parsedUrl.gdpr_consent); }); - it('should return GDPR Consent data with request data', () => { + it('should return GDPR Consent data with request data', function () { let request = spec.buildRequests([bids[0]], {gdprConsent: {gdprApplies: true, consentString: 'concentDataString'}}); assert.deepEqual(request.gdpr, { @@ -148,12 +148,12 @@ describe('Adform adapter', () => { }); }); - describe('interpretResponse', () => { - it('should respond with empty response when there is empty serverResponse', () => { + describe('interpretResponse', function () { + it('should respond with empty response when there is empty serverResponse', function () { let result = spec.interpretResponse({ body: {} }, {}); assert.deepEqual(result, []); }); - it('should respond with empty response when response from server is not banner', () => { + it('should respond with empty response when response from server is not banner', function () { serverResponse.body[0].response = 'not banner'; serverResponse.body = [serverResponse.body[0]]; bidRequest.bids = [bidRequest.bids[0]]; @@ -161,7 +161,7 @@ describe('Adform adapter', () => { assert.deepEqual(result, []); }); - it('should interpret server response correctly with one bid', () => { + it('should interpret server response correctly with one bid', function () { serverResponse.body = [serverResponse.body[0]]; bidRequest.bids = [bidRequest.bids[0]]; let result = spec.interpretResponse(serverResponse, bidRequest)[0]; @@ -180,7 +180,7 @@ describe('Adform adapter', () => { assert.equal(result.transactionId, '5f33781f-9552-4ca1'); }); - it('should set correct netRevenue', () => { + it('should set correct netRevenue', function () { serverResponse.body = [serverResponse.body[0]]; bidRequest.bids = [bidRequest.bids[1]]; bidRequest.netRevenue = 'gross'; @@ -189,22 +189,22 @@ describe('Adform adapter', () => { assert.equal(result.netRevenue, false); }); - it('should create bid response item for every requested item', () => { + it('should create bid response item for every requested item', function () { let result = spec.interpretResponse(serverResponse, bidRequest); assert.lengthOf(result, 5); }); - it('should create bid response with vast xml', () => { + it('should create bid response with vast xml', function () { const result = spec.interpretResponse(serverResponse, bidRequest)[3]; assert.equal(result.vastXml, ''); }); - it('should create bid response with vast url', () => { + it('should create bid response with vast url', function () { const result = spec.interpretResponse(serverResponse, bidRequest)[4]; assert.equal(result.vastUrl, 'vast://url'); }); - it('should set mediaType on bid response', () => { + it('should set mediaType on bid response', function () { const expected = [ BANNER, BANNER, BANNER, VIDEO, VIDEO ]; const result = spec.interpretResponse(serverResponse, bidRequest); for (let i = 0; i < result.length; i++) { @@ -212,7 +212,7 @@ describe('Adform adapter', () => { } }); - it('should set default netRevenue as gross', () => { + it('should set default netRevenue as gross', function () { bidRequest.netRevenue = 'gross'; const result = spec.interpretResponse(serverResponse, bidRequest); for (let i = 0; i < result.length; i++) { @@ -220,7 +220,7 @@ describe('Adform adapter', () => { } }); - it('should set gdpr if it exist in bidRequest', () => { + it('should set gdpr if it exist in bidRequest', function () { bidRequest.gdpr = { gdpr: true, gdpr_consent: 'ERW342EIOWT34234KMGds' @@ -239,8 +239,8 @@ describe('Adform adapter', () => { }; }); - describe('verifySizes', () => { - it('should respond with empty response when sizes doesn\'t match', () => { + describe('verifySizes', function () { + it('should respond with empty response when sizes doesn\'t match', function () { serverResponse.body[0].response = 'banner'; serverResponse.body[0].width = 100; serverResponse.body[0].height = 150; @@ -253,7 +253,7 @@ describe('Adform adapter', () => { assert.equal(serverResponse.body[0].response, 'banner'); assert.deepEqual(result, []); }); - it('should respond with empty response when sizes as a strings doesn\'t match', () => { + it('should respond with empty response when sizes as a strings doesn\'t match', function () { serverResponse.body[0].response = 'banner'; serverResponse.body[0].width = 100; serverResponse.body[0].height = 150; @@ -268,7 +268,7 @@ describe('Adform adapter', () => { assert.equal(serverResponse.body[0].response, 'banner'); assert.deepEqual(result, []); }); - it('should support size dimensions as a strings', () => { + it('should support size dimensions as a strings', function () { serverResponse.body[0].response = 'banner'; serverResponse.body[0].width = 300; serverResponse.body[0].height = 600; @@ -285,7 +285,7 @@ describe('Adform adapter', () => { }) }); - beforeEach(() => { + beforeEach(function () { let sizes = [[250, 300], [300, 250], [300, 600]]; let placementCode = ['div-01', 'div-02', 'div-03', 'div-04', 'div-05']; let params = [{ mid: 1, url: 'some// there' }, {adxDomain: null, mid: 2, someVar: 'someValue', pt: 'gross'}, { adxDomain: null, mid: 3, pdom: 'home' }, {mid: 5, pt: 'net'}, {mid: 6, pt: 'gross'}]; diff --git a/test/spec/modules/adformOpenRTBBidAdapter_spec.js b/test/spec/modules/adformOpenRTBBidAdapter_spec.js new file mode 100644 index 00000000000..5c0009ab1c7 --- /dev/null +++ b/test/spec/modules/adformOpenRTBBidAdapter_spec.js @@ -0,0 +1,473 @@ +// jshint esversion: 6, es3: false, node: true +import {assert, expect} from 'chai'; +import * as url from 'src/url'; +import {spec} from 'modules/adformOpenRTBBidAdapter'; +import { NATIVE } from 'src/mediaTypes'; + +describe('AdformOpenRTB adapter', function () { + let serverResponse, bidRequest, bidResponses; + let bids = []; + + describe('isBidRequestValid', function () { + let bid = { + 'bidder': 'adformOpenRTB', + 'params': { + 'mid': '19910113' + } + }; + + it('should return true when required params found', function () { + assert(spec.isBidRequestValid(bid)); + }); + + it('should return false when required params are missing', function () { + bid.params = { adxDomain: 'adx.adform.net' }; + assert.isFalse(spec.isBidRequestValid(bid)); + }); + }); + + describe('buildRequests', function () { + it('should send request with correct structure', function () { + let validBidRequests = [{ + bidId: 'bidId', + params: { + siteId: 'siteId', + adxDomain: '10.8.57.207' + } + }]; + let request = spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }); + + assert.equal(request.method, 'POST'); + assert.equal(request.url, '//10.8.57.207/adx/openrtb'); + assert.deepEqual(request.options, {contentType: 'application/json'}); + assert.ok(request.data); + }); + + describe('gdpr', function () { + it('should send GDPR Consent data to adform if gdprApplies', function () { + let validBidRequests = [{ bidId: 'bidId', params: { siteId: 'siteId', test: 1 } }]; + let bidderRequest = { gdprConsent: { gdprApplies: true, consentString: 'consentDataString' }, refererInfo: { referer: 'page' } }; + let request = JSON.parse(spec.buildRequests(validBidRequests, bidderRequest).data); + + assert.equal(request.user.ext.consent, bidderRequest.gdprConsent.consentString); + assert.equal(request.regs.ext.gdpr, bidderRequest.gdprConsent.gdprApplies); + assert.equal(typeof request.regs.ext.gdpr, 'number'); + }); + + it('should send gdpr as number', function () { + let validBidRequests = [{ bidId: 'bidId', params: { siteId: 'siteId', test: 1 } }]; + let bidderRequest = { gdprConsent: { gdprApplies: true, consentString: 'consentDataString' }, refererInfo: { referer: 'page' } }; + let request = JSON.parse(spec.buildRequests(validBidRequests, bidderRequest).data); + + assert.equal(typeof request.regs.ext.gdpr, 'number'); + }); + + it('should not send GDPR Consent data to adform if gdprApplies is false or undefined', function () { + let validBidRequests = [{ + bidId: 'bidId', + params: { siteId: 'siteId' } + }]; + let bidderRequest = {gdprConsent: {gdprApplies: false, consentString: 'consentDataString'}, refererInfo: { referer: 'page' }}; + let request = JSON.parse(spec.buildRequests(validBidRequests, bidderRequest).data); + + assert.equal(request.user, undefined); + assert.equal(request.regs, undefined); + }); + it('should send default GDPR Consent data to adform', function () { + let validBidRequests = [{ + bidId: 'bidId', + params: { siteId: 'siteId' } + }]; + let request = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data); + + assert.equal(request.user, undefined); + assert.equal(request.regs, undefined); + }); + }); + + it('should add test and is_debug to request, if test is set in parameters', function () { + let validBidRequests = [{ + bidId: 'bidId', + params: { siteId: 'siteId', test: 1 } + }]; + let request = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data); + + assert.ok(request.is_debug); + assert.equal(request.test, 1); + }); + + it('should have default request structure', function () { + let keys = 'site,device,source,ext,imp'.split(','); + let validBidRequests = [{ + bidId: 'bidId', + params: { siteId: 'siteId' } + }]; + let request = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data); + let data = Object.keys(request); + + assert.deepEqual(keys, data); + }); + + it('should set request keys correct values', function () { + let validBidRequests = [{ + bidId: 'bidId', + params: { siteId: 'siteId' }, + transactionId: 'transactionId' + }]; + let request = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data); + + assert.equal(request.source.tid, validBidRequests[0].transactionId); + assert.equal(request.source.fd, 1); + }); + + it('should send info about device', function () { + let validBidRequests = [{ + bidId: 'bidId', + params: { siteId: 'siteId' } + }]; + let request = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data); + + assert.equal(request.device.ua, navigator.userAgent); + }); + it('should send info about the site', function () { + let validBidRequests = [{ + bidId: 'bidId', + params: { siteId: 'siteId', publisher: {id: '123123', domain: 'publisher.domain.com', name: 'publisher\'s name'} } + }]; + let refererInfo = { referer: 'page' }; + let request = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo }).data); + + assert.deepEqual(request.site, { + page: refererInfo.referer, + publisher: validBidRequests[0].params.publisher, + id: validBidRequests[0].params.siteId + }); + }); + + describe('priceType', function () { + it('should send default priceType', function () { + let validBidRequests = [{ + bidId: 'bidId', + params: { siteId: 'siteId' } + }]; + let request = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data); + + assert.equal(request.ext.pt, 'net'); + }); + it('should send correct priceType value', function () { + let validBidRequests = [{ + bidId: 'bidId', + params: { siteId: 'siteId', priceType: 'net' } + }]; + let request = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data); + + assert.equal(request.ext.pt, 'net'); + }); + }); + + describe('bids', function () { + it('should add more than one bid to the request', function () { + let validBidRequests = [{ + bidId: 'bidId', + params: { siteId: 'siteId' } + }, { + bidId: 'bidId2', + params: { siteId: 'siteId' } + }]; + let request = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data); + + assert.equal(request.imp.length, 2); + }); + it('should add incrementing values of id', function () { + let validBidRequests = [{ + bidId: 'bidId', + params: { siteId: 'siteId' } + }, { + bidId: 'bidId2', + params: { siteId: 'siteId' } + }, { + bidId: 'bidId3', + params: { siteId: 'siteId' } + }]; + let imps = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data).imp; + + for (let i = 0; i < 3; i++) { + assert.equal(imps[i].id, i + 1); + } + }); + + it('should add mid', function () { + let validBidRequests = [{ bidId: 'bidId', params: { siteId: 'siteId', mid: 1000 } }, + { bidId: 'bidId2', params: { siteId: 'siteId', mid: 1001 } }, + { bidId: 'bidId3', params: { siteId: 'siteId', mid: 1002 } }]; + let imps = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data).imp; + for (let i = 0; i < 3; i++) { + assert.equal(imps[i].tagid, validBidRequests[i].params.mid); + } + }); + + describe('native', function () { + describe('assets', function () { + it('should set correct asset id', function () { + let validBidRequests = [{ + bidId: 'bidId', + params: { siteId: 'siteId', mid: 1000 }, + nativeParams: { + title: { required: true, len: 140 }, + image: { required: false, wmin: 836, hmin: 627, w: 325, h: 300, mimes: ['image/jpg', 'image/gif'] }, + body: { len: 140 } + } + }]; + let assets = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data).imp[0].native.request.assets; + + assert.equal(assets[0].id, 0); + assert.equal(assets[1].id, 3); + assert.equal(assets[2].id, 4); + }); + it('should add required key if it is necessary', function () { + let validBidRequests = [{ + bidId: 'bidId', + params: { siteId: 'siteId', mid: 1000 }, + nativeParams: { + title: { required: true, len: 140 }, + image: { required: false, wmin: 836, hmin: 627, w: 325, h: 300, mimes: ['image/jpg', 'image/gif'] }, + body: { len: 140 }, + sponsoredBy: { required: true, len: 140 } + } + }]; + + let assets = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data).imp[0].native.request.assets; + + assert.equal(assets[0].required, 1); + assert.ok(!assets[1].required); + assert.ok(!assets[2].required); + assert.equal(assets[3].required, 1); + }); + + it('should map img and data assets', function () { + let validBidRequests = [{ + bidId: 'bidId', + params: { siteId: 'siteId', mid: 1000 }, + nativeParams: { + title: { required: true, len: 140 }, + image: { required: true, sizes: [150, 50] }, + icon: { required: false, sizes: [50, 50] }, + body: { required: false, len: 140 }, + sponsoredBy: { required: true }, + cta: { required: false }, + clickUrl: { required: false } + } + }]; + + let assets = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data).imp[0].native.request.assets; + assert.ok(assets[0].title); + assert.equal(assets[0].title.len, 140); + assert.deepEqual(assets[1].img, { type: 3, wmin: 150, hmin: 50 }); + assert.deepEqual(assets[2].img, { type: 1, wmin: 50, hmin: 50 }); + assert.deepEqual(assets[3].data, { type: 2, len: 140 }); + assert.deepEqual(assets[4].data, { type: 1 }); + assert.deepEqual(assets[5].data, { type: 12 }); + assert.ok(!assets[6]); + }); + }); + }); + }); + }); + + describe('interpretResponse', function () { + it('should return if no body in response', function () { + let serverResponse = {}; + let bidRequest = {}; + + assert.ok(!spec.interpretResponse(serverResponse, bidRequest)); + }); + it('should return more than one bids', function () { + let serverResponse = { + body: { + seatbid: [{ + bid: [{impid: 'impid1', native: {ver: '1.1', link: { url: 'link' }, assets: [{id: 1, title: {text: 'Asset title text'}}]}}] + }, { + bid: [{impid: 'impid2', native: {ver: '1.1', link: { url: 'link' }, assets: [{id: 1, data: {value: 'Asset title text'}}]}}] + }] + } + }; + let bidRequest = { + data: {}, + bids: [ + { + bidId: 'bidId1', + params: { siteId: 'siteId', mid: 1000 }, + nativeParams: { + title: { required: true, len: 140 }, + image: { required: false, wmin: 836, hmin: 627, w: 325, h: 300, mimes: ['image/jpg', 'image/gif'] }, + body: { len: 140 } + } + }, + { + bidId: 'bidId2', + params: { siteId: 'siteId', mid: 1000 }, + nativeParams: { + title: { required: true, len: 140 }, + image: { required: false, wmin: 836, hmin: 627, w: 325, h: 300, mimes: ['image/jpg', 'image/gif'] }, + body: { len: 140 } + } + } + ] + }; + + bids = spec.interpretResponse(serverResponse, bidRequest); + assert.equal(spec.interpretResponse(serverResponse, bidRequest).length, 2); + }); + it('should set correct values to bid', function () { + let serverResponse = { + body: { + id: null, + bidid: null, + seatbid: [{ + bid: [ + { + impid: 'impid1', + price: 93.1231, + crid: '12312312', + native: { + assets: [], + link: { url: 'link' }, + imptrackers: ['imptrackers url1', 'imptrackers url2'] + } + } + ] + }], + cur: 'NOK' + } + }; + let bidRequest = { + data: {}, + bids: [ + { + bidId: 'bidId1', + params: { siteId: 'siteId', mid: 1000 }, + nativeParams: { + title: { required: true, len: 140 }, + image: { required: false, wmin: 836, hmin: 627, w: 325, h: 300, mimes: ['image/jpg', 'image/gif'] }, + body: { len: 140 } + } + } + ] + }; + + const bids = spec.interpretResponse(serverResponse, bidRequest); + const bid = serverResponse.body.seatbid[0].bid[0]; + assert.deepEqual(bids[0].requestId, bidRequest.bids[0].bidId); + assert.deepEqual(bids[0].cpm, bid.price); + assert.deepEqual(bids[0].creativeId, bid.crid); + assert.deepEqual(bids[0].ttl, 360); + assert.deepEqual(bids[0].netRevenue, false); + assert.deepEqual(bids[0].currency, serverResponse.body.cur); + assert.deepEqual(bids[0].mediaType, 'native'); + assert.deepEqual(bids[0].bidderCode, 'adformOpenRTB'); + }); + it('should set correct native params', function () { + const bid = [ + { + impid: 'impid1', + price: 93.1231, + crid: '12312312', + native: { + assets: [ + { + data: null, + id: 0, + img: null, + required: 0, + title: {text: 'title', len: null}, + video: null + }, { + data: null, + id: 2, + img: {type: null, url: 'test.url.com/Files/58345/308185.jpg?bv=1', w: 30, h: 10}, + required: 0, + title: null, + video: null + }, { + data: null, + id: 3, + img: {type: null, url: 'test.url.com/Files/58345/308200.jpg?bv=1', w: 100, h: 100}, + required: 0, + title: null, + video: null + }, { + data: {type: null, len: null, value: 'body'}, + id: 4, + img: null, + required: 0, + title: null, + video: null + }, { + data: {type: null, len: null, value: 'cta'}, + id: 1, + img: null, + required: 0, + title: null, + video: null + }, { + data: {type: null, len: null, value: 'sponsoredBy'}, + id: 5, + img: null, + required: 0, + title: null, + video: null + } + ], + link: { url: 'clickUrl', clicktrackers: ['clickTracker1', 'clickTracker2'] }, + imptrackers: ['imptrackers url1', 'imptrackers url2'], + jstracker: 'jstracker' + } + } + ]; + const serverResponse = { + body: { + id: null, + bidid: null, + seatbid: [{ bid }], + cur: 'NOK' + } + }; + let bidRequest = { + data: {}, + bids: [{ bidId: 'bidId1' }] + }; + + const result = spec.interpretResponse(serverResponse, bidRequest)[0].native; + const native = bid[0].native; + const assets = native.assets; + assert.deepEqual({ + clickUrl: native.link.url, + clickTrackers: native.link.clicktrackers, + impressionTrackers: native.imptrackers, + javascriptTrackers: [ native.jstracker ], + title: assets[0].title.text, + icon: {url: assets[1].img.url, width: assets[1].img.w, height: assets[1].img.h}, + image: {url: assets[2].img.url, width: assets[2].img.w, height: assets[2].img.h}, + body: assets[3].data.value, + cta: assets[4].data.value, + sponsoredBy: assets[5].data.value + }, result); + }); + it('should return empty when there is no bids in response', function () { + const serverResponse = { + body: { + id: null, + bidid: null, + seatbid: [{ bid: [] }], + cur: 'NOK' + } + }; + let bidRequest = { + data: {}, + bids: [{ bidId: 'bidId1' }] + }; + const result = spec.interpretResponse(serverResponse, bidRequest)[0]; + assert.ok(!result); + }); + }); +}); diff --git a/test/spec/modules/adgenerationBidAdapter_spec.js b/test/spec/modules/adgenerationBidAdapter_spec.js index 4239712ccaf..a2c8125850a 100644 --- a/test/spec/modules/adgenerationBidAdapter_spec.js +++ b/test/spec/modules/adgenerationBidAdapter_spec.js @@ -1,31 +1,32 @@ import {expect} from 'chai'; -import * as utils from 'src/utils'; import {spec} from 'modules/adgenerationBidAdapter'; import {newBidder} from 'src/adapters/bidderFactory'; import {NATIVE} from 'src/mediaTypes'; +import {config} from 'src/config'; +import prebid from '../../../package.json'; -describe('AdgenerationAdapter', () => { +describe('AdgenerationAdapter', function () { const adapter = newBidder(spec); const ENDPOINT = ['http://api-test.scaleout.jp/adsv/v1', 'https://d.socdm.com/adsv/v1']; - describe('inherited functions', () => { - it('exists and is a function', () => { + describe('inherited functions', function () { + it('exists and is a function', function () { expect(adapter.callBids).to.exist.and.to.be.a('function'); }); }); - describe('isBidRequestValid', () => { - let bid = { + describe('isBidRequestValid', function () { + const bid = { 'bidder': 'adg', 'params': { id: '58278', // banner } }; - it('should return true when required params found', () => { + it('should return true when required params found', function () { expect(spec.isBidRequestValid(bid)).to.equal(true); }); - it('should return false when required params are not passed', () => { + it('should return false when required params are not passed', function () { let bid = Object.assign({}, bid); delete bid.params; bid.params = {}; @@ -33,17 +34,16 @@ describe('AdgenerationAdapter', () => { }); }); - describe('buildRequests', () => { + describe('buildRequests', function () { const bidRequests = [ { // banner bidder: 'adg', params: { id: '58278', - width: '300', - height: '250' + currency: 'JPY', }, adUnitCode: 'adunit-code', - sizes: [[300, 250]], + sizes: [[300, 250], [320, 100]], bidId: '2f6ac468a9c15e', bidderRequestId: '14a9f773e30243', auctionId: '4aae9f05-18c6-4fcd-80cf-282708cd584a', @@ -53,8 +53,7 @@ describe('AdgenerationAdapter', () => { bidder: 'adg', params: { id: '58278', - width: '300', - height: '250' + currency: 'JPY', }, mediaTypes: { native: { @@ -87,35 +86,60 @@ describe('AdgenerationAdapter', () => { transactionTd: 'f76f6dfd-d64f-4645-a29f-682bac7f431a' } ]; + const bidderRequest = { + refererInfo: { + referer: 'http://example.com' + } + }; const data = { - banner: 'posall=SSPLOC&id=58278&sdktype=0&hb=true&t=json3&imark=1', - native: 'posall=SSPLOC&id=58278&sdktype=0&hb=true&t=json3' + banner: `posall=SSPLOC&id=58278&sdktype=0&hb=true&t=json3&sizes=300x250%2C320x100¤cy=JPY&pbver=${prebid.version}&sdkname=prebidjs&adapterver=1.0.1&imark=1&tp=http%3A%2F%2Fexample.com`, + bannerUSD: `posall=SSPLOC&id=58278&sdktype=0&hb=true&t=json3&sizes=300x250%2C320x100¤cy=USD&pbver=${prebid.version}&sdkname=prebidjs&adapterver=1.0.1&imark=1&tp=http%3A%2F%2Fexample.com`, + native: 'posall=SSPLOC&id=58278&sdktype=0&hb=true&t=json3&sizes=1x1¤cy=JPY&pbver=' + prebid.version + '&sdkname=prebidjs&adapterver=1.0.1&tp=http%3A%2F%2Fexample.com' }; - it('sends bid request to ENDPOINT via GET', () => { - const request = spec.buildRequests(bidRequests)[0]; + it('sends bid request to ENDPOINT via GET', function () { + const request = spec.buildRequests(bidRequests, bidderRequest)[0]; expect(request.url).to.equal(ENDPOINT[1]); expect(request.method).to.equal('GET'); }); - it('sends bid request to debug ENDPOINT via GET', () => { + it('sends bid request to debug ENDPOINT via GET', function () { bidRequests[0].params.debug = true; - const request = spec.buildRequests(bidRequests)[0]; + const request = spec.buildRequests(bidRequests, bidderRequest)[0]; expect(request.url).to.equal(ENDPOINT[0]); expect(request.method).to.equal('GET'); }); - it('should attache params to the banner request', () => { - const request = spec.buildRequests(bidRequests)[0]; + it('should attache params to the banner request', function () { + const request = spec.buildRequests(bidRequests, bidderRequest)[0]; expect(request.data).to.equal(data.banner); }); - it('should attache params to the native request', () => { - const request = spec.buildRequests(bidRequests)[1]; + it('should attache params to the native request', function () { + const request = spec.buildRequests(bidRequests, bidderRequest)[1]; expect(request.data).to.equal(data.native); }); + it('allows setConfig to set bidder currency for JPY', function () { + config.setConfig({ + currency: { + adServerCurrency: 'JPY' + } + }); + const request = spec.buildRequests(bidRequests, bidderRequest)[0]; + expect(request.data).to.equal(data.banner); + config.resetConfig(); + }); + it('allows setConfig to set bidder currency for USD', function () { + config.setConfig({ + currency: { + adServerCurrency: 'USD' + } + }); + const request = spec.buildRequests(bidRequests, bidderRequest)[0]; + expect(request.data).to.equal(data.bannerUSD); + config.resetConfig(); + }); }); - - describe('interpretResponse', () => { + describe('interpretResponse', function () { const bidRequests = { banner: { bidRequest: { @@ -298,7 +322,6 @@ describe('AdgenerationAdapter', () => { currency: 'JPY', netRevenue: true, ttl: 1000, - referrer: utils.getTopWindowUrl(), ad: '
', }, native: { @@ -311,7 +334,6 @@ describe('AdgenerationAdapter', () => { currency: 'JPY', netRevenue: true, ttl: 1000, - referrer: utils.getTopWindowUrl(), ad: '↵
', native: { title: 'Title', @@ -336,12 +358,12 @@ describe('AdgenerationAdapter', () => { } }; - it('no bid responses', () => { + it('no bid responses', function () { const result = spec.interpretResponse({body: serverResponse.noAd}, bidRequests.banner); expect(result.length).to.equal(0); }); - it('handles banner responses', () => { + it('handles banner responses', function () { const result = spec.interpretResponse({body: serverResponse.banner}, bidRequests.banner)[0]; expect(result.requestId).to.equal(bidResponses.banner.requestId); expect(result.width).to.equal(bidResponses.banner.width); @@ -351,11 +373,10 @@ describe('AdgenerationAdapter', () => { expect(result.currency).to.equal(bidResponses.banner.currency); expect(result.netRevenue).to.equal(bidResponses.banner.netRevenue); expect(result.ttl).to.equal(bidResponses.banner.ttl); - expect(result.referrer).to.equal(bidResponses.banner.referrer); expect(result.ad).to.equal(bidResponses.banner.ad); }); - it('handles native responses', () => { + it('handles native responses', function () { const result = spec.interpretResponse({body: serverResponse.native}, bidRequests.native)[0]; expect(result.requestId).to.equal(bidResponses.native.requestId); expect(result.width).to.equal(bidResponses.native.width); @@ -365,7 +386,6 @@ describe('AdgenerationAdapter', () => { expect(result.currency).to.equal(bidResponses.native.currency); expect(result.netRevenue).to.equal(bidResponses.native.netRevenue); expect(result.ttl).to.equal(bidResponses.native.ttl); - expect(result.referrer).to.equal(bidResponses.native.referrer); expect(result.native.title).to.equal(bidResponses.native.native.title); expect(result.native.image.url).to.equal(bidResponses.native.native.image.url); expect(result.native.image.height).to.equal(bidResponses.native.native.image.height); diff --git a/test/spec/modules/adheseBidAdapter_spec.js b/test/spec/modules/adheseBidAdapter_spec.js new file mode 100644 index 00000000000..bbeafe6d3b7 --- /dev/null +++ b/test/spec/modules/adheseBidAdapter_spec.js @@ -0,0 +1,285 @@ +import {expect} from 'chai'; +import {spec} from 'modules/adheseBidAdapter'; + +const BID_ID = 456; +const TTL = 360; +const NET_REVENUE = true; + +let minimalBid = function() { + return { + 'bidId': BID_ID, + 'bidder': 'adhese', + 'params': { + account: 'demo', + location: '_main_page_', + format: 'leaderboard' + } + } +}; + +let bidWithParams = function(data) { + let bid = minimalBid(); + bid.params.data = data; + return bid; +}; + +describe('AdheseAdapter', function () { + describe('getUserSyncs', function () { + const serverResponse = { + account: 'demo' + }; + const gdprConsent = { + gdprApplies: true, + consentString: 'CONSENT_STRING' + }; + it('should return empty when iframe disallowed', function () { + expect(spec.getUserSyncs({ iframeEnabled: false }, serverResponse, gdprConsent)).to.be.empty; + }); + it('should return usersync url when iframe allowed', function () { + expect(spec.getUserSyncs({ iframeEnabled: true }, serverResponse, gdprConsent)).to.deep.equal([{ type: 'iframe', url: 'https://user-sync.adhese.com/iframe/user_sync.html?account=demo&gdpr=1&consentString=CONSENT_STRING' }]); + }); + }); + + describe('isBidRequestValid', function () { + it('should return true when required params found', function () { + expect(spec.isBidRequestValid(minimalBid())).to.equal(true); + }); + + it('should return false when required params are not passed', function () { + let bid = Object.assign({}, minimalBid()); + delete bid.params; + bid.params = {}; + expect(spec.isBidRequestValid(bid)).to.equal(false); + }); + }); + + describe('buildRequests', function () { + let bidderRequest = { + gdprConsent: { + gdprApplies: true, + consentString: 'CONSENT_STRING' + } + }; + + it('should include all extra bid params', function () { + let req = spec.buildRequests([ bidWithParams({ 'ag': '25' }) ], bidderRequest); + + expect(req.url).to.contain('/sl_main_page_-leaderboard/ag25'); + }); + + it('should include duplicate bid params once', function () { + let req = spec.buildRequests([ bidWithParams({ 'ag': '25' }), bidWithParams({ 'ag': '25', 'ci': 'gent' }) ], bidderRequest); + + expect(req.url).to.contain('/sl_main_page_-leaderboard/ag25/cigent'); + }); + + it('should split multiple target values', function () { + let req = spec.buildRequests([ bidWithParams({ 'ci': 'london' }), bidWithParams({ 'ci': 'gent' }) ], bidderRequest); + + expect(req.url).to.contain('/sl_main_page_-leaderboard/cilondon;gent'); + }); + + it('should include gdpr consent param', function () { + let req = spec.buildRequests([ minimalBid() ], bidderRequest); + + expect(req.url).to.contain('/xtCONSENT_STRING'); + }); + + it('should include bids', function () { + let bid = minimalBid(); + let req = spec.buildRequests([ bid ], bidderRequest); + + expect(req.bids).to.deep.equal([ bid ]); + }); + }); + + describe('interpretResponse', () => { + let bidRequest = { + bids: [ minimalBid() ] + }; + + it('should get correct ssp banner response', () => { + let sspBannerResponse = { + body: [ + { + origin: 'APPNEXUS', + originInstance: '', + ext: 'js', + slotName: '_main_page_-leaderboard', + adType: 'leaderboard', + originData: { + seatbid: [{ + bid: [{ + crid: '60613369', + dealid: null + }], + seat: '958' + }] + }, + width: '728', + height: '90', + body: '
', + tracker: 'https://hosts-demo.adhese.com/rtb_gateway/handlers/client/track/?id=a2f39296-6dd0-4b3c-be85-7baa22e7ff4a', + impressionCounter: 'https://hosts-demo.adhese.com/rtb_gateway/handlers/client/track/?id=a2f39296-6dd0-4b3c-be85-7baa22e7ff4a', + extension: {'prebid': {'cpm': {'amount': '1.000000', 'currency': 'USD'}}} + } + ] + }; + + let expectedResponse = [{ + requestId: BID_ID, + ad: '
', + cpm: 1, + currency: 'USD', + creativeId: '60613369', + dealId: '', + width: 728, + height: 90, + mediaType: 'banner', + netRevenue: NET_REVENUE, + ttl: TTL, + }]; + expect(spec.interpretResponse(sspBannerResponse, bidRequest)).to.deep.equal(expectedResponse); + }); + + it('should get correct ssp video response', () => { + let sspVideoResponse = { + body: [ + { + origin: 'RUBICON', + ext: 'js', + slotName: '_main_page_-leaderboard', + adType: 'leaderboard', + width: '640', + height: '350', + body: '', + extension: {'prebid': {'cpm': {'amount': '2.1', 'currency': 'USD'}}} + } + ] + }; + + let expectedResponse = [{ + requestId: BID_ID, + vastXml: '', + cpm: 2.1, + currency: 'USD', + creativeId: 'RUBICON', + dealId: '', + width: 640, + height: 350, + mediaType: 'video', + netRevenue: NET_REVENUE, + ttl: TTL, + }]; + expect(spec.interpretResponse(sspVideoResponse, bidRequest)).to.deep.equal(expectedResponse); + }); + + it('should get correct Adhese banner response', () => { + const adheseBannerResponse = { + body: [ + { + adType: 'largeleaderboard', // it can differ from the requested slot + adFormat: 'largeleaderboard', + timeStamp: '1544009030000', + orderId: '22051', + adspaceId: '162363', + body: '', + tag: '', + tracker: 'https://hosts-demo.adhese.com/track/tracker', + altText: '', + height: '150', + width: '840', + tagUrl: 'https://pool-demo.adhese.com/pool/lib/90511.js', + libId: '90511', + id: '742898', + advertiserId: '2081', + ext: 'js', + url: 'https://hosts-demo.adhese.com/raylene/url', + clickTag: 'https://hosts-demo.adhese.com/raylene/clickTag', + poolPath: 'https://hosts-demo.adhese.com/pool/lib/', + orderName: 'Luminus boiler comodity-Pareto -201812', + creativeName: 'nl_demo _network_ron_dlbd_840x150_fix_dir_asv_std_dis_brd_nrt_na_red', + slotName: '_main_page_-leaderboard', + slotID: '29306', + impressionCounter: 'https://hosts-demo.adhese.com/track/742898', + origin: 'JERLICIA', + originData: {}, + auctionable: true, + extension: { + prebid: { + cpm: { + amount: '5.96', + currency: 'USD' + } + } + } + } + ] + }; + + let expectedResponse = [{ + requestId: BID_ID, + ad: '', + cpm: 5.96, + currency: 'USD', + creativeId: '742898', + dealId: '22051', + width: 840, + height: 150, + mediaType: 'banner', + netRevenue: NET_REVENUE, + ttl: TTL, + }]; + expect(spec.interpretResponse(adheseBannerResponse, bidRequest)).to.deep.equal(expectedResponse); + }); + + it('should get correct Adhese video response', () => { + const adheseVideoResponse = { + body: [ + { + adType: 'preroll', + adFormat: '', + orderId: '22248', + adspaceId: '164196', + body: '', + height: '360', + width: '640', + tag: "", + libId: '89860', + id: '742470', + advertiserId: '2263', + ext: 'advar', + orderName: 'Smartphoto EOY-20181112', + creativeName: 'PREROLL', + slotName: '_main_page_-leaderboard', + slotID: '41711', + impressionCounter: 'https://hosts-demo.adhese.com/track/742898', + origin: 'JERLICIA', + originData: {}, + auctionable: true + } + ] + }; + + let expectedResponse = [{ + requestId: BID_ID, + vastXml: '', + cpm: 0, + currency: 'USD', + creativeId: '742470', + dealId: '22248', + width: 640, + height: 360, + mediaType: 'video', + netRevenue: NET_REVENUE, + ttl: TTL, + }]; + expect(spec.interpretResponse(adheseVideoResponse, bidRequest)).to.deep.equal(expectedResponse); + }); + + it('should return no bids for empty adserver response', () => { + let adserverResponse = { body: [] }; + expect(spec.interpretResponse(adserverResponse, bidRequest)).to.be.empty; + }); + }); +}); diff --git a/test/spec/modules/adikteevBidAdapter_spec.js b/test/spec/modules/adikteevBidAdapter_spec.js new file mode 100644 index 00000000000..243cbe2a9c5 --- /dev/null +++ b/test/spec/modules/adikteevBidAdapter_spec.js @@ -0,0 +1,235 @@ +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/adkernelAdnAnalyticsAdapter_spec.js b/test/spec/modules/adkernelAdnAnalyticsAdapter_spec.js index f5d1a5d02f1..26fd13afd1f 100644 --- a/test/spec/modules/adkernelAdnAnalyticsAdapter_spec.js +++ b/test/spec/modules/adkernelAdnAnalyticsAdapter_spec.js @@ -1,7 +1,6 @@ import analyticsAdapter, {ExpiringQueue, getUmtSource, storage} from 'modules/adkernelAdnAnalyticsAdapter'; import {expect} from 'chai'; -import adaptermanager from 'src/adaptermanager'; -import * as ajax from 'src/ajax'; +import adapterManager from 'src/adapterManager'; import CONSTANTS from 'src/constants.json'; const events = require('../../../src/events'); @@ -33,81 +32,81 @@ const CAMPAIGN = { c5: '5' }; -describe('', () => { +describe('', function () { let sandbox; - before(() => { + before(function () { sandbox = sinon.sandbox.create(); }); - after(() => { + after(function () { sandbox.restore(); analyticsAdapter.disableAnalytics(); }); - describe('UTM source parser', () => { + describe('UTM source parser', function () { let stubSetItem; let stubGetItem; - before(() => { + before(function () { stubSetItem = sandbox.stub(storage, 'setItem'); stubGetItem = sandbox.stub(storage, 'getItem'); }); - afterEach(() => { + afterEach(function () { sandbox.reset(); }); - it('should parse first direct visit as (direct)', () => { + it('should parse first direct visit as (direct)', function () { stubGetItem.withArgs('adk_dpt_analytics').returns(undefined); stubSetItem.returns(undefined); let source = getUmtSource('http://example.com'); expect(source).to.be.eql(DIRECT); }); - it('should respect past campaign visits before direct', () => { + it('should respect past campaign visits before direct', function () { stubGetItem.withArgs('adk_dpt_analytics').returns(JSON.stringify(CAMPAIGN)); stubSetItem.returns(undefined); let source = getUmtSource('http://example.com'); expect(source).to.be.eql(CAMPAIGN); }); - it('should parse visit from google as organic', () => { + it('should parse visit from google as organic', function () { stubGetItem.withArgs('adk_dpt_analytics').returns(undefined); stubSetItem.returns(undefined); let source = getUmtSource('http://example.com', 'https://www.google.com/search?q=pikachu'); expect(source).to.be.eql(GOOGLE_ORGANIC); }); - it('should respect previous campaign visit before organic', () => { + it('should respect previous campaign visit before organic', function () { stubGetItem.withArgs('adk_dpt_analytics').returns(JSON.stringify(CAMPAIGN)); stubSetItem.returns(undefined); let source = getUmtSource('http://example.com', 'https://www.google.com/search?q=pikachu'); expect(source).to.be.eql(CAMPAIGN); }); - it('should parse referral visit', () => { + it('should parse referral visit', function () { stubGetItem.withArgs('adk_dpt_analytics').returns(undefined); stubSetItem.returns(undefined); let source = getUmtSource('http://example.com', 'http://lander.com/lander.html'); expect(source).to.be.eql(REFERRER); }); - it('should respect previous campaign visit before referral', () => { + it('should respect previous campaign visit before referral', function () { stubGetItem.withArgs('adk_dpt_analytics').returns(JSON.stringify(CAMPAIGN)); stubSetItem.returns(undefined); let source = getUmtSource('http://example.com', 'https://www.google.com/search?q=pikachu'); expect(source).to.be.eql(CAMPAIGN); }); - it('should parse referral visit from same domain as direct', () => { + it('should parse referral visit from same domain as direct', function () { stubGetItem.withArgs('adk_dpt_analytics').returns(undefined); stubSetItem.returns(undefined); let source = getUmtSource('http://lander.com/news.html', 'http://lander.com/lander.html'); expect(source).to.be.eql(DIRECT); }); - it('should parse campaign visit', () => { + it('should parse campaign visit', function () { stubGetItem.withArgs('adk_dpt_analytics').returns(undefined); stubSetItem.returns(undefined); let source = getUmtSource('http://lander.com/index.html?utm_campaign=new_campaign&utm_source=adkernel&utm_medium=email&utm_c1=1&utm_c2=2&utm_c3=3&utm_c4=4&utm_c5=5'); @@ -115,12 +114,12 @@ describe('', () => { }); }); - describe('ExpiringQueue', () => { + describe('ExpiringQueue', function () { let timer; - before(() => { + before(function () { timer = sandbox.useFakeTimers(0); }); - after(() => { + after(function () { timer.restore(); }); @@ -184,32 +183,32 @@ describe('', () => { size: '300x250' }; - describe('Analytics adapter', () => { + describe('Analytics adapter', function () { let ajaxStub; let timer; - before(() => { - ajaxStub = sandbox.stub(ajax, 'ajax'); + before(function () { + ajaxStub = sandbox.stub(analyticsAdapter, 'ajaxCall'); timer = sandbox.useFakeTimers(0); }); - beforeEach(() => { + beforeEach(function () { sandbox.stub(events, 'getEvents').callsFake(() => { return [] }); }); - afterEach(() => { + afterEach(function () { events.getEvents.restore(); }); - it('should be configurable', () => { - adaptermanager.registerAnalyticsAdapter({ + it('should be configurable', function () { + adapterManager.registerAnalyticsAdapter({ code: 'adkernelAdn', adapter: analyticsAdapter }); - adaptermanager.enableAnalytics({ + adapterManager.enableAnalytics({ provider: 'adkernelAdn', options: { pubId: 777, @@ -221,21 +220,21 @@ describe('', () => { expect(analyticsAdapter.context).to.have.property('pubId', 777); }); - it('should handle auction init event', () => { + it('should handle auction init event', function () { events.emit(CONSTANTS.EVENTS.AUCTION_INIT, {config: {}, timeout: 3000}); const ev = analyticsAdapter.context.queue.peekAll(); expect(ev).to.have.length(1); expect(ev[0]).to.be.eql({event: 'auctionInit'}); }); - it('should handle bid request event', () => { + it('should handle bid request event', function () { events.emit(CONSTANTS.EVENTS.BID_REQUESTED, REQUEST); const ev = analyticsAdapter.context.queue.peekAll(); expect(ev).to.have.length(2); expect(ev[1]).to.be.eql({event: 'bidRequested', adapter: 'adapter', tagid: 'container-1'}); }); - it('should handle bid response event', () => { + it('should handle bid response event', function () { events.emit(CONSTANTS.EVENTS.BID_RESPONSE, RESPONSE); const ev = analyticsAdapter.context.queue.peekAll(); expect(ev).to.have.length(3); @@ -248,21 +247,21 @@ describe('', () => { }); }); - it('should handle auction end event', () => { + it('should handle auction end event', function () { timer.tick(447); events.emit(CONSTANTS.EVENTS.AUCTION_END, RESPONSE); let ev = analyticsAdapter.context.queue.peekAll(); expect(ev).to.have.length(0); expect(ajaxStub.calledOnce).to.be.equal(true); - ev = JSON.parse(ajaxStub.firstCall.args[2]).hb_ev; + ev = JSON.parse(ajaxStub.firstCall.args[0]).hb_ev; expect(ev[3]).to.be.eql({event: 'auctionEnd', time: 0.447}); }); - it('should handle winning bid', () => { + it('should handle winning bid', function () { events.emit(CONSTANTS.EVENTS.BID_WON, RESPONSE); timer.tick(4500); expect(ajaxStub.calledTwice).to.be.equal(true); - let ev = JSON.parse(ajaxStub.secondCall.args[2]).hb_ev; + let ev = JSON.parse(ajaxStub.secondCall.args[0]).hb_ev; expect(ev[0]).to.be.eql({event: 'bidWon', adapter: 'adapter', tagid: 'container-1', val: 0.015}); }); }); diff --git a/test/spec/modules/adkernelAdnBidAdapter_spec.js b/test/spec/modules/adkernelAdnBidAdapter_spec.js index af9ccfd78ed..43e2dec7ce9 100644 --- a/test/spec/modules/adkernelAdnBidAdapter_spec.js +++ b/test/spec/modules/adkernelAdnBidAdapter_spec.js @@ -2,7 +2,7 @@ import {expect} from 'chai'; import {spec} from 'modules/adkernelAdnBidAdapter'; import * as utils from 'src/utils'; -describe('AdkernelAdn adapter', () => { +describe('AdkernelAdn adapter', function () { const bid1_pub1 = { bidder: 'adkernelAdn', transactionId: 'transact0', @@ -110,12 +110,12 @@ describe('AdkernelAdn adapter', () => { syncpages: ['https://dsp.adkernel.com/sync'] }; - describe('input parameters validation', () => { - it('empty request shouldn\'t generate exception', () => { + describe('input parameters validation', function () { + it('empty request shouldn\'t generate exception', function () { expect(spec.isBidRequestValid({bidderCode: 'adkernelAdn' })).to.be.equal(false); }); - it('request without pubid should be ignored', () => { + it('request without pubid should be ignored', function () { expect(spec.isBidRequestValid({ bidder: 'adkernelAdn', params: {}, @@ -123,7 +123,7 @@ describe('AdkernelAdn adapter', () => { sizes: [[300, 250]] })).to.be.equal(false); }); - it('request with invalid pubid should be ignored', () => { + it('request with invalid pubid should be ignored', function () { expect(spec.isBidRequestValid({ bidder: 'adkernelAdn', params: { @@ -157,41 +157,41 @@ describe('AdkernelAdn adapter', () => { return [pbRequests, tagRequests]; } - describe('banner request building', () => { + describe('banner request building', function () { let [_, tagRequests] = buildRequest([bid1_pub1]); let tagRequest = tagRequests[0]; - it('should have request id', () => { + it('should have request id', function () { expect(tagRequest).to.have.property('id'); }); - it('should have transaction id', () => { + it('should have transaction id', function () { expect(tagRequest).to.have.property('tid'); }); - it('should have sizes', () => { + it('should have sizes', function () { expect(tagRequest.imp[0].banner).to.have.property('format'); expect(tagRequest.imp[0].banner.format).to.be.eql(['300x250', '300x200']); }); - it('should have impression id', () => { + it('should have impression id', function () { expect(tagRequest.imp[0]).to.have.property('id', 'bidid_1'); }); - it('should have tagid', () => { + it('should have tagid', function () { expect(tagRequest.imp[0]).to.have.property('tagid', 'ad-unit-1'); }); - it('should create proper site block', () => { + it('should create proper site block', function () { expect(tagRequest.site).to.have.property('page', 'https://example.com/index.html'); expect(tagRequest.site).to.have.property('secure', 1); }); - it('should not have user object', () => { + it('should not have user object', function () { expect(tagRequest).to.not.have.property('user'); }); - it('shouldn\'t contain gdpr-related information for default request', () => { + it('shouldn\'t contain gdpr-related information for default request', function () { let [_, tagRequests] = buildRequest([bid1_pub1]); expect(tagRequests[0]).to.not.have.property('user'); }); - it('should contain gdpr-related information if consent is configured', () => { + it('should contain gdpr-related information if consent is configured', function () { let [_, bidRequests] = buildRequest([bid1_pub1], {gdprConsent: {gdprApplies: true, consentString: 'test-consent-string'}}); expect(bidRequests[0]).to.have.property('user'); @@ -199,7 +199,7 @@ describe('AdkernelAdn adapter', () => { expect(bidRequests[0].user).to.have.property('consent', 'test-consent-string'); }); - it('should\'t contain consent string if gdpr isn\'t applied', () => { + it('should\'t contain consent string if gdpr isn\'t applied', function () { let [_, bidRequests] = buildRequest([bid1_pub1], {gdprConsent: {gdprApplies: false}}); expect(bidRequests[0]).to.have.property('user'); expect(bidRequests[0].user).to.have.property('gdpr', 0); @@ -207,19 +207,19 @@ describe('AdkernelAdn adapter', () => { }); }); - describe('video request building', () => { + describe('video request building', function () { let [_, tagRequests] = buildRequest([bid_video1, bid_video2]); let tagRequest = tagRequests[0]; - it('should have video object', () => { + it('should have video object', function () { expect(tagRequest.imp[0]).to.have.property('video'); expect(tagRequest.imp[1]).to.have.property('video'); }); - it('should have tagid', () => { + it('should have tagid', function () { expect(tagRequest.imp[0]).to.have.property('tagid', 'video_wrapper'); expect(tagRequest.imp[1]).to.have.property('tagid', 'video_wrapper2'); }); - it('should have size', () => { + it('should have size', function () { expect(tagRequest.imp[0].video).to.have.property('w', 640); expect(tagRequest.imp[0].video).to.have.property('h', 300); expect(tagRequest.imp[1].video).to.have.property('w', 1920); @@ -227,8 +227,8 @@ describe('AdkernelAdn adapter', () => { }); }); - describe('requests routing', () => { - it('should issue a request for each publisher', () => { + describe('requests routing', function () { + it('should issue a request for each publisher', function () { let [pbRequests, tagRequests] = buildRequest([bid1_pub1, bid_video1]); expect(pbRequests).to.have.length(2); expect(pbRequests[0].url).to.have.string(`account=${bid1_pub1.params.pubId}`); @@ -236,7 +236,7 @@ describe('AdkernelAdn adapter', () => { expect(tagRequests[0].imp).to.have.length(1); expect(tagRequests[1].imp).to.have.length(1); }); - it('should issue a request for each host', () => { + it('should issue a request for each host', function () { let [pbRequests, tagRequests] = buildRequest([bid1_pub1, bid1_pub2]); expect(pbRequests).to.have.length(2); expect(pbRequests[0].url).to.have.string('//tag.adkernel.com/tag'); @@ -246,15 +246,15 @@ describe('AdkernelAdn adapter', () => { }); }); - describe('responses processing', () => { + describe('responses processing', function () { let responses; - before(() => { + before(function () { responses = spec.interpretResponse({body: response}); }); - it('should parse all responses', () => { + it('should parse all responses', function () { expect(responses).to.have.length(3); }); - it('should return fully-initialized bid-response', () => { + it('should return fully-initialized bid-response', function () { let resp = responses[0]; expect(resp).to.have.property('bidderCode', 'adkernelAdn'); expect(resp).to.have.property('requestId', '2c5e951baeeadd'); @@ -268,7 +268,7 @@ describe('AdkernelAdn adapter', () => { expect(resp).to.have.property('ad'); expect(resp.ad).to.have.string(''); }); - it('should return fully-initialized video bid-response', () => { + it('should return fully-initialized video bid-response', function () { let resp = responses[2]; expect(resp).to.have.property('bidderCode', 'adkernelAdn'); expect(resp).to.have.property('requestId', '57d602ad1c9545'); @@ -280,7 +280,7 @@ describe('AdkernelAdn adapter', () => { expect(resp).to.have.property('vastUrl', 'http://vast.com/vast.xml'); expect(resp).to.not.have.property('ad'); }); - it('should perform usersync', () => { + it('should perform usersync', function () { let syncs = spec.getUserSyncs({iframeEnabled: false}, [{body: response}]); expect(syncs).to.have.length(0); syncs = spec.getUserSyncs({iframeEnabled: true}, [{body: response}]); @@ -288,14 +288,21 @@ describe('AdkernelAdn adapter', () => { expect(syncs[0]).to.have.property('type', 'iframe'); expect(syncs[0]).to.have.property('url', 'https://dsp.adkernel.com/sync'); }); - it('should handle user-sync only response', () => { + it('should handle user-sync only response', function () { let [pbRequests, tagRequests] = buildRequest([bid1_pub1]); let resp = spec.interpretResponse({body: usersyncOnlyResponse}, pbRequests[0]); expect(resp).to.have.length(0); }); - it('shouldn\' fail on empty response', () => { + it('shouldn\' fail on empty response', function () { let syncs = spec.getUserSyncs({iframeEnabled: true}, [{body: ''}]); expect(syncs).to.have.length(0); }); }); + + describe('adapter configuration', () => { + it('should have aliases', () => { + expect(spec.aliases).to.have.lengthOf(1); + expect(spec.aliases[0]).to.be.equal('engagesimply'); + }); + }); }); diff --git a/test/spec/modules/adkernelBidAdapter_spec.js b/test/spec/modules/adkernelBidAdapter_spec.js index 0f5596b8b23..0668e84869a 100644 --- a/test/spec/modules/adkernelBidAdapter_spec.js +++ b/test/spec/modules/adkernelBidAdapter_spec.js @@ -1,9 +1,8 @@ import {expect} from 'chai'; import {spec} from 'modules/adkernelBidAdapter'; import * as utils from 'src/utils'; -import {parse as parseUrl} from 'src/url'; -describe('Adkernel adapter', () => { +describe('Adkernel adapter', function () { const bid1_zone1 = { bidder: 'adkernel', bidId: 'Bid_01', @@ -113,89 +112,88 @@ describe('Adkernel adapter', () => { } }; - function buildRequest(bidRequests, bidderRequest = {}, url = 'https://example.com/index.html', dnt = true) { - let wmock = sinon.stub(utils, 'getTopWindowLocation').callsFake(() => { - let loc = parseUrl(url); - loc.protocol += ':'; - return loc; - }); + function buildBidderRequest(url = 'https://example.com/index.html', params = {}) { + return Object.assign({}, params, {refererInfo: {referer: url, reachedTop: true}}) + } + const DEFAULT_BIDDER_REQUEST = buildBidderRequest(); + function buildRequest(bidRequests, bidderRequest = DEFAULT_BIDDER_REQUEST, dnt = true) { let dntmock = sinon.stub(utils, 'getDNT').callsFake(() => dnt); let pbRequests = spec.buildRequests(bidRequests, bidderRequest); - wmock.restore(); dntmock.restore(); let rtbRequests = pbRequests.map(r => JSON.parse(r.data.r)); return [pbRequests, rtbRequests]; } - describe('input parameters validation', () => { - it('empty request shouldn\'t generate exception', () => { + describe('input parameters validation', function () { + it('empty request shouldn\'t generate exception', function () { expect(spec.isBidRequestValid({ bidderCode: 'adkernel' })).to.be.equal(false); }); - it('request without zone shouldn\'t issue a request', () => { + it('request without zone shouldn\'t issue a request', function () { expect(spec.isBidRequestValid(bid_without_zone)).to.be.equal(false); }); - it('request without host shouldn\'t issue a request', () => { + it('request without host shouldn\'t issue a request', function () { expect(spec.isBidRequestValid(bid_without_host)).to.be.equal(false); }); - it('empty request shouldn\'t generate exception', () => { + it('empty request shouldn\'t generate exception', function () { expect(spec.isBidRequestValid(bid_with_wrong_zoneId)).to.be.equal(false); }); }); - describe('banner request building', () => { + describe('banner request building', function () { let bidRequest, bidRequests, _; - before(() => { + before(function () { [_, bidRequests] = buildRequest([bid1_zone1]); bidRequest = bidRequests[0]; }); - it('should be a first-price auction', () => { + it('should be a first-price auction', function () { expect(bidRequest).to.have.property('at', 1); }); - it('should have banner object', () => { + it('should have banner object', function () { expect(bidRequest.imp[0]).to.have.property('banner'); }); - it('should have w/h', () => { + it('should have w/h', function () { expect(bidRequest.imp[0].banner).to.have.property('format'); expect(bidRequest.imp[0].banner.format).to.be.eql([{w: 300, h: 250}, {w: 300, h: 200}]); }); - it('should respect secure connection', () => { + it('should respect secure connection', function () { expect(bidRequest.imp[0]).to.have.property('secure', 1); }); - it('should have tagid', () => { + it('should have tagid', function () { expect(bidRequest.imp[0]).to.have.property('tagid', 'ad-unit-1'); }); - it('should create proper site block', () => { + it('should create proper site block', function () { expect(bidRequest.site).to.have.property('domain', 'example.com'); expect(bidRequest.site).to.have.property('page', 'https://example.com/index.html'); }); - it('should fill device with caller macro', () => { + it('should fill device with caller macro', function () { expect(bidRequest).to.have.property('device'); expect(bidRequest.device).to.have.property('ip', 'caller'); expect(bidRequest.device).to.have.property('ua', 'caller'); expect(bidRequest.device).to.have.property('dnt', 1); }); - it('shouldn\'t contain gdpr-related information for default request', () => { + it('shouldn\'t contain gdpr-related information for default request', function () { let [_, bidRequests] = buildRequest([bid1_zone1]); expect(bidRequests[0]).to.not.have.property('regs'); expect(bidRequests[0]).to.not.have.property('user'); }); - it('should contain gdpr-related information if consent is configured', () => { + it('should contain gdpr-related information if consent is configured', function () { let [_, bidRequests] = buildRequest([bid1_zone1], - {gdprConsent: {gdprApplies: true, consentString: 'test-consent-string', vendorData: {}}}); + buildBidderRequest('http://example.com/index.html', + {gdprConsent: {gdprApplies: true, consentString: 'test-consent-string', vendorData: {}}})); let bidRequest = bidRequests[0]; expect(bidRequest).to.have.property('regs'); expect(bidRequest.regs.ext).to.be.eql({'gdpr': 1}); @@ -203,49 +201,49 @@ describe('Adkernel adapter', () => { expect(bidRequest.user.ext).to.be.eql({'consent': 'test-consent-string'}); }); - it('should\'t contain consent string if gdpr isn\'t applied', () => { - let [_, bidRequests] = buildRequest([bid1_zone1], {gdprConsent: {gdprApplies: false}}); + it('should\'t contain consent string if gdpr isn\'t applied', function () { + let [_, bidRequests] = buildRequest([bid1_zone1], buildBidderRequest('https://example.com/index.html', {gdprConsent: {gdprApplies: false}})); let bidRequest = bidRequests[0]; expect(bidRequest).to.have.property('regs'); expect(bidRequest.regs.ext).to.be.eql({'gdpr': 0}); expect(bidRequest).to.not.have.property('user'); }); - it('should\'t pass dnt if state is unknown', () => { - let [_, bidRequests] = buildRequest([bid1_zone1], {}, 'https://example.com/index.html', false); + it('should\'t pass dnt if state is unknown', function () { + let [_, bidRequests] = buildRequest([bid1_zone1], DEFAULT_BIDDER_REQUEST, false); expect(bidRequests[0].device).to.not.have.property('dnt'); }); }); - describe('video request building', () => { + describe('video request building', function () { let _, bidRequests; - before(() => { + before(function () { [_, bidRequests] = buildRequest([bid_video]); }); - it('should have video object', () => { + it('should have video object', function () { expect(bidRequests[0].imp[0]).to.have.property('video'); }); - it('should have h/w', () => { + it('should have h/w', function () { expect(bidRequests[0].imp[0].video).to.have.property('w', 640); expect(bidRequests[0].imp[0].video).to.have.property('h', 480); }); - it('should have tagid', () => { + it('should have tagid', function () { expect(bidRequests[0].imp[0]).to.have.property('tagid', 'ad-unit-1'); }); }); - describe('requests routing', () => { - it('should issue a request for each host', () => { + describe('requests routing', function () { + it('should issue a request for each host', function () { let [pbRequests, _] = buildRequest([bid1_zone1, bid3_host2]); expect(pbRequests).to.have.length(2); expect(pbRequests[0].url).to.have.string(`//${bid1_zone1.params.host}/`); expect(pbRequests[1].url).to.have.string(`//${bid3_host2.params.host}/`); }); - it('should issue a request for each zone', () => { + it('should issue a request for each zone', function () { let [pbRequests, _] = buildRequest([bid1_zone1, bid2_zone2]); expect(pbRequests).to.have.length(2); expect(pbRequests[0].data.zone).to.be.equal(bid1_zone1.params.zoneId); @@ -253,8 +251,8 @@ describe('Adkernel adapter', () => { }); }); - describe('responses processing', () => { - it('should return fully-initialized banner bid-response', () => { + describe('responses processing', function () { + it('should return fully-initialized banner bid-response', function () { let [pbRequests, _] = buildRequest([bid1_zone1]); let resp = spec.interpretResponse({body: bidResponse1}, pbRequests[0])[0]; expect(resp).to.have.property('requestId', 'Bid_01'); @@ -269,7 +267,7 @@ describe('Adkernel adapter', () => { expect(resp.ad).to.have.string(''); }); - it('should return fully-initialized video bid-response', () => { + it('should return fully-initialized video bid-response', function () { let [pbRequests, _] = buildRequest([bid_video]); let resp = spec.interpretResponse({body: videoBidResponse}, pbRequests[0])[0]; expect(resp).to.have.property('requestId', 'Bid_Video'); @@ -280,20 +278,20 @@ describe('Adkernel adapter', () => { expect(resp.height).to.equal(480); }); - it('should add nurl as pixel for banner response', () => { + it('should add nurl as pixel for banner response', function () { let [pbRequests, _] = buildRequest([bid1_zone1]); let resp = spec.interpretResponse({body: bidResponse1}, pbRequests[0])[0]; let expectedNurl = bidResponse1.seatbid[0].bid[0].nurl + '&px=1'; expect(resp.ad).to.have.string(expectedNurl); }); - it('should handle bidresponse with user-sync only', () => { + it('should handle bidresponse with user-sync only', function () { let [pbRequests, _] = buildRequest([bid1_zone1]); let resp = spec.interpretResponse({body: usersyncOnlyResponse}, pbRequests[0]); expect(resp).to.have.length(0); }); - it('should perform usersync', () => { + it('should perform usersync', function () { let syncs = spec.getUserSyncs({iframeEnabled: false}, [{body: bidResponse1}]); expect(syncs).to.have.length(0); syncs = spec.getUserSyncs({iframeEnabled: true}, [{body: bidResponse1}]); @@ -302,4 +300,11 @@ describe('Adkernel adapter', () => { expect(syncs[0]).to.have.property('url', 'http://adk.sync.com/sync'); }); }); + + describe('adapter configuration', () => { + it('should have aliases', () => { + expect(spec.aliases).to.have.lengthOf(1); + expect(spec.aliases[0]).to.be.equal('headbidding'); + }); + }); }); diff --git a/test/spec/modules/adliveBidAdapter_spec.js b/test/spec/modules/adliveBidAdapter_spec.js new file mode 100644 index 00000000000..a048ce6932b --- /dev/null +++ b/test/spec/modules/adliveBidAdapter_spec.js @@ -0,0 +1,78 @@ +import { expect } from 'chai'; +import { spec } from 'modules/adliveBidAdapter'; + +describe('adliveBidAdapterTests', function() { + let bidRequestData = { + bids: [ + { + bidId: 'transaction_1234', + bidder: 'adlive', + params: { + hashes: ['1e100887dd614b0909bf6c49ba7f69fdd1360437'] + }, + sizes: [[300, 250]] + } + ] + }; + let request = []; + + it('validate_pub_params', function() { + expect( + spec.isBidRequestValid({ + bidder: 'adlive', + params: { + hashes: ['1e100887dd614b0909bf6c49ba7f69fdd1360437'] + } + }) + ).to.equal(true); + }); + + it('validate_generated_params', function() { + request = spec.buildRequests(bidRequestData.bids); + let req_data = JSON.parse(request[0].data); + + expect(req_data.transaction_id).to.equal('transaction_1234'); + }); + + it('validate_response_params', function() { + let serverResponse = { + body: [ + { + hash: '1e100887dd614b0909bf6c49ba7f69fdd1360437', + content: 'Ad html', + price: 1.12, + size: [300, 250], + is_passback: 0 + } + ] + }; + + let bids = spec.interpretResponse(serverResponse, bidRequestData.bids[0]); + expect(bids).to.have.lengthOf(1); + + let bid = bids[0]; + + expect(bid.creativeId).to.equal('1e100887dd614b0909bf6c49ba7f69fdd1360437'); + expect(bid.ad).to.equal('Ad html'); + expect(bid.cpm).to.equal(1.12); + expect(bid.width).to.equal(300); + expect(bid.height).to.equal(250); + expect(bid.currency).to.equal('USD'); + }); + + it('validate_response_params_with passback', function() { + let serverResponse = { + body: [ + { + hash: '1e100887dd614b0909bf6c49ba7f69fdd1360437', + content: 'Ad html passback', + size: [300, 250], + is_passback: 1 + } + ] + }; + let bids = spec.interpretResponse(serverResponse); + + expect(bids).to.have.lengthOf(0); + }); +}); diff --git a/test/spec/modules/admixerBidAdapter_spec.js b/test/spec/modules/admixerBidAdapter_spec.js index 13312e3d24e..54d0dbee6e4 100644 --- a/test/spec/modules/admixerBidAdapter_spec.js +++ b/test/spec/modules/admixerBidAdapter_spec.js @@ -6,16 +6,16 @@ const BIDDER_CODE = 'admixer'; const ENDPOINT_URL = '//inv-nets.admixer.net/prebid.1.0.aspx'; const ZONE_ID = '2eb6bd58-865c-47ce-af7f-a918108c3fd2'; -describe('AdmixerAdapter', () => { +describe('AdmixerAdapter', function () { const adapter = newBidder(spec); - describe('inherited functions', () => { - it('exists and is a function', () => { + describe('inherited functions', function () { + it('exists and is a function', function () { expect(adapter.callBids).to.be.exist.and.to.be.a('function'); }); }); - describe('isBidRequestValid', () => { + describe('isBidRequestValid', function () { let bid = { 'bidder': BIDDER_CODE, 'params': { @@ -28,11 +28,11 @@ describe('AdmixerAdapter', () => { 'auctionId': '1d1a030790a475', }; - it('should return true when required params found', () => { + it('should return true when required params found', function () { expect(spec.isBidRequestValid(bid)).to.equal(true); }); - it('should return false when required params are not passed', () => { + it('should return false when required params are not passed', function () { let bid = Object.assign({}, bid); delete bid.params; bid.params = { @@ -42,7 +42,7 @@ describe('AdmixerAdapter', () => { }); }); - describe('buildRequests', () => { + describe('buildRequests', function () { let bidRequests = [ { 'bidder': BIDDER_CODE, @@ -57,21 +57,21 @@ describe('AdmixerAdapter', () => { } ]; - it('should add referrer and imp to be equal bidRequest', () => { + it('should add referrer and imp to be equal bidRequest', function () { const request = spec.buildRequests(bidRequests); const payload = JSON.parse(request.data.substr(5)); expect(payload.referrer).to.not.be.undefined; expect(payload.imps[0]).to.deep.equal(bidRequests[0]); }); - it('sends bid request to ENDPOINT via GET', () => { + it('sends bid request to ENDPOINT via GET', function () { const request = spec.buildRequests(bidRequests); expect(request.url).to.equal(ENDPOINT_URL); expect(request.method).to.equal('GET'); }); }); - describe('interpretResponse', () => { + describe('interpretResponse', function () { let response = { body: [{ 'currency': 'USD', @@ -86,7 +86,7 @@ describe('AdmixerAdapter', () => { }] }; - it('should get correct bid response', () => { + it('should get correct bid response', function () { const body = response.body; let expectedResponse = [ { @@ -107,7 +107,7 @@ describe('AdmixerAdapter', () => { expect(result[0]).to.deep.equal(expectedResponse[0]); }); - it('handles nobid responses', () => { + it('handles nobid responses', function () { let response = []; let result = spec.interpretResponse(response); diff --git a/test/spec/modules/adoceanBidAdapter_spec.js b/test/spec/modules/adoceanBidAdapter_spec.js index 149b9eb4d53..3e6d321e4f9 100644 --- a/test/spec/modules/adoceanBidAdapter_spec.js +++ b/test/spec/modules/adoceanBidAdapter_spec.js @@ -2,16 +2,16 @@ import { expect } from 'chai'; import { spec } from 'modules/adoceanBidAdapter'; import { newBidder } from 'src/adapters/bidderFactory'; -describe('AdoceanAdapter', () => { +describe('AdoceanAdapter', function () { const adapter = newBidder(spec); - describe('inherited functions', () => { - it('exists and is a function', () => { + describe('inherited functions', function () { + it('exists and is a function', function () { expect(adapter.callBids).to.exist.and.to.be.a('function'); }); }); - describe('isBidRequestValid', () => { + describe('isBidRequestValid', function () { const bid = { 'bidder': 'adocean', 'params': { @@ -26,21 +26,22 @@ describe('AdoceanAdapter', () => { 'auctionId': '1d1a030790a475', }; - it('should return true when required params found', () => { + it('should return true when required params found', function () { expect(spec.isBidRequestValid(bid)).to.equal(true); }); - it('should return false when required params are not passed', () => { + it('should return false when required params are not passed', function () { const bid = Object.assign({}, bid); delete bid.params; bid.params = { 'masterId': 0 }; + expect(spec.isBidRequestValid(bid)).to.equal(false); }); }); - describe('buildRequests', () => { + describe('buildRequests', function () { const bidRequests = [ { 'bidder': 'adocean', @@ -54,29 +55,62 @@ describe('AdoceanAdapter', () => { 'bidId': '30b31c1838de1e', 'bidderRequestId': '22edbae2733bf6', 'auctionId': '1d1a030790a475', + }, + { + 'bidder': 'adocean', + 'params': { + 'masterId': 'tmYF.DMl7ZBq.Nqt2Bq4FutQTJfTpxCOmtNPZoQUDcL.G7', + 'slaveId': 'adoceanmyaozpniqismex', + 'emiter': 'myao.adocean.pl' + }, + 'adUnitCode': 'adunit-code', + 'sizes': [[300, 250]], + 'bidId': '30b31c1838de1f', + 'bidderRequestId': '22edbae2733bf6', + 'auctionId': '1d1a030790a475', } ]; - it('should add bidIdMap with slaveId => bidId mapping', () => { - const request = spec.buildRequests(bidRequests)[0]; - expect(request.bidIdMap).to.exists; - const bidIdMap = request.bidIdMap; - expect(bidIdMap[bidRequests[0].params.slaveId]).to.equal(bidRequests[0].bidId); + const bidderRequest = { + gdprConsent: { + consentString: 'BOQHk-4OSlWKFBoABBPLBd-AAAAgWAHAACAAsAPQBSACmgFTAOkA', + gdprApplies: true + } + }; + + it('should send two requests if slave is duplicated', () => { + const nrOfRequests = spec.buildRequests(bidRequests, bidderRequest).length; + expect(nrOfRequests).to.equal(2); }); - it('sends bid request to url via GET', () => { - const request = spec.buildRequests(bidRequests)[0]; + it('should add bidIdMap with correct slaveId => bidId mapping', () => { + const requests = spec.buildRequests(bidRequests, bidderRequest); + for (let i = 0; i < bidRequests.length; i++) { + expect(requests[i]).to.exists; + expect(requests[i].bidIdMap).to.exists; + expect(requests[i].bidIdMap[bidRequests[i].params.slaveId]).to.equal(bidRequests[i].bidId); + } + }); + + it('sends bid request to url via GET', function () { + const request = spec.buildRequests(bidRequests, bidderRequest)[0]; expect(request.method).to.equal('GET'); expect(request.url).to.match(new RegExp(`^https://${bidRequests[0].params.emiter}/ad.json`)); }); - it('should attach id to url', () => { - const request = spec.buildRequests(bidRequests)[0]; + it('should attach id to url', function () { + const request = spec.buildRequests(bidRequests, bidderRequest)[0]; expect(request.url).to.include('id=' + bidRequests[0].params.masterId); }); + + it('should attach consent information to url', function () { + const request = spec.buildRequests(bidRequests, bidderRequest)[0]; + expect(request.url).to.include('gdpr=1'); + expect(request.url).to.include('gdpr_consent=' + bidderRequest.gdprConsent.consentString); + }); }) - describe('interpretResponse', () => { + describe('interpretResponse', function () { const response = { 'body': [ { @@ -115,7 +149,7 @@ describe('AdoceanAdapter', () => { 'auctionId': '1d1a030790a475', }; - it('should get correct bid response', () => { + it('should get correct bid response', function () { const expectedResponse = [ { 'requestId': '30b31c1838de1e', @@ -143,7 +177,7 @@ describe('AdoceanAdapter', () => { }); }); - it('handles nobid responses', () => { + it('handles nobid responses', function () { response.body = [ { 'id': 'adoceanmyaolafpjwftbz', diff --git a/test/spec/modules/adomikAnalyticsAdapter_spec.js b/test/spec/modules/adomikAnalyticsAdapter_spec.js index 59e6dadec96..16480d746b7 100644 --- a/test/spec/modules/adomikAnalyticsAdapter_spec.js +++ b/test/spec/modules/adomikAnalyticsAdapter_spec.js @@ -1,7 +1,7 @@ import adomikAnalytics from 'modules/adomikAnalyticsAdapter'; import {expect} from 'chai'; let events = require('src/events'); -let adaptermanager = require('src/adaptermanager'); +let adapterManager = require('src/adapterManager').default; let constants = require('src/constants.json'); describe('Adomik Prebid Analytic', function () { @@ -9,26 +9,26 @@ describe('Adomik Prebid Analytic', function () { let sendWonEventStub; describe('enableAnalytics', function () { - beforeEach(() => { + beforeEach(function () { sinon.spy(adomikAnalytics, 'track'); sendEventStub = sinon.stub(adomikAnalytics, 'sendTypedEvent'); sendWonEventStub = sinon.stub(adomikAnalytics, 'sendWonEvent'); sinon.stub(events, 'getEvents').returns([]); }); - afterEach(() => { + afterEach(function () { adomikAnalytics.track.restore(); sendEventStub.restore(); sendWonEventStub.restore(); events.getEvents.restore(); }); - after(() => { + after(function () { adomikAnalytics.disableAnalytics(); }); it('should catch all events', function (done) { - adaptermanager.registerAnalyticsAdapter({ + adapterManager.registerAnalyticsAdapter({ code: 'adomik', adapter: adomikAnalytics }); @@ -55,7 +55,7 @@ describe('Adomik Prebid Analytic', function () { } // Step 1: Initialize adapter - adaptermanager.enableAnalytics({ + adapterManager.enableAnalytics({ provider: 'adomik', options: initOptions }); diff --git a/test/spec/modules/adspiritBidAdapter_spec.js b/test/spec/modules/adspiritBidAdapter_spec.js index 5c8400a8cbc..7f907612384 100644 --- a/test/spec/modules/adspiritBidAdapter_spec.js +++ b/test/spec/modules/adspiritBidAdapter_spec.js @@ -1,10 +1,10 @@ import {expect} from 'chai'; import {spec} from 'modules/adspiritBidAdapter'; -describe('Adspirit adapter tests', () => { +describe('Adspirit adapter tests', function () { let bidRequests, serverResponses; - beforeEach(() => { + beforeEach(function () { bidRequests = [ // valid for adspirit { @@ -89,36 +89,36 @@ describe('Adspirit adapter tests', () => { ] }); - describe('test bid request', () => { - it('with valid data 1', () => { + describe('test bid request', function () { + it('with valid data 1', function () { expect(spec.isBidRequestValid(bidRequests[0])).to.equal(true); }); - it('with valid data 2', () => { + it('with valid data 2', function () { expect(spec.isBidRequestValid(bidRequests[1])).to.equal(true); }); - it('with valid data 3', () => { + it('with valid data 3', function () { expect(spec.isBidRequestValid(bidRequests[2])).to.equal(true); }); - it('with invalid data 1 (no host)', () => { + it('with invalid data 1 (no host)', function () { expect(spec.isBidRequestValid(bidRequests[3])).to.equal(false); }); - it('with invalid data 2 (no placementId)', () => { + it('with invalid data 2 (no placementId)', function () { expect(spec.isBidRequestValid(bidRequests[4])).to.equal(false); }); - it('with invalid data 3 (no bidder code)', () => { + it('with invalid data 3 (no bidder code)', function () { expect(spec.isBidRequestValid(bidRequests[5])).to.equal(false); }); }); - describe('test request build', () => { - it('normal', () => { + describe('test request build', function () { + it('normal', function () { var requests = spec.buildRequests([bidRequests[0]]); expect(requests).to.be.lengthOf(1); }); }); - describe('test bid responses', () => { - it('success 1', () => { + describe('test bid responses', function () { + it('success 1', function () { var bids = spec.interpretResponse(serverResponses[0], {'bidRequest': bidRequests[0]}); expect(bids).to.be.lengthOf(1); expect(bids[0].cpm).to.equal(1.5); @@ -126,15 +126,15 @@ describe('Adspirit adapter tests', () => { expect(bids[0].height).to.equal(250); expect(bids[0].ad).to.have.length.above(1); }); - it('fail 1 (cpm=0)', () => { + it('fail 1 (cpm=0)', function () { var bids = spec.interpretResponse(serverResponses[1], {'bidRequest': bidRequests[0]}); expect(bids).to.be.lengthOf(0); }); - it('fail 2 (no response)', () => { + it('fail 2 (no response)', function () { var bids = spec.interpretResponse([], {'bidRequest': bidRequests[0]}); expect(bids).to.be.lengthOf(0); }); - it('fail 3 (status fail)', () => { + it('fail 3 (status fail)', function () { var bids = spec.interpretResponse(serverResponses[2], {'bidRequest': bidRequests[0]}); expect(bids).to.be.lengthOf(0); }); diff --git a/test/spec/modules/adtelligentBidAdapter_spec.js b/test/spec/modules/adtelligentBidAdapter_spec.js index fa3e0479372..0ee2bb2726f 100644 --- a/test/spec/modules/adtelligentBidAdapter_spec.js +++ b/test/spec/modules/adtelligentBidAdapter_spec.js @@ -46,6 +46,7 @@ const SERVER_VIDEO_RESPONSE = { } ] }; + const SERVER_DISPLAY_RESPONSE = { 'source': {'aid': 12345, 'pubId': 54321}, 'bids': [{ @@ -57,7 +58,8 @@ const SERVER_DISPLAY_RESPONSE = { 'cur': 'USD', 'width': 300, 'cpm': 0.9 - }] + }], + 'cookieURLs': ['link1', 'link2'] }; const videoBidderRequest = { @@ -70,6 +72,14 @@ const displayBidderRequest = { bids: [{bidId: '2e41f65424c87c'}] }; +const displayBidderRequestWithGdpr = { + bidderCode: 'bidderCode', + bids: [{bidId: '2e41f65424c87c'}], + gdprConsent: { + consentString: 'test' + } +}; + const videoEqResponse = [{ vastUrl: 'http://rtb.adtelligent.com/vast/?adid=44F2AEB9BFC881B3', requestId: '2e41f65424c87c', @@ -96,28 +106,44 @@ const displayEqResponse = [{ cpm: 0.9 }]; -describe('adtelligentBidAdapter', () => { +describe('adtelligentBidAdapter', function () { // todo remove only const adapter = newBidder(spec); - describe('inherited functions', () => { - it('exists and is a function', () => { + describe('user syncs', function () { + it('should be returned if pixel enabled', function () { + const syncs = spec.getUserSyncs({pixelEnabled: true}, [{body: SERVER_DISPLAY_RESPONSE}]); + + expect(syncs.map(s => s.url)).to.deep.equal(SERVER_DISPLAY_RESPONSE.cookieURLs); + }) + }) + + describe('user syncs', function () { + it('should not be returned if pixel not set', function () { + const syncs = spec.getUserSyncs({}, [{body: SERVER_DISPLAY_RESPONSE}]); + + expect(syncs).to.be.empty; + }) + }) + + describe('inherited functions', function () { + it('exists and is a function', function () { expect(adapter.callBids).to.exist.and.to.be.a('function'); }); }); - describe('isBidRequestValid', () => { - it('should return true when required params found', () => { + describe('isBidRequestValid', function () { + it('should return true when required params found', function () { expect(spec.isBidRequestValid(VIDEO_REQUEST)).to.equal(12345); }); - it('should return false when required params are not passed', () => { + it('should return false when required params are not passed', function () { let bid = Object.assign({}, VIDEO_REQUEST); delete bid.params; expect(spec.isBidRequestValid(bid)).to.equal(undefined); }); }); - describe('buildRequests', () => { + describe('buildRequests', function () { let videoBidRequests = [VIDEO_REQUEST]; let displayBidRequests = [DISPLAY_REQUEST]; let videoAndDisplayBidRequests = [DISPLAY_REQUEST, VIDEO_REQUEST]; @@ -126,19 +152,19 @@ describe('adtelligentBidAdapter', () => { const videoRequest = spec.buildRequests(videoBidRequests, {}); const videoAndDisplayRequests = spec.buildRequests(videoAndDisplayBidRequests, {}); - it('sends bid request to ENDPOINT via GET', () => { + it('sends bid request to ENDPOINT via GET', function () { expect(videoRequest.method).to.equal('GET'); expect(displayRequest.method).to.equal('GET'); expect(videoAndDisplayRequests.method).to.equal('GET'); }); - it('sends bid request to correct ENDPOINT', () => { + it('sends bid request to correct ENDPOINT', function () { expect(videoRequest.url).to.equal(ENDPOINT); expect(displayRequest.url).to.equal(ENDPOINT); expect(videoAndDisplayRequests.url).to.equal(ENDPOINT); }); - it('sends correct video bid parameters', () => { + it('sends correct video bid parameters', function () { const bid = Object.assign({}, videoRequest.data); delete bid.domain; @@ -152,7 +178,7 @@ describe('adtelligentBidAdapter', () => { expect(bid).to.deep.equal(eq); }); - it('sends correct display bid parameters', () => { + it('sends correct display bid parameters', function () { const bid = Object.assign({}, displayRequest.data); delete bid.domain; @@ -166,7 +192,7 @@ describe('adtelligentBidAdapter', () => { expect(bid).to.deep.equal(eq); }); - it('sends correct video and display bid parameters', () => { + it('sends correct video and display bid parameters', function () { const bid = Object.assign({}, videoAndDisplayRequests.data); delete bid.domain; @@ -185,18 +211,18 @@ describe('adtelligentBidAdapter', () => { }); }); - describe('interpretResponse', () => { + describe('interpretResponse', function () { let serverResponse; let bidderRequest; let eqResponse; - afterEach(() => { + afterEach(function () { serverResponse = null; bidderRequest = null; eqResponse = null; }); - it('should get correct video bid response', () => { + it('should get correct video bid response', function () { serverResponse = SERVER_VIDEO_RESPONSE; bidderRequest = videoBidderRequest; eqResponse = videoEqResponse; @@ -204,7 +230,7 @@ describe('adtelligentBidAdapter', () => { bidServerResponseCheck(); }); - it('should get correct display bid response', () => { + it('should get correct display bid response', function () { serverResponse = SERVER_DISPLAY_RESPONSE; bidderRequest = displayBidderRequest; eqResponse = displayEqResponse; @@ -212,6 +238,13 @@ describe('adtelligentBidAdapter', () => { bidServerResponseCheck(); }); + it('should set gdpr data correctly', function () { + const builtRequestData = spec.buildRequests([DISPLAY_REQUEST], displayBidderRequestWithGdpr); + + expect(builtRequestData.data.gdpr).to.be.equal(1); + expect(builtRequestData.data.gdpr_consent).to.be.equal(displayBidderRequestWithGdpr.gdprConsent.consentString); + }); + function bidServerResponseCheck() { const result = spec.interpretResponse({body: serverResponse}, {bidderRequest}); @@ -225,13 +258,13 @@ describe('adtelligentBidAdapter', () => { expect(noBidResult.length).to.equal(0); } - it('handles video nobid responses', () => { + it('handles video nobid responses', function () { bidderRequest = videoBidderRequest; nobidServerResponseCheck(); }); - it('handles display nobid responses', () => { + it('handles display nobid responses', function () { bidderRequest = displayBidderRequest; nobidServerResponseCheck(); diff --git a/test/spec/modules/aduptechBidAdapter_spec.js b/test/spec/modules/aduptechBidAdapter_spec.js index 76689e9603f..da0b603ebfc 100644 --- a/test/spec/modules/aduptechBidAdapter_spec.js +++ b/test/spec/modules/aduptechBidAdapter_spec.js @@ -3,17 +3,17 @@ import { BIDDER_CODE, PUBLISHER_PLACEHOLDER, ENDPOINT_URL, ENDPOINT_METHOD, spec import { newBidder } from 'src/adapters/bidderFactory'; import * as utils from 'src/utils'; -describe('AduptechBidAdapter', () => { +describe('AduptechBidAdapter', function () { const adapter = newBidder(spec); - describe('inherited functions', () => { - it('exists and is a function', () => { + describe('inherited functions', function () { + it('exists and is a function', function () { expect(adapter.callBids).to.exist.and.to.be.a('function'); }); }); - describe('isBidRequestValid', () => { - it('should return true when necessary information is given', () => { + describe('isBidRequestValid', function () { + it('should return true when necessary information is given', function () { expect(spec.isBidRequestValid({ sizes: [[100, 200]], params: { @@ -23,11 +23,11 @@ describe('AduptechBidAdapter', () => { })).to.be.true; }); - it('should return false on empty bid', () => { + it('should return false on empty bid', function () { expect(spec.isBidRequestValid({})).to.be.false; }); - it('should return false on missing sizes', () => { + it('should return false on missing sizes', function () { expect(spec.isBidRequestValid({ params: { publisher: 'test', @@ -36,7 +36,7 @@ describe('AduptechBidAdapter', () => { })).to.be.false; }); - it('should return false on empty sizes', () => { + it('should return false on empty sizes', function () { expect(spec.isBidRequestValid({ sizes: [], params: { @@ -46,27 +46,27 @@ describe('AduptechBidAdapter', () => { })).to.be.false; }); - it('should return false on missing params', () => { + it('should return false on missing params', function () { expect(spec.isBidRequestValid({ sizes: [[100, 200]], })).to.be.false; }); - it('should return false on invalid params', () => { + it('should return false on invalid params', function () { expect(spec.isBidRequestValid({ sizes: [[100, 200]], params: 'bar' })).to.be.false; }); - it('should return false on empty params', () => { + it('should return false on empty params', function () { expect(spec.isBidRequestValid({ sizes: [[100, 200]], params: {} })).to.be.false; }); - it('should return false on missing publisher', () => { + it('should return false on missing publisher', function () { expect(spec.isBidRequestValid({ sizes: [[100, 200]], params: { @@ -75,7 +75,7 @@ describe('AduptechBidAdapter', () => { })).to.be.false; }); - it('should return false on missing placement', () => { + it('should return false on missing placement', function () { expect(spec.isBidRequestValid({ sizes: [[100, 200]], params: { @@ -85,8 +85,8 @@ describe('AduptechBidAdapter', () => { }); }); - describe('buildRequests', () => { - it('should send one bid request per ad unit to the endpoint via POST', () => { + describe('buildRequests', function () { + it('should send one bid request per ad unit to the endpoint via POST', function () { const bidRequests = [ { bidder: BIDDER_CODE, @@ -146,7 +146,7 @@ describe('AduptechBidAdapter', () => { }); }); - it('should pass gdpr informations', () => { + it('should pass gdpr informations', function () { const bidderRequest = { gdprConsent: { consentString: 'consentString', @@ -175,7 +175,7 @@ describe('AduptechBidAdapter', () => { expect(result[0].data.gdpr.consentString).to.exist.and.to.equal(bidderRequest.gdprConsent.consentString); }); - it('should encode publisher param in endpoint url', () => { + it('should encode publisher param in endpoint url', function () { const bidRequests = [ { bidder: BIDDER_CODE, @@ -196,13 +196,13 @@ describe('AduptechBidAdapter', () => { expect(result[0].url).to.equal(ENDPOINT_URL.replace(PUBLISHER_PLACEHOLDER, encodeURIComponent(bidRequests[0].params.publisher))); }); - it('should handle empty bidRequests', () => { + it('should handle empty bidRequests', function () { expect(spec.buildRequests([])).to.deep.equal([]); }); }); - describe('interpretResponse', () => { - it('should correctly interpret the server response', () => { + describe('interpretResponse', function () { + it('should correctly interpret the server response', function () { const serverResponse = { body: { bid: { @@ -238,11 +238,11 @@ describe('AduptechBidAdapter', () => { ]); }); - it('should handle empty serverResponse', () => { + it('should handle empty serverResponse', function () { expect(spec.interpretResponse({})).to.deep.equal([]); }); - it('should handle missing bid', () => { + it('should handle missing bid', function () { expect(spec.interpretResponse({ body: { creative: {} @@ -250,7 +250,7 @@ describe('AduptechBidAdapter', () => { })).to.deep.equal([]); }); - it('should handle missing creative', () => { + it('should handle missing creative', function () { expect(spec.interpretResponse({ body: { bid: {} diff --git a/test/spec/modules/advenueBidAdapter_spec.js b/test/spec/modules/advenueBidAdapter_spec.js new file mode 100644 index 00000000000..f6ffb277bf9 --- /dev/null +++ b/test/spec/modules/advenueBidAdapter_spec.js @@ -0,0 +1,107 @@ +import {expect} from 'chai'; +import {spec} from '../../../modules/advenueBidAdapter'; + +describe('AdvenueAdapter', function () { + let bid = { + bidId: '2dd581a2b6281d', + bidder: 'advenue', + bidderRequestId: '145e1d6a7837c9', + params: { + placementId: 123, + traffic: 'banner' + }, + placementCode: 'placement_0', + auctionId: '74f78609-a92d-4cf1-869f-1b244bbfb5d2', + sizes: [[300, 250]], + transactionId: '3bb2f6da-87a6-4029-aeb0-bfe951372e62' + }; + + describe('isBidRequestValid', function () { + it('Should return true when placementId can be cast to a number', function () { + expect(spec.isBidRequestValid(bid)).to.be.true; + }); + it('Should return false when placementId is not a number', function () { + bid.params.placementId = 'aaa'; + expect(spec.isBidRequestValid(bid)).to.be.false; + }); + }); + + describe('buildRequests', function () { + let serverRequest = spec.buildRequests([bid]); + it('Creates a ServerRequest object with method, URL and data', function () { + expect(serverRequest).to.exist; + expect(serverRequest.method).to.exist; + expect(serverRequest.url).to.exist; + expect(serverRequest.data).to.exist; + }); + it('Returns POST method', function () { + expect(serverRequest.method).to.equal('POST'); + }); + it('Returns valid URL', function () { + expect(serverRequest.url).to.equal('//ssp.advenuemedia.co.uk/?c=o&m=multi'); + }); + it('Returns valid data if array of bids is valid', function () { + let data = serverRequest.data; + expect(data).to.be.an('object'); + expect(data).to.have.all.keys('deviceWidth', 'deviceHeight', 'secure', 'host', 'page', 'placements'); + expect(data.deviceWidth).to.be.a('number'); + expect(data.deviceHeight).to.be.a('number'); + expect(data.secure).to.be.within(0, 1); + expect(data.host).to.be.a('string'); + expect(data.page).to.be.a('string'); + let placements = data['placements']; + for (let i = 0; i < placements.length; i++) { + let placement = placements[i]; + expect(placement).to.have.all.keys('placementId', 'bidId', 'traffic', 'sizes'); + expect(placement.placementId).to.be.a('number'); + expect(placement.bidId).to.be.a('string'); + expect(placement.traffic).to.be.a('string'); + expect(placement.sizes).to.be.an('array'); + } + }); + it('Returns empty data if no valid requests are passed', function () { + serverRequest = spec.buildRequests([]); + let data = serverRequest.data; + expect(data.placements).to.be.an('array').that.is.empty; + }); + }); + describe('interpretResponse', function () { + let resObject = { + body: [ { + requestId: '123', + mediaType: 'banner', + cpm: 0.3, + width: 320, + height: 50, + ad: '

Hello ad

', + ttl: 1000, + creativeId: '123asd', + netRevenue: true, + currency: 'USD' + } ] + }; + let serverResponses = spec.interpretResponse(resObject); + it('Returns an array of valid server responses if response object is valid', function () { + expect(serverResponses).to.be.an('array').that.is.not.empty; + for (let i = 0; i < serverResponses.length; i++) { + let dataItem = serverResponses[i]; + expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', + 'netRevenue', 'currency', 'mediaType'); + expect(dataItem.requestId).to.be.a('string'); + expect(dataItem.cpm).to.be.a('number'); + expect(dataItem.width).to.be.a('number'); + expect(dataItem.height).to.be.a('number'); + expect(dataItem.ad).to.be.a('string'); + expect(dataItem.ttl).to.be.a('number'); + expect(dataItem.creativeId).to.be.a('string'); + expect(dataItem.netRevenue).to.be.a('boolean'); + expect(dataItem.currency).to.be.a('string'); + expect(dataItem.mediaType).to.be.a('string'); + } + it('Returns an empty array if invalid response is passed', function () { + serverResponses = spec.interpretResponse('invalid_response'); + expect(serverResponses).to.be.an('array').that.is.empty; + }); + }); + }); +}); diff --git a/test/spec/modules/adxcgAnalyticsAdapter_spec.js b/test/spec/modules/adxcgAnalyticsAdapter_spec.js index 9b6b057ee56..605da3bd6bc 100644 --- a/test/spec/modules/adxcgAnalyticsAdapter_spec.js +++ b/test/spec/modules/adxcgAnalyticsAdapter_spec.js @@ -1,27 +1,27 @@ import adxcgAnalyticsAdapter from 'modules/adxcgAnalyticsAdapter'; import { expect } from 'chai'; +import adapterManager from 'src/adapterManager.js'; -let adaptermanager = require('src/adaptermanager'); let events = require('src/events'); let constants = require('src/constants.json'); -describe('adxcg analytics adapter', () => { +describe('adxcg analytics adapter', function () { let xhr; let requests; - beforeEach(() => { + beforeEach(function () { xhr = sinon.useFakeXMLHttpRequest(); requests = []; xhr.onCreate = request => requests.push(request); sinon.stub(events, 'getEvents').returns([]); }); - afterEach(() => { + afterEach(function () { xhr.restore(); events.getEvents.restore(); }); - describe('track', () => { + describe('track', function () { let initOptions = { publisherId: '42' }; @@ -159,23 +159,23 @@ describe('adxcg analytics adapter', () => { }] }; - adaptermanager.registerAnalyticsAdapter({ + adapterManager.registerAnalyticsAdapter({ code: 'adxcg', adapter: adxcgAnalyticsAdapter }); - beforeEach(() => { - adaptermanager.enableAnalytics({ + beforeEach(function () { + adapterManager.enableAnalytics({ provider: 'adxcg', options: initOptions }); }); - afterEach(() => { + afterEach(function () { adxcgAnalyticsAdapter.disableAnalytics(); }); - it('builds and sends auction data', () => { + it('builds and sends auction data', function () { // Step 1: Send auction init event events.emit(constants.EVENTS.AUCTION_INIT, { timestamp: auctionTimestamp diff --git a/test/spec/modules/adxcgBidAdapter_spec.js b/test/spec/modules/adxcgBidAdapter_spec.js index 60aadaec21f..faa8db8050a 100644 --- a/test/spec/modules/adxcgBidAdapter_spec.js +++ b/test/spec/modules/adxcgBidAdapter_spec.js @@ -2,8 +2,8 @@ import { expect } from 'chai' import * as url from 'src/url' import { spec } from 'modules/adxcgBidAdapter' -describe('AdxcgAdapter', () => { - describe('isBidRequestValid', () => { +describe('AdxcgAdapter', function () { + describe('isBidRequestValid', function () { let bidBanner = { 'bidder': 'adxcg', 'params': { @@ -37,22 +37,22 @@ describe('AdxcgAdapter', () => { 'auctionId': '1d1a030790a475', } - it('should return true when required params found', () => { + it('should return true when required params found', function () { expect(spec.isBidRequestValid(bidBanner)).to.equal(true) }) - it('should return true when required params not found', () => { + it('should return true when required params not found', function () { expect(spec.isBidRequestValid({})).to.be.false }) - it('should return false when required params are not passed', () => { + it('should return false when required params are not passed', function () { let bid = Object.assign({}, bidBanner) delete bid.params bid.params = {} expect(spec.isBidRequestValid(bid)).to.equal(false) }) - it('should return true when required video params not found', () => { + it('should return true when required video params not found', function () { const simpleVideo = JSON.parse(JSON.stringify(bidVideo)) simpleVideo.params.adzoneid = 123 expect(spec.isBidRequestValid(simpleVideo)).to.be.false @@ -63,7 +63,7 @@ describe('AdxcgAdapter', () => { }) }) - describe('request function http', () => { + describe('request function http', function () { let bid = { 'bidder': 'adxcg', 'params': { @@ -76,7 +76,7 @@ describe('AdxcgAdapter', () => { 'auctionId': '1d1a030790a475', } - it('creates a valid adxcg request url', () => { + it('creates a valid adxcg request url', function () { let request = spec.buildRequests([bid]) expect(request).to.exist expect(request.method).to.equal('GET') @@ -96,7 +96,7 @@ describe('AdxcgAdapter', () => { }) }) - describe('gdpr compliance', () => { + describe('gdpr compliance', function () { let bid = { 'bidder': 'adxcg', 'params': { @@ -109,7 +109,7 @@ describe('AdxcgAdapter', () => { 'auctionId': '1d1a030790a475', } - it('should send GDPR Consent data if gdprApplies', () => { + it('should send GDPR Consent data if gdprApplies', function () { let request = spec.buildRequests([bid], {gdprConsent: {gdprApplies: true, consentString: 'consentDataString'}}) let parsedRequestUrl = url.parse(request.url) let query = parsedRequestUrl.search @@ -118,7 +118,7 @@ describe('AdxcgAdapter', () => { expect(query.gdpr_consent).to.equal('consentDataString') }) - it('should not send GDPR Consent data if gdprApplies is false or undefined', () => { + it('should not send GDPR Consent data if gdprApplies is false or undefined', function () { let request = spec.buildRequests([bid], { gdprConsent: { gdprApplies: false, @@ -133,7 +133,7 @@ describe('AdxcgAdapter', () => { }) }) - describe('response handler', () => { + describe('response handler', function () { let BIDDER_REQUEST = { 'bidder': 'adxcg', 'params': { @@ -245,7 +245,7 @@ describe('AdxcgAdapter', () => { header: {'someheader': 'fakedata'} } - it('handles regular responses', () => { + it('handles regular responses', function () { let result = spec.interpretResponse(BANNER_RESPONSE, BIDDER_REQUEST) expect(result).to.have.lengthOf(1) @@ -262,7 +262,7 @@ describe('AdxcgAdapter', () => { expect(result[0].dealId).to.not.exist }) - it('handles regular responses with dealid', () => { + it('handles regular responses with dealid', function () { let result = spec.interpretResponse(BANNER_RESPONSE_WITHDEALID, BIDDER_REQUEST) expect(result).to.have.lengthOf(1) @@ -277,7 +277,7 @@ describe('AdxcgAdapter', () => { expect(result[0].ttl).to.equal(300) }) - it('handles video responses', () => { + it('handles video responses', function () { let result = spec.interpretResponse(VIDEO_RESPONSE, BIDDER_REQUEST) expect(result).to.have.lengthOf(1) @@ -292,7 +292,7 @@ describe('AdxcgAdapter', () => { expect(result[0].ttl).to.equal(300) }) - it('handles native responses', () => { + it('handles native responses', function () { let result = spec.interpretResponse(NATIVE_RESPONSE, BIDDER_REQUEST) expect(result[0].width).to.equal(0) @@ -312,7 +312,7 @@ describe('AdxcgAdapter', () => { expect(result[0].native.sponsoredBy).to.equal('sponsoredByContent') }) - it('handles nobid responses', () => { + it('handles nobid responses', function () { let response = [] let bidderRequest = BIDDER_REQUEST @@ -321,12 +321,12 @@ describe('AdxcgAdapter', () => { }) }) - describe('getUserSyncs', () => { + describe('getUserSyncs', function () { let syncoptionsIframe = { 'iframeEnabled': 'true' } - it('should return iframe sync option', () => { + it('should return iframe sync option', function () { expect(spec.getUserSyncs(syncoptionsIframe)[0].type).to.equal('iframe') expect(spec.getUserSyncs(syncoptionsIframe)[0].url).to.equal('//cdn.adxcg.net/pb-sync.html') }) diff --git a/test/spec/modules/adyoulikeBidAdapter_spec.js b/test/spec/modules/adyoulikeBidAdapter_spec.js index d7a5b1a87b7..26898d3f57e 100644 --- a/test/spec/modules/adyoulikeBidAdapter_spec.js +++ b/test/spec/modules/adyoulikeBidAdapter_spec.js @@ -4,7 +4,7 @@ import { parse } from '../../../src/url'; import { spec } from 'modules/adyoulikeBidAdapter'; import { newBidder } from 'src/adapters/bidderFactory'; -describe('Adyoulike Adapter', () => { +describe('Adyoulike Adapter', function () { const canonicalUrl = 'http://canonical.url/?t=%26'; const defaultDC = 'hb-api'; const bidderCode = 'adyoulike'; @@ -136,13 +136,13 @@ describe('Adyoulike Adapter', () => { let getEndpoint = (dc = defaultDC) => `http://${dc}.omnitagjs.com/hb-api/prebid`; - describe('inherited functions', () => { - it('exists and is a function', () => { + describe('inherited functions', function () { + it('exists and is a function', function () { expect(adapter.callBids).to.exist.and.to.be.a('function'); }); }); - describe('isBidRequestValid', () => { + describe('isBidRequestValid', function () { let bid = { 'bidId': 'bid_id_1', 'bidder': 'adyoulike', @@ -154,18 +154,18 @@ describe('Adyoulike Adapter', () => { 'transactionId': 'bid_id_1_transaction_id' }; - it('should return true when required params found', () => { + it('should return true when required params found', function () { expect(spec.isBidRequestValid(bid)).to.equal(true); }); - it('should return false when required params are not passed', () => { + it('should return false when required params are not passed', function () { let bid = Object.assign({}, bid); delete bid.size; expect(spec.isBidRequestValid(bid)).to.equal(false); }); - it('should return false when required params are not passed', () => { + it('should return false when required params are not passed', function () { let bid = Object.assign({}, bid); delete bid.params; bid.params = { @@ -175,10 +175,10 @@ describe('Adyoulike Adapter', () => { }); }); - describe('buildRequests', () => { + describe('buildRequests', function () { let canonicalQuery; - beforeEach(() => { + beforeEach(function () { let canonical = document.createElement('link'); canonical.rel = 'canonical'; canonical.href = canonicalUrl; @@ -186,11 +186,11 @@ describe('Adyoulike Adapter', () => { canonicalQuery.withArgs('link[rel="canonical"][href]').returns(canonical); }); - afterEach(() => { + afterEach(function () { canonicalQuery.restore(); }); - it('should add gdpr consent information to the request', () => { + it('should add gdpr consent information to the request', function () { let consentString = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A=='; let bidderRequest = { 'bidderCode': 'adyoulike', @@ -212,7 +212,7 @@ describe('Adyoulike Adapter', () => { expect(payload.gdprConsent.consentRequired).to.exist.and.to.be.true; }); - it('sends bid request to endpoint with single placement', () => { + it('sends bid request to endpoint with single placement', function () { const request = spec.buildRequests(bidRequestWithSinglePlacement); const payload = JSON.parse(request.data); @@ -226,7 +226,7 @@ describe('Adyoulike Adapter', () => { expect(payload.Bids['bid_id_0'].TransactionID).to.be.equal('bid_id_0_transaction_id'); }); - it('sends bid request to endpoint with single placement without canonical', () => { + it('sends bid request to endpoint with single placement without canonical', function () { canonicalQuery.restore(); const request = spec.buildRequests(bidRequestWithSinglePlacement); const payload = JSON.parse(request.data); @@ -241,7 +241,7 @@ describe('Adyoulike Adapter', () => { expect(payload.Bids['bid_id_0'].TransactionID).to.be.equal('bid_id_0_transaction_id'); }); - it('sends bid request to endpoint with multiple placements', () => { + it('sends bid request to endpoint with multiple placements', function () { const request = spec.buildRequests(bidRequestMultiPlacements); const payload = JSON.parse(request.data); expect(request.url).to.contain(getEndpoint()); @@ -261,7 +261,7 @@ describe('Adyoulike Adapter', () => { expect(payload.PageRefreshed).to.equal(false); }); - it('sends bid request to endpoint setted by parameters', () => { + it('sends bid request to endpoint setted by parameters', function () { const request = spec.buildRequests(bidRequestWithDCPlacement); const payload = JSON.parse(request.data); @@ -269,16 +269,16 @@ describe('Adyoulike Adapter', () => { }); }); // - describe('interpretResponse', () => { + describe('interpretResponse', function () { let serverResponse; - beforeEach(() => { + beforeEach(function () { serverResponse = { body: {} } }); - it('handles nobid responses', () => { + it('handles nobid responses', function () { let response = [{ BidID: '123dfsdf', Attempt: '32344fdse1', @@ -289,7 +289,7 @@ describe('Adyoulike Adapter', () => { expect(result).deep.equal([]); }); - it('receive reponse with single placement', () => { + it('receive reponse with single placement', function () { serverResponse.body = responseWithSinglePlacement; let result = spec.interpretResponse(serverResponse, bidRequestWithSinglePlacement); @@ -300,7 +300,7 @@ describe('Adyoulike Adapter', () => { expect(result[0].height).to.equal(300); }); - it('receive reponse with multiple placement', () => { + it('receive reponse with multiple placement', function () { serverResponse.body = responseWithMultiplePlacements; let result = spec.interpretResponse(serverResponse, bidRequestMultiPlacements); diff --git a/test/spec/modules/ajaBidAdapter_spec.js b/test/spec/modules/ajaBidAdapter_spec.js new file mode 100644 index 00000000000..00dafcb7b11 --- /dev/null +++ b/test/spec/modules/ajaBidAdapter_spec.js @@ -0,0 +1,213 @@ +import { spec } from 'modules/ajaBidAdapter'; +import { newBidder } from 'src/adapters/bidderFactory'; + +const ENDPOINT = '//ad.as.amanad.adtdp.com/v2/prebid'; + +describe('AjaAdapter', function () { + const adapter = newBidder(spec); + + describe('isBidRequestValid', function () { + let bid = { + 'bidder': 'aja', + 'params': { + 'asi': '123456' + }, + 'adUnitCode': 'adunit', + 'sizes': [[300, 250]], + 'bidId': '30b31c1838de1e', + 'bidderRequestId': '22edbae2733bf6', + 'auctionId': '1d1a030790a475', + }; + + it('should return true when required params found', function () { + expect(spec.isBidRequestValid(bid)).to.equal(true); + }); + + it('should return false when required params are not passed', function () { + let bid = Object.assign({}, bid); + delete bid.params; + bid.params = { + 'asi': 0 + }; + expect(spec.isBidRequestValid(bid)).to.equal(false); + }); + }); + + describe('buildRequests', function () { + let bidRequests = [ + { + 'bidder': 'aja', + 'params': { + 'asi': '123456' + }, + 'adUnitCode': 'adunit', + 'sizes': [[300, 250]], + 'bidId': '30b31c1838de1e', + 'bidderRequestId': '22edbae2733bf6', + 'auctionId': '1d1a030790a475', + } + ]; + + it('sends bid request to ENDPOINT via GET', function () { + const requests = spec.buildRequests(bidRequests); + expect(requests[0].url).to.equal(ENDPOINT); + expect(requests[0].method).to.equal('GET'); + }); + }); + describe('interpretResponse', function () { + let response = { + 'is_ad_return': true, + 'ad': { + 'ad_type': 1, + 'prebid_id': '51ef8751f9aead', + 'price': 12.34, + 'currency': 'USD', + 'creative_id': '123abc', + 'banner': { + 'w': 300, + 'h': 250, + 'tag': '
', + 'imps': [ + '//as.amanad.adtdp.com/v1/imp' + ] + } + }, + 'syncs': [ + 'https://example.com' + ] + }; + + it('should get correct banner bid response', function () { + let expectedResponse = [ + { + 'requestId': '51ef8751f9aead', + 'cpm': 12.34, + 'creativeId': '123abc', + 'dealId': undefined, + 'width': 300, + 'height': 250, + 'ad': '
', + 'mediaType': 'banner', + 'currency': 'USD', + 'ttl': 300, + 'netRevenue': true + } + ]; + + let bidderRequest; + let result = spec.interpretResponse({ body: response }, {bidderRequest}); + expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])); + }); + + it('handles video responses', function () { + let response = { + 'is_ad_return': true, + 'ad': { + 'ad_type': 3, + 'prebid_id': '51ef8751f9aead', + 'price': 12.34, + 'currency': 'JPY', + 'creative_id': '123abc', + 'video': { + 'w': 300, + 'h': 250, + 'vtag': '', + 'purl': 'http://cdn/player', + 'progress': true, + 'loop': false, + 'inread': false + } + }, + 'syncs': [ + 'https://example.com' + ] + }; + + let bidderRequest; + let result = spec.interpretResponse({ body: response }, {bidderRequest}); + expect(result[0]).to.have.property('vastXml'); + expect(result[0]).to.have.property('renderer'); + expect(result[0]).to.have.property('mediaType', 'video'); + }); + + it('handles nobid responses', function () { + let response = { + 'is_ad_return': false, + 'ad': {} + }; + + let bidderRequest; + let result = spec.interpretResponse({ body: response }, {bidderRequest}); + expect(result.length).to.equal(0); + }); + }); + + describe('getUserSyncs', function () { + const bidResponse1 = { + body: { + 'is_ad_return': true, + 'ad': { /* ad body */ }, + 'syncs': [ + 'https://example.test/pixel/1' + ], + 'sync_htmls': [ + 'https://example.test/iframe/1' + ] + } + }; + + const bidResponse2 = { + body: { + 'is_ad_return': true, + 'ad': { /* ad body */ }, + 'syncs': [ + 'https://example.test/pixel/2' + ] + } + }; + + it('should use a sync url from first response (pixel and iframe)', function () { + const syncs = spec.getUserSyncs({ pixelEnabled: true, iframeEnabled: true }, [bidResponse1, bidResponse2]); + expect(syncs).to.deep.equal([ + { + type: 'image', + url: 'https://example.test/pixel/1' + }, + { + type: 'iframe', + url: 'https://example.test/iframe/1' + } + ]); + }); + + it('handle empty response (e.g. timeout)', function () { + const syncs = spec.getUserSyncs({ pixelEnabled: true, iframeEnabled: true }, []); + expect(syncs).to.deep.equal([]); + }); + + it('returns empty syncs when not pixel enabled and not iframe enabled', function () { + const syncs = spec.getUserSyncs({ pixelEnabled: false, iframeEnabled: false }, [bidResponse1]); + expect(syncs).to.deep.equal([]); + }); + + it('returns pixel syncs when pixel enabled and not iframe enabled', function() { + const syncs = spec.getUserSyncs({ pixelEnabled: true, iframeEnabled: false }, [bidResponse1]); + expect(syncs).to.deep.equal([ + { + type: 'image', + url: 'https://example.test/pixel/1' + } + ]); + }); + + it('returns iframe syncs when not pixel enabled and iframe enabled', function() { + const syncs = spec.getUserSyncs({ pixelEnabled: false, iframeEnabled: true }, [bidResponse1]); + expect(syncs).to.deep.equal([ + { + type: 'iframe', + url: 'https://example.test/iframe/1' + } + ]); + }); + }); +}); diff --git a/test/spec/modules/andbeyondBidAdapter_spec.js b/test/spec/modules/andbeyondBidAdapter_spec.js index 5e58101ef66..f9b0758749b 100644 --- a/test/spec/modules/andbeyondBidAdapter_spec.js +++ b/test/spec/modules/andbeyondBidAdapter_spec.js @@ -2,7 +2,7 @@ import {expect} from 'chai'; import {spec} from 'modules/andbeyondBidAdapter'; import * as utils from 'src/utils'; -describe('andbeyond adapter', () => { +describe('andbeyond adapter', function () { const bid1_zone1 = { bidder: 'andbeyond', bidId: 'Bid_01', @@ -80,29 +80,29 @@ describe('andbeyond adapter', () => { cur: 'USD' }; - describe('input parameters validation', () => { - it('empty request shouldn\'t generate exception', () => { + describe('input parameters validation', function () { + it('empty request shouldn\'t generate exception', function () { expect(spec.isBidRequestValid({ bidderCode: 'andbeyond' })).to.be.equal(false); }); - it('request without zone shouldn\'t issue a request', () => { + it('request without zone shouldn\'t issue a request', function () { expect(spec.isBidRequestValid(bid_without_zone)).to.be.equal(false); }); - it('request without host shouldn\'t issue a request', () => { + it('request without host shouldn\'t issue a request', function () { expect(spec.isBidRequestValid(bid_without_host)).to.be.equal(false); }); - it('empty request shouldn\'t generate exception', () => { + it('empty request shouldn\'t generate exception', function () { expect(spec.isBidRequestValid(bid_with_wrong_zoneId)).to.be.equal(false); }); }); - describe('banner request building', () => { + describe('banner request building', function () { let bidRequest; - before(() => { + before(function () { let wmock = sinon.stub(utils, 'getTopWindowLocation').callsFake(() => ({ protocol: 'https:', hostname: 'example.com', @@ -117,33 +117,33 @@ describe('andbeyond adapter', () => { dntmock.restore(); }); - it('should be a first-price auction', () => { + it('should be a first-price auction', function () { expect(bidRequest).to.have.property('at', 1); }); - it('should have banner object', () => { + it('should have banner object', function () { expect(bidRequest.imp[0]).to.have.property('banner'); }); - it('should have w/h', () => { + it('should have w/h', function () { expect(bidRequest.imp[0].banner).to.have.property('format'); expect(bidRequest.imp[0].banner.format).to.be.eql([{w: 300, h: 250}, {w: 300, h: 200}]); }); - it('should respect secure connection', () => { + it('should respect secure connection', function () { expect(bidRequest.imp[0]).to.have.property('secure', 1); }); - it('should have tagid', () => { + it('should have tagid', function () { expect(bidRequest.imp[0]).to.have.property('tagid', 'ad-unit-1'); }); - it('should create proper site block', () => { + it('should create proper site block', function () { expect(bidRequest.site).to.have.property('domain', 'example.com'); expect(bidRequest.site).to.have.property('page', 'https://example.com/index.html'); }); - it('should fill device with caller macro', () => { + it('should fill device with caller macro', function () { expect(bidRequest).to.have.property('device'); expect(bidRequest.device).to.have.property('ip', 'caller'); expect(bidRequest.device).to.have.property('ua', 'caller'); @@ -151,15 +151,15 @@ describe('andbeyond adapter', () => { }); }); - describe('requests routing', () => { - it('should issue a request for each host', () => { + describe('requests routing', function () { + it('should issue a request for each host', function () { let pbRequests = spec.buildRequests([bid1_zone1, bid3_host2]); expect(pbRequests).to.have.length(2); expect(pbRequests[0].url).to.have.string(`//${bid1_zone1.params.host}/`); expect(pbRequests[1].url).to.have.string(`//${bid3_host2.params.host}/`); }); - it('should issue a request for each zone', () => { + it('should issue a request for each zone', function () { let pbRequests = spec.buildRequests([bid1_zone1, bid2_zone2]); expect(pbRequests).to.have.length(2); expect(pbRequests[0].data.zone).to.be.equal(bid1_zone1.params.zoneId); @@ -167,8 +167,8 @@ describe('andbeyond adapter', () => { }); }); - describe('responses processing', () => { - it('should return fully-initialized banner bid-response', () => { + describe('responses processing', function () { + it('should return fully-initialized banner bid-response', function () { let request = spec.buildRequests([bid1_zone1])[0]; let resp = spec.interpretResponse({body: bidResponse1}, request)[0]; expect(resp).to.have.property('requestId', 'Bid_01'); @@ -183,20 +183,20 @@ describe('andbeyond adapter', () => { expect(resp.ad).to.have.string(''); }); - it('should add nurl as pixel for banner response', () => { + it('should add nurl as pixel for banner response', function () { let request = spec.buildRequests([bid1_zone1])[0]; let resp = spec.interpretResponse({body: bidResponse1}, request)[0]; let expectedNurl = bidResponse1.seatbid[0].bid[0].nurl + '&px=1'; expect(resp.ad).to.have.string(expectedNurl); }); - it('should handle bidresponse with user-sync only', () => { + it('should handle bidresponse with user-sync only', function () { let request = spec.buildRequests([bid1_zone1])[0]; let resp = spec.interpretResponse({body: usersyncOnlyResponse}, request); expect(resp).to.have.length(0); }); - it('should perform usersync', () => { + it('should perform usersync', function () { let syncs = spec.getUserSyncs({iframeEnabled: false}, [{body: bidResponse1}]); expect(syncs).to.have.length(0); syncs = spec.getUserSyncs({iframeEnabled: true}, [{body: bidResponse1}]); diff --git a/test/spec/modules/aolBidAdapter_spec.js b/test/spec/modules/aolBidAdapter_spec.js index bc42f69ce63..53113d0a67c 100644 --- a/test/spec/modules/aolBidAdapter_spec.js +++ b/test/spec/modules/aolBidAdapter_spec.js @@ -75,7 +75,7 @@ let getPixels = () => { '\');'; }; -describe('AolAdapter', () => { +describe('AolAdapter', function () { const MARKETPLACE_URL = '//adserver-us.adtech.advertising.com/pubapi/3.0/'; const NEXAGE_URL = '//hb.nexage.com/bidRequest?'; const ONE_DISPLAY_TTL = 60; @@ -92,15 +92,14 @@ describe('AolAdapter', () => { return bidderRequest; } - describe('interpretResponse()', () => { + describe('interpretResponse()', function () { let bidderSettingsBackup; let bidResponse; let bidRequest; let logWarnSpy; - let formatPixelsStub; let isOneMobileBidderStub; - beforeEach(() => { + beforeEach(function () { bidderSettingsBackup = $$PREBID_GLOBAL$$.bidderSettings; bidRequest = { bidderCode: 'test-bidder-code', @@ -111,18 +110,16 @@ describe('AolAdapter', () => { body: getDefaultBidResponse() }; logWarnSpy = sinon.spy(utils, 'logWarn'); - formatPixelsStub = sinon.stub(spec, 'formatPixels'); isOneMobileBidderStub = sinon.stub(spec, 'isOneMobileBidder'); }); - afterEach(() => { + afterEach(function () { $$PREBID_GLOBAL$$.bidderSettings = bidderSettingsBackup; logWarnSpy.restore(); - formatPixelsStub.restore(); isOneMobileBidderStub.restore(); }); - it('should return formatted bid response with required properties', () => { + it('should return formatted bid response with required properties', function () { let formattedBidResponse = spec.interpretResponse(bidResponse, bidRequest); expect(formattedBidResponse).to.deep.equal({ bidderCode: bidRequest.bidderCode, @@ -139,47 +136,26 @@ describe('AolAdapter', () => { ttl: bidRequest.ttl }); }); - - it('should add pixels to ad content when pixels are present in the response', () => { - bidResponse.body.ext = { - pixels: 'pixels-content' - }; - - formatPixelsStub.returns('pixels-content'); - let formattedBidResponse = spec.interpretResponse(bidResponse, bidRequest); - - expect(formattedBidResponse.ad).to.equal(DEFAULT_AD_CONTENT + 'pixels-content'); - }); - - it('should show warning in the console', function() { - $$PREBID_GLOBAL$$.bidderSettings = { - aol: { - bidCpmAdjustment: function() {} - } - }; - spec.interpretResponse(bidResponse, bidRequest); - expect(utils.logWarn.calledOnce).to.be.true; - }); }); - describe('buildRequests()', () => { - it('method exists and is a function', () => { + describe('buildRequests()', function () { + it('method exists and is a function', function () { expect(spec.buildRequests).to.exist.and.to.be.a('function'); }); - describe('Marketplace', () => { - it('should not return request when no bids are present', () => { + describe('Marketplace', function () { + it('should not return request when no bids are present', function () { let [request] = spec.buildRequests([]); expect(request).to.be.empty; }); - it('should return request for Marketplace endpoint', () => { + it('should return request for Marketplace endpoint', function () { let bidRequest = getDefaultBidRequest(); let [request] = spec.buildRequests(bidRequest.bids); expect(request.url).to.contain(MARKETPLACE_URL); }); - it('should return request for Marketplace via onedisplay bidder code', () => { + it('should return request for Marketplace via onedisplay bidder code', function () { let bidRequest = createCustomBidRequest({ bids: [{ bidder: 'onedisplay' @@ -233,7 +209,7 @@ describe('AolAdapter', () => { expect(request).to.be.empty; }); - it('should return Marketplace URL for eu region', () => { + it('should return Marketplace URL for eu region', function () { let bidRequest = createCustomBidRequest({ params: { placement: 1234567, @@ -245,7 +221,7 @@ describe('AolAdapter', () => { expect(request.url).to.contain('adserver-eu.adtech.advertising.com/pubapi/3.0/'); }); - it('should return Marketplace URL for eu region when server option is present', () => { + it('should return Marketplace URL for eu region when server option is present', function () { let bidRequest = createCustomBidRequest({ params: { placement: 1234567, @@ -257,7 +233,7 @@ describe('AolAdapter', () => { expect(request.url).to.contain('adserver-eu.adtech.advertising.com/pubapi/3.0/'); }); - it('should return default Marketplace URL in case of unknown region config option', () => { + it('should return default Marketplace URL in case of unknown region config option', function () { let bidRequest = createCustomBidRequest({ params: { placement: 1234567, @@ -269,25 +245,25 @@ describe('AolAdapter', () => { expect(request.url).to.contain(MARKETPLACE_URL); }); - it('should return url with pubapi bid option', () => { + it('should return url with pubapi bid option', function () { let bidRequest = getDefaultBidRequest(); let [request] = spec.buildRequests(bidRequest.bids); expect(request.url).to.contain('cmd=bid;'); }); - it('should return url with version 2 of pubapi', () => { + it('should return url with version 2 of pubapi', function () { let bidRequest = getDefaultBidRequest(); let [request] = spec.buildRequests(bidRequest.bids); expect(request.url).to.contain('v=2;'); }); - it('should return url with cache busting option', () => { + it('should return url with cache busting option', function () { let bidRequest = getDefaultBidRequest(); let [request] = spec.buildRequests(bidRequest.bids); expect(request.url).to.match(/misc=\d+/); }); - it('should return url with default pageId and sizeId', () => { + it('should return url with default pageId and sizeId', function () { let bidRequest = createCustomBidRequest({ params: { placement: 1234567, @@ -298,7 +274,7 @@ describe('AolAdapter', () => { expect(request.url).to.contain('/pubapi/3.0/9599.1/1234567/0/0/ADTECH;'); }); - it('should return url with custom pageId and sizeId when options are present', () => { + it('should return url with custom pageId and sizeId when options are present', function () { let bidRequest = createCustomBidRequest({ params: { placement: 1234567, @@ -311,13 +287,13 @@ describe('AolAdapter', () => { expect(request.url).to.contain('/pubapi/3.0/9599.1/1234567/1111/2222/ADTECH;'); }); - it('should return url with default alias if alias param is missing', () => { + it('should return url with default alias if alias param is missing', function () { let bidRequest = getDefaultBidRequest(); let [request] = spec.buildRequests(bidRequest.bids); expect(request.url).to.match(/alias=\w+?;/); }); - it('should return url with custom alias if it is present', () => { + it('should return url with custom alias if it is present', function () { let bidRequest = createCustomBidRequest({ params: { placement: 1234567, @@ -329,13 +305,13 @@ describe('AolAdapter', () => { expect(request.url).to.contain('alias=desktop_articlepage_something_box_300_250'); }); - it('should return url without bidfloor option if is is missing', () => { + it('should return url without bidfloor option if is is missing', function () { let bidRequest = getDefaultBidRequest(); let [request] = spec.buildRequests(bidRequest.bids); expect(request.url).not.to.contain('bidfloor='); }); - it('should return url with bidFloor option if it is present', () => { + it('should return url with bidFloor option if it is present', function () { let bidRequest = createCustomBidRequest({ params: { placement: 1234567, @@ -347,7 +323,7 @@ describe('AolAdapter', () => { expect(request.url).to.contain('bidfloor=0.8'); }); - it('should return url with key values if keyValues param is present', () => { + it('should return url with key values if keyValues param is present', function () { let bidRequest = createCustomBidRequest({ params: { placement: 1234567, @@ -363,7 +339,7 @@ describe('AolAdapter', () => { expect(request.url).to.contain('kvage=25;kvheight=3.42;kvtest=key'); }); - it('should return request object for One Display when configuration is present', () => { + it('should return request object for One Display when configuration is present', function () { let bidRequest = getDefaultBidRequest(); let [request] = spec.buildRequests(bidRequest.bids); expect(request.method).to.equal('GET'); @@ -371,8 +347,8 @@ describe('AolAdapter', () => { }); }); - describe('One Mobile', () => { - it('should return One Mobile url when One Mobile get params are present', () => { + describe('One Mobile', function () { + it('should return One Mobile url when One Mobile get params are present', function () { let bidRequest = createCustomBidRequest({ params: getNexageGetBidParams() }); @@ -380,7 +356,7 @@ describe('AolAdapter', () => { expect(request.url).to.contain(NEXAGE_URL); }); - it('should return One Mobile url with different host when host option is present', () => { + it('should return One Mobile url with different host when host option is present', function () { let bidParams = Object.assign({ host: 'qa-hb.nexage.com' }, getNexageGetBidParams()); @@ -391,7 +367,7 @@ describe('AolAdapter', () => { expect(request.url).to.contain('qa-hb.nexage.com/bidRequest?'); }); - it('should return One Mobile url when One Mobile and Marketplace params are present', () => { + it('should return One Mobile url when One Mobile and Marketplace params are present', function () { let bidParams = Object.assign(getNexageGetBidParams(), getMarketplaceBidParams()); let bidRequest = createCustomBidRequest({ params: bidParams @@ -425,7 +401,7 @@ describe('AolAdapter', () => { expect(request).to.be.empty; }); - it('should return One Mobile url with required params - dcn & pos', () => { + it('should return One Mobile url with required params - dcn & pos', function () { let bidRequest = createCustomBidRequest({ params: getNexageGetBidParams() }); @@ -433,7 +409,7 @@ describe('AolAdapter', () => { expect(request.url).to.contain(NEXAGE_URL + 'dcn=2c9d2b50015c5ce9db6aeeed8b9500d6&pos=header'); }); - it('should return One Mobile url with cmd=bid option', () => { + it('should return One Mobile url with cmd=bid option', function () { let bidRequest = createCustomBidRequest({ params: getNexageGetBidParams() }); @@ -441,7 +417,7 @@ describe('AolAdapter', () => { expect(request.url).to.contain('cmd=bid'); }); - it('should return One Mobile url with generic params if ext option is present', () => { + it('should return One Mobile url with generic params if ext option is present', function () { let bidRequest = createCustomBidRequest({ params: { dcn: '54321123', @@ -459,7 +435,7 @@ describe('AolAdapter', () => { '¶m1=val1¶m2=val2¶m3=val3¶m4=val4'); }); - it('should return request object for One Mobile POST endpoint when POST configuration is present', () => { + it('should return request object for One Mobile POST endpoint when POST configuration is present', function () { let bidConfig = getNexagePostBidParams(); let bidRequest = createCustomBidRequest({ params: bidConfig @@ -491,92 +467,62 @@ describe('AolAdapter', () => { }); }); - describe('getUserSyncs()', () => { + describe('getUserSyncs()', function () { + let serverResponses; let bidResponse; - let bidRequest; - beforeEach(() => { - $$PREBID_GLOBAL$$.aolGlobals.pixelsDropped = false; - config.setConfig({ - aol: { - userSyncOn: 'bidResponse' - }, - }); + beforeEach(function () { bidResponse = getDefaultBidResponse(); bidResponse.ext = { pixels: getPixels() }; + + serverResponses = [ + {body: bidResponse} + ]; }); - it('should return user syncs only if userSyncOn equals to "bidResponse"', () => { - let userSyncs = spec.getUserSyncs({}, [bidResponse], bidRequest); + it('should return user syncs if pixels are present in the response', function () { + let userSyncs = spec.getUserSyncs({}, serverResponses); - expect($$PREBID_GLOBAL$$.aolGlobals.pixelsDropped).to.be.true; expect(userSyncs).to.deep.equal([ {type: 'image', url: 'img.org'}, {type: 'iframe', url: 'pixels1.org'} ]); }); - it('should not return user syncs if it has already been returned', () => { - $$PREBID_GLOBAL$$.aolGlobals.pixelsDropped = true; - - let userSyncs = spec.getUserSyncs({}, [bidResponse], bidRequest); - - expect($$PREBID_GLOBAL$$.aolGlobals.pixelsDropped).to.be.true; - expect(userSyncs).to.deep.equal([]); - }); - - it('should not return user syncs if pixels are not present', () => { + it('should not return user syncs if pixels are not present', function () { bidResponse.ext.pixels = null; + let userSyncs = spec.getUserSyncs({}, serverResponses); - let userSyncs = spec.getUserSyncs({}, [bidResponse], bidRequest); - - expect($$PREBID_GLOBAL$$.aolGlobals.pixelsDropped).to.be.false; expect(userSyncs).to.deep.equal([]); }); }); - describe('formatPixels()', () => { - it('should return pixels wrapped for dropping them once and within nested frames ', () => { - let pixels = ''; - let formattedPixels = spec.formatPixels(pixels); - - expect(formattedPixels).to.equal( - ''); - }); - }); - - describe('isOneMobileBidder()', () => { + describe('isOneMobileBidder()', function () { it('should return false when when bidderCode is not present', () => { expect(spec.isOneMobileBidder(null)).to.be.false; }); - it('should return false for unknown bidder code', () => { + it('should return false for unknown bidder code', function () { expect(spec.isOneMobileBidder('unknownBidder')).to.be.false; }); - it('should return true for aol bidder code', () => { + it('should return true for aol bidder code', function () { expect(spec.isOneMobileBidder('aol')).to.be.true; }); - it('should return true for one mobile bidder code', () => { + it('should return true for one mobile bidder code', function () { expect(spec.isOneMobileBidder('onemobile')).to.be.true; }); }); - describe('isConsentRequired()', () => { - it('should return false when consentData object is not present', () => { + describe('isConsentRequired()', function () { + it('should return false when consentData object is not present', function () { expect(spec.isConsentRequired(null)).to.be.false; }); - it('should return true when gdprApplies equals true and consentString is not present', () => { + it('should return true when gdprApplies equals true and consentString is not present', function () { let consentData = { consentString: null, gdprApplies: true @@ -585,7 +531,7 @@ describe('AolAdapter', () => { expect(spec.isConsentRequired(consentData)).to.be.true; }); - it('should return false when consentString is present and gdprApplies equals false', () => { + it('should return false when consentString is present and gdprApplies equals false', function () { let consentData = { consentString: 'consent-string', gdprApplies: false @@ -594,7 +540,7 @@ describe('AolAdapter', () => { expect(spec.isConsentRequired(consentData)).to.be.false; }); - it('should return true when consentString is present and gdprApplies equals true', () => { + it('should return true when consentString is present and gdprApplies equals true', function () { let consentData = { consentString: 'consent-string', gdprApplies: true @@ -604,25 +550,25 @@ describe('AolAdapter', () => { }); }); - describe('formatMarketplaceDynamicParams()', () => { + describe('formatMarketplaceDynamicParams()', function () { let formatConsentDataStub; let formatKeyValuesStub; - beforeEach(() => { + beforeEach(function () { formatConsentDataStub = sinon.stub(spec, 'formatConsentData'); formatKeyValuesStub = sinon.stub(spec, 'formatKeyValues'); }); - afterEach(() => { + afterEach(function () { formatConsentDataStub.restore(); formatKeyValuesStub.restore(); }); - it('should return empty string when params are not present', () => { + it('should return empty string when params are not present', function () { expect(spec.formatMarketplaceDynamicParams()).to.be.equal(''); }); - it('should return formatted params when formatConsentData returns data', () => { + it('should return formatted params when formatConsentData returns data', function () { formatConsentDataStub.returns({ euconsent: 'test-consent', gdpr: 1 @@ -630,7 +576,7 @@ describe('AolAdapter', () => { expect(spec.formatMarketplaceDynamicParams()).to.be.equal('euconsent=test-consent;gdpr=1;'); }); - it('should return formatted params when formatKeyValues returns data', () => { + it('should return formatted params when formatKeyValues returns data', function () { formatKeyValuesStub.returns({ param1: 'val1', param2: 'val2', @@ -639,7 +585,7 @@ describe('AolAdapter', () => { expect(spec.formatMarketplaceDynamicParams()).to.be.equal('param1=val1;param2=val2;param3=val3;'); }); - it('should return formatted bid floor param when it is present', () => { + it('should return formatted bid floor param when it is present', function () { let params = { bidFloor: 0.45 }; @@ -647,25 +593,25 @@ describe('AolAdapter', () => { }); }); - describe('formatOneMobileDynamicParams()', () => { + describe('formatOneMobileDynamicParams()', function () { let consentRequiredStub; let secureProtocolStub; - beforeEach(() => { + beforeEach(function () { consentRequiredStub = sinon.stub(spec, 'isConsentRequired'); secureProtocolStub = sinon.stub(spec, 'isSecureProtocol'); }); - afterEach(() => { + afterEach(function () { consentRequiredStub.restore(); secureProtocolStub.restore(); }); - it('should return empty string when params are not present', () => { + it('should return empty string when params are not present', function () { expect(spec.formatOneMobileDynamicParams()).to.be.equal(''); }); - it('should return formatted params when params are present', () => { + it('should return formatted params when params are present', function () { let params = { param1: 'val1', param2: 'val2', @@ -674,7 +620,7 @@ describe('AolAdapter', () => { expect(spec.formatOneMobileDynamicParams(params)).to.contain('¶m1=val1¶m2=val2¶m3=val3'); }); - it('should return formatted gdpr params when isConsentRequired returns true', () => { + it('should return formatted gdpr params when isConsentRequired returns true', function () { let consentData = { consentString: 'test-consent' }; @@ -682,7 +628,7 @@ describe('AolAdapter', () => { expect(spec.formatOneMobileDynamicParams({}, consentData)).to.be.equal('&gdpr=1&euconsent=test-consent'); }); - it('should return formatted secure param when isSecureProtocol returns true', () => { + it('should return formatted secure param when isSecureProtocol returns true', function () { secureProtocolStub.returns(true); expect(spec.formatOneMobileDynamicParams()).to.be.equal('&secure=1'); }); diff --git a/test/spec/modules/appierBidAdapter_spec.js b/test/spec/modules/appierBidAdapter_spec.js new file mode 100644 index 00000000000..c7fc5744d1c --- /dev/null +++ b/test/spec/modules/appierBidAdapter_spec.js @@ -0,0 +1,174 @@ +import { expect } from 'chai'; +import { spec, API_SERVERS_MAP, ADAPTER_VERSION } from 'modules/appierBidAdapter'; +import { newBidder } from 'src/adapters/bidderFactory'; +import { config } from 'src/config'; + +describe('AppierAdapter', 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('isBidRequestValid', function () { + let bid = { + 'bidder': 'appier', + 'params': { + 'hzid': 'abcd' + }, + 'adUnitCode': 'adunit-code', + 'sizes': [[300, 250], [300, 600]], + 'bidId': '30b31c1838de1e', + 'bidderRequestId': '22edbae2733bf6', + 'auctionId': '1d1a030790a475', + }; + + it('should return true when required params zoneId found', function () { + expect(spec.isBidRequestValid(bid)).to.equal(true); + }); + + it('should return false when required param zoneId is missing', function () { + let bid = Object.assign({}, bid); + bid.params = {}; + expect(spec.isBidRequestValid(bid)).to.equal(false); + }); + + it('should return false when required param zoneId has wrong type', function () { + let bid = Object.assign({}, bid); + bid.params = { + 'hzid': null + }; + expect(spec.isBidRequestValid(bid)).to.equal(false); + }); + }); + + describe('buildRequests', function() { + it('should return an empty list when there are no bid requests', function() { + const fakeBidRequests = []; + const fakeBidderRequest = {}; + expect(spec.buildRequests(fakeBidRequests, fakeBidderRequest)).to.be.an('array').that.is.empty; + }); + + it('should generate a POST bid request with method, url, and data fields', function() { + const bid = { + 'bidder': 'appier', + 'params': { + 'hzid': 'abcd' + }, + 'adUnitCode': 'adunit-code', + 'sizes': [[300, 250], [300, 600]], + 'bidId': '30b31c1838de1e', + 'bidderRequestId': '22edbae2733bf6', + 'auctionId': '1d1a030790a475', + }; + const fakeBidRequests = [bid]; + const fakeBidderRequest = {refererInfo: { + 'referer': 'fakeReferer', + 'reachedTop': true, + 'numIframes': 1, + 'stack': [] + }}; + + const builtRequests = spec.buildRequests(fakeBidRequests, fakeBidderRequest); + expect(builtRequests.length).to.equal(1); + expect(builtRequests[0].method).to.equal('POST'); + expect(builtRequests[0].url).match(/v1\/prebid\/bid/); + expect(builtRequests[0].data).deep.equal({ + 'bids': fakeBidRequests, + 'refererInfo': fakeBidderRequest.refererInfo, + 'version': ADAPTER_VERSION + }); + }); + }); + + describe('interpretResponse', function() { + const bid = { + 'bidder': 'appier', + 'params': { + 'hzid': 'abcd' + }, + 'adUnitCode': 'adunit-code', + 'sizes': [[300, 250], [300, 600]], + 'bidId': '30b31c1838de1e', + 'bidderRequestId': '22edbae2733bf6', + 'auctionId': '1d1a030790a475', + }; + const fakeBidRequests = [bid]; + + it('should return an empty aray to indicate no valid bids', function() { + const fakeServerResponse = {}; + + const bidResponses = spec.interpretResponse(fakeServerResponse, fakeBidRequests); + + expect(bidResponses).is.an('array').that.is.empty; + }); + + it('should generate correct response array for bidder', function() { + const fakeBidResult = { + 'requestId': '30b31c1838de1e', + 'cpm': 0.0029346001, + 'creativeId': 'Idl0P0d5S3Ca5kVWcia-wQ', + 'width': 300, + 'height': 250, + 'currency': 'USD', + 'netRevenue': true, + 'ttl': 300, + 'ad': '
fake html
', + 'appierParams': { + 'hzid': 'test_hzid' + } + }; + const fakeServerResponse = { + headers: [], + body: [fakeBidResult] + }; + + const bidResponses = spec.interpretResponse(fakeServerResponse, fakeBidRequests); + expect(bidResponses).deep.equal([fakeBidResult]); + }); + }); + + describe('getApiServer', function() { + it('should use the server specified by setConfig(appier.server)', function() { + config.setConfig({ + 'appier': {'server': 'fake_server'} + }); + + const server = spec.getApiServer(); + + expect(server).equals('fake_server'); + }); + + it('should retrieve a farm specific hostname if server is not specpfied', function() { + config.setConfig({ + 'appier': {'farm': 'tw'} + }); + + const server = spec.getApiServer(); + + expect(server).equals(API_SERVERS_MAP['tw']); + }); + + it('if farm is not recognized, use the default farm', function() { + config.setConfig({ + 'appier': {'farm': 'no_this_farm'} + }); + + const server = spec.getApiServer(); + + expect(server).equals(API_SERVERS_MAP['default']); + }); + + it('if farm is not specified, use the default farm', function() { + config.setConfig({ + 'appier': {} + }); + + const server = spec.getApiServer(); + + expect(server).equals(API_SERVERS_MAP['default']); + }); + }); +}); diff --git a/test/spec/modules/appnexusBidAdapter_spec.js b/test/spec/modules/appnexusBidAdapter_spec.js index abfd50d1746..b94e574713c 100644 --- a/test/spec/modules/appnexusBidAdapter_spec.js +++ b/test/spec/modules/appnexusBidAdapter_spec.js @@ -5,16 +5,16 @@ import { deepClone } from 'src/utils'; const ENDPOINT = '//ib.adnxs.com/ut/v3/prebid'; -describe('AppNexusAdapter', () => { +describe('AppNexusAdapter', function () { const adapter = newBidder(spec); - describe('inherited functions', () => { - it('exists and is a function', () => { + describe('inherited functions', function () { + it('exists and is a function', function () { expect(adapter.callBids).to.exist.and.to.be.a('function'); }); }); - describe('isBidRequestValid', () => { + describe('isBidRequestValid', function () { let bid = { 'bidder': 'appnexus', 'params': { @@ -27,11 +27,11 @@ describe('AppNexusAdapter', () => { 'auctionId': '1d1a030790a475', }; - it('should return true when required params found', () => { + it('should return true when required params found', function () { expect(spec.isBidRequestValid(bid)).to.equal(true); }); - it('should return true when required params found', () => { + it('should return true when required params found', function () { let bid = Object.assign({}, bid); delete bid.params; bid.params = { @@ -42,7 +42,7 @@ describe('AppNexusAdapter', () => { expect(spec.isBidRequestValid(bid)).to.equal(true); }); - it('should return false when required params are not passed', () => { + it('should return false when required params are not passed', function () { let bid = Object.assign({}, bid); delete bid.params; bid.params = { @@ -52,7 +52,7 @@ describe('AppNexusAdapter', () => { }); }); - describe('buildRequests', () => { + describe('buildRequests', function () { let bidRequests = [ { 'bidder': 'appnexus', @@ -67,7 +67,7 @@ describe('AppNexusAdapter', () => { } ]; - it('should parse out private sizes', () => { + it('should parse out private sizes', function () { let bidRequest = Object.assign({}, bidRequests[0], { @@ -85,7 +85,7 @@ describe('AppNexusAdapter', () => { expect(payload.tags[0].private_sizes).to.deep.equal([{width: 300, height: 250}]); }); - it('should add source and verison to the tag', () => { + it('should add source and verison to the tag', function () { const request = spec.buildRequests(bidRequests); const payload = JSON.parse(request.data); expect(payload.sdk).to.exist; @@ -95,7 +95,7 @@ describe('AppNexusAdapter', () => { }); }); - it('should populate the ad_types array on all requests', () => { + it('should populate the ad_types array on all requests', function () { ['banner', 'video', 'native'].forEach(type => { const bidRequest = Object.assign({}, bidRequests[0]); bidRequest.mediaTypes = {}; @@ -108,7 +108,7 @@ describe('AppNexusAdapter', () => { }); }); - it('should populate the ad_types array on outstream requests', () => { + it('should populate the ad_types array on outstream requests', function () { const bidRequest = Object.assign({}, bidRequests[0]); bidRequest.mediaTypes = {}; bidRequest.mediaTypes.video = {context: 'outstream'}; @@ -119,13 +119,13 @@ describe('AppNexusAdapter', () => { expect(payload.tags[0].ad_types).to.deep.equal(['video']); }); - it('sends bid request to ENDPOINT via POST', () => { + it('sends bid request to ENDPOINT via POST', function () { const request = spec.buildRequests(bidRequests); expect(request.url).to.equal(ENDPOINT); expect(request.method).to.equal('POST'); }); - it('should attach valid video params to the tag', () => { + it('should attach valid video params to the tag', function () { let bidRequest = Object.assign({}, bidRequests[0], { @@ -148,7 +148,7 @@ describe('AppNexusAdapter', () => { }); }); - it('should attach valid user params to the tag', () => { + it('should attach valid user params to the tag', function () { let bidRequest = Object.assign({}, bidRequests[0], { @@ -171,7 +171,7 @@ describe('AppNexusAdapter', () => { }); }); - it('should attach native params to the request', () => { + it('should attach native params to the request', function () { let bidRequest = Object.assign({}, bidRequests[0], { @@ -179,9 +179,19 @@ describe('AppNexusAdapter', () => { nativeParams: { title: {required: true}, body: {required: true}, + body2: {required: true}, image: {required: true, sizes: [{ width: 100, height: 100 }]}, cta: {required: false}, - sponsoredBy: {required: true} + rating: {required: true}, + sponsoredBy: {required: true}, + privacyLink: {required: true}, + displayUrl: {required: true}, + address: {required: true}, + downloads: {required: true}, + likes: {required: true}, + phone: {required: true}, + price: {required: true}, + salePrice: {required: true} } } ); @@ -192,13 +202,23 @@ describe('AppNexusAdapter', () => { expect(payload.tags[0].native.layouts[0]).to.deep.equal({ title: {required: true}, description: {required: true}, + desc2: {required: true}, main_image: {required: true, sizes: [{ width: 100, height: 100 }]}, ctatext: {required: false}, - sponsored_by: {required: true} + rating: {required: true}, + sponsored_by: {required: true}, + privacy_link: {required: true}, + displayurl: {required: true}, + address: {required: true}, + downloads: {required: true}, + likes: {required: true}, + phone: {required: true}, + price: {required: true}, + saleprice: {required: true} }); }); - it('sets minimum native asset params when not provided on adunit', () => { + it('sets minimum native asset params when not provided on adunit', function () { let bidRequest = Object.assign({}, bidRequests[0], { @@ -217,7 +237,7 @@ describe('AppNexusAdapter', () => { }); }); - it('does not overwrite native ad unit params with mimimum params', () => { + it('does not overwrite native ad unit params with mimimum params', function () { let bidRequest = Object.assign({}, bidRequests[0], { @@ -249,7 +269,7 @@ describe('AppNexusAdapter', () => { }); }); - it('should convert keyword params to proper form and attaches to request', () => { + it('should convert keyword params to proper form and attaches to request', function () { let bidRequest = Object.assign({}, bidRequests[0], { @@ -261,6 +281,8 @@ describe('AppNexusAdapter', () => { singleArrNum: [5], multiValMixed: ['value1', 2, 'value3'], singleValNum: 123, + emptyStr: '', + emptyArr: [''], badValue: {'foo': 'bar'} // should be dropped } } @@ -285,10 +307,14 @@ describe('AppNexusAdapter', () => { }, { 'key': 'singleValNum', 'value': ['123'] + }, { + 'key': 'emptyStr' + }, { + 'key': 'emptyArr' }]); }); - it('should add payment rules to the request', () => { + it('should add payment rules to the request', function () { let bidRequest = Object.assign({}, bidRequests[0], { @@ -305,7 +331,7 @@ describe('AppNexusAdapter', () => { expect(payload.tags[0].use_pmt_rule).to.equal(true); }); - it('should add gdpr consent information to the request', () => { + it('should add gdpr consent information to the request', function () { let consentString = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A=='; let bidderRequest = { 'bidderCode': 'appnexus', @@ -326,9 +352,79 @@ describe('AppNexusAdapter', () => { expect(payload.gdpr_consent.consent_string).to.exist.and.to.equal(consentString); expect(payload.gdpr_consent.consent_required).to.exist.and.to.be.true; }); + + it('supports sending hybrid mobile app parameters', function () { + let appRequest = Object.assign({}, + bidRequests[0], + { + params: { + placementId: '10433394', + app: { + id: 'B1O2W3M4AN.com.prebid.webview', + geo: { + lat: 40.0964439, + lng: -75.3009142 + }, + device_id: { + idfa: '4D12078D-3246-4DA4-AD5E-7610481E7AE', // Apple advertising identifier + aaid: '38400000-8cf0-11bd-b23e-10b96e40000d', // Android advertising identifier + md5udid: '5756ae9022b2ea1e47d84fead75220c8', // MD5 hash of the ANDROID_ID + sha1udid: '4DFAA92388699AC6539885AEF1719293879985BF', // SHA1 hash of the ANDROID_ID + windowsadid: '750c6be243f1c4b5c9912b95a5742fc5' // Windows advertising identifier + } + } + } + } + ); + const request = spec.buildRequests([appRequest]); + const payload = JSON.parse(request.data); + expect(payload.app).to.exist; + expect(payload.app).to.deep.equal({ + appid: 'B1O2W3M4AN.com.prebid.webview' + }); + expect(payload.device.device_id).to.exist; + expect(payload.device.device_id).to.deep.equal({ + aaid: '38400000-8cf0-11bd-b23e-10b96e40000d', + idfa: '4D12078D-3246-4DA4-AD5E-7610481E7AE', + md5udid: '5756ae9022b2ea1e47d84fead75220c8', + sha1udid: '4DFAA92388699AC6539885AEF1719293879985BF', + windowsadid: '750c6be243f1c4b5c9912b95a5742fc5' + }); + expect(payload.device.geo).to.exist; + expect(payload.device.geo).to.deep.equal({ + lat: 40.0964439, + lng: -75.3009142 + }); + }); + + it('should add referer info to payload', function () { + const bidRequest = Object.assign({}, bidRequests[0]) + const bidderRequest = { + refererInfo: { + referer: 'http://example.com/page.html', + reachedTop: true, + numIframes: 2, + stack: [ + 'http://example.com/page.html', + 'http://example.com/iframe1.html', + 'http://example.com/iframe2.html' + ] + } + } + const request = spec.buildRequests([bidRequest], bidderRequest); + const payload = JSON.parse(request.data); + + expect(payload.referrer_detection).to.exist; + expect(payload.referrer_detection).to.deep.equal({ + rd_ref: 'http%3A%2F%2Fexample.com%2Fpage.html', + rd_top: true, + rd_ifs: 2, + rd_stk: bidderRequest.refererInfo.stack.map((url) => encodeURIComponent(url)).join(',') + }); + }); }) - describe('interpretResponse', () => { + describe('interpretResponse', function () { let response = { 'version': '3.0.0', 'tags': [ @@ -373,7 +469,7 @@ describe('AppNexusAdapter', () => { ] }; - it('should get correct bid response', () => { + it('should get correct bid response', function () { let expectedResponse = [ { 'requestId': '3db3773286ee59', @@ -387,17 +483,23 @@ describe('AppNexusAdapter', () => { 'currency': 'USD', 'ttl': 300, 'netRevenue': true, + 'adUnitCode': 'code', 'appnexus': { 'buyerMemberId': 958 } } ]; - let bidderRequest; + let bidderRequest = { + bids: [{ + bidId: '3db3773286ee59', + adUnitCode: 'code' + }] + } let result = spec.interpretResponse({ body: response }, {bidderRequest}); expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])); }); - it('handles nobid responses', () => { + it('handles nobid responses', function () { let response = { 'version': '0.0.1', 'tags': [{ @@ -413,7 +515,7 @@ describe('AppNexusAdapter', () => { expect(result.length).to.equal(0); }); - it('handles non-banner media responses', () => { + it('handles non-banner media responses', function () { let response = { 'tags': [{ 'uuid': '84ab500420319d', @@ -429,7 +531,12 @@ describe('AppNexusAdapter', () => { }] }] }; - let bidderRequest; + let bidderRequest = { + bids: [{ + bidId: '84ab500420319d', + adUnitCode: 'code' + }] + } let result = spec.interpretResponse({ body: response }, {bidderRequest}); expect(result[0]).to.have.property('vastUrl'); @@ -437,12 +544,13 @@ describe('AppNexusAdapter', () => { expect(result[0]).to.have.property('mediaType', 'video'); }); - it('handles native responses', () => { + it('handles native responses', function () { let response1 = deepClone(response); response1.tags[0].ads[0].ad_type = 'native'; response1.tags[0].ads[0].rtb.native = { 'title': 'Native Creative', 'desc': 'Cool description great stuff', + 'desc2': 'Additional body text', 'ctatext': 'Do it', 'sponsored': 'AppNexus', 'icon': { @@ -461,8 +569,22 @@ describe('AppNexusAdapter', () => { 'click_trackers': ['http://nym1-ib.adnxs.com/click'] }, 'impression_trackers': ['http://example.com'], + 'rating': '5', + 'displayurl': 'http://AppNexus.com/?url=display_url', + 'likes': '38908320', + 'downloads': '874983', + 'price': '9.99', + 'saleprice': 'FREE', + 'phone': '1234567890', + 'address': '28 W 23rd St, New York, NY 10010', + 'privacy_link': 'http://appnexus.com/?url=privacy_url' }; - let bidderRequest; + let bidderRequest = { + bids: [{ + bidId: '3db3773286ee59', + adUnitCode: 'code' + }] + } let result = spec.interpretResponse({ body: response1 }, {bidderRequest}); expect(result[0].native.title).to.equal('Native Creative'); @@ -471,13 +593,14 @@ describe('AppNexusAdapter', () => { expect(result[0].native.image.url).to.equal('http://cdn.adnxs.com/img.png'); }); - it('supports configuring outstream renderers', () => { + it('supports configuring outstream renderers', function () { const outstreamResponse = deepClone(response); outstreamResponse.tags[0].ads[0].rtb.video = {}; outstreamResponse.tags[0].ads[0].renderer_url = 'renderer.js'; const bidderRequest = { bids: [{ + bidId: '3db3773286ee59', renderer: { options: { adText: 'configured' @@ -491,5 +614,20 @@ describe('AppNexusAdapter', () => { bidderRequest.bids[0].renderer.options ); }); + + it('should add deal_priority and deal_code', function() { + let responseWithDeal = deepClone(response); + responseWithDeal.tags[0].ads[0].deal_priority = 'high'; + responseWithDeal.tags[0].ads[0].deal_code = '123'; + + let bidderRequest = { + bids: [{ + bidId: '3db3773286ee59', + adUnitCode: 'code' + }] + } + let result = spec.interpretResponse({ body: responseWithDeal }, {bidderRequest}); + expect(Object.keys(result[0].appnexus)).to.include.members(['buyerMemberId', 'dealPriority', 'dealCode']); + }); }); }); diff --git a/test/spec/modules/arteebeeBidAdapter_spec.js b/test/spec/modules/arteebeeBidAdapter_spec.js index 041b48b0bc9..013e1bd6c0c 100644 --- a/test/spec/modules/arteebeeBidAdapter_spec.js +++ b/test/spec/modules/arteebeeBidAdapter_spec.js @@ -1,9 +1,9 @@ import {expect} from 'chai'; import {spec} from 'modules/arteebeeBidAdapter'; -describe('Arteebee adapater', () => { - describe('Test validate req', () => { - it('should accept minimum valid bid', () => { +describe('Arteebee adapater', function () { + describe('Test validate req', function () { + it('should accept minimum valid bid', function () { let bid = { bidder: 'arteebee', params: { @@ -16,7 +16,7 @@ describe('Arteebee adapater', () => { expect(isValid).to.equal(true); }); - it('should reject missing pub', () => { + it('should reject missing pub', function () { let bid = { bidder: 'arteebee', params: { @@ -28,7 +28,7 @@ describe('Arteebee adapater', () => { expect(isValid).to.equal(false); }); - it('should reject missing source', () => { + it('should reject missing source', function () { let bid = { bidder: 'arteebee', params: { @@ -41,8 +41,8 @@ describe('Arteebee adapater', () => { }); }); - describe('Test build request', () => { - it('minimum request', () => { + describe('Test build request', function () { + it('minimum request', function () { let bid = { bidder: 'arteebee', params: { @@ -59,7 +59,7 @@ describe('Arteebee adapater', () => { expect(req.imp[0]).to.not.have.property('secure'); }); - it('make test request', () => { + it('make test request', function () { let bid = { bidder: 'arteebee', params: { @@ -77,7 +77,7 @@ describe('Arteebee adapater', () => { expect(req.imp[0]).to.not.have.property('secure'); }); - it('test coppa', () => { + it('test coppa', function () { let bid = { bidder: 'arteebee', params: { @@ -95,7 +95,7 @@ describe('Arteebee adapater', () => { expect(req.imp[0]).to.not.have.property('secure'); }); - it('test gdpr', () => { + it('test gdpr', function () { let bid = { bidder: 'arteebee', params: { @@ -124,8 +124,8 @@ describe('Arteebee adapater', () => { }); }); - describe('Test interpret response', () => { - it('General banner response', () => { + describe('Test interpret response', function () { + it('General banner response', function () { let resp = spec.interpretResponse({ body: { id: 'abcd', diff --git a/test/spec/modules/atomxBidAdapter_spec.js b/test/spec/modules/atomxBidAdapter_spec.js index fdbb01a1838..fdcdb55ec7f 100644 --- a/test/spec/modules/atomxBidAdapter_spec.js +++ b/test/spec/modules/atomxBidAdapter_spec.js @@ -1,9 +1,9 @@ import { expect } from 'chai'; import { spec } from 'modules/atomxBidAdapter'; -describe('atomxAdapterTest', () => { - describe('bidRequestValidity', () => { - it('bidRequest with id param', () => { +describe('atomxAdapterTest', function () { + describe('bidRequestValidity', function () { + it('bidRequest with id param', function () { expect(spec.isBidRequestValid({ bidder: 'atomx', params: { @@ -12,7 +12,7 @@ describe('atomxAdapterTest', () => { })).to.equal(true); }); - it('bidRequest with no id param', () => { + it('bidRequest with no id param', function () { expect(spec.isBidRequestValid({ bidder: 'atomx', params: { @@ -21,7 +21,7 @@ describe('atomxAdapterTest', () => { }); }); - describe('bidRequest', () => { + describe('bidRequest', function () { const bidRequests = [{ 'bidder': 'atomx', 'params': { @@ -47,21 +47,21 @@ describe('atomxAdapterTest', () => { 'auctionId': 'e97cafd0-ebfc-4f5c-b7c9-baa0fd335a4a' }]; - it('bidRequest HTTP method', () => { + it('bidRequest HTTP method', function () { const requests = spec.buildRequests(bidRequests); requests.forEach(function(requestItem) { expect(requestItem.method).to.equal('GET'); }); }); - it('bidRequest url', () => { + it('bidRequest url', function () { const requests = spec.buildRequests(bidRequests); requests.forEach(function(requestItem) { expect(requestItem.url).to.match(new RegExp('p\\.ato\\.mx/placement')); }); }); - it('bidRequest data', () => { + it('bidRequest data', function () { const requests = spec.buildRequests(bidRequests); expect(requests[0].data.id).to.equal('123'); expect(requests[0].data.size).to.equal('300x250'); @@ -72,7 +72,7 @@ describe('atomxAdapterTest', () => { }); }); - describe('interpretResponse', () => { + describe('interpretResponse', function () { const bidRequest = { 'method': 'GET', 'url': 'https://p.ato.mx/placement', @@ -103,7 +103,7 @@ describe('atomxAdapterTest', () => { headers: {} }; - it('result is correct', () => { + it('result is correct', function () { const result = spec.interpretResponse(bidResponse, bidRequest); expect(result[0].requestId).to.equal('22aidtbx5eabd9'); diff --git a/test/spec/modules/audienceNetworkBidAdapter_spec.js b/test/spec/modules/audienceNetworkBidAdapter_spec.js index c61cd04c422..2f7e5776354 100644 --- a/test/spec/modules/audienceNetworkBidAdapter_spec.js +++ b/test/spec/modules/audienceNetworkBidAdapter_spec.js @@ -19,37 +19,37 @@ const placementId = 'test-placement-id'; const playerwidth = 320; const playerheight = 180; const requestId = 'test-request-id'; -const debug = 'adapterver=1.0.0&platform=241394079772386&platver=$prebid.version$'; +const debug = 'adapterver=1.1.0&platform=241394079772386&platver=$prebid.version$&cb=test-uuid'; const pageUrl = encodeURIComponent(utils.getTopWindowUrl()); -describe('AudienceNetwork adapter', () => { - describe('Public API', () => { - it('code', () => { +describe('AudienceNetwork adapter', function () { + describe('Public API', function () { + it('code', function () { expect(code).to.equal(bidder); }); - it('supportedMediaTypes', () => { + it('supportedMediaTypes', function () { expect(supportedMediaTypes).to.deep.equal(['banner', 'video']); }); - it('isBidRequestValid', () => { + it('isBidRequestValid', function () { expect(isBidRequestValid).to.be.a('function'); }); - it('buildRequests', () => { + it('buildRequests', function () { expect(buildRequests).to.be.a('function'); }); - it('interpretResponse', () => { + it('interpretResponse', function () { expect(interpretResponse).to.be.a('function'); }); }); - describe('isBidRequestValid', () => { - it('missing placementId parameter', () => { + describe('isBidRequestValid', function () { + it('missing placementId parameter', function () { expect(isBidRequestValid({ bidder, sizes: [[300, 250]] })).to.equal(false); }); - it('invalid sizes parameter', () => { + it('invalid sizes parameter', function () { expect(isBidRequestValid({ bidder, sizes: ['', undefined, null, '300x100', [300, 100], [300], {}], @@ -57,7 +57,7 @@ describe('AudienceNetwork adapter', () => { })).to.equal(false); }); - it('valid when at least one valid size', () => { + it('valid when at least one valid size', function () { expect(isBidRequestValid({ bidder, sizes: [[1, 1], [300, 250]], @@ -65,7 +65,7 @@ describe('AudienceNetwork adapter', () => { })).to.equal(true); }); - it('valid parameters', () => { + it('valid parameters', function () { expect(isBidRequestValid({ bidder, sizes: [[300, 250], [320, 50]], @@ -73,7 +73,7 @@ describe('AudienceNetwork adapter', () => { })).to.equal(true); }); - it('fullwidth', () => { + it('fullwidth', function () { expect(isBidRequestValid({ bidder, sizes: [[300, 250], [336, 280]], @@ -84,7 +84,7 @@ describe('AudienceNetwork adapter', () => { })).to.equal(true); }); - it('native', () => { + it('native', function () { expect(isBidRequestValid({ bidder, sizes: [[300, 250]], @@ -95,7 +95,7 @@ describe('AudienceNetwork adapter', () => { })).to.equal(true); }); - it('native with non-IAB size', () => { + it('native with non-IAB size', function () { expect(isBidRequestValid({ bidder, sizes: [[728, 90]], @@ -106,7 +106,7 @@ describe('AudienceNetwork adapter', () => { })).to.equal(true); }); - it('video', () => { + it('video', function () { expect(isBidRequestValid({ bidder, sizes: [[playerwidth, playerheight]], @@ -118,21 +118,22 @@ describe('AudienceNetwork adapter', () => { }); }); - describe('buildRequests', () => { - let isSafariBrowserStub; - before(() => { - isSafariBrowserStub = sinon.stub(utils, 'isSafariBrowser'); + describe('buildRequests', function () { + before(function () { + sinon + .stub(utils, 'generateUUID') + .returns('test-uuid'); }); - after(() => { - isSafariBrowserStub.restore(); + after(function () { + utils.generateUUID.restore(); }); - it('can build URL for IAB unit', () => { + it('can build URL for IAB unit', function () { expect(buildRequests([{ bidder, bidId: requestId, - sizes: [[300, 250], [320, 50]], + sizes: [[300, 50], [300, 250], [320, 50]], params: { placementId } }])).to.deep.equal([{ adformats: ['300x250'], @@ -144,7 +145,7 @@ describe('AudienceNetwork adapter', () => { }]); }); - it('can build URL for video unit', () => { + it('can build URL for video unit', function () { expect(buildRequests([{ bidder, bidId: requestId, @@ -163,7 +164,7 @@ describe('AudienceNetwork adapter', () => { }]); }); - it('can build URL for native unit in non-IAB size', () => { + it('can build URL for native unit in non-IAB size', function () { expect(buildRequests([{ bidder, bidId: requestId, @@ -182,38 +183,32 @@ describe('AudienceNetwork adapter', () => { }]); }); - it('can build URL for fullwidth 300x250 unit', () => { + it('can build URL for deprecated fullwidth unit, overriding platform', function () { + const platform = 'test-platform'; + const debugPlatform = debug.replace('241394079772386', platform); + expect(buildRequests([{ bidder, bidId: requestId, sizes: [[300, 250]], params: { placementId, + platform, format: 'fullwidth' } }])).to.deep.equal([{ - adformats: ['fullwidth'], + adformats: ['300x250'], method: 'GET', requestIds: [requestId], sizes: ['300x250'], url: 'https://an.facebook.com/v2/placementbid.json', - data: `placementids[]=test-placement-id&adformats[]=fullwidth&testmode=false&pageurl=${pageUrl}&sdk[]=5.5.web&${debug}` + data: `placementids[]=test-placement-id&adformats[]=300x250&testmode=false&pageurl=${pageUrl}&sdk[]=5.5.web&${debugPlatform}` }]); }); - - it('can build URL on Safari that includes a cachebuster param', () => { - isSafariBrowserStub.returns(true); - expect(buildRequests([{ - bidder, - bidId: requestId, - sizes: [[300, 250]], - params: { placementId } - }])[0].data).to.contain('&cb='); - }); }); - describe('interpretResponse', () => { - it('error in response', () => { + describe('interpretResponse', function () { + it('error in response', function () { expect(interpretResponse({ body: { errors: ['test-error-message'] @@ -221,7 +216,7 @@ describe('AudienceNetwork adapter', () => { }, {})).to.deep.equal([]); }); - it('valid native bid in response', () => { + it('valid native bid in response', function () { const [bidResponse] = interpretResponse({ body: { errors: [], @@ -249,6 +244,7 @@ describe('AudienceNetwork adapter', () => { .to.contain(`placementid:'${placementId}',format:'native',bidid:'test-bid-id'`, 'ad missing parameters') .and.to.contain('getElementsByTagName("style")', 'ad missing native styles') .and.to.contain('
', 'ad missing native container'); + expect(bidResponse.ttl).to.equal(600); expect(bidResponse.creativeId).to.equal(placementId); expect(bidResponse.netRevenue).to.equal(true); expect(bidResponse.currency).to.equal('USD'); @@ -259,7 +255,7 @@ describe('AudienceNetwork adapter', () => { expect(bidResponse.fb_placementid).to.equal(placementId); }); - it('valid IAB bid in response', () => { + it('valid IAB bid in response', function () { const [bidResponse] = interpretResponse({ body: { errors: [], @@ -287,6 +283,7 @@ describe('AudienceNetwork adapter', () => { .to.contain(`placementid:'${placementId}',format:'300x250',bidid:'test-bid-id'`, 'ad missing parameters') .and.not.to.contain('getElementsByTagName("style")', 'ad should not contain native styles') .and.not.to.contain('
', 'ad should not contain native container'); + expect(bidResponse.ttl).to.equal(600); expect(bidResponse.creativeId).to.equal(placementId); expect(bidResponse.netRevenue).to.equal(true); expect(bidResponse.currency).to.equal('USD'); @@ -296,7 +293,7 @@ describe('AudienceNetwork adapter', () => { expect(bidResponse.fb_placementid).to.equal(placementId); }); - it('filters invalid slot sizes', () => { + it('filters invalid slot sizes', function () { const [bidResponse] = interpretResponse({ body: { errors: [], @@ -320,6 +317,7 @@ describe('AudienceNetwork adapter', () => { expect(bidResponse.requestId).to.equal(requestId); expect(bidResponse.width).to.equal(300); expect(bidResponse.height).to.equal(250); + expect(bidResponse.ttl).to.equal(600); expect(bidResponse.creativeId).to.equal(placementId); expect(bidResponse.netRevenue).to.equal(true); expect(bidResponse.currency).to.equal('USD'); @@ -329,7 +327,7 @@ describe('AudienceNetwork adapter', () => { expect(bidResponse.fb_placementid).to.equal(placementId); }); - it('valid multiple bids in response', () => { + it('valid multiple bids in response', function () { const placementIdNative = 'test-placement-id-native'; const placementIdIab = 'test-placement-id-iab'; @@ -364,6 +362,7 @@ describe('AudienceNetwork adapter', () => { expect(bidResponseNative.width).to.equal(300); expect(bidResponseNative.height).to.equal(250); expect(bidResponseNative.ad).to.contain(`placementid:'${placementIdNative}',format:'native',bidid:'test-bid-id-native'`, 'ad missing parameters'); + expect(bidResponseNative.ttl).to.equal(600); expect(bidResponseNative.creativeId).to.equal(placementIdNative); expect(bidResponseNative.netRevenue).to.equal(true); expect(bidResponseNative.currency).to.equal('USD'); @@ -377,6 +376,7 @@ describe('AudienceNetwork adapter', () => { expect(bidResponseIab.width).to.equal(300); expect(bidResponseIab.height).to.equal(250); expect(bidResponseIab.ad).to.contain(`placementid:'${placementIdIab}',format:'300x250',bidid:'test-bid-id-iab'`, 'ad missing parameters'); + expect(bidResponseIab.ttl).to.equal(600); expect(bidResponseIab.creativeId).to.equal(placementIdIab); expect(bidResponseIab.netRevenue).to.equal(true); expect(bidResponseIab.currency).to.equal('USD'); @@ -386,7 +386,7 @@ describe('AudienceNetwork adapter', () => { expect(bidResponseIab.fb_placementid).to.equal(placementIdIab); }); - it('valid video bid in response', () => { + it('valid video bid in response', function () { const bidId = 'test-bid-id-video'; const [bidResponse] = interpretResponse({ @@ -410,13 +410,14 @@ describe('AudienceNetwork adapter', () => { expect(bidResponse.cpm).to.equal(1.23); expect(bidResponse.requestId).to.equal(requestId); + expect(bidResponse.ttl).to.equal(3600); expect(bidResponse.mediaType).to.equal('video'); expect(bidResponse.vastUrl).to.equal(`https://an.facebook.com/v1/instream/vast.xml?placementid=${placementId}&pageurl=${pageUrl}&playerwidth=${playerwidth}&playerheight=${playerheight}&bidid=${bidId}`); expect(bidResponse.width).to.equal(playerwidth); expect(bidResponse.height).to.equal(playerheight); }); - it('mixed video and native bids', () => { + it('mixed video and native bids', function () { const videoPlacementId = 'test-video-placement-id'; const videoBidId = 'test-video-bid-id'; const nativePlacementId = 'test-native-placement-id'; @@ -450,6 +451,7 @@ describe('AudienceNetwork adapter', () => { expect(bidResponseVideo.cpm).to.equal(1.23); expect(bidResponseVideo.requestId).to.equal(requestId); + expect(bidResponseVideo.ttl).to.equal(3600); expect(bidResponseVideo.mediaType).to.equal('video'); expect(bidResponseVideo.vastUrl).to.equal(`https://an.facebook.com/v1/instream/vast.xml?placementid=${videoPlacementId}&pageurl=${pageUrl}&playerwidth=${playerwidth}&playerheight=${playerheight}&bidid=${videoBidId}`); expect(bidResponseVideo.width).to.equal(playerwidth); @@ -457,12 +459,13 @@ describe('AudienceNetwork adapter', () => { expect(bidResponseNative.cpm).to.equal(4.56); expect(bidResponseNative.requestId).to.equal(requestId); + expect(bidResponseNative.ttl).to.equal(600); expect(bidResponseNative.width).to.equal(300); expect(bidResponseNative.height).to.equal(250); expect(bidResponseNative.ad).to.contain(`placementid:'${nativePlacementId}',format:'native',bidid:'${nativeBidId}'`); }); - it('mixture of valid native bid and error in response', () => { + it('mixture of valid native bid and error in response', function () { const [bidResponse] = interpretResponse({ body: { errors: ['test-error-message'], @@ -490,6 +493,7 @@ describe('AudienceNetwork adapter', () => { .to.contain(`placementid:'${placementId}',format:'native',bidid:'test-bid-id'`, 'ad missing parameters') .and.to.contain('getElementsByTagName("style")', 'ad missing native styles') .and.to.contain('
', 'ad missing native container'); + expect(bidResponse.ttl).to.equal(600); expect(bidResponse.creativeId).to.equal(placementId); expect(bidResponse.netRevenue).to.equal(true); expect(bidResponse.currency).to.equal('USD'); diff --git a/test/spec/modules/beachfrontBidAdapter_spec.js b/test/spec/modules/beachfrontBidAdapter_spec.js index fb149d59aee..b369ed1f941 100644 --- a/test/spec/modules/beachfrontBidAdapter_spec.js +++ b/test/spec/modules/beachfrontBidAdapter_spec.js @@ -1,11 +1,12 @@ import { expect } from 'chai'; import { spec, VIDEO_ENDPOINT, BANNER_ENDPOINT, OUTSTREAM_SRC, DEFAULT_MIMES } from 'modules/beachfrontBidAdapter'; import * as utils from 'src/utils'; +import { parse as parseUrl } from 'src/url'; -describe('BeachfrontAdapter', () => { +describe('BeachfrontAdapter', function () { let bidRequests; - beforeEach(() => { + beforeEach(function () { bidRequests = [ { bidder: 'beachfront', @@ -31,13 +32,13 @@ describe('BeachfrontAdapter', () => { ]; }); - describe('spec.isBidRequestValid', () => { - it('should return true when the required params are passed', () => { + describe('spec.isBidRequestValid', function () { + it('should return true when the required params are passed', function () { const bidRequest = bidRequests[0]; expect(spec.isBidRequestValid(bidRequest)).to.equal(true); }); - it('should return false when the "bidfloor" param is missing', () => { + it('should return false when the "bidfloor" param is missing', function () { const bidRequest = bidRequests[0]; bidRequest.params = { appId: '11bc5dd5-7421-4dd8-c926-40fa653bec76' @@ -45,7 +46,7 @@ describe('BeachfrontAdapter', () => { expect(spec.isBidRequestValid(bidRequest)).to.equal(false); }); - it('should return false when the "appId" param is missing', () => { + it('should return false when the "appId" param is missing', function () { const bidRequest = bidRequests[0]; bidRequest.params = { bidfloor: 5.00 @@ -53,19 +54,19 @@ describe('BeachfrontAdapter', () => { expect(spec.isBidRequestValid(bidRequest)).to.equal(false); }); - it('should return false when no bid params are passed', () => { + it('should return false when no bid params are passed', function () { const bidRequest = bidRequests[0]; bidRequest.params = {}; expect(spec.isBidRequestValid(bidRequest)).to.equal(false); }); - it('should return false when a bid request is not passed', () => { + it('should return false when a bid request is not passed', function () { expect(spec.isBidRequestValid()).to.equal(false); expect(spec.isBidRequestValid({})).to.equal(false); }); - describe('for multi-format bids', () => { - it('should return true when the required params are passed for video', () => { + describe('for multi-format bids', function () { + it('should return true when the required params are passed for video', function () { const bidRequest = bidRequests[0]; bidRequest.mediaTypes = { video: {} @@ -79,7 +80,7 @@ describe('BeachfrontAdapter', () => { expect(spec.isBidRequestValid(bidRequest)).to.equal(true); }); - it('should return false when the required params are missing for video', () => { + it('should return false when the required params are missing for video', function () { const bidRequest = bidRequests[0]; bidRequest.mediaTypes = { video: {} @@ -93,7 +94,7 @@ describe('BeachfrontAdapter', () => { expect(spec.isBidRequestValid(bidRequest)).to.equal(false); }); - it('should return true when the required params are passed for banner', () => { + it('should return true when the required params are passed for banner', function () { const bidRequest = bidRequests[0]; bidRequest.mediaTypes = { banner: {} @@ -107,7 +108,7 @@ describe('BeachfrontAdapter', () => { expect(spec.isBidRequestValid(bidRequest)).to.equal(true); }); - it('should return false when the required params are missing for banner', () => { + it('should return false when the required params are missing for banner', function () { const bidRequest = bidRequests[0]; bidRequest.mediaTypes = { banner: {} @@ -123,9 +124,9 @@ describe('BeachfrontAdapter', () => { }); }); - describe('spec.buildRequests', () => { - describe('for video bids', () => { - it('should attach the bid request object', () => { + describe('spec.buildRequests', function () { + describe('for video bids', function () { + it('should attach the bid request object', function () { bidRequests[0].mediaTypes = { video: {} }; bidRequests[1].mediaTypes = { video: {} }; const requests = spec.buildRequests(bidRequests); @@ -133,7 +134,7 @@ describe('BeachfrontAdapter', () => { expect(requests[1].bidRequest).to.equal(bidRequests[1]); }); - it('should create a POST request for each bid', () => { + it('should create a POST request for each bid', function () { const bidRequest = bidRequests[0]; bidRequest.mediaTypes = { video: {} }; const requests = spec.buildRequests([ bidRequest ]); @@ -141,7 +142,7 @@ describe('BeachfrontAdapter', () => { expect(requests[0].url).to.equal(VIDEO_ENDPOINT + bidRequest.params.appId); }); - it('should attach request data', () => { + it('should attach request data', function () { const width = 640; const height = 480; const bidRequest = bidRequests[0]; @@ -150,9 +151,14 @@ describe('BeachfrontAdapter', () => { playerSize: [ width, height ] } }; - const requests = spec.buildRequests([ bidRequest ]); + const topLocation = parseUrl('http://www.example.com?foo=bar', { decodeSearchAsString: true }); + const bidderRequest = { + refererInfo: { + referer: topLocation.href + } + }; + const requests = spec.buildRequests([ bidRequest ], bidderRequest); const data = requests[0].data; - const topLocation = utils.getTopWindowLocation(); expect(data.isPrebid).to.equal(true); expect(data.appId).to.equal(bidRequest.params.appId); expect(data.domain).to.equal(document.location.hostname); @@ -164,7 +170,7 @@ describe('BeachfrontAdapter', () => { expect(data.cur).to.deep.equal(['USD']); }); - it('must parse bid size from a nested array', () => { + it('must parse bid size from a nested array', function () { const width = 640; const height = 480; const bidRequest = bidRequests[0]; @@ -178,7 +184,7 @@ describe('BeachfrontAdapter', () => { expect(data.imp[0].video).to.deep.contain({ w: width, h: height }); }); - it('must parse bid size from a string', () => { + it('must parse bid size from a string', function () { const width = 640; const height = 480; const bidRequest = bidRequests[0]; @@ -192,7 +198,7 @@ describe('BeachfrontAdapter', () => { expect(data.imp[0].video).to.deep.contain({ w: width, h: height }); }); - it('must handle an empty bid size', () => { + it('must handle an empty bid size', function () { const bidRequest = bidRequests[0]; bidRequest.mediaTypes = { video: { @@ -204,7 +210,7 @@ describe('BeachfrontAdapter', () => { expect(data.imp[0].video).to.deep.contain({ w: undefined, h: undefined }); }); - it('must fall back to the size on the bid object', () => { + it('must fall back to the size on the bid object', function () { const width = 640; const height = 480; const bidRequest = bidRequests[0]; @@ -215,17 +221,19 @@ describe('BeachfrontAdapter', () => { expect(data.imp[0].video).to.deep.contain({ w: width, h: height }); }); - it('must override video targeting params', () => { + it('must override video targeting params', function () { const bidRequest = bidRequests[0]; const mimes = ['video/webm']; + const playbackmethod = 2; + const maxduration = 30; bidRequest.mediaTypes = { video: {} }; - bidRequest.params.video = { mimes }; + bidRequest.params.video = { mimes, playbackmethod, maxduration }; const requests = spec.buildRequests([ bidRequest ]); const data = requests[0].data; - expect(data.imp[0].video).to.deep.contain({ mimes }); + expect(data.imp[0].video).to.deep.contain({ mimes, playbackmethod, maxduration }); }); - it('must add GDPR consent data to the request', () => { + it('must add GDPR consent data to the request', function () { const bidRequest = bidRequests[0]; bidRequest.mediaTypes = { video: {} }; const consentString = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A=='; @@ -242,15 +250,15 @@ describe('BeachfrontAdapter', () => { }); }); - describe('for banner bids', () => { - it('should attach the bid requests array', () => { + describe('for banner bids', function () { + it('should attach the bid requests array', function () { bidRequests[0].mediaTypes = { banner: {} }; bidRequests[1].mediaTypes = { banner: {} }; const requests = spec.buildRequests(bidRequests); expect(requests[0].bidRequest).to.deep.equal(bidRequests); }); - it('should create a single POST request for all bids', () => { + it('should create a single POST request for all bids', function () { bidRequests[0].mediaTypes = { banner: {} }; bidRequests[1].mediaTypes = { banner: {} }; const requests = spec.buildRequests(bidRequests); @@ -259,7 +267,7 @@ describe('BeachfrontAdapter', () => { expect(requests[0].url).to.equal(BANNER_ENDPOINT); }); - it('should attach request data', () => { + it('should attach request data', function () { const width = 300; const height = 250; const bidRequest = bidRequests[0]; @@ -268,9 +276,14 @@ describe('BeachfrontAdapter', () => { sizes: [ width, height ] } }; - const requests = spec.buildRequests([ bidRequest ]); + const topLocation = parseUrl('http://www.example.com?foo=bar', { decodeSearchAsString: true }); + const bidderRequest = { + refererInfo: { + referer: topLocation.href + } + }; + const requests = spec.buildRequests([ bidRequest ], bidderRequest); const data = requests[0].data; - const topLocation = utils.getTopWindowLocation(); expect(data.slots).to.deep.equal([ { slot: bidRequest.adUnitCode, @@ -285,7 +298,7 @@ describe('BeachfrontAdapter', () => { expect(data.ua).to.equal(navigator.userAgent); }); - it('must parse bid size from a nested array', () => { + it('must parse bid size from a nested array', function () { const width = 300; const height = 250; const bidRequest = bidRequests[0]; @@ -301,7 +314,7 @@ describe('BeachfrontAdapter', () => { ]); }); - it('must parse bid size from a string', () => { + it('must parse bid size from a string', function () { const width = 300; const height = 250; const bidRequest = bidRequests[0]; @@ -317,7 +330,7 @@ describe('BeachfrontAdapter', () => { ]); }); - it('must handle an empty bid size', () => { + it('must handle an empty bid size', function () { const bidRequest = bidRequests[0]; bidRequest.mediaTypes = { banner: { @@ -329,7 +342,7 @@ describe('BeachfrontAdapter', () => { expect(data.slots[0].sizes).to.deep.equal([]); }); - it('must fall back to the size on the bid object', () => { + it('must fall back to the size on the bid object', function () { const width = 300; const height = 250; const bidRequest = bidRequests[0]; @@ -340,7 +353,7 @@ describe('BeachfrontAdapter', () => { expect(data.slots[0].sizes).to.deep.contain({ w: width, h: height }); }); - it('must add GDPR consent data to the request', () => { + it('must add GDPR consent data to the request', function () { const bidRequest = bidRequests[0]; bidRequest.mediaTypes = { banner: {} }; const consentString = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A=='; @@ -357,8 +370,8 @@ describe('BeachfrontAdapter', () => { }); }); - describe('for multi-format bids', () => { - it('should create a POST request for each bid format', () => { + describe('for multi-format bids', function () { + it('should create a POST request for each bid format', function () { const width = 300; const height = 250; const bidRequest = bidRequests[0]; @@ -386,7 +399,7 @@ describe('BeachfrontAdapter', () => { expect(requests[1].url).to.contain(BANNER_ENDPOINT); }); - it('must parse bid sizes for each bid format', () => { + it('must parse bid sizes for each bid format', function () { const bidRequest = bidRequests[0]; bidRequest.mediaTypes = { video: { @@ -413,16 +426,16 @@ describe('BeachfrontAdapter', () => { }); }); - describe('spec.interpretResponse', () => { - describe('for video bids', () => { - it('should return no bids if the response is not valid', () => { + describe('spec.interpretResponse', function () { + describe('for video bids', function () { + it('should return no bids if the response is not valid', function () { const bidRequest = bidRequests[0]; bidRequest.mediaTypes = { video: {} }; const bidResponse = spec.interpretResponse({ body: null }, { bidRequest }); expect(bidResponse.length).to.equal(0); }); - it('should return no bids if the response "url" is missing', () => { + it('should return no bids if the response "url" is missing', function () { const bidRequest = bidRequests[0]; bidRequest.mediaTypes = { video: {} }; const serverResponse = { @@ -432,7 +445,7 @@ describe('BeachfrontAdapter', () => { expect(bidResponse.length).to.equal(0); }); - it('should return no bids if the response "bidPrice" is missing', () => { + it('should return no bids if the response "bidPrice" is missing', function () { const bidRequest = bidRequests[0]; bidRequest.mediaTypes = { video: {} }; const serverResponse = { @@ -442,7 +455,7 @@ describe('BeachfrontAdapter', () => { expect(bidResponse.length).to.equal(0); }); - it('should return a valid video bid response', () => { + it('should return a valid video bid response', function () { const width = 640; const height = 480; const bidRequest = bidRequests[0]; @@ -473,7 +486,7 @@ describe('BeachfrontAdapter', () => { }); }); - it('should return a renderer for outstream video bids', () => { + it('should return a renderer for outstream video bids', function () { const bidRequest = bidRequests[0]; bidRequest.mediaTypes = { video: { @@ -493,22 +506,22 @@ describe('BeachfrontAdapter', () => { }); }); - describe('for banner bids', () => { - it('should return no bids if the response is not valid', () => { + describe('for banner bids', function () { + it('should return no bids if the response is not valid', function () { const bidRequest = bidRequests[0]; bidRequest.mediaTypes = { banner: {} }; const bidResponse = spec.interpretResponse({ body: null }, { bidRequest }); expect(bidResponse.length).to.equal(0); }); - it('should return no bids if the response is empty', () => { + it('should return no bids if the response is empty', function () { const bidRequest = bidRequests[0]; bidRequest.mediaTypes = { banner: {} }; const bidResponse = spec.interpretResponse({ body: [] }, { bidRequest }); expect(bidResponse.length).to.equal(0); }); - it('should return valid banner bid responses', () => { + it('should return valid banner bid responses', function () { bidRequests[0].mediaTypes = { banner: { sizes: [[ 300, 250 ], [ 728, 90 ]] @@ -555,11 +568,11 @@ describe('BeachfrontAdapter', () => { }); }); - describe('spec.getUserSyncs', () => { - describe('for video bids', () => { + describe('spec.getUserSyncs', function () { + describe('for video bids', function () { let bidResponse; - beforeEach(() => { + beforeEach(function () { bidResponse = { bidPrice: 5.00, url: 'http://reachms.bfmio.com/getmu?aid=bid:19c4a196-fb21-4c81-9a1a-ecc5437a39da', @@ -567,7 +580,7 @@ describe('BeachfrontAdapter', () => { }; }); - it('should return an iframe user sync if iframes are enabled', () => { + it('should return an iframe user sync if iframes are enabled', function () { const syncOptions = { iframeEnabled: true, pixelEnabled: true @@ -580,7 +593,7 @@ describe('BeachfrontAdapter', () => { expect(userSyncs[0].type).to.equal('iframe'); }); - it('should return an image user sync if iframes are disabled', () => { + it('should return an image user sync if iframes are disabled', function () { const syncOptions = { iframeEnabled: false, pixelEnabled: true @@ -593,7 +606,7 @@ describe('BeachfrontAdapter', () => { expect(userSyncs[0].type).to.equal('image'); }); - it('should not return user syncs if none are enabled', () => { + it('should not return user syncs if none are enabled', function () { const syncOptions = { iframeEnabled: false, pixelEnabled: false @@ -606,10 +619,10 @@ describe('BeachfrontAdapter', () => { }); }); - describe('for banner bids', () => { + describe('for banner bids', function () { let bidResponse; - beforeEach(() => { + beforeEach(function () { bidResponse = { slot: bidRequests[0].adUnitCode, adm: '
', @@ -620,7 +633,7 @@ describe('BeachfrontAdapter', () => { }; }); - it('should return user syncs defined the bid response', () => { + it('should return user syncs defined the bid response', function () { const syncUrl = 'http://sync.bfmio.com/sync_iframe?ifpl=5&ifg=1&id=test&gdpr=0&gc=&gce=0'; const syncOptions = { iframeEnabled: true, @@ -638,7 +651,7 @@ describe('BeachfrontAdapter', () => { ]); }); - it('should not return user syncs if iframes are disabled', () => { + it('should not return user syncs if iframes are disabled', function () { const syncUrl = 'http://sync.bfmio.com/sync_iframe?ifpl=5&ifg=1&id=test&gdpr=0&gc=&gce=0'; const syncOptions = { iframeEnabled: false, @@ -654,7 +667,7 @@ describe('BeachfrontAdapter', () => { expect(userSyncs).to.deep.equal([]); }); - it('should not return user syncs if there are none in the bid response', () => { + it('should not return user syncs if there are none in the bid response', function () { const syncOptions = { iframeEnabled: true, pixelEnabled: true diff --git a/test/spec/modules/betweenBidAdapter_spec.js b/test/spec/modules/betweenBidAdapter_spec.js index a99417067f8..f2d770805c5 100644 --- a/test/spec/modules/betweenBidAdapter_spec.js +++ b/test/spec/modules/betweenBidAdapter_spec.js @@ -1,30 +1,29 @@ import { expect } from 'chai'; import { spec } from 'modules/betweenBidAdapter'; -describe('betweenBidAdapterTests', () => { - it('validate_pub_params', () => { +describe('betweenBidAdapterTests', function () { + it('validate_pub_params', function () { expect(spec.isBidRequestValid({ bidder: 'between', params: { - placementId: 'example', w: 240, h: 400, s: 1112 } })).to.equal(true); }); - it('validate_generated_params', () => { + it('validate_generated_params', function () { let bidRequestData = [{ bidId: 'bid1234', bidder: 'between', - params: {w: 240, h: 400, s: 1112, placementId: 'example'}, + params: {w: 240, h: 400, s: 1112}, sizes: [[240, 400]] }] let request = spec.buildRequests(bidRequestData); let req_data = request[0].data; expect(req_data.bidid).to.equal('bid1234'); }); - it('validate_response_params', () => { + it('validate_response_params', function () { let serverResponse = { body: [{ bidid: 'bid1234', @@ -42,6 +41,28 @@ describe('betweenBidAdapterTests', () => { expect(bid.currency).to.equal('USD'); expect(bid.width).to.equal(240); expect(bid.height).to.equal(400); + expect(bid.netRevenue).to.equal(true); + expect(bid.requestId).to.equal('bid1234'); + expect(bid.ad).to.equal('Ad html'); + }); + it('validate_response_params', function () { + let serverResponse = { + body: [{ + bidid: 'bid1234', + w: 240, + h: 400, + currency: 'USD', + ad: 'Ad html' + }] + }; + let bids = spec.interpretResponse(serverResponse); + expect(bids).to.have.lengthOf(1); + let bid = bids[0]; + expect(bid.cpm).to.equal(0); + expect(bid.currency).to.equal('USD'); + expect(bid.width).to.equal(240); + expect(bid.height).to.equal(400); + expect(bid.netRevenue).to.equal(true); expect(bid.requestId).to.equal('bid1234'); expect(bid.ad).to.equal('Ad html'); }); diff --git a/test/spec/modules/bidfluenceBidAdapter_spec.js b/test/spec/modules/bidfluenceBidAdapter_spec.js new file mode 100644 index 00000000000..9ce6e808c6b --- /dev/null +++ b/test/spec/modules/bidfluenceBidAdapter_spec.js @@ -0,0 +1,114 @@ +import { expect } from 'chai'; +import { spec } from 'modules/bidfluenceBidAdapter'; + +const BIDDER_CODE = 'bidfluence'; +const PLACEMENT_ID = '1000'; +const PUB_ID = '1000'; +const CONSENT_STRING = 'DUXDSDFSFWRRR8345F=='; + +const validBidRequests = [{ + 'bidder': BIDDER_CODE, + 'params': { + 'placementId': PLACEMENT_ID, + 'publisherId': PUB_ID, + 'reservePrice': 0 + }, + 'adUnitCode': 'adunit-code', + 'sizes': [[300, 250]], + 'bidId': '2b1f23307fb8ef', + 'bidderRequestId': '10edf38ec1a719', + 'auctionId': '1025ba77-5463-4877-b0eb-14b205cb9304' +}]; + +const bidderRequest = { + 'bidderCode': 'bidfluence', + 'auctionId': '1025ba77-5463-4877-b0eb-14b205cb9304', + 'bidderRequestId': '10edf38ec1a719', + 'refererInfo': { + 'numIframes': 0, + 'reachedTop': true, + 'referer': 'test', + 'stack': ['test'] + }, + 'timeout': 1000, + 'gdprConsent': { + 'gdprApplies': true, + 'consentString': CONSENT_STRING, + 'vendorData': '' + } +}; + +bidderRequest.bids = validBidRequests; + +describe('Bidfluence Adapter test', () => { + describe('isBidRequestValid', function () { + it('should return true when required params found', function () { + expect(spec.isBidRequestValid(validBidRequests[0])).to.equal(true); + }); + it('should return the right bidder code', function () { + expect(spec.code).to.eql(BIDDER_CODE); + }); + }); + + describe('buildRequests', function () { + const request = spec.buildRequests(validBidRequests, bidderRequest); + + it('sends bid request to our endpoint via POST', function () { + expect(request.method).to.equal('POST'); + }); + + const payload = JSON.parse(request.data); + + expect(payload.bids[0].bid).to.equal(validBidRequests[0].bidId); + expect(payload.azr).to.equal(true); + expect(payload.ck).to.not.be.undefined; + expect(payload.bids[0].tid).to.equal(PLACEMENT_ID); + expect(payload.bids[0].pid).to.equal(PUB_ID); + expect(payload.bids[0].rp).to.be.a('number'); + expect(payload.re).to.not.be.undefined; + expect(payload.st).to.not.be.undefined; + expect(payload.tz).to.not.be.undefined; + expect(payload.sr).to.not.be.undefined; + expect(payload.vp).to.not.be.undefined; + expect(payload.sdt).to.not.be.undefined; + expect(payload.bids[0].w).to.equal('300'); + expect(payload.bids[0].h).to.equal('250'); + + it('sends gdpr info if exists', function () { + expect(payload.gdpr).to.equal(true); + expect(payload.gdprc).to.equal(CONSENT_STRING); + }); + }); + + describe('interpretResponse', function () { + const response = { + body: { + Bids: + [{ + 'CreativeId': '1000', + 'Cpm': 0.50, + 'Ad': '
', + 'Height': 250, + 'Width': 300 + }] + } + }; + + it('should get correct bid response', function () { + const expectedResponse = [{ + requestId: response.body.Bids[0].BidId, + cpm: response.body.Bids[0].Cpm, + width: response.body.Bids[0].Width, + height: response.body.Bids[0].Height, + creativeId: response.body.Bids[0].CreativeId, + ad: response.body.Bids[0].Ad, + currency: 'USD', + netRevenue: true, + ttl: 360 + }]; + + let result = spec.interpretResponse(response, { 'bidderRequest': validBidRequests[0] }); + expect(result).to.deep.equal(expectedResponse); + }); + }); +}); diff --git a/test/spec/modules/bizzclickBidAdapter_spec.js b/test/spec/modules/bizzclickBidAdapter_spec.js index 39587791bba..6f518f32ccf 100644 --- a/test/spec/modules/bizzclickBidAdapter_spec.js +++ b/test/spec/modules/bizzclickBidAdapter_spec.js @@ -1,7 +1,7 @@ import {expect} from 'chai'; import {spec} from '../../../modules/bizzclickBidAdapter'; -describe('BizzclickBidAdapter', () => { +describe('BizzclickBidAdapter', function () { let bid = { bidId: '67d581a232281d', bidder: 'bizzclickBidAdapter', @@ -16,31 +16,31 @@ describe('BizzclickBidAdapter', () => { transactionId: '3bb2f6da-87a6-4029-aeb0-1b244bbfb5' }; - describe('isBidRequestValid', () => { - it('Should return true when placement_id can be cast to a number', () => { + describe('isBidRequestValid', function () { + it('Should return true when placement_id can be cast to a number', function () { expect(spec.isBidRequestValid(bid)).to.be.true; }); - it('Should return false when placement_id is not a number', () => { + it('Should return false when placement_id is not a number', function () { bid.params.placementId = 'aaa'; expect(spec.isBidRequestValid(bid)).to.be.false; }); }); - describe('buildRequests', () => { + describe('buildRequests', function () { let serverRequest = spec.buildRequests([bid]); - it('Creates a ServerRequest object with method, URL and data', () => { + it('Creates a ServerRequest object with method, URL and data', function () { expect(serverRequest).to.exist; expect(serverRequest.method).to.exist; expect(serverRequest.url).to.exist; expect(serverRequest.data).to.exist; }); - it('Returns POST method', () => { + it('Returns POST method', function () { expect(serverRequest.method).to.equal('POST'); }); - it('Returns valid URL', () => { + it('Returns valid URL', function () { expect(serverRequest.url).to.equal('//supply.bizzclick.com/?c=o&m=multi'); }); - it('Returns valid data if array of bids is valid', () => { + it('Returns valid data if array of bids is valid', function () { let data = serverRequest.data; expect(data).to.be.an('object'); expect(data).to.have.all.keys('deviceWidth', 'deviceHeight', 'secure', 'host', 'page', 'placements'); @@ -59,13 +59,13 @@ describe('BizzclickBidAdapter', () => { expect(placement.sizes).to.be.an('array'); } }); - it('Returns empty data if no valid requests are passed', () => { + it('Returns empty data if no valid requests are passed', function () { serverRequest = spec.buildRequests([]); let data = serverRequest.data; expect(data.placements).to.be.an('array').that.is.empty; }); }); - describe('interpretResponse', () => { + describe('interpretResponse', function () { let resObject = { body: [ { requestId: '123', @@ -81,7 +81,7 @@ describe('BizzclickBidAdapter', () => { }] }; let serverResponses = spec.interpretResponse(resObject); - it('Returns an array of valid server responses if response object is valid', () => { + it('Returns an array of valid server responses if response object is valid', function () { expect(serverResponses).to.be.an('array').that.is.not.empty; for (let i = 0; i < serverResponses.length; i++) { let dataItem = serverResponses[i]; @@ -97,16 +97,16 @@ describe('BizzclickBidAdapter', () => { expect(dataItem.currency).to.be.a('string'); expect(dataItem.mediaType).to.be.a('string'); } - it('Returns an empty array if invalid response is passed', () => { + it('Returns an empty array if invalid response is passed', function () { serverResponses = spec.interpretResponse('invalid_response'); expect(serverResponses).to.be.an('array').that.is.empty; }); }); }); - describe('getUserSyncs', () => { + describe('getUserSyncs', function () { let userSync = spec.getUserSyncs(); - it('Returns valid URL and type', () => { + it('Returns valid URL and type', function () { expect(userSync).to.be.an('array').with.lengthOf(1); expect(userSync[0].type).to.exist; expect(userSync[0].url).to.exist; diff --git a/test/spec/modules/brainyBidAdapter_spec.js b/test/spec/modules/brainyBidAdapter_spec.js index 157356e82db..a3ce90d927a 100644 --- a/test/spec/modules/brainyBidAdapter_spec.js +++ b/test/spec/modules/brainyBidAdapter_spec.js @@ -64,17 +64,17 @@ const invalidSyncBidResponse = [{ } }]; -describe('brainy Adapter', () => { - describe('request', () => { - it('should validate bid request', () => { +describe('brainy Adapter', function () { + describe('request', function () { + it('should validate bid request', function () { expect(spec.isBidRequestValid(validBidReq)).to.equal(true); }); - it('should not validate incorrect bid request', () => { + it('should not validate incorrect bid request', function () { expect(spec.isBidRequestValid(invalidBidReq)).to.equal(false); }); }); - describe('build request', () => { - it('Verify bid request', () => { + describe('build request', function () { + it('Verify bid request', function () { const request = spec.buildRequests(bidReq); expect(request[0].method).to.equal('GET'); expect(request[0].url).to.equal(URL); @@ -83,14 +83,14 @@ describe('brainy Adapter', () => { }); }); - describe('interpretResponse', () => { - it('should build bid array', () => { + describe('interpretResponse', function () { + it('should build bid array', function () { const request = spec.buildRequests(bidReq); const result = spec.interpretResponse({body: bidResponse}, request[0]); expect(result.length).to.equal(1); }); - it('should have all relevant fields', () => { + it('should have all relevant fields', function () { const request = spec.buildRequests(bidReq); const result = spec.interpretResponse({body: bidResponse}, request[0]); const bid = result[0]; @@ -101,25 +101,25 @@ describe('brainy Adapter', () => { }); }); - describe('spec.getUserSyncs', () => { + describe('spec.getUserSyncs', function () { let syncOptions - beforeEach(() => { + beforeEach(function () { syncOptions = { enabledBidders: ['brainy'], pixelEnabled: true } }); - it('sucess with usersync url', () => { + it('sucess with usersync url', function () { const result = []; result.push({type: 'image', url: '//testparm.com/ssp-sync/p/sync?uid=2110180601155125000059&buyer=2&slot=34'}); expect(spec.getUserSyncs(syncOptions, bidSyncResponse)).to.deep.equal(result); }); - it('sucess without usersync url', () => { + it('sucess without usersync url', function () { const result = []; expect(spec.getUserSyncs(syncOptions, invalidSyncBidResponse)).to.deep.equal(result); }); - it('empty response', () => { + it('empty response', function () { const serverResponse = [{body: {}}]; const result = []; expect(spec.getUserSyncs(syncOptions, serverResponse)).to.deep.equal(result); diff --git a/test/spec/modules/bridgewellBidAdapter_spec.js b/test/spec/modules/bridgewellBidAdapter_spec.js index 5dae3c474ac..6ca9675a1bb 100644 --- a/test/spec/modules/bridgewellBidAdapter_spec.js +++ b/test/spec/modules/bridgewellBidAdapter_spec.js @@ -169,13 +169,13 @@ describe('bridgewellBidAdapter', function () { ]; const adapter = newBidder(spec); - describe('inherited functions', () => { - it('exists and is a function', () => { + describe('inherited functions', function () { + it('exists and is a function', function () { expect(adapter.callBids).to.exist.and.to.be.a('function'); }); }); - describe('isBidRequestValid', () => { + describe('isBidRequestValid', function () { let bidWithoutCpmWeight = { 'bidder': 'bridgewell', 'params': { @@ -227,18 +227,18 @@ describe('bridgewellBidAdapter', function () { 'auctionId': '1d1a030790a475', }; - it('should return true when required params found', () => { + it('should return true when required params found', function () { expect(spec.isBidRequestValid(bidWithoutCpmWeight)).to.equal(true); expect(spec.isBidRequestValid(bidWithCorrectCpmWeight)).to.equal(true); expect(spec.isBidRequestValid(bidWithUncorrectCpmWeight)).to.equal(false); expect(spec.isBidRequestValid(bidWithZeroCpmWeight)).to.equal(false); }); - it('should return false when required params not found', () => { + it('should return false when required params not found', function () { expect(spec.isBidRequestValid({})).to.equal(false); }); - it('should return false when required params are not passed', () => { + it('should return false when required params are not passed', function () { let bidWithoutCpmWeight = Object.assign({}, bidWithoutCpmWeight); let bidWithCorrectCpmWeight = Object.assign({}, bidWithCorrectCpmWeight); let bidWithUncorrectCpmWeight = Object.assign({}, bidWithUncorrectCpmWeight); @@ -272,8 +272,8 @@ describe('bridgewellBidAdapter', function () { }); }); - describe('buildRequests', () => { - it('should attach valid params to the tag', () => { + describe('buildRequests', function () { + it('should attach valid params to the tag', function () { const request = spec.buildRequests(bidRequests); const payload = request.data; const adUnits = payload.adUnits; @@ -286,14 +286,14 @@ describe('bridgewellBidAdapter', function () { } }); - it('should attach validBidRequests to the tag', () => { + it('should attach validBidRequests to the tag', function () { const request = spec.buildRequests(bidRequests); const validBidRequests = request.validBidRequests; expect(validBidRequests).to.deep.equal(bidRequests); }); }); - describe('interpretResponse', () => { + describe('interpretResponse', function () { const request = spec.buildRequests(bidRequests); const serverResponses = [ { @@ -440,7 +440,7 @@ describe('bridgewellBidAdapter', function () { } ]; - it('should return all required parameters', () => { + it('should return all required parameters', function () { const result = spec.interpretResponse({'body': serverResponses}, request); result.every(res => expect(res.cpm).to.be.a('number')); result.every(res => expect(res.width).to.be.a('number')); @@ -457,12 +457,12 @@ describe('bridgewellBidAdapter', function () { }); }); - it('should give up bid if server response is undefiend', () => { + it('should give up bid if server response is undefiend', function () { const result = spec.interpretResponse({'body': undefined}, request); expect(result).to.deep.equal([]); }); - it('should give up bid if request sizes is missing', () => { + it('should give up bid if request sizes is missing', function () { let target = Object.assign({}, serverResponses[0]); target.consumed = false; const result = spec.interpretResponse({'body': [target]}, spec.buildRequests([{ @@ -478,7 +478,7 @@ describe('bridgewellBidAdapter', function () { expect(result).to.deep.equal([]); }); - it('should give up bid if response sizes is invalid', () => { + it('should give up bid if response sizes is invalid', function () { let target = { 'id': 'e5b10774-32bf-4931-85ee-05095e8cff21', 'bidder_code': 'bridgewell', @@ -495,7 +495,7 @@ describe('bridgewellBidAdapter', function () { expect(result).to.deep.equal([]); }); - it('should give up bid if cpm is missing', () => { + it('should give up bid if cpm is missing', function () { let target = { 'id': 'e5b10774-32bf-4931-85ee-05095e8cff21', 'bidder_code': 'bridgewell', @@ -511,7 +511,7 @@ describe('bridgewellBidAdapter', function () { expect(result).to.deep.equal([]); }); - it('should give up bid if width or height is missing', () => { + it('should give up bid if width or height is missing', function () { let target = { 'id': 'e5b10774-32bf-4931-85ee-05095e8cff21', 'bidder_code': 'bridgewell', @@ -526,7 +526,7 @@ describe('bridgewellBidAdapter', function () { expect(result).to.deep.equal([]); }); - it('should give up bid if ad is missing', () => { + it('should give up bid if ad is missing', function () { let target = { 'id': 'e5b10774-32bf-4931-85ee-05095e8cff21', 'bidder_code': 'bridgewell', @@ -543,7 +543,7 @@ describe('bridgewellBidAdapter', function () { expect(result).to.deep.equal([]); }); - it('should give up bid if revenue mode is missing', () => { + it('should give up bid if revenue mode is missing', function () { let target = { 'id': 'e5b10774-32bf-4931-85ee-05095e8cff21', 'bidder_code': 'bridgewell', @@ -559,7 +559,7 @@ describe('bridgewellBidAdapter', function () { expect(result).to.deep.equal([]); }); - it('should give up bid if currency is missing', () => { + it('should give up bid if currency is missing', function () { let target = { 'id': 'e5b10774-32bf-4931-85ee-05095e8cff21', 'bidder_code': 'bridgewell', @@ -575,7 +575,7 @@ describe('bridgewellBidAdapter', function () { expect(result).to.deep.equal([]); }); - it('should give up bid if mediaType is missing', () => { + it('should give up bid if mediaType is missing', function () { let target = { 'id': 'e5b10774-32bf-4931-85ee-05095e8cff21', 'bidder_code': 'bridgewell', @@ -592,7 +592,7 @@ describe('bridgewellBidAdapter', function () { expect(result).to.deep.equal([]); }); - it('should give up bid if property native of mediaType native is missing', () => { + it('should give up bid if property native of mediaType native is missing', function () { let target = { 'id': '0e4048d3-5c74-4380-a21a-00ba35629f7d', 'bidder_code': 'bridgewell', @@ -609,7 +609,7 @@ describe('bridgewellBidAdapter', function () { expect(result).to.deep.equal([]); }); - it('should give up bid if native title is missing', () => { + it('should give up bid if native title is missing', function () { let target = { 'id': '0e4048d3-5c74-4380-a21a-00ba35629f7d', 'bidder_code': 'bridgewell', @@ -643,7 +643,7 @@ describe('bridgewellBidAdapter', function () { expect(result).to.deep.equal([]); }); - it('should give up bid if native title is too long', () => { + it('should give up bid if native title is too long', function () { let target = { 'id': '0e4048d3-5c74-4380-a21a-00ba35629f7d', 'bidder_code': 'bridgewell', @@ -678,7 +678,7 @@ describe('bridgewellBidAdapter', function () { expect(result).to.deep.equal([]); }); - it('should give up bid if native body is missing', () => { + it('should give up bid if native body is missing', function () { let target = { 'id': '0e4048d3-5c74-4380-a21a-00ba35629f7d', 'bidder_code': 'bridgewell', @@ -711,7 +711,7 @@ describe('bridgewellBidAdapter', function () { const result = spec.interpretResponse({'body': [target]}, request); expect(result).to.deep.equal([]); - it('should give up bid if native image url is missing', () => { + it('should give up bid if native image url is missing', function () { let target = { 'id': '0e4048d3-5c74-4380-a21a-00ba35629f7d', 'bidder_code': 'bridgewell', @@ -746,7 +746,7 @@ describe('bridgewellBidAdapter', function () { }); }); - it('should give up bid if native image is missing', () => { + it('should give up bid if native image is missing', function () { let target = { 'id': '0e4048d3-5c74-4380-a21a-00ba35629f7d', 'bidder_code': 'bridgewell', @@ -776,7 +776,7 @@ describe('bridgewellBidAdapter', function () { expect(result).to.deep.equal([]); }); - it('should give up bid if native image url is missing', () => { + it('should give up bid if native image url is missing', function () { let target = { 'id': '0e4048d3-5c74-4380-a21a-00ba35629f7d', 'bidder_code': 'bridgewell', @@ -808,7 +808,7 @@ describe('bridgewellBidAdapter', function () { expect(result).to.deep.equal([]); }); - it('should give up bid if native image sizes is unmatch', () => { + it('should give up bid if native image sizes is unmatch', function () { let target = { 'id': '0e4048d3-5c74-4380-a21a-00ba35629f7d', 'bidder_code': 'bridgewell', @@ -841,7 +841,7 @@ describe('bridgewellBidAdapter', function () { expect(result).to.deep.equal([]); }); - it('should give up bid if native sponsoredBy is missing', () => { + it('should give up bid if native sponsoredBy is missing', function () { let target = { 'id': '0e4048d3-5c74-4380-a21a-00ba35629f7d', 'bidder_code': 'bridgewell', @@ -875,7 +875,7 @@ describe('bridgewellBidAdapter', function () { expect(result).to.deep.equal([]); }); - it('should give up bid if native icon is missing', () => { + it('should give up bid if native icon is missing', function () { let target = { 'id': '0e4048d3-5c74-4380-a21a-00ba35629f7d', 'bidder_code': 'bridgewell', @@ -905,7 +905,7 @@ describe('bridgewellBidAdapter', function () { expect(result).to.deep.equal([]); }); - it('should give up bid if native icon url is missing', () => { + it('should give up bid if native icon url is missing', function () { let target = { 'id': '0e4048d3-5c74-4380-a21a-00ba35629f7d', 'bidder_code': 'bridgewell', @@ -939,7 +939,7 @@ describe('bridgewellBidAdapter', function () { expect(result).to.deep.equal([]); }); - it('should give up bid if native icon sizes is unmatch', () => { + it('should give up bid if native icon sizes is unmatch', function () { let target = { 'id': '0e4048d3-5c74-4380-a21a-00ba35629f7d', 'bidder_code': 'bridgewell', @@ -972,7 +972,7 @@ describe('bridgewellBidAdapter', function () { expect(result).to.deep.equal([]); }); - it('should give up bid if native clickUrl is missing', () => { + it('should give up bid if native clickUrl is missing', function () { let target = { 'id': '0e4048d3-5c74-4380-a21a-00ba35629f7d', 'bidder_code': 'bridgewell', @@ -1006,7 +1006,7 @@ describe('bridgewellBidAdapter', function () { expect(result).to.deep.equal([]); }); - it('should give up bid if native clickTrackers is missing', () => { + it('should give up bid if native clickTrackers is missing', function () { let target = { 'id': '0e4048d3-5c74-4380-a21a-00ba35629f7d', 'bidder_code': 'bridgewell', @@ -1040,7 +1040,7 @@ describe('bridgewellBidAdapter', function () { expect(result).to.deep.equal([]); }); - it('should give up bid if native clickTrackers is empty', () => { + it('should give up bid if native clickTrackers is empty', function () { let target = { 'id': '0e4048d3-5c74-4380-a21a-00ba35629f7d', 'bidder_code': 'bridgewell', @@ -1075,7 +1075,7 @@ describe('bridgewellBidAdapter', function () { expect(result).to.deep.equal([]); }); - it('should give up bid if native impressionTrackers is missing', () => { + it('should give up bid if native impressionTrackers is missing', function () { let target = { 'id': '0e4048d3-5c74-4380-a21a-00ba35629f7d', 'bidder_code': 'bridgewell', @@ -1109,7 +1109,7 @@ describe('bridgewellBidAdapter', function () { expect(result).to.deep.equal([]); }); - it('should give up bid if native impressionTrackers is empty', () => { + it('should give up bid if native impressionTrackers is empty', function () { let target = { 'id': '0e4048d3-5c74-4380-a21a-00ba35629f7d', 'bidder_code': 'bridgewell', @@ -1144,7 +1144,7 @@ describe('bridgewellBidAdapter', function () { expect(result).to.deep.equal([]); }); - it('should give up bid if mediaType is not support', () => { + it('should give up bid if mediaType is not support', function () { let target = { 'id': '0e4048d3-5c74-4380-a21a-00ba35629f7d', 'bidder_code': 'bridgewell', diff --git a/test/spec/modules/c1xBidAdapter_spec.js b/test/spec/modules/c1xBidAdapter_spec.js index bd7fa5df669..268ad46d0ce 100644 --- a/test/spec/modules/c1xBidAdapter_spec.js +++ b/test/spec/modules/c1xBidAdapter_spec.js @@ -5,16 +5,16 @@ import { newBidder } from 'src/adapters/bidderFactory'; const ENDPOINT = 'https://ht.c1exchange.com/ht'; const BIDDER_CODE = 'c1x'; -describe('C1XAdapter', () => { +describe('C1XAdapter', function () { const adapter = newBidder(c1xAdapter); - describe('inherited functions', () => { - it('exists and is a function', () => { + describe('inherited functions', function () { + it('exists and is a function', function () { expect(adapter.callBids).to.exist.and.to.be.a('function'); }); }); - describe('isBidRequestValid', () => { + describe('isBidRequestValid', function () { let bid = { 'bidder': BIDDER_CODE, 'adUnitCode': 'adunit-code', @@ -24,11 +24,11 @@ describe('C1XAdapter', () => { } }; - it('should return true when required params are passed', () => { + it('should return true when required params are passed', function () { expect(c1xAdapter.isBidRequestValid(bid)).to.equal(true); }); - it('should return false when required params are not found', () => { + it('should return false when required params are not found', function () { let bid = Object.assign({}, bid); delete bid.params; bid.params = { @@ -38,7 +38,7 @@ describe('C1XAdapter', () => { }); }); - describe('buildRequests', () => { + describe('buildRequests', function () { let bidRequests = [ { 'bidder': BIDDER_CODE, @@ -61,19 +61,19 @@ describe('C1XAdapter', () => { return parsedData; }; - it('sends bid request to ENDPOINT via GET', () => { + it('sends bid request to ENDPOINT via GET', function () { const request = c1xAdapter.buildRequests(bidRequests); expect(request.url).to.equal(ENDPOINT); expect(request.method).to.equal('GET'); }); - it('should generate correct bid Id tag', () => { + it('should generate correct bid Id tag', function () { const request = c1xAdapter.buildRequests(bidRequests); expect(request.bids[0].adUnitCode).to.equal('adunit-code'); expect(request.bids[0].bidId).to.equal('30b31c1838de1e'); }); - it('should convert params to proper form and attach to request', () => { + it('should convert params to proper form and attach to request', function () { const request = c1xAdapter.buildRequests(bidRequests); const originalPayload = parseRequest(request.data); const payloadObj = JSON.parse(originalPayload); @@ -83,7 +83,7 @@ describe('C1XAdapter', () => { expect(payloadObj.site).to.equal('9999'); }); - it('should convert floor price to proper form and attach to request', () => { + it('should convert floor price to proper form and attach to request', function () { let bidRequest = Object.assign({}, bidRequests[0], { @@ -100,7 +100,7 @@ describe('C1XAdapter', () => { expect(payloadObj.a1p).to.equal('4.35'); }); - it('should convert pageurl to proper form and attach to request', () => { + it('should convert pageurl to proper form and attach to request', function () { let bidRequest = Object.assign({}, bidRequests[0], { @@ -115,7 +115,7 @@ describe('C1XAdapter', () => { expect(payloadObj.pageurl).to.equal('http://c1exchange.com/'); }); - it('should convert GDPR Consent to proper form and attach to request', () => { + it('should convert GDPR Consent to proper form and attach to request', function () { let consentString = 'BOP2gFWOQIFovABABAENBGAAAAAAMw'; let bidderRequest = { 'bidderCode': 'c1x', @@ -134,7 +134,7 @@ describe('C1XAdapter', () => { }); }); - describe('interpretResponse', () => { + describe('interpretResponse', function () { let response = { 'bid': true, 'cpm': 1.5, @@ -146,7 +146,7 @@ describe('C1XAdapter', () => { 'bidType': 'GROSS_BID' }; - it('should get correct bid response', () => { + it('should get correct bid response', function () { let expectedResponse = [ { width: 300, @@ -169,7 +169,7 @@ describe('C1XAdapter', () => { expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])); }); - it('handles nobid responses', () => { + it('handles nobid responses', function () { let response = { bid: false, adId: 'c1x-test' diff --git a/test/spec/modules/ccxBidAdapter_spec.js b/test/spec/modules/ccxBidAdapter_spec.js index 535b3906a27..292503c9e04 100644 --- a/test/spec/modules/ccxBidAdapter_spec.js +++ b/test/spec/modules/ccxBidAdapter_spec.js @@ -2,7 +2,7 @@ import { expect } from 'chai'; import { spec } from 'modules/ccxBidAdapter'; import * as utils from 'src/utils'; -describe('ccxAdapter', () => { +describe('ccxAdapter', function () { let bids = [ { adUnitCode: 'banner', @@ -39,17 +39,17 @@ describe('ccxAdapter', () => { transactionId: 'aefddd38-cfa0-48ab-8bdd-325de4bab5f9' } ]; - describe('isBidRequestValid', () => { - it('Valid bid requests', () => { + describe('isBidRequestValid', function () { + it('Valid bid requests', function () { expect(spec.isBidRequestValid(bids[0])).to.be.true; expect(spec.isBidRequestValid(bids[1])).to.be.true; }); - it('Invalid bid reqeusts - no placementId', () => { + it('Invalid bid reqeusts - no placementId', function () { let bidsClone = utils.deepClone(bids); bidsClone[0].params = undefined; expect(spec.isBidRequestValid(bidsClone[0])).to.be.false; }); - it('Invalid bid reqeusts - invalid banner sizes', () => { + it('Invalid bid reqeusts - invalid banner sizes', function () { let bidsClone = utils.deepClone(bids); bidsClone[0].mediaTypes.banner.sizes = [300, 250]; expect(spec.isBidRequestValid(bidsClone[0])).to.be.false; @@ -58,14 +58,14 @@ describe('ccxAdapter', () => { bidsClone[0].mediaTypes.banner.sizes = []; expect(spec.isBidRequestValid(bidsClone[0])).to.be.false; }); - it('Invalid bid reqeusts - invalid video sizes', () => { + it('Invalid bid reqeusts - invalid video sizes', function () { let bidsClone = utils.deepClone(bids); bidsClone[1].mediaTypes.video.playerSize = []; expect(spec.isBidRequestValid(bidsClone[1])).to.be.false; bidsClone[1].mediaTypes.video.sizes = [640, 480]; expect(spec.isBidRequestValid(bidsClone[1])).to.be.false; }); - it('Valid bid reqeust - old style sizes', () => { + it('Valid bid reqeust - old style sizes', function () { let bidsClone = utils.deepClone(bids); delete (bidsClone[0].mediaTypes); delete (bidsClone[1].mediaTypes); diff --git a/test/spec/modules/clickforceBidAdapter_spec.js b/test/spec/modules/clickforceBidAdapter_spec.js index c09b69a6320..3d4fc70c057 100644 --- a/test/spec/modules/clickforceBidAdapter_spec.js +++ b/test/spec/modules/clickforceBidAdapter_spec.js @@ -2,16 +2,16 @@ import { expect } from 'chai'; import { spec } from 'modules/clickforceBidAdapter'; import { newBidder } from 'src/adapters/bidderFactory'; -describe('ClickforceAdapter', () => { +describe('ClickforceAdapter', function () { const adapter = newBidder(spec); - describe('inherited functions', () => { - it('exists and is a function', () => { + describe('inherited functions', function () { + it('exists and is a function', function () { expect(adapter.callBids).to.exist.and.to.be.a('function'); }); }); - describe('isBidRequestValid', () => { + describe('isBidRequestValid', function () { let bid = { 'bidder': 'clickforce', 'params': { @@ -26,11 +26,11 @@ describe('ClickforceAdapter', () => { 'auctionId': '1d1a030790a475' }; - it('should return true when required params found', () => { + it('should return true when required params found', function () { expect(spec.isBidRequestValid(bid)).to.equal(true); }); - it('should return false when required params are not passed', () => { + it('should return false when required params are not passed', function () { let bid = Object.assign({}, bid); delete bid.params; bid.params = { @@ -40,7 +40,7 @@ describe('ClickforceAdapter', () => { }); }); - describe('buildRequests', () => { + describe('buildRequests', function () { let bidRequests = [{ 'bidder': 'clickforce', 'params': { @@ -57,12 +57,12 @@ describe('ClickforceAdapter', () => { const request = spec.buildRequests(bidRequests); - it('sends bid request to our endpoint via POST', () => { + it('sends bid request to our endpoint via POST', function () { expect(request.method).to.equal('POST'); }); }); - describe('interpretResponse', () => { + describe('interpretResponse', function () { let response = [{ 'cpm': 0.5, 'width': '300', @@ -147,19 +147,19 @@ describe('ClickforceAdapter', () => { } }]; - it('should get the correct bid response by display ad', () => { + it('should get the correct bid response by display ad', function () { let bidderRequest; let result = spec.interpretResponse({ body: response }, {bidderRequest}); expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])); }); - it('should get the correct bid response by native ad', () => { + it('should get the correct bid response by native ad', function () { let bidderRequest; let result = spec.interpretResponse({ body: response1 }, {bidderRequest}); expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse1[0])); }); - it('handles empty bid response', () => { + it('handles empty bid response', function () { let response = { body: {} }; @@ -168,8 +168,8 @@ describe('ClickforceAdapter', () => { }); }); - describe('getUserSyncs function', () => { - it('should register type is iframe', () => { + describe('getUserSyncs function', function () { + it('should register type is iframe', function () { const syncOptions = { 'iframeEnabled': 'true' } @@ -178,7 +178,7 @@ describe('ClickforceAdapter', () => { expect(userSync[0].url).to.equal('https://cdn.doublemax.net/js/capmapping.htm'); }); - it('should register type is image', () => { + it('should register type is image', function () { const syncOptions = { 'pixelEnabled': 'true' } diff --git a/test/spec/modules/coinzillaBidAdapter_spec.js b/test/spec/modules/coinzillaBidAdapter_spec.js new file mode 100644 index 00000000000..7a0c745d57d --- /dev/null +++ b/test/spec/modules/coinzillaBidAdapter_spec.js @@ -0,0 +1,120 @@ +import {assert, expect} from 'chai'; +import {spec} from 'modules/coinzillaBidAdapter'; +import {newBidder} from 'src/adapters/bidderFactory'; + +const ENDPOINT_URL = 'https://request.czilladx.com/serve/request.php'; + +describe('coinzillaBidAdapter', function () { + const adapter = newBidder(spec); + describe('isBidRequestValid', function () { + let bid = { + 'bidder': 'coinzilla', + 'params': { + placementId: 'testPlacementId' + }, + 'adUnitCode': 'adunit-code', + 'sizes': [ + [300, 250] + ], + 'bidId': '1234asdf1234', + 'bidderRequestId': '1234asdf1234asdf', + 'auctionId': '61466567-d482-4a16-96f0-fe5f25ffbdf120' + }; + it('should return true where required params found', function () { + expect(spec.isBidRequestValid(bid)).to.equal(true); + }); + }); + describe('buildRequests', function () { + let bidRequests = [ + { + 'bidder': 'coinzilla', + 'params': { + placementId: 'testPlacementId' + }, + 'sizes': [ + [300, 250] + ], + 'bidId': '23beaa6af6cdde', + 'bidderRequestId': '19c0c1efdf37e7', + 'auctionId': '61466567-d482-4a16-96f0-fe5f25ffbdf1', + }, + { + 'bidder': 'coinzilla', + 'params': { + placementId: 'testPlacementId' + }, + 'adUnitCode': 'adunit-code2', + 'sizes': [ + [300, 250] + ], + 'bidId': '382091349b149f"', + 'bidderRequestId': '1f9c98192de251', + 'auctionId': '61466567-d482-4a16-96f0-fe5f25ffbdf1', + } + ]; + + let bidderRequests = { + 'refererInfo': { + 'numIframes': 0, + 'reachedTop': true, + 'referer': 'http://example.com', + 'stack': ['http://example.com'] + } + }; + + const request = spec.buildRequests(bidRequests, bidderRequests); + it('sends bid request to our endpoint via POST', function () { + expect(request[0].method).to.equal('POST'); + expect(request[1].method).to.equal('POST'); + }); + it('attaches source and version to endpoint URL as query params', function () { + expect(request[0].url).to.equal(ENDPOINT_URL); + expect(request[1].url).to.equal(ENDPOINT_URL); + }); + }); + + describe('interpretResponse', function () { + let bidRequest = [ + { + 'method': 'POST', + 'url': ENDPOINT_URL, + 'data': { + 'placementId': 'testPlacementId', + 'width': '300', + 'height': '200', + 'bidId': 'bidId123', + 'referer': 'www.example.com' + } + + } + ]; + let serverResponse = { + body: { + 'ad': '

I am an ad

', + 'cpm': 4.2, + 'creativeId': '12345asdfg', + 'currency': 'EUR', + 'statusMessage': 'Bid available', + 'requestId': 'bidId123', + 'width': 300, + 'height': 250, + 'netRevenue': true + } + }; + it('should get the correct bid response', function () { + let expectedResponse = [{ + 'requestId': 'bidId123', + 'cpm': 4.2, + 'width': 300, + 'height': 250, + 'creativeId': '12345asdfg', + 'currency': 'EUR', + 'netRevenue': true, + 'ttl': 3000, + 'ad': '

I am an ad

' + }]; + let result = spec.interpretResponse(serverResponse, bidRequest[0]); + expect(Object.keys(result)).to.deep.equal(Object.keys(expectedResponse)); + }); + }); +}); diff --git a/test/spec/modules/collectcentBidAdapter_spec.js b/test/spec/modules/collectcentBidAdapter_spec.js new file mode 100644 index 00000000000..04c819992cd --- /dev/null +++ b/test/spec/modules/collectcentBidAdapter_spec.js @@ -0,0 +1,118 @@ +import {expect} from 'chai'; +import {spec} from '../../../modules/collectcentBidAdapter'; + +describe('Collectcent', function () { + let bid = { + bidId: '2dd581a2b6281d', + bidder: 'collectcent', + bidderRequestId: '145e1d6a7837c9', + params: { + placementId: 123, + traffic: 'banner' + }, + placementCode: 'placement_0', + auctionId: '74f78609-a92d-4cf1-869f-1b244bbfb5d2', + sizes: [[300, 250]], + transactionId: '3bb2f6da-87a6-4029-aeb0-bfe951372e62' + }; + + describe('isBidRequestValid', function () { + it('Should return true when placementId can be cast to a number', function () { + expect(spec.isBidRequestValid(bid)).to.be.true; + }); + it('Should return false when placementId is not a number', function () { + bid.params.placementId = 'aaa'; + expect(spec.isBidRequestValid(bid)).to.be.false; + }); + }); + + describe('buildRequests', function () { + let serverRequest = spec.buildRequests([bid]); + it('Creates a ServerRequest object with method, URL and data', function () { + expect(serverRequest).to.exist; + expect(serverRequest.method).to.exist; + expect(serverRequest.url).to.exist; + expect(serverRequest.data).to.exist; + }); + it('Returns POST method', function () { + expect(serverRequest.method).to.equal('POST'); + }); + it('Returns valid URL', function () { + expect(serverRequest.url).to.equal('//publishers.motionspots.com/?c=o&m=multi'); + }); + it('Returns valid data if array of bids is valid', function () { + let data = serverRequest.data; + expect(data).to.be.an('object'); + expect(data).to.have.all.keys('deviceWidth', 'deviceHeight', 'secure', 'host', 'page', 'placements'); + expect(data.deviceWidth).to.be.a('number'); + expect(data.deviceHeight).to.be.a('number'); + expect(data.secure).to.be.within(0, 1); + expect(data.host).to.be.a('string'); + expect(data.page).to.be.a('string'); + let placements = data['placements']; + for (let i = 0; i < placements.length; i++) { + let placement = placements[i]; + expect(placement).to.have.all.keys('placementId', 'bidId', 'traffic', 'sizes'); + expect(placement.placementId).to.be.a('number'); + expect(placement.bidId).to.be.a('string'); + expect(placement.traffic).to.be.a('string'); + expect(placement.sizes).to.be.an('array'); + } + }); + it('Returns empty data if no valid requests are passed', function () { + serverRequest = spec.buildRequests([]); + let data = serverRequest.data; + expect(data.placements).to.be.an('array').that.is.empty; + }); + }); + describe('interpretResponse', function () { + let resObject = { + body: [ { + requestId: '123', + mediaType: 'banner', + cpm: 0.3, + width: 320, + height: 50, + ad: '

Hello ad

', + ttl: 1000, + creativeId: '123asd', + netRevenue: true, + currency: 'USD' + } ] + }; + let serverResponses = spec.interpretResponse(resObject); + it('Returns an array of valid server responses if response object is valid', function () { + expect(serverResponses).to.be.an('array').that.is.not.empty; + for (let i = 0; i < serverResponses.length; i++) { + let dataItem = serverResponses[i]; + expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', + 'netRevenue', 'currency', 'mediaType'); + expect(dataItem.requestId).to.be.a('string'); + expect(dataItem.cpm).to.be.a('number'); + expect(dataItem.width).to.be.a('number'); + expect(dataItem.height).to.be.a('number'); + expect(dataItem.ad).to.be.a('string'); + expect(dataItem.ttl).to.be.a('number'); + expect(dataItem.creativeId).to.be.a('string'); + expect(dataItem.netRevenue).to.be.a('boolean'); + expect(dataItem.currency).to.be.a('string'); + expect(dataItem.mediaType).to.be.a('string'); + } + it('Returns an empty array if invalid response is passed', function () { + serverResponses = spec.interpretResponse('invalid_response'); + expect(serverResponses).to.be.an('array').that.is.empty; + }); + }); + }); + + describe('getUserSyncs', function () { + let userSync = spec.getUserSyncs(); + it('Returns valid URL and `', function () { + expect(userSync).to.be.an('array').with.lengthOf(1); + expect(userSync[0].type).to.exist; + expect(userSync[0].url).to.exist; + expect(userSync[0].type).to.be.equal('image'); + expect(userSync[0].url).to.be.equal('//publishers.motionspots.com/?c=o&m=cookie'); + }); + }); +}); diff --git a/test/spec/modules/colombiaBidAdapter_spec.js b/test/spec/modules/colombiaBidAdapter_spec.js new file mode 100644 index 00000000000..5a8678e866c --- /dev/null +++ b/test/spec/modules/colombiaBidAdapter_spec.js @@ -0,0 +1,152 @@ +import { expect } from 'chai'; +import { spec } from 'modules/colombiaBidAdapter'; +import { newBidder } from 'src/adapters/bidderFactory'; + +const HOST_NAME = document.location.protocol + '//' + window.location.host; +const ENDPOINT = 'https://ade.clmbtech.com/cde/prebid.htm'; + +describe('colombiaBidAdapter', function() { + const adapter = newBidder(spec); + + describe('isBidRequestValid', function () { + let bid = { + 'bidder': 'colombia', + 'params': { + placementId: '307466' + }, + 'adUnitCode': 'adunit-code', + 'sizes': [ + [300, 250] + ], + 'bidId': '23beaa6af6cdde', + 'bidderRequestId': '19c0c1efdf37e7', + 'auctionId': '61466567-d482-4a16-96f0-fe5f25ffbdf1', + }; + + it('should return true when required params found', function () { + expect(spec.isBidRequestValid(bid)).to.equal(true); + }); + + it('should return false when placementId not passed correctly', function () { + bid.params.placementId = ''; + expect(spec.isBidRequestValid(bid)).to.equal(false); + }); + + it('should return false when require params are not passed', function () { + let bid = Object.assign({}, bid); + bid.params = {}; + expect(spec.isBidRequestValid(bid)).to.equal(false); + }); + }); + + describe('buildRequests', function () { + let bidRequests = [ + { + 'bidder': 'colombia', + 'params': { + placementId: '307466' + }, + 'adUnitCode': 'adunit-code1', + 'sizes': [ + [300, 250] + ], + 'bidId': '23beaa6af6cdde', + 'bidderRequestId': '19c0c1efdf37e7', + 'auctionId': '61466567-d482-4a16-96f0-fe5f25ffbdf1', + }, + { + 'bidder': 'colombia', + 'params': { + placementId: '307466' + }, + 'adUnitCode': 'adunit-code2', + 'sizes': [ + [300, 250] + ], + 'bidId': '382091349b149f"', + 'bidderRequestId': '"1f9c98192de251"', + 'auctionId': '61466567-d482-4a16-96f0-fe5f25ffbdf1', + } + ]; + + const request = spec.buildRequests(bidRequests); + + it('sends bid request to our endpoint via POST', function () { + expect(request[0].method).to.equal('POST'); + expect(request[1].method).to.equal('POST'); + }); + + it('attaches source and version to endpoint URL as query params', function () { + expect(request[0].url).to.equal(ENDPOINT); + expect(request[1].url).to.equal(ENDPOINT); + }); + }); + + describe('interpretResponse', function () { + let bidRequest = [ + { + 'method': 'POST', + 'url': ENDPOINT, + 'data': { + 'v': 'hb1', + 'p': '307466', + 'w': '300', + 'h': '250', + 'cb': 12892917383, + 'r': 'http%3A%2F%2Flocalhost%3A9876%2F%3Fid%3D74552836', + 'uid': '23beaa6af6cdde', + 't': 'i', + 'd': HOST_NAME + } + } + ]; + + let serverResponse = { + body: { + 'ad': '
This is test case
', + 'cpm': 3.14, + 'creativeId': '6b958110-612c-4b03-b6a9-7436c9f746dc-1sk24', + 'currency': 'USD', + 'statusMessage': 'Bid available', + 'uid': '23beaa6af6cdde', + 'width': 300, + 'height': 250, + 'netRevenue': true, + 'ttl': 600 + } + }; + + it('should get the correct bid response', function () { + let expectedResponse = [{ + 'requestId': '23beaa6af6cdde', + 'cpm': 3.14, + 'width': 300, + 'height': 250, + 'creativeId': '6b958110-612c-4b03-b6a9-7436c9f746dc-1sk24', + 'dealId': '', + 'currency': 'USD', + 'netRevenue': true, + 'ttl': 3000, + 'referrer': '', + 'ad': '
This is test case
' + }]; + let result = spec.interpretResponse(serverResponse, bidRequest[0]); + expect(Object.keys(result)).to.deep.equal(Object.keys(expectedResponse)); + }); + + it('handles empty bid response', function () { + let response = { + body: { + 'uid': '2c0b634db95a01', + 'height': 0, + 'crid': '', + 'statusMessage': 'Bid returned empty or error response', + 'width': 0, + 'cpm': 0 + } + }; + let result = spec.interpretResponse(response, bidRequest[0]); + expect(result.length).to.equal(0); + }); + }); +}); diff --git a/test/spec/modules/colossussspBidAdapter_spec.js b/test/spec/modules/colossussspBidAdapter_spec.js index 54952fbf4b5..62b4158676e 100644 --- a/test/spec/modules/colossussspBidAdapter_spec.js +++ b/test/spec/modules/colossussspBidAdapter_spec.js @@ -1,7 +1,7 @@ import {expect} from 'chai'; import {spec} from '../../../modules/colossussspBidAdapter'; -describe('ColossussspAdapter', () => { +describe('ColossussspAdapter', function () { let bid = { bidId: '2dd581a2b6281d', bidder: 'colossusssp', @@ -15,31 +15,31 @@ describe('ColossussspAdapter', () => { transactionId: '3bb2f6da-87a6-4029-aeb0-bfe951372e62' }; - describe('isBidRequestValid', () => { - it('Should return true when placement_id can be cast to a number', () => { + describe('isBidRequestValid', function () { + it('Should return true when placement_id can be cast to a number', function () { expect(spec.isBidRequestValid(bid)).to.be.true; }); - it('Should return false when placement_id is not a number', () => { + it('Should return false when placement_id is not a number', function () { bid.params.placement_id = 'aaa'; expect(spec.isBidRequestValid(bid)).to.be.false; }); }); - describe('buildRequests', () => { + describe('buildRequests', function () { let serverRequest = spec.buildRequests([bid]); - it('Creates a ServerRequest object with method, URL and data', () => { + it('Creates a ServerRequest object with method, URL and data', function () { expect(serverRequest).to.exist; expect(serverRequest.method).to.exist; expect(serverRequest.url).to.exist; expect(serverRequest.data).to.exist; }); - it('Returns POST method', () => { + it('Returns POST method', function () { expect(serverRequest.method).to.equal('POST'); }); - it('Returns valid URL', () => { + it('Returns valid URL', function () { expect(serverRequest.url).to.equal('//colossusssp.com/?c=o&m=multi'); }); - it('Returns valid data if array of bids is valid', () => { + it('Returns valid data if array of bids is valid', function () { let data = serverRequest.data; expect(data).to.be.an('object'); expect(data).to.have.all.keys('deviceWidth', 'deviceHeight', 'language', 'secure', 'host', 'page', 'placements'); @@ -59,13 +59,13 @@ describe('ColossussspAdapter', () => { expect(placement.sizes).to.be.an('array'); } }); - it('Returns empty data if no valid requests are passed', () => { + it('Returns empty data if no valid requests are passed', function () { serverRequest = spec.buildRequests([]); let data = serverRequest.data; expect(data.placements).to.be.an('array').that.is.empty; }); }); - describe('interpretResponse', () => { + describe('interpretResponse', function () { let resObject = { body: [ { requestId: '123', @@ -81,7 +81,7 @@ describe('ColossussspAdapter', () => { } ] }; let serverResponses = spec.interpretResponse(resObject); - it('Returns an array of valid server responses if response object is valid', () => { + it('Returns an array of valid server responses if response object is valid', function () { expect(serverResponses).to.be.an('array').that.is.not.empty; for (let i = 0; i < serverResponses.length; i++) { let dataItem = serverResponses[i]; @@ -98,16 +98,16 @@ describe('ColossussspAdapter', () => { expect(dataItem.currency).to.be.a('string'); expect(dataItem.mediaType).to.be.a('string'); } - it('Returns an empty array if invalid response is passed', () => { + it('Returns an empty array if invalid response is passed', function () { serverResponses = spec.interpretResponse('invalid_response'); expect(serverResponses).to.be.an('array').that.is.empty; }); }); }); - describe('getUserSyncs', () => { + describe('getUserSyncs', function () { let userSync = spec.getUserSyncs(); - it('Returns valid URL and type', () => { + it('Returns valid URL and type', function () { expect(userSync).to.be.an('array').with.lengthOf(1); expect(userSync[0].type).to.exist; expect(userSync[0].url).to.exist; diff --git a/test/spec/modules/consentManagement_spec.js b/test/spec/modules/consentManagement_spec.js index fe6bfc1ebfd..33e6eba42f7 100644 --- a/test/spec/modules/consentManagement_spec.js +++ b/test/spec/modules/consentManagement_spec.js @@ -1,5 +1,5 @@ -import {setConfig, requestBidsHook, resetConsentData, userCMP, consentTimeout, allowAuction} from 'modules/consentManagement'; -import {gdprDataHandler} from 'src/adaptermanager'; +import {setConfig, requestBidsHook, resetConsentData, userCMP, consentTimeout, allowAuction, staticConsentData} from 'modules/consentManagement'; +import {gdprDataHandler} from 'src/adapterManager'; import * as utils from 'src/utils'; import { config } from 'src/config'; @@ -7,18 +7,18 @@ let assert = require('chai').assert; let expect = require('chai').expect; describe('consentManagement', function () { - describe('setConfig tests:', () => { - describe('empty setConfig value', () => { - beforeEach(() => { + describe('setConfig tests:', function () { + describe('empty setConfig value', function () { + beforeEach(function () { sinon.stub(utils, 'logInfo'); }); - afterEach(() => { + afterEach(function () { utils.logInfo.restore(); config.resetConfig(); }); - it('should use system default values', () => { + it('should use system default values', function () { setConfig({}); expect(userCMP).to.be.equal('iab'); expect(consentTimeout).to.be.equal(10000); @@ -27,12 +27,12 @@ describe('consentManagement', function () { }); }); - describe('valid setConfig value', () => { - afterEach(() => { + describe('valid setConfig value', function () { + afterEach(function () { config.resetConfig(); $$PREBID_GLOBAL$$.requestBids.removeHook(requestBidsHook); }); - it('results in all user settings overriding system defaults', () => { + it('results in all user settings overriding system defaults', function () { let allConfig = { cmpApi: 'iab', timeout: 7500, @@ -45,9 +45,418 @@ describe('consentManagement', function () { expect(allowAuction).to.be.false; }); }); + + describe('static consent string setConfig value', () => { + afterEach(() => { + config.resetConfig(); + $$PREBID_GLOBAL$$.requestBids.removeHook(requestBidsHook); + }); + it('results in user settings overriding system defaults', () => { + let staticConfig = { + cmpApi: 'static', + timeout: 7500, + allowAuctionWithoutConsent: false, + consentData: { + getConsentData: { + 'gdprApplies': true, + 'hasGlobalScope': false, + 'consentData': 'BOOgjO9OOgjO9APABAENAi-AAAAWd7_______9____7_9uz_Gv_r_ff_3nW0739P1A_r_Oz_rm_-zzV44_lpQQRCEA' + }, + getVendorConsents: { + 'metadata': 'BOOgjO9OOgjO9APABAENAi-AAAAWd7_______9____7_9uz_Gv_r_ff_3nW0739P1A_r_Oz_rm_-zzV44_lpQQRCEA', + 'gdprApplies': true, + 'hasGlobalScope': false, + 'isEU': true, + 'cookieVersion': 1, + 'created': '2018-05-29T07:45:48.522Z', + 'lastUpdated': '2018-05-29T07:45:48.522Z', + 'cmpId': 15, + 'cmpVersion': 1, + 'consentLanguage': 'EN', + 'vendorListVersion': 34, + 'maxVendorId': 359, + 'purposeConsents': { + '1': true, + '2': true, + '3': true, + '4': true, + '5': true + }, + 'vendorConsents': { + '1': true, + '2': true, + '3': true, + '4': true, + '5': false, + '6': true, + '7': true, + '8': true, + '9': true, + '10': true, + '11': true, + '12': true, + '13': true, + '14': true, + '15': true, + '16': true, + '17': true, + '18': true, + '19': true, + '20': true, + '21': true, + '22': true, + '23': true, + '24': true, + '25': true, + '26': true, + '27': true, + '28': true, + '29': true, + '30': true, + '31': true, + '32': true, + '33': true, + '34': true, + '35': true, + '36': true, + '37': true, + '38': true, + '39': true, + '40': true, + '41': true, + '42': true, + '43': true, + '44': true, + '45': true, + '46': true, + '47': true, + '48': true, + '49': true, + '50': true, + '51': true, + '52': true, + '53': true, + '54': false, + '55': true, + '56': true, + '57': true, + '58': true, + '59': true, + '60': true, + '61': true, + '62': true, + '63': true, + '64': true, + '65': true, + '66': true, + '67': true, + '68': true, + '69': true, + '70': true, + '71': true, + '72': true, + '73': true, + '74': true, + '75': true, + '76': true, + '77': true, + '78': true, + '79': true, + '80': true, + '81': true, + '82': true, + '83': false, + '84': true, + '85': true, + '86': true, + '87': true, + '88': true, + '89': true, + '90': true, + '91': true, + '92': true, + '93': true, + '94': true, + '95': true, + '96': false, + '97': true, + '98': true, + '99': false, + '100': true, + '101': true, + '102': true, + '103': false, + '104': true, + '105': true, + '106': false, + '107': false, + '108': true, + '109': true, + '110': true, + '111': true, + '112': true, + '113': true, + '114': true, + '115': true, + '116': false, + '117': false, + '118': false, + '119': true, + '120': true, + '121': false, + '122': true, + '123': false, + '124': true, + '125': true, + '126': true, + '127': true, + '128': true, + '129': true, + '130': true, + '131': true, + '132': true, + '133': true, + '134': true, + '135': false, + '136': true, + '137': false, + '138': true, + '139': true, + '140': true, + '141': true, + '142': true, + '143': true, + '144': true, + '145': true, + '146': false, + '147': true, + '148': true, + '149': true, + '150': true, + '151': true, + '152': false, + '153': true, + '154': true, + '155': true, + '156': true, + '157': true, + '158': true, + '159': true, + '160': true, + '161': true, + '162': true, + '163': true, + '164': true, + '165': true, + '166': false, + '167': true, + '168': true, + '169': true, + '170': true, + '171': false, + '172': false, + '173': true, + '174': true, + '175': true, + '176': false, + '177': true, + '178': false, + '179': true, + '180': true, + '181': false, + '182': true, + '183': true, + '184': false, + '185': true, + '186': false, + '187': false, + '188': true, + '189': true, + '190': true, + '191': false, + '192': true, + '193': true, + '194': true, + '195': true, + '196': false, + '197': true, + '198': true, + '199': true, + '200': true, + '201': true, + '202': true, + '203': true, + '204': false, + '205': true, + '206': false, + '207': false, + '208': true, + '209': true, + '210': true, + '211': true, + '212': true, + '213': true, + '214': false, + '215': true, + '216': false, + '217': true, + '218': false, + '219': false, + '220': false, + '221': false, + '222': false, + '223': false, + '224': true, + '225': true, + '226': true, + '227': true, + '228': true, + '229': true, + '230': true, + '231': false, + '232': true, + '233': false, + '234': true, + '235': true, + '236': true, + '237': true, + '238': true, + '239': true, + '240': true, + '241': true, + '242': false, + '243': false, + '244': true, + '245': true, + '246': true, + '247': false, + '248': true, + '249': true, + '250': false, + '251': false, + '252': true, + '253': true, + '254': true, + '255': true, + '256': true, + '257': true, + '258': true, + '259': true, + '260': true, + '261': false, + '262': true, + '263': false, + '264': true, + '265': true, + '266': true, + '267': false, + '268': false, + '269': true, + '270': true, + '271': false, + '272': true, + '273': true, + '274': true, + '275': true, + '276': true, + '277': true, + '278': true, + '279': true, + '280': true, + '281': true, + '282': true, + '283': false, + '284': true, + '285': true, + '286': false, + '287': false, + '288': true, + '289': true, + '290': true, + '291': true, + '292': false, + '293': false, + '294': true, + '295': true, + '296': false, + '297': true, + '298': false, + '299': true, + '300': false, + '301': true, + '302': true, + '303': true, + '304': true, + '305': false, + '306': false, + '307': false, + '308': true, + '309': true, + '310': true, + '311': false, + '312': false, + '313': false, + '314': true, + '315': true, + '316': true, + '317': true, + '318': true, + '319': true, + '320': true, + '321': false, + '322': false, + '323': true, + '324': false, + '325': true, + '326': true, + '327': false, + '328': true, + '329': false, + '330': false, + '331': true, + '332': false, + '333': true, + '334': false, + '335': false, + '336': false, + '337': false, + '338': false, + '339': true, + '340': false, + '341': false, + '342': false, + '343': false, + '344': false, + '345': true, + '346': false, + '347': false, + '348': false, + '349': true, + '350': false, + '351': false, + '352': false, + '353': false, + '354': true, + '355': false, + '356': false, + '357': false, + '358': false, + '359': true + } + } + } + }; + + setConfig(staticConfig); + expect(userCMP).to.be.equal('static'); + expect(consentTimeout).to.be.equal(0); // should always return without a timeout when config is used + expect(allowAuction).to.be.false; + expect(staticConsentData).to.be.equal(staticConfig.consentData); + }); + }); }); - describe('requestBidsHook tests:', () => { + describe('requestBidsHook tests:', function () { let goodConfigWithCancelAuction = { cmpApi: 'iab', timeout: 7500, @@ -62,19 +471,19 @@ describe('consentManagement', function () { let didHookReturn; - afterEach(() => { + afterEach(function () { gdprDataHandler.consentData = null; resetConsentData(); }); - describe('error checks:', () => { - beforeEach(() => { + describe('error checks:', function () { + beforeEach(function () { didHookReturn = false; sinon.stub(utils, 'logWarn'); sinon.stub(utils, 'logError'); }); - afterEach(() => { + afterEach(function () { utils.logWarn.restore(); utils.logError.restore(); config.resetConfig(); @@ -82,7 +491,7 @@ describe('consentManagement', function () { resetConsentData(); }); - it('should throw a warning and return to hooked function when an unknown CMP framework ID is used', () => { + it('should throw a warning and return to hooked function when an unknown CMP framework ID is used', function () { let badCMPConfig = { cmpApi: 'bad' }; @@ -98,7 +507,7 @@ describe('consentManagement', function () { expect(consent).to.be.null; }); - it('should throw proper errors when CMP is not found', () => { + it('should throw proper errors when CMP is not found', function () { setConfig(goodConfigWithCancelAuction); requestBidsHook({}, () => { @@ -112,15 +521,15 @@ describe('consentManagement', function () { }); }); - describe('already known consentData:', () => { + describe('already known consentData:', function () { let cmpStub = sinon.stub(); - beforeEach(() => { + beforeEach(function () { didHookReturn = false; window.__cmp = function() {}; }); - afterEach(() => { + afterEach(function () { config.resetConfig(); $$PREBID_GLOBAL$$.requestBids.removeHook(requestBidsHook); cmpStub.restore(); @@ -128,7 +537,7 @@ describe('consentManagement', function () { resetConsentData(); }); - it('should bypass CMP and simply use previously stored consentData', () => { + it('should bypass CMP and simply use previously stored consentData', function () { let testConsentData = { gdprApplies: true, consentData: 'xyz' @@ -158,10 +567,10 @@ describe('consentManagement', function () { }); }); - describe('CMP workflow for safeframe page', () => { + describe('CMP workflow for safeframe page', function () { let registerStub = sinon.stub(); - beforeEach(() => { + beforeEach(function () { didHookReturn = false; window.$sf = { ext: { @@ -173,7 +582,7 @@ describe('consentManagement', function () { sinon.stub(utils, 'logWarn'); }); - afterEach(() => { + afterEach(function () { delete window.$sf; config.resetConfig(); $$PREBID_GLOBAL$$.requestBids.removeHook(requestBidsHook); @@ -183,7 +592,7 @@ describe('consentManagement', function () { resetConsentData(); }); - it('should return the consent data from a safeframe callback', () => { + it('should return the consent data from a safeframe callback', function () { var testConsentData = { data: { msgName: 'cmpReturn', @@ -215,18 +624,18 @@ describe('consentManagement', function () { }); }); - describe('CMP workflow for iframed page', () => { + describe('CMP workflow for iframed page', function () { let ifr = null; let stringifyResponse = false; - beforeEach(() => { + beforeEach(function () { sinon.stub(utils, 'logError'); sinon.stub(utils, 'logWarn'); ifr = createIFrameMarker(); window.addEventListener('message', cmpMessageHandler, false); }); - afterEach(() => { + afterEach(function () { config.resetConfig(); $$PREBID_GLOBAL$$.requestBids.removeHook(requestBidsHook); delete window.__cmp; @@ -288,17 +697,17 @@ describe('consentManagement', function () { } }); - describe('CMP workflow for normal pages:', () => { + describe('CMP workflow for normal pages:', function () { let cmpStub = sinon.stub(); - beforeEach(() => { + beforeEach(function () { didHookReturn = false; sinon.stub(utils, 'logError'); sinon.stub(utils, 'logWarn'); window.__cmp = function() {}; }); - afterEach(() => { + afterEach(function () { config.resetConfig(); $$PREBID_GLOBAL$$.requestBids.removeHook(requestBidsHook); cmpStub.restore(); @@ -308,7 +717,7 @@ describe('consentManagement', function () { resetConsentData(); }); - it('performs lookup check and stores consentData for a valid existing user', () => { + it('performs lookup check and stores consentData for a valid existing user', function () { let testConsentData = { gdprApplies: true, consentData: 'BOJy+UqOJy+UqABAB+AAAAAZ+A==' @@ -331,7 +740,7 @@ describe('consentManagement', function () { expect(consent.gdprApplies).to.be.true; }); - it('throws an error when processCmpData check failed while config had allowAuction set to false', () => { + it('throws an error when processCmpData check failed while config had allowAuction set to false', function () { let testConsentData = {}; let bidsBackHandlerReturn = false; @@ -352,7 +761,7 @@ describe('consentManagement', function () { expect(consent).to.be.null; }); - it('throws a warning + stores consentData + calls callback when processCmpData check failed while config had allowAuction set to true', () => { + it('throws a warning + stores consentData + calls callback when processCmpData check failed while config had allowAuction set to true', function () { let testConsentData = {}; cmpStub = sinon.stub(window, '__cmp').callsFake((...args) => { diff --git a/test/spec/modules/consumableBidAdapter_spec.js b/test/spec/modules/consumableBidAdapter_spec.js index b87ce6634f6..74453986ce1 100644 --- a/test/spec/modules/consumableBidAdapter_spec.js +++ b/test/spec/modules/consumableBidAdapter_spec.js @@ -1,215 +1,268 @@ -import {expect} from 'chai'; -import * as utils from 'src/utils'; -import {spec} from 'modules/consumableBidAdapter'; -import {config} from 'src/config'; - -const DEFAULT_OAD_CONTENT = ''; -const DEFAULT_AD_CONTENT = '' - -let getDefaultBidResponse = () => { - return { - id: '245730051428950632', - cur: 'USD', - seatbid: [{ - bid: [{ - id: 1, - impid: '245730051428950632', - price: 0.09, - adm: DEFAULT_OAD_CONTENT, - crid: 'creative-id', - h: 90, - w: 728, - dealid: 'deal-id', - ext: {sizeid: 225} - }] - }] - }; -}; +import { expect } from 'chai'; +import { spec } from 'modules/consumableBidAdapter'; +import { createBid } from 'src/bidfactory'; -let getBidParams = () => { - return { - placement: 1234567, - network: '9599.1', - unitId: '987654', - unitName: 'unitname', - zoneId: '9599.1' - }; -}; +const ENDPOINT = 'https://e.serverbid.com/api/v2'; +const SMARTSYNC_CALLBACK = 'serverbidCallBids'; -let getDefaultBidRequest = () => { - return { - bidderCode: 'consumable', - auctionId: 'd3e07445-ab06-44c8-a9dd-5ef9af06d2a6', - bidderRequestId: '7101db09af0db2', - start: new Date().getTime(), - bids: [{ - bidder: 'consumable', - bidId: '84ab500420319d', - bidderRequestId: '7101db09af0db2', - auctionId: 'd3e07445-ab06-44c8-a9dd-5ef9af06d2a6', - placementCode: 'foo', - params: getBidParams() - }] - }; +const REQUEST = { + 'bidderCode': 'consumable', + 'auctionId': 'a4713c32-3762-4798-b342-4ab810ca770d', + 'bidderRequestId': '109f2a181342a9', + 'bidRequest': [{ + 'bidder': 'consumable', + 'params': { + 'networkId': 9969, + 'siteId': 730181, + 'unitId': 123456, + 'unitName': 'cnsmbl-unit' + }, + 'placementCode': 'div-gpt-ad-1487778092495-0', + 'sizes': [ + [728, 90], + [970, 90] + ], + 'bidId': '2b0f82502298c9', + 'bidderRequestId': '109f2a181342a9', + 'auctionId': 'a4713c32-3762-4798-b342-4ab810ca770d' + }, + { + 'bidder': 'consumable', + 'params': { + 'networkId': 9969, + 'siteId': 730181, + 'unitId': 123456, + 'unitName': 'cnsmbl-unit' + }, + 'placementCode': 'div-gpt-ad-1487778092495-0', + 'sizes': [ + [728, 90], + [970, 90] + ], + 'bidId': '123', + 'bidderRequestId': '109f2a181342a9', + 'auctionId': 'a4713c32-3762-4798-b342-4ab810ca770d' + }], + 'start': 1487883186070, + 'auctionStart': 1487883186069, + 'timeout': 3000 }; -let getPixels = () => { - return ''; +const RESPONSE = { + 'headers': null, + 'body': { + 'user': { 'key': 'ue1-2d33e91b71e74929b4aeecc23f4376f1' }, + 'decisions': { + '2b0f82502298c9': { + 'adId': 2364764, + 'creativeId': 1950991, + 'flightId': 2788300, + 'campaignId': 542982, + 'clickUrl': 'https://e.serverbid.com/r', + 'impressionUrl': 'https://e.serverbid.com/i.gif', + 'contents': [{ + 'type': 'html', + 'body': '', + 'data': { + 'height': 90, + 'width': 728, + 'imageUrl': 'https://static.adzerk.net/Advertisers/b0ab77db8a7848c8b78931aed022a5ef.gif', + 'fileName': 'b0ab77db8a7848c8b78931aed022a5ef.gif' + }, + 'template': 'image' + }], + 'height': 90, + 'width': 728, + 'events': [], + 'pricing': {'price': 0.5, 'clearPrice': 0.5, 'revenue': 0.0005, 'rateType': 2, 'eCPM': 0.5} + }, + '123': { + 'adId': 2364764, + 'creativeId': 1950991, + 'flightId': 2788300, + 'campaignId': 542982, + 'clickUrl': 'https://e.serverbid.com/r', + 'impressionUrl': 'https://e.serverbid.com/i.gif', + 'contents': [{ + 'type': 'html', + 'body': '', + 'data': { + 'height': 90, + 'width': 728, + 'imageUrl': 'https://static.adzerk.net/Advertisers/b0ab77db8a7848c8b78931aed022a5ef.gif', + 'fileName': 'b0ab77db8a7848c8b78931aed022a5ef.gif' + }, + 'template': 'image' + }], + 'height': 90, + 'width': 728, + 'events': [], + 'pricing': {'price': 0.5, 'clearPrice': 0.5, 'revenue': 0.0005, 'rateType': 2, 'eCPM': 0.5} + } + } + } }; -describe('ConsumableAdapter', () => { - const CONSUMABLE_URL = '//adserver-us.adtech.advertising.com/pubapi/3.0/'; - const CONSUMABLE_TTL = 60; +describe('Consumable BidAdapter', function () { + let bidRequests; + let adapter = spec; - function createCustomBidRequest({bids, params} = {}) { - var bidderRequest = getDefaultBidRequest(); - if (bids && Array.isArray(bids)) { - bidderRequest.bids = bids; - } - if (params) { - bidderRequest.bids.forEach(bid => bid.params = params); - } - return bidderRequest; - } + beforeEach(function () { + bidRequests = [ + { + bidder: 'consumable', + params: { + networkId: '9969', + siteId: '730181', + unitId: '123456', + unitName: 'cnsmbl-unit' + }, + placementCode: 'header-bid-tag-1', + sizes: [[300, 250], [300, 600]], + bidId: '23acc48ad47af5', + auctionId: '0fb4905b-9456-4152-86be-c6f6d259ba99', + bidderRequestId: '1c56ad30b9b8ca8', + transactionId: '92489f71-1bf2-49a0-adf9-000cea934729' + } + ]; + }); - describe('interpretResponse()', () => { - let bidderSettingsBackup; - let bidResponse; - let bidRequest; - let logWarnSpy; - - beforeEach(() => { - bidderSettingsBackup = $$PREBID_GLOBAL$$.bidderSettings; - bidRequest = { - bidderCode: 'test-bidder-code', - bidId: 'bid-id', - unitName: 'unitname', - unitId: '987654', - zoneId: '9599.1', - network: '9599.1' - }; - bidResponse = { - body: getDefaultBidResponse() + describe('bid request validation', function () { + it('should accept valid bid requests', function () { + let bid = { + bidder: 'consumable', + params: { + networkId: '9969', + siteId: '123', + unitId: '123456', + unitName: 'cnsmbl-unit' + } }; - logWarnSpy = sinon.spy(utils, 'logWarn'); + expect(spec.isBidRequestValid(bid)).to.equal(true); }); - afterEach(() => { - $$PREBID_GLOBAL$$.bidderSettings = bidderSettingsBackup; - logWarnSpy.restore(); + it('should accept valid bid requests with extra fields', function () { + let bid = { + bidder: 'consumable', + params: { + networkId: '9969', + siteId: '123', + unitId: '123456', + unitName: 'cnsmbl-unit', + zoneId: '123' + } + }; + expect(spec.isBidRequestValid(bid)).to.equal(true); }); - it('should return formatted bid response with required properties', () => { - let formattedBidResponse = spec.interpretResponse(bidResponse, bidRequest); - expect(formattedBidResponse).to.deep.equal({ - bidderCode: bidRequest.bidderCode, - requestId: 'bid-id', - ad: DEFAULT_AD_CONTENT, - cpm: 0.09, - width: 728, - height: 90, - creativeId: 'creative-id', - pubapiId: '245730051428950632', - currency: 'USD', - dealId: 'deal-id', - netRevenue: true, - ttl: 60 - }); + it('should reject bid requests without siteId', function () { + let bid = { + bidder: 'consumable', + params: { + networkId: '9969', + unitId: '123456', + unitName: 'cnsmbl-unit' + } + }; + expect(spec.isBidRequestValid(bid)).to.equal(false); }); - it('should add formatted pixels to ad content when pixels are present in the response', () => { - bidResponse.body.ext = { - pixels: 'pixels-content' + it('should reject bid requests without networkId', function () { + let bid = { + bidder: 'consumable', + params: { + siteId: '9969', + unitId: '123456', + unitName: 'cnsmbl-unit' + } }; - - let formattedBidResponse = spec.interpretResponse(bidResponse, bidRequest); - - expect(formattedBidResponse.ad).to.equal(DEFAULT_AD_CONTENT + ''); - return true; + expect(spec.isBidRequestValid(bid)).to.equal(false); }); }); - describe('buildRequests()', () => { - it('method exists and is a function', () => { - expect(spec.buildRequests).to.exist.and.to.be.a('function'); + describe('buildRequests validation', function () { + it('creates request data', function () { + let request = spec.buildRequests(bidRequests); + + expect(request).to.exist.and.to.be.a('object'); }); - describe('Consumable', () => { - it('should not return request when no bids are present', () => { - let [request] = spec.buildRequests([]); - expect(request).to.be.empty; - }); + it('request to consumable should contain a url', function () { + let request = spec.buildRequests(bidRequests); - it('should return request for endpoint', () => { - let bidRequest = getDefaultBidRequest(); - let [request] = spec.buildRequests(bidRequest.bids); - expect(request.url).to.contain(CONSUMABLE_URL); - }); + expect(request.url).to.have.string('serverbid.com'); + }); - it('should return url with pubapi bid option', () => { - let bidRequest = getDefaultBidRequest(); - let [request] = spec.buildRequests(bidRequest.bids); - expect(request.url).to.contain('cmd=bid;'); - }); + it('requires valid bids to make request', function () { + let request = spec.buildRequests([]); + expect(request.bidRequest).to.be.empty; + }); - it('should return url with version 2 of pubapi', () => { - let bidRequest = getDefaultBidRequest(); - let [request] = spec.buildRequests(bidRequest.bids); - expect(request.url).to.contain('v=2;'); - }); + it('sends bid request to ENDPOINT via POST', function () { + let request = spec.buildRequests(bidRequests); - it('should return url with cache busting option', () => { - let bidRequest = getDefaultBidRequest(); - let [request] = spec.buildRequests(bidRequest.bids); - expect(request.url).to.match(/misc=\d+/); - }); + expect(request.method).to.have.string('POST'); }); }); + describe('interpretResponse validation', function () { + it('response should have valid bidderCode', function () { + let bidRequest = spec.buildRequests(REQUEST.bidRequest); + let bid = createBid(1, bidRequest.bidRequest[0]); + + expect(bid.bidderCode).to.equal('consumable'); + }); - describe('getUserSyncs()', () => { - let bidResponse; - let bidRequest; + it('response should include objects for all bids', function () { + let bids = spec.interpretResponse(RESPONSE, REQUEST); + expect(bids.length).to.equal(2); + }); - beforeEach(() => { - $$PREBID_GLOBAL$$.consumableGlobals.pixelsDropped = false; - config.setConfig({ - consumable: { - userSyncOn: 'bidResponse' - }, + it('registers bids', function () { + let bids = spec.interpretResponse(RESPONSE, REQUEST); + bids.forEach(b => { + expect(b).to.have.property('cpm'); + expect(b.cpm).to.be.above(0); + expect(b).to.have.property('requestId'); + expect(b).to.have.property('unitId'); + expect(b).to.have.property('unitName'); + expect(b).to.have.property('cpm'); + expect(b).to.have.property('width'); + expect(b).to.have.property('height'); + expect(b).to.have.property('ad'); + expect(b).to.have.property('currency', 'USD'); + expect(b).to.have.property('creativeId'); + expect(b).to.have.property('ttl', 30); + expect(b).to.have.property('netRevenue', true); + expect(b).to.have.property('referrer'); }); - bidResponse = getDefaultBidResponse(); - bidResponse.ext = { - pixels: getPixels() - }; }); - it('should return user syncs only if userSyncOn equals to "bidResponse"', () => { - let userSyncs = spec.getUserSyncs({}, [bidResponse], bidRequest); + it('handles nobid responses', function () { + let EMPTY_RESP = Object.assign({}, RESPONSE, {'body': {'decisions': null}}) + let bids = spec.interpretResponse(EMPTY_RESP, REQUEST); - expect($$PREBID_GLOBAL$$.consumableGlobals.pixelsDropped).to.be.true; - expect(userSyncs).to.deep.equal([ - {type: 'image', url: 'img.org'}, - {type: 'iframe', url: 'pixels1.org'} - ]); + expect(bids).to.be.empty; }); - it('should not return user syncs if it has already been returned', () => { - $$PREBID_GLOBAL$$.consumableGlobals.pixelsDropped = true; + it('handles no server response', function () { + let bids = spec.interpretResponse(null, REQUEST); - let userSyncs = spec.getUserSyncs({}, [bidResponse], bidRequest); - - expect($$PREBID_GLOBAL$$.consumableGlobals.pixelsDropped).to.be.true; - expect(userSyncs).to.deep.equal([]); + expect(bids).to.be.empty; }); + }); + describe('getUserSyncs', function () { + let syncOptions = {'iframeEnabled': true}; - it('should not return user syncs if pixels are not present', () => { - bidResponse.ext.pixels = null; + it('handles empty sync options', function () { + let opts = spec.getUserSyncs({}); + + expect(opts).to.be.empty; + }); - let userSyncs = spec.getUserSyncs({}, [bidResponse], bidRequest); + it('should return a sync url if iframe syncs are enabled', function () { + let opts = spec.getUserSyncs(syncOptions); - expect($$PREBID_GLOBAL$$.consumableGlobals.pixelsDropped).to.be.false; - expect(userSyncs).to.deep.equal([]); + expect(opts.length).to.equal(1); }); }); }); diff --git a/test/spec/modules/contentigniteBidAdapter_spec.js b/test/spec/modules/contentigniteBidAdapter_spec.js index cdf70e15615..1867791a234 100644 --- a/test/spec/modules/contentigniteBidAdapter_spec.js +++ b/test/spec/modules/contentigniteBidAdapter_spec.js @@ -1,10 +1,10 @@ import { expect } from 'chai'; import { spec } from '../../../modules/contentigniteBidAdapter'; -describe('Content Ignite adapter', () => { +describe('Content Ignite adapter', function () { let bidRequests; - beforeEach(() => { + beforeEach(function () { bidRequests = [ { bidder: 'contentignite', @@ -25,9 +25,9 @@ describe('Content Ignite adapter', () => { ]; }); - describe('implementation', () => { - describe('for requests', () => { - it('should accept valid bid', () => { + describe('implementation', function () { + describe('for requests', function () { + it('should accept valid bid', function () { const validBid = { bidder: 'contentignite', params: { @@ -40,7 +40,7 @@ describe('Content Ignite adapter', () => { expect(isValid).to.equal(true); }); - it('should reject invalid bid', () => { + it('should reject invalid bid', function () { const invalidBid = { bidder: 'contentignite', params: { @@ -52,14 +52,14 @@ describe('Content Ignite adapter', () => { expect(isValid).to.equal(false); }); - it('should set the keyword parameter', () => { + it('should set the keyword parameter', function () { const requests = spec.buildRequests(bidRequests), requestURL = requests[0].url; expect(requestURL).to.have.string(';kw=business;'); }); - it('should increment the count for the same zone', () => { + it('should increment the count for the same zone', function () { const bidRequests = [ { sizes: [[728, 90]], @@ -87,8 +87,8 @@ describe('Content Ignite adapter', () => { }); }); - describe('bid responses', () => { - it('should return complete bid response', () => { + describe('bid responses', function () { + it('should return complete bid response', function () { const serverResponse = { body: { status: 'SUCCESS', @@ -116,7 +116,7 @@ describe('Content Ignite adapter', () => { expect(bids[0].ad).to.have.length.above(1); }); - it('should return empty bid response', () => { + it('should return empty bid response', function () { const serverResponse = { status: 'NO_ELIGIBLE_ADS', zone_id: 299680, @@ -131,7 +131,7 @@ describe('Content Ignite adapter', () => { expect(bids).to.be.lengthOf(0); }); - it('should return empty bid response on incorrect size', () => { + it('should return empty bid response on incorrect size', function () { const serverResponse = { status: 'SUCCESS', account_id: 168237, @@ -148,7 +148,7 @@ describe('Content Ignite adapter', () => { expect(bids).to.be.lengthOf(0); }); - it('should return empty bid response with CPM too low', () => { + it('should return empty bid response with CPM too low', function () { const serverResponse = { status: 'SUCCESS', account_id: 168237, @@ -165,7 +165,7 @@ describe('Content Ignite adapter', () => { expect(bids).to.be.lengthOf(0); }); - it('should return empty bid response with CPM too high', () => { + it('should return empty bid response with CPM too high', function () { const serverResponse = { status: 'SUCCESS', account_id: 168237, diff --git a/test/spec/modules/conversantBidAdapter_spec.js b/test/spec/modules/conversantBidAdapter_spec.js index 91b3ed6892b..f4c14032fc5 100644 --- a/test/spec/modules/conversantBidAdapter_spec.js +++ b/test/spec/modules/conversantBidAdapter_spec.js @@ -8,6 +8,7 @@ describe('Conversant adapter tests', function() { const siteId = '108060'; const bidRequests = [ + // banner with single size { bidder: 'conversant', params: { @@ -23,19 +24,27 @@ describe('Conversant adapter tests', function() { bidId: 'bid000', bidderRequestId: '117d765b87bed38', auctionId: 'req000' - }, { + }, + // banner with sizes in mediaTypes.banner.sizes + { bidder: 'conversant', params: { site_id: siteId, secure: false }, + mediaTypes: { + banner: { + sizes: [[728, 90], [468, 60]] + } + }, placementCode: 'pcode001', transactionId: 'tx001', - sizes: [[468, 60]], bidId: 'bid001', bidderRequestId: '117d765b87bed38', auctionId: 'req000' - }, { + }, + // banner with tag id and position + { bidder: 'conversant', params: { site_id: siteId, @@ -49,7 +58,9 @@ describe('Conversant adapter tests', function() { bidId: 'bid002', bidderRequestId: '117d765b87bed38', auctionId: 'req000' - }, { + }, + // video with single size + { bidder: 'conversant', params: { site_id: siteId, @@ -60,7 +71,8 @@ describe('Conversant adapter tests', function() { }, mediaTypes: { video: { - context: 'instream' + context: 'instream', + playerSize: [632, 499], } }, placementCode: 'pcode003', @@ -69,6 +81,47 @@ describe('Conversant adapter tests', function() { bidId: 'bid003', bidderRequestId: '117d765b87bed38', auctionId: 'req000' + }, + // video with playerSize + { + bidder: 'conversant', + params: { + site_id: siteId, + maxduration: 30, + api: [2, 3] + }, + mediaTypes: { + video: { + context: 'instream', + playerSize: [1024, 768], + api: [1, 2], + protocols: [1, 2, 3], + mimes: ['video/mp4', 'video/x-flv'] + } + }, + placementCode: 'pcode004', + transactionId: 'tx004', + bidId: 'bid004', + bidderRequestId: '117d765b87bed38', + auctionId: 'req000' + }, + // video without sizes + { + bidder: 'conversant', + params: { + site_id: siteId + }, + mediaTypes: { + video: { + context: 'instream', + mimes: ['video/mp4', 'video/x-flv'] + } + }, + placementCode: 'pcode005', + transactionId: 'tx005', + bidId: 'bid005', + bidderRequestId: '117d765b87bed38', + auctionId: 'req000' }]; const bidResponses = { @@ -128,6 +181,8 @@ describe('Conversant adapter tests', function() { expect(spec.isBidRequestValid(bidRequests[1])).to.be.true; expect(spec.isBidRequestValid(bidRequests[2])).to.be.true; expect(spec.isBidRequestValid(bidRequests[3])).to.be.true; + expect(spec.isBidRequestValid(bidRequests[4])).to.be.true; + expect(spec.isBidRequestValid(bidRequests[5])).to.be.true; const simpleVideo = JSON.parse(JSON.stringify(bidRequests[3])); simpleVideo.params.site_id = 123; @@ -150,7 +205,7 @@ describe('Conversant adapter tests', function() { expect(payload).to.have.property('id', 'req000'); expect(payload).to.have.property('at', 1); expect(payload).to.have.property('imp'); - expect(payload.imp).to.be.an('array').with.lengthOf(4); + expect(payload.imp).to.be.an('array').with.lengthOf(6); expect(payload.imp[0]).to.have.property('id', 'bid000'); expect(payload.imp[0]).to.have.property('secure', 0); @@ -168,18 +223,18 @@ describe('Conversant adapter tests', function() { expect(payload.imp[1]).to.have.property('secure', 0); expect(payload.imp[1]).to.have.property('bidfloor', 0); expect(payload.imp[1]).to.have.property('displaymanager', 'Prebid.js'); - expect(payload.imp[0]).to.have.property('displaymanagerver').that.matches(/^\d+\.\d+\.\d+$/); + expect(payload.imp[1]).to.have.property('displaymanagerver').that.matches(/^\d+\.\d+\.\d+$/); expect(payload.imp[1]).to.not.have.property('tagid'); expect(payload.imp[1]).to.have.property('banner'); expect(payload.imp[1].banner).to.not.have.property('pos'); expect(payload.imp[1].banner).to.have.property('format'); - expect(payload.imp[1].banner.format).to.deep.equal([{w: 468, h: 60}]); + expect(payload.imp[1].banner.format).to.deep.equal([{w: 728, h: 90}, {w: 468, h: 60}]); expect(payload.imp[2]).to.have.property('id', 'bid002'); expect(payload.imp[2]).to.have.property('secure', 0); expect(payload.imp[2]).to.have.property('bidfloor', 0); expect(payload.imp[2]).to.have.property('displaymanager', 'Prebid.js'); - expect(payload.imp[0]).to.have.property('displaymanagerver').that.matches(/^\d+\.\d+\.\d+$/); + expect(payload.imp[2]).to.have.property('displaymanagerver').that.matches(/^\d+\.\d+\.\d+$/); expect(payload.imp[2]).to.have.property('banner'); expect(payload.imp[2].banner).to.have.property('pos', 2); expect(payload.imp[2].banner).to.have.property('format'); @@ -189,12 +244,12 @@ describe('Conversant adapter tests', function() { expect(payload.imp[3]).to.have.property('secure', 0); expect(payload.imp[3]).to.have.property('bidfloor', 0); expect(payload.imp[3]).to.have.property('displaymanager', 'Prebid.js'); - expect(payload.imp[0]).to.have.property('displaymanagerver').that.matches(/^\d+\.\d+\.\d+$/); + expect(payload.imp[3]).to.have.property('displaymanagerver').that.matches(/^\d+\.\d+\.\d+$/); expect(payload.imp[3]).to.not.have.property('tagid'); expect(payload.imp[3]).to.have.property('video'); expect(payload.imp[3].video).to.not.have.property('pos'); - expect(payload.imp[3].video).to.have.property('w', 640); - expect(payload.imp[3].video).to.have.property('h', 480); + expect(payload.imp[3].video).to.have.property('w', 632); + expect(payload.imp[3].video).to.have.property('h', 499); expect(payload.imp[3].video).to.have.property('mimes'); expect(payload.imp[3].video.mimes).to.deep.equal(['video/mp4', 'video/x-flv']); expect(payload.imp[3].video).to.have.property('protocols'); @@ -204,6 +259,42 @@ describe('Conversant adapter tests', function() { expect(payload.imp[3].video).to.have.property('maxduration', 30); expect(payload.imp[3]).to.not.have.property('banner'); + expect(payload.imp[4]).to.have.property('id', 'bid004'); + expect(payload.imp[4]).to.have.property('secure', 0); + expect(payload.imp[4]).to.have.property('bidfloor', 0); + expect(payload.imp[4]).to.have.property('displaymanager', 'Prebid.js'); + expect(payload.imp[4]).to.have.property('displaymanagerver').that.matches(/^\d+\.\d+\.\d+$/); + expect(payload.imp[4]).to.not.have.property('tagid'); + expect(payload.imp[4]).to.have.property('video'); + expect(payload.imp[4].video).to.not.have.property('pos'); + expect(payload.imp[4].video).to.have.property('w', 1024); + expect(payload.imp[4].video).to.have.property('h', 768); + expect(payload.imp[4].video).to.have.property('mimes'); + expect(payload.imp[4].video.mimes).to.deep.equal(['video/mp4', 'video/x-flv']); + expect(payload.imp[4].video).to.have.property('protocols'); + expect(payload.imp[4].video.protocols).to.deep.equal([1, 2, 3]); + expect(payload.imp[4].video).to.have.property('api'); + expect(payload.imp[4].video.api).to.deep.equal([2, 3]); + expect(payload.imp[4].video).to.have.property('maxduration', 30); + expect(payload.imp[4]).to.not.have.property('banner'); + + expect(payload.imp[5]).to.have.property('id', 'bid005'); + expect(payload.imp[5]).to.have.property('secure', 0); + expect(payload.imp[5]).to.have.property('bidfloor', 0); + expect(payload.imp[5]).to.have.property('displaymanager', 'Prebid.js'); + expect(payload.imp[5]).to.have.property('displaymanagerver').that.matches(/^\d+\.\d+\.\d+$/); + expect(payload.imp[5]).to.not.have.property('tagid'); + expect(payload.imp[5]).to.have.property('video'); + expect(payload.imp[5].video).to.not.have.property('pos'); + expect(payload.imp[5].video).to.not.have.property('w'); + expect(payload.imp[5].video).to.not.have.property('h'); + expect(payload.imp[5].video).to.have.property('mimes'); + expect(payload.imp[5].video.mimes).to.deep.equal(['video/mp4', 'video/x-flv']); + expect(payload.imp[5].video).to.not.have.property('protocols'); + expect(payload.imp[5].video).to.not.have.property('api'); + expect(payload.imp[5].video).to.not.have.property('maxduration'); + expect(payload.imp[5]).to.not.have.property('banner'); + expect(payload).to.have.property('site'); expect(payload.site).to.have.property('id', siteId); expect(payload.site).to.have.property('mobile').that.is.oneOf([0, 1]); @@ -254,8 +345,8 @@ describe('Conversant adapter tests', function() { expect(bid).to.have.property('currency', 'USD'); expect(bid).to.have.property('cpm', 3.99); expect(bid).to.have.property('creativeId', '1003'); - expect(bid).to.have.property('width', 640); - expect(bid).to.have.property('height', 480); + expect(bid).to.have.property('width', 632); + expect(bid).to.have.property('height', 499); expect(bid).to.have.property('vastUrl', 'markup003'); expect(bid).to.have.property('mediaType', 'video'); expect(bid).to.have.property('ttl', 300); diff --git a/test/spec/modules/coxBidAdapter_spec.js b/test/spec/modules/coxBidAdapter_spec.js deleted file mode 100644 index 9dd5a5a92b4..00000000000 --- a/test/spec/modules/coxBidAdapter_spec.js +++ /dev/null @@ -1,233 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/coxBidAdapter'; -import { newBidder } from 'src/adapters/bidderFactory'; -import { deepClone } from 'src/utils'; - -describe('CoxBidAdapter', () => { - const adapter = newBidder(spec); - - describe('isBidRequestValid', () => { - const CONFIG = { - 'bidder': 'cox', - 'params': { - 'id': '8888', - 'siteId': '1000', - 'size': '300x250' - } - }; - - it('should return true when required params present', () => { - expect(spec.isBidRequestValid(CONFIG)).to.equal(true); - }); - - it('should return false when id param is missing', () => { - let config = deepClone(CONFIG); - config.params.id = null; - - expect(spec.isBidRequestValid(config)).to.equal(false); - }); - - it('should return false when size param is missing', () => { - let config = deepClone(CONFIG); - config.params.size = null; - - expect(spec.isBidRequestValid(config)).to.equal(false); - }); - }); - - describe('buildRequests', () => { - const PROD_DOMAIN = 'ad.afy11.net'; - const PPE_DOMAIN = 'ppe-ad.afy11.net'; - const STG_DOMAIN = 'staging-ad.afy11.net'; - - const BID_INFO = [{ - 'bidder': 'cox', - 'params': { - 'id': '8888', - 'siteId': '1000', - 'size': '300x250' - }, - 'sizes': [[300, 250]], - 'transactionId': 'tId-foo', - 'bidId': 'bId-bar' - }]; - - it('should send bid request to PROD_DOMAIN via GET', () => { - let request = spec.buildRequests(BID_INFO); - expect(request.url).to.have.string(PROD_DOMAIN); - expect(request.method).to.equal('GET'); - }); - - it('should send bid request to PPE_DOMAIN when configured', () => { - let clone = deepClone(BID_INFO); - clone[0].params.env = 'PPE'; - - let request = spec.buildRequests(clone); - expect(request.url).to.have.string(PPE_DOMAIN); - }); - - it('should send bid request to STG_DOMAIN when configured', () => { - let clone = deepClone(BID_INFO); - clone[0].params.env = 'STG'; - - let request = spec.buildRequests(clone); - expect(request.url).to.have.string(STG_DOMAIN); - }); - - it('should return empty when id is invalid', () => { - let clone = deepClone(BID_INFO); - clone[0].params.id = null; - - let request = spec.buildRequests(clone); - expect(request).to.be.an('object').that.is.empty; - }); - - it('should return empty when size is invalid', () => { - let clone = deepClone(BID_INFO); - clone[0].params.size = 'FOO'; - - let request = spec.buildRequests(clone); - expect(request).to.be.an('object').that.is.empty; - }); - }) - - describe('interpretResponse', () => { - const BID_INFO_1 = [{ - 'bidder': 'cox', - 'params': { - 'id': '2000005657007', - 'siteId': '2000101880180', - 'size': '728x90' - }, - 'transactionId': 'foo_1', - 'bidId': 'bar_1' - }]; - - const BID_INFO_2 = [{ - 'bidder': 'cox', - 'params': { - 'id': '2000005658887', - 'siteId': '2000101880180', - 'size': '300x250' - }, - 'transactionId': 'foo_2', - 'bidId': 'bar_2' - }]; - - const RESPONSE_1 = { body: { - 'zones': { - 'as2000005657007': { - 'price': 1.88, - 'dealid': 'AA128460', - 'ad': '

2000005657007
728x90

', - 'adid': '7007-728-90' - }}}}; - - const RESPONSE_2 = { body: { - 'zones': { - 'as2000005658887': { - 'price': 2.88, - 'ad': '

2000005658887
300x250

', - 'adid': '888-88' - }}}}; - - const PBJS_BID_1 = { - 'requestId': 'bar_1', - 'cpm': 1.88, - 'width': '728', - 'height': '90', - 'creativeId': '7007-728-90', - 'dealId': 'AA128460', - 'currency': 'USD', - 'netRevenue': true, - 'ttl': 300, - 'ad': '

2000005657007
728x90

' - }; - - const PBJS_BID_2 = { - 'requestId': 'bar_2', - 'cpm': 2.88, - 'width': '300', - 'height': '250', - 'creativeId': '888-88', - 'dealId': undefined, - 'currency': 'USD', - 'netRevenue': true, - 'ttl': 300, - 'ad': '

2000005658887
300x250

' - }; - - it('should return correct pbjs bid', () => { - let result = spec.interpretResponse(RESPONSE_2, spec.buildRequests(BID_INFO_2)); - expect(result[0]).to.eql(PBJS_BID_2); - }); - - it('should handle multiple bid instances', () => { - let request1 = spec.buildRequests(BID_INFO_1); - let request2 = spec.buildRequests(BID_INFO_2); - - let result2 = spec.interpretResponse(RESPONSE_2, request2); - expect(result2[0]).to.eql(PBJS_BID_2); - - let result1 = spec.interpretResponse(RESPONSE_1, request1); - expect(result1[0]).to.eql(PBJS_BID_1); - }); - - it('should return empty when price is zero', () => { - let clone = deepClone(RESPONSE_1); - clone.body.zones.as2000005657007.price = 0; - - let result = spec.interpretResponse(clone, spec.buildRequests(BID_INFO_1)); - expect(result).to.be.an('array').that.is.empty; - }); - - it('should return empty when there is no ad', () => { - let clone = deepClone(RESPONSE_1); - clone.body.zones.as2000005657007.ad = null; - - let result = spec.interpretResponse(clone, spec.buildRequests(BID_INFO_1)); - expect(result).to.be.an('array').that.is.empty; - }); - - it('should return empty when there is no ad unit info', () => { - let clone = deepClone(RESPONSE_1); - delete (clone.body.zones.as2000005657007); - - let result = spec.interpretResponse(clone, spec.buildRequests(BID_INFO_1)); - expect(result).to.be.an('array').that.is.empty; - }); - }); - - describe('getUserSyncs', () => { - const RESPONSE = [{ body: { - 'zones': {}, - 'tpCookieSync': ['http://pixel.foo.com/', 'http://pixel.bar.com/'] - }}]; - - it('should return correct pbjs syncs when pixels are enabled', () => { - let syncs = spec.getUserSyncs({ pixelEnabled: true }, RESPONSE); - - expect(syncs.map(x => x.type)).to.eql(['image', 'image']); - expect(syncs.map(x => x.url)).to.have.members(['http://pixel.bar.com/', 'http://pixel.foo.com/']); - }); - - it('should return empty when pixels are not enabled', () => { - let syncs = spec.getUserSyncs({ pixelEnabled: false }, RESPONSE); - - expect(syncs).to.be.an('array').that.is.empty; - }); - - it('should return empty when response has no sync data', () => { - let clone = deepClone(RESPONSE); - delete (clone[0].body.tpCookieSync); - - let syncs = spec.getUserSyncs({ pixelEnabled: true }, clone); - expect(syncs).to.be.an('array').that.is.empty; - }); - - it('should return empty when response is empty', () => { - let syncs = spec.getUserSyncs({ pixelEnabled: true }, [{}]); - expect(syncs).to.be.an('array').that.is.empty; - }); - }); -}); diff --git a/test/spec/modules/criteoBidAdapter_spec.js b/test/spec/modules/criteoBidAdapter_spec.js index 6e2276d7e22..90059d5a1aa 100755 --- a/test/spec/modules/criteoBidAdapter_spec.js +++ b/test/spec/modules/criteoBidAdapter_spec.js @@ -1,10 +1,16 @@ import { expect } from 'chai'; -import { spec } from 'modules/criteoBidAdapter'; +import { cryptoVerify, spec, FAST_BID_PUBKEY } from 'modules/criteoBidAdapter'; +import { createBid } from 'src/bidfactory'; +import CONSTANTS from 'src/constants.json'; import * as utils from 'src/utils'; -describe('The Criteo bidding adapter', () => { - describe('isBidRequestValid', () => { - it('should return false when given an invalid bid', () => { +describe('The Criteo bidding adapter', function () { + beforeEach(function () { + // Remove FastBid to avoid side effects. + localStorage.removeItem('criteo_fast_bid'); + }); + describe('isBidRequestValid', function () { + it('should return false when given an invalid bid', function () { const bid = { bidder: 'criteo', }; @@ -12,7 +18,7 @@ describe('The Criteo bidding adapter', () => { expect(isValid).to.equal(false); }); - it('should return true when given a zoneId bid', () => { + it('should return true when given a zoneId bid', function () { const bid = { bidder: 'criteo', params: { @@ -23,7 +29,7 @@ describe('The Criteo bidding adapter', () => { expect(isValid).to.equal(true); }); - it('should return true when given a networkId bid', () => { + it('should return true when given a networkId bid', function () { const bid = { bidder: 'criteo', params: { @@ -34,7 +40,7 @@ describe('The Criteo bidding adapter', () => { expect(isValid).to.equal(true); }); - it('should return true when given a mixed bid with both a zoneId and a networkId', () => { + it('should return true when given a mixed bid with both a zoneId and a networkId', function () { const bid = { bidder: 'criteo', params: { @@ -47,7 +53,7 @@ describe('The Criteo bidding adapter', () => { }); }); - describe('buildRequests', () => { + describe('buildRequests', function () { const bidderRequest = { timeout: 3000, gdprConsent: { gdprApplies: 1, @@ -60,7 +66,7 @@ describe('The Criteo bidding adapter', () => { }, }; - it('should properly build a zoneId request', () => { + it('should properly build a zoneId request', function () { const bidRequests = [ { bidder: 'criteo', @@ -88,7 +94,7 @@ describe('The Criteo bidding adapter', () => { expect(ortbRequest.gdprConsent.consentGiven).to.equal(true); }); - it('should properly build a networkId request', () => { + it('should properly build a networkId request', function () { const bidderRequest = { timeout: 3000, gdprConsent: { @@ -129,7 +135,7 @@ describe('The Criteo bidding adapter', () => { expect(ortbRequest.gdprConsent.consentGiven).to.equal(undefined); }); - it('should properly build a mixed request', () => { + it('should properly build a mixed request', function () { const bidderRequest = { timeout: 3000 }; const bidRequests = [ { @@ -170,7 +176,7 @@ describe('The Criteo bidding adapter', () => { expect(ortbRequest.gdprConsent).to.equal(undefined); }); - it('should properly build request with undefined gdpr consent fields when they are not provided', () => { + it('should properly build request with undefined gdpr consent fields when they are not provided', function () { const bidRequests = [ { bidder: 'criteo', @@ -194,15 +200,15 @@ describe('The Criteo bidding adapter', () => { }); }); - describe('interpretResponse', () => { - it('should return an empty array when parsing a no bid response', () => { + describe('interpretResponse', function () { + it('should return an empty array when parsing a no bid response', function () { const response = {}; const request = { bidRequests: [] }; const bids = spec.interpretResponse(response, request); expect(bids).to.have.lengthOf(0); }); - it('should properly parse a bid response with a networkId', () => { + it('should properly parse a bid response with a networkId', function () { const response = { body: { slots: [{ @@ -232,11 +238,12 @@ describe('The Criteo bidding adapter', () => { expect(bids[0].height).to.equal(90); }); - it('should properly parse a bid responsewith with a zoneId', () => { + it('should properly parse a bid responsewith with a zoneId', function () { const response = { body: { slots: [{ impid: 'test-requestId', + bidId: 'abc123', cpm: 1.23, creative: 'test-ad', width: 728, @@ -257,13 +264,14 @@ describe('The Criteo bidding adapter', () => { const bids = spec.interpretResponse(response, request); expect(bids).to.have.lengthOf(1); expect(bids[0].requestId).to.equal('test-bidId'); + expect(bids[0].adId).to.equal('abc123'); expect(bids[0].cpm).to.equal(1.23); expect(bids[0].ad).to.equal('test-ad'); expect(bids[0].width).to.equal(728); expect(bids[0].height).to.equal(90); }); - it('should properly parse a bid responsewith with a zoneId passed as a string', () => { + it('should properly parse a bid responsewith with a zoneId passed as a string', function () { const response = { body: { slots: [{ @@ -293,5 +301,56 @@ describe('The Criteo bidding adapter', () => { expect(bids[0].width).to.equal(728); expect(bids[0].height).to.equal(90); }); + + it('should generate unique adIds if none are returned by the endpoint', function () { + const response = { + body: { + slots: [{ + impid: 'test-requestId', + cpm: 1.23, + creative: 'test-ad', + width: 300, + height: 250, + }, { + impid: 'test-requestId', + cpm: 4.56, + creative: 'test-ad', + width: 728, + height: 90, + }], + }, + }; + const request = { + bidRequests: [{ + adUnitCode: 'test-requestId', + bidId: 'test-bidId', + sizes: [[300, 250], [728, 90]], + params: { + networkId: 456, + } + }] + }; + const bids = spec.interpretResponse(response, request); + expect(bids).to.have.lengthOf(2); + const prebidBids = bids.map(bid => Object.assign(createBid(CONSTANTS.STATUS.GOOD, request.bidRequests[0]), bid)); + expect(prebidBids[0].adId).to.not.equal(prebidBids[1].adId); + }); + }); + + describe('cryptoVerify', function () { + const TEST_HASH = 'vBeD8Q7GU6lypFbzB07W8hLGj7NL+p7dI9ro2tCxkrmyv0F6stNuoNd75Us33iNKfEoW+cFWypelr6OJPXxki2MXWatRhJuUJZMcK4VBFnxi3Ro+3a0xEfxE4jJm4eGe98iC898M+/YFHfp+fEPEnS6pEyw124ONIFZFrcejpHU='; + + it('should verify right signature', function () { + expect(cryptoVerify(FAST_BID_PUBKEY, TEST_HASH, 'test')).to.equal(true); + }); + + it('should verify wrong signature', function () { + expect(cryptoVerify(FAST_BID_PUBKEY, TEST_HASH, 'test wrong')).to.equal(false); + }); + + it('should return undefined with incompatible browsers', function () { + // Here use a null hash to make the call to crypto library fail and simulate a browser failure + expect(cryptoVerify(FAST_BID_PUBKEY, null, 'test')).to.equal.undefined; + }); }); }); diff --git a/test/spec/modules/currency_spec.js b/test/spec/modules/currency_spec.js index a4ef643fece..44816dfd078 100644 --- a/test/spec/modules/currency_spec.js +++ b/test/spec/modules/currency_spec.js @@ -17,35 +17,117 @@ var expect = require('chai').expect; describe('currency', function () { let fakeCurrencyFileServer; + let sandbox; + let clock; let fn = sinon.spy(); let hookFn = createHook('asyncSeries', fn, 'addBidResponse'); - beforeEach(() => { + beforeEach(function () { fakeCurrencyFileServer = sinon.fakeServer.create(); }); - afterEach(() => { + afterEach(function () { fakeCurrencyFileServer.restore(); }); - describe('setConfig', () => { - it('results in currencySupportEnabled = false when currency not configured', () => { + describe('setConfig', function () { + beforeEach(function() { + sandbox = sinon.sandbox.create(); + clock = sinon.useFakeTimers(1046952000000); // 2003-03-06T12:00:00Z + }); + + afterEach(function () { + sandbox.restore(); + clock.restore(); + }); + + it('results in currencySupportEnabled = false when currency not configured', function () { setConfig({}); expect(currencySupportEnabled).to.equal(false); }); - it('results in currencySupportEnabled = true and currencyRates being loaded when configured', () => { + it('results in currencySupportEnabled = true and currencyRates being loaded when configured', function () { fakeCurrencyFileServer.respondWith(JSON.stringify(getCurrencyRates())); setConfig({ 'adServerCurrency': 'JPY' }); fakeCurrencyFileServer.respond(); expect(currencyRates.dataAsOf).to.equal('2017-04-25'); expect(currencySupportEnabled).to.equal(true); }); + + it('currency file is called even when default rates are specified', function() { + // RESET to request currency file (specifically url value for this test) + setConfig({ 'adServerCurrency': undefined }); + + // DO NOT SET DEFAULT RATES, currency file should be requested + setConfig({ + 'adServerCurrency': 'JPY' + }); + fakeCurrencyFileServer.respond(); + expect(fakeCurrencyFileServer.requests.length).to.equal(1); + expect(fakeCurrencyFileServer.requests[0].url).to.equal('https://cdn.jsdelivr.net/gh/prebid/currency-file@1/latest.json?date=20030306'); + + // RESET to request currency file (specifically url value for this test) + setConfig({ 'adServerCurrency': undefined }); + + // SET DEFAULT RATES, currency file should STILL be requested + setConfig({ + 'adServerCurrency': 'JPY', + 'defaultRates': { + 'GBP': { 'CNY': 66, 'JPY': 132, 'USD': 264 }, + 'USD': { 'CNY': 60, 'GBP': 120, 'JPY': 240 } + } }); + fakeCurrencyFileServer.respond(); + expect(fakeCurrencyFileServer.requests.length).to.equal(2); + expect(fakeCurrencyFileServer.requests[1].url).to.equal('https://cdn.jsdelivr.net/gh/prebid/currency-file@1/latest.json?date=20030306'); + }); + + it('date macro token $$TODAY$$ is replaced by current date (formatted as yyyymmdd)', function () { + // RESET to request currency file (specifically url value for this test) + setConfig({ 'adServerCurrency': undefined }); + + // date macro should replace $$TODAY$$ with date when DEFAULT_CURRENCY_RATE_URL is used + setConfig({ 'adServerCurrency': 'JPY' }); + fakeCurrencyFileServer.respond(); + expect(fakeCurrencyFileServer.requests[0].url).to.equal('https://cdn.jsdelivr.net/gh/prebid/currency-file@1/latest.json?date=20030306'); + + // RESET to request currency file (specifically url value for this test) + setConfig({ 'adServerCurrency': undefined }); + + // date macro should not modify 'conversionRateFile' if TOKEN is not found + setConfig({ + 'adServerCurrency': 'JPY', + 'conversionRateFile': 'http://test.net/currency.json?date=foobar' + }); + fakeCurrencyFileServer.respond(); + expect(fakeCurrencyFileServer.requests[1].url).to.equal('http://test.net/currency.json?date=foobar'); + + // RESET to request currency file (specifically url value for this test) + setConfig({ 'adServerCurrency': undefined }); + + // date macro should replace $$TODAY$$ with date for 'conversionRateFile' is configured + setConfig({ + 'adServerCurrency': 'JPY', + 'conversionRateFile': 'http://test.net/currency.json?date=$$TODAY$$' + }); + fakeCurrencyFileServer.respond(); + expect(fakeCurrencyFileServer.requests[2].url).to.equal('http://test.net/currency.json?date=20030306'); + + // RESET to request currency file (specifically url value for this test) + setConfig({ 'adServerCurrency': undefined }); + + // MULTIPLE TOKENS used in a url is not supported. Only the TOKEN at left-most position is REPLACED + setConfig({ + 'adServerCurrency': 'JPY', + 'conversionRateFile': 'http://test.net/$$TODAY$$/currency.json?date=$$TODAY$$' + }); + fakeCurrencyFileServer.respond(); + expect(fakeCurrencyFileServer.requests[3].url).to.equal('http://test.net/20030306/currency.json?date=$$TODAY$$'); + }); }); - describe('bidder override', () => { - it('allows setConfig to set bidder currency', () => { + describe('bidder override', function () { + it('allows setConfig to set bidder currency', function () { setConfig({}); var bid = { cpm: 1, bidder: 'rubicon' }; @@ -62,10 +144,12 @@ describe('currency', function () { innerBid = bid; }); - expect(innerBid.currency).to.equal('GBP') + expect(innerBid.currency).to.equal('GBP'); + expect(typeof innerBid.getCpmInNewCurrency).to.equal('function'); + expect(innerBid.getCpmInNewCurrency('GBP')).to.equal('1.000'); }); - it('uses adapter currency over currency override if specified', () => { + it('uses adapter currency over currency override if specified', function () { setConfig({}); var bid = { cpm: 1, currency: 'JPY', bidder: 'rubicon' }; @@ -82,10 +166,12 @@ describe('currency', function () { innerBid = bid; }); - expect(innerBid.currency).to.equal('JPY') + expect(innerBid.currency).to.equal('JPY'); + expect(typeof innerBid.getCpmInNewCurrency).to.equal('function'); + expect(innerBid.getCpmInNewCurrency('JPY')).to.equal('1.000'); }); - it('uses rates specified in json when provided', () => { + it('uses rates specified in json when provided', function () { setConfig({ adServerCurrency: 'USD', rates: { @@ -103,9 +189,11 @@ describe('currency', function () { }); expect(innerBid.cpm).to.equal('1.0000'); + expect(typeof innerBid.getCpmInNewCurrency).to.equal('function'); + expect(innerBid.getCpmInNewCurrency('JPY')).to.equal('100.000'); }); - it('uses default rates when currency file fails to load', () => { + it('uses default rates when currency file fails to load', function () { setConfig({}); setConfig({ @@ -128,11 +216,13 @@ describe('currency', function () { }); expect(innerBid.cpm).to.equal('1.0000'); + expect(typeof innerBid.getCpmInNewCurrency).to.equal('function'); + expect(innerBid.getCpmInNewCurrency('JPY')).to.equal('100.000'); }); }); - describe('currency.addBidResponseDecorator bidResponseQueue', () => { - it('not run until currency rates file is loaded', () => { + describe('currency.addBidResponseDecorator bidResponseQueue', function () { + it('not run until currency rates file is loaded', function () { setConfig({}); fakeCurrencyFileServer.respondWith(JSON.stringify(getCurrencyRates())); @@ -153,8 +243,8 @@ describe('currency', function () { }); }); - describe('currency.addBidResponseDecorator', () => { - it('should leave bid at 1 when currency support is not enabled and fromCurrency is USD', () => { + describe('currency.addBidResponseDecorator', function () { + it('should leave bid at 1 when currency support is not enabled and fromCurrency is USD', function () { setConfig({}); var bid = { 'cpm': 1, 'currency': 'USD' }; var innerBid; @@ -164,8 +254,9 @@ describe('currency', function () { expect(innerBid.cpm).to.equal(1); }); - it('should result in NO_BID when currency support is not enabled and fromCurrency is not USD', () => { + it('should result in NO_BID when currency support is not enabled and fromCurrency is not USD', function () { setConfig({}); + var bid = { 'cpm': 1, 'currency': 'GBP' }; var innerBid; addBidResponseHook('elementId', bid, function(adCodeId, bid) { @@ -174,7 +265,7 @@ describe('currency', function () { expect(innerBid.statusMessage).to.equal('Bid returned empty or error response'); }); - it('should not buffer bid when currency is already in desired currency', () => { + it('should not buffer bid when currency is already in desired currency', function () { setConfig({ 'adServerCurrency': 'USD' }); @@ -186,7 +277,10 @@ describe('currency', function () { expect(bid).to.equal(innerBid); }); - it('should result in NO_BID when fromCurrency is not supported in file', () => { + it('should result in NO_BID when fromCurrency is not supported in file', function () { + // RESET to request currency file + setConfig({ 'adServerCurrency': undefined }); + fakeCurrencyFileServer.respondWith(JSON.stringify(getCurrencyRates())); setConfig({ 'adServerCurrency': 'JPY' }); fakeCurrencyFileServer.respond(); @@ -198,7 +292,7 @@ describe('currency', function () { expect(innerBid.statusMessage).to.equal('Bid returned empty or error response'); }); - it('should result in NO_BID when adServerCurrency is not supported in file', () => { + it('should result in NO_BID when adServerCurrency is not supported in file', function () { fakeCurrencyFileServer.respondWith(JSON.stringify(getCurrencyRates())); setConfig({ 'adServerCurrency': 'ABC' }); fakeCurrencyFileServer.respond(); @@ -210,7 +304,7 @@ describe('currency', function () { expect(innerBid.statusMessage).to.equal('Bid returned empty or error response'); }); - it('should return 1 when currency support is enabled and same currency code is requested as is set to adServerCurrency', () => { + it('should return 1 when currency support is enabled and same currency code is requested as is set to adServerCurrency', function () { fakeCurrencyFileServer.respondWith(JSON.stringify(getCurrencyRates())); setConfig({ 'adServerCurrency': 'JPY' }); fakeCurrencyFileServer.respond(); @@ -223,7 +317,7 @@ describe('currency', function () { expect(innerBid.currency).to.equal('JPY'); }); - it('should return direct conversion rate when fromCurrency is one of the configured bases', () => { + it('should return direct conversion rate when fromCurrency is one of the configured bases', function () { fakeCurrencyFileServer.respondWith(JSON.stringify(getCurrencyRates())); setConfig({ 'adServerCurrency': 'GBP' }); fakeCurrencyFileServer.respond(); @@ -236,7 +330,7 @@ describe('currency', function () { expect(innerBid.currency).to.equal('GBP'); }); - it('should return reciprocal conversion rate when adServerCurrency is one of the configured bases, but fromCurrency is not', () => { + it('should return reciprocal conversion rate when adServerCurrency is one of the configured bases, but fromCurrency is not', function () { fakeCurrencyFileServer.respondWith(JSON.stringify(getCurrencyRates())); setConfig({ 'adServerCurrency': 'GBP' }); fakeCurrencyFileServer.respond(); @@ -249,7 +343,7 @@ describe('currency', function () { expect(innerBid.currency).to.equal('GBP'); }); - it('should return intermediate conversion rate when neither fromCurrency nor adServerCurrency is one of the configured bases', () => { + it('should return intermediate conversion rate when neither fromCurrency nor adServerCurrency is one of the configured bases', function () { fakeCurrencyFileServer.respondWith(JSON.stringify(getCurrencyRates())); setConfig({ 'adServerCurrency': 'CNY' }); fakeCurrencyFileServer.respond(); diff --git a/test/spec/modules/danmarketBidAdapter_spec.js b/test/spec/modules/danmarketBidAdapter_spec.js index 243e2fdfb66..973cd2afb1c 100644 --- a/test/spec/modules/danmarketBidAdapter_spec.js +++ b/test/spec/modules/danmarketBidAdapter_spec.js @@ -5,13 +5,13 @@ import { newBidder } from 'src/adapters/bidderFactory'; describe('DAN_Marketplace Adapter', function () { const adapter = newBidder(spec); - describe('inherited functions', () => { - it('exists and is a function', () => { + describe('inherited functions', function () { + it('exists and is a function', function () { expect(adapter.callBids).to.exist.and.to.be.a('function'); }); }); - describe('isBidRequestValid', () => { + describe('isBidRequestValid', function () { let bid = { 'bidder': 'danmarket', 'params': { @@ -24,11 +24,11 @@ describe('DAN_Marketplace Adapter', function () { 'auctionId': '1d1a030790a475', }; - it('should return true when required params found', () => { + it('should return true when required params found', function () { expect(spec.isBidRequestValid(bid)).to.equal(true); }); - it('should return false when required params are not passed', () => { + it('should return false when required params are not passed', function () { let bid = Object.assign({}, bid); delete bid.params; bid.params = { @@ -38,7 +38,7 @@ describe('DAN_Marketplace Adapter', function () { }); }); - describe('buildRequests', () => { + describe('buildRequests', function () { let bidRequests = [ { 'bidder': 'danmarket', @@ -75,7 +75,7 @@ describe('DAN_Marketplace Adapter', function () { } ]; - it('should attach valid params to the tag', () => { + it('should attach valid params to the tag', function () { const request = spec.buildRequests([bidRequests[0]]); const payload = request.data; expect(payload).to.be.an('object'); @@ -84,7 +84,7 @@ describe('DAN_Marketplace Adapter', function () { expect(payload).to.have.property('auids', '5'); }); - it('auids must not be duplicated', () => { + it('auids must not be duplicated', function () { const request = spec.buildRequests(bidRequests); const payload = request.data; expect(payload).to.be.an('object'); @@ -93,7 +93,7 @@ describe('DAN_Marketplace Adapter', function () { expect(payload).to.have.property('auids', '5,6'); }); - it('pt parameter must be "gross" if params.priceType === "gross"', () => { + it('pt parameter must be "gross" if params.priceType === "gross"', function () { bidRequests[1].params.priceType = 'gross'; const request = spec.buildRequests(bidRequests); const payload = request.data; @@ -104,7 +104,7 @@ describe('DAN_Marketplace Adapter', function () { delete bidRequests[1].params.priceType; }); - it('pt parameter must be "net" or "gross"', () => { + it('pt parameter must be "net" or "gross"', function () { bidRequests[1].params.priceType = 'some'; const request = spec.buildRequests(bidRequests); const payload = request.data; @@ -115,7 +115,7 @@ describe('DAN_Marketplace Adapter', function () { delete bidRequests[1].params.priceType; }); - it('if gdprConsent is present payload must have gdpr params', () => { + it('if gdprConsent is present payload must have gdpr params', function () { const request = spec.buildRequests(bidRequests, {gdprConsent: {consentString: 'AAA', gdprApplies: true}}); const payload = request.data; expect(payload).to.be.an('object'); @@ -123,7 +123,7 @@ describe('DAN_Marketplace Adapter', function () { expect(payload).to.have.property('gdpr_applies', 1); }); - it('if gdprApplies is false gdpr_applies must be 0', () => { + it('if gdprApplies is false gdpr_applies must be 0', function () { const request = spec.buildRequests(bidRequests, {gdprConsent: {consentString: 'AAA', gdprApplies: false}}); const payload = request.data; expect(payload).to.be.an('object'); @@ -131,7 +131,7 @@ describe('DAN_Marketplace Adapter', function () { expect(payload).to.have.property('gdpr_applies', 0); }); - it('if gdprApplies is undefined gdpr_applies must be 1', () => { + it('if gdprApplies is undefined gdpr_applies must be 1', function () { const request = spec.buildRequests(bidRequests, {gdprConsent: {consentString: 'AAA'}}); const payload = request.data; expect(payload).to.be.an('object'); @@ -140,7 +140,7 @@ describe('DAN_Marketplace Adapter', function () { }); }); - describe('interpretResponse', () => { + describe('interpretResponse', function () { const responses = [ {'bid': [{'price': 1.15, 'adm': '
test content 1
', 'auid': 4, 'h': 250, 'w': 300}], 'seat': '1'}, {'bid': [{'price': 0.5, 'adm': '
test content 2
', 'auid': 5, 'h': 90, 'w': 728}], 'seat': '1'}, @@ -151,7 +151,7 @@ describe('DAN_Marketplace Adapter', function () { {'seat': '1'}, ]; - it('should get correct bid response', () => { + it('should get correct bid response', function () { const bidRequests = [ { 'bidder': 'danmarket', @@ -185,7 +185,7 @@ describe('DAN_Marketplace Adapter', function () { expect(result).to.deep.equal(expectedResponse); }); - it('should get correct multi bid response', () => { + it('should get correct multi bid response', function () { const bidRequests = [ { 'bidder': 'danmarket', @@ -265,7 +265,7 @@ describe('DAN_Marketplace Adapter', function () { expect(result).to.deep.equal(expectedResponse); }); - it('handles wrong and nobid responses', () => { + it('handles wrong and nobid responses', function () { const bidRequests = [ { 'bidder': 'danmarket', diff --git a/test/spec/modules/dfpAdServerVideo_spec.js b/test/spec/modules/dfpAdServerVideo_spec.js index 8f779412c80..8afc597d3b4 100644 --- a/test/spec/modules/dfpAdServerVideo_spec.js +++ b/test/spec/modules/dfpAdServerVideo_spec.js @@ -13,8 +13,8 @@ const bid = { adserverTargeting: { }, }; -describe('The DFP video support module', () => { - it('should make a legal request URL when given the required params', () => { +describe('The DFP video support module', function () { + it('should make a legal request URL when given the required params', function () { const url = parse(buildDfpVideoUrl({ adUnit: adUnit, bid: bid, @@ -39,7 +39,7 @@ describe('The DFP video support module', () => { expect(queryParams).to.have.property('url'); }); - it('can take an adserver url as a parameter', () => { + it('can take an adserver url as a parameter', function () { const bidCopy = Object.assign({ }, bid); bidCopy.vastUrl = 'vastUrl.example'; @@ -55,7 +55,7 @@ describe('The DFP video support module', () => { expect(queryObject.description_url).to.equal('vastUrl.example'); }); - it('requires a params object or url', () => { + it('requires a params object or url', function () { const url = buildDfpVideoUrl({ adUnit: adUnit, bid: bid, @@ -64,7 +64,7 @@ describe('The DFP video support module', () => { expect(url).to.be.undefined; }); - it('overwrites url params when both url and params object are given', () => { + it('overwrites url params when both url and params object are given', function () { const url = parse(buildDfpVideoUrl({ adUnit: adUnit, bid: bid, @@ -76,7 +76,7 @@ describe('The DFP video support module', () => { expect(queryObject.iu).to.equal('my/adUnit'); }); - it('should override param defaults with user-provided ones', () => { + it('should override param defaults with user-provided ones', function () { const url = parse(buildDfpVideoUrl({ adUnit: adUnit, bid: bid, @@ -89,7 +89,7 @@ describe('The DFP video support module', () => { expect(parseQS(url.query)).to.have.property('output', 'vast'); }); - it('should include the cache key and adserver targeting in cust_params', () => { + it('should include the cache key and adserver targeting in cust_params', function () { const bidCopy = Object.assign({ }, bid); bidCopy.adserverTargeting = { hb_adid: 'ad_id', @@ -110,7 +110,7 @@ describe('The DFP video support module', () => { expect(customParams).to.have.property('hb_cache_id', bid.videoCacheKey); }); - describe('special targeting unit test', () => { + describe('special targeting unit test', function () { const allTargetingData = { 'hb_format': 'video', 'hb_source': 'client', @@ -133,7 +133,7 @@ describe('The DFP video support module', () => { }; let targetingStub; - before(() => { + before(function () { targetingStub = sinon.stub(targeting, 'getAllTargeting'); targetingStub.returns({'video1': allTargetingData}); @@ -142,12 +142,12 @@ describe('The DFP video support module', () => { }); }); - after(() => { + after(function () { config.resetConfig(); targetingStub.restore(); }); - it('should include all adserver targeting in cust_params if pbjs.enableSendAllBids is true', () => { + it('should include all adserver targeting in cust_params if pbjs.enableSendAllBids is true', function () { const adUnitsCopy = utils.deepClone(adUnit); adUnitsCopy.bids.push({ 'bidder': 'testBidder2', @@ -183,7 +183,7 @@ describe('The DFP video support module', () => { }); }); - it('should merge the user-provided cust_params with the default ones', () => { + it('should merge the user-provided cust_params with the default ones', function () { const bidCopy = Object.assign({ }, bid); bidCopy.adserverTargeting = { hb_adid: 'ad_id', @@ -206,7 +206,7 @@ describe('The DFP video support module', () => { expect(customParams).to.have.property('my_targeting', 'foo'); }); - it('should merge the user-provided cust-params with the default ones when using url object', () => { + it('should merge the user-provided cust-params with the default ones when using url object', function () { const bidCopy = Object.assign({ }, bid); bidCopy.adserverTargeting = { hb_adid: 'ad_id', @@ -228,7 +228,7 @@ describe('The DFP video support module', () => { expect(customParams).to.have.property('hb_cache_id', 'abc'); }); - it('should not overwrite an existing description_url for object input and cache disabled', () => { + it('should not overwrite an existing description_url for object input and cache disabled', function () { const bidCopy = Object.assign({}, bid); bidCopy.vastUrl = 'vastUrl.example'; @@ -245,7 +245,7 @@ describe('The DFP video support module', () => { expect(queryObject.description_url).to.equal('descriptionurl.example'); }); - it('should work with nobid responses', () => { + it('should work with nobid responses', function () { const url = buildDfpVideoUrl({ adUnit: adUnit, params: { 'iu': 'my/adUnit' } diff --git a/test/spec/modules/dgadsBidAdapter_spec.js b/test/spec/modules/dgadsBidAdapter_spec.js index 89affd94880..2454885217d 100644 --- a/test/spec/modules/dgadsBidAdapter_spec.js +++ b/test/spec/modules/dgadsBidAdapter_spec.js @@ -1,20 +1,21 @@ import {expect} from 'chai'; import * as utils from 'src/utils'; -import {spec} from 'modules/dgadsBidAdapter'; +import {spec, getCookieUid} from 'modules/dgadsBidAdapter'; import {newBidder} from 'src/adapters/bidderFactory'; import { BANNER, NATIVE } from 'src/mediaTypes'; -describe('dgadsBidAdapter', () => { +describe('dgadsBidAdapter', function () { const adapter = newBidder(spec); + const UID_NAME = 'dgads_uid'; const VALID_ENDPOINT = 'https://ads-tr.bigmining.com/ad/p/bid'; - describe('inherited functions', () => { - it('exists and is a function', () => { + describe('inherited functions', function () { + it('exists and is a function', function () { expect(adapter.callBids).to.exist.and.to.be.a('function'); }); }); - describe('isBidRequestValid', () => { + describe('isBidRequestValid', function () { let bid = { 'bidder': 'dgads', params: { @@ -22,11 +23,11 @@ describe('dgadsBidAdapter', () => { location_id: '1' } }; - it('should return true when required params found', () => { + it('should return true when required params found', function () { expect(spec.isBidRequestValid(bid)).to.equal(true); }); - it('should return false when required params(location_id) are not passed', () => { + it('should return false when required params(location_id) are not passed', function () { let bid = Object.assign({}, bid); delete bid.params; bid.params = { @@ -35,7 +36,7 @@ describe('dgadsBidAdapter', () => { expect(spec.isBidRequestValid(bid)).to.equal(false); }); - it('should return false when required params(site_id) are not passed', () => { + it('should return false when required params(site_id) are not passed', function () { let bid = Object.assign({}, bid); delete bid.params; bid.params = { @@ -45,7 +46,7 @@ describe('dgadsBidAdapter', () => { }); }); - describe('buildRequests', () => { + describe('buildRequests', function () { const bidRequests = [ { // banner bidder: 'dgads', @@ -97,31 +98,38 @@ describe('dgadsBidAdapter', () => { transactionId: 'c1f1eff6-23c6-4844-a321-575212939e37' } ]; - it('no bidRequests', () => { + it('no bidRequests', function () { const noBidRequests = []; expect(Object.keys(spec.buildRequests(noBidRequests)).length).to.equal(0); }); + it('getCookieUid return empty if cookie not found', function () { + expect(getCookieUid(UID_NAME)).to.equal(''); + }); const data = { location_id: '1', site_id: '1', transaction_id: 'c1f1eff6-23c6-4844-a321-575212939e37', - bid_id: '2db3101abaec66' + bid_id: '2db3101abaec66', + referer: utils.getTopWindowUrl(), + _uid: '' }; - it('sends bid request to VALID_ENDPOINT via POST', () => { + it('sends bid request to VALID_ENDPOINT via GET', function () { const request = spec.buildRequests(bidRequests)[0]; expect(request.url).to.equal(VALID_ENDPOINT); - expect(request.method).to.equal('POST'); + expect(request.method).to.equal('GET'); }); - it('should attache params to the request', () => { + it('should attache params to the request', function () { const request = spec.buildRequests(bidRequests)[0]; - expect(request.data['location_id']).to.equal(data['location_id']); - expect(request.data['site_id']).to.equal(data['site_id']); + expect(request.data['_loc']).to.equal(data['location_id']); + expect(request.data['_medium']).to.equal(data['site_id']); expect(request.data['transaction_id']).to.equal(data['transaction_id']); expect(request.data['bid_id']).to.equal(data['bid_id']); + expect(request.data['referer']).to.equal(data['referer']); + expect(request.data['_uid']).to.equal(data['_uid']); }); }); - describe('interpretResponse', () => { + describe('interpretResponse', function () { const bidRequests = { banner: { bidRequest: { @@ -252,11 +260,11 @@ describe('dgadsBidAdapter', () => { } }; - it('no bid responses', () => { + it('no bid responses', function () { const result = spec.interpretResponse({body: serverResponse.noAd}, bidRequests.banner); expect(result.length).to.equal(0); }); - it('handles banner responses', () => { + it('handles banner responses', function () { const result = spec.interpretResponse({body: serverResponse.banner}, bidRequests.banner)[0]; expect(result.requestId).to.equal(bidResponses.banner.requestId); expect(result.width).to.equal(bidResponses.banner.width); @@ -269,7 +277,7 @@ describe('dgadsBidAdapter', () => { expect(result.ad).to.equal(bidResponses.banner.ad); }); - it('handles native responses', () => { + it('handles native responses', function () { const result = spec.interpretResponse({body: serverResponse.native}, bidRequests.native)[0]; expect(result.requestId).to.equal(bidResponses.native.requestId); expect(result.creativeId).to.equal(bidResponses.native.creativeId); diff --git a/test/spec/modules/districtmDmxBidAdapter_spec.js b/test/spec/modules/districtmDmxBidAdapter_spec.js index cfdab445f71..64f76eb026d 100644 --- a/test/spec/modules/districtmDmxBidAdapter_spec.js +++ b/test/spec/modules/districtmDmxBidAdapter_spec.js @@ -1,6 +1,6 @@ import {expect} from 'chai'; import * as _ from 'lodash'; -import {spec, matchRequest, checkDeepArray, defaultSize} from '../../../modules/districtmDmxBidAdapter'; +import {spec, matchRequest, checkDeepArray, defaultSize} from '../../../modules/districtmDMXBidAdapter'; const bidRequest = [{ 'bidder': 'districtmDMX', @@ -420,58 +420,58 @@ const responsesNegative = { const emptyResponse = { body: {} }; const emptyResponseSeatBid = { body: { seatbid: [] } }; -describe('DistrictM Adaptor', () => { +describe('DistrictM Adaptor', function () { const districtm = spec; - describe('All needed functions are available', () => { - it(`isBidRequestValid is present and type function`, () => { + 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`, () => { + 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`, () => { + 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`, () => { + 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`, () => { - it(`code should have a value of districtmDMX`, () => { + 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`, () => { + it(`timeout should not be defined`, function () { expect(districtm.onTimeout).to.be.an('undefined'); }); }); - describe(`isBidRequestValid test response`, () => { + describe(`isBidRequestValid test response`, function () { let params = { dmxid: 10001, memberid: 10003, }; - it(`function should return true`, () => { + it(`function should return true`, function () { expect(districtm.isBidRequestValid({params})).to.be.equal(true); }); - it(`function should return false`, () => { + it(`function should return false`, function () { expect(districtm.isBidRequestValid({ params: { memberid: 12345 } })).to.be.equal(false); }); - it(`expect to have two property available dmxid and memberid`, () => { + it(`expect to have two property available dmxid and memberid`, function () { expect(params).to.have.property('dmxid'); expect(params).to.have.property('memberid'); }); }); - describe(`getUserSyncs test usage`, () => { - it(`return value should be an array`, () => { + 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'`, () => { + 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'); @@ -479,53 +479,53 @@ describe('DistrictM Adaptor', () => { }); }); - describe(`buildRequests test usage`, () => { + describe(`buildRequests test usage`, function () { const buildRequestResults = districtm.buildRequests(bidRequest, bidderRequest); - it(`the function should return an array`, () => { + it(`the function should return an array`, function () { expect(buildRequestResults).to.be.an('object'); }); - it(`the function should return array length of 1`, () => { + it(`the function should return array length of 1`, function () { expect(buildRequestResults.data).to.be.a('string'); }); }); - describe(`interpretResponse test usage`, () => { + 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`, () => { + it(`the function should return an array`, function () { expect(responseResults).to.be.an('array'); }); - it(`the function should return array length of 1`, () => { + it(`the function should return array length of 1`, function () { expect(responseResults.length).to.be.equal(1); }); - it(`the response return nothing`, () => { + it(`the response return nothing`, function () { expect(emptyResponseResults.length).to.be.equal(0); }); - it(`the response seatbid return nothing`, () => { + it(`the response seatbid return nothing`, function () { expect(emptyResponseResultsEmptySeat.length).to.be.equal(0); }); - it(`on invalid CPM`, () => { + it(`on invalid CPM`, function () { expect(emptyResponseResultsNegation.length).to.be.equal(0); }); }); - describe(`Helper function testing`, () => { + describe(`Helper function testing`, function () { const bid = matchRequest('29a28a1bbc8a8d', {bidderRequest}); const {width, height} = defaultSize(bid); - it(`test matchRequest`, () => { + it(`test matchRequest`, function () { expect(matchRequest('29a28a1bbc8a8d', {bidderRequest})).to.be.an('object'); }); - it(`test checkDeepArray`, () => { + 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`, () => { + it(`test defaultSize`, function () { expect(width).to.be.equal(300); expect(height).to.be.equal(250); }); diff --git a/test/spec/modules/dspxBidAdapter_spec.js b/test/spec/modules/dspxBidAdapter_spec.js new file mode 100644 index 00000000000..7eeac43680a --- /dev/null +++ b/test/spec/modules/dspxBidAdapter_spec.js @@ -0,0 +1,130 @@ +import { expect } from 'chai'; +import { spec } from 'modules/dspxBidAdapter'; +import { newBidder } from 'src/adapters/bidderFactory'; + +const ENDPOINT_URL = 'https://buyer.dspx.tv/request/'; + +describe('dspxAdapter', function () { + const adapter = newBidder(spec); + + describe('isBidRequestValid', function () { + let bid = { + 'bidder': 'dspx', + 'params': { + 'placement': '6682', + 'pfilter': { + 'floorprice': 1000000 + }, + 'bcat': 'IAB2,IAB4', + 'dvt': 'desktop' + }, + 'sizes': [ + [300, 250] + ], + 'bidId': '30b31c1838de1e', + 'bidderRequestId': '22edbae2733bf6', + 'auctionId': '1d1a030790a475' + }; + + it('should return true when required params found', function () { + expect(spec.isBidRequestValid(bid)).to.equal(true); + }); + + it('should return false when required params are not passed', function () { + let bid = Object.assign({}, bid); + delete bid.params; + bid.params = { + 'someIncorrectParam': 0 + }; + expect(spec.isBidRequestValid(bid)).to.equal(false); + }); + }); + + describe('buildRequests', function () { + let bidRequests = [{ + 'bidder': 'dspx', + 'params': { + 'placement': '6682', + 'pfilter': { + 'floorprice': 1000000, + 'private_auction': 0, + 'geo': { + 'country': 'DE' + } + }, + 'bcat': 'IAB2,IAB4', + 'dvt': 'desktop' + }, + 'sizes': [ + [300, 250] + ], + 'bidId': '30b31c1838de1e', + 'bidderRequestId': '22edbae2733bf6', + 'auctionId': '1d1a030790a475' + }]; + + let bidderRequest = { + refererInfo: { + referer: 'some_referrer.net' + } + } + + const request = spec.buildRequests(bidRequests, bidderRequest); + it('sends bid request to our endpoint via GET', function () { + expect(request[0].method).to.equal('GET'); + let data = request[0].data.replace(/rnd=\d+\&/g, '').replace(/ref=.*\&bid/g, 'bid'); + expect(data).to.equal('_f=html&alternative=prebid_js&inventory_item_id=6682&srw=300&srh=250&idt=100&bid_id=30b31c1838de1e&pfilter%5Bfloorprice%5D=1000000&pfilter%5Bprivate_auction%5D=0&pfilter%5Bgeo%5D%5Bcountry%5D=DE&bcat=IAB2%2CIAB4&dvt=desktop'); + }); + }); + + describe('interpretResponse', function () { + let serverResponse = { + 'body': { + 'cpm': 5000000, + 'crid': 100500, + 'width': '300', + 'height': '250', + 'tag': '', + 'requestId': '220ed41385952a', + 'currency': 'EUR', + 'ttl': 60, + 'netRevenue': true, + 'zone': '6682' + } + }; + + let expectedResponse = [{ + requestId: '23beaa6af6cdde', + cpm: 0.5, + width: 0, + height: 0, + creativeId: 100500, + dealId: '', + currency: 'EUR', + netRevenue: true, + ttl: 300, + referrer: '', + ad: '' + }]; + + it('should get the correct bid response by display ad', function () { + let bidRequest = [{ + 'method': 'GET', + 'url': ENDPOINT_URL, + 'data': { + 'bid_id': '30b31c1838de1e' + } + }]; + let result = spec.interpretResponse(serverResponse, bidRequest[0]); + expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])); + }); + + it('handles empty bid response', function () { + let response = { + body: {} + }; + let result = spec.interpretResponse(response); + expect(result.length).to.equal(0); + }); + }); +}); diff --git a/test/spec/modules/ebdrBidAdapter_spec.js b/test/spec/modules/ebdrBidAdapter_spec.js index 3ec5a4f0a81..d742e28f2e6 100644 --- a/test/spec/modules/ebdrBidAdapter_spec.js +++ b/test/spec/modules/ebdrBidAdapter_spec.js @@ -3,10 +3,10 @@ import { spec } from 'modules/ebdrBidAdapter'; import { VIDEO, BANNER } from 'src/mediaTypes'; import * as utils from 'src/utils'; -describe('ebdrBidAdapter', () => { +describe('ebdrBidAdapter', function () { let bidRequests; - beforeEach(() => { + beforeEach(function () { bidRequests = [ { code: 'div-gpt-ad-1460505748561-0', @@ -51,13 +51,13 @@ describe('ebdrBidAdapter', () => { ]; }); - describe('spec.isBidRequestValid', () => { - it('should return true when the required params are passed', () => { + describe('spec.isBidRequestValid', function () { + it('should return true when the required params are passed', function () { const bidRequest = bidRequests[0]; expect(spec.isBidRequestValid(bidRequest)).to.equal(true); }); - it('should return true when the only required param is missing', () => { + it('should return true when the only required param is missing', function () { const bidRequest = bidRequests[0]; bidRequest.params = { zoneid: '99998', @@ -66,7 +66,7 @@ describe('ebdrBidAdapter', () => { expect(spec.isBidRequestValid(bidRequest)).to.equal(true); }); - it('should return true when the "bidfloor" param is missing', () => { + it('should return true when the "bidfloor" param is missing', function () { const bidRequest = bidRequests[0]; bidRequest.params = { zoneid: '99998', @@ -74,34 +74,34 @@ describe('ebdrBidAdapter', () => { expect(spec.isBidRequestValid(bidRequest)).to.equal(true); }); - it('should return false when no bid params are passed', () => { + it('should return false when no bid params are passed', function () { const bidRequest = bidRequests[0]; bidRequest.params = {}; expect(spec.isBidRequestValid(bidRequest)).to.equal(false); }); - it('should return false when a bid request is not passed', () => { + it('should return false when a bid request is not passed', function () { expect(spec.isBidRequestValid()).to.equal(false); expect(spec.isBidRequestValid({})).to.equal(false); }); }); - describe('spec.buildRequests', () => { - describe('for banner bids', () => { - it('must handle an empty bid size', () => { + describe('spec.buildRequests', function () { + describe('for banner bids', function () { + it('must handle an empty bid size', function () { bidRequests[0].mediaTypes = { banner: {} }; const requests = spec.buildRequests(bidRequests); const bidRequest = {}; bidRequest['2c5e8a1a84522d'] = { mediaTypes: BANNER, w: null, h: null }; expect(requests.bids['2c5e8a1a84522d']).to.deep.equals(bidRequest['2c5e8a1a84522d']); }); - it('should create a single GET', () => { + it('should create a single GET', function () { bidRequests[0].mediaTypes = { banner: {} }; bidRequests[1].mediaTypes = { banner: {} }; const requests = spec.buildRequests(bidRequests); expect(requests.method).to.equal('GET'); }); - it('must parse bid size from a nested array', () => { + it('must parse bid size from a nested array', function () { const width = 640; const height = 480; const bidRequest = bidRequests[0]; @@ -112,8 +112,8 @@ describe('ebdrBidAdapter', () => { expect(requests.bids['2c5e8a1a84522d']).to.deep.equal(data['2c5e8a1a84522d']); }); }); - describe('for video bids', () => { - it('must handle an empty bid size', () => { + describe('for video bids', function () { + it('must handle an empty bid size', function () { bidRequests[1].mediaTypes = { video: {} }; const requests = spec.buildRequests(bidRequests); const bidRequest = {}; @@ -121,7 +121,7 @@ describe('ebdrBidAdapter', () => { expect(requests.bids['23a01e95856577']).to.deep.equals(bidRequest['23a01e95856577']); }); - it('should create a GET request for each bid', () => { + it('should create a GET request for each bid', function () { const bidRequest = bidRequests[1]; const requests = spec.buildRequests([ bidRequest ]); expect(requests.method).to.equal('GET'); @@ -129,16 +129,16 @@ describe('ebdrBidAdapter', () => { }); }); - describe('spec.interpretResponse', () => { - describe('for video bids', () => { - it('should return no bids if the response is not valid', () => { + describe('spec.interpretResponse', function () { + describe('for video bids', function () { + it('should return no bids if the response is not valid', function () { const bidRequest = bidRequests[0]; bidRequest.mediaTypes = { video: {} }; const bidResponse = spec.interpretResponse({ body: null }, { bidRequest }); expect(bidResponse.length).to.equal(0); }); - it('should return a valid video bid response', () => { + it('should return a valid video bid response', function () { const ebdrReq = {bids: {}}; bidRequests.forEach(bid => { let _mediaTypes = (bid.mediaTypes && bid.mediaTypes.video ? VIDEO : BANNER); @@ -165,22 +165,22 @@ describe('ebdrBidAdapter', () => { }); }); - describe('for banner bids', () => { - it('should return no bids if the response is not valid', () => { + describe('for banner bids', function () { + it('should return no bids if the response is not valid', function () { const bidRequest = bidRequests[0]; bidRequest.mediaTypes = { banner: {} }; const bidResponse = spec.interpretResponse({ body: null }, { bidRequest }); expect(bidResponse.length).to.equal(0); }); - it('should return no bids if the response is empty', () => { + it('should return no bids if the response is empty', function () { const bidRequest = bidRequests[0]; bidRequest.mediaTypes = { banner: {} }; const bidResponse = spec.interpretResponse({ body: [] }, { bidRequest }); expect(bidResponse.length).to.equal(0); }); - it('should return valid banner bid responses', () => { + it('should return valid banner bid responses', function () { const ebdrReq = {bids: {}}; bidRequests.forEach(bid => { let _mediaTypes = (bid.mediaTypes && bid.mediaTypes.video ? VIDEO : BANNER); @@ -206,27 +206,27 @@ describe('ebdrBidAdapter', () => { }); }); }); - describe('spec.getUserSyncs', () => { + describe('spec.getUserSyncs', function () { let syncOptions - beforeEach(() => { + beforeEach(function () { syncOptions = { enabledBidders: ['ebdr'], // only these bidders are allowed to sync pixelEnabled: true } }); - it('sucess with usersync url', () => { + it('sucess with usersync url', function () { const serverResponse = {id: '1d0c4017f02458', seatbid: [{bid: [{id: '2c5e8a1a84522d', impid: '2c5e8a1a84522d', price: 0.81, adid: 'abcde-12345', nurl: '', adm: '
', adomain: ['advertiserdomain.com'], iurl: '//match.bnmla.com/usersync?sspid=59&redir=', cid: 'campaign1', crid: 'abcde-12345', w: 300, h: 250}], seat: '19513bcfca8006'}], bidid: '19513bcfca8006', cur: 'USD', w: 300, h: 250}; const result = []; result.push({type: 'image', url: '//match.bnmla.com/usersync?sspid=59&redir='}); expect(spec.getUserSyncs(syncOptions, { body: serverResponse })).to.deep.equal(result); }); - it('sucess without usersync url', () => { + it('sucess without usersync url', function () { const serverResponse = {id: '1d0c4017f02458', seatbid: [{bid: [{id: '2c5e8a1a84522d', impid: '2c5e8a1a84522d', price: 0.81, adid: 'abcde-12345', nurl: '', adm: '
', adomain: ['advertiserdomain.com'], iurl: '', cid: 'campaign1', crid: 'abcde-12345', w: 300, h: 250}], seat: '19513bcfca8006'}], bidid: '19513bcfca8006', cur: 'USD', w: 300, h: 250}; const result = []; expect(spec.getUserSyncs(syncOptions, { body: serverResponse })).to.deep.equal(result); }); - it('empty response', () => { + it('empty response', function () { const serverResponse = {}; const result = []; expect(spec.getUserSyncs(syncOptions, { body: serverResponse })).to.deep.equal(result); diff --git a/test/spec/modules/emx_digitalBidAdapter_spec.js b/test/spec/modules/emx_digitalBidAdapter_spec.js new file mode 100644 index 00000000000..85256c20bd9 --- /dev/null +++ b/test/spec/modules/emx_digitalBidAdapter_spec.js @@ -0,0 +1,399 @@ +import { expect } from 'chai'; +import { spec } from 'modules/emx_digitalBidAdapter'; +import * as utils from 'src/utils'; +import { newBidder } from 'src/adapters/bidderFactory'; + +describe('emx_digital Adapter', function () { + const adapter = newBidder(spec); + + describe('required function', function () { + it('exists and is a function', function () { + expect(adapter.callBids).to.exist.and.to.be.a('function'); + }); + }); + + describe('isBidRequestValid', function () { + let bid = { + 'bidder': 'emx_digital', + 'params': { + 'tagid': '25251' + }, + 'mediaTypes': { + 'banner': { + 'sizes': [ + [300, 250], + [300, 600] + ] + } + }, + 'adUnitCode': 'adunit-code', + 'sizes': [ + [300, 250], + [300, 600] + ], + 'bidId': '30b31c2501de1e', + 'bidderRequestId': '22edbae3120bf6', + 'auctionId': '1d1a01234a475' + }; + + it('should return true when required params found', function () { + expect(spec.isBidRequestValid(bid)).to.equal(true); + }); + + it('should contain tagid param', function () { + expect(spec.isBidRequestValid({ + bidder: 'emx_digital', + params: {}, + mediaTypes: { + banner: { + sizes: [ + [300, 250], + [300, 600] + ] + } + } + })).to.equal(false); + expect(spec.isBidRequestValid({ + bidder: 'emx_digital', + params: { + tagid: '' + }, + mediaTypes: { + banner: { + sizes: [ + [300, 250], + [300, 600] + ] + } + } + })).to.equal(false); + expect(spec.isBidRequestValid({ + bidder: 'emx_digital', + params: { + tagid: '123' + }, + mediaTypes: { + banner: { + sizes: [ + ] + } + } + })).to.equal(false); + expect(spec.isBidRequestValid({ + bidder: 'emxdigital', + params: { + tagid: '123' + }, + mediaTypes: { + banner: { + sizes: [ + [300, 250], + [300, 600] + ] + } + } + })).to.equal(false); + expect(spec.isBidRequestValid({ + bidder: 'emx_digital', + params: { + tagid: '123' + }, + mediaTypes: { + banner: { + sizes: [ + [300, 250], + [300, 600] + ] + } + } + })).to.equal(true); + }); + }); + + describe('buildRequests', function () { + const bidRequests = [{ + 'bidder': 'emx_digital', + 'params': { + 'tagid': '25251' + }, + 'adUnitCode': 'adunit-code', + 'mediaTypes': { + 'banner': { + 'sizes': [ + [300, 250], + [300, 600] + ] + } + }, + 'sizes': [ + [300, 250], + [300, 600] + ], + 'bidId': '30b31c2501de1e', + 'bidderRequestId': '22edbae3120bf6', + 'auctionId': 'e19f1eff-8b27-42a6-888d-9674e5a6130c', + 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec' + }, { + 'bidder': 'emx_digital', + 'params': { + 'tagid': '25251' + }, + 'adUnitCode': 'adunit-code', + 'mediaTypes': { + 'banner': { + 'sizes': [ + [300, 250], + [300, 600] + ] + } + }, + 'sizes': [ + [300, 250], + [300, 600] + ], + 'bidId': '30b31c2501de1e', + 'bidderRequestId': '22edbae3120bf6', + 'auctionId': 'e19f1eff-8b27-42a6-888d-9674e5a6130c', + 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec' + }]; + let bidderRequest = { + 'bidderCode': 'emx_digital', + 'auctionId': 'e19f1eff-8b27-42a6-888d-9674e5a6130c', + 'bidderRequestId': '22edbae3120bf6', + 'timeout': 1500, + }; + bidderRequest.bids = bidRequests + + let request = spec.buildRequests(bidRequests, bidderRequest); + + it('sends bid request to ENDPOINT via POST', function () { + expect(request.method).to.equal('POST'); + }); + + it('contains the correct options', function () { + expect(request.options.withCredentials).to.equal(true); + }); + + it('sends contains a properly formatted endpoint url', function () { + const url = request.url.split('?'); + const queryParams = url[1].split('&'); + expect(queryParams[0]).to.match(new RegExp('^t=\d*', 'g')); + expect(queryParams[1]).to.match(new RegExp('^ts=\d*', 'g')); + }); + + it('builds request properly', function () { + const data = JSON.parse(request.data); + + expect(Array.isArray(data.imp)).to.equal(true); + expect(data.id).to.equal(bidderRequest.auctionId); + expect(data.imp.length).to.equal(2); + expect(data.imp[0].id).to.equal('30b31c2501de1e'); + expect(data.imp[0].tid).to.equal('d7b773de-ceaa-484d-89ca-d9f51b8d61ec'); + expect(data.imp[0].tagid).to.equal('25251'); + expect(data.imp[0].secure).to.equal(0); + }); + + it('builds with bid floor', function() { + const bidRequestWithBidFloor = utils.deepClone(bidRequests); + bidRequestWithBidFloor[0].params.bidfloor = 1; + const requestWithFloor = spec.buildRequests(bidRequestWithBidFloor, bidderRequest); + const data = JSON.parse(requestWithFloor.data); + expect(data.imp[0].bidfloor).to.equal(bidRequestWithBidFloor[0].params.bidfloor); + }) + + it('properly sends site information and protocol', function () { + let mock = sinon.stub(utils, 'getTopWindowLocation').callsFake(() => { + return { + protocol: 'https:', + host: 'example.com', + href: 'https://example.com/index.html' + }; + }); + + let request; + + request = spec.buildRequests(bidRequests, bidderRequest); + request = JSON.parse(request.data); + expect(request.site.domain).to.equal('example.com'); + expect(request.site.page).to.equal('https://example.com/index.html'); + expect(request.imp[0].secure).to.equal(1); + + mock.restore(); + }) + + it('builds correctly formatted request banner object', function () { + let request; + + let bidRequestWithBanner = utils.deepClone(bidRequests); + + request = spec.buildRequests(bidRequestWithBanner, bidderRequest); + const data = JSON.parse(request.data); + expect(data.imp[0].banner.w).to.equal(bidRequestWithBanner[0].mediaTypes.banner.sizes[0][0]); + expect(data.imp[0].banner.h).to.equal(bidRequestWithBanner[0].mediaTypes.banner.sizes[0][1]); + expect(data.imp[0].banner.format[0].w).to.equal(bidRequestWithBanner[0].mediaTypes.banner.sizes[0][0]); + expect(data.imp[0].banner.format[0].h).to.equal(bidRequestWithBanner[0].mediaTypes.banner.sizes[0][1]); + expect(data.imp[0].banner.format[1].w).to.equal(bidRequestWithBanner[0].mediaTypes.banner.sizes[1][0]); + expect(data.imp[0].banner.format[1].h).to.equal(bidRequestWithBanner[0].mediaTypes.banner.sizes[1][1]); + }) + + it('shouldn\'t contain a user obj without GDPR information', function () { + let request = spec.buildRequests(bidRequests, bidderRequest) + request = JSON.parse(request.data) + expect(request).to.not.have.property('user'); + }); + + it('should have the right gdpr info when enabled', function () { + let consentString = 'OIJSZsOAFsABAB8EMXZZZZZ+A=='; + let bidderRequest = { + 'bidderCode': 'emx_digital', + 'auctionId': 'e19f1eff-8b27-42a6-888d-9674e5a6130c', + 'bidderRequestId': '22edbae3120bf6', + 'timeout': 1500, + 'gdprConsent': { + 'consentString': consentString, + 'gdprApplies': true + } + }; + bidderRequest.bids = bidRequests + let request = spec.buildRequests(bidRequests, bidderRequest); + + request = JSON.parse(request.data) + expect(request.regs.ext).to.have.property('gdpr', 1); + expect(request.user.ext).to.have.property('consent', 'OIJSZsOAFsABAB8EMXZZZZZ+A=='); + }); + + it('should\'t contain consent string if gdpr isn\'t applied', function () { + let bidderRequest = { + 'bidderCode': 'emx_digital', + 'auctionId': 'e19f1eff-8b27-42a6-888d-9674e5a6130c', + 'bidderRequestId': '22edbae3120bf6', + 'timeout': 1500, + 'gdprConsent': { + 'gdprApplies': false + } + }; + bidderRequest.bids = bidRequests + let request = spec.buildRequests(bidRequests, bidderRequest); + + request = JSON.parse(request.data) + expect(request.regs.ext).to.have.property('gdpr', 0); + expect(request).to.not.have.property('user'); + }); + }); + + describe('interpretResponse', function () { + const serverResponse = { + 'id': '12819a18-56e1-4256-b836-b69a10202668', + 'seatbid': [{ + 'bid': [{ + 'adid': '123456abcde', + 'adm': '', + 'crid': '3434abab34', + 'h': 250, + 'id': '987654321cba', + 'price': 0.5, + 'ttl': 300, + 'w': 300 + }], + 'seat': '1356' + }, { + 'bid': [{ + 'adid': '123456abcdf', + 'adm': '', + 'crid': '3434abab35', + 'h': 600, + 'id': '987654321cba', + 'price': 0.5, + 'ttl': 300, + 'w': 300 + }] + }] + }; + + const expectedResponse = [{ + 'requestId': '12819a18-56e1-4256-b836-b69a10202668', + 'cpm': 0.5, + 'width': 300, + 'height': 250, + 'creativeId': '3434abab34', + 'dealId': null, + 'currency': 'USD', + 'netRevneue': true, + 'mediaType': 'banner', + 'ad': '', + 'ttl': 300 + }, { + 'requestId': '12819a18-56e1-4256-b836-b69a10202668', + 'cpm': 0.7, + 'width': 300, + 'height': 600, + 'creativeId': '3434abab35', + 'dealId': null, + 'currency': 'USD', + 'netRevneue': true, + 'mediaType': 'banner', + 'ad': '', + 'ttl': 300 + }]; + + it('should properly format bid response', function () { + let result = spec.interpretResponse({ + body: serverResponse + }); + expect(Object.keys(result[0]).length).to.equal(Object.keys(expectedResponse[0]).length); + expect(Object.keys(result[0]).requestId).to.equal(Object.keys(expectedResponse[0]).requestId); + expect(Object.keys(result[0]).bidderCode).to.equal(Object.keys(expectedResponse[0]).bidderCode); + expect(Object.keys(result[0]).cpm).to.equal(Object.keys(expectedResponse[0]).cpm); + expect(Object.keys(result[0]).creativeId).to.equal(Object.keys(expectedResponse[0]).creativeId); + expect(Object.keys(result[0]).width).to.equal(Object.keys(expectedResponse[0]).width); + expect(Object.keys(result[0]).height).to.equal(Object.keys(expectedResponse[0]).height); + expect(Object.keys(result[0]).ttl).to.equal(Object.keys(expectedResponse[0]).ttl); + expect(Object.keys(result[0]).adId).to.equal(Object.keys(expectedResponse[0]).adId); + expect(Object.keys(result[0]).currency).to.equal(Object.keys(expectedResponse[0]).currency); + expect(Object.keys(result[0]).netRevenue).to.equal(Object.keys(expectedResponse[0]).netRevenue); + expect(Object.keys(result[0]).ad).to.equal(Object.keys(expectedResponse[0]).ad); + }); + + it('should return multiple bids', function () { + let result = spec.interpretResponse({ + body: serverResponse + }); + expect(Array.isArray(result.seatbid)) + + const ad0 = result[0]; + const ad1 = result[1]; + expect(ad0.ad).to.equal(serverResponse.seatbid[0].bid[0].adm); + expect(ad0.cpm).to.equal(serverResponse.seatbid[0].bid[0].price); + expect(ad0.creativeId).to.equal(serverResponse.seatbid[0].bid[0].crid); + expect(ad0.currency).to.equal('USD'); + expect(ad0.height).to.equal(serverResponse.seatbid[0].bid[0].h); + expect(ad0.mediaType).to.equal('banner'); + expect(ad0.netRevenue).to.equal(true); + expect(ad0.requestId).to.equal(serverResponse.seatbid[0].bid[0].id); + expect(ad0.ttl).to.equal(300); + expect(ad0.width).to.equal(serverResponse.seatbid[0].bid[0].w); + + expect(ad1.ad).to.equal(serverResponse.seatbid[1].bid[0].adm); + expect(ad1.cpm).to.equal(serverResponse.seatbid[1].bid[0].price); + expect(ad1.creativeId).to.equal(serverResponse.seatbid[1].bid[0].crid); + expect(ad1.currency).to.equal('USD'); + expect(ad1.height).to.equal(serverResponse.seatbid[1].bid[0].h); + expect(ad1.mediaType).to.equal('banner'); + expect(ad1.netRevenue).to.equal(true); + expect(ad1.requestId).to.equal(serverResponse.seatbid[1].bid[0].id); + expect(ad1.ttl).to.equal(300); + expect(ad1.width).to.equal(serverResponse.seatbid[1].bid[0].w); + }); + + it('handles nobid responses', function () { + let serverResponse = { + 'bids': [] + }; + + let result = spec.interpretResponse({ + body: serverResponse + }); + expect(result.length).to.equal(0); + }); + }); +}); diff --git a/test/spec/modules/eplanningAnalyticsAdapter_spec.js b/test/spec/modules/eplanningAnalyticsAdapter_spec.js index cd538815954..8609024c7d9 100644 --- a/test/spec/modules/eplanningAnalyticsAdapter_spec.js +++ b/test/spec/modules/eplanningAnalyticsAdapter_spec.js @@ -2,29 +2,29 @@ import eplAnalyticsAdapter from 'modules/eplanningAnalyticsAdapter'; import includes from 'core-js/library/fn/array/includes'; import { expect } from 'chai'; import {parse as parseURL} from 'src/url'; -let adaptermanager = require('src/adaptermanager'); +let adapterManager = require('src/adapterManager').default; let events = require('src/events'); let constants = require('src/constants.json'); -describe('eplanning analytics adapter', () => { +describe('eplanning analytics adapter', function () { let xhr; let requests; - beforeEach(() => { + beforeEach(function () { xhr = sinon.useFakeXMLHttpRequest(); requests = []; xhr.onCreate = request => { requests.push(request) }; sinon.stub(events, 'getEvents').returns([]); }); - afterEach(() => { + afterEach(function () { xhr.restore(); events.getEvents.restore(); eplAnalyticsAdapter.disableAnalytics(); }); - describe('track', () => { - it('builds and sends auction data', () => { + describe('track', function () { + it('builds and sends auction data', function () { sinon.spy(eplAnalyticsAdapter, 'track'); let auctionTimestamp = 1496510254313; @@ -75,12 +75,12 @@ describe('eplanning analytics adapter', () => { } ]; - adaptermanager.registerAnalyticsAdapter({ + adapterManager.registerAnalyticsAdapter({ code: 'eplanning', adapter: eplAnalyticsAdapter }); - adaptermanager.enableAnalytics({ + adapterManager.enableAnalytics({ provider: 'eplanning', options: initOptions }); diff --git a/test/spec/modules/eplanningBidAdapter_spec.js b/test/spec/modules/eplanningBidAdapter_spec.js index a56bff42285..93290229ce3 100644 --- a/test/spec/modules/eplanningBidAdapter_spec.js +++ b/test/spec/modules/eplanningBidAdapter_spec.js @@ -3,13 +3,13 @@ import { spec } from 'modules/eplanningBidAdapter'; import { newBidder } from 'src/adapters/bidderFactory'; import * as utils from 'src/utils'; -describe('E-Planning Adapter', () => { +describe('E-Planning Adapter', function () { const adapter = newBidder('spec'); const CI = '12345'; - const ADUNIT_CODE = 'adunit-code'; + const ADUNIT_CODE = 'adunit-co:de'; const ADUNIT_CODE2 = 'adunit-code-dos'; const CLEAN_ADUNIT_CODE2 = 'adunitcodedos'; - const CLEAN_ADUNIT_CODE = 'adunitcode'; + const CLEAN_ADUNIT_CODE = 'adunitco_de'; const BID_ID = '123456789'; const BID_ID2 = '987654321'; const CPM = 1.3; @@ -167,55 +167,55 @@ describe('E-Planning Adapter', () => { } }; - describe('inherited functions', () => { - it('exists and is a function', () => { + describe('inherited functions', function () { + it('exists and is a function', function () { expect(adapter.callBids).to.exist.and.to.be.a('function'); }); }); - describe('isBidRequestValid', () => { - it('should return true when bid has ci parameter', () => { + describe('isBidRequestValid', function () { + it('should return true when bid has ci parameter', function () { expect(spec.isBidRequestValid(validBid)).to.equal(true); }); - it('should return false when bid does not have ci parameter and is not a test bid', () => { + it('should return false when bid does not have ci parameter and is not a test bid', function () { expect(spec.isBidRequestValid(invalidBid)).to.equal(false); }); - it('should return true when bid does not have ci parameter but is a test bid', () => { + it('should return true when bid does not have ci parameter but is a test bid', function () { expect(spec.isBidRequestValid(testBid)).to.equal(true); }); }); - describe('buildRequests', () => { + describe('buildRequests', function () { let bidRequests = [validBid]; - it('should create the url correctly', () => { + it('should create the url correctly', function () { const url = spec.buildRequests(bidRequests).url; expect(url).to.equal('//ads.us.e-planning.net/hb/1/' + CI + '/1/localhost/ROS'); }); - it('should return GET method', () => { + it('should return GET method', function () { const method = spec.buildRequests(bidRequests).method; expect(method).to.equal('GET'); }); - it('should return r parameter with value pbjs', () => { + it('should return r parameter with value pbjs', function () { const r = spec.buildRequests(bidRequests).data.r; expect(r).to.equal('pbjs'); }); - it('should return pbv parameter with value prebid version', () => { + it('should return pbv parameter with value prebid version', function () { const pbv = spec.buildRequests(bidRequests).data.pbv; expect(pbv).to.equal('$prebid.version$'); }); - it('should return e parameter with value according to the adunit sizes', () => { + it('should return e parameter with value according to the adunit sizes', function () { const e = spec.buildRequests(bidRequests).data.e; expect(e).to.equal(CLEAN_ADUNIT_CODE + ':300x250,300x600'); }); - it('should return correct e parameter with more than one adunit', () => { + it('should return correct e parameter with more than one adunit', function () { const NEW_CODE = ADUNIT_CODE + '2'; const CLEAN_NEW_CODE = CLEAN_ADUNIT_CODE + '2'; const anotherBid = { @@ -232,7 +232,7 @@ describe('E-Planning Adapter', () => { expect(e).to.equal(CLEAN_ADUNIT_CODE + ':300x250,300x600+' + CLEAN_NEW_CODE + ':100x100'); }); - it('should return correct e parameter when the adunit has no size', () => { + it('should return correct e parameter when the adunit has no size', function () { const noSizeBid = { 'bidder': 'eplanning', 'params': { @@ -245,12 +245,12 @@ describe('E-Planning Adapter', () => { expect(e).to.equal(CLEAN_ADUNIT_CODE + ':1x1'); }); - it('should return ur parameter with current window url', () => { + it('should return ur parameter with current window url', function () { const ur = spec.buildRequests(bidRequests).data.ur; expect(ur).to.equal(utils.getTopWindowUrl()); }); - it('should return fr parameter when there is a referrer', () => { + it('should return fr parameter when there is a referrer', function () { const referrer = 'thisisafakereferrer'; const stubGetReferrer = sinon.stub(utils, 'getTopWindowReferrer'); stubGetReferrer.returns(referrer); @@ -259,7 +259,7 @@ describe('E-Planning Adapter', () => { stubGetReferrer.restore() }); - it('should return crs parameter with document charset', () => { + it('should return crs parameter with document charset', function () { let expected; try { expected = window.top.document.characterSet; @@ -272,30 +272,30 @@ describe('E-Planning Adapter', () => { expect(chset).to.equal(expected); }); - it('should return the testing url when the request has the t parameter', () => { + it('should return the testing url when the request has the t parameter', function () { const url = spec.buildRequests([testBid]).url; const expectedUrl = '//' + TEST_ISV + '/layers/t_pbjs_2.json'; expect(url).to.equal(expectedUrl); }); - it('should return the parameter ncb with value 1', () => { + it('should return the parameter ncb with value 1', function () { const ncb = spec.buildRequests(bidRequests).data.ncb; expect(ncb).to.equal('1'); }); }); - describe('interpretResponse', () => { - it('should return an empty array when there is no ads in the response', () => { + describe('interpretResponse', function () { + it('should return an empty array when there is no ads in the response', function () { const bidResponses = spec.interpretResponse(responseWithNoAd); expect(bidResponses).to.be.empty; }); - it('should return an empty array when there is no spaces in the response', () => { + it('should return an empty array when there is no spaces in the response', function () { const bidResponses = spec.interpretResponse(responseWithNoSpace); expect(bidResponses).to.be.empty; }); - it('should correctly map the parameters in the response', () => { + it('should correctly map the parameters in the response', function () { const bidResponse = spec.interpretResponse(response, { adUnitToBidId: { [CLEAN_ADUNIT_CODE]: BID_ID } })[0]; const expectedResponse = { requestId: BID_ID, @@ -312,7 +312,7 @@ describe('E-Planning Adapter', () => { }); }); - describe('getUserSyncs', () => { + describe('getUserSyncs', function () { const sOptionsAllEnabled = { pixelEnabled: true, iframeEnabled: true @@ -330,30 +330,30 @@ describe('E-Planning Adapter', () => { iframeEnabled: true }; - it('should return an empty array if the response has no syncs', () => { + it('should return an empty array if the response has no syncs', function () { const noSyncsResponse = { cs: [] }; const syncs = spec.getUserSyncs(sOptionsAllEnabled, [noSyncsResponse]); expect(syncs).to.be.empty; }); - it('should return an empty array if there is no sync options enabled', () => { + it('should return an empty array if there is no sync options enabled', function () { const syncs = spec.getUserSyncs(sOptionsAllDisabled, [response]); expect(syncs).to.be.empty; }); - it('should only return pixels if iframe is not enabled', () => { + it('should only return pixels if iframe is not enabled', function () { const syncs = spec.getUserSyncs(sOptionsOnlyPixel, [response]); syncs.forEach(sync => expect(sync.type).to.equal('image')); }); - it('should only return iframes if pixel is not enabled', () => { + it('should only return iframes if pixel is not enabled', function () { const syncs = spec.getUserSyncs(sOptionsOnlyIframe, [response]); syncs.forEach(sync => expect(sync.type).to.equal('iframe')); }); }); - describe('adUnits mapping to bidId', () => { - it('should correctly map the bidId to the adunit', () => { + describe('adUnits mapping to bidId', function () { + it('should correctly map the bidId to the adunit', function () { const requests = spec.buildRequests([validBid, validBid2]); const responses = spec.interpretResponse(responseWithTwoAdunits, requests); expect(responses[0].requestId).to.equal(BID_ID); diff --git a/test/spec/modules/etargetBidAdapter_spec.js b/test/spec/modules/etargetBidAdapter_spec.js index 2af61505afa..e4cccbf5cf3 100644 --- a/test/spec/modules/etargetBidAdapter_spec.js +++ b/test/spec/modules/etargetBidAdapter_spec.js @@ -3,10 +3,10 @@ import * as url from 'src/url'; import {spec} from 'modules/etargetBidAdapter'; import { BANNER, VIDEO } from 'src/mediaTypes'; -describe('etarget adapter', () => { +describe('etarget adapter', function () { let serverResponse, bidRequest, bidResponses; let bids = []; - describe('isBidRequestValid', () => { + describe('isBidRequestValid', function () { let bid = { 'bidder': 'etarget', 'params': { @@ -15,29 +15,29 @@ describe('etarget adapter', () => { } }; - it('should return true when required params found', () => { + it('should return true when required params found', function () { assert(spec.isBidRequestValid(bid)); }); }); - describe('buildRequests', () => { - it('should pass multiple bids via single request', () => { + describe('buildRequests', function () { + it('should pass multiple bids via single request', function () { let request = spec.buildRequests(bids); let parsedUrl = parseUrl(request.url); assert.lengthOf(parsedUrl.items, 7); }); - it('should handle global request parameters', () => { + it('should handle global request parameters', function () { let parsedUrl = parseUrl(spec.buildRequests([bids[0]]).url); assert.equal(parsedUrl.path, '//sk.search.etargetnet.com/hb'); }); - it('should set correct request method', () => { + it('should set correct request method', function () { let request = spec.buildRequests([bids[0]]); assert.equal(request.method, 'POST'); }); - it('should correctly form bid items', () => { + it('should correctly form bid items', function () { let bidList = bids; let request = spec.buildRequests(bidList); let parsedUrl = parseUrl(request.url); @@ -88,14 +88,14 @@ describe('etarget adapter', () => { ]); }); - it('should not change original validBidRequests object', () => { + it('should not change original validBidRequests object', function () { var resultBids = JSON.parse(JSON.stringify(bids[0])); let request = spec.buildRequests([bids[0]]); assert.deepEqual(resultBids, bids[0]); }); - describe('gdpr', () => { - it('should send GDPR Consent data to etarget if gdprApplies', () => { + describe('gdpr', function () { + it('should send GDPR Consent data to etarget if gdprApplies', function () { let resultBids = JSON.parse(JSON.stringify(bids[0])); let request = spec.buildRequests([bids[0]], {gdprConsent: {gdprApplies: true, consentString: 'concentDataString'}}); let parsedUrl = parseUrl(request.url).query; @@ -104,7 +104,7 @@ describe('etarget adapter', () => { assert.equal(parsedUrl.gdpr_consent, 'concentDataString'); }); - it('should not send GDPR Consent data to etarget if gdprApplies is false or undefined', () => { + it('should not send GDPR Consent data to etarget if gdprApplies is false or undefined', function () { let resultBids = JSON.parse(JSON.stringify(bids[0])); let request = spec.buildRequests([bids[0]], {gdprConsent: {gdprApplies: false, consentString: 'concentDataString'}}); let parsedUrl = parseUrl(request.url).query; @@ -117,7 +117,7 @@ describe('etarget adapter', () => { assert.ok(!parsedUrl.gdpr_consent); }); - it('should return GDPR Consent data with request data', () => { + it('should return GDPR Consent data with request data', function () { let request = spec.buildRequests([bids[0]], {gdprConsent: {gdprApplies: true, consentString: 'concentDataString'}}); assert.deepEqual(request.gdpr, { @@ -131,12 +131,12 @@ describe('etarget adapter', () => { }); }); - describe('interpretResponse', () => { - it('should respond with empty response when there is empty serverResponse', () => { + describe('interpretResponse', function () { + it('should respond with empty response when there is empty serverResponse', function () { let result = spec.interpretResponse({ body: {} }, {}); assert.deepEqual(result, []); }); - it('should respond with empty response when response from server is not banner', () => { + it('should respond with empty response when response from server is not banner', function () { serverResponse.body[0].response = 'not banner'; serverResponse.body = [serverResponse.body[0]]; bidRequest.bids = [bidRequest.bids[0]]; @@ -144,7 +144,7 @@ describe('etarget adapter', () => { assert.deepEqual(result, []); }); - it('should interpret server response correctly with one bid', () => { + it('should interpret server response correctly with one bid', function () { serverResponse.body = [serverResponse.body[0]]; bidRequest.bids = [bidRequest.bids[0]]; let result = spec.interpretResponse(serverResponse, bidRequest)[0]; @@ -160,7 +160,7 @@ describe('etarget adapter', () => { assert.equal(result.transactionId, '5f33781f-9552-4ca1'); }); - it('should set correct netRevenue', () => { + it('should set correct netRevenue', function () { serverResponse.body = [serverResponse.body[0]]; bidRequest.bids = [bidRequest.bids[1]]; bidRequest.netRevenue = 'net'; @@ -169,22 +169,22 @@ describe('etarget adapter', () => { assert.equal(result.netRevenue, true); }); - it('should create bid response item for every requested item', () => { + it('should create bid response item for every requested item', function () { let result = spec.interpretResponse(serverResponse, bidRequest); assert.lengthOf(result, 5); }); - it('should create bid response with vast xml', () => { + it('should create bid response with vast xml', function () { const result = spec.interpretResponse(serverResponse, bidRequest)[3]; assert.equal(result.vastXml, ''); }); - it('should create bid response with vast url', () => { + it('should create bid response with vast url', function () { const result = spec.interpretResponse(serverResponse, bidRequest)[4]; assert.equal(result.vastUrl, 'vast://url'); }); - it('should set mediaType on bid response', () => { + it('should set mediaType on bid response', function () { const expected = [ BANNER, BANNER, BANNER, VIDEO, VIDEO ]; const result = spec.interpretResponse(serverResponse, bidRequest); for (let i = 0; i < result.length; i++) { @@ -192,7 +192,7 @@ describe('etarget adapter', () => { } }); - it('should set default netRevenue as gross', () => { + it('should set default netRevenue as gross', function () { bidRequest.netRevenue = 'gross'; const result = spec.interpretResponse(serverResponse, bidRequest); for (let i = 0; i < result.length; i++) { @@ -200,7 +200,7 @@ describe('etarget adapter', () => { } }); - it('should set gdpr if it exist in bidRequest', () => { + it('should set gdpr if it exist in bidRequest', function () { bidRequest.gdpr = { gdpr: true, gdpr_consent: 'ERW342EIOWT34234KMGds' @@ -219,8 +219,8 @@ describe('etarget adapter', () => { }; }); - describe('verifySizes', () => { - it('should respond with empty response when sizes doesn\'t match', () => { + describe('verifySizes', function () { + it('should respond with empty response when sizes doesn\'t match', function () { serverResponse.body[0].response = 'banner'; serverResponse.body[0].width = 100; serverResponse.body[0].height = 150; @@ -233,7 +233,7 @@ describe('etarget adapter', () => { assert.equal(serverResponse.body[0].response, 'banner'); assert.deepEqual(result, []); }); - it('should respond with empty response when sizes as a strings doesn\'t match', () => { + it('should respond with empty response when sizes as a strings doesn\'t match', function () { serverResponse.body[0].response = 'banner'; serverResponse.body[0].width = 100; serverResponse.body[0].height = 150; @@ -248,7 +248,7 @@ describe('etarget adapter', () => { assert.equal(serverResponse.body[0].response, 'banner'); assert.deepEqual(result, []); }); - it('should support size dimensions as a strings', () => { + it('should support size dimensions as a strings', function () { serverResponse.body[0].response = 'banner'; serverResponse.body[0].width = 300; serverResponse.body[0].height = 600; @@ -265,7 +265,7 @@ describe('etarget adapter', () => { }) }); - beforeEach(() => { + beforeEach(function () { let sizes = [[250, 300], [300, 250], [300, 600]]; let placementCode = ['div-01', 'div-02', 'div-03', 'div-04', 'div-05']; let params = [{refid: 1, country: 1, url: 'some// there'}, {refid: 2, country: 1, someVar: 'someValue', pt: 'gross'}, {refid: 3, country: 1, pdom: 'home'}, {refid: 5, country: 1, pt: 'net'}, {refid: 6, country: 1, pt: 'gross'}]; diff --git a/test/spec/modules/fairtradeBidAdapter_spec.js b/test/spec/modules/fairtradeBidAdapter_spec.js index 07c26e8f0c1..ecd5db3c051 100644 --- a/test/spec/modules/fairtradeBidAdapter_spec.js +++ b/test/spec/modules/fairtradeBidAdapter_spec.js @@ -5,13 +5,13 @@ import { newBidder } from 'src/adapters/bidderFactory'; describe('FairTradeAdapter', function () { const adapter = newBidder(spec); - describe('inherited functions', () => { - it('exists and is a function', () => { + describe('inherited functions', function () { + it('exists and is a function', function () { expect(adapter.callBids).to.exist.and.to.be.a('function'); }); }); - describe('isBidRequestValid', () => { + describe('isBidRequestValid', function () { let bid = { 'bidder': 'fairtrade', 'params': { @@ -24,11 +24,11 @@ describe('FairTradeAdapter', function () { 'auctionId': '1d1a030790a475', }; - it('should return true when required params found', () => { + it('should return true when required params found', function () { expect(spec.isBidRequestValid(bid)).to.equal(true); }); - it('should return false when required params are not passed', () => { + it('should return false when required params are not passed', function () { let bid = Object.assign({}, bid); delete bid.params; bid.params = { @@ -38,7 +38,7 @@ describe('FairTradeAdapter', function () { }); }); - describe('buildRequests', () => { + describe('buildRequests', function () { let bidRequests = [ { 'bidder': 'fairtrade', @@ -75,7 +75,7 @@ describe('FairTradeAdapter', function () { } ]; - it('should attach valid params to the tag', () => { + it('should attach valid params to the tag', function () { const request = spec.buildRequests([bidRequests[0]]); const payload = request.data; expect(payload).to.be.an('object'); @@ -85,7 +85,7 @@ describe('FairTradeAdapter', function () { expect(payload).to.have.property('r', '22edbae2733bf6'); }); - it('auids must not be duplicated', () => { + it('auids must not be duplicated', function () { const request = spec.buildRequests(bidRequests); const payload = request.data; expect(payload).to.be.an('object'); @@ -95,7 +95,7 @@ describe('FairTradeAdapter', function () { expect(payload).to.have.property('r', '22edbae2733bf6'); }); - it('pt parameter must be "gross" if params.priceType === "gross"', () => { + it('pt parameter must be "gross" if params.priceType === "gross"', function () { bidRequests[1].params.priceType = 'gross'; const request = spec.buildRequests(bidRequests); const payload = request.data; @@ -107,7 +107,7 @@ describe('FairTradeAdapter', function () { delete bidRequests[1].params.priceType; }); - it('pt parameter must be "net" or "gross"', () => { + it('pt parameter must be "net" or "gross"', function () { bidRequests[1].params.priceType = 'some'; const request = spec.buildRequests(bidRequests); const payload = request.data; @@ -120,7 +120,7 @@ describe('FairTradeAdapter', function () { }); }); - describe('interpretResponse', () => { + describe('interpretResponse', function () { const responses = [ {'bid': [{'price': 1.15, 'adm': '
test content 1
', 'auid': 165, 'h': 250, 'w': 300}], 'seat': '1'}, {'bid': [{'price': 0.5, 'adm': '
test content 2
', 'auid': 166, 'h': 90, 'w': 728}], 'seat': '1'}, @@ -131,7 +131,7 @@ describe('FairTradeAdapter', function () { {'seat': '1'}, ]; - it('should get correct bid response', () => { + it('should get correct bid response', function () { const bidRequests = [ { 'bidder': 'fairtrade', @@ -165,7 +165,7 @@ describe('FairTradeAdapter', function () { expect(result).to.deep.equal(expectedResponse); }); - it('should get correct multi bid response', () => { + it('should get correct multi bid response', function () { const bidRequests = [ { 'bidder': 'fairtrade', @@ -245,7 +245,7 @@ describe('FairTradeAdapter', function () { expect(result).to.deep.equal(expectedResponse); }); - it('handles wrong and nobid responses', () => { + it('handles wrong and nobid responses', function () { const bidRequests = [ { 'bidder': 'fairtrade', diff --git a/test/spec/modules/fidelityBidAdapter_spec.js b/test/spec/modules/fidelityBidAdapter_spec.js index 28ea18aacac..e8e008103e6 100644 --- a/test/spec/modules/fidelityBidAdapter_spec.js +++ b/test/spec/modules/fidelityBidAdapter_spec.js @@ -2,16 +2,16 @@ import { expect } from 'chai'; import { spec } from 'modules/fidelityBidAdapter'; import { newBidder } from 'src/adapters/bidderFactory'; -describe('FidelityAdapter', () => { +describe('FidelityAdapter', function () { const adapter = newBidder(spec); - describe('inherited functions', () => { - it('exists and is a function', () => { + describe('inherited functions', function () { + it('exists and is a function', function () { expect(adapter.callBids).to.exist.and.to.be.a('function'); }); }); - describe('isBidRequestValid', () => { + describe('isBidRequestValid', function () { let bid = { 'bidder': 'fidelity', 'params': { @@ -26,11 +26,11 @@ describe('FidelityAdapter', () => { 'auctionId': '1d1a030790a475', }; - it('should return true when required params found', () => { + it('should return true when required params found', function () { expect(spec.isBidRequestValid(bid)).to.equal(true); }); - it('should return true when required params found', () => { + it('should return true when required params found', function () { let bid = Object.assign({}, bid); delete bid.params; bid.params = { @@ -39,7 +39,7 @@ describe('FidelityAdapter', () => { expect(spec.isBidRequestValid(bid)).to.equal(true); }); - it('should return false when required params are not passed', () => { + it('should return false when required params are not passed', function () { let bid = Object.assign({}, bid); delete bid.params; bid.params = { @@ -49,10 +49,10 @@ describe('FidelityAdapter', () => { }); }); - describe('buildRequests', () => { + describe('buildRequests', function () { let bidderRequest = { bidderCode: 'fidelity', - auctionId: 'c45dd708-a418-42ec-b8a7-b70a6c6fab0a', + requestId: 'c45dd708-a418-42ec-b8a7-b70a6c6fab0a', bidderRequestId: '178e34bad3658f', bids: [ { @@ -66,7 +66,7 @@ describe('FidelityAdapter', () => { sizes: [[300, 250], [320, 50]], bidId: '2ffb201a808da7', bidderRequestId: '178e34bad3658f', - auctionId: 'c45dd708-a418-42ec-b8a7-b70a6c6fab0a', + requestId: 'c45dd708-a418-42ec-b8a7-b70a6c6fab0a', transactionId: 'd45dd707-a418-42ec-b8a7-b70a6c6fab0b' } ], @@ -75,7 +75,7 @@ describe('FidelityAdapter', () => { timeout: 5000 }; - it('should add source and verison to the tag', () => { + it('should add source and verison to the tag', function () { const [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); const payload = request.data; expect(payload.from).to.exist; @@ -85,21 +85,41 @@ describe('FidelityAdapter', () => { expect(payload.zoneid).to.exist; expect(payload.floor).to.exist; expect(payload.charset).to.exist; - expect(payload.defloc).to.exist; - expect(payload.altloc).to.exist; expect(payload.subid).to.exist; expect(payload.flashver).to.exist; expect(payload.tmax).to.exist; + expect(payload.defloc).to.exist; + }); + + it('should add gdpr consent information to the request', function () { + let consentString = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A=='; + bidderRequest.gdprConsent = { + gdprApplies: true, + consentString: consentString, + vendorData: { + vendorConsents: { + '408': 1 + }, + }, + }; + const [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); + const payload = request.data; + expect(payload.gdpr).to.exist.and.to.be.a('number'); + expect(payload.gdpr).to.equal(1); + expect(payload.consent_str).to.exist.and.to.be.a('string'); + expect(payload.consent_str).to.equal(consentString); + expect(payload.consent_given).to.exist.and.to.be.a('number'); + expect(payload.consent_given).to.equal(1); }); - it('sends bid request to ENDPOINT via GET', () => { + it('sends bid request to ENDPOINT via GET', function () { const [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); expect(request.url).to.equal('//t.fidelity-media.com/delivery/hb.php'); expect(request.method).to.equal('GET'); }); }) - describe('interpretResponse', () => { + describe('interpretResponse', function () { let response = { 'id': '543210', 'seatbid': [ { @@ -114,7 +134,7 @@ describe('FidelityAdapter', () => { } ] }; - it('should get correct bid response', () => { + it('should get correct bid response', function () { let expectedResponse = [ { requestId: 'bidId-123456-1', @@ -133,7 +153,7 @@ describe('FidelityAdapter', () => { expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse[0])); }); - it('handles nobid responses', () => { + it('handles nobid responses', function () { let response = { 'id': '543210', 'seatbid': [ ] @@ -144,10 +164,10 @@ describe('FidelityAdapter', () => { }); }); - describe('user sync', () => { + describe('user sync', function () { const syncUrl = '//x.fidelity-media.com/delivery/matches.php?type=iframe'; - it('should register the sync iframe', () => { + it('should register the sync iframe', function () { expect(spec.getUserSyncs({})).to.be.undefined; expect(spec.getUserSyncs({iframeEnabled: false})).to.be.undefined; const options = spec.getUserSyncs({iframeEnabled: true}); diff --git a/test/spec/modules/freewheel-sspBidAdapter_spec.js b/test/spec/modules/freewheel-sspBidAdapter_spec.js index 00c725027a1..177deaca7e7 100644 --- a/test/spec/modules/freewheel-sspBidAdapter_spec.js +++ b/test/spec/modules/freewheel-sspBidAdapter_spec.js @@ -4,16 +4,16 @@ import { newBidder } from 'src/adapters/bidderFactory'; const ENDPOINT = '//ads.stickyadstv.com/www/delivery/swfIndex.php'; -describe('freewheel-ssp BidAdapter Test', () => { +describe('freewheel-ssp BidAdapter Test', function () { const adapter = newBidder(spec); - describe('inherited functions', () => { - it('exists and is a function', () => { + describe('inherited functions', function () { + it('exists and is a function', function () { expect(adapter.callBids).to.exist.and.to.be.a('function'); }); }); - describe('isBidRequestValid', () => { + describe('isBidRequestValid', function () { let bid = { 'bidder': 'freewheel-ssp', 'params': { @@ -26,11 +26,11 @@ describe('freewheel-ssp BidAdapter Test', () => { 'auctionId': '1d1a030790a475', }; - it('should return true when required params found', () => { + it('should return true when required params found', function () { expect(spec.isBidRequestValid(bid)).to.equal(true); }); - it('should return false when required params are not passed', () => { + it('should return false when required params are not passed', function () { let bid = Object.assign({}, bid); delete bid.params; bid.params = { @@ -40,12 +40,13 @@ describe('freewheel-ssp BidAdapter Test', () => { }); }); - describe('buildRequests', () => { + describe('buildRequests', function () { let bidRequests = [ { 'bidder': 'freewheel-ssp', 'params': { - 'zoneId': '277225' + 'zoneId': '277225', + 'vastUrlParams': {'ownerId': 'kombRJ'} }, 'adUnitCode': 'adunit-code', 'sizes': [[300, 250], [300, 600]], @@ -59,46 +60,33 @@ describe('freewheel-ssp BidAdapter Test', () => { } ]; - it('should add parameters to the tag', () => { + it('should add parameters to the tag', function () { const request = spec.buildRequests(bidRequests, bidRequests[0]); const payload = request.data; expect(payload.reqType).to.equal('AdsSetup'); expect(payload.protocolVersion).to.equal('2.0'); expect(payload.zoneId).to.equal('277225'); expect(payload.componentId).to.equal('mustang'); + expect(payload.ownerId).to.equal('kombRJ'); expect(payload.playerSize).to.equal('300x600'); expect(payload._fw_gdpr).to.equal(true); expect(payload._fw_gdpr_consent).to.equal('BOJ/P2HOJ/P2HABABMAAAAAZ+A=='); }); - it('sends bid request to ENDPOINT via GET', () => { + it('sends bid request to ENDPOINT via GET', function () { const request = spec.buildRequests(bidRequests, bidRequests[0]); expect(request.url).to.contain(ENDPOINT); expect(request.method).to.equal('GET'); }); - }) - - describe('interpretResponse', () => { - let bidRequests = [ - { - 'bidder': 'freewheel-ssp', - 'params': { - 'zoneId': '277225' - }, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - } - ]; + }); - let formattedBidRequests = [ + describe('interpretResponse - formated', function () { + let intextBidRequests = [ { 'bidder': 'freewheel-ssp', 'params': { 'zoneId': '277225', - 'format': 'floorad' + 'format': 'intext-roll' }, 'adUnitCode': 'adunit-code', 'sizes': [[600, 250], [300, 600]], @@ -120,6 +108,36 @@ describe('freewheel-ssp BidAdapter Test', () => { } ]; + let expandBidRequests = [ + { + 'bidder': 'freewheel-ssp', + 'params': { + 'zoneId': '277225', + 'format': 'expand-banner', + 'vastUrlParams': {'ownerId': 'kombRJ'} + }, + 'adUnitCode': 'adunit-code', + 'sizes': [[600, 250], [300, 600]], + 'bidId': '30b3other1c1838de1e', + 'bidderRequestId': '22edbae273other3bf6', + 'auctionId': '1d1a03079test0a475', + } + ]; + + let bannerBidRequests = [ + { + 'bidder': 'freewheel-ssp', + 'params': { + 'zoneId': '277225' + }, + 'adUnitCode': 'adunit-code', + 'sizes': [[600, 250], [300, 600]], + 'bidId': '30b3other1c1838de1e', + 'bidderRequestId': '22edbae273other3bf6', + 'auctionId': '1d1a03079test0a475', + } + ]; + let response = '' + '' + ' ' + @@ -142,10 +160,11 @@ describe('freewheel-ssp BidAdapter Test', () => { ''; let ad = '
'; - let formattedAd = '
'; + let intextAd = '
'; + let expandAd = '
'; - it('should get correct bid response', () => { - var request = spec.buildRequests(formattedBidRequests, formattedBidRequests[0]); + it('should get correct intext bid response', function () { + var request = spec.buildRequests(bannerBidRequests, bannerBidRequests[0]); let expectedResponse = [ { @@ -165,8 +184,29 @@ describe('freewheel-ssp BidAdapter Test', () => { expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse[0])); }); - it('should get correct bid response with formated ad', () => { - var request = spec.buildRequests(formattedBidRequests, formattedBidRequests[0]); + it('should get correct expand bid response', function () { + var request = spec.buildRequests(expandBidRequests, expandBidRequests[0]); + + let expectedResponse = [ + { + requestId: '30b31c1838de1e', + cpm: '0.2000', + width: 300, + height: 600, + creativeId: '28517153', + currency: 'EUR', + netRevenue: true, + ttl: 360, + ad: expandAd + } + ]; + + let result = spec.interpretResponse(response, request); + expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse[0])); + }); + + it('should get correct bid response with formated ad', function () { + var request = spec.buildRequests(intextBidRequests, intextBidRequests[0]); let expectedResponse = [ { @@ -178,7 +218,7 @@ describe('freewheel-ssp BidAdapter Test', () => { currency: 'EUR', netRevenue: true, ttl: 360, - ad: formattedAd + ad: intextAd } ]; @@ -186,8 +226,8 @@ describe('freewheel-ssp BidAdapter Test', () => { expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse[0])); }); - it('handles nobid responses', () => { - var reqest = spec.buildRequests(formattedBidRequests, formattedBidRequests[0]); + it('handles nobid responses', function () { + var reqest = spec.buildRequests(intextBidRequests, intextBidRequests[0]); let response = ''; let result = spec.interpretResponse(response, reqest); diff --git a/test/spec/modules/fyberBidAdapter_spec.js b/test/spec/modules/fyberBidAdapter_spec.js index c6b49916519..a16c069d2a0 100644 --- a/test/spec/modules/fyberBidAdapter_spec.js +++ b/test/spec/modules/fyberBidAdapter_spec.js @@ -72,82 +72,82 @@ const mock = { } }; -describe('FyberAdapter', () => { +describe('FyberAdapter', function () { const adapter = newBidder(spec); - describe('inherited functions', () => { - it('callBids exists and is a function', () => { + describe('inherited functions', function () { + it('callBids exists and is a function', function () { expect(adapter.callBids).to.exist.and.to.be.a('function'); }); }); - describe('Verifies bidder code', () => { - it('Verifies bidder code', () => { + describe('Verifies bidder code', function () { + it('Verifies bidder code', function () { expect(spec.code).to.equal('fyber'); }); }); - describe('isBidRequestValid', () => { - it('should return true when required params found', () => { + describe('isBidRequestValid', function () { + it('should return true when required params found', function () { const bid = Object.assign({}, mock.bid); expect(spec.isBidRequestValid(bid)).to.equal(true); }); - it('should return false when required params{spotType} not found', () => { + it('should return false when required params{spotType} not found', function () { const bid = Object.assign({}, mock.bid); delete bid.params.spotType; expect(spec.isBidRequestValid(bid)).to.equal(false); }); - it('should return false when required{appId} params not found', () => { + it('should return false when required{appId} params not found', function () { const bid = Object.assign({}, mock.bid); delete bid.params.appId; expect(spec.isBidRequestValid(bid)).to.equal(false); }); }); - describe('buildRequests', () => { + describe('buildRequests', function () { const bidsRequest = Object.assign([], mock.bidsRequest); const requests = spec.buildRequests(bidsRequest); - it('Verify only one build request', () => { + it('Verify only one build request', function () { expect(requests.length).to.equal(1); }); const request = requests[0]; - it('Verify build request http method', () => { + it('Verify build request http method', function () { expect(request.method).to.equal('GET'); }); - it('Verify build request bidId', () => { + it('Verify build request bidId', function () { expect(request.bidId).to.equal(bidId); }); }); - describe('interpretResponse', () => { + describe('interpretResponse', function () { const request = Object.assign([], mock.bidsRequest)[0]; const validResponse = Object.assign({}, mock.validResponse); const validResult = spec.interpretResponse(validResponse, request); - it('Verify only one bid response', () => { + it('Verify only one bid response', function () { expect(validResult.length).to.equal(1); }); const bidResponse = validResult[0]; - it('Verify CPM', () => { + it('Verify CPM', function () { expect(bidResponse.cpm).to.equal(10000); }); - it('Verify requestId', () => { + it('Verify requestId', function () { expect(bidResponse.requestId).to.equal(bidId); }); const invalidResponse = Object.assign({}, mock.invalidResponse); const invalidResult = spec.interpretResponse(invalidResponse, request); - it('Verify empty bid response', () => { + it('Verify empty bid response', function () { expect(invalidResult.length).to.equal(0); }); }); diff --git a/test/spec/modules/gammaBidAdapter_spec.js b/test/spec/modules/gammaBidAdapter_spec.js index 5ff959cfb21..99593e6e06f 100644 --- a/test/spec/modules/gammaBidAdapter_spec.js +++ b/test/spec/modules/gammaBidAdapter_spec.js @@ -22,26 +22,26 @@ describe('gammaBidAdapter', function() { }; let bidArray = [bid]; - describe('isBidRequestValid', () => { - it('should return true when required params found', () => { + describe('isBidRequestValid', function () { + it('should return true when required params found', function () { expect(spec.isBidRequestValid(bid)).to.equal(true); }); - it('should return false when require params are not passed', () => { + it('should return false when require params are not passed', function () { let bid = Object.assign({}, bid); bid.params = {}; expect(spec.isBidRequestValid(bid)).to.equal(false); }); - it('should return false when params not passed correctly', () => { + it('should return false when params not passed correctly', function () { bid.params.siteId = ''; bid.params.zoneId = ''; expect(spec.isBidRequestValid(bid)).to.equal(false); }); }); - describe('buildRequests', () => { - it('should attempt to send bid requests to the endpoint via GET', () => { + describe('buildRequests', function () { + it('should attempt to send bid requests to the endpoint via GET', function () { const requests = spec.buildRequests(bidArray); requests.forEach(function(requestItem) { expect(requestItem.method).to.equal('GET'); @@ -50,10 +50,10 @@ describe('gammaBidAdapter', function() { }); }); - describe('interpretResponse', () => { + describe('interpretResponse', function () { let serverResponse; - beforeEach(() => { + beforeEach(function () { serverResponse = { body: { 'id': '23beaa6af6cdde', @@ -77,7 +77,7 @@ describe('gammaBidAdapter', function() { }; }) - it('should get the correct bid response', () => { + it('should get the correct bid response', function () { let expectedResponse = [{ 'requestId': '23beaa6af6cdde', 'cpm': 0.45, @@ -94,7 +94,7 @@ describe('gammaBidAdapter', function() { expect(Object.keys(result)).to.deep.equal(Object.keys(expectedResponse)); }); - it('handles empty bid response', () => { + it('handles empty bid response', function () { let response = { body: {} }; diff --git a/test/spec/modules/gamoshiBidAdapter_spec.js b/test/spec/modules/gamoshiBidAdapter_spec.js new file mode 100644 index 00000000000..26d67b70f78 --- /dev/null +++ b/test/spec/modules/gamoshiBidAdapter_spec.js @@ -0,0 +1,406 @@ +import {expect} from 'chai'; +import {spec} from 'modules/gamoshiBidAdapter'; +import {helper} from 'modules/gamoshiBidAdapter'; +import * as utils from 'src/utils'; +import {newBidder} from '../../../src/adapters/bidderFactory'; +import {deepClone} from 'src/utils'; +const supplyPartnerId = '123'; +const adapter = newBidder(spec); +describe('GamoshiAdapter', function () { + describe('Get top Frame', function () { + it('check if you are in the top frame', function () { + expect(helper.getTopFrame()).to.equal(0); + }); + it('verify domain parsing', function () { + expect(helper.getTopWindowDomain('http://www.domain.com')).to.equal('www.domain.com'); + }); + }); + describe('Is String start with search ', function () { + it('check if a string started with', function () { + expect(helper.startsWith('gamoshi.com', 'gamo')).to.equal(true); + }); + }); + + describe('inherited functions', function () { + it('exists and is a function', function () { + expect(adapter.callBids).to.exist.and.to.be.a('function'); + }); + }); + + describe('isBidRequestValid', function () { + it('should validate supply-partner ID', function () { + expect(spec.isBidRequestValid({params: {}})).to.equal(false); + expect(spec.isBidRequestValid({params: {supplyPartnerId: 123}})).to.equal(false); + expect(spec.isBidRequestValid({params: {supplyPartnerId: '123'}})).to.equal(true); + }); + + it('should validate RTB endpoint', function () { + expect(spec.isBidRequestValid({params: {supplyPartnerId: '123'}})).to.equal(true); // RTB endpoint has a default + expect(spec.isBidRequestValid({params: {supplyPartnerId: '123', rtbEndpoint: 123}})).to.equal(false); + expect(spec.isBidRequestValid({ + params: { + supplyPartnerId: '123', + rtbEndpoint: 'https://some.url.com' + } + })).to.equal(true); + }); + + it('should validate bid floor', function () { + expect(spec.isBidRequestValid({params: {supplyPartnerId: '123'}})).to.equal(true); // bidfloor has a default + expect(spec.isBidRequestValid({params: {supplyPartnerId: '123', bidfloor: '123'}})).to.equal(false); + expect(spec.isBidRequestValid({params: {supplyPartnerId: '123', bidfloor: 0.1}})).to.equal(true); + }); + + it('should validate adpos', function () { + expect(spec.isBidRequestValid({params: {supplyPartnerId: '123'}})).to.equal(true); // adpos has a default + expect(spec.isBidRequestValid({params: {supplyPartnerId: '123', adpos: '123'}})).to.equal(false); + expect(spec.isBidRequestValid({params: {supplyPartnerId: '123', adpos: 0.1}})).to.equal(true); + }); + + it('should validate instl', function () { + expect(spec.isBidRequestValid({params: {supplyPartnerId: '123'}})).to.equal(true); // adpos has a default + expect(spec.isBidRequestValid({params: {supplyPartnerId: '123', instl: '123'}})).to.equal(false); + expect(spec.isBidRequestValid({params: {supplyPartnerId: '123', instl: -1}})).to.equal(false); + expect(spec.isBidRequestValid({params: {supplyPartnerId: '123', instl: 0}})).to.equal(true); + expect(spec.isBidRequestValid({params: {supplyPartnerId: '123', instl: 1}})).to.equal(true); + expect(spec.isBidRequestValid({params: {supplyPartnerId: '123', instl: 2}})).to.equal(false); + }); + }); + + describe('buildRequests', function () { + const bidRequest = { + 'adUnitCode': 'adunit-code', + 'auctionId': '1d1a030790a475', + 'mediaTypes': { + banner: {} + }, + 'params': { + 'supplyPartnerId': supplyPartnerId + }, + 'sizes': [[300, 250], [300, 600]], + 'transactionId': 'a123456789', + refererInfo: {referer: 'http://examplereferer.com'} + }; + it('returns an array', function () { + let response; + response = spec.buildRequests([]); + expect(Array.isArray(response)).to.equal(true); + expect(response.length).to.equal(0); + response = spec.buildRequests([bidRequest]); + expect(Array.isArray(response)).to.equal(true); + expect(response.length).to.equal(1); + const adUnit1 = Object.assign({}, utils.deepClone(bidRequest), {auctionId: '1', adUnitCode: 'a'}); + const adUnit2 = Object.assign({}, utils.deepClone(bidRequest), {auctionId: '1', adUnitCode: 'b'}); + response = spec.buildRequests([adUnit1, adUnit2]); + expect(Array.isArray(response)).to.equal(true); + expect(response.length).to.equal(2); + }); + + it('targets correct endpoint', function () { + let response; + response = spec.buildRequests([bidRequest])[0]; + expect(response.method).to.equal('POST'); + expect(response.url).to.match(new RegExp(`^https://rtb\\.gamoshi\\.io/r/${supplyPartnerId}/bidr\\?rformat=open_rtb&reqformat=rtb_json&bidder=prebid$`, 'g')); + expect(response.data.id).to.equal(bidRequest.auctionId); + const bidRequestWithEndpoint = utils.deepClone(bidRequest); + bidRequestWithEndpoint.params.rtbEndpoint = 'https://rtb2.gamoshi.io/a12'; + response = spec.buildRequests([bidRequestWithEndpoint])[0]; + expect(response.url).to.match(new RegExp(`^https://rtb2\\.gamoshi\\.io/a12/r/${supplyPartnerId}/bidr\\?rformat=open_rtb&reqformat=rtb_json&bidder=prebid$`, 'g')); + }); + + it('builds request correctly', function () { + let stub = sinon.stub(utils, 'getTopWindowUrl').returns('http://www.test.com/page.html'); + let response; + response = spec.buildRequests([bidRequest])[0]; + expect(response.data.site.domain).to.equal('www.test.com'); + expect(response.data.site.page).to.equal('http://www.test.com/page.html'); + expect(response.data.site.ref).to.equal(''); + expect(response.data.imp.length).to.equal(1); + expect(response.data.imp[0].id).to.equal(bidRequest.transactionId); + expect(response.data.imp[0].instl).to.equal(0); + expect(response.data.imp[0].tagid).to.equal(bidRequest.adUnitCode); + expect(response.data.imp[0].bidfloor).to.equal(0); + expect(response.data.imp[0].bidfloorcur).to.equal('USD'); + const bidRequestWithInstlEquals1 = utils.deepClone(bidRequest); + bidRequestWithInstlEquals1.params.instl = 1; + response = spec.buildRequests([bidRequestWithInstlEquals1])[0]; + expect(response.data.imp[0].instl).to.equal(bidRequestWithInstlEquals1.params.instl); + const bidRequestWithInstlEquals0 = utils.deepClone(bidRequest); + bidRequestWithInstlEquals0.params.instl = 1; + response = spec.buildRequests([bidRequestWithInstlEquals0])[0]; + expect(response.data.imp[0].instl).to.equal(bidRequestWithInstlEquals0.params.instl); + const bidRequestWithBidfloorEquals1 = utils.deepClone(bidRequest); + bidRequestWithBidfloorEquals1.params.bidfloor = 1; + response = spec.buildRequests([bidRequestWithBidfloorEquals1])[0]; + expect(response.data.imp[0].bidfloor).to.equal(bidRequestWithBidfloorEquals1.params.bidfloor); + stub.restore(); + }); + + it('builds request banner object correctly', function () { + let response; + const bidRequestWithBanner = utils.deepClone(bidRequest); + bidRequestWithBanner.mediaTypes = { + banner: { + sizes: [[300, 250], [120, 600]] + } + }; + response = spec.buildRequests([bidRequestWithBanner])[0]; + expect(response.data.imp[0].banner.w).to.equal(bidRequestWithBanner.mediaTypes.banner.sizes[0][0]); + expect(response.data.imp[0].banner.h).to.equal(bidRequestWithBanner.mediaTypes.banner.sizes[0][1]); + expect(response.data.imp[0].banner.pos).to.equal(0); + expect(response.data.imp[0].banner.topframe).to.equal(0); + const bidRequestWithPosEquals1 = utils.deepClone(bidRequestWithBanner); + bidRequestWithPosEquals1.params.pos = 1; + response = spec.buildRequests([bidRequestWithPosEquals1])[0]; + expect(response.data.imp[0].banner.pos).to.equal(bidRequestWithPosEquals1.params.pos); + }); + + it('builds request video object correctly', function () { + let response; + const bidRequestWithVideo = utils.deepClone(bidRequest); + bidRequestWithVideo.mediaTypes = { + video: { + sizes: [[300, 250], [120, 600]] + } + }; + response = spec.buildRequests([bidRequestWithVideo])[0]; + expect(response.data.imp[0].video.w).to.equal(bidRequestWithVideo.mediaTypes.video.sizes[0][0]); + expect(response.data.imp[0].video.h).to.equal(bidRequestWithVideo.mediaTypes.video.sizes[0][1]); + expect(response.data.imp[0].video.pos).to.equal(0); + expect(response.data.imp[0].video.topframe).to.equal(0); + const bidRequestWithPosEquals1 = utils.deepClone(bidRequestWithVideo); + bidRequestWithPosEquals1.params.pos = 1; + response = spec.buildRequests([bidRequestWithPosEquals1])[0]; + expect(response.data.imp[0].video.pos).to.equal(bidRequestWithPosEquals1.params.pos); + }); + }); + + describe('interpretResponse', function () { + const bannerBidRequest = { + 'adUnitCode': 'adunit-code', + 'auctionId': '1d1a030790a475', + 'mediaTypes': { + banner: {} + }, + 'params': { + 'supplyPartnerId': supplyPartnerId + }, + 'sizes': [[300, 250], [300, 600]], + 'transactionId': 'a123456789', + 'bidId': '111', + refererInfo: { referer: 'http://examplereferer.com' } + }; + + const videoBidRequest = { + 'adUnitCode': 'adunit-code', + 'auctionId': '1d1a030790a475', + 'mediaTypes': { + video: {} + }, + 'params': { + 'supplyPartnerId': supplyPartnerId + }, + 'sizes': [[300, 250], [300, 600]], + 'transactionId': 'a123456789', + 'bidId': '111', + refererInfo: { referer: 'http://examplereferer.com' } + }; + + const rtbResponse = { + 'id': 'imp_5b05b9fde4b09084267a556f', + 'bidid': 'imp_5b05b9fde4b09084267a556f', + 'cur': 'USD', + 'ext': { + 'utrk': [ + {'type': 'iframe', 'url': '//rtb.gamoshi.io/user/sync/1'}, + {'type': 'image', 'url': '//rtb.gamoshi.io/user/sync/2'} + ] + }, + 'seatbid': [ + { + 'seat': 'seat1', + 'group': 0, + 'bid': [ + { + 'id': '0', + 'impid': '1', + 'price': 2.016, + 'adid': '579ef31bfa788b9d2000d562', + 'nurl': 'https://rtb.gamoshi.io/pix/monitoring/win_notice/imp_5b05b9fde4b09084267a556f/im.gif?r=imp_5b05b9fde4b09084267a556f&i=1&a=579ef31bfa788b9d2000d562&b=0&p=${AUCTION_PRICE}', + 'adm': ' ', + 'adomain': ['aaa.com'], + 'cid': '579ef268fa788b9d2000d55c', + 'crid': '579ef31bfa788b9d2000d562', + 'attr': [], + 'h': 600, + 'w': 120, + 'ext': { + 'vast_url': 'http://my.vast.com', + 'utrk': [ + {'type': 'iframe', 'url': '//p.partner1.io/user/sync/1'} + ] + } + } + ] + }, + { + 'seat': 'seat2', + 'group': 0, + 'bid': [ + { + 'id': '1', + 'impid': '1', + 'price': 3, + 'adid': '542jlhdfd2112jnjf3x', + 'nurl': 'https://rtb.gamoshi.io/pix/monitoring/win_notice/imp_5b05b9fde4b09084267a556f/im.gif?r=imp_5b05b9fde4b09084267a556f&i=1&a=579ef31bfa788b9d2000d562&b=0&p=${AUCTION_PRICE}', + 'adm': ' ', + 'adomain': ['bbb.com'], + 'cid': 'fgdlwjh2498ydjhg1', + 'crid': 'kjh34297ydh2133d', + 'attr': [], + 'h': 250, + 'w': 300, + 'ext': { + 'utrk': [ + {'type': 'image', 'url': '//p.partner2.io/user/sync/1'} + ] + } + } + ] + } + ] + }; + + it('returns an empty array on missing response', function () { + let response; + + response = spec.interpretResponse(undefined, {bidRequest: bannerBidRequest}); + expect(Array.isArray(response)).to.equal(true); + expect(response.length).to.equal(0); + + response = spec.interpretResponse({}, {bidRequest: bannerBidRequest}); + expect(Array.isArray(response)).to.equal(true); + expect(response.length).to.equal(0); + }); + + it('aggregates banner bids from all seat bids', function () { + const response = spec.interpretResponse({body: rtbResponse}, {bidRequest: bannerBidRequest}); + expect(Array.isArray(response)).to.equal(true); + expect(response.length).to.equal(2); + + const ad0 = response[0], ad1 = response[1]; + expect(ad0.requestId).to.equal(bannerBidRequest.bidId); + expect(ad0.cpm).to.equal(rtbResponse.seatbid[0].bid[0].price); + expect(ad0.width).to.equal(rtbResponse.seatbid[0].bid[0].w); + expect(ad0.height).to.equal(rtbResponse.seatbid[0].bid[0].h); + expect(ad0.ttl).to.equal(60 * 10); + expect(ad0.creativeId).to.equal(rtbResponse.seatbid[0].bid[0].crid); + expect(ad0.netRevenue).to.equal(true); + expect(ad0.currency).to.equal(rtbResponse.seatbid[0].bid[0].cur || rtbResponse.cur || 'USD'); + expect(ad0.ad).to.equal(rtbResponse.seatbid[0].bid[0].adm); + expect(ad0.vastXml).to.be.an('undefined'); + + expect(ad1.requestId).to.equal(bannerBidRequest.bidId); + expect(ad1.cpm).to.equal(rtbResponse.seatbid[1].bid[0].price); + expect(ad1.width).to.equal(rtbResponse.seatbid[1].bid[0].w); + expect(ad1.height).to.equal(rtbResponse.seatbid[1].bid[0].h); + expect(ad1.ttl).to.equal(60 * 10); + expect(ad1.creativeId).to.equal(rtbResponse.seatbid[1].bid[0].crid); + expect(ad1.netRevenue).to.equal(true); + expect(ad1.currency).to.equal(rtbResponse.seatbid[1].bid[0].cur || rtbResponse.cur || 'USD'); + expect(ad1.ad).to.equal(rtbResponse.seatbid[1].bid[0].adm); + expect(ad1.vastXml).to.be.an('undefined'); + }); + + it('aggregates video bids from all seat bids', function () { + const response = spec.interpretResponse({body: rtbResponse}, {bidRequest: videoBidRequest}); + expect(Array.isArray(response)).to.equal(true); + expect(response.length).to.equal(2); + + const ad0 = response[0], ad1 = response[1]; + expect(ad0.requestId).to.equal(videoBidRequest.bidId); + expect(ad0.cpm).to.equal(rtbResponse.seatbid[0].bid[0].price); + expect(ad0.width).to.equal(rtbResponse.seatbid[0].bid[0].w); + expect(ad0.height).to.equal(rtbResponse.seatbid[0].bid[0].h); + expect(ad0.ttl).to.equal(60 * 10); + expect(ad0.creativeId).to.equal(rtbResponse.seatbid[0].bid[0].crid); + expect(ad0.netRevenue).to.equal(true); + expect(ad0.currency).to.equal(rtbResponse.seatbid[0].bid[0].cur || rtbResponse.cur || 'USD'); + expect(ad0.ad).to.be.an('undefined'); + expect(ad0.vastXml).to.equal(rtbResponse.seatbid[0].bid[0].adm); + expect(ad0.vastUrl).to.equal(rtbResponse.seatbid[0].bid[0].ext.vast_url); + + expect(ad1.requestId).to.equal(videoBidRequest.bidId); + expect(ad1.cpm).to.equal(rtbResponse.seatbid[1].bid[0].price); + expect(ad1.width).to.equal(rtbResponse.seatbid[1].bid[0].w); + expect(ad1.height).to.equal(rtbResponse.seatbid[1].bid[0].h); + expect(ad1.ttl).to.equal(60 * 10); + expect(ad1.creativeId).to.equal(rtbResponse.seatbid[1].bid[0].crid); + expect(ad1.netRevenue).to.equal(true); + expect(ad1.currency).to.equal(rtbResponse.seatbid[1].bid[0].cur || rtbResponse.cur || 'USD'); + expect(ad1.ad).to.be.an('undefined'); + expect(ad1.vastXml).to.equal(rtbResponse.seatbid[1].bid[0].adm); + expect(ad1.vastUrl).to.equal(rtbResponse.seatbid[1].bid[0].ext.vast_url); + }); + + it('aggregates user-sync pixels', function () { + const response = spec.getUserSyncs({}, [{body: rtbResponse}]); + expect(Array.isArray(response)).to.equal(true); + expect(response.length).to.equal(4); + expect(response[0].type).to.equal(rtbResponse.ext.utrk[0].type); + expect(response[0].url).to.equal(rtbResponse.ext.utrk[0].url + '?gc=missing'); + expect(response[1].type).to.equal(rtbResponse.ext.utrk[1].type); + expect(response[1].url).to.equal(rtbResponse.ext.utrk[1].url + '?gc=missing'); + expect(response[2].type).to.equal(rtbResponse.seatbid[0].bid[0].ext.utrk[0].type); + expect(response[2].url).to.equal(rtbResponse.seatbid[0].bid[0].ext.utrk[0].url + '?gc=missing'); + expect(response[3].type).to.equal(rtbResponse.seatbid[1].bid[0].ext.utrk[0].type); + expect(response[3].url).to.equal(rtbResponse.seatbid[1].bid[0].ext.utrk[0].url + '?gc=missing'); + }); + + it('supports configuring outstream renderers', function () { + const videoResponse = { + 'id': '64f32497-b2f7-48ec-9205-35fc39894d44', + 'bidid': 'imp_5c24924de4b0d106447af333', + 'cur': 'USD', + 'seatbid': [ + { + 'seat': '3668', + 'group': 0, + 'bid': [ + { + 'id': 'gb_1', + 'impid': 'afbb5852-7cea-4a81-aa9a-a41aab505c23', + 'price': 5.0, + 'adid': '1274', + 'nurl': 'https://rtb.gamoshi.io/pix/1275/win_notice/imp_5c24924de4b0d106447af333/im.gif?r=imp_5c24924de4b0d106447af333&i=afbb5852-7cea-4a81-aa9a-a41aab505c23&a=1274&b=gb_1&p=${AUCTION_PRICE}', + 'adomain': [], + 'adm': '\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n', + 'cid': '3668', + 'crid': '1274', + 'cat': [], + 'attr': [], + 'h': 250, + 'w': 300, + 'ext': { + 'vast_url': 'https://rtb.gamoshi.io/pix/1275/vast_o/imp_5c24924de4b0d106447af333/im.xml?r=imp_5c24924de4b0d106447af333&i=afbb5852-7cea-4a81-aa9a-a41aab505c23&a=1274&b=gb_1&w=300&h=250&vatu=aHR0cHM6Ly9zdGF0aWMuZ2FtYmlkLmlvL2RlbW8vdmFzdC54bWw&vwarv', + 'imptrackers': [ + 'https://rtb.gamoshi.io/pix/1275/imp/imp_5c24924de4b0d106447af333/im.gif?r=imp_5c24924de4b0d106447af333&i=afbb5852-7cea-4a81-aa9a-a41aab505c23&a=1274&b=gb_1'] + } + } + ] + } + ], + 'ext': { + 'utrk': [{ + 'type': 'image', + 'url': 'https://rtb.gamoshi.io/pix/1275/scm?cb=1545900621675' + }] + } + }; + const videoRequest = deepClone(videoBidRequest); + videoRequest.mediaTypes.video.context = 'outstream'; + const result = spec.interpretResponse({body: videoResponse}, {bidRequest: videoRequest}); + expect(result[0].renderer).to.not.equal(undefined); + }); + }); +}); diff --git a/test/spec/modules/getintentBidAdapter_spec.js b/test/spec/modules/getintentBidAdapter_spec.js index 17f9a95fec4..ebbda7e108e 100644 --- a/test/spec/modules/getintentBidAdapter_spec.js +++ b/test/spec/modules/getintentBidAdapter_spec.js @@ -1,7 +1,7 @@ import { expect } from 'chai' import { spec } from 'modules/getintentBidAdapter' -describe('GetIntent Adapter Tests:', () => { +describe('GetIntent Adapter Tests:', function () { const bidRequests = [{ bidId: 'bid12345', params: { @@ -34,7 +34,7 @@ describe('GetIntent Adapter Tests:', () => { mediaType: 'video' }; - it('Verify build request', () => { + it('Verify build request', function () { const serverRequests = spec.buildRequests(bidRequests); let serverRequest = serverRequests[0]; expect(serverRequest.url).to.equal('//px.adhigh.net/rtb/direct_banner'); @@ -48,7 +48,7 @@ describe('GetIntent Adapter Tests:', () => { expect(serverRequest.data.size).to.equal('50x50,100x100'); }); - it('Verify build video request', () => { + it('Verify build video request', function () { const serverRequests = spec.buildRequests([videoBidRequest]); let serverRequest = serverRequests[0]; expect(serverRequest.url).to.equal('//px.adhigh.net/rtb/direct_vast'); @@ -64,7 +64,7 @@ describe('GetIntent Adapter Tests:', () => { expect(serverRequest.data.skippable).to.equal(true); }); - it('Verify parse response', () => { + it('Verify parse response', function () { const serverResponse = { body: { bid_id: 'bid12345', @@ -90,7 +90,7 @@ describe('GetIntent Adapter Tests:', () => { expect(bid.ad).to.equal('Ad markup'); }); - it('Verify parse video response', () => { + it('Verify parse video response', function () { const serverResponse = { body: { bid_id: 'bid789', @@ -116,22 +116,22 @@ describe('GetIntent Adapter Tests:', () => { expect(bid.vastUrl).to.equal('//vast.xml/url'); }); - it('Verify bidder code', () => { + it('Verify bidder code', function () { expect(spec.code).to.equal('getintent'); }); - it('Verify bidder aliases', () => { + it('Verify bidder aliases', function () { expect(spec.aliases).to.have.lengthOf(1); expect(spec.aliases[0]).to.equal('getintentAdapter'); }); - it('Verify supported media types', () => { + it('Verify supported media types', function () { expect(spec.supportedMediaTypes).to.have.lengthOf(2); expect(spec.supportedMediaTypes[0]).to.equal('video'); expect(spec.supportedMediaTypes[1]).to.equal('banner'); }); - it('Verify if bid request valid', () => { + it('Verify if bid request valid', function () { expect(spec.isBidRequestValid(bidRequests[0])).to.equal(true); expect(spec.isBidRequestValid(bidRequests[1])).to.equal(true); expect(spec.isBidRequestValid({})).to.equal(false); diff --git a/test/spec/modules/giantsBidAdapter_spec.js b/test/spec/modules/giantsBidAdapter_spec.js index 69535cba13f..bab2415745d 100644 --- a/test/spec/modules/giantsBidAdapter_spec.js +++ b/test/spec/modules/giantsBidAdapter_spec.js @@ -1,301 +1,301 @@ -import { expect } from 'chai'; -import { spec } from 'modules/giantsBidAdapter'; -import { newBidder } from 'src/adapters/bidderFactory'; -import { deepClone } from 'src/utils'; -import * as utils from 'src/utils'; - -const ENDPOINT = '//d.admp.io/hb/multi?url='; - -describe('GiantsAdapter', () => { - const adapter = newBidder(spec); - - describe('inherited functions', () => { - it('exists and is a function', () => { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', () => { - let bid = { - 'bidder': 'giants', - 'params': { - 'zoneId': '584072408' - }, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - }; - - it('should return true when required params found', () => { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when required params are not passed', () => { - let bid = Object.assign({}, bid); - delete bid.params; - bid.params = { - 'zoneId': 0 - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - }); - - describe('buildRequests', () => { - let bidRequests = [ - { - 'bidder': 'giants', - 'params': { - 'zoneId': '584072408' - }, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - } - ]; - - it('should parse out private sizes', () => { - let bidRequest = Object.assign({}, - bidRequests[0], - { - params: { - zoneId: '584072408', - privateSizes: [300, 250] - } - } - ); - - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - - expect(payload.tags[0].private_sizes).to.exist; - expect(payload.tags[0].private_sizes).to.deep.equal([{width: 300, height: 250}]); - }); - - it('should add source and verison to the tag', () => { - const request = spec.buildRequests(bidRequests); - const payload = JSON.parse(request.data); - expect(payload.sdk).to.exist; - expect(payload.sdk).to.deep.equal({ - source: 'pbjs', - version: '$prebid.version$' - }); - }); - - it('should populate the ad_types array on all requests', () => { - ['banner', 'video', 'native'].forEach(type => { - const bidRequest = Object.assign({}, bidRequests[0]); - bidRequest.mediaTypes = {}; - bidRequest.mediaTypes[type] = {}; - - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - - expect(payload.tags[0].ad_types).to.deep.equal([type]); - }); - }); - - it('should populate the ad_types array on outstream requests', () => { - const bidRequest = Object.assign({}, bidRequests[0]); - bidRequest.mediaTypes = {}; - bidRequest.mediaTypes.video = {context: 'outstream'}; - - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - - expect(payload.tags[0].ad_types).to.deep.equal(['video']); - }); - - it('sends bid request to ENDPOINT via POST', () => { - const request = spec.buildRequests(bidRequests); - expect(request.url).to.equal(ENDPOINT + utils.getTopWindowUrl()); - expect(request.method).to.equal('POST'); - }); - - it('should attach valid video params to the tag', () => { - let bidRequest = Object.assign({}, - bidRequests[0], - { - params: { - zoneId: '584072408', - video: { - id: 123, - minduration: 100, - foobar: 'invalid' - } - } - } - ); - - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - expect(payload.tags[0].video).to.deep.equal({ - id: 123, - minduration: 100 - }); - }); - - it('sets minimum native asset params when not provided on adunit', () => { - let bidRequest = Object.assign({}, - bidRequests[0], - { - mediaType: 'native', - nativeParams: { - image: {required: true}, - } - } - ); - - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - - expect(payload.tags[0].native.layouts[0]).to.deep.equal({ - main_image: {required: true, sizes: [{}]}, - }); - }); - - it('does not overwrite native ad unit params with mimimum params', () => { - let bidRequest = Object.assign({}, - bidRequests[0], - { - mediaType: 'native', - nativeParams: { - image: { - aspect_ratios: [{ - min_width: 100, - ratio_width: 2, - ratio_height: 3, - }] - } - } - } - ); - - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - - expect(payload.tags[0].native.layouts[0]).to.deep.equal({ - main_image: { - required: true, - aspect_ratios: [{ - min_width: 100, - ratio_width: 2, - ratio_height: 3, - }] - }, - }); - }); - - it('should convert keyword params to proper form and attaches to request', () => { - let bidRequest = Object.assign({}, - bidRequests[0], - { - params: { - zoneId: '584072408', - keywords: { - single: 'val', - singleArr: ['val'], - singleArrNum: [5], - multiValMixed: ['value1', 2, 'value3'], - singleValNum: 123, - badValue: {'foo': 'bar'} // should be dropped - } - } - } - ); - - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - - expect(payload.tags[0].keywords).to.deep.equal([{ - 'key': 'single', - 'value': ['val'] - }, { - 'key': 'singleArr', - 'value': ['val'] - }, { - 'key': 'singleArrNum', - 'value': ['5'] - }, { - 'key': 'multiValMixed', - 'value': ['value1', '2', 'value3'] - }, { - 'key': 'singleValNum', - 'value': ['123'] - }]); - }); - - it('should add payment rules to the request', () => { - let bidRequest = Object.assign({}, - bidRequests[0], - { - params: { - zoneId: '584072408', - usePaymentRule: true - } - } - ); - - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - - expect(payload.tags[0].use_pmt_rule).to.equal(true); - }); - }) - - describe('interpretResponse', () => { - let response = { - 'version': '3.0.0', - 'tags': [ - { - 'uuid': '3db3773286ee59', - 'creative_id': '584944065', - 'height': 600, - 'width': 300, - 'zoneId': '584072408', - 'adUrl': '//d.admp.io/pbc/v1/cache-banner/f7aca005-8171-4299-90bf-0750a864a61c', - 'cpm': 0.5 - } - ] - }; - - it('should get correct bid response', () => { - let expectedResponse = [ - { - 'requestId': '3db3773286ee59', - 'cpm': 0.5, - 'creativeId': 29681110, - 'currency': 'USD', - 'netRevenue': true, - 'ttl': 300, - 'width': 300, - 'height': 250, - 'ad': '', - 'mediaType': 'banner' - } - ]; - let bidderRequest; - let result = spec.interpretResponse({ body: response }, {bidderRequest}); - expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])); - }); - - it('handles nobid responses', () => { - let response = { - 'version': '0.0.1', - 'tags': [{ - 'uuid': '84ab500420319d', - 'tag_id': 5976557, - 'auction_id': '297492697822162468', - 'nobid': true - }] - }; - let bidderRequest; - - let result = spec.interpretResponse({ body: response }, {bidderRequest}); - expect(result.length).to.equal(0); - }); - }); -}); +import { expect } from 'chai'; +import { spec } from 'modules/giantsBidAdapter'; +import { newBidder } from 'src/adapters/bidderFactory'; +import { deepClone } from 'src/utils'; +import * as utils from 'src/utils'; + +const ENDPOINT = '//d.admp.io/hb/multi?url='; + +describe('GiantsAdapter', 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('isBidRequestValid', function () { + let bid = { + 'bidder': 'giants', + 'params': { + 'zoneId': '584072408' + }, + 'adUnitCode': 'adunit-code', + 'sizes': [[300, 250], [300, 600]], + 'bidId': '30b31c1838de1e', + 'bidderRequestId': '22edbae2733bf6', + 'auctionId': '1d1a030790a475', + }; + + it('should return true when required params found', function () { + expect(spec.isBidRequestValid(bid)).to.equal(true); + }); + + it('should return false when required params are not passed', function () { + let bid = Object.assign({}, bid); + delete bid.params; + bid.params = { + 'zoneId': 0 + }; + expect(spec.isBidRequestValid(bid)).to.equal(false); + }); + }); + + describe('buildRequests', function () { + let bidRequests = [ + { + 'bidder': 'giants', + 'params': { + 'zoneId': '584072408' + }, + 'adUnitCode': 'adunit-code', + 'sizes': [[300, 250], [300, 600]], + 'bidId': '30b31c1838de1e', + 'bidderRequestId': '22edbae2733bf6', + 'auctionId': '1d1a030790a475', + } + ]; + + it('should parse out private sizes', function () { + let bidRequest = Object.assign({}, + bidRequests[0], + { + params: { + zoneId: '584072408', + privateSizes: [300, 250] + } + } + ); + + const request = spec.buildRequests([bidRequest]); + const payload = JSON.parse(request.data); + + expect(payload.tags[0].private_sizes).to.exist; + expect(payload.tags[0].private_sizes).to.deep.equal([{width: 300, height: 250}]); + }); + + it('should add source and verison to the tag', function () { + const request = spec.buildRequests(bidRequests); + const payload = JSON.parse(request.data); + expect(payload.sdk).to.exist; + expect(payload.sdk).to.deep.equal({ + source: 'pbjs', + version: '$prebid.version$' + }); + }); + + it('should populate the ad_types array on all requests', function () { + ['banner', 'video', 'native'].forEach(type => { + const bidRequest = Object.assign({}, bidRequests[0]); + bidRequest.mediaTypes = {}; + bidRequest.mediaTypes[type] = {}; + + const request = spec.buildRequests([bidRequest]); + const payload = JSON.parse(request.data); + + expect(payload.tags[0].ad_types).to.deep.equal([type]); + }); + }); + + it('should populate the ad_types array on outstream requests', function () { + const bidRequest = Object.assign({}, bidRequests[0]); + bidRequest.mediaTypes = {}; + bidRequest.mediaTypes.video = {context: 'outstream'}; + + const request = spec.buildRequests([bidRequest]); + const payload = JSON.parse(request.data); + + expect(payload.tags[0].ad_types).to.deep.equal(['video']); + }); + + it('sends bid request to ENDPOINT via POST', function () { + const request = spec.buildRequests(bidRequests); + expect(request.url).to.equal(ENDPOINT + utils.getTopWindowUrl()); + expect(request.method).to.equal('POST'); + }); + + it('should attach valid video params to the tag', function () { + let bidRequest = Object.assign({}, + bidRequests[0], + { + params: { + zoneId: '584072408', + video: { + id: 123, + minduration: 100, + foobar: 'invalid' + } + } + } + ); + + const request = spec.buildRequests([bidRequest]); + const payload = JSON.parse(request.data); + expect(payload.tags[0].video).to.deep.equal({ + id: 123, + minduration: 100 + }); + }); + + it('sets minimum native asset params when not provided on adunit', function () { + let bidRequest = Object.assign({}, + bidRequests[0], + { + mediaType: 'native', + nativeParams: { + image: {required: true}, + } + } + ); + + const request = spec.buildRequests([bidRequest]); + const payload = JSON.parse(request.data); + + expect(payload.tags[0].native.layouts[0]).to.deep.equal({ + main_image: {required: true, sizes: [{}]}, + }); + }); + + it('does not overwrite native ad unit params with mimimum params', function () { + let bidRequest = Object.assign({}, + bidRequests[0], + { + mediaType: 'native', + nativeParams: { + image: { + aspect_ratios: [{ + min_width: 100, + ratio_width: 2, + ratio_height: 3, + }] + } + } + } + ); + + const request = spec.buildRequests([bidRequest]); + const payload = JSON.parse(request.data); + + expect(payload.tags[0].native.layouts[0]).to.deep.equal({ + main_image: { + required: true, + aspect_ratios: [{ + min_width: 100, + ratio_width: 2, + ratio_height: 3, + }] + }, + }); + }); + + it('should convert keyword params to proper form and attaches to request', function () { + let bidRequest = Object.assign({}, + bidRequests[0], + { + params: { + zoneId: '584072408', + keywords: { + single: 'val', + singleArr: ['val'], + singleArrNum: [5], + multiValMixed: ['value1', 2, 'value3'], + singleValNum: 123, + badValue: {'foo': 'bar'} // should be dropped + } + } + } + ); + + const request = spec.buildRequests([bidRequest]); + const payload = JSON.parse(request.data); + + expect(payload.tags[0].keywords).to.deep.equal([{ + 'key': 'single', + 'value': ['val'] + }, { + 'key': 'singleArr', + 'value': ['val'] + }, { + 'key': 'singleArrNum', + 'value': ['5'] + }, { + 'key': 'multiValMixed', + 'value': ['value1', '2', 'value3'] + }, { + 'key': 'singleValNum', + 'value': ['123'] + }]); + }); + + it('should add payment rules to the request', function () { + let bidRequest = Object.assign({}, + bidRequests[0], + { + params: { + zoneId: '584072408', + usePaymentRule: true + } + } + ); + + const request = spec.buildRequests([bidRequest]); + const payload = JSON.parse(request.data); + + expect(payload.tags[0].use_pmt_rule).to.equal(true); + }); + }) + + describe('interpretResponse', function () { + let response = { + 'version': '3.0.0', + 'tags': [ + { + 'uuid': '3db3773286ee59', + 'creative_id': '584944065', + 'height': 600, + 'width': 300, + 'zoneId': '584072408', + 'adUrl': '//d.admp.io/pbc/v1/cache-banner/f7aca005-8171-4299-90bf-0750a864a61c', + 'cpm': 0.5 + } + ] + }; + + it('should get correct bid response', function () { + let expectedResponse = [ + { + 'requestId': '3db3773286ee59', + 'cpm': 0.5, + 'creativeId': 29681110, + 'currency': 'USD', + 'netRevenue': true, + 'ttl': 300, + 'width': 300, + 'height': 250, + 'ad': '', + 'mediaType': 'banner' + } + ]; + let bidderRequest; + let result = spec.interpretResponse({ body: response }, {bidderRequest}); + expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])); + }); + + it('handles nobid responses', function () { + let response = { + 'version': '0.0.1', + 'tags': [{ + 'uuid': '84ab500420319d', + 'tag_id': 5976557, + 'auction_id': '297492697822162468', + 'nobid': true + }] + }; + let bidderRequest; + + let result = spec.interpretResponse({ body: response }, {bidderRequest}); + expect(result.length).to.equal(0); + }); + }); +}); diff --git a/test/spec/modules/gjirafaBidAdapter_spec.js b/test/spec/modules/gjirafaBidAdapter_spec.js index 542e8185db5..d3aaf9765b2 100644 --- a/test/spec/modules/gjirafaBidAdapter_spec.js +++ b/test/spec/modules/gjirafaBidAdapter_spec.js @@ -1,9 +1,9 @@ import { expect } from 'chai'; import { spec } from 'modules/gjirafaBidAdapter'; -describe('gjirafaAdapterTest', () => { - describe('bidRequestValidity', () => { - it('bidRequest with placementId, minCPM and minCPC params', () => { +describe('gjirafaAdapterTest', function () { + describe('bidRequestValidity', function () { + it('bidRequest with placementId, minCPM and minCPC params', function () { expect(spec.isBidRequestValid({ bidder: 'gjirafa', params: { @@ -14,7 +14,7 @@ describe('gjirafaAdapterTest', () => { })).to.equal(true); }); - it('bidRequest with only placementId param', () => { + it('bidRequest with only placementId param', function () { expect(spec.isBidRequestValid({ bidder: 'gjirafa', params: { @@ -23,7 +23,7 @@ describe('gjirafaAdapterTest', () => { })).to.equal(true); }); - it('bidRequest with minCPM and minCPC params', () => { + it('bidRequest with minCPM and minCPC params', function () { expect(spec.isBidRequestValid({ bidder: 'gjirafa', params: { @@ -33,7 +33,7 @@ describe('gjirafaAdapterTest', () => { })).to.equal(true); }); - it('bidRequest with no placementId, minCPM or minCPC params', () => { + it('bidRequest with no placementId, minCPM or minCPC params', function () { expect(spec.isBidRequestValid({ bidder: 'gjirafa', params: { @@ -42,7 +42,7 @@ describe('gjirafaAdapterTest', () => { }); }); - describe('bidRequest', () => { + describe('bidRequest', function () { const bidRequests = [{ 'bidder': 'gjirafa', 'params': { @@ -74,14 +74,14 @@ describe('gjirafaAdapterTest', () => { 'consent_required': 'true' }]; - it('bidRequest HTTP method', () => { + it('bidRequest HTTP method', function () { const requests = spec.buildRequests(bidRequests); requests.forEach(function(requestItem) { expect(requestItem.method).to.equal('GET'); }); }); - it('bidRequest url', () => { + it('bidRequest url', function () { const endpointUrl = 'https://gjc.gjirafa.com/Home/GetBid'; const requests = spec.buildRequests(bidRequests); requests.forEach(function(requestItem) { @@ -89,20 +89,20 @@ describe('gjirafaAdapterTest', () => { }); }); - it('bidRequest data', () => { + it('bidRequest data', function () { const requests = spec.buildRequests(bidRequests); requests.forEach(function(requestItem) { expect(requestItem.data).to.exists; }); }); - it('bidRequest sizes', () => { + it('bidRequest sizes', function () { const requests = spec.buildRequests(bidRequests); expect(requests[0].data.sizes).to.equal('728x90;980x200;980x150;970x90;970x250'); expect(requests[1].data.sizes).to.equal('300x250'); }); - it('should add GDPR data', () => { + it('should add GDPR data', function () { const requests = spec.buildRequests(bidRequests); expect(requests[0].data.consent_string).to.exists; expect(requests[0].data.consent_required).to.exists; @@ -111,7 +111,7 @@ describe('gjirafaAdapterTest', () => { }); }); - describe('interpretResponse', () => { + describe('interpretResponse', function () { const bidRequest = { 'method': 'GET', 'url': 'https://gjc.gjirafa.com/Home/GetBid', @@ -143,7 +143,7 @@ describe('gjirafaAdapterTest', () => { headers: {} }; - it('all keys present', () => { + it('all keys present', function () { const result = spec.interpretResponse(bidResponse, bidRequest); let keys = [ diff --git a/test/spec/modules/googleAnalyticsAdapter_spec.js b/test/spec/modules/googleAnalyticsAdapter_spec.js index 4260a831cad..20517f4138d 100644 --- a/test/spec/modules/googleAnalyticsAdapter_spec.js +++ b/test/spec/modules/googleAnalyticsAdapter_spec.js @@ -1,5 +1,6 @@ +import ga from 'modules/googleAnalyticsAdapter'; + var assert = require('assert'); -var ga = require('modules/googleAnalyticsAdapter'); describe('Ga', function () { describe('enableAnalytics', function () { diff --git a/test/spec/modules/gridBidAdapter_spec.js b/test/spec/modules/gridBidAdapter_spec.js new file mode 100644 index 00000000000..f4401dfe677 --- /dev/null +++ b/test/spec/modules/gridBidAdapter_spec.js @@ -0,0 +1,299 @@ +import { expect } from 'chai'; +import { spec } from 'modules/gridBidAdapter'; +import { newBidder } from 'src/adapters/bidderFactory'; + +describe('TheMediaGrid Adapter', 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('isBidRequestValid', function () { + let bid = { + 'bidder': 'grid', + 'params': { + 'uid': '1' + }, + 'adUnitCode': 'adunit-code', + 'sizes': [[300, 250], [300, 600]], + 'bidId': '30b31c1838de1e', + 'bidderRequestId': '22edbae2733bf6', + 'auctionId': '1d1a030790a475', + }; + + it('should return true when required params found', function () { + expect(spec.isBidRequestValid(bid)).to.equal(true); + }); + + it('should return false when required params are not passed', function () { + let bid = Object.assign({}, bid); + delete bid.params; + bid.params = { + 'uid': 0 + }; + expect(spec.isBidRequestValid(bid)).to.equal(false); + }); + }); + + describe('buildRequests', function () { + function parseRequest(url) { + const res = {}; + url.split('&').forEach((it) => { + const couple = it.split('='); + res[couple[0]] = decodeURIComponent(couple[1]); + }); + return res; + } + let bidRequests = [ + { + 'bidder': 'grid', + 'params': { + 'uid': '1' + }, + 'adUnitCode': 'adunit-code-1', + 'sizes': [[300, 250], [300, 600]], + 'bidId': '30b31c1838de1e', + 'bidderRequestId': '22edbae2733bf6', + 'auctionId': '1d1a030790a475', + }, + { + 'bidder': 'grid', + 'params': { + 'uid': '1' + }, + 'adUnitCode': 'adunit-code-2', + 'sizes': [[728, 90]], + 'bidId': '3150ccb55da321', + 'bidderRequestId': '22edbae2733bf6', + 'auctionId': '1d1a030790a475', + }, + { + 'bidder': 'grid', + 'params': { + 'uid': '2' + }, + 'adUnitCode': 'adunit-code-1', + 'sizes': [[300, 250], [300, 600]], + 'bidId': '42dbe3a7168a6a', + 'bidderRequestId': '22edbae2733bf6', + 'auctionId': '1d1a030790a475', + } + ]; + + it('should attach valid params to the tag', function () { + const request = spec.buildRequests([bidRequests[0]]); + expect(request.data).to.be.an('string'); + const payload = parseRequest(request.data); + expect(payload).to.have.property('u').that.is.a('string'); + expect(payload).to.have.property('auids', '1'); + expect(payload).to.have.property('r', '22edbae2733bf6'); + }); + + it('auids must not be duplicated', function () { + const request = spec.buildRequests(bidRequests); + expect(request.data).to.be.an('string'); + const payload = parseRequest(request.data); + expect(payload).to.have.property('u').that.is.a('string'); + expect(payload).to.have.property('auids', '1,2'); + expect(payload).to.have.property('r', '22edbae2733bf6'); + }); + + it('if gdprConsent is present payload must have gdpr params', function () { + const request = spec.buildRequests(bidRequests, {gdprConsent: {consentString: 'AAA', gdprApplies: true}}); + expect(request.data).to.be.an('string'); + const payload = parseRequest(request.data); + expect(payload).to.have.property('gdpr_consent', 'AAA'); + expect(payload).to.have.property('gdpr_applies', '1'); + }); + + it('if gdprApplies is false gdpr_applies must be 0', function () { + const request = spec.buildRequests(bidRequests, {gdprConsent: {consentString: 'AAA', gdprApplies: false}}); + expect(request.data).to.be.an('string'); + const payload = parseRequest(request.data); + expect(payload).to.have.property('gdpr_consent', 'AAA'); + expect(payload).to.have.property('gdpr_applies', '0'); + }); + + it('if gdprApplies is undefined gdpr_applies must be 1', function () { + const request = spec.buildRequests(bidRequests, {gdprConsent: {consentString: 'AAA'}}); + expect(request.data).to.be.an('string'); + const payload = parseRequest(request.data); + expect(payload).to.have.property('gdpr_consent', 'AAA'); + expect(payload).to.have.property('gdpr_applies', '1'); + }); + }); + + describe('interpretResponse', function () { + const responses = [ + {'bid': [{'price': 1.15, 'adm': '
test content 1
', 'auid': 1, 'h': 250, 'w': 300}], 'seat': '1'}, + {'bid': [{'price': 0.5, 'adm': '
test content 2
', 'auid': 2, 'h': 90, 'w': 728}], 'seat': '1'}, + {'bid': [{'price': 0, 'auid': 3, 'h': 250, 'w': 300}], 'seat': '1'}, + {'bid': [{'price': 0, 'adm': '
test content 4
', 'h': 250, 'w': 300}], 'seat': '1'}, + undefined, + {'bid': [], 'seat': '1'}, + {'seat': '1'}, + ]; + + it('should get correct bid response', function () { + const bidRequests = [ + { + 'bidder': 'grid', + 'params': { + 'uid': '1' + }, + 'adUnitCode': 'adunit-code-1', + 'sizes': [[300, 250], [300, 600]], + 'bidId': '659423fff799cb', + 'bidderRequestId': '5f2009617a7c0a', + 'auctionId': '1cbd2feafe5e8b', + } + ]; + const request = spec.buildRequests(bidRequests); + const expectedResponse = [ + { + 'requestId': '659423fff799cb', + 'cpm': 1.15, + 'creativeId': 1, + 'dealId': undefined, + 'width': 300, + 'height': 250, + 'ad': '
test content 1
', + 'bidderCode': 'grid', + 'currency': 'USD', + 'netRevenue': false, + 'ttl': 360, + } + ]; + + const result = spec.interpretResponse({'body': {'seatbid': [responses[0]]}}, request); + expect(result).to.deep.equal(expectedResponse); + }); + + it('should get correct multi bid response', function () { + const bidRequests = [ + { + 'bidder': 'grid', + 'params': { + 'uid': '1' + }, + 'adUnitCode': 'adunit-code-1', + 'sizes': [[300, 250], [300, 600]], + 'bidId': '300bfeb0d71a5b', + 'bidderRequestId': '2c2bb1972df9a', + 'auctionId': '1fa09aee5c8c99', + }, + { + 'bidder': 'grid', + 'params': { + 'uid': '2' + }, + 'adUnitCode': 'adunit-code-1', + 'sizes': [[300, 250], [300, 600]], + 'bidId': '4dff80cc4ee346', + 'bidderRequestId': '2c2bb1972df9a', + 'auctionId': '1fa09aee5c8c99', + }, + { + 'bidder': 'grid', + 'params': { + 'uid': '1' + }, + 'adUnitCode': 'adunit-code-2', + 'sizes': [[728, 90]], + 'bidId': '5703af74d0472a', + 'bidderRequestId': '2c2bb1972df9a', + 'auctionId': '1fa09aee5c8c99', + } + ]; + const request = spec.buildRequests(bidRequests); + const expectedResponse = [ + { + 'requestId': '300bfeb0d71a5b', + 'cpm': 1.15, + 'creativeId': 1, + 'dealId': undefined, + 'width': 300, + 'height': 250, + 'ad': '
test content 1
', + 'bidderCode': 'grid', + 'currency': 'USD', + 'netRevenue': false, + 'ttl': 360, + }, + { + 'requestId': '5703af74d0472a', + 'cpm': 1.15, + 'creativeId': 1, + 'dealId': undefined, + 'width': 300, + 'height': 250, + 'ad': '
test content 1
', + 'bidderCode': 'grid', + 'currency': 'USD', + 'netRevenue': false, + 'ttl': 360, + }, + { + 'requestId': '4dff80cc4ee346', + 'cpm': 0.5, + 'creativeId': 2, + 'dealId': undefined, + 'width': 728, + 'height': 90, + 'ad': '
test content 2
', + 'bidderCode': 'grid', + 'currency': 'USD', + 'netRevenue': false, + 'ttl': 360, + } + ]; + + const result = spec.interpretResponse({'body': {'seatbid': [responses[0], responses[1]]}}, request); + expect(result).to.deep.equal(expectedResponse); + }); + + it('handles wrong and nobid responses', function () { + const bidRequests = [ + { + 'bidder': 'grid', + 'params': { + 'uid': '3' + }, + 'adUnitCode': 'adunit-code-1', + 'sizes': [[300, 250], [300, 600]], + 'bidId': '300bfeb0d7190gf', + 'bidderRequestId': '2c2bb1972d23af', + 'auctionId': '1fa09aee5c84d34', + }, + { + 'bidder': 'grid', + 'params': { + 'uid': '4' + }, + 'adUnitCode': 'adunit-code-1', + 'sizes': [[300, 250], [300, 600]], + 'bidId': '300bfeb0d71321', + 'bidderRequestId': '2c2bb1972d23af', + 'auctionId': '1fa09aee5c84d34', + }, + { + 'bidder': 'grid', + 'params': { + 'uid': '5' + }, + 'adUnitCode': 'adunit-code-2', + 'sizes': [[728, 90]], + 'bidId': '300bfeb0d7183bb', + 'bidderRequestId': '2c2bb1972d23af', + 'auctionId': '1fa09aee5c84d34', + } + ]; + const request = spec.buildRequests(bidRequests); + const result = spec.interpretResponse({'body': {'seatbid': responses.slice(2)}}, request); + expect(result.length).to.equal(0); + }); + }); +}); diff --git a/test/spec/modules/gumgumBidAdapter_spec.js b/test/spec/modules/gumgumBidAdapter_spec.js index 23ad392ff1b..0c1431b71a5 100644 --- a/test/spec/modules/gumgumBidAdapter_spec.js +++ b/test/spec/modules/gumgumBidAdapter_spec.js @@ -4,16 +4,16 @@ import { spec } from 'modules/gumgumBidAdapter'; const ENDPOINT = 'https://g2.gumgum.com/hbid/imp'; -describe('gumgumAdapter', () => { +describe('gumgumAdapter', function () { const adapter = newBidder(spec); - describe('inherited functions', () => { - it('exists and is a function', () => { + describe('inherited functions', function () { + it('exists and is a function', function () { expect(adapter.callBids).to.exist.and.to.be.a('function'); }); }); - describe('isBidRequestValid', () => { + describe('isBidRequestValid', function () { let bid = { 'bidder': 'gumgum', 'params': { @@ -26,11 +26,11 @@ describe('gumgumAdapter', () => { 'auctionId': '1d1a030790a475', }; - it('should return true when required params found', () => { + it('should return true when required params found', function () { expect(spec.isBidRequestValid(bid)).to.equal(true); }); - it('should return true when required params found', () => { + it('should return true when required params found', function () { let bid = Object.assign({}, bid); delete bid.params; bid.params = { @@ -40,7 +40,7 @@ describe('gumgumAdapter', () => { expect(spec.isBidRequestValid(bid)).to.equal(true); }); - it('should return false when required params are not passed', () => { + it('should return false when required params are not passed', function () { let bid = Object.assign({}, bid); delete bid.params; bid.params = { @@ -50,7 +50,7 @@ describe('gumgumAdapter', () => { }); }); - describe('buildRequests', () => { + describe('buildRequests', function () { let bidRequests = [ { 'bidder': 'gumgum', @@ -63,20 +63,20 @@ describe('gumgumAdapter', () => { } ]; - it('sends bid request to ENDPOINT via GET', () => { + it('sends bid request to ENDPOINT via GET', function () { const request = spec.buildRequests(bidRequests)[0]; expect(request.url).to.equal(ENDPOINT); expect(request.method).to.equal('GET'); expect(request.id).to.equal('30b31c1838de1e'); }); - it('should add consent parameters if gdprConsent is present', () => { + it('should add consent parameters if gdprConsent is present', function () { const gdprConsent = { consentString: 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==', gdprApplies: true }; const fakeBidRequest = { gdprConsent: gdprConsent }; const bidRequest = spec.buildRequests(bidRequests, fakeBidRequest)[0]; expect(bidRequest.data.gdprApplies).to.eq(true); expect(bidRequest.data.gdprConsent).to.eq('BOJ/P2HOJ/P2HABABMAAAAAZ+A=='); }); - it('should handle gdprConsent is present but values are undefined case', () => { + it('should handle gdprConsent is present but values are undefined case', function () { const gdprConsent = { consent_string: undefined, gdprApplies: undefined }; const fakeBidRequest = { gdprConsent: gdprConsent }; const bidRequest = spec.buildRequests(bidRequests, fakeBidRequest)[0]; @@ -84,7 +84,7 @@ describe('gumgumAdapter', () => { }); }) - describe('interpretResponse', () => { + describe('interpretResponse', function () { let serverResponse = { 'ad': { 'id': 29593, @@ -115,7 +115,7 @@ describe('gumgumAdapter', () => { pi: 3 } - it('should get correct bid response', () => { + it('should get correct bid response', function () { let expectedResponse = { 'ad': '

I am an ad

', 'cpm': 0, @@ -132,7 +132,7 @@ describe('gumgumAdapter', () => { expect(spec.interpretResponse({ body: serverResponse }, bidRequest)).to.deep.equal([expectedResponse]); }); - it('handles nobid responses', () => { + it('handles nobid responses', function () { let response = { 'ad': {}, 'pag': { @@ -147,7 +147,7 @@ describe('gumgumAdapter', () => { expect(result.length).to.equal(0); }); - it('returns 1x1 when eligible product and size available', () => { + it('returns 1x1 when eligible product and size available', function () { let inscreenBidRequest = { id: 12346, sizes: [[300, 250], [1, 1]], @@ -184,7 +184,7 @@ describe('gumgumAdapter', () => { expect(result[0].height).to.equal('1'); }) }) - describe('getUserSyncs', () => { + describe('getUserSyncs', function () { const syncOptions = { 'iframeEnabled': 'true' } diff --git a/test/spec/modules/gxoneBidAdapter_spec.js b/test/spec/modules/gxoneBidAdapter_spec.js index f34f4358490..afeb2c781f5 100644 --- a/test/spec/modules/gxoneBidAdapter_spec.js +++ b/test/spec/modules/gxoneBidAdapter_spec.js @@ -5,13 +5,13 @@ import { newBidder } from 'src/adapters/bidderFactory'; describe('GXOne Adapter', function () { const adapter = newBidder(spec); - describe('inherited functions', () => { - it('exists and is a function', () => { + describe('inherited functions', function () { + it('exists and is a function', function () { expect(adapter.callBids).to.exist.and.to.be.a('function'); }); }); - describe('isBidRequestValid', () => { + describe('isBidRequestValid', function () { let bid = { 'bidder': 'gxone', 'params': { @@ -24,11 +24,11 @@ describe('GXOne Adapter', function () { 'auctionId': '1d1a030790a475', }; - it('should return true when required params found', () => { + it('should return true when required params found', function () { expect(spec.isBidRequestValid(bid)).to.equal(true); }); - it('should return false when required params are not passed', () => { + it('should return false when required params are not passed', function () { let bid = Object.assign({}, bid); delete bid.params; bid.params = { @@ -38,7 +38,7 @@ describe('GXOne Adapter', function () { }); }); - describe('buildRequests', () => { + describe('buildRequests', function () { function parseRequest(url) { const res = {}; url.split('&').forEach((it) => { @@ -83,7 +83,7 @@ describe('GXOne Adapter', function () { } ]; - it('should attach valid params to the tag', () => { + it('should attach valid params to the tag', function () { const request = spec.buildRequests([bidRequests[0]]); expect(request.data).to.be.an('string'); const payload = parseRequest(request.data); @@ -92,7 +92,7 @@ describe('GXOne Adapter', function () { expect(payload).to.have.property('auids', '5'); }); - it('auids must not be duplicated', () => { + it('auids must not be duplicated', function () { const request = spec.buildRequests(bidRequests); expect(request.data).to.be.an('string'); const payload = parseRequest(request.data); @@ -101,7 +101,7 @@ describe('GXOne Adapter', function () { expect(payload).to.have.property('auids', '5,6'); }); - it('pt parameter must be "gross" if params.priceType === "gross"', () => { + it('pt parameter must be "gross" if params.priceType === "gross"', function () { bidRequests[1].params.priceType = 'gross'; const request = spec.buildRequests(bidRequests); expect(request.data).to.be.an('string'); @@ -112,7 +112,7 @@ describe('GXOne Adapter', function () { delete bidRequests[1].params.priceType; }); - it('pt parameter must be "net" or "gross"', () => { + it('pt parameter must be "net" or "gross"', function () { bidRequests[1].params.priceType = 'some'; const request = spec.buildRequests(bidRequests); expect(request.data).to.be.an('string'); @@ -124,7 +124,7 @@ describe('GXOne Adapter', function () { }); }); - describe('interpretResponse', () => { + describe('interpretResponse', function () { const responses = [ {'bid': [{'price': 1.15, 'adm': '
test content 1
', 'auid': 4, 'h': 250, 'w': 300}], 'seat': '1'}, {'bid': [{'price': 0.5, 'adm': '
test content 2
', 'auid': 5, 'h': 90, 'w': 728}], 'seat': '1'}, @@ -135,7 +135,7 @@ describe('GXOne Adapter', function () { {'seat': '1'}, ]; - it('should get correct bid response', () => { + it('should get correct bid response', function () { const bidRequests = [ { 'bidder': 'gxone', @@ -169,7 +169,7 @@ describe('GXOne Adapter', function () { expect(result).to.deep.equal(expectedResponse); }); - it('should get correct multi bid response', () => { + it('should get correct multi bid response', function () { const bidRequests = [ { 'bidder': 'gxone', @@ -249,7 +249,7 @@ describe('GXOne Adapter', function () { expect(result).to.deep.equal(expectedResponse); }); - it('handles wrong and nobid responses', () => { + it('handles wrong and nobid responses', function () { const bidRequests = [ { 'bidder': 'gxone', diff --git a/test/spec/modules/huddledmassesBidAdapter_spec.js b/test/spec/modules/huddledmassesBidAdapter_spec.js index f98bc06d0da..7823ae53c12 100644 --- a/test/spec/modules/huddledmassesBidAdapter_spec.js +++ b/test/spec/modules/huddledmassesBidAdapter_spec.js @@ -1,7 +1,7 @@ import {expect} from 'chai'; import {spec} from '../../../modules/huddledmassesBidAdapter'; -describe('HuddledmassesAdapter', () => { +describe('HuddledmassesAdapter', function () { let bid = { bidId: '2dd581a2b6281d', bidder: 'huddledmasses', @@ -15,35 +15,35 @@ describe('HuddledmassesAdapter', () => { transactionId: '3bb2f6da-87a6-4029-aeb0-bfe951372e62' }; - describe('isBidRequestValid', () => { - it('Should return true when placement_id can be cast to a number, and when at least one of the sizes passed is allowed', () => { + describe('isBidRequestValid', function () { + it('Should return true when placement_id can be cast to a number, and when at least one of the sizes passed is allowed', function () { expect(spec.isBidRequestValid(bid)).to.be.true; }); - it('Should return false when placement_id is not a number', () => { + it('Should return false when placement_id is not a number', function () { bid.params.placement_id = 'aaa'; expect(spec.isBidRequestValid(bid)).to.be.false; }); - it('Should return false when the sizes are not allowed', () => { + it('Should return false when the sizes are not allowed', function () { bid.sizes = [[1, 1]]; expect(spec.isBidRequestValid(bid)).to.be.false; }); }); - describe('buildRequests', () => { + describe('buildRequests', function () { let serverRequest = spec.buildRequests([bid]); - it('Creates a ServerRequest object with method, URL and data', () => { + it('Creates a ServerRequest object with method, URL and data', function () { expect(serverRequest).to.exist; expect(serverRequest.method).to.exist; expect(serverRequest.url).to.exist; expect(serverRequest.data).to.exist; }); - it('Returns POST method', () => { + it('Returns POST method', function () { expect(serverRequest.method).to.equal('POST'); }); - it('Returns valid URL', () => { + it('Returns valid URL', function () { expect(serverRequest.url).to.equal('//huddledmassessupply.com/?c=o&m=multi'); }); - it('Returns valid data if array of bids is valid', () => { + it('Returns valid data if array of bids is valid', function () { let data = serverRequest.data; expect(data).to.be.an('object'); expect(data).to.have.all.keys('deviceWidth', 'deviceHeight', 'language', 'secure', 'host', 'page', 'placements'); @@ -62,13 +62,13 @@ describe('HuddledmassesAdapter', () => { expect(placement.sizes).to.be.an('array'); } }); - it('Returns empty data if no valid requests are passed', () => { + it('Returns empty data if no valid requests are passed', function () { serverRequest = spec.buildRequests([]); let data = serverRequest.data; expect(data.placements).to.be.an('array').that.is.empty; }); }); - describe('interpretResponse', () => { + describe('interpretResponse', function () { let resObject = { body: [ { requestId: '123', @@ -83,7 +83,7 @@ describe('HuddledmassesAdapter', () => { } ] }; let serverResponses = spec.interpretResponse(resObject); - it('Returns an array of valid server responses if response object is valid', () => { + it('Returns an array of valid server responses if response object is valid', function () { expect(serverResponses).to.be.an('array').that.is.not.empty; for (let i = 0; i < serverResponses.length; i++) { let dataItem = serverResponses[i]; @@ -99,16 +99,16 @@ describe('HuddledmassesAdapter', () => { expect(dataItem.netRevenue).to.be.a('boolean'); expect(dataItem.currency).to.be.a('string'); } - it('Returns an empty array if invalid response is passed', () => { + it('Returns an empty array if invalid response is passed', function () { serverResponses = spec.interpretResponse('invalid_response'); expect(serverResponses).to.be.an('array').that.is.empty; }); }); }); - describe('getUserSyncs', () => { + describe('getUserSyncs', function () { let userSync = spec.getUserSyncs(); - it('Returns valid URL and type', () => { + it('Returns valid URL and type', function () { expect(userSync).to.be.an('array').with.lengthOf(1); expect(userSync[0].type).to.exist; expect(userSync[0].url).to.exist; diff --git a/test/spec/modules/iasBidAdapter_spec.js b/test/spec/modules/iasBidAdapter_spec.js index 1ee38999f7f..21ef9f8e15a 100644 --- a/test/spec/modules/iasBidAdapter_spec.js +++ b/test/spec/modules/iasBidAdapter_spec.js @@ -1,15 +1,15 @@ import { expect } from 'chai'; import { spec } from 'modules/iasBidAdapter'; -describe('iasBidAdapter is an adapter that', () => { - it('has the correct bidder code', () => { +describe('iasBidAdapter is an adapter that', function () { + it('has the correct bidder code', function () { expect(spec.code).to.equal('ias'); }); - describe('has a method `isBidRequestValid` that', () => { - it('exists', () => { + describe('has a method `isBidRequestValid` that', function () { + it('exists', function () { expect(spec.isBidRequestValid).to.be.a('function'); }); - it('returns false if bid params misses `pubId`', () => { + it('returns false if bid params misses `pubId`', function () { expect(spec.isBidRequestValid( { params: { @@ -17,7 +17,7 @@ describe('iasBidAdapter is an adapter that', () => { } })).to.equal(false); }); - it('returns false if bid params misses `adUnitPath`', () => { + it('returns false if bid params misses `adUnitPath`', function () { expect(spec.isBidRequestValid( { params: { @@ -25,7 +25,7 @@ describe('iasBidAdapter is an adapter that', () => { } })).to.equal(false); }); - it('returns true otherwise', () => { + it('returns true otherwise', function () { expect(spec.isBidRequestValid( { params: { @@ -37,13 +37,13 @@ describe('iasBidAdapter is an adapter that', () => { }); }); - describe('has a method `buildRequests` that', () => { - it('exists', () => { + describe('has a method `buildRequests` that', function () { + it('exists', function () { expect(spec.buildRequests).to.be.a('function'); }); - describe('given bid requests, returns a `ServerRequest` instance that', () => { + describe('given bid requests, returns a `ServerRequest` instance that', function () { let bidRequests, IAS_HOST; - beforeEach(() => { + beforeEach(function () { IAS_HOST = '//pixel.adsafeprotected.com/services/pub'; bidRequests = [ { @@ -79,20 +79,20 @@ describe('iasBidAdapter is an adapter that', () => { } ]; }); - it('has property `method` of `GET`', () => { + it('has property `method` of `GET`', function () { expect(spec.buildRequests(bidRequests)).to.deep.include({ method: 'GET' }); }); - it('has property `url` to be the correct IAS endpoint', () => { + it('has property `url` to be the correct IAS endpoint', function () { expect(spec.buildRequests(bidRequests)).to.deep.include({ url: IAS_HOST }); }); - it('only includes the first `bidRequest` as the bidRequest variable on a multiple slot request', () => { + it('only includes the first `bidRequest` as the bidRequest variable on a multiple slot request', function () { expect(spec.buildRequests(bidRequests).bidRequest.adUnitCode).to.equal(bidRequests[0].adUnitCode); }); - describe('has property `data` that is an encode query string containing information such as', () => { + describe('has property `data` that is an encode query string containing information such as', function () { let val; const ANID_PARAM = 'anId'; const SLOT_PARAM = 'slot'; @@ -100,35 +100,37 @@ describe('iasBidAdapter is an adapter that', () => { const SLOT_SIZE_PARAM = 'ss'; const SLOT_AD_UNIT_PATH_PARAM = 'p'; - beforeEach(() => val = decodeURI(spec.buildRequests(bidRequests).data)); - it('publisher id', () => { + beforeEach(function () { + val = decodeURI(spec.buildRequests(bidRequests).data); + }); + it('publisher id', function () { expect(val).to.have.string(`${ANID_PARAM}=1234`); }); - it('ad slot`s id, size and ad unit path', () => { + it('ad slot`s id, size and ad unit path', function () { expect(val).to.have.string(`${SLOT_PARAM}={${SLOT_ID_PARAM}:one-div-id,${SLOT_SIZE_PARAM}:[10.20,300.400],${SLOT_AD_UNIT_PATH_PARAM}:/a/b/c}`); expect(val).to.have.string(`${SLOT_PARAM}={${SLOT_ID_PARAM}:two-div-id,${SLOT_SIZE_PARAM}:[50.60],${SLOT_AD_UNIT_PATH_PARAM}:/d/e/f}`); }); - it('window size', () => { + it('window size', function () { expect(val).to.match(/.*wr=[0-9]*\.[0-9]*/); }); - it('screen size', () => { + it('screen size', function () { expect(val).to.match(/.*sr=[0-9]*\.[0-9]*/); }); }); - it('has property `bidRequest` that is the first passed in bid request', () => { + it('has property `bidRequest` that is the first passed in bid request', function () { expect(spec.buildRequests(bidRequests)).to.deep.include({ bidRequest: bidRequests[0] }); }); }); }); - describe('has a method `interpretResponse` that', () => { - it('exists', () => { + describe('has a method `interpretResponse` that', function () { + it('exists', function () { expect(spec.interpretResponse).to.be.a('function'); }); - describe('returns a list of bid response that', () => { + describe('returns a list of bid response that', function () { let bidRequests, bidResponse, slots, serverResponse; - beforeEach(() => { + beforeEach(function () { bidRequests = [ { adUnitCode: 'one-div-id', @@ -194,34 +196,34 @@ describe('iasBidAdapter is an adapter that', () => { }; bidResponse = spec.interpretResponse(serverResponse, request); }); - it('has IAS keyword `adt` as property', () => { + it('has IAS keyword `adt` as property', function () { expect(bidResponse[0]).to.deep.include({ adt: 'adtVal' }); }); - it('has IAS keyword `alc` as property', () => { + it('has IAS keyword `alc` as property', function () { expect(bidResponse[0]).to.deep.include({ alc: 'alcVal' }); }); - it('has IAS keyword `dlm` as property', () => { + it('has IAS keyword `dlm` as property', function () { expect(bidResponse[0]).to.deep.include({ dlm: 'dlmVal' }); }); - it('has IAS keyword `drg` as property', () => { + it('has IAS keyword `drg` as property', function () { expect(bidResponse[0]).to.deep.include({ drg: 'drgVal' }); }); - it('has IAS keyword `hat` as property', () => { + it('has IAS keyword `hat` as property', function () { expect(bidResponse[0]).to.deep.include({ hat: 'hatVal' }); }); - it('has IAS keyword `off` as property', () => { + it('has IAS keyword `off` as property', function () { expect(bidResponse[0]).to.deep.include({ off: 'offVal' }); }); - it('has IAS keyword `vio` as property', () => { + it('has IAS keyword `vio` as property', function () { expect(bidResponse[0]).to.deep.include({ vio: 'vioVal' }); }); - it('has IAS keyword `fr` as property', () => { + it('has IAS keyword `fr` as property', function () { expect(bidResponse[0]).to.deep.include({ fr: 'false' }); }); - it('has property `slots`', () => { + it('has property `slots`', function () { expect(bidResponse[0]).to.deep.include({ slots: slots }); }); - it('response is the same for multiple slots', () => { + it('response is the same for multiple slots', function () { var adapter = spec; var requests = adapter.buildRequests(bidRequests); expect(adapter.interpretResponse(serverResponse, requests)).to.length(2); diff --git a/test/spec/modules/improvedigitalBidAdapter_spec.js b/test/spec/modules/improvedigitalBidAdapter_spec.js index d7595934194..8b76bfcbe9c 100644 --- a/test/spec/modules/improvedigitalBidAdapter_spec.js +++ b/test/spec/modules/improvedigitalBidAdapter_spec.js @@ -40,22 +40,22 @@ describe('Improve Digital Adapter Tests', function () { }, }; - describe('isBidRequestValid', () => { - it('should return false when no bid', () => { + describe('isBidRequestValid', function () { + it('should return false when no bid', function () { expect(spec.isBidRequestValid()).to.equal(false); }); - it('should return false when no bid.params', () => { + it('should return false when no bid.params', function () { let bid = {}; expect(spec.isBidRequestValid(bid)).to.equal(false); }); - it('should return false when both placementId and placementKey + publisherId are missing', () => { + it('should return false when both placementId and placementKey + publisherId are missing', function () { let bid = { 'params': {} }; expect(spec.isBidRequestValid(bid)).to.equal(false); }); - it('should return false when only one of placementKey and publisherId is present', () => { + it('should return false when only one of placementKey and publisherId is present', function () { let bid = { params: { publisherId: 1234 @@ -70,19 +70,19 @@ describe('Improve Digital Adapter Tests', function () { expect(spec.isBidRequestValid(bid)).to.equal(false); }); - it('should return true when placementId is passed', () => { + it('should return true when placementId is passed', function () { let bid = { 'params': {} }; expect(spec.isBidRequestValid(simpleBidRequest)).to.equal(true); }); - it('should return true when both placementKey and publisherId are passed', () => { + it('should return true when both placementKey and publisherId are passed', function () { let bid = { 'params': {} }; expect(spec.isBidRequestValid(simpleSmartTagBidRequest)).to.equal(true); }); }); - describe('buildRequests', () => { - it('should make a well-formed request objects', () => { + describe('buildRequests', function () { + it('should make a well-formed request objects', function () { const requests = spec.buildRequests([simpleBidRequest]); expect(requests).to.be.an('array'); expect(requests.length).to.equal(1); @@ -92,7 +92,7 @@ describe('Improve Digital Adapter Tests', function () { expect(request.url).to.equal(URL); expect(request.data.substring(0, PARAM_PREFIX.length)).to.equal(PARAM_PREFIX); - const params = JSON.parse(request.data.substring(PARAM_PREFIX.length)); + const params = JSON.parse(decodeURIComponent(request.data.substring(PARAM_PREFIX.length))); expect(params.bid_request).to.be.an('object'); expect(params.bid_request.id).to.be.a('string'); expect(params.bid_request.version).to.equal(`${spec.version}-${idClient.CONSTANTS.CLIENT_VERSION}`); @@ -106,14 +106,14 @@ describe('Improve Digital Adapter Tests', function () { ]); }); - it('should set placementKey and publisherId for smart tags', () => { + it('should set placementKey and publisherId for smart tags', function () { const requests = spec.buildRequests([simpleSmartTagBidRequest]); - const params = JSON.parse(requests[0].data.substring(PARAM_PREFIX.length)); + const params = JSON.parse(decodeURIComponent(requests[0].data.substring(PARAM_PREFIX.length))); expect(params.bid_request.imp[0].pubid).to.equal(1032); expect(params.bid_request.imp[0].pkey).to.equal('data_team_test_hb_smoke_test'); }); - it('should add keyValues', () => { + it('should add keyValues', function () { let bidRequest = Object.assign({}, simpleBidRequest); const keyValues = { testKey: [ @@ -122,11 +122,11 @@ describe('Improve Digital Adapter Tests', function () { }; bidRequest.params.keyValues = keyValues; const request = spec.buildRequests([bidRequest])[0]; - const params = JSON.parse(request.data.substring(PARAM_PREFIX.length)); + const params = JSON.parse(decodeURIComponent(request.data.substring(PARAM_PREFIX.length))); expect(params.bid_request.imp[0].kvw).to.deep.equal(keyValues); }); - it('should add size', () => { + it('should add size', function () { let bidRequest = Object.assign({}, simpleBidRequest); const size = { w: 800, @@ -134,27 +134,27 @@ describe('Improve Digital Adapter Tests', function () { }; bidRequest.params.size = size; const request = spec.buildRequests([bidRequest])[0]; - const params = JSON.parse(request.data.substring(PARAM_PREFIX.length)); + const params = JSON.parse(decodeURIComponent(request.data.substring(PARAM_PREFIX.length))); expect(params.bid_request.imp[0].banner).to.deep.equal(size); }); - it('should add currency', () => { + it('should add currency', function () { const bidRequest = Object.assign({}, simpleBidRequest); const getConfigStub = sinon.stub(config, 'getConfig').returns('JPY'); const request = spec.buildRequests([bidRequest])[0]; - const params = JSON.parse(request.data.substring(PARAM_PREFIX.length)); + const params = JSON.parse(decodeURIComponent(request.data.substring(PARAM_PREFIX.length))); expect(params.bid_request.imp[0].currency).to.equal('JPY'); getConfigStub.restore(); }); - it('should add GDPR consent string', () => { + it('should add GDPR consent string', function () { const bidRequest = Object.assign({}, simpleBidRequest); const request = spec.buildRequests([bidRequest], bidderRequest)[0]; - const params = JSON.parse(request.data.substring(PARAM_PREFIX.length)); + const params = JSON.parse(decodeURIComponent(request.data.substring(PARAM_PREFIX.length))); expect(params.bid_request.gdpr).to.equal('BOJ/P2HOJ/P2HABABMAAAAAZ+A=='); }); - it('should return 2 requests', () => { + it('should return 2 requests', function () { const requests = spec.buildRequests([ simpleBidRequest, simpleSmartTagBidRequest @@ -162,63 +162,169 @@ describe('Improve Digital Adapter Tests', function () { expect(requests).to.be.an('array'); expect(requests.length).to.equal(2); }); + + it('should return one request in a single request mode', function () { + const getConfigStub = sinon.stub(config, 'getConfig'); + getConfigStub.withArgs('improvedigital.singleRequest').returns(true); + const requests = spec.buildRequests([ + simpleBidRequest, + simpleSmartTagBidRequest + ]); + expect(requests).to.be.an('array'); + expect(requests.length).to.equal(1); + getConfigStub.restore(); + }); }); - describe('interpretResponse', () => { - const serverResponse = { - 'body': { - 'id': '687a06c541d8d1', - 'site_id': 191642, - 'bid': [ - { - 'isNet': false, - 'id': '33e9500b21129f', - 'advid': '5279', - 'price': 1.45888594164456, - 'nurl': 'http://ad.360yield.com/imp_pixel?ic=wVmhKI07hCVyGC1sNdFp.6buOSiGYOw8jPyZLlcMY2RCwD4ek3Fy6.xUI7U002skGBs3objMBoNU-Frpvmb9js3NKIG0YZJgWaNdcpXY9gOXE9hY4-wxybCjVSNzhOQB-zic73hzcnJnKeoGgcfvt8fMy18-yD0aVdYWt4zbqdoITOkKNCPBEgbPFu1rcje-o7a64yZ7H3dKvtnIixXQYc1Ep86xGSBGXY6xW2KfUOMT6vnkemxO72divMkMdhR8cAuqIubbx-ZID8-xf5c9k7p6DseeBW0I8ionrlTHx.rGosgxhiFaMqtr7HiA7PBzKvPdeEYN0hQ8RYo8JzYL82hA91A3V2m9Ij6y0DfIJnnrKN8YORffhxmJ6DzwEl1zjrVFbD01bqB3Vdww8w8PQJSkKQkd313tr-atU8LS26fnBmOngEkVHwAr2WCKxuUvxHmuVBTA-Lgz7wKwMoOJCA3hFxMavVb0ZFB7CK0BUTVU6z0De92Q.FJKNCHLMbjX3vcAQ90=', - 'h': 290, - 'pid': 1053688, - 'sync': [ - 'http://link1', - 'http://link2' + const serverResponse = { + 'body': { + 'id': '687a06c541d8d1', + 'site_id': 191642, + 'bid': [ + { + 'isNet': false, + 'id': '33e9500b21129f', + 'advid': '5279', + 'price': 1.45888594164456, + 'nurl': 'http://ad.360yield.com/imp_pixel?ic=wVmhKI07hCVyGC1sNdFp.6buOSiGYOw8jPyZLlcMY2RCwD4ek3Fy6.xUI7U002skGBs3objMBoNU-Frpvmb9js3NKIG0YZJgWaNdcpXY9gOXE9hY4-wxybCjVSNzhOQB-zic73hzcnJnKeoGgcfvt8fMy18-yD0aVdYWt4zbqdoITOkKNCPBEgbPFu1rcje-o7a64yZ7H3dKvtnIixXQYc1Ep86xGSBGXY6xW2KfUOMT6vnkemxO72divMkMdhR8cAuqIubbx-ZID8-xf5c9k7p6DseeBW0I8ionrlTHx.rGosgxhiFaMqtr7HiA7PBzKvPdeEYN0hQ8RYo8JzYL82hA91A3V2m9Ij6y0DfIJnnrKN8YORffhxmJ6DzwEl1zjrVFbD01bqB3Vdww8w8PQJSkKQkd313tr-atU8LS26fnBmOngEkVHwAr2WCKxuUvxHmuVBTA-Lgz7wKwMoOJCA3hFxMavVb0ZFB7CK0BUTVU6z0De92Q.FJKNCHLMbjX3vcAQ90=', + 'h': 290, + 'pid': 1053688, + 'sync': [ + 'http://link1', + 'http://link2' + ], + 'crid': '422031', + 'w': 600, + 'cid': '99006', + 'adm': 'document.writeln(\"
\\\"\\\"\\/<\\/a>\");document.writeln(\"<\\/improvedigital_ad_output_information>\");' + } + ], + 'debug': '' + } + }; + + const serverResponseTwoBids = { + 'body': { + 'id': '687a06c541d8d1', + 'site_id': 191642, + 'bid': [ + serverResponse.body.bid[0], + { + 'isNet': true, + 'id': '1234', + 'advid': '5280', + 'price': 1.23, + 'nurl': 'http://link/imp_pixel?ic=wVmhKI07hCVyGC1sNdFp.6buOSiGYOw8jPyZLlcMY2RCwD4ek3Fy6.xUI7U002skGBs3objMBoNU-Frpvmb9js3NKIG0YZJgWaNdcpXY9gOXE9hY4-wxybCjVSNzhOQB-zic73hzcnJnKeoGgcfvt8fMy18-yD0aVdYWt4zbqdoITOkKNCPBEgbPFu1rcje-o7a64yZ7H3dKvtnIixXQYc1Ep86xGSBGXY6xW2KfUOMT6vnkemxO72divMkMdhR8cAuqIubbx-ZID8-xf5c9k7p6DseeBW0I8ionrlTHx.rGosgxhiFaMqtr7HiA7PBzKvPdeEYN0hQ8RYo8JzYL82hA91A3V2m9Ij6y0DfIJnnrKN8YORffhxmJ6DzwEl1zjrVFbD01bqB3Vdww8w8PQJSkKQkd313tr-atU8LS26fnBmOngEkVHwAr2WCKxuUvxHmuVBTA-Lgz7wKwMoOJCA3hFxMavVb0ZFB7CK0BUTVU6z0De92Q.FJKNCHLMbjX3vcAQ90=', + 'h': 400, + 'pid': 1053688, + 'sync': [ + 'http://link3' + ], + 'crid': '422033', + 'w': 700, + 'cid': '99006', + 'adm': 'document.writeln(\"\\\"\\\"\\/<\\/a>\");document.writeln(\"<\\/improvedigital_ad_output_information>\");' + } + ], + 'debug': '' + } + }; + + const serverResponseNative = { + body: { + id: '687a06c541d8d1', + site_id: 191642, + bid: [ + { + isNet: false, + id: '33e9500b21129f', + advid: '5279', + price: 1.45888594164456, + nurl: 'http://ad.360yield.com/imp_pixel?ic=wVm', + h: 290, + pid: 1053688, + sync: [ + 'http://link1', + 'http://link2' + ], + crid: '422031', + w: 600, + cid: '99006', + native: { + assets: [ + { + title: { + text: 'Native title' + } + }, + { + data: { + type: 1, + value: 'Improve Digital' + } + }, + { + data: { + type: 2, + value: 'Native body' + } + }, + { + data: { + type: 3, + value: 'Should get ignored' + } + }, + { + data: { + type: 12, + value: 'Do it' + } + }, + { + img: { + type: 1, + url: 'Should get ignored', + h: 300, + w: 400 + } + }, + { + img: { + type: 2, + url: 'http://blah.com/icon.jpg', + h: 30, + w: 40 + } + }, + { + img: { + type: 3, + url: 'http://blah.com/image.jpg', + h: 200, + w: 800 + } + } ], - 'crid': '422031', - 'w': 600, - 'cid': '99006', - 'adm': 'document.writeln(\"\\\"\\\"\\/<\\/a>\");document.writeln(\"<\\/improvedigital_ad_output_information>\");' - } - ], - 'debug': '' - } - }; - - const serverResponseTwoBids = { - 'body': { - 'id': '687a06c541d8d1', - 'site_id': 191642, - 'bid': [ - serverResponse.body.bid[0], - { - 'isNet': true, - 'id': '1234', - 'advid': '5280', - 'price': 1.23, - 'nurl': 'http://link/imp_pixel?ic=wVmhKI07hCVyGC1sNdFp.6buOSiGYOw8jPyZLlcMY2RCwD4ek3Fy6.xUI7U002skGBs3objMBoNU-Frpvmb9js3NKIG0YZJgWaNdcpXY9gOXE9hY4-wxybCjVSNzhOQB-zic73hzcnJnKeoGgcfvt8fMy18-yD0aVdYWt4zbqdoITOkKNCPBEgbPFu1rcje-o7a64yZ7H3dKvtnIixXQYc1Ep86xGSBGXY6xW2KfUOMT6vnkemxO72divMkMdhR8cAuqIubbx-ZID8-xf5c9k7p6DseeBW0I8ionrlTHx.rGosgxhiFaMqtr7HiA7PBzKvPdeEYN0hQ8RYo8JzYL82hA91A3V2m9Ij6y0DfIJnnrKN8YORffhxmJ6DzwEl1zjrVFbD01bqB3Vdww8w8PQJSkKQkd313tr-atU8LS26fnBmOngEkVHwAr2WCKxuUvxHmuVBTA-Lgz7wKwMoOJCA3hFxMavVb0ZFB7CK0BUTVU6z0De92Q.FJKNCHLMbjX3vcAQ90=', - 'h': 400, - 'pid': 1053688, - 'sync': [ - 'http://link3' + link: { + url: 'http://advertiser.com', + clicktrackers: [ + 'http://click.tracker.com/click?impid=123' + ] + }, + imptrackers: [ + 'http://imptrack1.com', + 'http://imptrack2.com' ], - 'crid': '422033', - 'w': 700, - 'cid': '99006', - 'adm': 'document.writeln(\"\\\"\\\"\\/<\\/a>\");document.writeln(\"<\\/improvedigital_ad_output_information>\");' + jstracker: '' } - ], - 'debug': '' - } - }; + } + ], + debug: '' + } + }; + describe('interpretResponse', function () { let expectedBid = [ { 'ad': '', @@ -227,6 +333,7 @@ describe('Improve Digital Adapter Tests', function () { 'cpm': 1.45888594164456, 'currency': 'USD', 'height': 290, + 'mediaType': 'banner', 'netRevenue': false, 'requestId': '33e9500b21129f', 'ttl': 300, @@ -243,6 +350,7 @@ describe('Improve Digital Adapter Tests', function () { 'cpm': 1.23, 'currency': 'USD', 'height': 400, + 'mediaType': 'banner', 'netRevenue': true, 'requestId': '1234', 'ttl': 300, @@ -250,51 +358,103 @@ describe('Improve Digital Adapter Tests', function () { } ]; - it('should return a well-formed bid', () => { + let expectedBidNative = [ + { + mediaType: 'native', + adId: '33e9500b21129f', + creativeId: '422031', + cpm: 1.45888594164456, + currency: 'USD', + height: 290, + netRevenue: false, + requestId: '33e9500b21129f', + ttl: 300, + width: 600, + native: { + title: 'Native title', + body: 'Native body', + cta: 'Do it', + sponsoredBy: 'Improve Digital', + icon: { + url: 'http://blah.com/icon.jpg', + height: 30, + width: 40 + }, + image: { + url: 'http://blah.com/image.jpg', + height: 200, + width: 800 + }, + clickUrl: 'http://advertiser.com', + clickTrackers: ['http://click.tracker.com/click?impid=123'], + impressionTrackers: [ + 'http://ad.360yield.com/imp_pixel?ic=wVm', + 'http://imptrack1.com', + 'http://imptrack2.com' + ], + javascriptTrackers: '' + } + } + ]; + + it('should return a well-formed bid', function () { const bids = spec.interpretResponse(serverResponse); expect(bids).to.deep.equal(expectedBid); }); - it('should return two bids', () => { + it('should return two bids', function () { const bids = spec.interpretResponse(serverResponseTwoBids); expect(bids).to.deep.equal(expectedTwoBids); }); - it('should register user syncs', () => { - const registerSyncSpy = sinon.spy(userSync, 'registerSync'); - const bids = spec.interpretResponse(serverResponse); - expect(registerSyncSpy.withArgs('image', 'improvedigital', 'http://link1').calledOnce).to.equal(true); - expect(registerSyncSpy.withArgs('image', 'improvedigital', 'http://link2').calledOnce).to.equal(true); - registerSyncSpy.restore(); - }); - - it('should set dealId correctly', () => { + it('should set dealId correctly', function () { let response = JSON.parse(JSON.stringify(serverResponse)); let bids; - response.body.bid[0].lid = 'xyz'; + delete response.body.bid[0].lid; + response.body.bid[0].buying_type = 'deal_id'; bids = spec.interpretResponse(response); expect(bids[0].dealId).to.not.exist; response.body.bid[0].lid = 268515; + delete response.body.bid[0].buying_type; bids = spec.interpretResponse(response); - expect(bids[0].dealId).to.equal(268515); + expect(bids[0].dealId).to.not.exist; - response.body.bid[0].lid = { - 1: 268515 - }; + response.body.bid[0].lid = 268515; + response.body.bid[0].buying_type = 'classic'; + bids = spec.interpretResponse(response); + expect(bids[0].dealId).to.not.exist; + + response.body.bid[0].lid = 268515; + response.body.bid[0].buying_type = 'deal_id'; bids = spec.interpretResponse(response); expect(bids[0].dealId).to.equal(268515); + + response.body.bid[0].lid = [ 268515, 12456, 34567 ]; + response.body.bid[0].buying_type = 'deal_id'; + bids = spec.interpretResponse(response); + expect(bids[0].dealId).to.not.exist; + + response.body.bid[0].lid = [ 268515, 12456, 34567 ]; + response.body.bid[0].buying_type = [ 'deal_id', 'classic' ]; + bids = spec.interpretResponse(response); + expect(bids[0].dealId).to.not.exist; + + response.body.bid[0].lid = [ 268515, 12456, 34567 ]; + response.body.bid[0].buying_type = [ 'classic', 'deal_id', 'deal_id' ]; + bids = spec.interpretResponse(response); + expect(bids[0].dealId).to.equal(12456); }); - it('should set currency', () => { + it('should set currency', function () { let response = JSON.parse(JSON.stringify(serverResponse)); response.body.bid[0].currency = 'eur'; const bids = spec.interpretResponse(response); expect(bids[0].currency).to.equal('EUR'); }); - it('should return empty array for bad response or no price', () => { + it('should return empty array for bad response or no price', function () { let response = JSON.parse(JSON.stringify(serverResponse)); let bids; @@ -315,7 +475,7 @@ describe('Improve Digital Adapter Tests', function () { bids = spec.interpretResponse(response); expect(bids).to.deep.equal([]); - // Adm missing or bad + // adm and native missing response = JSON.parse(JSON.stringify(serverResponse)); delete response.body.bid[0].adm; bids = spec.interpretResponse(response); @@ -323,19 +483,38 @@ describe('Improve Digital Adapter Tests', function () { response.body.bid[0].adm = null; bids = spec.interpretResponse(response); expect(bids).to.deep.equal([]); - response.body.bid[0].adm = 1234; - bids = spec.interpretResponse(response); - expect(bids).to.deep.equal([]); - response.body.bid[0].adm = {}; - bids = spec.interpretResponse(response); - expect(bids).to.deep.equal([]); }); - it('should set netRevenue', () => { + it('should set netRevenue', function () { let response = JSON.parse(JSON.stringify(serverResponse)); response.body.bid[0].isNet = true; const bids = spec.interpretResponse(response); expect(bids[0].netRevenue).to.equal(true); }); + + // Native ads + it('should return a well-formed native ad bid', function () { + const bids = spec.interpretResponse(serverResponseNative); + expect(bids).to.deep.equal(expectedBidNative); + }); + }); + + describe('getUserSyncs', function () { + const serverResponses = [ serverResponseTwoBids ]; + + it('should return no syncs when pixel syncing is disabled', function () { + const syncs = spec.getUserSyncs({ pixelEnabled: false }, serverResponses); + expect(syncs).to.deep.equal([]); + }); + + it('should return user syncs', function () { + const syncs = spec.getUserSyncs({ pixelEnabled: true }, serverResponses); + const expected = [ + { type: 'image', url: 'http://link1' }, + { type: 'image', url: 'http://link2' }, + { type: 'image', url: 'http://link3' } + ]; + expect(syncs).to.deep.equal(expected); + }); }); }); diff --git a/test/spec/modules/innityBidAdapter_spec.js b/test/spec/modules/innityBidAdapter_spec.js index 87042ca6a6d..0132f093ca1 100644 --- a/test/spec/modules/innityBidAdapter_spec.js +++ b/test/spec/modules/innityBidAdapter_spec.js @@ -1,9 +1,9 @@ import { expect } from 'chai'; import { spec } from 'modules/innityBidAdapter'; -describe('innityAdapterTest', () => { - describe('bidRequestValidity', () => { - it('bidRequest with pub ID and zone ID param', () => { +describe('innityAdapterTest', function () { + describe('bidRequestValidity', function () { + it('bidRequest with pub ID and zone ID param', function () { expect(spec.isBidRequestValid({ bidder: 'innity', params: { @@ -13,7 +13,7 @@ describe('innityAdapterTest', () => { })).to.equal(true); }); - it('bidRequest with no required params', () => { + it('bidRequest with no required params', function () { expect(spec.isBidRequestValid({ bidder: 'innity', params: { @@ -22,7 +22,7 @@ describe('innityAdapterTest', () => { }); }); - describe('bidRequest', () => { + describe('bidRequest', function () { const bidRequests = [{ 'bidder': 'innity', 'params': { @@ -37,14 +37,14 @@ describe('innityAdapterTest', () => { 'auctionId': '18fd8b8b0bd757' }]; - it('bidRequest HTTP method', () => { + it('bidRequest HTTP method', function () { const requests = spec.buildRequests(bidRequests); requests.forEach(function(requestItem) { expect(requestItem.method).to.equal('GET'); }); }); - it('bidRequest data', () => { + it('bidRequest data', function () { const requests = spec.buildRequests(bidRequests); expect(requests[0].data.pub).to.equal(267); expect(requests[0].data.zone).to.equal(62546); @@ -54,7 +54,7 @@ describe('innityAdapterTest', () => { }); }); - describe('interpretResponse', () => { + describe('interpretResponse', function () { const bidRequest = { 'method': 'GET', 'url': 'https://as.innity.com/synd/?', @@ -85,7 +85,7 @@ describe('innityAdapterTest', () => { headers: {} }; - it('result is correct', () => { + it('result is correct', function () { const result = spec.interpretResponse(bidResponse, bidRequest); expect(result[0].requestId).to.equal('51ef8751f9aead'); expect(result[0].cpm).to.equal(1); diff --git a/test/spec/modules/inskinBidAdapter_spec.js b/test/spec/modules/inskinBidAdapter_spec.js index 40a84525ffa..8a62a465a5b 100644 --- a/test/spec/modules/inskinBidAdapter_spec.js +++ b/test/spec/modules/inskinBidAdapter_spec.js @@ -1,7 +1,6 @@ import { expect } from 'chai'; import { spec } from 'modules/inskinBidAdapter'; - -var bidFactory = require('src/bidfactory.js'); +import { createBid } from 'src/bidfactory'; const ENDPOINT = 'https://mfad.inskinad.com/api/v2'; @@ -99,11 +98,11 @@ const RESPONSE = { } }; -describe('InSkin BidAdapter', () => { +describe('InSkin BidAdapter', function () { let bidRequests; let adapter = spec; - beforeEach(() => { + beforeEach(function () { bidRequests = [ { bidder: 'inskin', @@ -121,8 +120,8 @@ describe('InSkin BidAdapter', () => { ]; }); - describe('bid request validation', () => { - it('should accept valid bid requests', () => { + describe('bid request validation', function () { + it('should accept valid bid requests', function () { let bid = { bidder: 'inskin', params: { @@ -133,7 +132,7 @@ describe('InSkin BidAdapter', () => { expect(spec.isBidRequestValid(bid)).to.equal(true); }); - it('should accept valid bid requests with extra fields', () => { + it('should accept valid bid requests with extra fields', function () { let bid = { bidder: 'inskin', params: { @@ -145,7 +144,7 @@ describe('InSkin BidAdapter', () => { expect(spec.isBidRequestValid(bid)).to.equal(true); }); - it('should reject bid requests without siteId', () => { + it('should reject bid requests without siteId', function () { let bid = { bidder: 'inskin', params: { @@ -155,7 +154,7 @@ describe('InSkin BidAdapter', () => { expect(spec.isBidRequestValid(bid)).to.equal(false); }); - it('should reject bid requests without networkId', () => { + it('should reject bid requests without networkId', function () { let bid = { bidder: 'inskin', params: { @@ -166,31 +165,31 @@ describe('InSkin BidAdapter', () => { }); }); - describe('buildRequests validation', () => { - it('creates request data', () => { + describe('buildRequests validation', function () { + it('creates request data', function () { let request = spec.buildRequests(bidRequests); expect(request).to.exist.and.to.be.a('object'); }); - it('request to inskin should contain a url', () => { + it('request to inskin should contain a url', function () { let request = spec.buildRequests(bidRequests); expect(request.url).to.have.string('inskinad.com'); }); - it('requires valid bids to make request', () => { + it('requires valid bids to make request', function () { let request = spec.buildRequests([]); expect(request.bidRequest).to.be.empty; }); - it('sends bid request to ENDPOINT via POST', () => { + it('sends bid request to ENDPOINT via POST', function () { let request = spec.buildRequests(bidRequests); expect(request.method).to.have.string('POST'); }); - it('should add gdpr consent information to the request', () => { + it('should add gdpr consent information to the request', function () { let consentString = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A=='; let bidderRequest = { 'bidderCode': 'inskin', @@ -210,21 +209,21 @@ describe('InSkin BidAdapter', () => { expect(payload.consent.gdprConsentRequired).to.exist.and.to.be.true; }); }); - describe('interpretResponse validation', () => { - it('response should have valid bidderCode', () => { + describe('interpretResponse validation', function () { + it('response should have valid bidderCode', function () { let bidRequest = spec.buildRequests(REQUEST.bidRequest); - let bid = bidFactory.createBid(1, bidRequest.bidRequest[0]); + let bid = createBid(1, bidRequest.bidRequest[0]); expect(bid.bidderCode).to.equal('inskin'); }); - it('response should include objects for all bids', () => { + it('response should include objects for all bids', function () { let bids = spec.interpretResponse(RESPONSE, REQUEST); expect(bids.length).to.equal(2); }); - it('registers bids', () => { + it('registers bids', function () { let bids = spec.interpretResponse(RESPONSE, REQUEST); bids.forEach(b => { expect(b).to.have.property('cpm'); @@ -242,34 +241,34 @@ describe('InSkin BidAdapter', () => { }); }); - it('handles nobid responses', () => { + it('handles nobid responses', function () { let EMPTY_RESP = Object.assign({}, RESPONSE, {'body': {'decisions': null}}) let bids = spec.interpretResponse(EMPTY_RESP, REQUEST); expect(bids).to.be.empty; }); - it('handles no server response', () => { + it('handles no server response', function () { let bids = spec.interpretResponse(null, REQUEST); expect(bids).to.be.empty; }); }); - describe('getUserSyncs', () => { - it('handles empty sync options', () => { + describe('getUserSyncs', function () { + it('handles empty sync options', function () { let opts = spec.getUserSyncs({}); expect(opts).to.be.empty; }); - it('should return two sync urls if pixel syncs are enabled', () => { + it('should return two sync urls if pixel syncs are enabled', function () { let syncOptions = {'pixelEnabled': true}; let opts = spec.getUserSyncs(syncOptions); expect(opts.length).to.equal(2); }); - it('should return three sync urls if pixel and iframe syncs are enabled', () => { + it('should return three sync urls if pixel and iframe syncs are enabled', function () { let syncOptions = {'iframeEnabled': true, 'pixelEnabled': true}; let opts = spec.getUserSyncs(syncOptions); diff --git a/test/spec/modules/interactiveOffersBidAdapter_spec.js b/test/spec/modules/interactiveOffersBidAdapter_spec.js index 6cf09cf6149..8921a302738 100644 --- a/test/spec/modules/interactiveOffersBidAdapter_spec.js +++ b/test/spec/modules/interactiveOffersBidAdapter_spec.js @@ -1,10 +1,10 @@ import {expect} from 'chai'; import {spec} from 'modules/interactiveOffersBidAdapter'; -describe('interactiveOffers adapter', () => { - describe('implementation', () => { - describe('for requests', () => { - it('should accept valid bid', () => { +describe('interactiveOffers adapter', function () { + describe('implementation', function () { + describe('for requests', function () { + it('should accept valid bid', function () { let validBid = { bidder: 'interactiveOffers', params: { @@ -16,7 +16,7 @@ describe('interactiveOffers adapter', () => { expect(isValid).to.equal(true); }); - it('should reject invalid bid', () => { + it('should reject invalid bid', function () { let invalidBid = { bidder: 'interactiveOffers' }, @@ -25,8 +25,8 @@ describe('interactiveOffers adapter', () => { expect(isValid).to.equal(false); }); }); - describe('for requests', () => { - it('should accept valid bid with optional params', () => { + describe('for requests', function () { + it('should accept valid bid with optional params', function () { let validBid = { bidder: 'interactiveOffers', params: { @@ -44,7 +44,7 @@ describe('interactiveOffers adapter', () => { expect(requestUrlCustomParams).have.property('tmax', 1500); }); - it('should accept valid bid without optional params', () => { + it('should accept valid bid without optional params', function () { let validBid = { bidder: 'interactiveOffers', params: { @@ -60,7 +60,7 @@ describe('interactiveOffers adapter', () => { expect(requestUrlCustomParams).have.property('tmax'); }); - it('should reject invalid bid without pubId', () => { + it('should reject invalid bid without pubId', function () { let invalidBid = { bidder: 'interactiveOffers', params: {} @@ -70,8 +70,8 @@ describe('interactiveOffers adapter', () => { expect(isValid).to.equal(false); }); }); - describe('bid responses', () => { - it('should return complete bid response', () => { + describe('bid responses', function () { + it('should return complete bid response', function () { let serverResponse = { body: { 'success': 'true', @@ -104,7 +104,7 @@ describe('interactiveOffers adapter', () => { expect(bids[0].ad).to.have.length.above(1); }); - it('should return empty bid response', () => { + it('should return empty bid response', function () { let bidRequests = [ { bidder: 'interactiveOffers', @@ -128,7 +128,7 @@ describe('interactiveOffers adapter', () => { expect(bids).to.be.lengthOf(0); }); - it('should return empty bid response with error', () => { + it('should return empty bid response with error', function () { let bidRequests = [ { bidder: 'interactiveOffers', @@ -143,7 +143,7 @@ describe('interactiveOffers adapter', () => { expect(bids).to.be.lengthOf(0); }); - it('should return empty bid response without payload', () => { + it('should return empty bid response without payload', function () { let bidRequests = [ { bidder: 'interactiveOffers', @@ -158,7 +158,7 @@ describe('interactiveOffers adapter', () => { expect(bids).to.be.lengthOf(0); }); - it('should return empty bid response on empty body', () => { + it('should return empty bid response on empty body', function () { let bidRequests = [ { bidder: 'interactiveOffers', diff --git a/test/spec/modules/invibesBidAdapter_spec.js b/test/spec/modules/invibesBidAdapter_spec.js index f6f601e0efc..6391f168599 100644 --- a/test/spec/modules/invibesBidAdapter_spec.js +++ b/test/spec/modules/invibesBidAdapter_spec.js @@ -1,5 +1,5 @@ import { expect } from 'chai'; -import { spec, resetInvibes } from 'modules/invibesBidAdapter'; +import { spec, resetInvibes, stubDomainOptions } from 'modules/invibesBidAdapter'; describe('invibesBidAdapter:', function () { const BIDDER_CODE = 'invibes'; @@ -40,6 +40,21 @@ describe('invibesBidAdapter:', function () { } ]; + let StubbedPersistence = function(initialValue) { + var value = initialValue; + return { + load: function () { + let str = value || ''; + try { + return JSON.parse(str); + } catch (e) { } + }, + save: function (obj) { + value = JSON.stringify(obj); + } + } + }; + beforeEach(function () { resetInvibes(); document.cookie = ''; @@ -83,22 +98,34 @@ describe('invibesBidAdapter:', function () { expect(spec.isBidRequestValid(invalidBid)).to.be.false; }); + + it('returns false when bid response was previously received', function() { + const validBid = { + bidder: BIDDER_CODE, + params: { + placementId: PLACEMENT_ID + } + } + + top.window.invibes.bidResponse = { prop: 'prop' }; + expect(spec.isBidRequestValid(validBid)).to.be.false; + }); }); }); - describe('buildRequests', () => { - it('sends bid request to ENDPOINT via GET', () => { + describe('buildRequests', function () { + it('sends bid request to ENDPOINT via GET', function () { const request = spec.buildRequests(bidRequests); expect(request.url).to.equal(ENDPOINT); expect(request.method).to.equal('GET'); }); - it('sends cookies with the bid request', () => { + it('sends cookies with the bid request', function () { const request = spec.buildRequests(bidRequests); expect(request.options.withCredentials).to.equal(true); }); - it('has location, html id, placement and width/height', () => { + it('has location, html id, placement and width/height', function () { const request = spec.buildRequests(bidRequests, { auctionStart: Date.now() }); const parsedData = request.data; expect(parsedData.location).to.exist; @@ -108,56 +135,70 @@ describe('invibesBidAdapter:', function () { expect(parsedData.height).to.exist; }); - it('sends all Placement Ids', () => { + it('sends all Placement Ids', function () { const request = spec.buildRequests(bidRequests); expect(JSON.parse(request.data.bidParamsJson).placementIds).to.contain(bidRequests[0].params.placementId); expect(JSON.parse(request.data.bidParamsJson).placementIds).to.contain(bidRequests[1].params.placementId); }); - it('uses cookies', () => { + it('uses cookies', function () { global.document.cookie = 'ivNoCookie=1'; let request = spec.buildRequests(bidRequests); expect(request.data.lId).to.be.undefined; }); - it('doesnt send the domain id if not graduated', () => { + it('doesnt send the domain id if not graduated', function () { global.document.cookie = 'ivbsdid={"id":"dvdjkams6nkq","cr":1522929537626,"hc":1}'; let request = spec.buildRequests(bidRequests); expect(request.data.lId).to.not.exist; }); - it('graduate and send the domain id', () => { - top.window.invibes.optIn = 1; - global.document.cookie = 'ivbsdid={"id":"dvdjkams6nkq","cr":1521818537626,"hc":7}'; - let request = spec.buildRequests(bidRequests); + it('try to graduate but not enough count - doesnt send the domain id', function () { + global.document.cookie = 'ivbsdid={"id":"dvdjkams6nkq","cr":1521818537626,"hc":5}'; + let bidderRequest = { gdprConsent: { vendorData: { vendorConsents: { 436: true } } } }; + let request = spec.buildRequests(bidRequests, bidderRequest); + expect(request.data.lId).to.not.exist; + }); + + it('try to graduate but not old enough - doesnt send the domain id', function () { + let bidderRequest = { gdprConsent: { vendorData: { vendorConsents: { 436: true } } } }; + global.document.cookie = 'ivbsdid={"id":"dvdjkams6nkq","cr":' + Date.now() + ',"hc":5}'; + let request = spec.buildRequests(bidRequests, bidderRequest); + expect(request.data.lId).to.not.exist; + }); + + it('graduate and send the domain id', function () { + let bidderRequest = { gdprConsent: { vendorData: { vendorConsents: { 436: true } } } }; + stubDomainOptions(new StubbedPersistence('{"id":"dvdjkams6nkq","cr":1521818537626,"hc":7}')); + let request = spec.buildRequests(bidRequests, bidderRequest); expect(request.data.lId).to.exist; }); - it('send the domain id if already graduated', () => { - top.window.invibes.optIn = 1; - global.document.cookie = 'ivbsdid={"id":"f8zoh044p9oi"}'; - let request = spec.buildRequests(bidRequests); + it('send the domain id if already graduated', function () { + let bidderRequest = { gdprConsent: { vendorData: { vendorConsents: { 436: true } } } }; + stubDomainOptions(new StubbedPersistence('{"id":"f8zoh044p9oi"}')); + let request = spec.buildRequests(bidRequests, bidderRequest); expect(request.data.lId).to.exist; }); - it('send the domain id after replacing it with new format', () => { - top.window.invibes.optIn = 1; - global.document.cookie = 'ivbsdid={"id":"f8zoh044p9oi.8537626"}'; - let request = spec.buildRequests(bidRequests); + it('send the domain id after replacing it with new format', function () { + let bidderRequest = { gdprConsent: { vendorData: { vendorConsents: { 436: true } } } }; + stubDomainOptions(new StubbedPersistence('{"id":"f8zoh044p9oi.8537626"}')); + let request = spec.buildRequests(bidRequests, bidderRequest); expect(request.data.lId).to.exist; }); - it('try to graduate but not enough count - doesnt send the domain id', () => { - top.window.invibes.optIn = 1; - global.document.cookie = 'ivbsdid={"id":"dvdjkams6nkq","cr":1521818537626,"hc":5}'; - let request = spec.buildRequests(bidRequests); + it('dont send the domain id if consent declined', function () { + let bidderRequest = { gdprConsent: { vendorData: { vendorConsents: { 436: false } } } }; + stubDomainOptions(new StubbedPersistence('{"id":"f8zoh044p9oi.8537626"}')); + let request = spec.buildRequests(bidRequests, bidderRequest); expect(request.data.lId).to.not.exist; }); - it('try to graduate but not old enough - doesnt send the domain id', () => { - top.window.invibes.optIn = 1; - global.document.cookie = 'ivbsdid={"id":"dvdjkams6nkq","cr":' + Date.now() + ',"hc":5}'; - let request = spec.buildRequests(bidRequests); + it('dont send the domain id if no consent', function () { + let bidderRequest = { }; + stubDomainOptions(new StubbedPersistence('{"id":"f8zoh044p9oi.8537626"}')); + let request = spec.buildRequests(bidRequests, bidderRequest); expect(request.data.lId).to.not.exist; }); }); @@ -194,55 +235,55 @@ describe('invibesBidAdapter:', function () { }]; context('when the response is not valid', function () { - it('handles response with no bids requested', () => { + it('handles response with no bids requested', function () { let emptyResult = spec.interpretResponse({ body: response }); expect(emptyResult).to.be.empty; }); - it('handles empty response', () => { + it('handles empty response', function () { let emptyResult = spec.interpretResponse(null, { bidRequests }); expect(emptyResult).to.be.empty; }); - it('handles response with bidding is not configured', () => { + it('handles response with bidding is not configured', function () { let emptyResult = spec.interpretResponse({ body: { Ads: [{ BidPrice: 1 }] } }, { bidRequests }); expect(emptyResult).to.be.empty; }); - it('handles response with no ads are received', () => { + it('handles response with no ads are received', function () { let emptyResult = spec.interpretResponse({ body: { BidModel: { PlacementId: '12345' }, AdReason: 'No ads' } }, { bidRequests }); expect(emptyResult).to.be.empty; }); - it('handles response with no ads are received - no ad reason', () => { + it('handles response with no ads are received - no ad reason', function () { let emptyResult = spec.interpretResponse({ body: { BidModel: { PlacementId: '12345' } } }, { bidRequests }); expect(emptyResult).to.be.empty; }); - it('handles response when no placement Id matches', () => { + it('handles response when no placement Id matches', function () { let emptyResult = spec.interpretResponse({ body: { BidModel: { PlacementId: '123456' }, Ads: [{ BidPrice: 1 }] } }, { bidRequests }); expect(emptyResult).to.be.empty; }); - it('handles response when placement Id is not present', () => { + it('handles response when placement Id is not present', function () { let emptyResult = spec.interpretResponse({ BidModel: { }, Ads: [{ BidPrice: 1 }] }, { bidRequests }); expect(emptyResult).to.be.empty; }); }); context('when the response is valid', function () { - it('responds with a valid bid', () => { + it('responds with a valid bid', function () { let result = spec.interpretResponse({ body: response }, { bidRequests }); expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])); }); - it('responds with a valid bid and uses logger', () => { + it('responds with a valid bid and uses logger', function () { localStorage.InvibesDEBUG = true; let result = spec.interpretResponse({ body: response }, { bidRequests }); expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])); }); - it('does not make multiple bids', () => { + it('does not make multiple bids', function () { localStorage.InvibesDEBUG = false; let result = spec.interpretResponse({ body: response }, { bidRequests }); let secondResult = spec.interpretResponse({ body: response }, { bidRequests }); @@ -252,13 +293,13 @@ describe('invibesBidAdapter:', function () { }); describe('getUserSyncs', function () { - it('returns an iframe if enabled', () => { + it('returns an iframe if enabled', function () { let response = spec.getUserSyncs({iframeEnabled: true}); expect(response.type).to.equal('iframe'); expect(response.url).to.include(SYNC_ENDPOINT); }); - it('returns an iframe with params if enabled', () => { + it('returns an iframe with params if enabled', function () { top.window.invibes.optIn = 1; global.document.cookie = 'ivvbks=17639.0,1,2'; let response = spec.getUserSyncs({ iframeEnabled: true }); @@ -269,7 +310,7 @@ describe('invibesBidAdapter:', function () { expect(response.url).to.include('ivbsdid'); }); - it('returns undefined if iframe not enabled ', () => { + it('returns undefined if iframe not enabled ', function () { let response = spec.getUserSyncs({ iframeEnabled: false }); expect(response).to.equal(undefined); }); diff --git a/test/spec/modules/iqmBidAdapter_spec.js b/test/spec/modules/iqmBidAdapter_spec.js index 8958a4dfc45..5535c52af9b 100644 --- a/test/spec/modules/iqmBidAdapter_spec.js +++ b/test/spec/modules/iqmBidAdapter_spec.js @@ -2,7 +2,7 @@ import {expect} from 'chai'; import {spec} from 'modules/iqmBidAdapter' import * as utils from 'src/utils'; -describe('iqmBidAdapter', () => { +describe('iqmBidAdapter', function () { const ENDPOINT_URL = 'https://pbd.bids.iqm.com'; const bidRequests = [{ bidder: 'iqm', @@ -80,15 +80,15 @@ describe('iqmBidAdapter', () => { headers: {} }; - describe('Request verification', () => { - it('basic property verification', () => { + describe('Request verification', function () { + it('basic property verification', function () { expect(spec.code).to.equal('iqm'); expect(spec.aliases).to.be.an('array'); // expect(spec.aliases).to.be.ofSize(1); expect(spec.aliases).to.have.lengthOf(1); }); - describe('isBidRequestValid', () => { + describe('isBidRequestValid', function () { let bid = { 'bidder': 'iqm', 'params': { @@ -103,17 +103,17 @@ describe('iqmBidAdapter', () => { 'auctionId': '1d1a030790a475' }; - it('should return false for empty object', () => { + it('should return false for empty object', function () { expect(spec.isBidRequestValid({})).to.equal(false); }); - it('should return false for request without param', () => { + it('should return false for request without param', function () { let bid = Object.assign({}, bid); delete bid.params; expect(spec.isBidRequestValid(bid)).to.equal(false); }); - it('should return false for invalid params', () => { + it('should return false for invalid params', function () { let bid = Object.assign({}, bid); delete bid.params; bid.params = { @@ -122,13 +122,13 @@ describe('iqmBidAdapter', () => { expect(spec.isBidRequestValid(bid)).to.equal(false); }); - it('should return true for proper request', () => { + it('should return true for proper request', function () { expect(spec.isBidRequestValid(bid)).to.equal(true); }); }); - describe('buildRequests', () => { - it('sends every bid request to ENDPOINT_URL via POST method', () => { + describe('buildRequests', function () { + it('sends every bid request to ENDPOINT_URL via POST method', function () { const requests = spec.buildRequests(bidRequests); expect(requests[0].method).to.equal('POST'); expect(requests[0].url).to.equal(ENDPOINT_URL); @@ -136,7 +136,7 @@ describe('iqmBidAdapter', () => { // expect(requests[1].url).to.equal(ENDPOINT_URL); }); - it('should send request data with every request', () => { + it('should send request data with every request', function () { const requests = spec.buildRequests(bidRequests); const data = requests[0].data; expect(data.id).to.equal(bidRequests[0].requestId); @@ -175,31 +175,31 @@ describe('iqmBidAdapter', () => { }); }); - describe('interpretResponse', () => { - it('should handle no bid response', () => { + describe('interpretResponse', function () { + it('should handle no bid response', function () { const response = spec.interpretResponse({ body: null }, { bidRequests }); expect(response.length).to.equal(0); }); - it('should have at least one Seat Object', () => { + it('should have at least one Seat Object', function () { const request = spec.buildRequests(bidRequests); const response = spec.interpretResponse(bidResponseEmptySeat, request); expect(response.length).to.equal(0); }); - it('should have at least one Bid Object', () => { + it('should have at least one Bid Object', function () { const request = spec.buildRequests(bidRequests); const response = spec.interpretResponse(bidResponseEmptyBid, request); expect(response.length).to.equal(0); }); - it('should have impId in Bid Object', () => { + it('should have impId in Bid Object', function () { const request = spec.buildRequests(bidRequests); const response = spec.interpretResponse(bidResponseNoImpId, request); expect(response.length).to.equal(0); }); - it('should handle valid response', () => { + it('should handle valid response', function () { const request = spec.buildRequests(bidRequests); const response = spec.interpretResponse(bidResponses, request); expect(response).to.be.an('array').to.have.lengthOf(1); diff --git a/test/spec/modules/ixBidAdapter_spec.js b/test/spec/modules/ixBidAdapter_spec.js index 3bf0fb27280..6bf7a0331a8 100644 --- a/test/spec/modules/ixBidAdapter_spec.js +++ b/test/spec/modules/ixBidAdapter_spec.js @@ -4,8 +4,9 @@ import { expect } from 'chai'; import { newBidder } from 'src/adapters/bidderFactory'; import { spec } from 'modules/ixBidAdapter'; -describe('IndexexchangeAdapter', () => { - const IX_ENDPOINT = 'http://as.casalemedia.com/cygnus'; +describe('IndexexchangeAdapter', function () { + const IX_INSECURE_ENDPOINT = 'http://as.casalemedia.com/cygnus'; + const IX_SECURE_ENDPOINT = 'https://as-sec.casalemedia.com/cygnus'; const BIDDER_VERSION = 7.2; const DEFAULT_BANNER_VALID_BID = [ @@ -28,6 +29,17 @@ describe('IndexexchangeAdapter', () => { auctionId: '1aa2bb3cc4dd' } ]; + const DEFAULT_BANNER_OPTION = { + gdprConsent: { + gdprApplies: true, + consentString: '3huaa11=qu3198ae', + vendorData: {} + }, + refererInfo: { + referer: 'http://www.prebid.org', + canonicalUrl: 'http://www.prebid.org/the/link/to/the/page' + } + }; const DEFAULT_BANNER_BID_RESPONSE = { cur: 'USD', id: '11a22b33c44d', @@ -58,44 +70,44 @@ describe('IndexexchangeAdapter', () => { ] }; - describe('inherited functions', () => { - it('should exists and is a function', () => { + describe('inherited functions', function () { + it('should exists and is a function', function () { const adapter = newBidder(spec); expect(adapter.callBids).to.exist.and.to.be.a('function'); }); }); - describe('isBidRequestValid', () => { - it('should return true when required params found for a banner ad', () => { + describe('isBidRequestValid', function () { + it('should return true when required params found for a banner ad', function () { expect(spec.isBidRequestValid(DEFAULT_BANNER_VALID_BID[0])).to.equal(true); }); - it('should return true when optional params found for a banner ad', () => { + it('should return true when optional params found for a banner ad', function () { const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); bid.params.bidFloor = 50; bid.params.bidFloorCur = 'USD'; expect(spec.isBidRequestValid(bid)).to.equal(true); }); - it('should return true when siteID is number', () => { + it('should return true when siteID is number', function () { const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); bid.params.siteId = 123; expect(spec.isBidRequestValid(bid)).to.equal(true); }); - it('should return false when siteID is missing', () => { + it('should return false when siteID is missing', function () { const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); delete bid.params.siteId; expect(spec.isBidRequestValid(bid)).to.equal(false); }); - it('should return false when size is missing', () => { + it('should return false when size is missing', function () { const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); delete bid.params.size; expect(spec.isBidRequestValid(bid)).to.equal(false); }); - it('should return false when size array is wrong length', () => { + it('should return false when size array is wrong length', function () { const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); bid.params.size = [ 300, @@ -105,13 +117,13 @@ describe('IndexexchangeAdapter', () => { expect(spec.isBidRequestValid(bid)).to.equal(false); }); - it('should return false when size array is array of strings', () => { + it('should return false when size array is array of strings', function () { const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); bid.params.size = ['300', '250']; expect(spec.isBidRequestValid(bid)).to.equal(false); }); - it('should return false when mediaTypes is not banner', () => { + it('should return false when mediaTypes is not banner', function () { const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); bid.mediaTypes = { video: { @@ -121,7 +133,7 @@ describe('IndexexchangeAdapter', () => { expect(spec.isBidRequestValid(bid)).to.equal(false); }); - it('should return false when mediaTypes.banner does not have sizes', () => { + it('should return false when mediaTypes.banner does not have sizes', function () { const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); bid.mediaTypes = { banner: { @@ -131,7 +143,7 @@ describe('IndexexchangeAdapter', () => { expect(spec.isBidRequestValid(bid)).to.equal(false); }); - it('should return false when mediaType is not banner', () => { + it('should return false when mediaType is not banner', function () { const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); delete bid.params.mediaTypes; bid.mediaType = 'banne'; @@ -139,7 +151,7 @@ describe('IndexexchangeAdapter', () => { expect(spec.isBidRequestValid(bid)).to.equal(false); }); - it('should return false when mediaType is video', () => { + it('should return false when mediaType is video', function () { const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); delete bid.params.mediaTypes; bid.mediaType = 'video'; @@ -147,7 +159,7 @@ describe('IndexexchangeAdapter', () => { expect(spec.isBidRequestValid(bid)).to.equal(false); }); - it('should return false when mediaType is native', () => { + it('should return false when mediaType is native', function () { const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); delete bid.params.mediaTypes; bid.mediaType = 'native'; @@ -155,14 +167,14 @@ describe('IndexexchangeAdapter', () => { expect(spec.isBidRequestValid(bid)).to.equal(false); }); - it('should return true when mediaType is missing and has sizes', () => { + it('should return true when mediaType is missing and has sizes', function () { const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); delete bid.mediaTypes; bid.sizes = [[300, 250]]; expect(spec.isBidRequestValid(bid)).to.equal(true); }); - it('should return true when mediaType is banner', () => { + it('should return true when mediaType is banner', function () { const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); delete bid.mediaTypes; bid.mediaType = 'banner'; @@ -170,26 +182,26 @@ describe('IndexexchangeAdapter', () => { expect(spec.isBidRequestValid(bid)).to.equal(true); }); - it('should return false when there is only bidFloor', () => { + it('should return false when there is only bidFloor', function () { const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); bid.params.bidFloor = 50; expect(spec.isBidRequestValid(bid)).to.equal(false); }); - it('should return false when there is only bidFloorCur', () => { + it('should return false when there is only bidFloorCur', function () { const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); bid.params.bidFloorCur = 'USD'; expect(spec.isBidRequestValid(bid)).to.equal(false); }); - it('should return false when bidFloor is string', () => { + it('should return false when bidFloor is string', function () { const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); bid.params.bidFloor = '50'; bid.params.bidFloorCur = 'USD'; expect(spec.isBidRequestValid(bid)).to.equal(false); }); - it('should return false when bidFloorCur is number', () => { + it('should return false when bidFloorCur is number', function () { const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); bid.params.bidFloor = 50; bid.params.bidFloorCur = 70; @@ -197,8 +209,8 @@ describe('IndexexchangeAdapter', () => { }); }); - describe('buildRequestsBanner', () => { - const request = spec.buildRequests(DEFAULT_BANNER_VALID_BID); + describe('buildRequestsBanner', function () { + const request = spec.buildRequests(DEFAULT_BANNER_VALID_BID, DEFAULT_BANNER_OPTION); const requestUrl = request.url; const requestMethod = request.method; const query = request.data; @@ -206,15 +218,15 @@ describe('IndexexchangeAdapter', () => { const bidWithoutMediaType = utils.deepClone(DEFAULT_BANNER_VALID_BID); delete bidWithoutMediaType[0].mediaTypes; bidWithoutMediaType[0].sizes = [[300, 250], [300, 600]]; - const requestWithoutMediaType = spec.buildRequests(bidWithoutMediaType); + const requestWithoutMediaType = spec.buildRequests(bidWithoutMediaType, DEFAULT_BANNER_OPTION); const queryWithoutMediaType = requestWithoutMediaType.data; - it('request should be made to IX endpoint with GET method', () => { + it('request should be made to IX endpoint with GET method', function () { expect(requestMethod).to.equal('GET'); - expect(requestUrl).to.equal(IX_ENDPOINT); + expect(requestUrl).to.equal(IX_INSECURE_ENDPOINT); }); - it('query object (version, siteID and request) should be correct', () => { + it('query object (version, siteID and request) should be correct', function () { expect(query.v).to.equal(BIDDER_VERSION); expect(query.s).to.equal(DEFAULT_BANNER_VALID_BID[0].params.siteId); expect(query.r).to.exist; @@ -222,15 +234,13 @@ describe('IndexexchangeAdapter', () => { expect(query.sd).to.equal(1); }); - it('payload should have correct format and value', () => { + it('payload should have correct format and value', function () { const payload = JSON.parse(query.r); expect(payload.id).to.equal(DEFAULT_BANNER_VALID_BID[0].bidderRequestId); expect(payload.site).to.exist; - expect(payload.site.page).to.exist; - expect(payload.site.page).to.contain('http'); - expect(payload.site.ref).to.exist; - expect(payload.site.ref).to.be.a('string'); + expect(payload.site.page).to.equal(DEFAULT_BANNER_OPTION.refererInfo.referer); + expect(payload.site.ref).to.equal(document.referrer); expect(payload.ext).to.exist; expect(payload.ext.source).to.equal('prebid'); expect(payload.imp).to.exist; @@ -238,7 +248,7 @@ describe('IndexexchangeAdapter', () => { expect(payload.imp).to.have.lengthOf(1); }); - it('impression should have correct format and value', () => { + it('impression should have correct format and value', function () { const impression = JSON.parse(query.r).imp[0]; const sidValue = `${DEFAULT_BANNER_VALID_BID[0].params.size[0].toString()}x${DEFAULT_BANNER_VALID_BID[0].params.size[1].toString()}`; @@ -253,7 +263,7 @@ describe('IndexexchangeAdapter', () => { expect(impression.ext.sid).to.equal(sidValue); }); - it('impression should have bidFloor and bidFloorCur if configured', () => { + it('impression should have bidFloor and bidFloorCur if configured', function () { const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); bid.params.bidFloor = 50; bid.params.bidFloorCur = 'USD'; @@ -264,15 +274,13 @@ describe('IndexexchangeAdapter', () => { expect(impression.bidfloorcur).to.equal(bid.params.bidFloorCur); }); - it('payload without mediaType should have correct format and value', () => { + it('payload without mediaType should have correct format and value', function () { const payload = JSON.parse(queryWithoutMediaType.r); expect(payload.id).to.equal(DEFAULT_BANNER_VALID_BID[0].bidderRequestId); expect(payload.site).to.exist; - expect(payload.site.page).to.exist; - expect(payload.site.page).to.contain('http'); - expect(payload.site.ref).to.exist; - expect(payload.site.ref).to.be.a('string'); + expect(payload.site.page).to.equal(DEFAULT_BANNER_OPTION.refererInfo.referer); + expect(payload.site.ref).to.equal(document.referrer); expect(payload.ext).to.exist; expect(payload.ext.source).to.equal('prebid'); expect(payload.imp).to.exist; @@ -280,7 +288,7 @@ describe('IndexexchangeAdapter', () => { expect(payload.imp).to.have.lengthOf(1); }); - it('impression without mediaType should have correct format and value', () => { + it('impression without mediaType should have correct format and value', function () { const impression = JSON.parse(queryWithoutMediaType.r).imp[0]; const sidValue = `${DEFAULT_BANNER_VALID_BID[0].params.size[0].toString()}x${DEFAULT_BANNER_VALID_BID[0].params.size[1].toString()}`; @@ -295,7 +303,7 @@ describe('IndexexchangeAdapter', () => { expect(impression.ext.sid).to.equal(sidValue); }); - it('impression should have sid if id is configured as number', () => { + it('impression should have sid if id is configured as number', function () { const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); bid.params.id = 50; const requestBidFloor = spec.buildRequests([bid]); @@ -312,7 +320,7 @@ describe('IndexexchangeAdapter', () => { expect(impression.ext.sid).to.equal('50'); }); - it('impression should have sid if id is configured as string', () => { + it('impression should have sid if id is configured as string', function () { const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); bid.params.id = 'abc'; const requestBidFloor = spec.buildRequests([bid]); @@ -328,7 +336,7 @@ describe('IndexexchangeAdapter', () => { expect(impression.ext.sid).to.equal('abc'); }); - it('should add first party data to page url in bid request if it exists in config', () => { + it('should add first party data to page url in bid request if it exists in config', function () { config.setConfig({ ix: { firstPartyData: { @@ -340,47 +348,47 @@ describe('IndexexchangeAdapter', () => { } }); - const requestWithFirstPartyData = spec.buildRequests(DEFAULT_BANNER_VALID_BID); + const requestWithFirstPartyData = spec.buildRequests(DEFAULT_BANNER_VALID_BID, DEFAULT_BANNER_OPTION); const pageUrl = JSON.parse(requestWithFirstPartyData.data.r).site.page; - const expectedPageUrl = `${utils.getTopWindowUrl()}?ab=123&cd=123%23ab&e%2Ff=456&h%3Fg=456%23cd`; + const expectedPageUrl = DEFAULT_BANNER_OPTION.refererInfo.referer + '?ab=123&cd=123%23ab&e%2Ff=456&h%3Fg=456%23cd'; expect(pageUrl).to.equal(expectedPageUrl); }); - it('should not set first party data if it is not an object', () => { + it('should not set first party data if it is not an object', function () { config.setConfig({ ix: { firstPartyData: 500 } }); - const requestFirstPartyDataNumber = spec.buildRequests(DEFAULT_BANNER_VALID_BID); + const requestFirstPartyDataNumber = spec.buildRequests(DEFAULT_BANNER_VALID_BID, DEFAULT_BANNER_OPTION); const pageUrl = JSON.parse(requestFirstPartyDataNumber.data.r).site.page; - expect(pageUrl).to.equal(utils.getTopWindowUrl()); + expect(pageUrl).to.equal(DEFAULT_BANNER_OPTION.refererInfo.referer); }); - it('should not set first party or timeout if it is not present', () => { + it('should not set first party or timeout if it is not present', function () { config.setConfig({ ix: {} }); - const requestWithoutConfig = spec.buildRequests(DEFAULT_BANNER_VALID_BID); + const requestWithoutConfig = spec.buildRequests(DEFAULT_BANNER_VALID_BID, DEFAULT_BANNER_OPTION); const pageUrl = JSON.parse(requestWithoutConfig.data.r).site.page; - expect(pageUrl).to.equal(utils.getTopWindowUrl()); + expect(pageUrl).to.equal(DEFAULT_BANNER_OPTION.refererInfo.referer); expect(requestWithoutConfig.data.t).to.be.undefined; }); - it('should not set first party or timeout if it is setConfig is not called', () => { - const requestWithoutConfig = spec.buildRequests(DEFAULT_BANNER_VALID_BID); + it('should not set first party or timeout if it is setConfig is not called', function () { + const requestWithoutConfig = spec.buildRequests(DEFAULT_BANNER_VALID_BID, DEFAULT_BANNER_OPTION); const pageUrl = JSON.parse(requestWithoutConfig.data.r).site.page; - expect(pageUrl).to.equal(utils.getTopWindowUrl()); + expect(pageUrl).to.equal(DEFAULT_BANNER_OPTION.refererInfo.referer); expect(requestWithoutConfig.data.t).to.be.undefined; }); - it('should set timeout if publisher set it through setConfig', () => { + it('should set timeout if publisher set it through setConfig', function () { config.setConfig({ ix: { timeout: 500 @@ -391,7 +399,7 @@ describe('IndexexchangeAdapter', () => { expect(requestWithTimeout.data.t).to.equal(500); }); - it('should set timeout if timeout is a string', () => { + it('should set timeout if timeout is a string', function () { config.setConfig({ ix: { timeout: '500' @@ -403,8 +411,8 @@ describe('IndexexchangeAdapter', () => { }); }); - describe('interpretResponseBanner', () => { - it('should get correct bid response', () => { + describe('interpretResponseBanner', function () { + it('should get correct bid response', function () { const expectedParse = [ { requestId: '1a2b3c4d', @@ -423,7 +431,7 @@ describe('IndexexchangeAdapter', () => { expect(result[0]).to.deep.equal(expectedParse[0]); }); - it('should set creativeId to default value if not provided', () => { + it('should set creativeId to default value if not provided', function () { const bidResponse = utils.deepClone(DEFAULT_BANNER_BID_RESPONSE); delete bidResponse.seatbid[0].bid[0].crid; const expectedParse = [ @@ -444,7 +452,7 @@ describe('IndexexchangeAdapter', () => { expect(result[0]).to.deep.equal(expectedParse[0]); }); - it('should set Japanese price correctly', () => { + it('should set Japanese price correctly', function () { const bidResponse = utils.deepClone(DEFAULT_BANNER_BID_RESPONSE); bidResponse.cur = 'JPY'; const expectedParse = [ @@ -465,7 +473,7 @@ describe('IndexexchangeAdapter', () => { expect(result[0]).to.deep.equal(expectedParse[0]); }); - it('should set dealId correctly', () => { + it('should set dealId correctly', function () { const bidResponse = utils.deepClone(DEFAULT_BANNER_BID_RESPONSE); bidResponse.seatbid[0].bid[0].ext.dealid = 'deal'; const expectedParse = [ @@ -486,22 +494,15 @@ describe('IndexexchangeAdapter', () => { expect(result[0]).to.deep.equal(expectedParse[0]); }); - it('bidrequest should have consent info if gdprApplies and consentString exist', () => { - const options = { - gdprConsent: { - gdprApplies: true, - consentString: '3huaa11=qu3198ae', - vendorData: {} - } - }; - const validBidWithConsent = spec.buildRequests(DEFAULT_BANNER_VALID_BID, options); + it('bidrequest should have consent info if gdprApplies and consentString exist', function () { + const validBidWithConsent = spec.buildRequests(DEFAULT_BANNER_VALID_BID, DEFAULT_BANNER_OPTION); const requestWithConsent = JSON.parse(validBidWithConsent.data.r); expect(requestWithConsent.regs.ext.gdpr).to.equal(1); expect(requestWithConsent.user.ext.consent).to.equal('3huaa11=qu3198ae'); }); - it('bidrequest should not have consent field if consentString is undefined', () => { + it('bidrequest should not have consent field if consentString is undefined', function () { const options = { gdprConsent: { gdprApplies: true, @@ -515,7 +516,7 @@ describe('IndexexchangeAdapter', () => { expect(requestWithConsent.user).to.be.undefined; }); - it('bidrequest should not have gdpr field if gdprApplies is undefined', () => { + it('bidrequest should not have gdpr field if gdprApplies is undefined', function () { const options = { gdprConsent: { consentString: '3huaa11=qu3198ae', @@ -529,7 +530,7 @@ describe('IndexexchangeAdapter', () => { expect(requestWithConsent.user.ext.consent).to.equal('3huaa11=qu3198ae'); }); - it('bidrequest should not have consent info if options.gdprConsent is undefined', () => { + it('bidrequest should not have consent info if options.gdprConsent is undefined', function () { const options = {}; const validBidWithConsent = spec.buildRequests(DEFAULT_BANNER_VALID_BID, options); const requestWithConsent = JSON.parse(validBidWithConsent.data.r); @@ -537,5 +538,38 @@ describe('IndexexchangeAdapter', () => { expect(requestWithConsent.regs).to.be.undefined; expect(requestWithConsent.user).to.be.undefined; }); + + it('bidrequest should not have page if options is undefined', function () { + const options = {}; + const validBidWithoutreferInfo = spec.buildRequests(DEFAULT_BANNER_VALID_BID, options); + const requestWithoutreferInfo = JSON.parse(validBidWithoutreferInfo.data.r); + + expect(requestWithoutreferInfo.site.page).to.be.undefined; + expect(validBidWithoutreferInfo.url).to.equal(IX_SECURE_ENDPOINT); + }); + + it('bidrequest should not have page if options.refererInfo is an empty object', function () { + const options = { + refererInfo: {} + }; + const validBidWithoutreferInfo = spec.buildRequests(DEFAULT_BANNER_VALID_BID, options); + const requestWithoutreferInfo = JSON.parse(validBidWithoutreferInfo.data.r); + + expect(requestWithoutreferInfo.site.page).to.be.undefined; + expect(validBidWithoutreferInfo.url).to.equal(IX_SECURE_ENDPOINT); + }); + + it('bidrequest should sent to secure endpoint if page url is secure', function () { + const options = { + refererInfo: { + referer: 'https://www.prebid.org' + } + }; + const validBidWithoutreferInfo = spec.buildRequests(DEFAULT_BANNER_VALID_BID, options); + const requestWithoutreferInfo = JSON.parse(validBidWithoutreferInfo.data.r); + + expect(requestWithoutreferInfo.site.page).to.equal(options.refererInfo.referer); + expect(validBidWithoutreferInfo.url).to.equal(IX_SECURE_ENDPOINT); + }); }); }); diff --git a/test/spec/modules/jcmBidAdapter_spec.js b/test/spec/modules/jcmBidAdapter_spec.js index 27784def4f9..0b467e1ecfb 100644 --- a/test/spec/modules/jcmBidAdapter_spec.js +++ b/test/spec/modules/jcmBidAdapter_spec.js @@ -4,16 +4,16 @@ import { newBidder } from 'src/adapters/bidderFactory'; const ENDPOINT = '//media.adfrontiers.com/'; -describe('jcmAdapter', () => { +describe('jcmAdapter', function () { const adapter = newBidder(spec); - describe('inherited functions', () => { - it('exists and is a function', () => { + describe('inherited functions', function () { + it('exists and is a function', function () { expect(adapter.callBids).to.exist.and.to.be.a('function'); }); }); - describe('isBidRequestValid', () => { + describe('isBidRequestValid', function () { let bid = { 'bidder': 'jcm', 'params': { @@ -26,18 +26,18 @@ describe('jcmAdapter', () => { 'auctionId': '1d1a030790a475', }; - it('should return true when required params found', () => { + it('should return true when required params found', function () { expect(spec.isBidRequestValid(bid)).to.equal(true); }); - it('should return false when required params are not passed', () => { + it('should return false when required params are not passed', function () { let bid = Object.assign({}, bid); delete bid.params; expect(spec.isBidRequestValid(bid)).to.equal(false); }); }); - describe('buildRequests', () => { + describe('buildRequests', function () { let bidRequests = [ { 'bidder': 'jcm', @@ -55,11 +55,11 @@ describe('jcmAdapter', () => { const request = spec.buildRequests(bidRequests); - it('sends bid request to ENDPOINT via GET', () => { + it('sends bid request to ENDPOINT via GET', function () { expect(request.method).to.equal('GET'); }); - it('sends correct bid parameters', () => { + it('sends correct bid parameters', function () { const payloadArr = request.data.split('&'); expect(request.method).to.equal('GET'); expect(payloadArr.length).to.equal(4); @@ -75,8 +75,8 @@ describe('jcmAdapter', () => { }); }); - describe('interpretResponse', () => { - it('should get correct bid response', () => { + describe('interpretResponse', function () { + it('should get correct bid response', function () { let serverResponse = {'bids': [{'width': 300, 'height': 250, 'creativeId': '29681110', 'ad': '', 'cpm': 0.5, 'callbackId': '30b31c1838de1e'}]}; let expectedResponse = [ @@ -109,15 +109,15 @@ describe('jcmAdapter', () => { expect(Object.keys(result[0]).ad).to.equal(Object.keys(expectedResponse[0]).ad); }); - it('handles nobid responses', () => { + it('handles nobid responses', function () { let serverResponse = {'bids': []}; let result = spec.interpretResponse({ body: serverResponse }); expect(result.length).to.equal(0); }); }); - describe('getUserSyncs', () => { - it('Verifies sync iframe option', () => { + describe('getUserSyncs', function () { + it('Verifies sync iframe option', function () { expect(spec.getUserSyncs({})).to.be.undefined; expect(spec.getUserSyncs({ iframeEnabled: false })).to.be.undefined; const options = spec.getUserSyncs({ iframeEnabled: true }); @@ -127,7 +127,7 @@ describe('jcmAdapter', () => { expect(options[0].url).to.equal('//media.adfrontiers.com/hb/jcm_usersync.html'); }); - it('Verifies sync image option', () => { + it('Verifies sync image option', function () { expect(spec.getUserSyncs({ image: false })).to.be.undefined; const options = spec.getUserSyncs({ image: true }); expect(options).to.not.be.undefined; diff --git a/test/spec/modules/justpremiumBidAdapter_spec.js b/test/spec/modules/justpremiumBidAdapter_spec.js index 3b74b730044..8167c29e5c2 100644 --- a/test/spec/modules/justpremiumBidAdapter_spec.js +++ b/test/spec/modules/justpremiumBidAdapter_spec.js @@ -1,9 +1,22 @@ import { expect } from 'chai' -import { spec } from 'modules/justpremiumBidAdapter' +import { spec, pixel } from 'modules/justpremiumBidAdapter' + +describe('justpremium adapter', function () { + let sandbox; + let pixelStub; + + beforeEach(function() { + sandbox = sinon.sandbox.create(); + pixelStub = sandbox.stub(pixel, 'fire'); + }); + + afterEach(function() { + sandbox.restore(); + }); -describe('justpremium adapter', () => { let adUnits = [ { + adUnitCode: 'div-gpt-ad-1471513102552-1', bidder: 'justpremium', params: { zone: 28313, @@ -11,6 +24,7 @@ describe('justpremium adapter', () => { } }, { + adUnitCode: 'div-gpt-ad-1471513102552-2', bidder: 'justpremium', params: { zone: 32831, @@ -19,12 +33,12 @@ describe('justpremium adapter', () => { }, ] - describe('isBidRequestValid', () => { - it('Verifies bidder code', () => { + describe('isBidRequestValid', function () { + it('Verifies bidder code', function () { expect(spec.code).to.equal('justpremium') }) - it('Verify build request', () => { + it('Verify build request', function () { expect(spec.isBidRequestValid({bidder: 'justpremium', params: {}})).to.equal(false) expect(spec.isBidRequestValid({})).to.equal(false) expect(spec.isBidRequestValid(adUnits[0])).to.equal(true) @@ -32,8 +46,8 @@ describe('justpremium adapter', () => { }) }) - describe('buildRequests', () => { - it('Verify build request and parameters', () => { + describe('buildRequests', function () { + it('Verify build request and parameters', function () { 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/) @@ -51,13 +65,13 @@ describe('justpremium adapter', () => { expect(jpxRequest.id).to.equal(adUnits[0].params.zone) expect(jpxRequest.sizes).to.not.equal('undefined') expect(jpxRequest.version.prebid).to.equal('$prebid.version$') - expect(jpxRequest.version.jp_adapter).to.equal('1.1') + expect(jpxRequest.version.jp_adapter).to.equal('1.3') }) }) - describe('interpretResponse', () => { + describe('interpretResponse', function () { const request = spec.buildRequests(adUnits) - it('Verify server response', () => { + it('Verify server response', function () { let response = { 'bid': { '28313': [{ @@ -105,7 +119,7 @@ describe('justpremium adapter', () => { expect(result[0].format).to.equal('lb') }) - it('Verify wrong server response', () => { + it('Verify wrong server response', function () { let response = { 'bid': { '28313': [] @@ -120,12 +134,42 @@ describe('justpremium adapter', () => { }) }) - describe('getUserSyncs', () => { - it('Verifies sync options', () => { + describe('getUserSyncs', function () { + it('Verifies sync options', function () { const options = spec.getUserSyncs({iframeEnabled: true}) expect(options).to.not.be.undefined expect(options[0].type).to.equal('iframe') expect(options[0].url).to.match(/\/\/pre.ads.justpremium.com\/v\/1.0\/t\/sync/) }) }) + + describe('onTimeout', function () { + it('onTimeout', function(done) { + spec.onTimeout([{ + 'bidId': '25cd3ec3fd6ed7', + 'bidder': 'justpremium', + 'adUnitCode': 'div-gpt-ad-1471513102552-1', + 'auctionId': '6fbd0562-f613-4151-a6df-6cb446fc717b', + 'params': [{ + 'adType': 'iab', + 'zone': 21521 + }], + 'timeout': 1 + }, { + 'bidId': '3b51df1f254e32', + 'bidder': 'justpremium', + 'adUnitCode': 'div-gpt-ad-1471513102552-3', + 'auctionId': '6fbd0562-f613-4151-a6df-6cb446fc717b', + 'params': [{ + 'adType': 'iab', + 'zone': 21521 + }], + 'timeout': 1 + }]); + + expect(pixelStub.calledOnce).to.equal(true); + + done() + }) + }) }) diff --git a/test/spec/modules/kargoBidAdapter_spec.js b/test/spec/modules/kargoBidAdapter_spec.js index bb0feeba069..eb829ce552d 100644 --- a/test/spec/modules/kargoBidAdapter_spec.js +++ b/test/spec/modules/kargoBidAdapter_spec.js @@ -1,17 +1,16 @@ import {expect, assert} from 'chai'; import {spec} from 'modules/kargoBidAdapter'; -import {registerBidder} from 'src/adapters/bidderFactory'; import {config} from 'src/config'; describe('kargo adapter tests', function () { var sandbox, clock, frozenNow = new Date(); - beforeEach(() => { + beforeEach(function () { sandbox = sinon.sandbox.create(); clock = sinon.useFakeTimers(frozenNow.getTime()); }); - afterEach(() => { + afterEach(function () { sandbox.restore(); clock.restore(); }); @@ -35,12 +34,20 @@ describe('kargo adapter tests', function () { }); describe('build request', function() { - var bids, cookies = [], localStorageItems = []; + var bids, undefinedCurrency, noAdServerCurrency, cookies = [], localStorageItems = []; - beforeEach(() => { + beforeEach(function () { + undefinedCurrency = false; + noAdServerCurrency = false; sandbox.stub(config, 'getConfig').callsFake(function(key) { if (key === 'currency') { - return 'USD'; + if (undefinedCurrency) { + return undefined; + } + if (noAdServerCurrency) { + return {}; + } + return {adServerCurrency: 'USD'}; } throw new Error(`Config stub incomplete! Missing key "${key}"`) }); @@ -50,18 +57,24 @@ describe('kargo adapter tests', function () { params: { placementId: 'foo' }, - placementCode: 1 + bidId: 1 + }, + { + params: { + placementId: 'bar' + }, + bidId: 2 }, { params: { placementId: 'bar' }, - placementCode: 2 + bidId: 3 } ]; }); - afterEach(() => { + afterEach(function () { for (let key in cookies) { let cookie = cookies[key]; removeCookie(cookie); @@ -103,6 +116,16 @@ describe('kargo adapter tests', function () { return sandbox.stub(localStorage, 'getItem').throws(); } + function simulateNoCurrencyObject() { + undefinedCurrency = true; + noAdServerCurrency = false; + } + + function simulateNoAdServerCurrency() { + undefinedCurrency = false; + noAdServerCurrency = true; + } + function initializeKruxUser() { setLocalStorageItem('kxkar_user', 'rsgr9pnij'); } @@ -173,10 +196,11 @@ describe('kargo adapter tests', function () { floor: 0, ceil: 20 }, - adSlotIDs: [ - 'foo', - 'bar' - ], + bidIDs: { + 1: 'foo', + 2: 'bar', + 3: 'bar' + }, userIDs: { kargoID: '5f108831-302d-11e7-bf6b-4595acd3bf6c', clientID: '2410d8f2-c111-4811-88a5-7b5e190e475f', @@ -235,7 +259,7 @@ describe('kargo adapter tests', function () { var request = spec.buildRequests(bids, {timeout: 200, foo: 'bar'}); var krakenParams = JSON.parse(decodeURIComponent(request.data.slice(5))); expect(request.data.slice(0, 5)).to.equal('json='); - expect(request.url).to.equal('https://krk.kargo.com/api/v1/bid'); + expect(request.url).to.equal('https://krk.kargo.com/api/v2/bid'); expect(request.method).to.equal('GET'); expect(request.currency).to.equal('USD'); expect(request.timeout).to.equal(200); @@ -301,18 +325,46 @@ describe('kargo adapter tests', function () { initializeInvalidKrgCrbType3(); testBuildRequests(getExpectedKrakenParams({crb: true}, undefined, getInvalidKrgCrbType3())); }); + + it('handles a non-existant currency object on the config', function() { + simulateNoCurrencyObject(); + initializeKruxUser(); + initializeKruxSegments(); + initializeKrgUid(); + initializeKrgCrb(); + testBuildRequests(getExpectedKrakenParams(undefined, undefined, getKrgCrb())); + }); + + it('handles no ad server currency being set on the currency object in the config', function() { + simulateNoAdServerCurrency(); + initializeKruxUser(); + initializeKruxSegments(); + initializeKrgUid(); + initializeKrgCrb(); + testBuildRequests(getExpectedKrakenParams(undefined, undefined, getKrgCrb())); + }); }); describe('response handler', function() { it('handles bid responses', function() { var resp = spec.interpretResponse({body: { - foo: { + 1: { + id: 'foo', cpm: 3, adm: '
', width: 320, height: 50 }, - bar: { + 2: { + id: 'bar', + cpm: 2.5, + adm: '
', + width: 300, + height: 250, + targetingCustom: 'dmpmptest1234' + }, + 3: { + id: 'bar', cpm: 2.5, adm: '
', width: 300, @@ -321,39 +373,150 @@ describe('kargo adapter tests', function () { }}, { currency: 'USD', bids: [{ - bidId: 'fake bid id 1', + bidId: 1, params: { placementId: 'foo' } }, { - bidId: 'fake bid id 2', + bidId: 2, + params: { + placementId: 'bar' + } + }, { + bidId: 3, params: { placementId: 'bar' } }] }); var expectation = [{ - requestId: 'fake bid id 1', + requestId: '1', cpm: 3, width: 320, height: 50, ad: '
', ttl: 300, creativeId: 'foo', + dealId: undefined, netRevenue: true, currency: 'USD' }, { - requestId: 'fake bid id 2', + requestId: '2', cpm: 2.5, width: 300, height: 250, ad: '
', ttl: 300, creativeId: 'bar', + dealId: 'dmpmptest1234', + netRevenue: true, + currency: 'USD' + }, { + requestId: '3', + cpm: 2.5, + width: 300, + height: 250, + ad: '
', + ttl: 300, + creativeId: 'bar', + dealId: undefined, netRevenue: true, currency: 'USD' }]; expect(resp).to.deep.equal(expectation); }); }); + + describe('user sync handler', function() { + const clientId = '74c81cbb-7d07-46d9-be9b-68ccb291c949'; + var shouldSimulateOutdatedBrowser, uid, isActuallyOutdatedBrowser; + + beforeEach(() => { + uid = {}; + shouldSimulateOutdatedBrowser = false; + isActuallyOutdatedBrowser = false; + + // IE11 fails these tests in the Prebid test suite. Since this + // browser won't support any of this stuff we expect all user + // syncing to fail gracefully. Kargo is mobile only, so this + // doesn't really matter. + if (!window.crypto) { + isActuallyOutdatedBrowser = true; + } else { + sandbox.stub(crypto, 'getRandomValues').callsFake(function(buf) { + if (shouldSimulateOutdatedBrowser) { + throw new Error('Could not generate random values'); + } + var bytes = [50, 5, 232, 133, 141, 55, 49, 57, 244, 126, 248, 44, 255, 38, 128, 0]; + for (var i = 0; i < bytes.length; i++) { + buf[i] = bytes[i]; + } + return buf; + }); + } + + sandbox.stub(spec, '_getUid').callsFake(function() { + return uid; + }); + }); + + function getUserSyncsWhenAllowed() { + return spec.getUserSyncs({iframeEnabled: true}); + } + + function getUserSyncsWhenForbidden() { + return spec.getUserSyncs({}); + } + + function turnOnClientId() { + uid.clientId = clientId; + } + + function simulateOutdatedBrowser() { + shouldSimulateOutdatedBrowser = true; + } + + function getSyncUrl(index) { + return { + type: 'iframe', + url: `https://crb.kargo.com/api/v1/initsyncrnd/${clientId}?seed=3205e885-8d37-4139-b47e-f82cff268000&idx=${index}` + }; + } + + function getSyncUrls() { + var syncs = []; + for (var i = 0; i < 5; i++) { + syncs[i] = getSyncUrl(i); + } + return syncs; + } + + function safelyRun(runExpectation) { + if (isActuallyOutdatedBrowser) { + expect(getUserSyncsWhenAllowed()).to.be.an('array').that.is.empty; + } else { + runExpectation(); + } + } + + it('handles user syncs when there is a client id', function() { + turnOnClientId(); + safelyRun(() => expect(getUserSyncsWhenAllowed()).to.deep.equal(getSyncUrls())); + }); + + it('no user syncs when there is no client id', function() { + safelyRun(() => expect(getUserSyncsWhenAllowed()).to.be.an('array').that.is.empty); + }); + + it('no user syncs when there is outdated browser', function() { + turnOnClientId(); + simulateOutdatedBrowser(); + safelyRun(() => expect(getUserSyncsWhenAllowed()).to.be.an('array').that.is.empty); + }); + + it('no user syncs when no iframe syncing allowed', function() { + turnOnClientId(); + safelyRun(() => expect(getUserSyncsWhenForbidden()).to.be.an('array').that.is.empty); + }); + }); }); diff --git a/test/spec/modules/komoonaBidAdapter_spec.js b/test/spec/modules/komoonaBidAdapter_spec.js index f7038505db3..b6d17c7b20c 100644 --- a/test/spec/modules/komoonaBidAdapter_spec.js +++ b/test/spec/modules/komoonaBidAdapter_spec.js @@ -1,7 +1,7 @@ import { expect } from 'chai'; import { spec } from 'modules/komoonaBidAdapter'; -describe('Komoona.com Adapter Tests', () => { +describe('Komoona.com Adapter Tests', function () { const bidsRequest = [ { bidder: 'komoona', @@ -54,11 +54,11 @@ describe('Komoona.com Adapter Tests', () => { } }; - it('Verifies komoonaAdapter bidder code', () => { + it('Verifies komoonaAdapter bidder code', function () { expect(spec.code).to.equal('komoona'); }); - it('Verifies komoonaAdapter bid request validation', () => { + it('Verifies komoonaAdapter bid request validation', function () { expect(spec.isBidRequestValid(bidsRequest[0])).to.equal(true); expect(spec.isBidRequestValid(bidsRequest[1])).to.equal(true); expect(spec.isBidRequestValid({})).to.equal(false); @@ -69,7 +69,7 @@ describe('Komoona.com Adapter Tests', () => { expect(spec.isBidRequestValid({ params: { hbid: 12345, placementId: 67890, floorPrice: 0.8 } })).to.equal(true); }); - it('Verify komoonaAdapter build request', () => { + it('Verify komoonaAdapter build request', function () { var startTime = new Date().getTime(); const request = spec.buildRequests(bidsRequest); @@ -127,7 +127,7 @@ describe('Komoona.com Adapter Tests', () => { expect(kbConf.hb_placements[1]).to.equal(bids[1].placementid); }); - it('Verify komoonaAdapter build response', () => { + it('Verify komoonaAdapter build response', function () { const request = spec.buildRequests(bidsRequest); const bids = spec.interpretResponse(bidsResponse, request); @@ -150,7 +150,7 @@ describe('Komoona.com Adapter Tests', () => { expect(bid.creativeId).to.equal(responseBids[0].creativeId); }); - it('Verifies komoonaAdapter sync options', () => { + it('Verifies komoonaAdapter sync options', function () { // user sync disabled expect(spec.getUserSyncs({})).to.be.undefined; expect(spec.getUserSyncs({ iframeEnabled: false })).to.be.undefined; diff --git a/test/spec/modules/kummaBidAdapter_spec.js b/test/spec/modules/kummaBidAdapter_spec.js index 84efa032cec..82076717dcc 100644 --- a/test/spec/modules/kummaBidAdapter_spec.js +++ b/test/spec/modules/kummaBidAdapter_spec.js @@ -3,7 +3,7 @@ import {spec} from 'modules/kummaBidAdapter'; import {getTopWindowLocation} from 'src/utils'; import {newBidder} from 'src/adapters/bidderFactory'; -describe('Kumma Adapter Tests', () => { +describe('Kumma Adapter Tests', function () { const slotConfigs = [{ placementCode: '/DfpAccount1/slot1', sizes: [[300, 250]], @@ -77,7 +77,7 @@ describe('Kumma Adapter Tests', () => { } }]; - it('Verify build request', () => { + it('Verify build request', function () { const request = spec.buildRequests(slotConfigs); expect(request.url).to.equal('//hb.kumma.com/'); expect(request.method).to.equal('POST'); @@ -109,7 +109,7 @@ describe('Kumma Adapter Tests', () => { expect(ortbRequest.imp[1].bidfloor).to.equal('0.000001'); }); - it('Verify parse response', () => { + it('Verify parse response', function () { const request = spec.buildRequests(slotConfigs); const ortbRequest = JSON.parse(request.data); const ortbResponse = { @@ -137,13 +137,13 @@ describe('Kumma Adapter Tests', () => { expect(bid.ttl).to.equal(360); }); - it('Verify full passback', () => { + it('Verify full passback', function () { const request = spec.buildRequests(slotConfigs); const bids = spec.interpretResponse({ body: null }, request) expect(bids).to.have.lengthOf(0); }); - it('Verify Native request', () => { + it('Verify Native request', function () { const request = spec.buildRequests(nativeSlotConfig); expect(request.url).to.equal('//hb.kumma.com/'); expect(request.method).to.equal('POST'); @@ -181,7 +181,7 @@ describe('Kumma Adapter Tests', () => { expect(nativeRequest.assets[4].img.type).to.equal(3); }); - it('Verify Native response', () => { + it('Verify Native response', function () { const request = spec.buildRequests(nativeSlotConfig); expect(request.url).to.equal('//hb.kumma.com/'); expect(request.method).to.equal('POST'); @@ -231,7 +231,7 @@ describe('Kumma Adapter Tests', () => { expect(nativeBid.impressionTrackers[0]).to.equal('http://rtb.adx1.com/log'); }); - it('Verify Video request', () => { + it('Verify Video request', function () { const request = spec.buildRequests(videoSlotConfig); expect(request.url).to.equal('//hb.kumma.com/'); expect(request.method).to.equal('POST'); @@ -253,7 +253,7 @@ describe('Kumma Adapter Tests', () => { expect(videoRequest.imp[0].native).to.equal(null); }); - it('Verify parse video response', () => { + it('Verify parse video response', function () { const request = spec.buildRequests(videoSlotConfig); const videoRequest = JSON.parse(request.data); const videoResponse = { @@ -282,25 +282,25 @@ describe('Kumma Adapter Tests', () => { expect(bid.ttl).to.equal(360); }); - it('Verifies bidder code', () => { + it('Verifies bidder code', function () { expect(spec.code).to.equal('kumma'); }); - it('Verifies supported media types', () => { + it('Verifies supported media types', function () { expect(spec.supportedMediaTypes).to.have.lengthOf(3); expect(spec.supportedMediaTypes[0]).to.equal('banner'); expect(spec.supportedMediaTypes[1]).to.equal('native'); expect(spec.supportedMediaTypes[2]).to.equal('video'); }); - it('Verifies if bid request valid', () => { + it('Verifies if bid request valid', function () { expect(spec.isBidRequestValid(slotConfigs[0])).to.equal(true); expect(spec.isBidRequestValid(slotConfigs[1])).to.equal(true); expect(spec.isBidRequestValid(nativeSlotConfig[0])).to.equal(true); expect(spec.isBidRequestValid(videoSlotConfig[0])).to.equal(true); }); - it('Verify app requests', () => { + it('Verify app requests', function () { const request = spec.buildRequests(appSlotConfig); const ortbRequest = JSON.parse(request.data); expect(ortbRequest.site).to.equal(null); @@ -314,7 +314,7 @@ describe('Kumma Adapter Tests', () => { expect(ortbRequest.app.domain).to.equal('kumma.com'); }); - it('Verify GDPR', () => { + it('Verify GDPR', function () { const bidderRequest = { gdprConsent: { gdprApplies: true, diff --git a/test/spec/modules/lifestreetBidAdapter_spec.js b/test/spec/modules/lifestreetBidAdapter_spec.js index 2c48a0f1892..6c9c6eeba31 100644 --- a/test/spec/modules/lifestreetBidAdapter_spec.js +++ b/test/spec/modules/lifestreetBidAdapter_spec.js @@ -56,45 +56,45 @@ let getDefaultBidResponse = (isBanner, noBid = 0) => { }; }; -describe('LifestreetAdapter', () => { +describe('LifestreetAdapter', function () { const LIFESTREET_URL = '//ads.lfstmedia.com/gate/'; const ADAPTER_VERSION = 'prebidJS-2.0'; - describe('buildRequests()', () => { - it('method exists and is a function', () => { + describe('buildRequests()', function () { + it('method exists and is a function', function () { expect(spec.buildRequests).to.exist.and.to.be.a('function'); }); - it('should not return request when no bids are present', () => { + it('should not return request when no bids are present', function () { let [request] = spec.buildRequests([]); expect(request).to.be.empty; }); let bidRequest = getDefaultBidRequest(); let [request] = spec.buildRequests(bidRequest.bids); - it('should return request for Lifestreet endpoint', () => { + it('should return request for Lifestreet endpoint', function () { expect(request.url).to.contain(LIFESTREET_URL); }); - it('should use json adapter', () => { + it('should use json adapter', function () { expect(request.url).to.contain('/prebid/'); }); - it('should contain slot', () => { + it('should contain slot', function () { expect(request.url).to.contain('slot166704'); }); - it('should contain adkey', () => { + it('should contain adkey', function () { expect(request.url).to.contain('adkey=78c'); }); - it('should contain ad_size', () => { + it('should contain ad_size', function () { expect(request.url).to.contain('ad_size=160x600'); }); - it('should contain location and rferrer paramters', () => { + it('should contain location and rferrer paramters', function () { expect(request.url).to.contain('__location='); expect(request.url).to.contain('__referrer='); }); - it('should contain info parameters', () => { + it('should contain info parameters', function () { expect(request.url).to.contain('__wn='); expect(request.url).to.contain('__sf='); expect(request.url).to.contain('__fif='); @@ -103,24 +103,24 @@ describe('LifestreetAdapter', () => { expect(request.url).to.contain('__pp='); }); - it('should contain HB enabled', () => { + it('should contain HB enabled', function () { expect(request.url).to.contain('__hb=1'); }); - it('should include gzip', () => { + it('should include gzip', function () { expect(request.url).to.contain('__gz=1'); }); - it('should not contain __gdpr parameter', () => { + it('should not contain __gdpr parameter', function () { expect(request.url).to.not.contain('__gdpr'); }); - it('should not contain __concent parameter', () => { + it('should not contain __concent parameter', function () { expect(request.url).to.not.contain('__consent'); }); - it('should contain the right version of adapter', () => { + it('should contain the right version of adapter', function () { expect(request.url).to.contain('__hbver=' + ADAPTER_VERSION); }); - it('should contain __gdpr and __consent parameters', () => { + it('should contain __gdpr and __consent parameters', function () { const options = { gdprConsent: { gdprApplies: true, @@ -132,7 +132,7 @@ describe('LifestreetAdapter', () => { expect(request.url).to.contain('__gdpr=1'); expect(request.url).to.contain('__consent=test'); }); - it('should contain __gdpr parameters', () => { + it('should contain __gdpr parameters', function () { const options = { gdprConsent: { gdprApplies: true, @@ -143,7 +143,7 @@ describe('LifestreetAdapter', () => { expect(request.url).to.contain('__gdpr=1'); expect(request.url).to.not.contain('__consent'); }); - it('should contain __consent parameters', () => { + it('should contain __consent parameters', function () { const options = { gdprConsent: { consentString: 'test', @@ -155,8 +155,8 @@ describe('LifestreetAdapter', () => { expect(request.url).to.contain('__consent=test'); }); }); - describe('interpretResponse()', () => { - it('should return formatted bid response with required properties', () => { + describe('interpretResponse()', function () { + it('should return formatted bid response with required properties', function () { let bidRequest = getDefaultBidRequest().bids[0]; let bidResponse = { body: getDefaultBidResponse(true) }; let formattedBidResponse = spec.interpretResponse(bidResponse, bidRequest); @@ -174,7 +174,7 @@ describe('LifestreetAdapter', () => { mediaType: 'banner' }]); }); - it('should return formatted VAST bid response with required properties', () => { + it('should return formatted VAST bid response with required properties', function () { let bidRequest = getDefaultBidRequest().bids[0]; let bidResponse = { body: getDefaultBidResponse(false) }; let formattedBidResponse = spec.interpretResponse(bidResponse, bidRequest); @@ -192,7 +192,7 @@ describe('LifestreetAdapter', () => { mediaType: 'video' }]); }); - it('should return formatted VAST bid response with vastUrl', () => { + it('should return formatted VAST bid response with vastUrl', function () { let bidRequest = getDefaultBidRequest().bids[0]; let bidResponse = { body: getDefaultBidResponse(false) }; bidResponse.body.vastUrl = 'http://lifestreet.com'; // set vastUrl @@ -212,7 +212,7 @@ describe('LifestreetAdapter', () => { }]); }); - it('should return no-bid', () => { + it('should return no-bid', function () { let bidRequest = getDefaultBidRequest().bids[0]; let bidResponse = { body: getDefaultBidResponse(true, true) }; let formattedBidResponse = spec.interpretResponse(bidResponse, bidRequest); diff --git a/test/spec/modules/livewrappedAnalyticsAdapter_spec.js b/test/spec/modules/livewrappedAnalyticsAdapter_spec.js new file mode 100644 index 00000000000..60fc9bdc1ec --- /dev/null +++ b/test/spec/modules/livewrappedAnalyticsAdapter_spec.js @@ -0,0 +1,265 @@ +import livewrappedAnalyticsAdapter, { BID_WON_TIMEOUT } from 'modules/livewrappedAnalyticsAdapter'; +import CONSTANTS from 'src/constants.json'; +import { config } from 'src/config'; + +let events = require('src/events'); +let adapterManager = require('src/adapterManager').default; + +const { + EVENTS: { + AUCTION_INIT, + AUCTION_END, + BID_REQUESTED, + BID_RESPONSE, + BIDDER_DONE, + BID_WON, + BID_TIMEOUT, + SET_TARGETING + }, + STATUS: { + GOOD + } +} = CONSTANTS; + +const BID1 = { + width: 980, + height: 240, + cpm: 1.1, + timeToRespond: 200, + bidId: '2ecff0db240757', + adId: '2ecff0db240757', + auctionId: '25c6d7f5-699a-4bfc-87c9-996f915341fa', + getStatusCode() { + return CONSTANTS.STATUS.GOOD; + } +}; + +const BID2 = Object.assign({}, BID1, { + width: 300, + height: 250, + cpm: 2.2, + timeToRespond: 300, + bidId: '3ecff0db240757', + adId: '3ecff0db240757', +}); + +const MOCK = { + AUCTION_INIT: { + 'auctionId': '25c6d7f5-699a-4bfc-87c9-996f915341fa', + }, + BID_REQUESTED: { + 'bidder': 'livewrapped', + 'auctionId': '25c6d7f5-699a-4bfc-87c9-996f915341fa', + 'bidderRequestId': '1be65d7958826a', + 'bids': [ + { + 'bidder': 'livewrapped', + 'adUnitCode': 'panorama_d_1', + 'bidId': '2ecff0db240757', + }, + { + 'bidder': 'livewrapped', + 'adUnitCode': 'box_d_1', + 'bidId': '3ecff0db240757', + } + ], + 'start': 1519149562216 + }, + BID_RESPONSE: [ + BID1, + BID2 + ], + AUCTION_END: { + }, + BID_WON: [ + Object.assign({}, BID1, { + 'status': 'rendered' + }), + Object.assign({}, BID2, { + 'status': 'rendered' + }) + ], + BIDDER_DONE: { + 'bidderCode': 'livewrapped', + 'bids': [ + BID1, + BID2 + ] + }, + BID_TIMEOUT: [ + { + 'bidId': '2ecff0db240757', + 'auctionId': '25c6d7f5-699a-4bfc-87c9-996f915341fa' + } + ] +}; + +const ANALYTICS_MESSAGE = { + publisherId: 'CC411485-42BC-4F92-8389-42C503EE38D7', + requests: [ + { + adUnit: 'panorama_d_1', + bidder: 'livewrapped', + timeStamp: 1519149562216 + }, + { + adUnit: 'box_d_1', + bidder: 'livewrapped', + timeStamp: 1519149562216 + } + ], + responses: [ + { + timeStamp: 1519149562216, + adUnit: 'panorama_d_1', + bidder: 'livewrapped', + width: 980, + height: 240, + cpm: 1.1, + ttr: 200, + IsBid: true + }, + { + timeStamp: 1519149562216, + adUnit: 'box_d_1', + bidder: 'livewrapped', + width: 300, + height: 250, + cpm: 2.2, + ttr: 300, + IsBid: true + } + ], + timeouts: [], + wins: [ + { + timeStamp: 1519149562216, + adUnit: 'panorama_d_1', + bidder: 'livewrapped', + width: 980, + height: 240, + cpm: 1.1 + }, + { + timeStamp: 1519149562216, + adUnit: 'box_d_1', + bidder: 'livewrapped', + width: 300, + height: 250, + cpm: 2.2 + } + ] +}; + +function performStandardAuction() { + events.emit(AUCTION_INIT, MOCK.AUCTION_INIT); + events.emit(BID_REQUESTED, MOCK.BID_REQUESTED); + events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[0]); + events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[1]); + events.emit(BIDDER_DONE, MOCK.BIDDER_DONE); + events.emit(AUCTION_END, MOCK.AUCTION_END); + events.emit(SET_TARGETING, MOCK.SET_TARGETING); + events.emit(BID_WON, MOCK.BID_WON[0]); + events.emit(BID_WON, MOCK.BID_WON[1]); +} + +describe('Livewrapped analytics adapter', function () { + let sandbox; + let xhr; + let requests; + let clock; + + beforeEach(function () { + sandbox = sinon.sandbox.create(); + + xhr = sandbox.useFakeXMLHttpRequest(); + requests = []; + xhr.onCreate = request => requests.push(request); + + sandbox.stub(events, 'getEvents').returns([]); + + clock = sandbox.useFakeTimers(1519767013781); + }); + + afterEach(function () { + sandbox.restore(); + config.resetConfig(); + }); + + describe('when handling events', function () { + adapterManager.registerAnalyticsAdapter({ + code: 'livewrapped', + adapter: livewrappedAnalyticsAdapter + }); + + beforeEach(function () { + adapterManager.enableAnalytics({ + provider: 'livewrapped', + options: { + publisherId: 'CC411485-42BC-4F92-8389-42C503EE38D7' + } + }); + }); + + afterEach(function () { + livewrappedAnalyticsAdapter.disableAnalytics(); + }); + + it('should build a batched message from prebid events', function () { + performStandardAuction(); + + clock.tick(BID_WON_TIMEOUT + 1000); + + expect(requests.length).to.equal(1); + let request = requests[0]; + + expect(request.url).to.equal('//lwadm.com/analytics/10'); + + let message = JSON.parse(request.requestBody); + + expect(message).to.deep.equal(ANALYTICS_MESSAGE); + }); + + it('should send batched message without BID_WON if necessary and further BID_WON events individually', function () { + events.emit(AUCTION_INIT, MOCK.AUCTION_INIT); + events.emit(BID_REQUESTED, MOCK.BID_REQUESTED); + events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[0]); + events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[1]); + events.emit(BIDDER_DONE, MOCK.BIDDER_DONE); + events.emit(AUCTION_END, MOCK.AUCTION_END); + events.emit(SET_TARGETING, MOCK.SET_TARGETING); + events.emit(BID_WON, MOCK.BID_WON[0]); + + clock.tick(BID_WON_TIMEOUT + 1000); + + events.emit(BID_WON, MOCK.BID_WON[1]); + + expect(requests.length).to.equal(2); + + let message = JSON.parse(requests[0].requestBody); + expect(message.wins.length).to.equal(1); + expect(message.requests).to.deep.equal(ANALYTICS_MESSAGE.requests); + expect(message.wins[0]).to.deep.equal(ANALYTICS_MESSAGE.wins[0]); + + message = JSON.parse(requests[1].requestBody); + expect(message.wins.length).to.equal(1); + expect(message.wins[0]).to.deep.equal(ANALYTICS_MESSAGE.wins[1]); + }); + + it('should properly mark bids as timed out', function () { + events.emit(AUCTION_INIT, MOCK.AUCTION_INIT); + events.emit(BID_REQUESTED, MOCK.BID_REQUESTED); + events.emit(BID_TIMEOUT, MOCK.BID_TIMEOUT); + events.emit(AUCTION_END, MOCK.AUCTION_END); + + clock.tick(BID_WON_TIMEOUT + 1000); + + expect(requests.length).to.equal(1); + + let message = JSON.parse(requests[0].requestBody); + expect(message.timeouts.length).to.equal(1); + expect(message.timeouts[0].bidder).to.equal('livewrapped'); + expect(message.timeouts[0].adUnit).to.equal('panorama_d_1'); + }); + }); +}); diff --git a/test/spec/modules/livewrappedBidAdapter_spec.js b/test/spec/modules/livewrappedBidAdapter_spec.js new file mode 100644 index 00000000000..072d374ac72 --- /dev/null +++ b/test/spec/modules/livewrappedBidAdapter_spec.js @@ -0,0 +1,633 @@ +import {expect} from 'chai'; +import {spec} from 'modules/livewrappedBidAdapter'; +import {config} from 'src/config'; +import * as utils from 'src/utils'; + +describe('Livewrapped adapter tests', function () { + let sandbox, + bidderRequest; + + beforeEach(function () { + sandbox = sinon.sandbox.create(); + + bidderRequest = { + bidderCode: 'livewrapped', + auctionId: 'c45dd708-a418-42ec-b8a7-b70a6c6fab0a', + bidderRequestId: '178e34bad3658f', + bids: [ + { + bidder: 'livewrapped', + params: { + adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + userId: 'user id', + url: 'http://www.domain.com', + seats: {'dsp': ['seat 1']} + }, + adUnitCode: 'panorama_d_1', + sizes: [[980, 240], [980, 120]], + bidId: '2ffb201a808da7', + bidderRequestId: '178e34bad3658f', + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D' + } + ], + start: 1472239426002, + auctionStart: 1472239426000, + timeout: 5000 + }; + }); + + afterEach(function () { + sandbox.restore(); + }); + + describe('isBidRequestValid', function() { + it('should accept a request with id only as valid', function() { + let bid = {params: {adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37'}}; + + let result = spec.isBidRequestValid(bid); + + expect(result).to.be.true; + }); + + it('should accept a request with adUnitName and PublisherId as valid', function() { + let bid = {params: {adUnitName: 'panorama_d_1', publisherId: '26947112-2289-405D-88C1-A7340C57E63E'}}; + + let result = spec.isBidRequestValid(bid); + + expect(result).to.be.true; + }); + + it('should accept a request with adUnitCode and PublisherId as valid', function() { + let bid = {adUnitCode: 'panorama_d_1', params: {publisherId: '26947112-2289-405D-88C1-A7340C57E63E'}}; + + let result = spec.isBidRequestValid(bid); + + expect(result).to.be.true; + }); + + it('should accept a request with placementCode and PublisherId as valid', function() { + let bid = {placementCode: 'panorama_d_1', params: {publisherId: '26947112-2289-405D-88C1-A7340C57E63E'}}; + + let result = spec.isBidRequestValid(bid); + + expect(result).to.be.true; + }); + + it('should not accept a request with adUnitName, adUnitCode, placementCode but no PublisherId as valid', function() { + let bid = {placementCode: 'panorama_d_1', adUnitCode: 'panorama_d_1', params: {adUnitName: 'panorama_d_1'}}; + + let result = spec.isBidRequestValid(bid); + + expect(result).to.be.false; + }); + }); + + describe('buildRequests', function() { + it('should make a well-formed single request object', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); + let result = spec.buildRequests(bidderRequest.bids, bidderRequest); + let data = JSON.parse(result.data); + + expect(result.url).to.equal('//lwadm.com/ad'); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + userId: 'user id', + url: 'http://www.domain.com', + seats: {'dsp': ['seat 1']}, + version: '1.1', + cookieSupport: true, + adRequests: [{ + adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + + it('should make a well-formed multiple request object', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); + let multiplebidRequest = clone(bidderRequest); + multiplebidRequest.bids.push(clone(bidderRequest.bids[0])); + multiplebidRequest.bids[1].adUnitCode = 'box_d_1'; + multiplebidRequest.bids[1].sizes = [[300, 250]]; + multiplebidRequest.bids[1].bidId = '3ffb201a808da7'; + delete multiplebidRequest.bids[1].params.adUnitId; + + let result = spec.buildRequests(multiplebidRequest.bids, multiplebidRequest); + let data = JSON.parse(result.data); + + expect(result.url).to.equal('//lwadm.com/ad'); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + userId: 'user id', + url: 'http://www.domain.com', + seats: {'dsp': ['seat 1']}, + version: '1.1', + cookieSupport: true, + adRequests: [{ + adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}] + }, { + callerAdUnitId: 'box_d_1', + bidId: '3ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 300, height: 250}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + + it('should make a well-formed single request object with AdUnitName', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); + let testbidRequest = clone(bidderRequest); + testbidRequest.bids[0].params.adUnitName = 'caller id 1'; + delete testbidRequest.bids[0].params.adUnitId; + let result = spec.buildRequests(testbidRequest.bids, testbidRequest); + let data = JSON.parse(result.data); + + expect(result.url).to.equal('//lwadm.com/ad'); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + userId: 'user id', + url: 'http://www.domain.com', + seats: {'dsp': ['seat 1']}, + version: '1.1', + cookieSupport: true, + adRequests: [{ + callerAdUnitId: 'caller id 1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + + it('should make a well-formed single request object with less parameters', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); + let testbidRequest = clone(bidderRequest); + delete testbidRequest.bids[0].params.userId; + delete testbidRequest.bids[0].params.seats; + delete testbidRequest.bids[0].params.adUnitId; + let result = spec.buildRequests(testbidRequest.bids, testbidRequest); + let data = JSON.parse(result.data); + + expect(result.url).to.equal('//lwadm.com/ad'); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + url: 'http://www.domain.com', + version: '1.1', + cookieSupport: true, + adRequests: [{ + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + + it('should make a well-formed single request object with less parameters, no publisherId', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); + let testbidRequest = clone(bidderRequest); + delete testbidRequest.bids[0].params.userId; + delete testbidRequest.bids[0].params.seats; + delete testbidRequest.bids[0].params.publisherId; + let result = spec.buildRequests(testbidRequest.bids, testbidRequest); + let data = JSON.parse(result.data); + + expect(result.url).to.equal('//lwadm.com/ad'); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + url: 'http://www.domain.com', + version: '1.1', + cookieSupport: true, + adRequests: [{ + adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + + it('should make a well-formed single request object with app parameters', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); + let testbidRequest = clone(bidderRequest); + delete testbidRequest.bids[0].params.userId; + delete testbidRequest.bids[0].params.seats; + delete testbidRequest.bids[0].params.adUnitId; + testbidRequest.bids[0].params.deviceId = 'deviceid'; + testbidRequest.bids[0].params.ifa = 'ifa'; + let result = spec.buildRequests(testbidRequest.bids, testbidRequest); + let data = JSON.parse(result.data); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + url: 'http://www.domain.com', + version: '1.1', + deviceId: 'deviceid', + ifa: 'ifa', + cookieSupport: true, + adRequests: [{ + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + + it('should make a well-formed single request object with debug parameters', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); + let testbidRequest = clone(bidderRequest); + delete testbidRequest.bids[0].params.userId; + delete testbidRequest.bids[0].params.seats; + delete testbidRequest.bids[0].params.adUnitId; + testbidRequest.bids[0].params.tid = 'tracking id'; + testbidRequest.bids[0].params.test = true; + let result = spec.buildRequests(testbidRequest.bids, testbidRequest); + let data = JSON.parse(result.data); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + url: 'http://www.domain.com', + version: '1.1', + tid: 'tracking id', + test: true, + cookieSupport: true, + adRequests: [{ + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + + it('should pass gdpr true parameters', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); + let testRequest = clone(bidderRequest); + testRequest.gdprConsent = { + gdprApplies: true, + consentString: 'test' + }; + let result = spec.buildRequests(testRequest.bids, testRequest); + let data = JSON.parse(result.data); + + expect(result.url).to.equal('//lwadm.com/ad'); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + userId: 'user id', + url: 'http://www.domain.com', + seats: {'dsp': ['seat 1']}, + version: '1.1', + cookieSupport: true, + gdprApplies: true, + gdprConsent: 'test', + adRequests: [{ + adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + + it('should pass gdpr false parameters', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); + let testRequest = clone(bidderRequest); + testRequest.gdprConsent = { + gdprApplies: false + }; + let result = spec.buildRequests(testRequest.bids, testRequest); + let data = JSON.parse(result.data); + + expect(result.url).to.equal('//lwadm.com/ad'); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + userId: 'user id', + url: 'http://www.domain.com', + seats: {'dsp': ['seat 1']}, + version: '1.1', + cookieSupport: true, + gdprApplies: false, + adRequests: [{ + adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + + it('should pass no cookie support', function() { + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => false); + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + let result = spec.buildRequests(bidderRequest.bids, bidderRequest); + let data = JSON.parse(result.data); + + expect(result.url).to.equal('//lwadm.com/ad'); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + userId: 'user id', + url: 'http://www.domain.com', + seats: {'dsp': ['seat 1']}, + version: '1.1', + cookieSupport: false, + adRequests: [{ + adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + + it('should pass no cookie support Safari', function() { + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => true); + let result = spec.buildRequests(bidderRequest.bids, bidderRequest); + let data = JSON.parse(result.data); + + expect(result.url).to.equal('//lwadm.com/ad'); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + userId: 'user id', + url: 'http://www.domain.com', + seats: {'dsp': ['seat 1']}, + version: '1.1', + cookieSupport: false, + adRequests: [{ + adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + + it('should use params.url, then config pageUrl, then getTopWindowUrl', function() { + let testRequest = clone(bidderRequest); + sandbox.stub(utils, 'getTopWindowUrl').callsFake(() => 'http://www.topurl.com'); + + let result = spec.buildRequests(testRequest.bids, testRequest); + let data = JSON.parse(result.data); + + expect(data.url).to.equal('http://www.domain.com'); + + delete testRequest.bids[0].params.url; + + result = spec.buildRequests(testRequest.bids, testRequest); + data = JSON.parse(result.data); + + expect(data.url).to.equal('http://www.topurl.com'); + + let origGetConfig = config.getConfig; + sandbox.stub(config, 'getConfig').callsFake(function (key) { + if (key === 'pageUrl') { + return 'http://www.configurl.com'; + } + return origGetConfig.apply(config, arguments); + }); + + result = spec.buildRequests(testRequest.bids, testRequest); + data = JSON.parse(result.data); + + expect(data.url).to.equal('http://www.configurl.com'); + }); + }); + + describe('interpretResponse', function () { + it('should handle single success response', function() { + let lwResponse = { + ads: [ + { + id: '28e5ddf4-3c01-11e8-86a7-0a44794250d4', + callerId: 'site_outsider_0', + tag: 'ad', + width: 300, + height: 250, + cpmBid: 2.565917, + bidId: '32e50fad901ae89', + auctionId: '13e674db-d4d8-4e19-9d28-ff38177db8bf', + creativeId: '52cbd598-2715-4c43-a06f-229fc170f945:427077', + ttl: 120 + } + ], + currency: 'USD' + }; + + let expectedResponse = [{ + requestId: '32e50fad901ae89', + bidderCode: 'livewrapped', + cpm: 2.565917, + width: 300, + height: 250, + ad: 'ad', + ttl: 120, + creativeId: '52cbd598-2715-4c43-a06f-229fc170f945:427077', + netRevenue: true, + currency: 'USD' + }]; + + let bids = spec.interpretResponse({body: lwResponse}); + + expect(bids).to.deep.equal(expectedResponse); + }) + + it('should handle multiple success response', function() { + let lwResponse = { + ads: [ + { + id: '28e5ddf4-3c01-11e8-86a7-0a44794250d4', + callerId: 'site_outsider_0', + tag: 'ad1', + width: 300, + height: 250, + cpmBid: 2.565917, + bidId: '32e50fad901ae89', + auctionId: '13e674db-d4d8-4e19-9d28-ff38177db8bf', + creativeId: '52cbd598-2715-4c43-a06f-229fc170f945:427077', + ttl: 120 + }, + { + id: '38e5ddf4-3c01-11e8-86a7-0a44794250d4', + callerId: 'site_outsider_1', + tag: 'ad2', + width: 980, + height: 240, + cpmBid: 3.565917, + bidId: '42e50fad901ae89', + auctionId: '13e674db-d4d8-4e19-9d28-ff38177db8bf', + creativeId: '62cbd598-2715-4c43-a06f-229fc170f945:427077', + ttl: 120 + } + ], + currency: 'USD' + }; + + let expectedResponse = [{ + requestId: '32e50fad901ae89', + bidderCode: 'livewrapped', + cpm: 2.565917, + width: 300, + height: 250, + ad: 'ad1', + ttl: 120, + creativeId: '52cbd598-2715-4c43-a06f-229fc170f945:427077', + netRevenue: true, + currency: 'USD' + }, { + requestId: '42e50fad901ae89', + bidderCode: 'livewrapped', + cpm: 3.565917, + width: 980, + height: 240, + ad: 'ad2', + ttl: 120, + creativeId: '62cbd598-2715-4c43-a06f-229fc170f945:427077', + netRevenue: true, + currency: 'USD' + }]; + + let bids = spec.interpretResponse({body: lwResponse}); + + expect(bids).to.deep.equal(expectedResponse); + }) + }); + + describe('user sync', function () { + let serverResponses; + + beforeEach(function () { + serverResponses = [{ + body: { + pixels: [ + {type: 'Redirect', url: 'http://pixelsync'}, + {type: 'Iframe', url: 'http://iframesync'} + ] + } + }]; + }); + + it('should return empty if no server responses', function() { + let syncs = spec.getUserSyncs({ + pixelEnabled: true, + iframeEnabled: true + }, []); + + let expectedResponse = []; + + expect(syncs).to.deep.equal(expectedResponse) + }); + + it('should return empty if no user sync', function() { + let syncs = spec.getUserSyncs({ + pixelEnabled: true, + iframeEnabled: true + }, [{body: {}}]); + + let expectedResponse = []; + + expect(syncs).to.deep.equal(expectedResponse) + }); + + it('should returns pixel and iframe user sync', function() { + let syncs = spec.getUserSyncs({ + pixelEnabled: true, + iframeEnabled: true + }, serverResponses); + + let expectedResponse = [{type: 'image', url: 'http://pixelsync'}, {type: 'iframe', url: 'http://iframesync'}]; + + expect(syncs).to.deep.equal(expectedResponse) + }); + + it('should returns pixel only if iframe not supported user sync', function() { + let syncs = spec.getUserSyncs({ + pixelEnabled: true, + iframeEnabled: false + }, serverResponses); + + let expectedResponse = [{type: 'image', url: 'http://pixelsync'}]; + + expect(syncs).to.deep.equal(expectedResponse) + }); + + it('should returns iframe only if pixel not supported user sync', function() { + let syncs = spec.getUserSyncs({ + pixelEnabled: false, + iframeEnabled: true + }, serverResponses); + + let expectedResponse = [{type: 'iframe', url: 'http://iframesync'}]; + + expect(syncs).to.deep.equal(expectedResponse) + }); + }); +}); + +function clone(obj) { + return JSON.parse(JSON.stringify(obj)); +} diff --git a/test/spec/modules/liveyieldAnalyticsAdapter_spec.js b/test/spec/modules/liveyieldAnalyticsAdapter_spec.js new file mode 100644 index 00000000000..61d9d9e5de0 --- /dev/null +++ b/test/spec/modules/liveyieldAnalyticsAdapter_spec.js @@ -0,0 +1,399 @@ +import CONSTANTS from 'src/constants.json'; +import liveyield from 'modules/liveyieldAnalyticsAdapter'; +import { expect } from 'chai'; +const events = require('src/events'); + +const { + EVENTS: { BID_REQUESTED, BID_TIMEOUT, BID_RESPONSE, BID_WON } +} = CONSTANTS; + +describe('liveyield analytics adapter', function() { + const rtaCalls = []; + + window.rta = function() { + rtaCalls.push({ callArgs: arguments }); + }; + + beforeEach(function() { + sinon.stub(events, 'getEvents').returns([]); + }); + afterEach(function() { + events.getEvents.restore(); + }); + describe('initialization', function() { + afterEach(function() { + rtaCalls.length = 0; + }); + it('it should require provider', function() { + liveyield.enableAnalytics({}); + expect(rtaCalls).to.be.empty; + }); + it('should require config.options', function() { + liveyield.enableAnalytics({ provider: 'liveyield' }); + expect(rtaCalls).to.be.empty; + }); + it('should require options.customerId', function() { + liveyield.enableAnalytics({ provider: 'liveyield', options: {} }); + expect(rtaCalls).to.be.empty; + }); + it('should require options.customerName', function() { + liveyield.enableAnalytics({ + provider: 'liveyield', + options: { + customerId: 'd6a6f8da-190f-47d6-ae11-f1a4469083fa' + } + }) + expect(rtaCalls).to.be.empty; + }); + it('should require options.customerSite', function() { + liveyield.enableAnalytics({ + provider: 'liveyield', + options: { + customerId: 'd6a6f8da-190f-47d6-ae11-f1a4469083fa', + customerName: 'pubocean' + } + }); + expect(rtaCalls).to.be.empty; + }); + it('should require options.sessionTimezoneOffset', function() { + liveyield.enableAnalytics({ + provider: 'liveyield', + options: { + customerId: 'd6a6f8da-190f-47d6-ae11-f1a4469083fa', + customerName: 'pubocean', + customerSite: 'scribol.com' + } + }); + expect(rtaCalls).to.be.empty; + }); + it("should throw error, when 'rta' function is not defined ", function() { + const keepMe = window.rta; + + delete window.rta; + + liveyield.enableAnalytics({ + provider: 'liveyield', + options: { + customerId: 'd6a6f8da-190f-47d6-ae11-f1a4469083fa', + customerName: 'pubocean', + customerSite: 'scribol.com', + sessionTimezoneOffset: 12 + } + }); + expect(rtaCalls).to.be.empty; + + window.rta = keepMe; + }); + it('should initialize when all required parameters are passed', function() { + liveyield.enableAnalytics({ + provider: 'liveyield', + options: { + customerId: 'd6a6f8da-190f-47d6-ae11-f1a4469083fa', + customerName: 'pubocean', + customerSite: 'scribol.com', + sessionTimezoneOffset: 12 + } + }); + expect(rtaCalls[0].callArgs['0']).to.match(/create/); + expect(rtaCalls[0].callArgs['1']).to.match( + /d6a6f8da-190f-47d6-ae11-f1a4469083fa/ + ); + expect(rtaCalls[0].callArgs['2']).to.match(/pubocean/); + expect(rtaCalls[0].callArgs['4']).to.match(/12/); + liveyield.disableAnalytics(); + }); + it('should allow to redefine rta function name', function() { + const keepMe = window.rta; + window.abc = keepMe; + delete window.rta; + liveyield.enableAnalytics({ + provider: 'liveyield', + options: { + rtaFunctionName: 'abc', + customerId: 'd6a6f8da-190f-47d6-ae11-f1a4469083fa', + customerName: 'test', + customerSite: 'scribol.com', + sessionTimezoneOffset: 25 + } + }); + + liveyield.disableAnalytics(); + expect(rtaCalls[0].callArgs['0']).to.match(/create/); + expect(rtaCalls[0].callArgs['1']).to.match( + /d6a6f8da-190f-47d6-ae11-f1a4469083fa/ + ); + expect(rtaCalls[0].callArgs['2']).to.match(/test/); + expect(rtaCalls[0].callArgs['4']).to.match(/25/); + + window.rta = keepMe; + liveyield.disableAnalytics(); + }); + it('should handle custom parameters', function() { + liveyield.enableAnalytics({ + provider: 'liveyield', + options: { + customerId: 'd6a6f8da-190f-47d6-ae11-f1a4469083fa', + customerName: 'test2', + customerSite: 'scribol.com', + sessionTimezoneOffset: 38, + contentTitle: 'testTitle', + contentAuthor: 'testAuthor', + contentCategory: 'testCategory' + } + }); + + liveyield.disableAnalytics(); + expect(rtaCalls[0].callArgs['0']).to.match(/create/); + expect(rtaCalls[0].callArgs['2']).to.match(/test2/); + expect(rtaCalls[0].callArgs['4']).to.match(/38/); + expect(rtaCalls[0].callArgs['5'].contentTitle).to.match(/testTitle/); + expect(rtaCalls[0].callArgs['5'].contentAuthor).to.match(/testAuthor/); + expect(rtaCalls[0].callArgs['5'].contentCategory).to.match( + /testCategory/ + ); + liveyield.disableAnalytics(); + }); + }); + + describe('handling events', function() { + const options = { + provider: 'liveyield', + options: { + customerId: 'd6a6f8da-190f-47d6-ae11-f1a4469083fa', + customerName: 'pubocean', + customerSite: 'scribol.com', + sessionTimezoneOffset: 12 + } + }; + beforeEach(function() { + rtaCalls.length = 0; + liveyield.enableAnalytics(options); + }); + afterEach(function() { + liveyield.disableAnalytics(); + }); + it('should handle BID_REQUESTED event', function() { + const bidRequest = { + bidderCode: 'appnexus', + bids: [ + { + params: { + placementId: '10433394' + }, + adUnitCode: 'div-gpt-ad-1438287399331-0', + transactionId: '2f481ff1-8d20-4c28-8e36-e384e9e3eec6', + sizes: '300x250,300x600', + bidId: '2eddfdc0c791dc', + auctionId: 'a5b849e5-87d7-4205-8300-d063084fcfb7' + } + ] + }; + + events.emit(BID_REQUESTED, bidRequest); + expect(rtaCalls[1].callArgs['0']).to.equal('bidRequested'); + expect(rtaCalls[1].callArgs['1']).to.equal('div-gpt-ad-1438287399331-0'); + expect(rtaCalls[1].callArgs['2']).to.equal('appnexus'); + }); + it('should handle BID_REQUESTED event with invalid args', function() { + const bidRequest = { + bids: [ + { + params: { + placementId: '10433394' + }, + transactionId: '2f481ff1-8d20-4c28-8e36-e384e9e3eec6', + sizes: '300x250,300x600', + bidId: '2eddfdc0c791dc', + auctionId: 'a5b849e5-87d7-4205-8300-d063084fcf' + }, + { + params: { + placementId: '31034023' + }, + transactionId: '2f481ff1-8d20-4c28-8e36-e384e9e3eec6', + sizes: '300x250,300x600', + bidId: '3dkg0404fmd0', + auctionId: 'a5b849e5-87d7-4205-8300-d063084fcf' + } + ] + }; + events.emit(BID_REQUESTED, bidRequest); + expect(rtaCalls[1].callArgs['0']).to.equal('bidRequested'); + expect(rtaCalls[1].callArgs['1']).to.equal(undefined); + expect(rtaCalls[1].callArgs['2']).to.equal(undefined); + expect(rtaCalls[1].callArgs['0']).to.equal('bidRequested'); + }); + it('should handle BID_RESPONSE event', function() { + const bidResponse = { + height: 250, + statusMessage: 'Bid available', + adId: '2eddfdc0c791dc', + mediaType: 'banner', + source: 'client', + requestId: '2eddfdc0c791dc', + cpm: 0.5, + creativeId: 29681110, + currency: 'USD', + netRevenue: true, + ttl: 300, + auctionId: 'a5b849e5-87d7-4205-8300-d063084fcfb7', + responseTimestamp: 1522265866110, + requestTimestamp: 1522265863600, + bidder: 'appnexus', + adUnitCode: 'div-gpt-ad-1438287399331-0', + timeToRespond: 2510, + size: '300x250' + }; + + events.emit(BID_RESPONSE, bidResponse); + expect(rtaCalls[1].callArgs['0']).to.equal('addBid'); + expect(rtaCalls[1].callArgs['1']).to.equal('div-gpt-ad-1438287399331-0'); + expect(rtaCalls[1].callArgs['2']).to.equal('appnexus'); + expect(rtaCalls[1].callArgs['3']).to.equal(500); + expect(rtaCalls[1].callArgs['4']).to.equal(false); + expect(rtaCalls[1].callArgs['5']).to.equal(false); + }); + it('should handle BID_RESPONSE event with undefined bidder and cpm', function() { + const bidResponse = { + height: 250, + statusMessage: 'Bid available', + adId: '2eddfdc0c791dc', + mediaType: 'banner', + source: 'client', + requestId: '2eddfdc0c791dc', + creativeId: 29681110, + currency: 'USD', + netRevenue: true, + ttl: 300, + auctionId: 'a5b849e5-87d7-4205-8300-d063084fcfb7', + responseTimestamp: 1522265866110, + requestTimestamp: 1522265863600, + adUnitCode: 'div-gpt-ad-1438287399331-0', + timeToRespond: 2510, + size: '300x250' + }; + events.emit(BID_RESPONSE, bidResponse); + expect(rtaCalls[1].callArgs['0']).to.equal('addBid'); + expect(rtaCalls[1].callArgs['2']).to.equal('unknown'); + expect(rtaCalls[1].callArgs['3']).to.equal(0); + expect(rtaCalls[1].callArgs['4']).to.equal(true); + }); + it('should handle BID_RESPONSE event with undefined status message and adUnitCode', function() { + const bidResponse = { + height: 250, + adId: '2eddfdc0c791dc', + mediaType: 'banner', + source: 'client', + requestId: '2eddfdc0c791dc', + cpm: 0.5, + creativeId: 29681110, + currency: 'USD', + netRevenue: true, + ttl: 300, + auctionId: 'a5b849e5-87d7-4205-8300-d063084fcfb7', + responseTimestamp: 1522265866110, + requestTimestamp: 1522265863600, + bidder: 'appnexus', + timeToRespond: 2510, + size: '300x250' + }; + events.emit(BID_RESPONSE, bidResponse); + expect(rtaCalls[1].callArgs['0']).to.equal('addBid'); + expect(rtaCalls[1].callArgs['1']).to.equal(undefined); + expect(rtaCalls[1].callArgs['3']).to.equal(0); + expect(rtaCalls[1].callArgs['5']).to.equal(true); + }); + it('should handle BID_TIMEOUT', function() { + const bidTimeout = [ + { + bidId: '2baa51527bd015', + bidder: 'bidderOne', + adUnitCode: '/19968336/header-bid-tag-0', + auctionId: '66529d4c-8998-47c2-ab3e-5b953490b98f' + }, + { + bidId: '6fe3b4c2c23092', + bidder: 'bidderTwo', + adUnitCode: '/19968336/header-bid-tag-0', + auctionId: '66529d4c-8998-47c2-ab3e-5b953490b98f' + } + ]; + events.emit(BID_TIMEOUT, bidTimeout); + expect(rtaCalls[1].callArgs['0']).to.equal('biddersTimeout'); + expect(rtaCalls[1].callArgs['1'].length).to.equal(2); + }); + it('should handle BID_WON event', function() { + const bidWon = { + adId: '4587fec4900b81', + mediaType: 'banner', + requestId: '4587fec4900b81', + cpm: 1.962, + creativeId: 2126, + currency: 'EUR', + netRevenue: true, + ttl: 302, + auctionId: '914bedad-b145-4e46-ba58-51365faea6cb', + statusMessage: 'Bid available', + responseTimestamp: 1530628534437, + requestTimestamp: 1530628534219, + bidderCode: 'testbidder4', + adUnitCode: 'div-gpt-ad-1438287399331-0', + timeToRespond: 218, + size: '300x250', + status: 'rendered' + }; + events.emit(BID_WON, bidWon); + expect(rtaCalls[1].callArgs['0']).to.equal('resolveSlot'); + expect(rtaCalls[1].callArgs['1']).to.equal( + 'div-gpt-ad-1438287399331-0' + ); + expect(rtaCalls[1].callArgs['2'].prebidWon).to.equal(true); + expect(rtaCalls[1].callArgs['2'].prebidPartner).to.equal('testbidder4'); + expect(rtaCalls[1].callArgs['2'].prebidValue).to.equal(1962); + }); + it('should throw error, invoking BID_WON event without adUnitCode', function() { + const bidWon = { + adId: '4587fec4900b81', + mediaType: 'banner', + requestId: '4587fec4900b81', + cpm: 1.962, + creativeId: 2126, + currency: 'EUR', + netRevenue: true, + ttl: 302, + auctionId: '914bedad-b145-4e46-ba58-51365faea6cb', + statusMessage: 'Bid available', + responseTimestamp: 1530628534437, + requestTimestamp: 1530628534219, + timeToRespond: 218, + bidderCode: 'testbidder4', + size: '300x250', + status: 'rendered' + }; + events.emit(BID_WON, bidWon); + expect(rtaCalls[1]).to.be.undefined; + }); + it('should throw error, invoking BID_WON event without bidderCode', function() { + const bidWon = { + adId: '4587fec4900b81', + mediaType: 'banner', + requestId: '4587fec4900b81', + cpm: 1.962, + creativeId: 2126, + currency: 'EUR', + netRevenue: true, + ttl: 302, + auctionId: '914bedad-b145-4e46-ba58-51365faea6cb', + statusMessage: 'Bid available', + responseTimestamp: 1530628534437, + requestTimestamp: 1530628534219, + adUnitCode: 'div-gpt-ad-1438287399331-0', + timeToRespond: 218, + size: '300x250', + status: 'rendered' + }; + events.emit(BID_WON, bidWon); + expect(rtaCalls[1]).to.be.undefined; + }); + }); +}); diff --git a/test/spec/modules/lkqdBidAdapter_spec.js b/test/spec/modules/lkqdBidAdapter_spec.js index a5e75086229..0cebb2651a9 100644 --- a/test/spec/modules/lkqdBidAdapter_spec.js +++ b/test/spec/modules/lkqdBidAdapter_spec.js @@ -2,16 +2,16 @@ import { spec } from 'modules/lkqdBidAdapter'; import { newBidder } from 'src/adapters/bidderFactory'; const { expect } = require('chai'); -describe('LKQD Bid Adapter Test', () => { +describe('LKQD Bid Adapter Test', function () { const adapter = newBidder(spec); - describe('inherited functions', () => { - it('exists and is a function', () => { + describe('inherited functions', function () { + it('exists and is a function', function () { expect(adapter.callBids).to.exist.and.to.be.a('function'); }); }); - describe('isBidRequestValid', () => { + describe('isBidRequestValid', function () { let bid = { 'bidder': 'lkqd', 'params': { @@ -26,11 +26,11 @@ describe('LKQD Bid Adapter Test', () => { 'transactionId': 'd6f6b392-54a9-454c-85fb-a2fd882c4a2d', }; - it('should return true when required params found', () => { + it('should return true when required params found', function () { expect(spec.isBidRequestValid(bid)).to.equal(true); }); - it('should return false when required params are not passed', () => { + it('should return false when required params are not passed', function () { let bid = Object.assign({}, bid); delete bid.params; bid.params = { @@ -40,7 +40,7 @@ describe('LKQD Bid Adapter Test', () => { }); }); - describe('buildRequests', () => { + describe('buildRequests', function () { const ENDPOINT = 'https://v.lkqd.net/ad'; let bidRequests = [ { @@ -73,7 +73,7 @@ describe('LKQD Bid Adapter Test', () => { } ]; - it('should populate available parameters', () => { + it('should populate available parameters', function () { const requests = spec.buildRequests(bidRequests); expect(requests.length).to.equal(2); const r1 = requests[0].data; @@ -96,7 +96,7 @@ describe('LKQD Bid Adapter Test', () => { expect(r2.height).to.equal(480); }); - it('should not populate unspecified parameters', () => { + it('should not populate unspecified parameters', function () { const requests = spec.buildRequests(bidRequests); expect(requests.length).to.equal(2); const r1 = requests[0].data; @@ -115,7 +115,7 @@ describe('LKQD Bid Adapter Test', () => { expect(r2).to.not.have.property('contenturl'); }); - it('should handle single size request', () => { + it('should handle single size request', function () { const requests = spec.buildRequests(bidRequest); expect(requests.length).to.equal(1); const r1 = requests[0].data; @@ -129,7 +129,7 @@ describe('LKQD Bid Adapter Test', () => { expect(r1.height).to.equal(480); }); - it('sends bid request to ENDPOINT via GET', () => { + it('sends bid request to ENDPOINT via GET', function () { const requests = spec.buildRequests(bidRequests); expect(requests.length).to.equal(2); const r1 = requests[0]; @@ -141,7 +141,7 @@ describe('LKQD Bid Adapter Test', () => { }); }); - describe('interpretResponse', () => { + describe('interpretResponse', function () { let bidRequest = { 'url': 'https://ssp.lkqd.net/ad?pid=263&sid=662921&output=vast&execution=any&placement=&playinit=auto&volume=100&timeout=&width=300%E2%80%8C&height=250&pbt=[PREBID_TOKEN]%E2%80%8C&dnt=[DO_NOT_TRACK]%E2%80%8C&pageurl=[PAGEURL]%E2%80%8C&contentid=[CONTENT_ID]%E2%80%8C&contenttitle=[CONTENT_TITLE]%E2%80%8C&contentlength=[CONTENT_LENGTH]%E2%80%8C&contenturl=[CONTENT_URL]&prebid=true%E2%80%8C&rnd=874313435?bidId=253dcb69fb2577&bidWidth=300&bidHeight=250&', 'data': { @@ -322,7 +322,7 @@ https://creative.lkqd.net/internal/lkqd_300x250.mp4 `; - it('should correctly parse valid bid response', () => { + it('should correctly parse valid bid response', function () { const BIDDER_CODE = 'lkqd'; let bidResponses = spec.interpretResponse(serverResponse, bidRequest); expect(bidResponses.length).to.equal(1); @@ -340,7 +340,7 @@ https://creative.lkqd.net/internal/lkqd_300x250.mp4 expect(bidResponse.mediaType).to.equal('video'); }); - it('safely handles XML parsing failure from invalid bid response', () => { + it('safely handles XML parsing failure from invalid bid response', function () { let invalidServerResponse = {}; invalidServerResponse.body = ''; @@ -348,7 +348,7 @@ https://creative.lkqd.net/internal/lkqd_300x250.mp4 expect(result.length).to.equal(0); }); - it('handles nobid responses', () => { + it('handles nobid responses', function () { let nobidResponse = {}; nobidResponse.body = ''; diff --git a/test/spec/modules/lockerdomeBidAdapter_spec.js b/test/spec/modules/lockerdomeBidAdapter_spec.js index 84f0dd43e72..1cd6778b01f 100644 --- a/test/spec/modules/lockerdomeBidAdapter_spec.js +++ b/test/spec/modules/lockerdomeBidAdapter_spec.js @@ -2,7 +2,7 @@ import { expect } from 'chai'; import { spec } from '../../../modules/lockerdomeBidAdapter'; import * as utils from 'src/utils'; -describe('LockerDomeAdapter', () => { +describe('LockerDomeAdapter', function () { const bidRequests = [{ bidder: 'lockerdome', params: { @@ -37,20 +37,20 @@ describe('LockerDomeAdapter', () => { auctionId: 'd4c83108-615d-4c2c-9384-dac9ffd4fd72' }]; - describe('isBidRequestValid', () => { - it('should return true if the adUnitId parameter is present', () => { + describe('isBidRequestValid', function () { + it('should return true if the adUnitId parameter is present', function () { expect(spec.isBidRequestValid(bidRequests[0])).to.be.true; expect(spec.isBidRequestValid(bidRequests[1])).to.be.true; }); - it('should return false if the adUnitId parameter is not present', () => { + it('should return false if the adUnitId parameter is not present', function () { let bidRequest = utils.deepClone(bidRequests[0]); delete bidRequest.params.adUnitId; expect(spec.isBidRequestValid(bidRequest)).to.be.false; }); }); - describe('buildRequests', () => { - it('should generate a valid single POST request for multiple bid requests', () => { + describe('buildRequests', function () { + it('should generate a valid single POST request for multiple bid requests', function () { const request = spec.buildRequests(bidRequests); expect(request.method).to.equal('POST'); expect(request.url).to.equal('https://lockerdome.com/ladbid/prebid'); @@ -65,19 +65,21 @@ describe('LockerDomeAdapter', () => { expect(bids).to.have.lengthOf(2); expect(bids[0].requestId).to.equal('2652ca954bce9'); + expect(bids[0].adUnitCode).to.equal('ad-1'); expect(bids[0].adUnitId).to.equal(10809467961050726); expect(bids[0].sizes).to.have.lengthOf(1); expect(bids[0].sizes[0][0]).to.equal(300); expect(bids[0].sizes[0][1]).to.equal(250); expect(bids[1].requestId).to.equal('4510f2834773ce'); + expect(bids[1].adUnitCode).to.equal('ad-2'); expect(bids[1].adUnitId).to.equal(9434769725128806); expect(bids[1].sizes).to.have.lengthOf(1); expect(bids[1].sizes[0][0]).to.equal(300); expect(bids[1].sizes[0][1]).to.equal(600); }); - it('should add GDPR data to request if available', () => { + it('should add GDPR data to request if available', function () { const bidderRequest = { gdprConsent: { consentString: 'AAABBB', @@ -93,13 +95,13 @@ describe('LockerDomeAdapter', () => { }); }); - describe('interpretResponse', () => { - it('should return an empty array if an invalid response is passed', () => { + describe('interpretResponse', function () { + it('should return an empty array if an invalid response is passed', function () { const interpretedResponse = spec.interpretResponse({ body: {} }); expect(interpretedResponse).to.be.an('array').that.is.empty; }); - it('should return valid response when passed valid server response', () => { + it('should return valid response when passed valid server response', function () { const serverResponse = { body: { bids: [{ diff --git a/test/spec/modules/madvertiseBidAdapter_spec.js b/test/spec/modules/madvertiseBidAdapter_spec.js index c391ca1d39f..b2a08410532 100644 --- a/test/spec/modules/madvertiseBidAdapter_spec.js +++ b/test/spec/modules/madvertiseBidAdapter_spec.js @@ -3,9 +3,9 @@ import {config} from 'src/config'; import * as utils from 'src/utils'; import {spec} from 'modules/madvertiseBidAdapter'; -describe('madvertise adapater', () => { - describe('Test validate req', () => { - it('should accept minimum valid bid', () => { +describe('madvertise adapater', function () { + describe('Test validate req', function () { + it('should accept minimum valid bid', function () { let bid = { bidder: 'madvertise', sizes: [[728, 90]], @@ -17,7 +17,7 @@ describe('madvertise adapater', () => { expect(isValid).to.equal(true); }); - it('should reject no sizes', () => { + it('should reject no sizes', function () { let bid = { bidder: 'madvertise', params: { @@ -28,7 +28,7 @@ describe('madvertise adapater', () => { expect(isValid).to.equal(false); }); - it('should reject empty sizes', () => { + it('should reject empty sizes', function () { let bid = { bidder: 'madvertise', sizes: [], @@ -40,7 +40,7 @@ describe('madvertise adapater', () => { expect(isValid).to.equal(false); }); - it('should reject wrong format sizes', () => { + it('should reject wrong format sizes', function () { let bid = { bidder: 'madvertise', sizes: [['728x90']], @@ -51,7 +51,7 @@ describe('madvertise adapater', () => { const isValid = spec.isBidRequestValid(bid); expect(isValid).to.equal(false); }); - it('should reject no params', () => { + it('should reject no params', function () { let bid = { bidder: 'madvertise', sizes: [[728, 90]] @@ -60,7 +60,7 @@ describe('madvertise adapater', () => { expect(isValid).to.equal(false); }); - it('should reject missing s', () => { + it('should reject missing s', function () { let bid = { bidder: 'madvertise', params: {} @@ -71,7 +71,7 @@ describe('madvertise adapater', () => { }); }); - describe('Test build request', () => { + describe('Test build request', function () { beforeEach(function () { let mockConfig = { consentManagement: { @@ -100,7 +100,7 @@ describe('madvertise adapater', () => { s: 'test', } }]; - it('minimum request with gdpr consent', () => { + it('minimum request with gdpr consent', function () { let bidderRequest = { gdprConsent: { consentString: 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==', @@ -122,7 +122,7 @@ describe('madvertise adapater', () => { expect(req[0].url).to.contain(`&consent[0][value]=BOJ/P2HOJ/P2HABABMAAAAAZ+A==`) }); - it('minimum request without gdpr consent', () => { + it('minimum request without gdpr consent', function () { let bidderRequest = {}; const req = spec.buildRequests(bid, bidderRequest); @@ -139,8 +139,8 @@ describe('madvertise adapater', () => { }); }); - describe('Test interpret response', () => { - it('General banner response', () => { + describe('Test interpret response', function () { + it('General banner response', function () { let bid = { bidder: 'madvertise', sizes: [[728, 90]], @@ -180,7 +180,7 @@ describe('madvertise adapater', () => { expect(resp[0]).to.have.property('currency', 'EUR'); expect(resp[0]).to.have.property('dealId', 'DEAL_ID'); }); - it('No response', () => { + it('No response', function () { let bid = { bidder: 'madvertise', sizes: [[728, 90]], diff --git a/test/spec/modules/mantisBidAdapter_spec.js b/test/spec/modules/mantisBidAdapter_spec.js index 46cb413597e..464cea2aab3 100644 --- a/test/spec/modules/mantisBidAdapter_spec.js +++ b/test/spec/modules/mantisBidAdapter_spec.js @@ -2,10 +2,10 @@ import {expect} from 'chai'; import {spec} from 'modules/mantisBidAdapter'; import {newBidder} from 'src/adapters/bidderFactory'; -describe('MantisAdapter', () => { +describe('MantisAdapter', function () { const adapter = newBidder(spec); - describe('isBidRequestValid', () => { + describe('isBidRequestValid', function () { let bid = { 'bidder': 'mantis', 'params': { @@ -19,11 +19,11 @@ describe('MantisAdapter', () => { 'auctionId': '1d1a030790a475', }; - it('should return true when required params found', () => { + it('should return true when required params found', function () { expect(spec.isBidRequestValid(bid)).to.equal(true); }); - it('should return false when required params are not passed', () => { + it('should return false when required params are not passed', function () { let bid = Object.assign({}, bid); delete bid.params; bid.params = {}; @@ -31,7 +31,7 @@ describe('MantisAdapter', () => { }); }); - describe('buildRequests', () => { + describe('buildRequests', function () { let bidRequests = [ { 'bidder': 'mantis', @@ -47,7 +47,7 @@ describe('MantisAdapter', () => { } ]; - it('domain override', () => { + it('domain override', function () { window.mantis_domain = 'http://foo'; const request = spec.buildRequests(bidRequests); @@ -56,7 +56,7 @@ describe('MantisAdapter', () => { delete window.mantis_domain; }); - it('standard request', () => { + it('standard request', function () { const request = spec.buildRequests(bidRequests); expect(request.url).to.include('property=10433394'); @@ -68,7 +68,7 @@ describe('MantisAdapter', () => { expect(request.url).to.include('bids[0][sizes][1][height]=600'); }); - it('use window uuid', () => { + it('use window uuid', function () { window.mantis_uuid = 'foo'; const request = spec.buildRequests(bidRequests); @@ -78,7 +78,7 @@ describe('MantisAdapter', () => { delete window.mantis_uuid; }); - it('use storage uuid', () => { + it('use storage uuid', function () { window.localStorage.setItem('mantis:uuid', 'bar'); const request = spec.buildRequests(bidRequests); @@ -88,7 +88,7 @@ describe('MantisAdapter', () => { window.localStorage.removeItem('mantis:uuid'); }); - it('detect amp', () => { + it('detect amp', function () { var oldContext = window.context; window.context = {}; @@ -107,8 +107,8 @@ describe('MantisAdapter', () => { }); }); - describe('getUserSyncs', () => { - it('iframe', () => { + describe('getUserSyncs', function () { + it('iframe', function () { let result = spec.getUserSyncs({ iframeEnabled: true }); @@ -117,7 +117,7 @@ describe('MantisAdapter', () => { expect(result[0].url).to.include('https://mantodea.mantisadnetwork.com/prebid/iframe'); }); - it('pixel', () => { + it('pixel', function () { let result = spec.getUserSyncs({ pixelEnabled: true }); @@ -127,8 +127,8 @@ describe('MantisAdapter', () => { }); }); - describe('interpretResponse', () => { - it('display ads returned', () => { + describe('interpretResponse', function () { + it('display ads returned', function () { let response = { body: { uuid: 'uuid', @@ -166,7 +166,7 @@ describe('MantisAdapter', () => { expect(window.localStorage.getItem('mantis:uuid')).to.equal(response.body.uuid); }); - it('no ads returned', () => { + it('no ads returned', function () { let response = { body: { ads: [] diff --git a/test/spec/modules/medianetBidAdapter_spec.js b/test/spec/modules/medianetBidAdapter_spec.js index d94cb64c145..331b36b3217 100644 --- a/test/spec/modules/medianetBidAdapter_spec.js +++ b/test/spec/modules/medianetBidAdapter_spec.js @@ -17,7 +17,8 @@ let VALID_BID_REQUEST = [{ 'sizes': [[300, 250]], 'bidId': '28f8f8130a583e', 'bidderRequestId': '1e9b1f07797c1c', - 'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d' + 'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', + 'bidRequestsCount': 1 }, { 'bidder': 'medianet', 'params': { @@ -33,7 +34,8 @@ let VALID_BID_REQUEST = [{ 'sizes': [[300, 251]], 'bidId': '3f97ca71b1e5c2', 'bidderRequestId': '1e9b1f07797c1c', - 'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d' + 'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', + 'bidRequestsCount': 1 }], VALID_BID_REQUEST_INVALID_BIDFLOOR = [{ 'bidder': 'medianet', @@ -51,7 +53,8 @@ let VALID_BID_REQUEST = [{ 'sizes': [[300, 250]], 'bidId': '28f8f8130a583e', 'bidderRequestId': '1e9b1f07797c1c', - 'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d' + 'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', + 'bidRequestsCount': 1 }, { 'bidder': 'medianet', 'params': { @@ -67,7 +70,8 @@ let VALID_BID_REQUEST = [{ 'sizes': [[300, 251]], 'bidId': '3f97ca71b1e5c2', 'bidderRequestId': '1e9b1f07797c1c', - 'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d' + 'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', + 'bidRequestsCount': 1 }], VALID_AUCTIONDATA = { 'timeout': config.getConfig('bidderTimeout'), @@ -103,7 +107,8 @@ let VALID_BID_REQUEST = [{ x: 100, y: 100 } - } + }, + 'display_count': 1 }, 'banner': [{ 'w': 300, @@ -133,7 +138,8 @@ let VALID_BID_REQUEST = [{ x: 100, y: 100 } - } + }, + 'display_count': 1 }, 'banner': [{ 'w': 300, @@ -181,7 +187,8 @@ let VALID_BID_REQUEST = [{ x: 100, y: 100 } - } + }, + 'display_count': 1 }, 'banner': [{ 'w': 300, @@ -210,7 +217,8 @@ let VALID_BID_REQUEST = [{ x: 100, y: 100 } - } + }, + 'display_count': 1 }, 'banner': [{ 'w': 300, @@ -372,7 +380,8 @@ let VALID_BID_REQUEST = [{ 'sizes': [300, 250], 'bidId': '28f8f8130a583e', 'bidderRequestId': '1e9b1f07797c1c', - 'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d' + 'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', + 'bidRequestsCount': 1 }, { 'bidder': 'medianet', 'params': { @@ -388,7 +397,8 @@ let VALID_BID_REQUEST = [{ 'sizes': [300, 251], 'bidId': '3f97ca71b1e5c2', 'bidderRequestId': '1e9b1f07797c1c', - 'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d' + 'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', + 'bidRequestsCount': 1 }], VALID_BIDDER_REQUEST_WITH_GDPR = { 'gdprConsent': { @@ -429,7 +439,8 @@ let VALID_BID_REQUEST = [{ x: 100, y: 100 } - } + }, + 'display_count': 1 }, 'banner': [{ 'w': 300, @@ -458,7 +469,8 @@ let VALID_BID_REQUEST = [{ x: 100, y: 100 } - } + }, + 'display_count': 1 }, 'banner': [{ 'w': 300, @@ -476,40 +488,40 @@ let VALID_BID_REQUEST = [{ 'tmax': 3000, }; -describe('Media.net bid adapter', () => { +describe('Media.net bid adapter', function () { let sandbox; - beforeEach(() => { + beforeEach(function () { sandbox = sinon.sandbox.create(); }); - afterEach(() => { + afterEach(function () { sandbox.restore(); }); - describe('isBidRequestValid', () => { - it('should accept valid bid params', () => { + describe('isBidRequestValid', function () { + it('should accept valid bid params', function () { let isValid = spec.isBidRequestValid(VALID_PARAMS); expect(isValid).to.equal(true); }); - it('should reject bid if cid is not present', () => { + it('should reject bid if cid is not present', function () { let isValid = spec.isBidRequestValid(PARAMS_WITHOUT_CID); expect(isValid).to.equal(false); }); - it('should reject bid if cid is not a string', () => { + it('should reject bid if cid is not a string', function () { let isValid = spec.isBidRequestValid(PARAMS_WITH_INTEGER_CID); expect(isValid).to.equal(false); }); - it('should reject bid if cid is a empty string', () => { + it('should reject bid if cid is a empty string', function () { let isValid = spec.isBidRequestValid(PARAMS_WITH_EMPTY_CID); expect(isValid).to.equal(false); }); }); - describe('buildRequests', () => { - beforeEach(() => { + describe('buildRequests', function () { + beforeEach(function () { let documentStub = sandbox.stub(document, 'getElementById'); let boundingRect = { top: 50, @@ -530,27 +542,30 @@ describe('Media.net bid adapter', () => { }); }); - it('should build valid payload on bid', () => { + it('should build valid payload on bid', function () { let requestObj = spec.buildRequests(VALID_BID_REQUEST, VALID_AUCTIONDATA); expect(JSON.parse(requestObj.data)).to.deep.equal(VALID_PAYLOAD); }); - it('should accept size as a one dimensional array', () => { + it('should accept size as a one dimensional array', function () { let bidReq = spec.buildRequests(BID_REQUEST_SIZE_AS_1DARRAY, VALID_AUCTIONDATA); expect(JSON.parse(bidReq.data)).to.deep.equal(VALID_PAYLOAD); }); - it('should ignore bidfloor if not a valid number', () => { + it('should ignore bidfloor if not a valid number', function () { let bidReq = spec.buildRequests(VALID_BID_REQUEST_INVALID_BIDFLOOR, VALID_AUCTIONDATA); expect(JSON.parse(bidReq.data)).to.deep.equal(VALID_PAYLOAD_INVALID_BIDFLOOR); }); - it('should add gdpr to response ext', () => { + it('should add gdpr to response ext', function () { let bidReq = spec.buildRequests(VALID_BID_REQUEST, VALID_BIDDER_REQUEST_WITH_GDPR); expect(JSON.parse(bidReq.data)).to.deep.equal(VALID_PAYLOAD_FOR_GDPR); }); describe('build requests: when page meta-data is available', () => { + beforeEach(() => { + spec.clearMnData(); + }); it('should pass canonical, twitter and fb paramters if available', () => { let documentStub = sandbox.stub(window.top.document, 'querySelector'); documentStub.withArgs('link[rel="canonical"]').returns({ @@ -568,9 +583,9 @@ describe('Media.net bid adapter', () => { }); }); - describe('slot visibility', () => { + describe('slot visibility', function () { let documentStub; - beforeEach(() => { + beforeEach(function () { let windowSizeStub = sandbox.stub(spec, 'getWindowSize'); windowSizeStub.returns({ w: 1000, @@ -578,7 +593,7 @@ describe('Media.net bid adapter', () => { }); documentStub = sandbox.stub(document, 'getElementById'); }); - it('slot visibility should be 2 and ratio 0 when ad unit is BTF', () => { + it('slot visibility should be 2 and ratio 0 when ad unit is BTF', function () { let boundingRect = { top: 1010, left: 1010, @@ -597,7 +612,7 @@ describe('Media.net bid adapter', () => { expect(data.imp[0].ext.visibility).to.equal(2); expect(data.imp[0].ext.viewability).to.equal(0); }); - it('slot visibility should be 2 and ratio < 0.5 when ad unit is partially inside viewport', () => { + it('slot visibility should be 2 and ratio < 0.5 when ad unit is partially inside viewport', function () { let boundingRect = { top: 990, left: 990, @@ -615,7 +630,7 @@ describe('Media.net bid adapter', () => { expect(data.imp[0].ext.visibility).to.equal(2); expect(data.imp[0].ext.viewability).to.equal(100 / 75000); }); - it('slot visibility should be 1 and ratio > 0.5 when ad unit mostly in viewport', () => { + it('slot visibility should be 1 and ratio > 0.5 when ad unit mostly in viewport', function () { let boundingRect = { top: 800, left: 800, @@ -633,7 +648,7 @@ describe('Media.net bid adapter', () => { expect(data.imp[0].ext.visibility).to.equal(1); expect(data.imp[0].ext.viewability).to.equal(40000 / 75000); }); - it('co-ordinates should not be sent and slot visibility should be 0 when ad unit is not present', () => { + it('co-ordinates should not be sent and slot visibility should be 0 when ad unit is not present', function () { let bidReq = spec.buildRequests(VALID_BID_REQUEST, VALID_AUCTIONDATA); let data = JSON.parse(bidReq.data); expect(data.imp[1].ext).to.not.have.ownPropertyDescriptor('viewability'); @@ -641,37 +656,37 @@ describe('Media.net bid adapter', () => { }); }); - describe('getUserSyncs', () => { - it('should exclude iframe syncs if iframe is disabled', () => { + describe('getUserSyncs', function () { + it('should exclude iframe syncs if iframe is disabled', function () { let userSyncs = spec.getUserSyncs(SYNC_OPTIONS_PIXEL_ENABLED, SERVER_CSYNC_RESPONSE); expect(userSyncs).to.deep.equal(ENABLED_SYNC_PIXEL); }); - it('should exclude pixel syncs if pixel is disabled', () => { + it('should exclude pixel syncs if pixel is disabled', function () { let userSyncs = spec.getUserSyncs(SYNC_OPTIONS_IFRAME_ENABLED, SERVER_CSYNC_RESPONSE); expect(userSyncs).to.deep.equal(ENABLED_SYNC_IFRAME); }); - it('should choose iframe sync urls if both sync options are enabled', () => { + it('should choose iframe sync urls if both sync options are enabled', function () { let userSyncs = spec.getUserSyncs(SYNC_OPTIONS_BOTH_ENABLED, SERVER_CSYNC_RESPONSE); expect(userSyncs).to.deep.equal(ENABLED_SYNC_IFRAME); }); }); - describe('interpretResponse', () => { - it('should not push bid response if cpm missing', () => { + describe('interpretResponse', function () { + it('should not push bid response if cpm missing', function () { let validBids = []; let bids = spec.interpretResponse(SERVER_RESPONSE_CPM_MISSING, []); expect(bids).to.deep.equal(validBids); }); - it('should not push bid response if cpm 0', () => { + it('should not push bid response if cpm 0', function () { let validBids = []; let bids = spec.interpretResponse(SERVER_RESPONSE_CPM_ZERO, []); expect(bids).to.deep.equal(validBids); }); - it('should not push response if no-bid', () => { + it('should not push response if no-bid', function () { let validBids = []; let bids = spec.interpretResponse(SERVER_RESPONSE_NOBID, []); expect(bids).to.deep.equal(validBids); diff --git a/test/spec/modules/mobfoxBidAdapter_spec.js b/test/spec/modules/mobfoxBidAdapter_spec.js index 54a057991e3..90125f3e0d0 100644 --- a/test/spec/modules/mobfoxBidAdapter_spec.js +++ b/test/spec/modules/mobfoxBidAdapter_spec.js @@ -1,4 +1,4 @@ -describe('mobfox adapter tests', () => { +describe('mobfox adapter tests', function () { const expect = require('chai').expect; const utils = require('src/utils'); const adapter = require('modules/mobfoxBidAdapter'); @@ -18,7 +18,7 @@ describe('mobfox adapter tests', () => { transactionId: '31f42cba-5920-4e47-adad-69c79d0d4fb4' }]; - describe('validRequests', () => { + describe('validRequests', function () { let bidRequestInvalid1 = [{ code: 'div-gpt-ad-1460505748561-0', sizes: [[320, 480], [300, 250], [300, 600]], @@ -33,19 +33,19 @@ describe('mobfox adapter tests', () => { transactionId: '31f42cba-5920-4e47-adad-69c79d0d4fb4' }]; - it('test valid MF request success', () => { + it('test valid MF request success', function () { let isValid = adapter.spec.isBidRequestValid(bidRequest[0]); expect(isValid).to.equal(true); }); - it('test valid MF request failed1', () => { + it('test valid MF request failed1', function () { let isValid = adapter.spec.isBidRequestValid(bidRequestInvalid1[0]); expect(isValid).to.equal(false); }); }) - describe('buildRequests', () => { - it('test build MF request', () => { + describe('buildRequests', function () { + it('test build MF request', function () { let request = adapter.spec.buildRequests(bidRequest); let payload = request.data.split('&'); expect(payload[0]).to.equal('rt=api-fetchip'); @@ -57,7 +57,7 @@ describe('mobfox adapter tests', () => { expect(payload[7]).to.equal('imp_instl=1'); }); - it('test build MF request', () => { + it('test build MF request', function () { let request = adapter.spec.buildRequests(bidRequest); let payload = request.data.split('&'); expect(payload[0]).to.equal('rt=api-fetchip'); @@ -70,7 +70,7 @@ describe('mobfox adapter tests', () => { }); }) - describe('interceptResponse', () => { + describe('interceptResponse', function () { let mockServerResponse = { body: { request: { @@ -93,7 +93,7 @@ describe('mobfox adapter tests', () => { } } }; - it('test intercept response', () => { + it('test intercept response', function () { let request = adapter.spec.buildRequests(bidRequest); let bidResponses = adapter.spec.interpretResponse(mockServerResponse, request); expect(bidResponses.length).to.equal(1); @@ -109,7 +109,7 @@ describe('mobfox adapter tests', () => { expect(bidResponses[0].width).to.equal('320'); }); - it('test intercept response with empty server response', () => { + it('test intercept response with empty server response', function () { let request = adapter.spec.buildRequests(bidRequest); let serverResponse = { request: { diff --git a/test/spec/modules/my6senseBidAdapter_spec.js b/test/spec/modules/my6senseBidAdapter_spec.js index ec8389acbb3..d2c875dad07 100644 --- a/test/spec/modules/my6senseBidAdapter_spec.js +++ b/test/spec/modules/my6senseBidAdapter_spec.js @@ -1,9 +1,9 @@ import { expect } from 'chai'; -import spec from 'modules/my6senseBidAdapter'; +import { spec } from 'modules/my6senseBidAdapter'; -describe('My6sense Bid adapter test', () => { +describe('My6sense Bid adapter test', function () { let bidRequests, serverResponses; - beforeEach(() => { + beforeEach(function () { bidRequests = [ { // valid 1 @@ -99,29 +99,29 @@ describe('My6sense Bid adapter test', () => { ] }); - describe('test if requestIsValid function', () => { - it('with valid data 1', () => { + describe('test if requestIsValid function', function () { + it('with valid data 1', function () { expect(spec.isBidRequestValid(bidRequests[0])).to.equal(true); }); - it('with invalid data 2', () => { + it('with invalid data 2', function () { expect(spec.isBidRequestValid(bidRequests[1])).to.equal(false); }); - it('with invalid data 3', () => { + it('with invalid data 3', function () { expect(spec.isBidRequestValid(bidRequests[2])).to.equal(false); }); - it('with invalid data 3', () => { + it('with invalid data 3', function () { expect(spec.isBidRequestValid(bidRequests[3])).to.equal(false); }); }); - describe('test if buildRequests function', () => { - it('normal', () => { + describe('test if buildRequests function', function () { + it('normal', function () { var requests = spec.buildRequests([bidRequests[0]]); expect(requests).to.be.lengthOf(1); }); }); - describe('test bid responses', () => { - it('success 1', () => { + describe('test bid responses', function () { + it('success 1', function () { var bids = spec.interpretResponse(serverResponses[0], {'bidRequest': bidRequests[0]}); expect(bids).to.be.lengthOf(1); expect(bids[0].cpm).to.equal(1.5); @@ -129,7 +129,7 @@ describe('My6sense Bid adapter test', () => { expect(bids[0].height).to.equal(250); expect(bids[0].adm).to.have.length.above(1); }); - it('success 2', () => { + it('success 2', function () { var bids = spec.interpretResponse(serverResponses[3]); expect(bids).to.be.lengthOf(1); expect(bids[0].cpm).to.equal(5); @@ -139,11 +139,11 @@ describe('My6sense Bid adapter test', () => { expect(bids[0].ttl).to.equal(360); expect(bids[0].currency).to.equal('USD'); }); - it('fail 1 (cpm=0)', () => { + it('fail 1 (cpm=0)', function () { var bids = spec.interpretResponse(serverResponses[1]); expect(bids).to.be.lengthOf(1); }); - it('fail 2 (no response)', () => { + it('fail 2 (no response)', function () { var bids = spec.interpretResponse([]); expect(bids).to.be.lengthOf(0); }); diff --git a/test/spec/modules/nanointeractiveBidAdapter_spec.js b/test/spec/modules/nanointeractiveBidAdapter_spec.js index 1aecb8ab06b..3731535b88a 100644 --- a/test/spec/modules/nanointeractiveBidAdapter_spec.js +++ b/test/spec/modules/nanointeractiveBidAdapter_spec.js @@ -64,10 +64,10 @@ describe('nanointeractive adapter tests', function () { }; } - describe('NanoAdapter', () => { + describe('NanoAdapter', function () { let nanoBidAdapter = spec; - describe('Methods', () => { + describe('Methods', function () { it('Test isBidRequestValid() with valid param(s): pid', function () { expect(nanoBidAdapter.isBidRequestValid(getBidRequest({ [DATA_PARTNER_PIXEL_ID]: DATA_PARTNER_PIXEL_ID_VALUE, diff --git a/test/spec/modules/nasmediaAdmixerBidAdapter_spec.js b/test/spec/modules/nasmediaAdmixerBidAdapter_spec.js index 7ed65718657..dd6ed4686d1 100644 --- a/test/spec/modules/nasmediaAdmixerBidAdapter_spec.js +++ b/test/spec/modules/nasmediaAdmixerBidAdapter_spec.js @@ -2,16 +2,16 @@ import {expect} from 'chai'; import {spec} from 'modules/nasmediaAdmixerBidAdapter'; import {newBidder} from 'src/adapters/bidderFactory'; -describe('nasmediaAdmixerBidAdapter', () => { +describe('nasmediaAdmixerBidAdapter', function () { const adapter = newBidder(spec); - describe('inherited functions', () => { - it('exists and is a function', () => { + describe('inherited functions', function () { + it('exists and is a function', function () { expect(adapter.callBids).to.exist.and.to.be.a('function'); }); }); - describe('isBidRequestValid', () => { + describe('isBidRequestValid', function () { const bid = { 'bidder': 'nasmediaAdmixer', 'params': { @@ -24,11 +24,11 @@ describe('nasmediaAdmixerBidAdapter', () => { 'auctionId': '124cb070528662', }; - it('should return true when required params found', () => { + it('should return true when required params found', function () { expect(spec.isBidRequestValid(bid)).to.equal(true); }); - it('should return false when required params are not passed', () => { + it('should return false when required params are not passed', function () { const bid = Object.assign({}, bid); delete bid.params; bid.params = { @@ -38,7 +38,7 @@ describe('nasmediaAdmixerBidAdapter', () => { }); }); - describe('buildRequests', () => { + describe('buildRequests', function () { const bidRequests = [ { 'bidder': 'nasmediaAdmixer', @@ -53,14 +53,14 @@ describe('nasmediaAdmixerBidAdapter', () => { } ]; - it('sends bid request to url via GET', () => { + it('sends bid request to url via GET', function () { const request = spec.buildRequests(bidRequests)[0]; expect(request.method).to.equal('GET'); expect(request.url).to.match(new RegExp(`https://adn.admixer.co.kr`)); }); }); - describe('interpretResponse', () => { + describe('interpretResponse', function () { const response = { 'body': { 'bidder': 'nasmedia_admixer', @@ -94,7 +94,7 @@ describe('nasmediaAdmixerBidAdapter', () => { 'auctionId': '169827a33f03cc', }; - it('should get correct bid response', () => { + it('should get correct bid response', function () { const expectedResponse = [ { 'requestId': '861a8e7952c82c', @@ -122,7 +122,7 @@ describe('nasmediaAdmixerBidAdapter', () => { }); }); - it('handles nobid responses', () => { + it('handles nobid responses', function () { response.body = { 'bidder': 'nasmedia_admixer', 'req_id': '861a8e7952c82c', diff --git a/test/spec/modules/nextMilleniumBidAdapter_spec.js b/test/spec/modules/nextMilleniumBidAdapter_spec.js new file mode 100644 index 00000000000..74c8ff5dfd9 --- /dev/null +++ b/test/spec/modules/nextMilleniumBidAdapter_spec.js @@ -0,0 +1,91 @@ +import { expect } from 'chai'; +import { spec } from 'modules/nextMilleniumBidAdapter'; + +describe('nextMilleniumBidAdapterTests', function() { + let bidRequestData = { + bids: [ + { + bidId: 'transaction_1234', + bidder: 'nextMillenium', + params: { + placement_id: 12345 + }, + sizes: [[300, 250]] + } + ] + }; + let request = []; + + it('validate_pub_params', function() { + expect( + spec.isBidRequestValid({ + bidder: 'nextMillenium', + params: { + placement_id: 12345 + } + }) + ).to.equal(true); + }); + + it('validate_generated_params', function() { + let bidRequestData = [ + { + bidId: 'bid1234', + bidder: 'nextMillenium', + params: { placement_id: -1 }, + sizes: [[300, 250]] + } + ]; + let request = spec.buildRequests(bidRequestData); + expect(request[0].bidId).to.equal('bid1234'); + }); + + it('validate_getUserSyncs_function', function() { + expect(spec.getUserSyncs({ iframeEnabled: true })).to.have.lengthOf(1); + expect(spec.getUserSyncs({ iframeEnabled: false })).to.have.lengthOf(0); + + let pixel = spec.getUserSyncs({ iframeEnabled: true }); + expect(pixel[0].type).to.equal('iframe'); + expect(pixel[0].url).to.equal('https://brainlyads.com/hb/s2s/matching'); + }); + + it('validate_response_params', function() { + let serverResponse = { + body: { + cpm: 1.7, + width: 300, + height: 250, + creativeId: 'p35t0enob6twbt9mofjc8e', + ad: 'Hello! It\'s a test ad!' + } + }; + + let bids = spec.interpretResponse(serverResponse, bidRequestData.bids[0]); + expect(bids).to.have.lengthOf(1); + + let bid = bids[0]; + + expect(bid.creativeId).to.equal('p35t0enob6twbt9mofjc8e'); + expect(bid.ad).to.equal('Hello! It\'s a test ad!'); + expect(bid.cpm).to.equal(1.7); + expect(bid.width).to.equal(300); + expect(bid.height).to.equal(250); + expect(bid.currency).to.equal('USD'); + }); + + it('validate_response_params_with passback', function() { + let serverResponse = { + body: [ + { + hash: '1e100887dd614b0909bf6c49ba7f69fdd1360437', + content: 'Ad html passback', + size: [300, 250], + is_passback: 1 + } + ] + }; + let bids = spec.interpretResponse(serverResponse); + + expect(bids).to.have.lengthOf(0); + }); +}); diff --git a/test/spec/modules/oneVideoBidAdapter_spec.js b/test/spec/modules/oneVideoBidAdapter_spec.js index 3d7bba417f9..f67105751df 100644 --- a/test/spec/modules/oneVideoBidAdapter_spec.js +++ b/test/spec/modules/oneVideoBidAdapter_spec.js @@ -1,11 +1,14 @@ import { expect } from 'chai'; import { spec } from 'modules/oneVideoBidAdapter'; import * as utils from 'src/utils'; +import {config} from 'src/config'; -describe('OneVideoBidAdapter', () => { +describe('OneVideoBidAdapter', function () { let bidRequest; + let bidderRequest; + let mockConfig; - beforeEach(() => { + beforeEach(function () { bidRequest = { bidder: 'oneVideo', sizes: [640, 480], @@ -30,19 +33,19 @@ describe('OneVideoBidAdapter', () => { }; }); - describe('spec.isBidRequestValid', () => { - it('should return true when the required params are passed', () => { + describe('spec.isBidRequestValid', function () { + it('should return true when the required params are passed', function () { expect(spec.isBidRequestValid(bidRequest)).to.equal(true); }); - it('should return false when the "video" param is missing', () => { + it('should return false when the "video" param is missing', function () { bidRequest.params = { pubId: 'brxd' }; expect(spec.isBidRequestValid(bidRequest)).to.equal(false); }); - it('should return false when the "pubId" param is missing', () => { + it('should return false when the "pubId" param is missing', function () { bidRequest.params = { video: { playerWidth: 480, @@ -57,25 +60,25 @@ describe('OneVideoBidAdapter', () => { expect(spec.isBidRequestValid(bidRequest)).to.equal(false); }); - it('should return false when no bid params are passed', () => { + it('should return false when no bid params are passed', function () { bidRequest.params = {}; expect(spec.isBidRequestValid(bidRequest)).to.equal(false); }); }); - describe('spec.buildRequests', () => { - it('should create a POST request for every bid', () => { + describe('spec.buildRequests', function () { + it('should create a POST request for every bid', function () { const requests = spec.buildRequests([ bidRequest ]); expect(requests[0].method).to.equal('POST'); expect(requests[0].url).to.equal(location.protocol + spec.ENDPOINT + bidRequest.params.pubId); }); - it('should attach the bid request object', () => { + it('should attach the bid request object', function () { const requests = spec.buildRequests([ bidRequest ]); expect(requests[0].bidRequest).to.equal(bidRequest); }); - it('should attach request data', () => { + it('should attach request data', function () { const requests = spec.buildRequests([ bidRequest ]); const data = requests[0].data; const [ width, height ] = bidRequest.sizes; @@ -84,7 +87,7 @@ describe('OneVideoBidAdapter', () => { expect(data.imp[0].bidfloor).to.equal(bidRequest.params.bidfloor); }); - it('must parse bid size from a nested array', () => { + it('must parse bid size from a nested array', function () { const width = 640; const height = 480; bidRequest.sizes = [[ width, height ]]; @@ -95,25 +98,25 @@ describe('OneVideoBidAdapter', () => { }); }); - describe('spec.interpretResponse', () => { - it('should return no bids if the response is not valid', () => { + describe('spec.interpretResponse', function () { + it('should return no bids if the response is not valid', function () { const bidResponse = spec.interpretResponse({ body: null }, { bidRequest }); expect(bidResponse.length).to.equal(0); }); - it('should return no bids if the response "nurl" and "adm" are missing', () => { + it('should return no bids if the response "nurl" and "adm" are missing', function () { const serverResponse = {seatbid: [{bid: [{price: 6.01}]}]}; const bidResponse = spec.interpretResponse({ body: serverResponse }, { bidRequest }); expect(bidResponse.length).to.equal(0); }); - it('should return no bids if the response "price" is missing', () => { + it('should return no bids if the response "price" is missing', function () { const serverResponse = {seatbid: [{bid: [{adm: ''}]}]}; const bidResponse = spec.interpretResponse({ body: serverResponse }, { bidRequest }); expect(bidResponse.length).to.equal(0); }); - it('should return a valid bid response with just "adm"', () => { + it('should return a valid bid response with just "adm"', function () { const serverResponse = {seatbid: [{bid: [{id: 1, price: 6.01, adm: ''}]}], cur: 'USD'}; const bidResponse = spec.interpretResponse({ body: serverResponse }, { bidRequest }); let o = { @@ -132,4 +135,33 @@ describe('OneVideoBidAdapter', () => { expect(bidResponse).to.deep.equal(o); }); }); + + describe('when GDPR applies', function () { + beforeEach(function () { + bidderRequest = { + gdprConsent: { + consentString: 'test-gdpr-consent-string', + gdprApplies: true + } + }; + + mockConfig = { + consentManagement: { + cmpApi: 'iab', + timeout: 1111, + allowAuctionWithoutConsent: 'cancel' + } + }; + }); + + it('should send a signal to specify that GDPR applies to this request', function () { + const request = spec.buildRequests([ bidRequest ], bidderRequest); + expect(request[0].data.regs.ext.gdpr).to.equal(1); + }); + + it('should send the consent string', function () { + const request = spec.buildRequests([ bidRequest ], bidderRequest); + expect(request[0].data.user.ext.consent).to.equal(bidderRequest.gdprConsent.consentString); + }); + }); }); diff --git a/test/spec/modules/oneplanetonlyBidAdapter_spec.js b/test/spec/modules/oneplanetonlyBidAdapter_spec.js index 4a42b471b6f..fbcec66ef51 100644 --- a/test/spec/modules/oneplanetonlyBidAdapter_spec.js +++ b/test/spec/modules/oneplanetonlyBidAdapter_spec.js @@ -1,7 +1,7 @@ import {expect} from 'chai'; import {spec} from '../../../modules/oneplanetonlyBidAdapter'; -describe('OnePlanetOnlyAdapter', () => { +describe('OnePlanetOnlyAdapter', function () { let bid = { bidId: '51ef8751f9aead', bidder: 'oneplanetonly', @@ -16,31 +16,31 @@ describe('OnePlanetOnlyAdapter', () => { auctionId: '18fd8b8b0bd757' }; - describe('isBidRequestValid', () => { - it('Should return true if there are params.siteId and params.adUnitId parameters present', () => { + describe('isBidRequestValid', function () { + it('Should return true if there are params.siteId and params.adUnitId parameters present', function () { expect(spec.isBidRequestValid(bid)).to.be.true; }); - it('Should return false if at least one of parameters is not present', () => { + it('Should return false if at least one of parameters is not present', function () { delete bid.params.adUnitId; expect(spec.isBidRequestValid(bid)).to.be.false; }); }); - describe('buildRequests', () => { + describe('buildRequests', function () { let serverRequest = spec.buildRequests([bid]); - it('Creates a ServerRequest object with method, URL and data', () => { + it('Creates a ServerRequest object with method, URL and data', function () { expect(serverRequest).to.exist; expect(serverRequest.method).to.exist; expect(serverRequest.url).to.exist; expect(serverRequest.data).to.exist; }); - it('Returns POST method', () => { + it('Returns POST method', function () { expect(serverRequest.method).to.equal('POST'); }); - it('Returns valid URL', () => { + it('Returns valid URL', function () { expect(serverRequest.url).to.equal('//show.oneplanetonly.com/prebid?siteId=5'); }); - it('Returns valid data if array of bids is valid', () => { + it('Returns valid data if array of bids is valid', function () { let data = serverRequest.data; expect(data).to.be.an('object'); expect(data).to.have.all.keys('id', 'ver', 'prebidVer', 'transactionId', 'currency', 'timeout', 'siteId', @@ -52,14 +52,14 @@ describe('OnePlanetOnlyAdapter', () => { expect(adUnit.bidId).to.equal('51ef8751f9aead'); expect(adUnit.sizes).to.have.members(['300x250', '300x600']); }); - it('Returns empty data if no valid requests are passed', () => { + it('Returns empty data if no valid requests are passed', function () { serverRequest = spec.buildRequests([]); let data = serverRequest.data; expect(data.adUnits).to.be.an('array').that.is.empty; }); }); - describe('interpretResponse', () => { - it('Should interpret banner response', () => { + describe('interpretResponse', function () { + it('Should interpret banner response', function () { const serverResponse = { body: { bids: [{ @@ -89,7 +89,7 @@ describe('OnePlanetOnlyAdapter', () => { expect(bidObject.netRevenue).to.be.true; expect(bidObject.currency).to.equal('USD'); }); - it('Should return an empty array if invalid response is passed', () => { + it('Should return an empty array if invalid response is passed', function () { const invalid = { body: {} }; diff --git a/test/spec/modules/onetagBidAdapter_spec.js b/test/spec/modules/onetagBidAdapter_spec.js index 85597a0c6c6..d56ad9e6dc5 100644 --- a/test/spec/modules/onetagBidAdapter_spec.js +++ b/test/spec/modules/onetagBidAdapter_spec.js @@ -1,7 +1,7 @@ import { spec } from 'modules/onetagBidAdapter'; import { expect } from 'chai'; -describe('onetag', () => { +describe('onetag', function () { let bid = { 'bidder': 'onetag', 'params': { @@ -15,43 +15,43 @@ describe('onetag', () => { 'transactionId': 'qwerty123' }; - describe('isBidRequestValid', () => { - it('Should return true when required params are found', () => { + describe('isBidRequestValid', function () { + it('Should return true when required params are found', function () { expect(spec.isBidRequestValid(bid)).to.be.true; }); - it('Should return false when pubId is not a string', () => { + it('Should return false when pubId is not a string', function () { bid.params.pubId = 30; expect(spec.isBidRequestValid(bid)).to.be.false; }); - it('Should return false when pubId is undefined', () => { + it('Should return false when pubId is undefined', function () { bid.params.pubId = undefined; expect(spec.isBidRequestValid(bid)).to.be.false; }); - it('Should return false when the sizes array is empty', () => { + it('Should return false when the sizes array is empty', function () { bid.sizes = []; expect(spec.isBidRequestValid(bid)).to.be.false; }); }); - describe('buildRequests', () => { + describe('buildRequests', function () { let serverRequest = spec.buildRequests([bid]); - it('Creates a ServerRequest object with method, URL and data', () => { + it('Creates a ServerRequest object with method, URL and data', function () { expect(serverRequest).to.exist; expect(serverRequest.method).to.exist; expect(serverRequest.url).to.exist; expect(serverRequest.data).to.exist; }); - it('Returns POST method', () => { + it('Returns POST method', function () { expect(serverRequest.method).to.equal('POST'); }); - it('Returns valid URL', () => { + it('Returns valid URL', function () { expect(serverRequest.url).to.equal('https://onetag-sys.com/prebid-request'); }); const d = serverRequest.data; try { const data = JSON.parse(d); - it('Should contains all keys', () => { + it('Should contains all keys', function () { expect(data).to.be.an('object'); expect(data).to.have.all.keys('location', 'masked', 'referrer', 'sHeight', 'sWidth', 'timeOffset', 'date', 'wHeight', 'wWidth', 'bids'); expect(data.location).to.be.a('string'); @@ -76,7 +76,7 @@ describe('onetag', () => { } catch (e) { console.log('Error while parsing'); } - it('Returns empty data if no valid requests are passed', () => { + it('Returns empty data if no valid requests are passed', function () { serverRequest = spec.buildRequests([]); let dataString = serverRequest.data; try { @@ -86,7 +86,7 @@ describe('onetag', () => { console.log('Error while parsing'); } }); - it('should send GDPR consent data', () => { + it('should send GDPR consent data', function () { let consentString = 'consentString'; let bidderRequest = { 'bidderCode': 'onetag', @@ -107,7 +107,7 @@ describe('onetag', () => { expect(payload.gdprConsent.consentRequired).to.exist.and.to.be.true; }); }); - describe('interpretResponse', () => { + describe('interpretResponse', function () { const resObject = { body: { nobid: false, @@ -123,7 +123,7 @@ describe('onetag', () => { }] } }; - it('Returns an array of valid server responses if response object is valid', () => { + it('Returns an array of valid server responses if response object is valid', function () { const serverResponses = spec.interpretResponse(resObject); expect(serverResponses).to.be.an('array').that.is.not.empty; @@ -140,7 +140,7 @@ describe('onetag', () => { expect(dataItem.netRevenue).to.be.a('boolean'); expect(dataItem.currency).to.be.a('string'); } - it('Returns an empty array if invalid response is passed', () => { + it('Returns an empty array if invalid response is passed', function () { const serverResponses = spec.interpretResponse('invalid_response'); expect(serverResponses).to.be.an('array').that.is.empty; }); diff --git a/test/spec/modules/openxAnalyticsAdapter_spec.js b/test/spec/modules/openxAnalyticsAdapter_spec.js new file mode 100644 index 00000000000..7b73b11887f --- /dev/null +++ b/test/spec/modules/openxAnalyticsAdapter_spec.js @@ -0,0 +1,445 @@ +import { expect } from 'chai'; +import openxAdapter from 'modules/openxAnalyticsAdapter'; +import { config } from 'src/config'; +import events from 'src/events'; +import CONSTANTS from 'src/constants.json'; +import * as utils from 'src/utils'; + +const { + EVENTS: { AUCTION_INIT, BID_REQUESTED, BID_RESPONSE, BID_TIMEOUT, BID_WON } +} = CONSTANTS; + +const SLOT_LOADED = 'slotOnload'; + +describe('openx analytics adapter', function() { + it('should require publisher id', function() { + sinon.spy(utils, 'logError'); + + openxAdapter.enableAnalytics(); + expect( + utils.logError.calledWith( + 'OpenX analytics adapter: publisherId is required.' + ) + ).to.be.true; + + utils.logError.restore(); + }); + + describe('sending analytics event', function() { + const auctionInit = { auctionId: 'add5eb0f-587d-441d-86ec-bbb722c70f79' }; + + const bidRequestedOpenX = { + auctionId: 'add5eb0f-587d-441d-86ec-bbb722c70f79', + auctionStart: 1540944528017, + bids: [ + { + adUnitCode: 'div-1', + bidId: '2f0c647b904e25', + bidder: 'openx', + params: { unit: '540249866' }, + transactionId: 'ac66c3e6-3118-4213-a3ae-8cdbe4f72873' + } + ], + start: 1540944528021 + }; + + const bidRequestedCloseX = { + auctionId: 'add5eb0f-587d-441d-86ec-bbb722c70f79', + auctionStart: 1540944528017, + bids: [ + { + adUnitCode: 'div-1', + bidId: '43d454020e9409', + bidder: 'closex', + params: { unit: '513144370' }, + transactionId: 'ac66c3e6-3118-4213-a3ae-8cdbe4f72873' + } + ], + start: 1540944528026 + }; + + const bidResponseOpenX = { + adId: '2f0c647b904e25', + adUnitCode: 'div-1', + auctionId: 'add5eb0f-587d-441d-86ec-bbb722c70f79', + cpm: 0.5, + creativeId: 'openx-crid', + responseTimestamp: 1540944528184, + ts: '2DAABBgABAAECAAIBAAsAAgAAAJccGApKSGt6NUZxRXYyHBbinsLj' + }; + + const bidResponseCloseX = { + adId: '43d454020e9409', + adUnitCode: 'div-1', + auctionId: 'add5eb0f-587d-441d-86ec-bbb722c70f79', + cpm: 0.3, + creativeId: 'closex-crid', + responseTimestamp: 1540944528196, + ts: 'hu1QWo6iD3MHs6NG_AQAcFtyNqsj9y4S0YRbX7Kb06IrGns0BABb' + }; + + const bidTimeoutOpenX = { + 0: { + adUnitCode: 'div-1', + auctionId: 'add5eb0f-587d-441d-86ec-bbb722c70f79', + bidId: '2f0c647b904e25' + } + }; + + const bidTimeoutCloseX = { + 0: { + adUnitCode: 'div-1', + auctionId: 'add5eb0f-587d-441d-86ec-bbb722c70f79', + bidId: '43d454020e9409' + } + }; + + const bidWonOpenX = { + adId: '2f0c647b904e25', + adUnitCode: 'div-1', + auctionId: 'add5eb0f-587d-441d-86ec-bbb722c70f79' + }; + + const bidWonCloseX = { + adId: '43d454020e9409', + adUnitCode: 'div-1', + auctionId: 'add5eb0f-587d-441d-86ec-bbb722c70f79' + }; + + function simulateAuction(events) { + let highestBid; + + events.forEach(event => { + const [eventType, args] = event; + openxAdapter.track({ eventType, args }); + if (eventType === BID_RESPONSE) { + highestBid = highestBid || args; + if (highestBid.cpm < args.cpm) { + highestBid = args; + } + } + }); + + openxAdapter.track({ + eventType: SLOT_LOADED, + args: { + slot: { + getAdUnitPath: () => { + return '/90577858/test_ad_unit'; + }, + getTargetingKeys: () => { + return []; + }, + getTargeting: sinon + .stub() + .withArgs('hb_adid') + .returns(highestBid ? [highestBid.adId] : []) + } + } + }); + } + + function getQueryData(url) { + const queryArgs = url.split('?')[1].split('&'); + return queryArgs.reduce((data, arg) => { + const [key, val] = arg.split('='); + data[key] = val; + return data; + }, {}); + } + + let xhr; + let requests; + + before(function() { + xhr = sinon.useFakeXMLHttpRequest(); + xhr.onCreate = request => requests.push(request); + sinon.stub(events, 'getEvents').returns([]); + openxAdapter.enableAnalytics({ + options: { + publisherId: 'test123' + } + }); + }); + + after(function() { + xhr.restore(); + events.getEvents.restore(); + openxAdapter.disableAnalytics(); + }); + + beforeEach(function() { + requests = []; + openxAdapter.reset(); + }); + + afterEach(function() {}); + + it('should not send request if no bid response', function() { + simulateAuction([ + [AUCTION_INIT, auctionInit], + [BID_REQUESTED, bidRequestedOpenX] + ]); + + expect(requests.length).to.equal(0); + }); + + it('should send 1 request to the right endpoint', function() { + simulateAuction([ + [AUCTION_INIT, auctionInit], + [BID_REQUESTED, bidRequestedOpenX], + [BID_RESPONSE, bidResponseOpenX] + ]); + + expect(requests.length).to.equal(1); + + const endpoint = requests[0].url.split('?')[0]; + expect(endpoint).to.equal('http://ads.openx.net/w/1.0/pban'); + }); + + describe('hb.ct, hb.rid, dddid, hb.asiid, hb.pubid', function() { + it('should always be in the query string', function() { + simulateAuction([ + [AUCTION_INIT, auctionInit], + [BID_REQUESTED, bidRequestedOpenX], + [BID_RESPONSE, bidResponseOpenX] + ]); + + const queryData = getQueryData(requests[0].url); + expect(queryData).to.include({ + 'hb.ct': String(bidRequestedOpenX.auctionStart), + 'hb.rid': auctionInit.auctionId, + dddid: bidRequestedOpenX.bids[0].transactionId, + 'hb.asiid': '/90577858/test_ad_unit', + 'hb.pubid': 'test123' + }); + }); + }); + + describe('hb.cur', function() { + it('should be in the query string if currency is set', function() { + sinon + .stub(config, 'getConfig') + .withArgs('currency.adServerCurrency') + .returns('bitcoin'); + + simulateAuction([ + [AUCTION_INIT, auctionInit], + [BID_REQUESTED, bidRequestedOpenX], + [BID_RESPONSE, bidResponseOpenX] + ]); + + config.getConfig.restore(); + + const queryData = getQueryData(requests[0].url); + expect(queryData).to.include({ + 'hb.cur': 'bitcoin' + }); + }); + + it('should not be in the query string if currency is not set', function() { + simulateAuction([ + [AUCTION_INIT, auctionInit], + [BID_REQUESTED, bidRequestedOpenX], + [BID_RESPONSE, bidResponseOpenX] + ]); + + const queryData = getQueryData(requests[0].url); + expect(queryData).to.not.have.key('hb.cur'); + }); + }); + + describe('hb.dcl, hb.dl, hb.tta, hb.ttr', function() { + it('should be in the query string if browser supports performance API', function() { + const timing = { + fetchStart: 1540944528000, + domContentLoadedEventEnd: 1540944528010, + loadEventEnd: 1540944528110 + }; + const originalPerf = window.top.performance; + window.top.performance = { timing }; + + const renderTime = 1540944528100; + sinon.stub(Date, 'now').returns(renderTime); + + simulateAuction([ + [AUCTION_INIT, auctionInit], + [BID_REQUESTED, bidRequestedOpenX], + [BID_RESPONSE, bidResponseOpenX] + ]); + + window.top.performance = originalPerf; + Date.now.restore(); + + const queryData = getQueryData(requests[0].url); + expect(queryData).to.include({ + 'hb.dcl': String(timing.domContentLoadedEventEnd - timing.fetchStart), + 'hb.dl': String(timing.loadEventEnd - timing.fetchStart), + 'hb.tta': String(bidRequestedOpenX.auctionStart - timing.fetchStart), + 'hb.ttr': String(renderTime - timing.fetchStart) + }); + }); + + it('should not be in the query string if browser does not support performance API', function() { + const originalPerf = window.top.performance; + window.top.performance = undefined; + + simulateAuction([ + [AUCTION_INIT, auctionInit], + [BID_REQUESTED, bidRequestedOpenX], + [BID_RESPONSE, bidResponseOpenX] + ]); + + window.top.performance = originalPerf; + + const queryData = getQueryData(requests[0].url); + expect(queryData).to.not.have.keys( + 'hb.dcl', + 'hb.dl', + 'hb.tta', + 'hb.ttr' + ); + }); + }); + + describe('ts, auid', function() { + it('OpenX is in auction and has a bid response', function() { + simulateAuction([ + [AUCTION_INIT, auctionInit], + [BID_REQUESTED, bidRequestedOpenX], + [BID_REQUESTED, bidRequestedCloseX], + [BID_RESPONSE, bidResponseOpenX], + [BID_RESPONSE, bidResponseCloseX] + ]); + + const queryData = getQueryData(requests[0].url); + expect(queryData).to.include({ + ts: bidResponseOpenX.ts, + auid: bidRequestedOpenX.bids[0].params.unit + }); + }); + + it('OpenX is in auction but no bid response', function() { + simulateAuction([ + [AUCTION_INIT, auctionInit], + [BID_REQUESTED, bidRequestedOpenX], + [BID_REQUESTED, bidRequestedCloseX], + [BID_RESPONSE, bidResponseCloseX] + ]); + + const queryData = getQueryData(requests[0].url); + expect(queryData).to.include({ + auid: bidRequestedOpenX.bids[0].params.unit + }); + expect(queryData).to.not.have.key('ts'); + }); + + it('OpenX is not in auction', function() { + simulateAuction([ + [AUCTION_INIT, auctionInit], + [BID_REQUESTED, bidRequestedCloseX], + [BID_RESPONSE, bidResponseCloseX] + ]); + + const queryData = getQueryData(requests[0].url); + expect(queryData).to.not.have.keys('auid', 'ts'); + }); + }); + + describe('hb.exn, hb.sts, hb.ets, hb.bv, hb.crid, hb.to', function() { + it('2 bidders in auction', function() { + simulateAuction([ + [AUCTION_INIT, auctionInit], + [BID_REQUESTED, bidRequestedOpenX], + [BID_REQUESTED, bidRequestedCloseX], + [BID_RESPONSE, bidResponseOpenX], + [BID_RESPONSE, bidResponseCloseX] + ]); + + const queryData = getQueryData(requests[0].url); + const auctionStart = bidRequestedOpenX.auctionStart; + expect(queryData).to.include({ + 'hb.exn': [ + bidRequestedOpenX.bids[0].bidder, + bidRequestedCloseX.bids[0].bidder + ].join(','), + 'hb.sts': [ + bidRequestedOpenX.start - auctionStart, + bidRequestedCloseX.start - auctionStart + ].join(','), + 'hb.ets': [ + bidResponseOpenX.responseTimestamp - auctionStart, + bidResponseCloseX.responseTimestamp - auctionStart + ].join(','), + 'hb.bv': [bidResponseOpenX.cpm, bidResponseCloseX.cpm].join(','), + 'hb.crid': [ + bidResponseOpenX.creativeId, + bidResponseCloseX.creativeId + ].join(','), + 'hb.to': [false, false].join(',') + }); + }); + + it('OpenX timed out', function() { + simulateAuction([ + [AUCTION_INIT, auctionInit], + [BID_REQUESTED, bidRequestedOpenX], + [BID_REQUESTED, bidRequestedCloseX], + [BID_RESPONSE, bidResponseCloseX], + [BID_TIMEOUT, bidTimeoutOpenX] + ]); + + const queryData = getQueryData(requests[0].url); + const auctionStart = bidRequestedOpenX.auctionStart; + expect(queryData).to.include({ + 'hb.exn': [ + bidRequestedOpenX.bids[0].bidder, + bidRequestedCloseX.bids[0].bidder + ].join(','), + 'hb.sts': [ + bidRequestedOpenX.start - auctionStart, + bidRequestedCloseX.start - auctionStart + ].join(','), + 'hb.ets': [ + undefined, + bidResponseCloseX.responseTimestamp - auctionStart + ].join(','), + 'hb.bv': [0, bidResponseCloseX.cpm].join(','), + 'hb.crid': [undefined, bidResponseCloseX.creativeId].join(','), + 'hb.to': [true, false].join(',') + }); + }); + }); + + describe('hb.we, hb.g1', function() { + it('OpenX won', function() { + simulateAuction([ + [AUCTION_INIT, auctionInit], + [BID_REQUESTED, bidRequestedOpenX], + [BID_RESPONSE, bidResponseOpenX], + [BID_WON, bidWonOpenX] + ]); + + const queryData = getQueryData(requests[0].url); + expect(queryData).to.include({ + 'hb.we': '0', + 'hb.g1': 'false' + }); + }); + + it('DFP won', function() { + simulateAuction([ + [AUCTION_INIT, auctionInit], + [BID_REQUESTED, bidRequestedOpenX], + [BID_RESPONSE, bidResponseOpenX] + ]); + + const queryData = getQueryData(requests[0].url); + expect(queryData).to.include({ + 'hb.we': '-1', + 'hb.g1': 'true' + }); + }); + }); + }); +}); diff --git a/test/spec/modules/openxBidAdapter_spec.js b/test/spec/modules/openxBidAdapter_spec.js index c0588f2eff0..7a115ae1096 100644 --- a/test/spec/modules/openxBidAdapter_spec.js +++ b/test/spec/modules/openxBidAdapter_spec.js @@ -8,7 +8,7 @@ import * as utils from 'src/utils'; const URLBASE = '/w/1.0/arj'; const URLBASEVIDEO = '/v/1.0/avjp'; -describe('OpenxAdapter', () => { +describe('OpenxAdapter', function () { const adapter = newBidder(spec); /** @@ -121,16 +121,16 @@ describe('OpenxAdapter', () => { } }; - describe('inherited functions', () => { - it('exists and is a function', () => { + describe('inherited functions', function () { + it('exists and is a function', function () { expect(adapter.callBids).to.exist.and.to.be.a('function'); }); }); - describe('isBidRequestValid', () => { - describe('when request is for a banner ad', () => { + describe('isBidRequestValid', function () { + describe('when request is for a banner ad', function () { let bannerBid; - beforeEach(() => { + beforeEach(function () { bannerBid = { bidder: 'openx', params: {}, @@ -143,35 +143,35 @@ describe('OpenxAdapter', () => { }; }); - it('should return false when there is no delivery domain', () => { + it('should return false when there is no delivery domain', function () { bannerBid.params = {'unit': '12345678'}; expect(spec.isBidRequestValid(bannerBid)).to.equal(false); }); - describe('when there is a delivery domain', () => { + describe('when there is a delivery domain', function () { beforeEach(function () { bannerBid.params = {delDomain: 'test-delivery-domain'} }); - it('should return false when there is no ad unit id and size', () => { + it('should return false when there is no ad unit id and size', function () { expect(spec.isBidRequestValid(bannerBid)).to.equal(false); }); - it('should return true if there is an adunit id ', () => { + it('should return true if there is an adunit id ', function () { bannerBid.params.unit = '12345678'; expect(spec.isBidRequestValid(bannerBid)).to.equal(true); }); - it('should return true if there is no adunit id and sizes are defined', () => { + it('should return true if there is no adunit id and sizes are defined', function () { bannerBid.mediaTypes.banner.sizes = [720, 90]; expect(spec.isBidRequestValid(bannerBid)).to.equal(true); }); - it('should return false if no sizes are defined ', () => { + it('should return false if no sizes are defined ', function () { expect(spec.isBidRequestValid(bannerBid)).to.equal(false); }); - it('should return false if sizes empty ', () => { + it('should return false if sizes empty ', function () { bannerBid.mediaTypes.banner.sizes = []; expect(spec.isBidRequestValid(bannerBid)).to.equal(false); }); @@ -179,62 +179,111 @@ describe('OpenxAdapter', () => { }); describe('when request is for a video ad', function () { - const videoBidWithMediaTypes = { - bidder: 'openx', - params: { - unit: '12345678', - delDomain: 'test-del-domain' - }, - adUnitCode: 'adunit-code', - mediaTypes: { - video: { - playerSize: [640, 480] - } - }, - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - transactionId: '4008d88a-8137-410b-aa35-fbfdabcb478e' - }; - - const videoBidWithMediaType = { - 'bidder': 'openx', - 'params': { - 'unit': '12345678', - 'delDomain': 'test-del-domain' - }, - 'adUnitCode': 'adunit-code', - 'mediaType': 'video', - 'sizes': [640, 480], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - 'transactionId': '4008d88a-8137-410b-aa35-fbfdabcb478e' - }; - it('should return true when required params found', () => { - expect(spec.isBidRequestValid(videoBidWithMediaTypes)).to.equal(true); - }); + describe('and request config uses mediaTypes', () => { + const videoBidWithMediaTypes = { + bidder: 'openx', + params: { + unit: '12345678', + delDomain: 'test-del-domain' + }, + adUnitCode: 'adunit-code', + mediaTypes: { + video: { + playerSize: [640, 480] + } + }, + bidId: '30b31c1838de1e', + bidderRequestId: '22edbae2733bf6', + auctionId: '1d1a030790a475', + transactionId: '4008d88a-8137-410b-aa35-fbfdabcb478e' + }; + it('should return true when required params found', function () { + expect(spec.isBidRequestValid(videoBidWithMediaTypes)).to.equal(true); + }); - it('should return false when required params are not passed', () => { - let videoBidWithMediaTypes = Object.assign({}, videoBidWithMediaTypes); - videoBidWithMediaTypes.params = {}; - expect(spec.isBidRequestValid(videoBidWithMediaTypes)).to.equal(false); + it('should return false when required params are not passed', function () { + let videoBidWithMediaTypes = Object.assign({}, videoBidWithMediaTypes); + videoBidWithMediaTypes.params = {}; + expect(spec.isBidRequestValid(videoBidWithMediaTypes)).to.equal(false); + }); + it('should send bid request to openx url via GET, with mediaType specified as video', function () { + const request = spec.buildRequests([videoBidWithMediaTypes]); + expect(request[0].url).to.equal(`//${videoBidWithMediaTypes.params.delDomain}${URLBASEVIDEO}`); + expect(request[0].data.ph).to.be.undefined; + expect(request[0].method).to.equal('GET'); + }); }); + describe('and request config uses both delDomain and platform', () => { + const videoBidWithDelDomainAndPlatform = { + bidder: 'openx', + params: { + unit: '12345678', + delDomain: 'test-del-domain', + platform: '1cabba9e-cafe-3665-beef-f00f00f00f00', + }, + adUnitCode: 'adunit-code', + mediaTypes: { + video: { + playerSize: [640, 480] + } + }, + bidId: '30b31c1838de1e', + bidderRequestId: '22edbae2733bf6', + auctionId: '1d1a030790a475', + transactionId: '4008d88a-8137-410b-aa35-fbfdabcb478e' + }; + it('should return true when required params found', function () { + expect(spec.isBidRequestValid(videoBidWithDelDomainAndPlatform)).to.equal(true); + }); - it('should return true when required params found', () => { - expect(spec.isBidRequestValid(videoBidWithMediaType)).to.equal(true); + it('should return false when required params are not passed', function () { + let videoBidWithMediaTypes = Object.assign({}, videoBidWithDelDomainAndPlatform); + videoBidWithMediaTypes.params = {}; + expect(spec.isBidRequestValid(videoBidWithMediaTypes)).to.equal(false); + }); + it('should send bid request to openx url via GET, with mediaType specified as video', function () { + const request = spec.buildRequests([videoBidWithDelDomainAndPlatform]); + expect(request[0].url).to.equal(`//u.openx.net${URLBASEVIDEO}`); + expect(request[0].data.ph).to.equal(videoBidWithDelDomainAndPlatform.params.platform); + expect(request[0].method).to.equal('GET'); + }); }); + describe('and request config uses mediaType', () => { + const videoBidWithMediaType = { + 'bidder': 'openx', + 'params': { + 'unit': '12345678', + 'delDomain': 'test-del-domain' + }, + 'adUnitCode': 'adunit-code', + 'mediaType': 'video', + 'sizes': [640, 480], + 'bidId': '30b31c1838de1e', + 'bidderRequestId': '22edbae2733bf6', + 'auctionId': '1d1a030790a475', + 'transactionId': '4008d88a-8137-410b-aa35-fbfdabcb478e' + }; + it('should return true when required params found', function () { + expect(spec.isBidRequestValid(videoBidWithMediaType)).to.equal(true); + }); - it('should return false when required params are not passed', () => { - let videoBidWithMediaType = Object.assign({}, videoBidWithMediaType); - delete videoBidWithMediaType.params; - videoBidWithMediaType.params = {}; - expect(spec.isBidRequestValid(videoBidWithMediaType)).to.equal(false); + it('should return false when required params are not passed', function () { + let videoBidWithMediaType = Object.assign({}, videoBidWithMediaType); + delete videoBidWithMediaType.params; + videoBidWithMediaType.params = {}; + expect(spec.isBidRequestValid(videoBidWithMediaType)).to.equal(false); + }); + it('should send bid request to openx url via GET, with mediaType specified as video', function () { + const request = spec.buildRequests([videoBidWithMediaType]); + expect(request[0].url).to.equal(`//${videoBidWithMediaType.params.delDomain}${URLBASEVIDEO}`); + expect(request[0].data.ph).to.be.undefined; + expect(request[0].method).to.equal('GET'); + }); }); }); }); - describe('buildRequests for banner ads', () => { + describe('buildRequests for banner ads', function () { const bidRequestsWithMediaType = [{ 'bidder': 'openx', 'params': { @@ -279,25 +328,105 @@ describe('OpenxAdapter', () => { 'bidderRequestId': 'test-bid-request-2', 'auctionId': 'test-auction-2' }]; + const bidRequestsWithPlatform = [{ + 'bidder': 'openx', + 'params': { + 'unit': '11', + 'platform': '1cabba9e-cafe-3665-beef-f00f00f00f00', + }, + 'adUnitCode': '/adunit-code/test-path', + mediaTypes: { + banner: { + sizes: [[300, 250], [300, 600]] + } + }, + 'bidId': 'test-bid-id-1', + 'bidderRequestId': 'test-bid-request-1', + 'auctionId': 'test-auction-1' + }, { + 'bidder': 'openx', + 'params': { + 'unit': '11', + 'platform': '1cabba9e-cafe-3665-beef-f00f00f00f00', + }, + 'adUnitCode': '/adunit-code/test-path', + mediaTypes: { + banner: { + sizes: [[300, 250], [300, 600]] + } + }, + 'bidId': 'test-bid-id-1', + 'bidderRequestId': 'test-bid-request-1', + 'auctionId': 'test-auction-1' + }]; + const bidRequestsWithPlatformAndDelDomain = [{ + 'bidder': 'openx', + 'params': { + 'unit': '11', + 'delDomain': 'test-del-domain', + 'platform': '1cabba9e-cafe-3665-beef-f00f00f00f00', + }, + 'adUnitCode': '/adunit-code/test-path', + mediaTypes: { + banner: { + sizes: [[300, 250], [300, 600]] + } + }, + 'bidId': 'test-bid-id-1', + 'bidderRequestId': 'test-bid-request-1', + 'auctionId': 'test-auction-1' + }, { + 'bidder': 'openx', + 'params': { + 'unit': '11', + 'delDomain': 'test-del-domain', + 'platform': '1cabba9e-cafe-3665-beef-f00f00f00f00', + }, + 'adUnitCode': '/adunit-code/test-path', + mediaTypes: { + banner: { + sizes: [[300, 250], [300, 600]] + } + }, + 'bidId': 'test-bid-id-1', + 'bidderRequestId': 'test-bid-request-1', + 'auctionId': 'test-auction-1' + }]; - it('should send bid request to openx url via GET, with mediaType specified as banner', () => { + it('should send bid request to openx url via GET, with mediaType specified as banner', function () { const request = spec.buildRequests(bidRequestsWithMediaType); expect(request[0].url).to.equal('//' + bidRequestsWithMediaType[0].params.delDomain + URLBASE); + expect(request[0].data.ph).to.be.undefined; expect(request[0].method).to.equal('GET'); }); - it('should send bid request to openx url via GET, with mediaTypes specified with banner type', () => { + it('should send bid request to openx url via GET, with mediaTypes specified with banner type', function () { const request = spec.buildRequests(bidRequestsWithMediaTypes); expect(request[0].url).to.equal('//' + bidRequestsWithMediaTypes[0].params.delDomain + URLBASE); + expect(request[0].data.ph).to.be.undefined; + expect(request[0].method).to.equal('GET'); + }); + + it('should send bid request to openx platform url via GET, if platform is present', function () { + const request = spec.buildRequests(bidRequestsWithPlatform); + expect(request[0].url).to.equal(`//u.openx.net${URLBASE}`); + expect(request[0].data.ph).to.equal(bidRequestsWithPlatform[0].params.platform); + expect(request[0].method).to.equal('GET'); + }); + + it('should send bid request to openx platform url via GET, if both params present', function () { + const request = spec.buildRequests(bidRequestsWithPlatformAndDelDomain); + expect(request[0].url).to.equal(`//u.openx.net${URLBASE}`); + expect(request[0].data.ph).to.equal(bidRequestsWithPlatform[0].params.platform); expect(request[0].method).to.equal('GET'); }); - it('should send the adunit codes', () => { + it('should send the adunit codes', function () { const request = spec.buildRequests(bidRequestsWithMediaTypes); expect(request[0].data.divIds).to.equal(`${encodeURIComponent(bidRequestsWithMediaTypes[0].adUnitCode)},${encodeURIComponent(bidRequestsWithMediaTypes[1].adUnitCode)}`); }); - it('should send ad unit ids when any are defined', () => { + it('should send ad unit ids when any are defined', function () { const bidRequestsWithUnitIds = [{ 'bidder': 'openx', 'params': { @@ -332,7 +461,7 @@ describe('OpenxAdapter', () => { expect(request[0].data.auid).to.equal(`,${bidRequestsWithUnitIds[1].params.unit}`); }); - it('should not send any ad unit ids when none are defined', () => { + it('should not send any ad unit ids when none are defined', function () { const bidRequestsWithoutUnitIds = [{ 'bidder': 'openx', 'params': { @@ -386,7 +515,7 @@ describe('OpenxAdapter', () => { requestData = spec.buildRequests(deprecatedBidRequestsFormatWithNoMediaType)[0].data; }); - it('should have an ad unit id', () => { + it('should have an ad unit id', function () { expect(requestData.auid).to.equal('12345678'); }); @@ -395,7 +524,7 @@ describe('OpenxAdapter', () => { }); }); - it('should send out custom params on bids that have customParams specified', () => { + it('should send out custom params on bids that have customParams specified', function () { const bidRequest = Object.assign({}, bidRequestsWithMediaTypes[0], { @@ -414,7 +543,7 @@ describe('OpenxAdapter', () => { expect(dataParams.tps).to.equal(btoa('test1=testval1.&test2=testval2_,testval3')); }); - it('should send out custom floors on bids that have customFloors specified', () => { + it('should send out custom floors on bids that have customFloors specified', function () { const bidRequest = Object.assign({}, bidRequestsWithMediaTypes[0], { @@ -433,7 +562,7 @@ describe('OpenxAdapter', () => { expect(dataParams.aumfs).to.equal('1500'); }); - it('should send out custom bc parameter, if override is present', () => { + it('should send out custom bc parameter, if override is present', function () { const bidRequest = Object.assign({}, bidRequestsWithMediaTypes[0], { @@ -459,13 +588,13 @@ describe('OpenxAdapter', () => { expect(request[0].data.x_gdpr_f).to.equal(undefined); }); - describe('when there is a consent management framework', () => { + describe('when there is a consent management framework', function () { let bidRequests; let mockConfig; let bidderRequest; const IAB_CONSENT_FRAMEWORK_CODE = 1; - beforeEach(() => { + beforeEach(function () { bidRequests = [{ bidder: 'openx', params: { @@ -632,7 +761,7 @@ describe('OpenxAdapter', () => { }); }); - it('should not send a coppa query param when there are no coppa param settings in the bid requests', () => { + it('should not send a coppa query param when there are no coppa param settings in the bid requests', function () { const bidRequestsWithoutCoppa = [{ bidder: 'openx', params: { @@ -669,7 +798,7 @@ describe('OpenxAdapter', () => { expect(request[0].data).to.not.have.any.keys('tfcd'); }); - it('should send a coppa flag there is when there is coppa param settings in the bid requests', () => { + it('should send a coppa flag there is when there is coppa param settings in the bid requests', function () { const bidRequestsWithCoppa = [{ bidder: 'openx', params: { @@ -707,7 +836,7 @@ describe('OpenxAdapter', () => { expect(request[0].data.tfcd).to.equal(1); }); - it('should not send a "no segmentation" flag there no DoNotTrack setting that is set to true', () => { + it('should not send a "no segmentation" flag there no DoNotTrack setting that is set to true', function () { const bidRequestsWithoutDnt = [{ bidder: 'openx', params: { @@ -744,7 +873,7 @@ describe('OpenxAdapter', () => { expect(request[0].data).to.not.have.any.keys('ns'); }); - it('should send a "no segmentation" flag there is any DoNotTrack setting that is set to true', () => { + it('should send a "no segmentation" flag there is any DoNotTrack setting that is set to true', function () { const bidRequestsWithDnt = [{ bidder: 'openx', params: { @@ -781,9 +910,40 @@ describe('OpenxAdapter', () => { const request = spec.buildRequests(bidRequestsWithDnt); expect(request[0].data.ns).to.equal(1); }); + + describe('publisher common id query param', function() { + it('should not send a pubcid query param when there is no crumbs.pubcid defined in the bid requests', function () { + const request = spec.buildRequests(bidRequestsWithMediaType); + expect(request[0].data).to.not.have.any.keys('pubcid'); + }); + + it('should send a pubcid query param when crumbs.pubcid is defined in the bid requests', function () { + const bidRequestsWithPubcid = [{ + bidder: 'openx', + params: { + unit: '11', + delDomain: 'test-del-domain' + }, + crumbs: { + pubcid: 'c4a4c843-2368-4b5e-b3b1-6ee4702b9ad6' + }, + adUnitCode: 'adunit-code', + mediaTypes: { + banner: { + sizes: [[300, 250], [300, 600]] + } + }, + bidId: 'test-bid-id-1', + bidderRequestId: 'test-bid-request-1', + auctionId: 'test-auction-1' + }]; + const request = spec.buildRequests(bidRequestsWithPubcid); + expect(request[0].data.pubcid).to.equal('c4a4c843-2368-4b5e-b3b1-6ee4702b9ad6'); + }); + }) }); - describe('buildRequests for video', () => { + describe('buildRequests for video', function () { const bidRequestsWithMediaTypes = [{ 'bidder': 'openx', 'mediaTypes': { @@ -818,19 +978,19 @@ describe('OpenxAdapter', () => { 'transactionId': '4008d88a-8137-410b-aa35-fbfdabcb478e' }]; - it('should send bid request to openx url via GET, with mediaType as video', () => { + it('should send bid request to openx url via GET, with mediaType as video', function () { const request = spec.buildRequests(bidRequestsWithMediaType); expect(request[0].url).to.equal('//' + bidRequestsWithMediaType[0].params.delDomain + URLBASEVIDEO); expect(request[0].method).to.equal('GET'); }); - it('should send bid request to openx url via GET, with mediaTypes having video parameter', () => { + it('should send bid request to openx url via GET, with mediaTypes having video parameter', function () { const request = spec.buildRequests(bidRequestsWithMediaTypes); expect(request[0].url).to.equal('//' + bidRequestsWithMediaTypes[0].params.delDomain + URLBASEVIDEO); expect(request[0].method).to.equal('GET'); }); - it('should have the correct parameters', () => { + it('should have the correct parameters', function () { const request = spec.buildRequests(bidRequestsWithMediaTypes); const dataParams = request[0].data; @@ -839,6 +999,13 @@ describe('OpenxAdapter', () => { expect(dataParams.vwd).to.equal(640); }); + it('should send a bc parameter', function () { + const request = spec.buildRequests(bidRequestsWithMediaTypes); + const dataParams = request[0].data; + + expect(dataParams.bc).to.have.string('hb_pb'); + }); + describe('when using the video param', function () { let videoBidRequest; @@ -926,8 +1093,8 @@ describe('OpenxAdapter', () => { }); }); - describe('interpretResponse for banner ads', () => { - beforeEach(() => { + describe('interpretResponse for banner ads', function () { + beforeEach(function () { sinon.spy(userSync, 'registerSync'); }); @@ -1023,7 +1190,7 @@ describe('OpenxAdapter', () => { expect(bid.ts).to.equal(adUnitOverride.ts); }); - it('should register a beacon', () => { + it('should register a beacon', function () { resetBoPixel(); spec.interpretResponse({body: bidResponse}, bidRequest); sinon.assert.calledWith(userSync.registerSync, 'image', 'openx', sinon.match(new RegExp(`\/\/openx-d\.openx\.net.*\/bo\?.*ts=${adUnitOverride.ts}`))); @@ -1100,7 +1267,7 @@ describe('OpenxAdapter', () => { }; }); - it('handles nobid responses', () => { + it('handles nobid responses', function () { const bidResponse = { 'ads': { @@ -1208,8 +1375,8 @@ describe('OpenxAdapter', () => { }); }); - describe('interpretResponse for video ads', () => { - beforeEach(() => { + describe('interpretResponse for video ads', function () { + beforeEach(function () { sinon.spy(userSync, 'registerSync'); }); @@ -1266,7 +1433,7 @@ describe('OpenxAdapter', () => { 'pixels': 'http://testpixels.net' }; - it('should return correct bid response with MediaTypes', () => { + it('should return correct bid response with MediaTypes', function () { const expectedResponse = [ { 'requestId': '30b31c1838de1e', @@ -1287,7 +1454,7 @@ describe('OpenxAdapter', () => { expect(JSON.stringify(Object.keys(result[0]).sort())).to.eql(JSON.stringify(Object.keys(expectedResponse[0]).sort())); }); - it('should return correct bid response with MediaType', () => { + it('should return correct bid response with MediaType', function () { const expectedResponse = [ { 'requestId': '30b31c1838de1e', @@ -1308,19 +1475,19 @@ describe('OpenxAdapter', () => { expect(JSON.stringify(Object.keys(result[0]).sort())).to.eql(JSON.stringify(Object.keys(expectedResponse[0]).sort())); }); - it('should handle nobid responses for bidRequests with MediaTypes', () => { + it('should handle nobid responses for bidRequests with MediaTypes', function () { const bidResponse = {'vastUrl': '', 'pub_rev': '', 'width': '', 'height': '', 'adid': '', 'pixels': ''}; const result = spec.interpretResponse({body: bidResponse}, bidRequestsWithMediaTypes); expect(result.length).to.equal(0); }); - it('should handle nobid responses for bidRequests with MediaType', () => { + it('should handle nobid responses for bidRequests with MediaType', function () { const bidResponse = {'vastUrl': '', 'pub_rev': '', 'width': '', 'height': '', 'adid': '', 'pixels': ''}; const result = spec.interpretResponse({body: bidResponse}, bidRequestsWithMediaType); expect(result.length).to.equal(0); }); - it('should register a beacon', () => { + it('should register a beacon', function () { resetBoPixel(); spec.interpretResponse({body: bidResponse}, bidRequestsWithMediaTypes); sinon.assert.calledWith(userSync.registerSync, 'image', 'openx', sinon.match(/^\/\/test-colo\.com/)) @@ -1329,31 +1496,67 @@ describe('OpenxAdapter', () => { }); }); - describe('user sync', () => { + describe('user sync', function () { const syncUrl = 'http://testpixels.net'; - it('should register the pixel iframe from banner ad response', () => { - let syncs = spec.getUserSyncs( - {iframeEnabled: true}, - [{body: {ads: {pixels: syncUrl}}}] - ); - expect(syncs).to.deep.equal([{type: 'iframe', url: syncUrl}]); + describe('iframe sync', function () { + it('should register the pixel iframe from banner ad response', function () { + let syncs = spec.getUserSyncs( + {iframeEnabled: true}, + [{body: {ads: {pixels: syncUrl}}}] + ); + expect(syncs).to.deep.equal([{type: 'iframe', url: syncUrl}]); + }); + + it('should register the pixel iframe from video ad response', function () { + let syncs = spec.getUserSyncs( + {iframeEnabled: true}, + [{body: {pixels: syncUrl}}] + ); + expect(syncs).to.deep.equal([{type: 'iframe', url: syncUrl}]); + }); + + it('should register the default iframe if no pixels available', function () { + let syncs = spec.getUserSyncs( + {iframeEnabled: true}, + [] + ); + expect(syncs).to.deep.equal([{type: 'iframe', url: '//u.openx.net/w/1.0/pd'}]); + }); }); - it('should register the pixel iframe from video ad response', () => { - let syncs = spec.getUserSyncs( - {iframeEnabled: true}, - [{body: {pixels: syncUrl}}] - ); - expect(syncs).to.deep.equal([{type: 'iframe', url: syncUrl}]); + describe('pixel sync', function () { + it('should register the image pixel from banner ad response', function () { + let syncs = spec.getUserSyncs( + {pixelEnabled: true}, + [{body: {ads: {pixels: syncUrl}}}] + ); + expect(syncs).to.deep.equal([{type: 'image', url: syncUrl}]); + }); + + it('should register the image pixel from video ad response', function () { + let syncs = spec.getUserSyncs( + {pixelEnabled: true}, + [{body: {pixels: syncUrl}}] + ); + expect(syncs).to.deep.equal([{type: 'image', url: syncUrl}]); + }); + + it('should register the default image pixel if no pixels available', function () { + let syncs = spec.getUserSyncs( + {pixelEnabled: true}, + [] + ); + expect(syncs).to.deep.equal([{type: 'image', url: '//u.openx.net/w/1.0/pd'}]); + }); }); - it('should register the default iframe if no pixels available', () => { + it('should prioritize iframe over image for user sync', function () { let syncs = spec.getUserSyncs( - {iframeEnabled: true}, - [] + {iframeEnabled: true, pixelEnabled: true}, + [{body: {ads: {pixels: syncUrl}}}] ); - expect(syncs).to.deep.equal([{type: 'iframe', url: '//u.openx.net/w/1.0/pd'}]); + expect(syncs).to.deep.equal([{type: 'iframe', url: syncUrl}]); }); }); diff --git a/test/spec/modules/openxoutstreamBidAdapter_spec.js b/test/spec/modules/openxoutstreamBidAdapter_spec.js new file mode 100644 index 00000000000..9b189856e1a --- /dev/null +++ b/test/spec/modules/openxoutstreamBidAdapter_spec.js @@ -0,0 +1,239 @@ +import {expect} from 'chai'; +import {spec} from 'modules/openxoutstreamBidAdapter'; +import {newBidder} from 'src/adapters/bidderFactory'; + +describe('OpenXOutstreamAdapter', function () { + const adapter = newBidder(spec); + const URLBASE = '/v/1.0/avjp'; + const BIDDER = 'openxoutstream'; + const div = document.createElement('div'); + const PLACEMENT_ID = '1986307928000988495'; + const YM_SCRIPT = `!function(e,t){if(void 0===t._ym){var a=Math.round(5*Math.random()/3)+'';t._ym='';var m=e.createElement('script');m.type='text/javascript',m.async=!0,m.src='//static.yieldmo.com/ym.'+a+'.js',(e.getElementsByTagName('head')[0]||e.getElementsByTagName('body')[0]).appendChild(m)}else t._ym instanceof String||void 0===t._ym.chkPls||t._ym.chkPls()}(document,window);`; + const PUBLISHER_ID = '1986307525700126029'; + const CR_ID = '2052941939925262540'; + const AD_ID = '1991358644725162800'; + + describe('inherited functions', function () { + it('exists and is a function', function () { + expect(adapter.callBids).to.exist.and.to.be.a('function'); + }); + }); + + describe('isBidRequestValid', function () { + describe('when request is for a banner ad', function () { + let bannerBid; + beforeEach(function () { + bannerBid = { + bidder: BIDDER, + params: {}, + adUnitCode: 'adunit-code', + mediaTypes: {banner: {}}, + sizes: [[300, 250], [300, 600]], + bidId: '30b31c1838de1e', + bidderRequestId: '22edbae2733bf6', + auctionId: '1d1a030790a475' + }; + }); + it('should return false when there is no delivery domain', function () { + bannerBid.params = {'unit': '12345678'}; + expect(spec.isBidRequestValid(bannerBid)).to.equal(false); + }); + + describe('when there is a delivery domain', function () { + beforeEach(function () { + bannerBid.params = {delDomain: 'test-delivery-domain'} + }); + + it('should return false if there is no adunit id and sizes are defined', function () { + bannerBid.mediaTypes.banner.sizes = [720, 90]; + expect(spec.isBidRequestValid(bannerBid)).to.equal(false); + }); + + it('should return true if there is delivery domain and unit', function () { + bannerBid.params.unit = '12345678'; + expect(spec.isBidRequestValid(bannerBid)).to.equal(true); + }); + it('should return false if there is unit but no delivery domain', function () { + bannerBid.params = {unit: '12345678'}; + expect(spec.isBidRequestValid(bannerBid)).to.equal(false); + }); + it('shoud return false if there is no delivery domain and no unit', function () { + bannerBid.params = {}; + expect(spec.isBidRequestValid(bannerBid)).to.equal(false); + }) + }); + }); + }); + + describe('buildRequests for banner ads', function () { + const bidRequestsWithMediaType = [{ + 'bidder': BIDDER, + 'params': { + 'unit': '12345678', + 'delDomain': 'test-del-domain' + }, + 'adUnitCode': 'adunit-code', + 'mediaType': 'banner', + 'sizes': [[300, 250], [300, 600]], + 'bidId': '30b31c1838de1e', + 'bidderRequestId': '22edbae2733bf6', + 'auctionId': '1d1a030790a475' + }]; + + it('should send bid request to openx url via GET, with mediaType specified as banner', function () { + const request = spec.buildRequests(bidRequestsWithMediaType); + const params = bidRequestsWithMediaType[0].params; + expect(request[0].url).to.equal(`https://` + params.delDomain + URLBASE); + expect(request[0].method).to.equal('GET'); + }); + + it('should send ad unit ids, height, and width when any are defined', function () { + const bidRequestsWithUnitIds = [{ + 'bidder': BIDDER, + 'params': { + 'unit': '540141567', + 'height': '300', + 'width': '250', + 'delDomain': 'test-del-domain' + }, + 'adUnitCode': 'adunit-code', + sizes: [300, 250], + mediaTypes: { + banner: { + sizes: [[728, 90]] + } + }, + 'bidId': 'test-bid-id-2', + 'bidderRequestId': 'test-bid-request-2', + 'auctionId': 'test-auction-2' + }, { + 'bidder': BIDDER, + 'params': { + 'delDomain': 'test-del-domain' + }, + 'adUnitCode': 'adunit-code', + 'sizes': [300, 250], + mediaTypes: { + banner: { + sizes: [[300, 250], [300, 600]] + } + }, + 'bidId': 'test-bid-id-1', + 'bidderRequestId': 'test-bid-request-1', + 'auctionId': 'test-auction-1' + }]; + const request = spec.buildRequests(bidRequestsWithUnitIds); + expect(request[0].data.auid).to.equal(`${bidRequestsWithUnitIds[0].params.unit}`); + expect(request[0].data.vht).to.equal(`${bidRequestsWithUnitIds[0].params.height}`); + expect(request[0].data.vwd).to.equal(`${bidRequestsWithUnitIds[0].params.width}`); + }); + + describe('interpretResponse', function () { + let serverResponse; + let serverRequest; + + beforeEach(function () { + serverResponse = { + body: { + width: 300, + height: 250, + pub_rev: 3000, + bidderCode: 'openxoutstream', + vastUrl: 'test.vast.url', + mediaType: 'banner', + adid: '9874652394875' + }, + header: 'header?', + }; + serverRequest = { + payload: { + bid: { + bidId: '2d36ac90d654af', + }, + } + }; + }); + + it('should correctly reorder the server response', function () { + const newResponse = spec.interpretResponse(serverResponse, serverRequest); + const openHtmlTag = ''; + const closeHtmlTag = ''; + const sdkScript = createSdkScript().outerHTML; + const placementDiv = createPlacementDiv(); + placementDiv.dataset.pId = PUBLISHER_ID; + const placementDivString = placementDiv.outerHTML; + const adResponse = getTemplateAdResponse(serverResponse.body.vastUrl, PLACEMENT_ID); + const adResponseString = JSON.stringify(adResponse); + const ymAdsScript = ''; + expect(newResponse.length).to.be.equal(1); + expect(newResponse[0]).to.deep.equal({ + requestId: '2d36ac90d654af', + bidderCode: 'openxoutstream', + vastUrl: 'test.vast.url', + mediaType: 'banner', + cpm: 3, + width: 300, + height: 250, + creativeId: '9874652394875', + currency: 'USD', + netRevenue: true, + ttl: 300, + ad: openHtmlTag + placementDivString + ymAdsScript + sdkScript + closeHtmlTag + }); + }); + + it('should not add responses if the cpm is 0 or null', function () { + serverResponse.body.pub_rev = 0; + let response = spec.interpretResponse(serverResponse, serverRequest); + expect(response).to.deep.equal([]); + + serverResponse.body.pub_rev = null; + response = spec.interpretResponse(serverResponse, serverRequest); + expect(response).to.deep.equal([]) + }); + }); + }) + + function createSdkScript() { + const script = document.createElement('script'); + script.innerHTML = YM_SCRIPT; + return script; + } + function createPlacementDiv() { + div.id = `ym_${PLACEMENT_ID}`; + div.classList.add('ym'); + div.dataset.lfId = CR_ID; + return div + } + const getTemplateAdResponse = (vastUrl) => { + return { + availability_zone: 'us-east-1a', + data: [ + { + ads: [ + { + actions: {}, + adv_id: AD_ID, + configurables: { + cta_button_copy: 'Learn More', + vast_click_tracking: 'true', + vast_url: vastUrl, + }, + cr_id: CR_ID, + } + ], + column_count: 1, + configs: { + allowable_height: '248', + header_copy: 'You May Like', + ping: 'true', + }, + creative_format_id: 40, + css: '', + placement_id: PLACEMENT_ID, + } + ], + nc: 0, + }; + }; +}); diff --git a/test/spec/modules/optimaticBidAdapter_spec.js b/test/spec/modules/optimaticBidAdapter_spec.js index d701d981f37..3dd7ca79cc7 100644 --- a/test/spec/modules/optimaticBidAdapter_spec.js +++ b/test/spec/modules/optimaticBidAdapter_spec.js @@ -2,10 +2,10 @@ import { expect } from 'chai'; import { spec, ENDPOINT } from 'modules/optimaticBidAdapter'; import * as utils from 'src/utils'; -describe('OptimaticBidAdapter', () => { +describe('OptimaticBidAdapter', function () { let bidRequest; - beforeEach(() => { + beforeEach(function () { bidRequest = { bidder: 'optimatic', params: { @@ -20,49 +20,49 @@ describe('OptimaticBidAdapter', () => { }; }); - describe('spec.isBidRequestValid', () => { - it('should return true when the required params are passed', () => { + describe('spec.isBidRequestValid', function () { + it('should return true when the required params are passed', function () { expect(spec.isBidRequestValid(bidRequest)).to.equal(true); }); - it('should return false when the "bidfloor" param is missing', () => { + it('should return false when the "bidfloor" param is missing', function () { bidRequest.params = { placement: '2chy7Gc2eSQL' }; expect(spec.isBidRequestValid(bidRequest)).to.equal(false); }); - it('should return false when the "placement" param is missing', () => { + it('should return false when the "placement" param is missing', function () { bidRequest.params = { bidfloor: 5.00 }; expect(spec.isBidRequestValid(bidRequest)).to.equal(false); }); - it('should return false when no bid params are passed', () => { + it('should return false when no bid params are passed', function () { bidRequest.params = {}; expect(spec.isBidRequestValid(bidRequest)).to.equal(false); }); - it('should return false when a bid request is not passed', () => { + it('should return false when a bid request is not passed', function () { expect(spec.isBidRequestValid()).to.equal(false); expect(spec.isBidRequestValid({})).to.equal(false); }); }); - describe('spec.buildRequests', () => { - it('should create a POST request for every bid', () => { + describe('spec.buildRequests', function () { + it('should create a POST request for every bid', function () { const requests = spec.buildRequests([ bidRequest ]); expect(requests[0].method).to.equal('POST'); expect(requests[0].url).to.equal(ENDPOINT + bidRequest.params.placement); }); - it('should attach the bid request object', () => { + it('should attach the bid request object', function () { const requests = spec.buildRequests([ bidRequest ]); expect(requests[0].bidRequest).to.equal(bidRequest); }); - it('should attach request data', () => { + it('should attach request data', function () { const requests = spec.buildRequests([ bidRequest ]); const data = requests[0].data; const [ width, height ] = bidRequest.sizes; @@ -71,7 +71,7 @@ describe('OptimaticBidAdapter', () => { expect(data.imp[0].bidfloor).to.equal(bidRequest.params.bidfloor); }); - it('must parse bid size from a nested array', () => { + it('must parse bid size from a nested array', function () { const width = 640; const height = 480; bidRequest.sizes = [[ width, height ]]; @@ -81,7 +81,7 @@ describe('OptimaticBidAdapter', () => { expect(data.imp[0].video.h).to.equal(height); }); - it('must parse bid size from a string', () => { + it('must parse bid size from a string', function () { const width = 640; const height = 480; bidRequest.sizes = `${width}x${height}`; @@ -91,7 +91,7 @@ describe('OptimaticBidAdapter', () => { expect(data.imp[0].video.h).to.equal(height); }); - it('must handle an empty bid size', () => { + it('must handle an empty bid size', function () { bidRequest.sizes = []; const requests = spec.buildRequests([ bidRequest ]); const data = requests[0].data; @@ -100,25 +100,25 @@ describe('OptimaticBidAdapter', () => { }); }); - describe('spec.interpretResponse', () => { - it('should return no bids if the response is not valid', () => { + describe('spec.interpretResponse', function () { + it('should return no bids if the response is not valid', function () { const bidResponse = spec.interpretResponse({ body: null }, { bidRequest }); expect(bidResponse.length).to.equal(0); }); - it('should return no bids if the response "nurl" and "adm" are missing', () => { + it('should return no bids if the response "nurl" and "adm" are missing', function () { const serverResponse = {seatbid: [{bid: [{price: 5.01}]}]}; const bidResponse = spec.interpretResponse({ body: serverResponse }, { bidRequest }); expect(bidResponse.length).to.equal(0); }); - it('should return no bids if the response "price" is missing', () => { + it('should return no bids if the response "price" is missing', function () { const serverResponse = {seatbid: [{bid: [{adm: ''}]}]}; const bidResponse = spec.interpretResponse({ body: serverResponse }, { bidRequest }); expect(bidResponse.length).to.equal(0); }); - it('should return a valid bid response with just "adm"', () => { + it('should return a valid bid response with just "adm"', function () { const serverResponse = {seatbid: [{bid: [{id: 1, price: 5.01, adm: ''}]}], cur: 'USD'}; const bidResponse = spec.interpretResponse({ body: serverResponse }, { bidRequest }); let o = { @@ -137,7 +137,7 @@ describe('OptimaticBidAdapter', () => { expect(bidResponse).to.deep.equal(o); }); - it('should return a valid bid response with just "nurl"', () => { + it('should return a valid bid response with just "nurl"', function () { const serverResponse = {seatbid: [{bid: [{id: 1, price: 5.01, nurl: 'https://mg-bid-win.optimatic.com/win/134eb262-948a-463e-ad93-bc8b622d399c?wp=${AUCTION_PRICE}'}]}], cur: 'USD'}; const bidResponse = spec.interpretResponse({ body: serverResponse }, { bidRequest }); let o = { @@ -156,7 +156,7 @@ describe('OptimaticBidAdapter', () => { expect(bidResponse).to.deep.equal(o); }); - it('should return a valid bid response with "nurl" when both nurl and adm exist', () => { + it('should return a valid bid response with "nurl" when both nurl and adm exist', function () { const serverResponse = {seatbid: [{bid: [{id: 1, price: 5.01, adm: '', nurl: 'https://mg-bid-win.optimatic.com/win/134eb262-948a-463e-ad93-bc8b622d399c?wp=${AUCTION_PRICE}'}]}], cur: 'USD'}; const bidResponse = spec.interpretResponse({ body: serverResponse }, { bidRequest }); let o = { diff --git a/test/spec/modules/optimeraBidAdapter_spec.js b/test/spec/modules/optimeraBidAdapter_spec.js index 413a52d2d7f..ff5793b5040 100644 --- a/test/spec/modules/optimeraBidAdapter_spec.js +++ b/test/spec/modules/optimeraBidAdapter_spec.js @@ -2,16 +2,16 @@ import { expect } from 'chai'; import { spec } from 'modules/optimeraBidAdapter'; import { newBidder } from 'src/adapters/bidderFactory'; -describe('OptimeraAdapter', () => { +describe('OptimeraAdapter', function () { const adapter = newBidder(spec); - describe('inherited functions', () => { - it('exists and is a function', () => { + describe('inherited functions', function () { + it('exists and is a function', function () { expect(adapter.callBids).to.exist.and.to.be.a('function'); }); }) - describe('isBidRequestValid', () => { + describe('isBidRequestValid', function () { let bid = { 'bidder': 'optimera', 'params': { @@ -24,12 +24,12 @@ describe('OptimeraAdapter', () => { 'auctionId': '1d1a030790a475', }; - it('should return true when required params found', () => { + it('should return true when required params found', function () { expect(spec.isBidRequestValid(bid)).to.equal(true); }); }) - describe('buildRequests', () => { + describe('buildRequests', function () { let bid = [ { 'adUnitCode': 'div-0', @@ -42,7 +42,7 @@ describe('OptimeraAdapter', () => { } } ]; - it('buildRequests fires', () => { + it('buildRequests fires', function () { let request = spec.buildRequests(bid); expect(request).to.exist; expect(request.method).to.equal('GET'); @@ -51,7 +51,7 @@ describe('OptimeraAdapter', () => { }); }) - describe('interpretResponse', () => { + describe('interpretResponse', function () { let serverResponse = {}; serverResponse.body = JSON.parse('{"div-0":["RB_K","728x90K"], "timestamp":["RB_K","1507565666"]}'); var bidRequest = { @@ -67,7 +67,7 @@ describe('OptimeraAdapter', () => { } ] } - it('interpresResponse fires', () => { + it('interpresResponse fires', function () { let bidResponses = spec.interpretResponse(serverResponse, bidRequest); expect(bidResponses[0].dealId[0]).to.equal('RB_K'); expect(bidResponses[0].dealId[1]).to.equal('728x90K'); diff --git a/test/spec/modules/orbidderBidAdapter_spec.js b/test/spec/modules/orbidderBidAdapter_spec.js new file mode 100644 index 00000000000..bf31a6ad7e5 --- /dev/null +++ b/test/spec/modules/orbidderBidAdapter_spec.js @@ -0,0 +1,194 @@ +import {expect} from 'chai'; +import {spec} from 'modules/orbidderBidAdapter'; +import {newBidder} from 'src/adapters/bidderFactory'; + +describe('orbidderBidAdapter', () => { + const adapter = newBidder(spec); + const bidRequest = { + bidId: 'd66fa86787e0b0ca900a96eacfd5f0bb', + auctionId: 'ccc4c7cdfe11cfbd74065e6dd28413d8', + transactionId: 'd58851660c0c4461e4aa06344fc9c0c6', + adUnitCode: 'adunit-code', + sizes: [[300, 250], [300, 600]], + params: { + 'foo': 'bar' + } + }; + + const buildRequest = function (buildRequest) { + return spec.buildRequests( + [buildRequest], + { + refererInfo: { + referer: 'http://localhost:9876/' + } + })[0]; + } + + describe('inherited functions', () => { + it('exists and is a function', () => { + expect(adapter.callBids).to.exist.and.to.be.a('function'); + }); + }); + + describe('isBidRequestValid', () => { + it('should return true when required params found', () => { + expect(spec.isBidRequestValid(bidRequest)).to.equal(true); + }); + + it('should return false when required params are not passed', () => { + let bidRequest = Object.assign({}, bidRequest); + delete bidRequest.params; + expect(spec.isBidRequestValid(bidRequest)).to.equal(false); + }); + }); + + describe('buildRequests', () => { + const request = buildRequest(bidRequest); + + it('sends bid request to endpoint via https using post', () => { + expect(request.method).to.equal('POST'); + expect(request.url.indexOf('https://')).to.equal(0); + expect(request.url).to.equal(`${spec.orbidderHost}/bid`); + }); + + it('sends correct bid parameters', () => { + // we add one, because we add referer information from bidderRequest object + expect(Object.keys(request.data).length).to.equal(Object.keys(bidRequest).length + 1); + expect(request.data.pageUrl).to.equal('http://localhost:9876/'); + // expect(request.data.referrer).to.equal(''); + Object.keys(bidRequest).forEach((key) => { + expect(bidRequest[key]).to.equal(request.data[key]); + }); + }); + + it('handles empty gdpr object', () => { + let bidRequest = Object.assign({}, bidRequest); + bidRequest.gdprConsent = {}; + + const request = buildRequest(bidRequest); + expect(request.data.gdprConsent.consentRequired).to.be.equal(true); + }); + + it('handles non-existent gdpr object', () => { + let bidRequest = Object.assign({}, bidRequest); + bidRequest.gdprConsent = null; + + const request = buildRequest(bidRequest); + expect(request.data.gdprConsent).to.be.undefined; + }); + + it('handles properly filled gdpr object where gdpr applies', () => { + const consentString = 'someWeirdString'; + const bidRequest = Object.assign({}, bidRequest); + bidRequest.gdprConsent = { + gdprApplies: true, + consentString: 'someWeirdString' + }; + + const request = buildRequest(bidRequest); + const gdprConsent = request.data.gdprConsent; + expect(gdprConsent.consentRequired).to.be.equal(true); + expect(gdprConsent.consentString).to.be.equal(consentString); + }); + + it('handles properly filled gdpr object where gdpr does not apply', () => { + const consentString = 'someWeirdString'; + const bidRequest = Object.assign({}, bidRequest); + bidRequest.gdprConsent = { + gdprApplies: false, + consentString: 'someWeirdString' + }; + + const request = buildRequest(bidRequest); + const gdprConsent = request.data.gdprConsent; + expect(gdprConsent.consentRequired).to.be.equal(false); + expect(gdprConsent.consentString).to.be.equal(consentString); + }); + }); + + describe('onBidWon', () => { + let ajaxStub; + const winObj = { + test: 1, + pageUrl: 'www.someurl.de', + referrer: 'www.somereferrer.de' + }; + + beforeEach(() => { + ajaxStub = sinon.stub(spec, 'ajaxCall'); + }); + + afterEach(() => { + ajaxStub.restore(); + }); + + it('calls orbidder\'s win endpoint', () => { + spec.onBidWon(winObj); + expect(ajaxStub.calledOnce).to.equal(true); + expect(ajaxStub.firstCall.args[0].indexOf('https://')).to.equal(0); + expect(ajaxStub.firstCall.args[0]).to.equal(`${spec.orbidderHost}/win`); + expect(ajaxStub.firstCall.args[1]).to.equal(JSON.stringify(winObj)); + }); + }); + + describe('interpretResponse', () => { + it('should get correct bid response', () => { + const serverResponse = [ + { + 'width': 300, + 'height': 250, + 'creativeId': '29681110', + 'ad': '', + 'cpm': 0.5, + 'requestId': '30b31c1838de1e', + 'ttl': 60, + 'netRevenue': true, + 'currency': 'EUR' + } + ]; + + const expectedResponse = [ + { + 'requestId': '30b31c1838de1e', + 'cpm': 0.5, + 'creativeId': '29681110', + 'width': 300, + 'height': 250, + 'ttl': 60, + 'currency': 'EUR', + 'ad': '', + 'netRevenue': true + } + ]; + + const result = spec.interpretResponse({body: serverResponse}); + + expect(result.length).to.equal(expectedResponse.length); + Object.keys(expectedResponse[0]).forEach((key) => { + expect(result[0][key]).to.equal(expectedResponse[0][key]); + }); + }); + + it('handles broken server response', () => { + const serverResponse = [ + { + 'ad': '', + 'cpm': 0.5, + 'requestId': '30b31c1838de1e', + 'ttl': 60 + } + ]; + const result = spec.interpretResponse({body: serverResponse}); + + expect(result.length).to.equal(0); + }); + + it('handles nobid responses', () => { + const serverResponse = []; + const result = spec.interpretResponse({body: serverResponse}); + + expect(result.length).to.equal(0); + }); + }); +}); diff --git a/test/spec/modules/orbitsoftBidAdapter_spec.js b/test/spec/modules/orbitsoftBidAdapter_spec.js index 50145a1e72e..18ba9a6e8f3 100644 --- a/test/spec/modules/orbitsoftBidAdapter_spec.js +++ b/test/spec/modules/orbitsoftBidAdapter_spec.js @@ -2,10 +2,10 @@ import {expect} from 'chai'; import {spec} from 'modules/orbitsoftBidAdapter'; const ENDPOINT_URL = 'https://orbitsoft.com/php/ads/hb.phps'; -describe('Orbitsoft adapter', () => { - describe('implementation', () => { - describe('for requests', () => { - it('should accept valid bid', () => { +describe('Orbitsoft adapter', function () { + describe('implementation', function () { + describe('for requests', function () { + it('should accept valid bid', function () { let validBid = { bidder: 'orbitsoft', params: { @@ -18,7 +18,7 @@ describe('Orbitsoft adapter', () => { expect(isValid).to.equal(true); }); - it('should reject invalid bid', () => { + it('should reject invalid bid', function () { let invalidBid = { bidder: 'orbitsoft' }, @@ -27,8 +27,8 @@ describe('Orbitsoft adapter', () => { expect(isValid).to.equal(false); }); }); - describe('for requests', () => { - it('should accept valid bid with styles', () => { + describe('for requests', function () { + it('should accept valid bid with styles', function () { let validBid = { bidder: 'orbitsoft', params: { @@ -91,7 +91,7 @@ describe('Orbitsoft adapter', () => { expect(requestUrlParams).have.property('c6', '5B99FE'); }); - it('should accept valid bid with custom params', () => { + it('should accept valid bid with custom params', function () { let validBid = { bidder: 'orbitsoft', params: { @@ -112,7 +112,7 @@ describe('Orbitsoft adapter', () => { expect(requestUrlCustomParams).have.property('c.clickUrl', 'http://testclickurl.com'); }); - it('should reject invalid bid without requestUrl', () => { + it('should reject invalid bid without requestUrl', function () { let invalidBid = { bidder: 'orbitsoft', params: { @@ -124,7 +124,7 @@ describe('Orbitsoft adapter', () => { expect(isValid).to.equal(false); }); - it('should reject invalid bid without placementId', () => { + it('should reject invalid bid without placementId', function () { let invalidBid = { bidder: 'orbitsoft', params: { @@ -136,8 +136,8 @@ describe('Orbitsoft adapter', () => { expect(isValid).to.equal(false); }); }); - describe('bid responses', () => { - it('should return complete bid response', () => { + describe('bid responses', function () { + it('should return complete bid response', function () { let serverResponse = { body: { callback_uid: '265b29b70cc106', @@ -168,7 +168,7 @@ describe('Orbitsoft adapter', () => { expect(bids[0].adUrl).to.have.string('https://orbitsoft.com/php/ads/hb.html'); }); - it('should return empty bid response', () => { + it('should return empty bid response', function () { let bidRequests = [ { bidder: 'orbitsoft', @@ -189,7 +189,7 @@ describe('Orbitsoft adapter', () => { expect(bids).to.be.lengthOf(0); }); - it('should return empty bid response on incorrect size', () => { + it('should return empty bid response on incorrect size', function () { let bidRequests = [ { bidder: 'orbitsoft', @@ -212,7 +212,7 @@ describe('Orbitsoft adapter', () => { expect(bids).to.be.lengthOf(0); }); - it('should return empty bid response with error', () => { + it('should return empty bid response with error', function () { let bidRequests = [ { bidder: 'orbitsoft', @@ -228,7 +228,7 @@ describe('Orbitsoft adapter', () => { expect(bids).to.be.lengthOf(0); }); - it('should return empty bid response on empty body', () => { + it('should return empty bid response on empty body', function () { let bidRequests = [ { bidder: 'orbitsoft', diff --git a/test/spec/modules/otmBidAdapter_spec.js b/test/spec/modules/otmBidAdapter_spec.js new file mode 100644 index 00000000000..0fe81a512cb --- /dev/null +++ b/test/spec/modules/otmBidAdapter_spec.js @@ -0,0 +1,67 @@ +import {expect} from 'chai'; +import {spec} from 'modules/otmBidAdapter'; + +describe('otmBidAdapterTests', function () { + it('validate_pub_params', function () { + expect(spec.isBidRequestValid({ + bidder: 'otm', + params: { + tid: '123', + bidfloor: 20 + } + })).to.equal(true); + }); + + it('validate_generated_params', function () { + let bidRequestData = [{ + bidId: 'bid1234', + bidder: 'otm', + params: { + tid: '123', + bidfloor: 20 + }, + sizes: [[240, 400]] + }]; + + let request = spec.buildRequests(bidRequestData); + let req_data = request[0].data; + + expect(req_data.bidid).to.equal('bid1234'); + }); + + it('validate_response_params', function () { + let bidRequestData = { + data: { + bidId: 'bid1234' + } + }; + + let serverResponse = { + body: [ + { + 'auctionid': '3c6f8e22-541b-485c-9214-e974d9fb1b6f', + 'cpm': 847.097, + 'ad': 'test html', + 'w': 240, + 'h': 400, + 'currency': 'RUB', + 'ttl': 300, + 'creativeid': '1_7869053', + 'bidid': '101f211def7c99', + 'transactionid': 'transaction_id_1' + } + ] + }; + + let bids = spec.interpretResponse(serverResponse, bidRequestData); + expect(bids).to.have.lengthOf(1); + let bid = bids[0]; + expect(bid.cpm).to.equal(847.097); + expect(bid.currency).to.equal('RUB'); + expect(bid.width).to.equal(240); + expect(bid.height).to.equal(400); + expect(bid.netRevenue).to.equal(true); + expect(bid.requestId).to.equal('101f211def7c99'); + expect(bid.ad).to.equal('test html'); + }); +}); diff --git a/test/spec/modules/ozoneBidAdapter_spec.js b/test/spec/modules/ozoneBidAdapter_spec.js new file mode 100644 index 00000000000..6b4f6c88bdd --- /dev/null +++ b/test/spec/modules/ozoneBidAdapter_spec.js @@ -0,0 +1,448 @@ +import { expect } from 'chai'; +import { spec } from 'modules/ozoneBidAdapter'; + +const OZONEURI = 'https://elb.the-ozone-project.com/openrtb2/auction'; +const BIDDER_CODE = 'ozone'; +/* + +NOTE - use firefox console to deep copy the objects to use here + + */ +var validBidRequests = [ + { + adUnitCode: 'div-gpt-ad-1460505748561-0', + auctionId: '27dcb421-95c6-4024-a624-3c03816c5f99', + bidId: '2899ec066a91ff8', + bidRequestsCount: 1, + bidder: 'ozone', + bidderRequestId: '1c1586b27a1b5c8', + crumbs: {pubcid: '203a0692-f728-4856-87f6-9a25a6b63715'}, + params: { publisherId: '9876abcd12-3', customData: {'gender': 'bart', 'age': 'low'}, ozoneData: {'networkID': '3048', 'dfpSiteID': 'd.thesun', 'sectionID': 'homepage', 'path': '/', 'sec_id': 'null', 'sec': 'sec', 'topics': 'null', 'kw': 'null', 'aid': 'null', 'search': 'null', 'article_type': 'null', 'hide_ads': '', 'article_slug': 'null'}, lotameData: {'Profile': {'tpid': 'c8ef27a0d4ba771a81159f0d2e792db4', 'Audiences': {'Audience': [{'id': '99999', 'abbr': 'sports'}, {'id': '88888', 'abbr': 'movie'}, {'id': '77777', 'abbr': 'blogger'}], 'ThirdPartyAudience': [{'id': '123', 'name': 'Automobiles'}, {'id': '456', 'name': 'Ages: 30-39'}]}}}, placementId: '1310000099', siteId: '1234567890', id: 'fea37168-78f1-4a23-a40e-88437a99377e', auctionId: '27dcb421-95c6-4024-a624-3c03816c5f99', imp: [ { id: '2899ec066a91ff8', tagid: 'undefined', secure: 1, banner: { format: [{ w: 300, h: 250 }, { w: 300, h: 600 }], h: 250, topframe: 1, w: 300 } } ] }, + sizes: [[300, 250], [300, 600]], + transactionId: '2e63c0ed-b10c-4008-aed5-84582cecfe87' + } +]; + +var validBidderRequest = { + auctionId: '27dcb421-95c6-4024-a624-3c03816c5f99', + auctionStart: 1536838908986, + bidderCode: 'ozone', + bidderRequestId: '1c1586b27a1b5c8', + bids: [{ + adUnitCode: 'div-gpt-ad-1460505748561-0', + auctionId: '27dcb421-95c6-4024-a624-3c03816c5f99', + bidId: '2899ec066a91ff8', + bidRequestsCount: 1, + bidder: 'ozone', + bidderRequestId: '1c1586b27a1b5c8', + crumbs: {pubcid: '203a0692-f728-4856-87f6-9a25a6b63715'}, + params: { publisherId: '9876abcd12-3', customData: {'gender': 'bart', 'age': 'low'}, ozoneData: {'networkID': '3048', 'dfpSiteID': 'd.thesun', 'sectionID': 'homepage', 'path': '/', 'sec_id': 'null', 'sec': 'sec', 'topics': 'null', 'kw': 'null', 'aid': 'null', 'search': 'null', 'article_type': 'null', 'hide_ads': '', 'article_slug': 'null'}, lotameData: {'Profile': {'tpid': 'c8ef27a0d4ba771a81159f0d2e792db4', 'Audiences': {'Audience': [{'id': '99999', 'abbr': 'sports'}, {'id': '88888', 'abbr': 'movie'}, {'id': '77777', 'abbr': 'blogger'}], 'ThirdPartyAudience': [{'id': '123', 'name': 'Automobiles'}, {'id': '456', 'name': 'Ages: 30-39'}]}}}, placementId: '1310000099', siteId: '1234567890', id: 'fea37168-78f1-4a23-a40e-88437a99377e', auctionId: '27dcb421-95c6-4024-a624-3c03816c5f99', imp: [ { banner: { topframe: 1, w: 300, h: 250, format: [{ w: 300, h: 250 }, { w: 300, h: 600 }] }, id: '2899ec066a91ff8', secure: 1, tagid: 'undefined' } ] }, + sizes: [[300, 250], [300, 600]], + transactionId: '2e63c0ed-b10c-4008-aed5-84582cecfe87' + }], + doneCbCallCount: 1, + start: 1536838908987, + timeout: 3000 +}; +// make sure the impid matches the request bidId +var validResponse = { + 'body': { + 'id': 'd6198807-7a53-4141-b2db-d2cb754d68ba', + 'seatbid': [ + { + 'bid': [ + { + 'id': '677903815252395017', + 'impid': '2899ec066a91ff8', + 'price': 0.5, + 'adm': '', + 'adid': '98493581', + 'adomain': [ + 'http://prebid.org' + ], + 'iurl': 'https://fra1-ib.adnxs.com/cr?id=98493581', + 'cid': '9325', + 'crid': '98493581', + 'cat': [ + 'IAB3-1' + ], + 'w': 300, + 'h': 600, + 'ext': { + 'prebid': { + 'type': 'banner' + }, + 'bidder': { + 'appnexus': { + 'brand_id': 555545, + 'auction_id': 6500448734132353000, + 'bidder_id': 2, + 'bid_ad_type': 0 + } + } + } + } + ], + 'seat': 'appnexus' + } + ], + 'ext': { + 'responsetimemillis': { + 'appnexus': 47, + 'openx': 30 + } + }, + 'timing': { + 'start': 1536848078.089177, + 'end': 1536848078.142203, + 'TimeTaken': 0.05302619934082031 + } + }, + 'headers': {} +} + +describe('ozone Adapter', function () { + describe('isBidRequestValid', function () { + // A test ad unit that will consistently return test creatives + let validBidReq = { + bidder: BIDDER_CODE, + params: { + placementId: '1310000099', + publisherId: '9876abcd12-3', + siteId: '1234567890' + } + }; + + it('should return true when required params found', function () { + expect(spec.isBidRequestValid(validBidReq)).to.equal(true); + }); + + var validBidReq2 = { + + bidder: BIDDER_CODE, + params: { + placementId: '1310000099', + publisherId: '9876abcd12-3', + siteId: '1234567890' + }, + customData: {'gender': 'bart', 'age': 'low'}, + ozoneData: {'networkID': '3048', 'dfpSiteID': 'd.thesun', 'sectionID': 'homepage', 'path': '/', 'sec_id': 'null', 'sec': 'sec', 'topics': 'null', 'kw': 'null', 'aid': 'null', 'search': 'null', 'article_type': 'null', 'hide_ads': '', 'article_slug': 'null'}, + lotameData: {'Profile': {'tpid': 'c8ef27a0d4ba771a81159f0d2e792db4', 'Audiences': {'Audience': [{'id': '99999', 'abbr': 'sports'}, {'id': '88888', 'abbr': 'movie'}, {'id': '77777', 'abbr': 'blogger'}], 'ThirdPartyAudience': [{'id': '123', 'name': 'Automobiles'}, {'id': '456', 'name': 'Ages: 30-39'}]}}}, + siteId: 1234567890 + } + + it('should return true when required params found and all optional params are valid', function () { + expect(spec.isBidRequestValid(validBidReq2)).to.equal(true); + }); + + var xEmptyPlacement = { + bidder: BIDDER_CODE, + params: { + placementId: '', + publisherId: '9876abcd12-3', + siteId: '1234567890' + } + }; + + it('should not validate empty placementId', function () { + expect(spec.isBidRequestValid(xEmptyPlacement)).to.equal(false); + }); + + var xMissingPlacement = { + bidder: BIDDER_CODE, + params: { + publisherId: '9876abcd12-3', + siteId: '1234567890' + } + }; + + it('should not validate missing placementId', function () { + expect(spec.isBidRequestValid(xMissingPlacement)).to.equal(false); + }); + + var xBadPlacement = { + bidder: BIDDER_CODE, + params: { + placementId: '123X45', + publisherId: '9876abcd12-3', + siteId: '1234567890' + } + }; + + it('should not validate placementId with a non-numeric value', function () { + expect(spec.isBidRequestValid(xBadPlacement)).to.equal(false); + }); + + var xBadPlacementTooShort = { + bidder: BIDDER_CODE, + params: { + placementId: 123456789, /* should be exactly 10 chars */ + publisherId: '9876abcd12-3', + siteId: '1234567890' + } + }; + + it('should not validate placementId with a numeric value of wrong length', function () { + expect(spec.isBidRequestValid(xBadPlacementTooShort)).to.equal(false); + }); + + var xBadPlacementTooLong = { + bidder: BIDDER_CODE, + params: { + placementId: 12345678901, /* should be exactly 10 chars */ + publisherId: '9876abcd12-3', + siteId: '1234567890' + } + }; + + it('should not validate placementId with a numeric value of wrong length', function () { + expect(spec.isBidRequestValid(xBadPlacementTooLong)).to.equal(false); + }); + + var xMissingPublisher = { + bidder: BIDDER_CODE, + params: { + placementId: '1234567890', + siteId: '1234567890' + } + }; + + it('should not validate missing publisherId', function () { + expect(spec.isBidRequestValid(xMissingPublisher)).to.equal(false); + }); + + var xBadPublisherTooShort = { + bidder: BIDDER_CODE, + params: { + placementId: '1234567890', + publisherId: '9876abcd12a', + siteId: '1234567890' + } + }; + + it('should not validate publisherId being too short', function () { + expect(spec.isBidRequestValid(xBadPublisherTooShort)).to.equal(false); + }); + + var xBadPublisherTooLong = { + bidder: BIDDER_CODE, + params: { + placementId: '1234567890', + publisherId: '9876abcd12abc', + siteId: '1234567890' + } + }; + + it('should not validate publisherId being too long', function () { + expect(spec.isBidRequestValid(xBadPublisherTooLong)).to.equal(false); + }); + + var publisherNumericOk = { + bidder: BIDDER_CODE, + params: { + placementId: '1234567890', + publisherId: 123456789012, + siteId: '1234567890' + } + }; + + it('should validate publisherId being 12 digits', function () { + expect(spec.isBidRequestValid(publisherNumericOk)).to.equal(true); + }); + + var xEmptyPublisher = { + bidder: BIDDER_CODE, + params: { + placementId: '1234567890', + publisherId: '', + siteId: '1234567890' + } + }; + + it('should not validate empty publisherId', function () { + expect(spec.isBidRequestValid(xEmptyPublisher)).to.equal(false); + }); + + var xBadSite = { + bidder: BIDDER_CODE, + params: { + placementId: '1234567890', + publisherId: '9876abcd12-3', + siteId: '12345Z' + } + }; + + it('should not validate bad siteId', function () { + expect(spec.isBidRequestValid(xBadSite)).to.equal(false); + }); + + var xBadSiteTooLong = { + bidder: BIDDER_CODE, + params: { + placementId: '1234567890', + publisherId: '9876abcd12-3', + siteId: '12345678901' + } + }; + + it('should not validate siteId too long', function () { + expect(spec.isBidRequestValid(xBadSite)).to.equal(false); + }); + + var xBadSiteTooShort = { + bidder: BIDDER_CODE, + params: { + placementId: '1234567890', + publisherId: '9876abcd12-3', + siteId: '123456789' + } + }; + + it('should not validate siteId too short', function () { + expect(spec.isBidRequestValid(xBadSite)).to.equal(false); + }); + + var allNonStrings = { + bidder: BIDDER_CODE, + params: { + placementId: 1234567890, + publisherId: '9876abcd12-3', + siteId: 1234567890 + } + }; + + it('should validate all numeric values being sent as non-string numbers', function () { + expect(spec.isBidRequestValid(allNonStrings)).to.equal(true); + }); + + var emptySiteId = { + bidder: BIDDER_CODE, + params: { + placementId: 1234567890, + publisherId: '9876abcd12-3', + siteId: '' + } + }; + + it('should not validate siteId being empty string (it is required now)', function () { + expect(spec.isBidRequestValid(emptySiteId)).to.equal(false); + }); + + var xBadCustomData = { + bidder: BIDDER_CODE, + params: { + 'placementId': '1234567890', + 'publisherId': '9876abcd12-3', + 'siteId': '1234567890', + 'customData': 'this aint gonna work' + } + }; + + it('should not validate customData not being an object', function () { + expect(spec.isBidRequestValid(xBadCustomData)).to.equal(false); + }); + + var xCustomParams = { + bidder: BIDDER_CODE, + params: { + 'placementId': '1234567890', + 'publisherId': '9876abcd12-3', + 'customParams': {'info': 'this is not allowed'}, + siteId: '1234567890' + } + }; + + it('should not validate customParams being sent', function () { + expect(spec.isBidRequestValid(xCustomParams)).to.equal(false); + }); + + var xBadOzoneData = { + bidder: BIDDER_CODE, + params: { + 'placementId': '1234567890', + 'publisherId': '9876abcd12-3', + 'ozoneData': 'this should be an object', + siteId: '1234567890' + } + }; + + it('should not validate ozoneData being sent', function () { + expect(spec.isBidRequestValid(xBadOzoneData)).to.equal(false); + }); + + var xBadCustomData = { + bidder: BIDDER_CODE, + params: { + 'placementId': '1234567890', + 'publisherId': '9876abcd12-3', + 'customData': 'this should be an object', + siteId: '1234567890' + } + }; + + it('should not validate ozoneData being sent', function () { + expect(spec.isBidRequestValid(xBadCustomData)).to.equal(false); + }); + var xBadLotame = { + bidder: BIDDER_CODE, + params: { + 'placementId': '1234567890', + 'publisherId': '9876abcd12-3', + 'lotameData': 'this should be an object', + siteId: '1234567890' + } + }; + + it('should not validate lotameData being sent', function () { + expect(spec.isBidRequestValid(xBadLotame)).to.equal(false); + }); + }); + + describe('buildRequests', function () { + it('sends bid request to OZONEURI via POST', function () { + const request = spec.buildRequests(validBidRequests, validBidderRequest); + expect(request.url).to.equal(OZONEURI); + expect(request.method).to.equal('POST'); + }); + + it('sends data as a string', function () { + const request = spec.buildRequests(validBidRequests, validBidderRequest); + expect(request.data).to.be.a('string'); + }); + + it('sends all bid parameters', function () { + const request = spec.buildRequests(validBidRequests, validBidderRequest); + expect(request).to.have.all.keys(['bidderRequest', 'data', 'method', 'url']); + }); + + it('has correct bidder', function () { + const request = spec.buildRequests(validBidRequests, validBidderRequest); + expect(request.bidderRequest.bids[0].bidder).to.equal(BIDDER_CODE); + }); + }); + + describe('interpretResponse', function () { + it('should build bid array', function () { + const request = spec.buildRequests(validBidRequests, validBidderRequest); + const result = spec.interpretResponse(validResponse, request); + expect(result.length).to.equal(1); + }); + + it('should have all relevant fields', function () { + const request = spec.buildRequests(validBidRequests, validBidderRequest); + const result = spec.interpretResponse(validResponse, request); + const bid = result[0]; + expect(bid.cpm).to.equal(validResponse.body.seatbid[0].bid[0].cpm); + expect(bid.width).to.equal(validResponse.body.seatbid[0].bid[0].width); + expect(bid.height).to.equal(validResponse.body.seatbid[0].bid[0].height); + }); + + it('should build bid array with gdpr', function () { + var validBidderRequestWithGdpr = validBidderRequest; + validBidderRequestWithGdpr.gdprConsent = {'gdprApplies': 1, 'consentString': 'This is the gdpr consent string'}; + const request = spec.buildRequests(validBidRequests, validBidderRequestWithGdpr); + const result = spec.interpretResponse(validResponse, request); + expect(result.length).to.equal(1); + }); + }); +}); diff --git a/test/spec/modules/papyrusBidAdapter_spec.js b/test/spec/modules/papyrusBidAdapter_spec.js index a61a1c55269..289da56379a 100644 --- a/test/spec/modules/papyrusBidAdapter_spec.js +++ b/test/spec/modules/papyrusBidAdapter_spec.js @@ -4,8 +4,8 @@ import { spec } from 'modules/papyrusBidAdapter'; const ENDPOINT = '//prebid.papyrus.global'; const BIDDER_CODE = 'papyrus'; -describe('papyrus Adapter', () => { - describe('isBidRequestValid', () => { +describe('papyrus Adapter', function () { + describe('isBidRequestValid', function () { let validBidReq = { bidder: BIDDER_CODE, params: { @@ -14,7 +14,7 @@ describe('papyrus Adapter', () => { } }; - it('should return true when required params found', () => { + it('should return true when required params found', function () { expect(spec.isBidRequestValid(validBidReq)).to.equal(true); }); @@ -25,12 +25,12 @@ describe('papyrus Adapter', () => { } }; - it('should not validate incorrect bid request', () => { + it('should not validate incorrect bid request', function () { expect(spec.isBidRequestValid(invalidBidReq)).to.equal(false); }); }); - describe('buildRequests', () => { + describe('buildRequests', function () { let bidRequests = [ { bidder: BIDDER_CODE, @@ -46,29 +46,29 @@ describe('papyrus Adapter', () => { } ]; - it('sends bid request to ENDPOINT via POST', () => { + it('sends bid request to ENDPOINT via POST', function () { const request = spec.buildRequests(bidRequests); expect(request.url).to.equal(ENDPOINT); expect(request.method).to.equal('POST'); }); - it('sends valid bids count', () => { + it('sends valid bids count', function () { const request = spec.buildRequests(bidRequests); expect(request.data.length).to.equal(1); }); - it('sends all bid parameters', () => { + it('sends all bid parameters', function () { const request = spec.buildRequests(bidRequests); expect(request.data[0]).to.have.all.keys(['address', 'placementId', 'sizes', 'bidId', 'transactionId']); }); - it('sedns valid sizes parameter', () => { + it('sedns valid sizes parameter', function () { const request = spec.buildRequests(bidRequests); expect(request.data[0].sizes[0]).to.equal('300x250'); }); }); - describe('interpretResponse', () => { + describe('interpretResponse', function () { let bidRequests = [ { bidder: BIDDER_CODE, @@ -96,13 +96,13 @@ describe('papyrus Adapter', () => { ] }; - it('should build bid array', () => { + it('should build bid array', function () { const request = spec.buildRequests(bidRequests); const result = spec.interpretResponse({body: bidResponse}, request[0]); expect(result.length).to.equal(1); }); - it('should have all relevant fields', () => { + it('should have all relevant fields', function () { const request = spec.buildRequests(bidRequests); const result = spec.interpretResponse({body: bidResponse}, request[0]); const bid = result[0]; diff --git a/test/spec/modules/peak226BidAdapter_spec.js b/test/spec/modules/peak226BidAdapter_spec.js index f85e46c4289..8b8157225bb 100644 --- a/test/spec/modules/peak226BidAdapter_spec.js +++ b/test/spec/modules/peak226BidAdapter_spec.js @@ -4,11 +4,11 @@ import { newBidder } from 'src/adapters/bidderFactory'; const URL = 'a.ad216.com/header_bid'; -describe('PeakAdapter', () => { +describe('PeakAdapter', function () { const adapter = newBidder(spec); - describe('isBidRequestValid', () => { - it('should return true when required params found', () => { + describe('isBidRequestValid', function () { + it('should return true when required params found', function () { const bid = { params: { uid: 123 @@ -18,7 +18,7 @@ describe('PeakAdapter', () => { expect(spec.isBidRequestValid(bid)).to.equal(true); }); - it('should return false when required params are not passed', () => { + it('should return false when required params are not passed', function () { const bid = { params: {} }; @@ -27,7 +27,7 @@ describe('PeakAdapter', () => { }); }); - // xdescribe('buildRequests', () => { + // xdescribe('buildRequests', function () { // const bidRequests = [ // { // params: { @@ -36,7 +36,7 @@ describe('PeakAdapter', () => { // } // ]; - // it('sends bid request to URL via GET', () => { + // it('sends bid request to URL via GET', function () { // const request = spec.buildRequests(bidRequests); // expect(request.url).to.equal(`${URL}?uids=1234`); @@ -44,8 +44,8 @@ describe('PeakAdapter', () => { // }); // }); - describe('interpretResponse', () => { - it('should handle empty response', () => { + describe('interpretResponse', function () { + it('should handle empty response', function () { let bids = spec.interpretResponse( {}, { @@ -56,7 +56,7 @@ describe('PeakAdapter', () => { expect(bids).to.be.lengthOf(0); }); - it('should handle no seatbid returned', () => { + it('should handle no seatbid returned', function () { let response = {}; let bids = spec.interpretResponse( @@ -69,7 +69,7 @@ describe('PeakAdapter', () => { expect(bids).to.be.lengthOf(0); }); - it('should handle empty seatbid returned', () => { + it('should handle empty seatbid returned', function () { let response = { seatbid: [] }; let bids = spec.interpretResponse( @@ -82,7 +82,7 @@ describe('PeakAdapter', () => { expect(bids).to.be.lengthOf(0); }); - it('should handle seatbid returned bids', () => { + it('should handle seatbid returned bids', function () { const bidsMap = { 1: [{ bidId: 11 }] }; const bid = { price: 0.2, diff --git a/test/spec/modules/piximediaBidAdapter_spec.js b/test/spec/modules/piximediaBidAdapter_spec.js new file mode 100644 index 00000000000..02cf80c614f --- /dev/null +++ b/test/spec/modules/piximediaBidAdapter_spec.js @@ -0,0 +1,102 @@ +import { expect } from 'chai'; +import { spec } from 'modules/piximediaBidAdapter'; + +describe('piximediaAdapterTest', function() { + describe('bidRequestValidity', function() { + it('bidRequest with site ID and placement ID param', function() { + expect(spec.isBidRequestValid({ + bidder: 'piximedia', + params: { + 'siteId': 'PIXIMEDIA_PREBID10', + 'placementId': 'RG' + }, + })).to.equal(true); + }); + + it('bidRequest with no required params', function() { + expect(spec.isBidRequestValid({ + bidder: 'piximedia', + params: { + }, + })).to.equal(false); + }); + }); + + describe('bidRequest', function() { + const bidRequests = [{ + 'bidder': 'piximedia', + 'params': { + 'siteId': 'PIXIMEDIA_PREBID10', + 'placementId': 'RG' + }, + 'adUnitCode': 'div-gpt-ad-1460505748561-0', + 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', + 'sizes': [300, 250], + 'bidId': '51ef8751f9aead', + 'bidderRequestId': '418b37f85e772c', + 'auctionId': '18fd8b8b0bd757' + }]; + + it('bidRequest HTTP method', function() { + const requests = spec.buildRequests(bidRequests); + requests.forEach(function(requestItem) { + expect(requestItem.method).to.equal('GET'); + }); + }); + + it('bidRequest data', function() { + const requests = spec.buildRequests(bidRequests); + expect(typeof requests[0].data.timestamp).to.equal('number'); + expect(requests[0].data.pver).to.equal('1.0'); + expect(requests[0].data.pbparams).to.equal(JSON.stringify(bidRequests[0].params)); + expect(requests[0].data.pbwidth).to.equal('300'); + expect(requests[0].data.pbheight).to.equal('250'); + expect(requests[0].data.pbbidid).to.equal('51ef8751f9aead'); + }); + }); + + describe('interpretResponse', function() { + const bidRequest = { + 'method': 'GET', + 'url': 'https://ad.piximedia.com/', + 'data': { + 'ver': 2, + 'hb': 1, + 'output': 'js', + 'pub': 267, + 'zone': 62546, + 'width': '300', + 'height': '250', + 'callback': 'json', + 'callback_uid': '51ef8751f9aead', + 'url': 'https://example.com', + 'cb': '', + } + }; + + const bidResponse = { + body: { + 'bidId': '51ef8751f9aead', + 'cpm': 4.2, + 'width': '300', + 'height': '250', + 'creative_id': '1234', + 'currency': 'EUR', + 'adm': '
', + }, + headers: {} + }; + + it('result is correct', function() { + const result = spec.interpretResponse(bidResponse, bidRequest); + expect(result[0].requestId).to.equal('51ef8751f9aead'); + expect(result[0].cpm).to.equal(4.2); + expect(result[0].width).to.equal('300'); + expect(result[0].height).to.equal('250'); + expect(result[0].creativeId).to.equal('1234'); + expect(result[0].currency).to.equal('EUR'); + expect(result[0].ttl).to.equal(300); + expect(result[0].ad).to.equal('
'); + }); + }); +}); diff --git a/test/spec/modules/platformioBidAdapter_spec.js b/test/spec/modules/platformioBidAdapter_spec.js index 39ada3cc01c..f3754654cf1 100644 --- a/test/spec/modules/platformioBidAdapter_spec.js +++ b/test/spec/modules/platformioBidAdapter_spec.js @@ -1,335 +1,335 @@ -import {expect} from 'chai'; -import {spec} from 'modules/platformioBidAdapter'; -import {getTopWindowLocation} from 'src/utils'; -import {newBidder} from 'src/adapters/bidderFactory'; - -describe('Platform.io Adapter Tests', () => { - const slotConfigs = [{ - placementCode: '/DfpAccount1/slot1', - bidId: 'bid12345', - mediaType: 'banner', - params: { - pubId: '29521', - siteId: '26047', - placementId: '123', - size: '300x250', - bidFloor: '0.001', - ifa: 'IFA', - latitude: '40.712775', - longitude: '-74.005973' - } - }, { - placementCode: '/DfpAccount2/slot2', - bidId: 'bid23456', - mediaType: 'banner', - params: { - pubId: '29521', - siteId: '26047', - placementId: '1234', - size: '728x90', - bidFloor: '0.000001', - } - }]; - const nativeSlotConfig = [{ - placementCode: '/DfpAccount1/slot3', - bidId: 'bid12345', - mediaType: 'native', - nativeParams: { - title: { required: true, len: 200 }, - body: {}, - image: { wmin: 100 }, - sponsoredBy: { }, - icon: { } - }, - params: { - pubId: '29521', - placementId: '123', - siteId: '26047' - } - }]; - const videoSlotConfig = [{ - placementCode: '/DfpAccount1/slot4', - bidId: 'bid12345678', - mediaType: 'video', - video: { - skippable: true - }, - params: { - pubId: '29521', - placementId: '1234567', - siteId: '26047', - size: '640x480' - } - }]; - const appSlotConfig = [{ - placementCode: '/DfpAccount1/slot5', - bidId: 'bid12345', - params: { - pubId: '29521', - placementId: '1234', - app: { - id: '1111', - name: 'app name', - bundle: 'io.platform.apps', - storeUrl: 'http://platform.io/apps', - domain: 'platform.io' - } - } - }]; - - it('Verify build request', () => { - const request = spec.buildRequests(slotConfigs); - expect(request.url).to.equal('//piohbdisp.hb.adx1.com/'); - expect(request.method).to.equal('POST'); - const ortbRequest = JSON.parse(request.data); - // site object - expect(ortbRequest.site).to.not.equal(null); - expect(ortbRequest.site.publisher).to.not.equal(null); - expect(ortbRequest.site.publisher.id).to.equal('29521'); - expect(ortbRequest.site.ref).to.equal(window.top.document.referrer); - expect(ortbRequest.site.page).to.equal(getTopWindowLocation().href); - expect(ortbRequest.imp).to.have.lengthOf(2); - // device object - expect(ortbRequest.device).to.not.equal(null); - expect(ortbRequest.device.ua).to.equal(navigator.userAgent); - expect(ortbRequest.device.ifa).to.equal('IFA'); - expect(ortbRequest.device.geo.lat).to.equal('40.712775'); - expect(ortbRequest.device.geo.lon).to.equal('-74.005973'); - // slot 1 - expect(ortbRequest.imp[0].tagid).to.equal('123'); - expect(ortbRequest.imp[0].banner).to.not.equal(null); - expect(ortbRequest.imp[0].banner.w).to.equal(300); - expect(ortbRequest.imp[0].banner.h).to.equal(250); - expect(ortbRequest.imp[0].bidfloor).to.equal('0.001'); - // slot 2 - expect(ortbRequest.imp[1].tagid).to.equal('1234'); - expect(ortbRequest.imp[1].banner).to.not.equal(null); - expect(ortbRequest.imp[1].banner.w).to.equal(728); - expect(ortbRequest.imp[1].banner.h).to.equal(90); - expect(ortbRequest.imp[1].bidfloor).to.equal('0.000001'); - }); - - it('Verify parse response', () => { - const request = spec.buildRequests(slotConfigs); - const ortbRequest = JSON.parse(request.data); - const ortbResponse = { - seatbid: [{ - bid: [{ - impid: ortbRequest.imp[0].id, - price: 1.25, - adm: 'This is an Ad' - }] - }], - cur: 'USD' - }; - const bids = spec.interpretResponse({ body: ortbResponse }, request); - expect(bids).to.have.lengthOf(1); - // verify first bid - const bid = bids[0]; - expect(bid.cpm).to.equal(1.25); - expect(bid.ad).to.equal('This is an Ad'); - expect(bid.width).to.equal(300); - expect(bid.height).to.equal(250); - expect(bid.adId).to.equal('bid12345'); - expect(bid.creativeId).to.equal('bid12345'); - expect(bid.netRevenue).to.equal(true); - expect(bid.currency).to.equal('USD'); - expect(bid.ttl).to.equal(360); - }); - - it('Verify full passback', () => { - const request = spec.buildRequests(slotConfigs); - const bids = spec.interpretResponse({ body: null }, request) - expect(bids).to.have.lengthOf(0); - }); - - it('Verify Native request', () => { - const request = spec.buildRequests(nativeSlotConfig); - expect(request.url).to.equal('//piohbdisp.hb.adx1.com/'); - expect(request.method).to.equal('POST'); - const ortbRequest = JSON.parse(request.data); - // native impression - expect(ortbRequest.imp[0].tagid).to.equal('123'); - const nativePart = ortbRequest.imp[0]['native']; - expect(nativePart).to.not.equal(null); - expect(nativePart.ver).to.equal('1.1'); - expect(nativePart.request).to.not.equal(null); - // native request assets - const nativeRequest = JSON.parse(ortbRequest.imp[0]['native'].request); - expect(nativeRequest).to.not.equal(null); - expect(nativeRequest.assets).to.have.lengthOf(5); - expect(nativeRequest.assets[0].id).to.equal(1); - expect(nativeRequest.assets[1].id).to.equal(2); - expect(nativeRequest.assets[2].id).to.equal(3); - expect(nativeRequest.assets[3].id).to.equal(4); - expect(nativeRequest.assets[4].id).to.equal(5); - expect(nativeRequest.assets[0].required).to.equal(1); - expect(nativeRequest.assets[0].title).to.not.equal(null); - expect(nativeRequest.assets[0].title.len).to.equal(200); - expect(nativeRequest.assets[1].title).to.be.undefined; - expect(nativeRequest.assets[1].data).to.not.equal(null); - expect(nativeRequest.assets[1].data.type).to.equal(2); - expect(nativeRequest.assets[1].data.len).to.equal(200); - expect(nativeRequest.assets[2].required).to.equal(0); - expect(nativeRequest.assets[3].img).to.not.equal(null); - expect(nativeRequest.assets[3].img.wmin).to.equal(50); - expect(nativeRequest.assets[3].img.hmin).to.equal(50); - expect(nativeRequest.assets[3].img.type).to.equal(1); - expect(nativeRequest.assets[4].img).to.not.equal(null); - expect(nativeRequest.assets[4].img.wmin).to.equal(100); - expect(nativeRequest.assets[4].img.hmin).to.equal(150); - expect(nativeRequest.assets[4].img.type).to.equal(3); - }); - - it('Verify Native response', () => { - const request = spec.buildRequests(nativeSlotConfig); - expect(request.url).to.equal('//piohbdisp.hb.adx1.com/'); - expect(request.method).to.equal('POST'); - const ortbRequest = JSON.parse(request.data); - const nativeResponse = { - 'native': { - assets: [ - { id: 1, title: { text: 'Ad Title' } }, - { id: 2, data: { value: 'Test description' } }, - { id: 3, data: { value: 'Brand' } }, - { id: 4, img: { url: 'https://s3.amazonaws.com/adx1public/creatives_icon.png', w: 100, h: 100 } }, - { id: 5, img: { url: 'https://s3.amazonaws.com/adx1public/creatives_image.png', w: 300, h: 300 } } - ], - link: { url: 'http://brand.com/' } - } - }; - const ortbResponse = { - seatbid: [{ - bid: [{ - impid: ortbRequest.imp[0].id, - price: 1.25, - nurl: 'http://rtb.adx1.com/log', - adm: JSON.stringify(nativeResponse) - }] - }], - cur: 'USD', - }; - const bids = spec.interpretResponse({ body: ortbResponse }, request); - // verify bid - const bid = bids[0]; - expect(bid.cpm).to.equal(1.25); - expect(bid.adId).to.equal('bid12345'); - expect(bid.ad).to.be.undefined; - expect(bid.mediaType).to.equal('native'); - const nativeBid = bid['native']; - expect(nativeBid).to.not.equal(null); - expect(nativeBid.title).to.equal('Ad Title'); - expect(nativeBid.sponsoredBy).to.equal('Brand'); - expect(nativeBid.icon.url).to.equal('https://s3.amazonaws.com/adx1public/creatives_icon.png'); - expect(nativeBid.image.url).to.equal('https://s3.amazonaws.com/adx1public/creatives_image.png'); - expect(nativeBid.image.width).to.equal(300); - expect(nativeBid.image.height).to.equal(300); - expect(nativeBid.icon.width).to.equal(100); - expect(nativeBid.icon.height).to.equal(100); - expect(nativeBid.clickUrl).to.equal(encodeURIComponent('http://brand.com/')); - expect(nativeBid.impressionTrackers).to.have.lengthOf(1); - expect(nativeBid.impressionTrackers[0]).to.equal('http://rtb.adx1.com/log'); - }); - - it('Verify Video request', () => { - const request = spec.buildRequests(videoSlotConfig); - expect(request.url).to.equal('//piohbdisp.hb.adx1.com/'); - expect(request.method).to.equal('POST'); - const videoRequest = JSON.parse(request.data); - // site object - expect(videoRequest.site).to.not.equal(null); - expect(videoRequest.site.publisher.id).to.equal('29521'); - expect(videoRequest.site.ref).to.equal(window.top.document.referrer); - expect(videoRequest.site.page).to.equal(getTopWindowLocation().href); - // device object - expect(videoRequest.device).to.not.equal(null); - expect(videoRequest.device.ua).to.equal(navigator.userAgent); - // slot 1 - expect(videoRequest.imp[0].tagid).to.equal('1234567'); - expect(videoRequest.imp[0].video).to.not.equal(null); - expect(videoRequest.imp[0].video.w).to.equal(640); - expect(videoRequest.imp[0].video.h).to.equal(480); - expect(videoRequest.imp[0].banner).to.equal(null); - expect(videoRequest.imp[0].native).to.equal(null); - }); - - it('Verify parse video response', () => { - const request = spec.buildRequests(videoSlotConfig); - const videoRequest = JSON.parse(request.data); - const videoResponse = { - seatbid: [{ - bid: [{ - impid: videoRequest.imp[0].id, - price: 1.90, - adm: 'http://vid.example.com/9876', - crid: '510511_754567308' - }] - }], - cur: 'USD' - }; - const bids = spec.interpretResponse({ body: videoResponse }, request); - expect(bids).to.have.lengthOf(1); - // verify first bid - const bid = bids[0]; - expect(bid.cpm).to.equal(1.90); - expect(bid.vastUrl).to.equal('http://vid.example.com/9876'); - expect(bid.crid).to.equal('510511_754567308'); - expect(bid.width).to.equal(640); - expect(bid.height).to.equal(480); - expect(bid.adId).to.equal('bid12345678'); - expect(bid.netRevenue).to.equal(true); - expect(bid.currency).to.equal('USD'); - expect(bid.ttl).to.equal(360); - }); - - it('Verifies bidder code', () => { - expect(spec.code).to.equal('platformio'); - }); - - it('Verifies supported media types', () => { - expect(spec.supportedMediaTypes).to.have.lengthOf(3); - expect(spec.supportedMediaTypes[0]).to.equal('banner'); - expect(spec.supportedMediaTypes[1]).to.equal('native'); - expect(spec.supportedMediaTypes[2]).to.equal('video'); - }); - - it('Verifies if bid request valid', () => { - expect(spec.isBidRequestValid(slotConfigs[0])).to.equal(true); - expect(spec.isBidRequestValid(slotConfigs[1])).to.equal(true); - expect(spec.isBidRequestValid(nativeSlotConfig[0])).to.equal(true); - expect(spec.isBidRequestValid(videoSlotConfig[0])).to.equal(true); - }); - - it('Verify app requests', () => { - const request = spec.buildRequests(appSlotConfig); - const ortbRequest = JSON.parse(request.data); - expect(ortbRequest.site).to.equal(null); - expect(ortbRequest.app).to.not.be.null; - expect(ortbRequest.app.publisher).to.not.equal(null); - expect(ortbRequest.app.publisher.id).to.equal('29521'); - expect(ortbRequest.app.id).to.equal('1111'); - expect(ortbRequest.app.name).to.equal('app name'); - expect(ortbRequest.app.bundle).to.equal('io.platform.apps'); - expect(ortbRequest.app.storeurl).to.equal('http://platform.io/apps'); - expect(ortbRequest.app.domain).to.equal('platform.io'); - }); - - it('Verify GDPR', () => { - const bidderRequest = { - gdprConsent: { - gdprApplies: true, - consentString: 'serialized_gpdr_data' - } - }; - const request = spec.buildRequests(slotConfigs, bidderRequest); - expect(request.url).to.equal('//piohbdisp.hb.adx1.com/'); - expect(request.method).to.equal('POST'); - const ortbRequest = JSON.parse(request.data); - expect(ortbRequest.user).to.not.equal(null); - expect(ortbRequest.user.ext).to.not.equal(null); - expect(ortbRequest.user.ext.consent).to.equal('serialized_gpdr_data'); - expect(ortbRequest.regs).to.not.equal(null); - expect(ortbRequest.regs.ext).to.not.equal(null); - expect(ortbRequest.regs.ext.gdpr).to.equal(1); - }); -}); +import {expect} from 'chai'; +import {spec} from 'modules/platformioBidAdapter'; +import {getTopWindowLocation} from 'src/utils'; +import {newBidder} from 'src/adapters/bidderFactory'; + +describe('Platform.io Adapter Tests', function () { + const slotConfigs = [{ + placementCode: '/DfpAccount1/slot1', + bidId: 'bid12345', + mediaType: 'banner', + params: { + pubId: '29521', + siteId: '26047', + placementId: '123', + size: '300x250', + bidFloor: '0.001', + ifa: 'IFA', + latitude: '40.712775', + longitude: '-74.005973' + } + }, { + placementCode: '/DfpAccount2/slot2', + bidId: 'bid23456', + mediaType: 'banner', + params: { + pubId: '29521', + siteId: '26047', + placementId: '1234', + size: '728x90', + bidFloor: '0.000001', + } + }]; + const nativeSlotConfig = [{ + placementCode: '/DfpAccount1/slot3', + bidId: 'bid12345', + mediaType: 'native', + nativeParams: { + title: { required: true, len: 200 }, + body: {}, + image: { wmin: 100 }, + sponsoredBy: { }, + icon: { } + }, + params: { + pubId: '29521', + placementId: '123', + siteId: '26047' + } + }]; + const videoSlotConfig = [{ + placementCode: '/DfpAccount1/slot4', + bidId: 'bid12345678', + mediaType: 'video', + video: { + skippable: true + }, + params: { + pubId: '29521', + placementId: '1234567', + siteId: '26047', + size: '640x480' + } + }]; + const appSlotConfig = [{ + placementCode: '/DfpAccount1/slot5', + bidId: 'bid12345', + params: { + pubId: '29521', + placementId: '1234', + app: { + id: '1111', + name: 'app name', + bundle: 'io.platform.apps', + storeUrl: 'http://platform.io/apps', + domain: 'platform.io' + } + } + }]; + + it('Verify build request', function () { + const request = spec.buildRequests(slotConfigs); + expect(request.url).to.equal('//piohbdisp.hb.adx1.com/'); + expect(request.method).to.equal('POST'); + const ortbRequest = JSON.parse(request.data); + // site object + expect(ortbRequest.site).to.not.equal(null); + expect(ortbRequest.site.publisher).to.not.equal(null); + expect(ortbRequest.site.publisher.id).to.equal('29521'); + expect(ortbRequest.site.ref).to.equal(window.top.document.referrer); + expect(ortbRequest.site.page).to.equal(getTopWindowLocation().href); + expect(ortbRequest.imp).to.have.lengthOf(2); + // device object + expect(ortbRequest.device).to.not.equal(null); + expect(ortbRequest.device.ua).to.equal(navigator.userAgent); + expect(ortbRequest.device.ifa).to.equal('IFA'); + expect(ortbRequest.device.geo.lat).to.equal('40.712775'); + expect(ortbRequest.device.geo.lon).to.equal('-74.005973'); + // slot 1 + expect(ortbRequest.imp[0].tagid).to.equal('123'); + expect(ortbRequest.imp[0].banner).to.not.equal(null); + expect(ortbRequest.imp[0].banner.w).to.equal(300); + expect(ortbRequest.imp[0].banner.h).to.equal(250); + expect(ortbRequest.imp[0].bidfloor).to.equal('0.001'); + // slot 2 + expect(ortbRequest.imp[1].tagid).to.equal('1234'); + expect(ortbRequest.imp[1].banner).to.not.equal(null); + expect(ortbRequest.imp[1].banner.w).to.equal(728); + expect(ortbRequest.imp[1].banner.h).to.equal(90); + expect(ortbRequest.imp[1].bidfloor).to.equal('0.000001'); + }); + + it('Verify parse response', function () { + const request = spec.buildRequests(slotConfigs); + const ortbRequest = JSON.parse(request.data); + const ortbResponse = { + seatbid: [{ + bid: [{ + impid: ortbRequest.imp[0].id, + price: 1.25, + adm: 'This is an Ad' + }] + }], + cur: 'USD' + }; + const bids = spec.interpretResponse({ body: ortbResponse }, request); + expect(bids).to.have.lengthOf(1); + // verify first bid + const bid = bids[0]; + expect(bid.cpm).to.equal(1.25); + expect(bid.ad).to.equal('This is an Ad'); + expect(bid.width).to.equal(300); + expect(bid.height).to.equal(250); + expect(bid.adId).to.equal('bid12345'); + expect(bid.creativeId).to.equal('bid12345'); + expect(bid.netRevenue).to.equal(true); + expect(bid.currency).to.equal('USD'); + expect(bid.ttl).to.equal(360); + }); + + it('Verify full passback', function () { + const request = spec.buildRequests(slotConfigs); + const bids = spec.interpretResponse({ body: null }, request) + expect(bids).to.have.lengthOf(0); + }); + + it('Verify Native request', function () { + const request = spec.buildRequests(nativeSlotConfig); + expect(request.url).to.equal('//piohbdisp.hb.adx1.com/'); + expect(request.method).to.equal('POST'); + const ortbRequest = JSON.parse(request.data); + // native impression + expect(ortbRequest.imp[0].tagid).to.equal('123'); + const nativePart = ortbRequest.imp[0]['native']; + expect(nativePart).to.not.equal(null); + expect(nativePart.ver).to.equal('1.1'); + expect(nativePart.request).to.not.equal(null); + // native request assets + const nativeRequest = JSON.parse(ortbRequest.imp[0]['native'].request); + expect(nativeRequest).to.not.equal(null); + expect(nativeRequest.assets).to.have.lengthOf(5); + expect(nativeRequest.assets[0].id).to.equal(1); + expect(nativeRequest.assets[1].id).to.equal(2); + expect(nativeRequest.assets[2].id).to.equal(3); + expect(nativeRequest.assets[3].id).to.equal(4); + expect(nativeRequest.assets[4].id).to.equal(5); + expect(nativeRequest.assets[0].required).to.equal(1); + expect(nativeRequest.assets[0].title).to.not.equal(null); + expect(nativeRequest.assets[0].title.len).to.equal(200); + expect(nativeRequest.assets[1].title).to.be.undefined; + expect(nativeRequest.assets[1].data).to.not.equal(null); + expect(nativeRequest.assets[1].data.type).to.equal(2); + expect(nativeRequest.assets[1].data.len).to.equal(200); + expect(nativeRequest.assets[2].required).to.equal(0); + expect(nativeRequest.assets[3].img).to.not.equal(null); + expect(nativeRequest.assets[3].img.wmin).to.equal(50); + expect(nativeRequest.assets[3].img.hmin).to.equal(50); + expect(nativeRequest.assets[3].img.type).to.equal(1); + expect(nativeRequest.assets[4].img).to.not.equal(null); + expect(nativeRequest.assets[4].img.wmin).to.equal(100); + expect(nativeRequest.assets[4].img.hmin).to.equal(150); + expect(nativeRequest.assets[4].img.type).to.equal(3); + }); + + it('Verify Native response', function () { + const request = spec.buildRequests(nativeSlotConfig); + expect(request.url).to.equal('//piohbdisp.hb.adx1.com/'); + expect(request.method).to.equal('POST'); + const ortbRequest = JSON.parse(request.data); + const nativeResponse = { + 'native': { + assets: [ + { id: 1, title: { text: 'Ad Title' } }, + { id: 2, data: { value: 'Test description' } }, + { id: 3, data: { value: 'Brand' } }, + { id: 4, img: { url: 'https://s3.amazonaws.com/adx1public/creatives_icon.png', w: 100, h: 100 } }, + { id: 5, img: { url: 'https://s3.amazonaws.com/adx1public/creatives_image.png', w: 300, h: 300 } } + ], + link: { url: 'http://brand.com/' } + } + }; + const ortbResponse = { + seatbid: [{ + bid: [{ + impid: ortbRequest.imp[0].id, + price: 1.25, + nurl: 'http://rtb.adx1.com/log', + adm: JSON.stringify(nativeResponse) + }] + }], + cur: 'USD', + }; + const bids = spec.interpretResponse({ body: ortbResponse }, request); + // verify bid + const bid = bids[0]; + expect(bid.cpm).to.equal(1.25); + expect(bid.adId).to.equal('bid12345'); + expect(bid.ad).to.be.undefined; + expect(bid.mediaType).to.equal('native'); + const nativeBid = bid['native']; + expect(nativeBid).to.not.equal(null); + expect(nativeBid.title).to.equal('Ad Title'); + expect(nativeBid.sponsoredBy).to.equal('Brand'); + expect(nativeBid.icon.url).to.equal('https://s3.amazonaws.com/adx1public/creatives_icon.png'); + expect(nativeBid.image.url).to.equal('https://s3.amazonaws.com/adx1public/creatives_image.png'); + expect(nativeBid.image.width).to.equal(300); + expect(nativeBid.image.height).to.equal(300); + expect(nativeBid.icon.width).to.equal(100); + expect(nativeBid.icon.height).to.equal(100); + expect(nativeBid.clickUrl).to.equal(encodeURIComponent('http://brand.com/')); + expect(nativeBid.impressionTrackers).to.have.lengthOf(1); + expect(nativeBid.impressionTrackers[0]).to.equal('http://rtb.adx1.com/log'); + }); + + it('Verify Video request', function () { + const request = spec.buildRequests(videoSlotConfig); + expect(request.url).to.equal('//piohbdisp.hb.adx1.com/'); + expect(request.method).to.equal('POST'); + const videoRequest = JSON.parse(request.data); + // site object + expect(videoRequest.site).to.not.equal(null); + expect(videoRequest.site.publisher.id).to.equal('29521'); + expect(videoRequest.site.ref).to.equal(window.top.document.referrer); + expect(videoRequest.site.page).to.equal(getTopWindowLocation().href); + // device object + expect(videoRequest.device).to.not.equal(null); + expect(videoRequest.device.ua).to.equal(navigator.userAgent); + // slot 1 + expect(videoRequest.imp[0].tagid).to.equal('1234567'); + expect(videoRequest.imp[0].video).to.not.equal(null); + expect(videoRequest.imp[0].video.w).to.equal(640); + expect(videoRequest.imp[0].video.h).to.equal(480); + expect(videoRequest.imp[0].banner).to.equal(null); + expect(videoRequest.imp[0].native).to.equal(null); + }); + + it('Verify parse video response', function () { + const request = spec.buildRequests(videoSlotConfig); + const videoRequest = JSON.parse(request.data); + const videoResponse = { + seatbid: [{ + bid: [{ + impid: videoRequest.imp[0].id, + price: 1.90, + adm: 'http://vid.example.com/9876', + crid: '510511_754567308' + }] + }], + cur: 'USD' + }; + const bids = spec.interpretResponse({ body: videoResponse }, request); + expect(bids).to.have.lengthOf(1); + // verify first bid + const bid = bids[0]; + expect(bid.cpm).to.equal(1.90); + expect(bid.vastUrl).to.equal('http://vid.example.com/9876'); + expect(bid.crid).to.equal('510511_754567308'); + expect(bid.width).to.equal(640); + expect(bid.height).to.equal(480); + expect(bid.adId).to.equal('bid12345678'); + expect(bid.netRevenue).to.equal(true); + expect(bid.currency).to.equal('USD'); + expect(bid.ttl).to.equal(360); + }); + + it('Verifies bidder code', function () { + expect(spec.code).to.equal('platformio'); + }); + + it('Verifies supported media types', function () { + expect(spec.supportedMediaTypes).to.have.lengthOf(3); + expect(spec.supportedMediaTypes[0]).to.equal('banner'); + expect(spec.supportedMediaTypes[1]).to.equal('native'); + expect(spec.supportedMediaTypes[2]).to.equal('video'); + }); + + it('Verifies if bid request valid', function () { + expect(spec.isBidRequestValid(slotConfigs[0])).to.equal(true); + expect(spec.isBidRequestValid(slotConfigs[1])).to.equal(true); + expect(spec.isBidRequestValid(nativeSlotConfig[0])).to.equal(true); + expect(spec.isBidRequestValid(videoSlotConfig[0])).to.equal(true); + }); + + it('Verify app requests', function () { + const request = spec.buildRequests(appSlotConfig); + const ortbRequest = JSON.parse(request.data); + expect(ortbRequest.site).to.equal(null); + expect(ortbRequest.app).to.not.be.null; + expect(ortbRequest.app.publisher).to.not.equal(null); + expect(ortbRequest.app.publisher.id).to.equal('29521'); + expect(ortbRequest.app.id).to.equal('1111'); + expect(ortbRequest.app.name).to.equal('app name'); + expect(ortbRequest.app.bundle).to.equal('io.platform.apps'); + expect(ortbRequest.app.storeurl).to.equal('http://platform.io/apps'); + expect(ortbRequest.app.domain).to.equal('platform.io'); + }); + + it('Verify GDPR', function () { + const bidderRequest = { + gdprConsent: { + gdprApplies: true, + consentString: 'serialized_gpdr_data' + } + }; + const request = spec.buildRequests(slotConfigs, bidderRequest); + expect(request.url).to.equal('//piohbdisp.hb.adx1.com/'); + expect(request.method).to.equal('POST'); + const ortbRequest = JSON.parse(request.data); + expect(ortbRequest.user).to.not.equal(null); + expect(ortbRequest.user.ext).to.not.equal(null); + expect(ortbRequest.user.ext.consent).to.equal('serialized_gpdr_data'); + expect(ortbRequest.regs).to.not.equal(null); + expect(ortbRequest.regs.ext).to.not.equal(null); + expect(ortbRequest.regs.ext.gdpr).to.equal(1); + }); +}); diff --git a/test/spec/modules/playgroundxyzBidAdapter_spec.js b/test/spec/modules/playgroundxyzBidAdapter_spec.js index becd8612a9c..fc430bfb31b 100644 --- a/test/spec/modules/playgroundxyzBidAdapter_spec.js +++ b/test/spec/modules/playgroundxyzBidAdapter_spec.js @@ -3,19 +3,19 @@ import { spec } from 'modules/playgroundxyzBidAdapter'; import { newBidder } from 'src/adapters/bidderFactory'; import { deepClone } from 'src/utils'; -const URL = 'https://ads.playground.xyz/host-config/prebid'; +const URL = 'https://ads.playground.xyz/host-config/prebid?v=2'; const GDPR_CONSENT = 'XYZ-CONSENT'; -describe('playgroundxyzBidAdapter', () => { +describe('playgroundxyzBidAdapter', function () { const adapter = newBidder(spec); - describe('inherited functions', () => { - it('exists and is a function', () => { + describe('inherited functions', function () { + it('exists and is a function', function () { expect(adapter.callBids).to.exist.and.to.be.a('function'); }); }); - describe('isBidRequestValid', () => { + describe('isBidRequestValid', function () { let bid = { 'bidder': 'playgroundxyz', 'params': { @@ -28,11 +28,11 @@ describe('playgroundxyzBidAdapter', () => { 'auctionId': '1d1a030790a475', }; - it('should return true when required params found', () => { + it('should return true when required params found', function () { expect(spec.isBidRequestValid(bid)).to.equal(true); }); - it('should return false when required params are not passed', () => { + it('should return false when required params are not passed', function () { let bid = Object.assign({}, bid); delete bid.params; bid.params = { @@ -42,7 +42,7 @@ describe('playgroundxyzBidAdapter', () => { }); }); - describe('buildRequests', () => { + describe('buildRequests', function () { let bidRequests = [ { 'bidder': 'playgroundxyz', @@ -57,14 +57,14 @@ describe('playgroundxyzBidAdapter', () => { } ]; - it('sends bid request to ENDPOINT via POST', () => { + it('sends bid request to ENDPOINT via POST', function () { let bidRequest = Object.assign([], bidRequests); const request = spec.buildRequests(bidRequest); const data = JSON.parse(request.data); const banner = data.imp[0].banner; - expect(Object.keys(data.imp[0].ext)).to.have.members(['appnexus']); + expect(Object.keys(data.imp[0].ext)).to.have.members(['appnexus', 'pxyz']); expect([banner.w, banner.h]).to.deep.equal([300, 250]); expect(banner.format).to.deep.equal([{w: 300, h: 250}, {w: 300, h: 600}]); expect(request.url).to.equal(URL); @@ -72,7 +72,7 @@ describe('playgroundxyzBidAdapter', () => { }); }) - describe('interpretResponse', () => { + describe('interpretResponse', function () { let response = { 'id': 'bidd_id', 'seatbid': [ { @@ -102,14 +102,14 @@ describe('playgroundxyzBidAdapter', () => { 'seat': '4321' }], 'bidid': '6894227111893743356', - 'cur': 'USD' + 'cur': 'AUD' }; let bidderRequest = { 'bidderCode': 'playgroundxyz' }; - it('should get correct bid response', () => { + it('should get correct bid response', function () { let expectedResponse = [ { 'requestId': '221f2bdc1fbc31', @@ -119,7 +119,7 @@ describe('playgroundxyzBidAdapter', () => { 'height': 50, 'ad': '', 'mediaType': 'banner', - 'currency': 'USD', + 'currency': 'AUD', 'ttl': 300, 'netRevenue': true } @@ -128,14 +128,14 @@ describe('playgroundxyzBidAdapter', () => { expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])); }); - it('handles nobid responses', () => { - let response = ''; + it('handles nobid response', function () { + const response = undefined; let result = spec.interpretResponse({ body: response }, {bidderRequest}); expect(result.length).to.equal(0); }); }); - describe('buildRequests', () => { + describe('buildRequests', function () { let bidRequests = [ { 'bidder': 'playgroundxyz', @@ -150,7 +150,7 @@ describe('playgroundxyzBidAdapter', () => { } ]; - it('should not populate GDPR', () => { + it('should not populate GDPR', function () { let bidRequest = Object.assign([], bidRequests); const request = spec.buildRequests(bidRequest); let data = JSON.parse(request.data); @@ -158,7 +158,7 @@ describe('playgroundxyzBidAdapter', () => { expect(data).to.not.have.property('regs'); }); - it('should populate GDPR and consent string when consetString is presented but not gdpApplies', () => { + it('should populate GDPR and consent string when consetString is presented but not gdpApplies', function () { let bidRequest = Object.assign([], bidRequests); const request = spec.buildRequests(bidRequest, {gdprConsent: {consentString: GDPR_CONSENT}}); let data = JSON.parse(request.data); @@ -166,7 +166,7 @@ describe('playgroundxyzBidAdapter', () => { expect(data.user.ext.consent).to.equal('XYZ-CONSENT'); }); - it('should populate GDPR and consent string when gdpr is set to true', () => { + it('should populate GDPR and consent string when gdpr is set to true', function () { let bidRequest = Object.assign([], bidRequests); const request = spec.buildRequests(bidRequest, {gdprConsent: {gdprApplies: true, consentString: GDPR_CONSENT}}); let data = JSON.parse(request.data); @@ -174,7 +174,7 @@ describe('playgroundxyzBidAdapter', () => { expect(data.user.ext.consent).to.equal('XYZ-CONSENT'); }); - it('should populate GDPR and consent string when gdpr is set to false', () => { + it('should populate GDPR and consent string when gdpr is set to false', function () { let bidRequest = Object.assign([], bidRequests); const request = spec.buildRequests(bidRequest, {gdprConsent: {gdprApplies: false, consentString: GDPR_CONSENT}}); let data = JSON.parse(request.data); diff --git a/test/spec/modules/polluxBidAdapter_spec.js b/test/spec/modules/polluxBidAdapter_spec.js index ea550fecd71..ad30771e15b 100644 --- a/test/spec/modules/polluxBidAdapter_spec.js +++ b/test/spec/modules/polluxBidAdapter_spec.js @@ -24,7 +24,7 @@ describe('POLLUX Bid Adapter tests', function () { params: {zone: '276'} }]; - it('TEST: verify buildRequests no valid bid requests', () => { + it('TEST: verify buildRequests no valid bid requests', function () { let request = spec.buildRequests(false); expect(request).to.not.equal(null); expect(request).to.not.have.property('method'); @@ -47,7 +47,7 @@ describe('POLLUX Bid Adapter tests', function () { expect(request).to.not.have.property('data'); }); - it('TEST: verify buildRequests single bid', () => { + it('TEST: verify buildRequests single bid', function () { const request = spec.buildRequests(setup_single_bid); expect(request.method).to.equal('POST'); const requested_bids = JSON.parse(request.data); @@ -70,7 +70,7 @@ describe('POLLUX Bid Adapter tests', function () { expect(requested_bids[0].zones).to.equal('1806,276'); }); - it('TEST: verify buildRequests multi bid', () => { + it('TEST: verify buildRequests multi bid', function () { const request = spec.buildRequests(setup_multi_bid); expect(request.method).to.equal('POST'); const requested_bids = JSON.parse(request.data); @@ -102,7 +102,7 @@ describe('POLLUX Bid Adapter tests', function () { expect(requested_bids[1].zones).to.equal('276'); }); - it('TEST: verify interpretResponse empty', () => { + it('TEST: verify interpretResponse empty', function () { let bids = spec.interpretResponse(false, {}); expect(bids).to.not.equal(null); expect(bids).to.have.lengthOf(0); @@ -117,7 +117,7 @@ describe('POLLUX Bid Adapter tests', function () { expect(bids).to.have.lengthOf(0); }); - it('TEST: verify interpretResponse ad_type url', () => { + it('TEST: verify interpretResponse ad_type url', function () { const serverResponse = { body: [ { @@ -147,7 +147,7 @@ describe('POLLUX Bid Adapter tests', function () { expect(bids[0]).to.not.have.property('ad'); }); - it('TEST: verify interpretResponse ad_type html', () => { + it('TEST: verify interpretResponse ad_type html', function () { const serverResponse = { body: [ { @@ -176,7 +176,7 @@ describe('POLLUX Bid Adapter tests', function () { expect(bids[0].ad).to.equal('

I am an ad

'); }); - it('TEST: verify url and query params', () => { + it('TEST: verify url and query params', function () { const URL = require('url-parse'); const querystringify = require('querystringify'); const request = spec.buildRequests(setup_single_bid); @@ -188,7 +188,7 @@ describe('POLLUX Bid Adapter tests', function () { expect(parsedQuery).to.have.property('domain').and.to.have.length.above(1); }); - it('TEST: verify isBidRequestValid', () => { + it('TEST: verify isBidRequestValid', function () { expect(spec.isBidRequestValid({})).to.equal(false); expect(spec.isBidRequestValid({params: {}})).to.equal(false); expect(spec.isBidRequestValid(setup_single_bid[0])).to.equal(true); @@ -196,11 +196,11 @@ describe('POLLUX Bid Adapter tests', function () { expect(spec.isBidRequestValid(setup_multi_bid[1])).to.equal(true); }); - it('TEST: verify bidder code', () => { + it('TEST: verify bidder code', function () { expect(spec.code).to.equal('pollux'); }); - it('TEST: verify bidder aliases', () => { + it('TEST: verify bidder aliases', function () { expect(spec.aliases).to.have.lengthOf(1); expect(spec.aliases[0]).to.equal('plx'); }); diff --git a/test/spec/modules/polymorphBidAdapter_spec.js b/test/spec/modules/polymorphBidAdapter_spec.js index cf20cdfaf22..6fd4bd90288 100644 --- a/test/spec/modules/polymorphBidAdapter_spec.js +++ b/test/spec/modules/polymorphBidAdapter_spec.js @@ -5,6 +5,9 @@ import { newBidder } from 'src/adapters/bidderFactory'; const BIDDER_CODE = 'polymorph'; const ENDPOINT_URL = '//api.adsnative.com/v1/ad-template.json'; const PLACEMENT_ID = 'ping'; +const NETWORK_KEY = 'abcd1234'; +const WIDGET_ID = 'xyz'; +const CATEGORIES = 'IAB1,IAB2'; const spec = newBidder(polymorphAdapterSpec).getSpec(); @@ -31,21 +34,38 @@ const bidRequests = [{ 'bidId': '30b31c1838de1d', 'bidderRequestId': '22edbae2733bf7', 'auctionId': '1d1a030790a476', +}, +{ + 'bidder': BIDDER_CODE, + 'params': { + 'network_key': NETWORK_KEY, + 'widget_id': WIDGET_ID, + 'cat': CATEGORIES + }, + 'adUnitCode': 'adunit-code', + 'sizes': [[700, 250], [300, 600]], + 'bidId': '30b31c1838de1f', + 'bidderRequestId': '22edbae2733bf7', + 'auctionId': '1d1a030790a476', }]; -describe('Polymorph adapter test', () => { - describe('.code', () => { - it('should return a bidder code of polymorph', () => { +describe('Polymorph adapter test', function () { + describe('.code', function () { + it('should return a bidder code of polymorph', function () { expect(spec.code).to.eql(BIDDER_CODE); }); }); - describe('isBidRequestValid', () => { - it('should return true when required params found', () => { + describe('isBidRequestValid', function () { + it('should return true when required params found', function () { expect(spec.isBidRequestValid(bidRequests[0])).to.equal(true); }); - it('should return false if req has no placementId', () => { + it('should return true when required params found', function () { + expect(spec.isBidRequestValid(bidRequests[2])).to.equal(true); + }); + + it('should return false if req has no placementId', function () { const invalidBidRequest = { bidder: BIDDER_CODE, params: { @@ -55,7 +75,7 @@ describe('Polymorph adapter test', () => { expect(spec.isBidRequestValid(invalidBidRequest)).to.eql(false); }); - it('should return false if req has wrong bidder code', () => { + it('should return false if req has wrong bidder code', function () { const invalidBidRequest = { bidder: 'something', params: { @@ -66,8 +86,8 @@ describe('Polymorph adapter test', () => { }); }); - describe('buildRequests', () => { - it('payload test', () => { + describe('buildRequests', function () { + it('payload test', function () { const requests = spec.buildRequests(bidRequests); var payload1 = {}; requests[0].data.replace(/([^=&]+)=([^&]*)/g, function(m, key, value) { @@ -79,6 +99,7 @@ describe('Polymorph adapter test', () => { expect(payload1.hb_source).to.equal('prebid'); expect(payload1.zid).to.equal(PLACEMENT_ID); expect(payload1.sizes).to.equal('300,250,300,600'); + expect(payload1.bid_id).to.equal('30b31c1838de1e'); var payload2 = {}; requests[1].data.replace(/([^=&]+)=([^&]*)/g, function(m, key, value) { @@ -90,16 +111,31 @@ describe('Polymorph adapter test', () => { expect(payload2.hb_source).to.equal('prebid'); expect(payload2.zid).to.equal(PLACEMENT_ID); expect(payload2.sizes).to.equal('700,250,300,600'); + expect(payload2.bid_id).to.equal('30b31c1838de1d'); + + var payload3 = {}; + requests[2].data.replace(/([^=&]+)=([^&]*)/g, function(m, key, value) { + payload3[decodeURIComponent(key)] = decodeURIComponent(value); + }); + expect(payload3.ref).to.not.be.undefined; + expect(payload3.url).to.not.be.undefined; + expect(payload3.hb).to.equal('1'); + expect(payload3.hb_source).to.equal('prebid'); + expect(payload3.network_key).to.equal(NETWORK_KEY); + expect(payload3.widget_id).to.equal(WIDGET_ID); + expect(payload3.cat).to.equal(CATEGORIES); + expect(payload3.sizes).to.equal('700,250,300,600'); + expect(payload3.bid_id).to.equal('30b31c1838de1f'); }); - it('sends bid request to ENDPOINT via GET', () => { + it('sends bid request to ENDPOINT via GET', function () { const requests = spec.buildRequests(bidRequests); expect(requests[0].url).to.equal(ENDPOINT_URL); expect(requests[0].method).to.equal('GET'); }); }); - describe('interpretResponse', () => { + describe('interpretResponse', function () { const response = { body: { 'status': 'OK', @@ -133,7 +169,7 @@ describe('Polymorph adapter test', () => { } }; - it('should get correct bid response', () => { + it('should get correct bid response', function () { const body = response.body; const expectedResponse = [{ requestId: bidRequests[0].bidId, @@ -152,7 +188,7 @@ describe('Polymorph adapter test', () => { expect(result).to.deep.equal(expectedResponse); }); - it('widget use case', () => { + it('widget use case', function () { const body = response2.body; const expectedResponse = [ { @@ -173,7 +209,7 @@ describe('Polymorph adapter test', () => { expect(result).to.deep.equal(expectedResponse); }); - it('handles nobid responses', () => { + it('handles nobid responses', function () { let response = []; let result = spec.interpretResponse(response, { 'bidderRequest': bidRequests[0] }); diff --git a/test/spec/modules/prebidServerBidAdapter_spec.js b/test/spec/modules/prebidServerBidAdapter_spec.js index f3cc150ab6e..4f7467cf9b1 100644 --- a/test/spec/modules/prebidServerBidAdapter_spec.js +++ b/test/spec/modules/prebidServerBidAdapter_spec.js @@ -1,8 +1,7 @@ import { expect } from 'chai'; import { PrebidServer as Adapter, resetSyncedStatus } from 'modules/prebidServerBidAdapter/index.js'; -import adapterManager from 'src/adaptermanager'; +import adapterManager from 'src/adapterManager'; import * as utils from 'src/utils'; -import cookie from 'src/cookie'; import { userSync } from 'src/userSync'; import { ajax } from 'src/ajax'; import { config } from 'src/config'; @@ -329,12 +328,12 @@ const RESPONSE_UNSUPPORTED_BIDDER = { }] }; -describe('S2S Adapter', () => { +describe('S2S Adapter', function () { let adapter, addBidResponse = sinon.spy(), done = sinon.spy(); - beforeEach(() => { + beforeEach(function () { adapter = new Adapter(); BID_REQUESTS = [ { @@ -370,16 +369,16 @@ describe('S2S Adapter', () => { ]; }); - afterEach(() => { + afterEach(function () { addBidResponse.resetHistory(); done.resetHistory(); }); - describe('request function', () => { + describe('request function', function () { let xhr; let requests; - beforeEach(() => { + beforeEach(function () { xhr = sinon.useFakeXMLHttpRequest(); requests = []; xhr.onCreate = request => requests.push(request); @@ -387,13 +386,15 @@ describe('S2S Adapter', () => { resetSyncedStatus(); }); - afterEach(() => xhr.restore()); + afterEach(function () { + xhr.restore(); + }); - it('exists and is a function', () => { + it('exists and is a function', function () { expect(adapter.callBids).to.exist.and.to.be.a('function'); }); - it('exists converts types', () => { + it('exists converts types', function () { config.setConfig({s2sConfig: CONFIG}); adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax); const requestBid = JSON.parse(requests[0].requestBody); @@ -402,13 +403,13 @@ describe('S2S Adapter', () => { expect(requestBid.ad_units[0].bids[0].params.member).to.exist.and.to.be.a('string'); }); - describe('gdpr tests', () => { - afterEach(() => { + describe('gdpr tests', function () { + afterEach(function () { config.resetConfig(); $$PREBID_GLOBAL$$.requestBids.removeHook(requestBidsHook); }); - it('adds gdpr consent information to ortb2 request depending on presence of module', () => { + it('adds gdpr consent information to ortb2 request depending on presence of module', function () { let ortb2Config = utils.deepClone(CONFIG); ortb2Config.endpoint = 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction' @@ -437,7 +438,7 @@ describe('S2S Adapter', () => { expect(requestBid.user).to.not.exist; }); - it('check gdpr info gets added into cookie_sync request: have consent data', () => { + it('check gdpr info gets added into cookie_sync request: have consent data', function () { let cookieSyncConfig = utils.deepClone(CONFIG); cookieSyncConfig.syncEndpoint = 'https://prebid.adnxs.com/pbs/v1/cookie_sync'; @@ -456,9 +457,11 @@ describe('S2S Adapter', () => { expect(requestBid.gdpr).is.equal(1); expect(requestBid.gdpr_consent).is.equal('abc123def'); + expect(requestBid.bidders).to.contain('appnexus').and.to.have.lengthOf(1); + expect(requestBid.account).is.equal('1'); }); - it('check gdpr info gets added into cookie_sync request: have consent data but gdprApplies is false', () => { + it('check gdpr info gets added into cookie_sync request: have consent data but gdprApplies is false', function () { let cookieSyncConfig = utils.deepClone(CONFIG); cookieSyncConfig.syncEndpoint = 'https://prebid.adnxs.com/pbs/v1/cookie_sync'; @@ -478,7 +481,7 @@ describe('S2S Adapter', () => { expect(requestBid.gdpr_consent).is.undefined; }); - it('checks gdpr info gets added to cookie_sync request: consent data unknown', () => { + it('checks gdpr info gets added to cookie_sync request: consent data unknown', function () { let cookieSyncConfig = utils.deepClone(CONFIG); cookieSyncConfig.syncEndpoint = 'https://prebid.adnxs.com/pbs/v1/cookie_sync'; @@ -499,7 +502,7 @@ describe('S2S Adapter', () => { }); }); - it('sets invalid cacheMarkup value to 0', () => { + it('sets invalid cacheMarkup value to 0', function () { const s2sConfig = Object.assign({}, CONFIG, { cacheMarkup: 999 }); @@ -509,7 +512,7 @@ describe('S2S Adapter', () => { expect(requestBid).to.have.property('cache_markup', 0); }); - it('adds digitrust id is present and user is not optout', () => { + it('adds digitrust id is present and user is not optout', function () { let digiTrustObj = { success: true, identity: { @@ -544,7 +547,7 @@ describe('S2S Adapter', () => { delete window.DigiTrust; }); - it('adds device and app objects to request', () => { + it('adds device and app objects to request', function () { const _config = { s2sConfig: CONFIG, device: { ifa: '6D92078A-8246-4BA4-AE5B-76104861E7DC' }, app: { bundle: 'com.test.app' }, @@ -555,6 +558,8 @@ describe('S2S Adapter', () => { const requestBid = JSON.parse(requests[0].requestBody); expect(requestBid.device).to.deep.equal({ ifa: '6D92078A-8246-4BA4-AE5B-76104861E7DC', + w: window.innerWidth, + h: window.innerHeight }); expect(requestBid.app).to.deep.equal({ bundle: 'com.test.app', @@ -562,7 +567,7 @@ describe('S2S Adapter', () => { }); }); - it('adds device and app objects to request for ORTB', () => { + it('adds device and app objects to request for ORTB', function () { const s2sConfig = Object.assign({}, CONFIG, { endpoint: 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction' }); @@ -578,6 +583,31 @@ describe('S2S Adapter', () => { const requestBid = JSON.parse(requests[0].requestBody); expect(requestBid.device).to.deep.equal({ ifa: '6D92078A-8246-4BA4-AE5B-76104861E7DC', + w: window.innerWidth, + h: window.innerHeight + }); + expect(requestBid.app).to.deep.equal({ + bundle: 'com.test.app', + publisher: {'id': '1'} + }); + }); + + it('adds device.w and device.h even if the config lacks a device object', function () { + const s2sConfig = Object.assign({}, CONFIG, { + endpoint: 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction' + }); + + const _config = { + s2sConfig: s2sConfig, + app: { bundle: 'com.test.app' }, + }; + + config.setConfig(_config); + adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax); + const requestBid = JSON.parse(requests[0].requestBody); + expect(requestBid.device).to.deep.equal({ + w: window.innerWidth, + h: window.innerHeight }); expect(requestBid.app).to.deep.equal({ bundle: 'com.test.app', @@ -585,7 +615,7 @@ describe('S2S Adapter', () => { }); }); - it('adds site if app is not present', () => { + it('adds site if app is not present', function () { const s2sConfig = Object.assign({}, CONFIG, { endpoint: 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction' }); @@ -602,7 +632,7 @@ describe('S2S Adapter', () => { expect(requestBid.site.page).to.exist.and.to.be.a('string'); }); - it('adds appnexus aliases to request', () => { + it('adds appnexus aliases to request', function () { const s2sConfig = Object.assign({}, CONFIG, { endpoint: 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction' }); @@ -629,7 +659,7 @@ describe('S2S Adapter', () => { }); }); - it('adds dynamic aliases to request', () => { + it('adds dynamic aliases to request', function () { const s2sConfig = Object.assign({}, CONFIG, { endpoint: 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction' }); @@ -659,7 +689,7 @@ describe('S2S Adapter', () => { }); }); - it('converts appnexus params to expected format for PBS', () => { + it('converts appnexus params to expected format for PBS', function () { const s2sConfig = Object.assign({}, CONFIG, { endpoint: 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction' }); @@ -708,34 +738,96 @@ describe('S2S Adapter', () => { value: ['buzz'] }]); }); + + it('adds limit to the cookie_sync request if userSyncLimit is greater than 0', function () { + let cookieSyncConfig = utils.deepClone(CONFIG); + cookieSyncConfig.syncEndpoint = 'https://prebid.adnxs.com/pbs/v1/cookie_sync'; + cookieSyncConfig.userSyncLimit = 1; + + config.setConfig({ s2sConfig: cookieSyncConfig }); + + let bidRequest = utils.deepClone(BID_REQUESTS); + adapter.callBids(REQUEST, bidRequest, addBidResponse, done, ajax); + let requestBid = JSON.parse(requests[0].requestBody); + + expect(requestBid.bidders).to.contain('appnexus').and.to.have.lengthOf(1); + expect(requestBid.account).is.equal('1'); + expect(requestBid.limit).is.equal(1); + }); + + it('does not add limit to cooke_sync request if userSyncLimit is missing or 0', function () { + let cookieSyncConfig = utils.deepClone(CONFIG); + cookieSyncConfig.syncEndpoint = 'https://prebid.adnxs.com/pbs/v1/cookie_sync'; + config.setConfig({ s2sConfig: cookieSyncConfig }); + + let bidRequest = utils.deepClone(BID_REQUESTS); + adapter.callBids(REQUEST, bidRequest, addBidResponse, done, ajax); + let requestBid = JSON.parse(requests[0].requestBody); + + expect(requestBid.bidders).to.contain('appnexus').and.to.have.lengthOf(1); + expect(requestBid.account).is.equal('1'); + expect(requestBid.limit).is.undefined; + + cookieSyncConfig.userSyncLimit = 0; + config.resetConfig(); + config.setConfig({ s2sConfig: cookieSyncConfig }); + + bidRequest = utils.deepClone(BID_REQUESTS); + adapter.callBids(REQUEST, bidRequest, addBidResponse, done, ajax); + requestBid = JSON.parse(requests[0].requestBody); + + expect(requestBid.bidders).to.contain('appnexus').and.to.have.lengthOf(1); + expect(requestBid.account).is.equal('1'); + expect(requestBid.limit).is.undefined; + }); + + it('adds s2sConfig adapterOptions to request for ORTB', function () { + const s2sConfig = Object.assign({}, CONFIG, { + endpoint: 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction', + adapterOptions: { + appnexus: { + key: 'value' + } + } + }); + const _config = { + s2sConfig: s2sConfig, + device: { ifa: '6D92078A-8246-4BA4-AE5B-76104861E7DC' }, + app: { bundle: 'com.test.app' }, + }; + + config.setConfig(_config); + adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax); + const requestBid = JSON.parse(requests[0].requestBody); + expect(requestBid.imp[0].ext.appnexus).to.haveOwnProperty('key'); + expect(requestBid.imp[0].ext.appnexus.key).to.be.equal('value') + }); }); - describe('response handler', () => { + describe('response handler', function () { let server; let logWarnSpy; - beforeEach(() => { + beforeEach(function () { server = sinon.fakeServer.create(); sinon.stub(utils, 'triggerPixel'); sinon.stub(utils, 'insertUserSyncIframe'); sinon.stub(utils, 'logError'); - sinon.stub(cookie, 'cookieSet'); sinon.stub(events, 'emit'); logWarnSpy = sinon.spy(utils, 'logWarn'); }); - afterEach(() => { + afterEach(function () { server.restore(); utils.triggerPixel.restore(); utils.insertUserSyncIframe.restore(); utils.logError.restore(); events.emit.restore(); - cookie.cookieSet.restore(); logWarnSpy.restore(); }); // TODO: test dependent on pbjs_api_spec. Needs to be isolated - it('registers bids and calls BIDDER_DONE', () => { + it('registers bids and calls BIDDER_DONE', function () { server.respondWith(JSON.stringify(RESPONSE)); config.setConfig({s2sConfig: CONFIG}); @@ -758,7 +850,7 @@ describe('S2S Adapter', () => { expect(response).to.not.have.property('vastUrl'); }); - it('registers video bids', () => { + it('registers video bids', function () { server.respondWith(JSON.stringify(VIDEO_RESPONSE)); config.setConfig({s2sConfig: CONFIG}); @@ -776,7 +868,7 @@ describe('S2S Adapter', () => { expect(response).to.have.property('vastUrl', 'video_cache_url'); }); - it('does not call addBidResponse and calls done when ad unit not set', () => { + it('does not call addBidResponse and calls done when ad unit not set', function () { server.respondWith(JSON.stringify(RESPONSE_NO_BID_NO_UNIT)); config.setConfig({s2sConfig: CONFIG}); @@ -787,7 +879,7 @@ describe('S2S Adapter', () => { sinon.assert.calledOnce(done); }); - it('does not call addBidResponse and calls done when server requests cookie sync', () => { + it('does not call addBidResponse and calls done when server requests cookie sync', function () { server.respondWith(JSON.stringify(RESPONSE_NO_COOKIE)); config.setConfig({s2sConfig: CONFIG}); @@ -798,7 +890,7 @@ describe('S2S Adapter', () => { sinon.assert.calledOnce(done); }); - it('does not call addBidResponse and calls done when ad unit is set', () => { + it('does not call addBidResponse and calls done when ad unit is set', function () { server.respondWith(JSON.stringify(RESPONSE_NO_BID_UNIT_SET)); config.setConfig({s2sConfig: CONFIG}); @@ -809,7 +901,7 @@ describe('S2S Adapter', () => { sinon.assert.calledOnce(done); }); - it('registers successful bids and calls done when there are less bids than requests', () => { + it('registers successful bids and calls done when there are less bids than requests', function () { server.respondWith(JSON.stringify(RESPONSE)); config.setConfig({s2sConfig: CONFIG}); @@ -827,7 +919,7 @@ describe('S2S Adapter', () => { .to.have.property('statusMessage', 'Bid available'); }); - it('should have dealId in bidObject', () => { + it('should have dealId in bidObject', function () { server.respondWith(JSON.stringify(RESPONSE)); config.setConfig({s2sConfig: CONFIG}); @@ -837,7 +929,7 @@ describe('S2S Adapter', () => { expect(response).to.have.property('dealId', 'test-dealid'); }); - it('should pass through default adserverTargeting if present in bidObject', () => { + it('should pass through default adserverTargeting if present in bidObject', function () { server.respondWith(JSON.stringify(RESPONSE)); config.setConfig({s2sConfig: CONFIG}); @@ -847,7 +939,7 @@ describe('S2S Adapter', () => { expect(response).to.have.property('adserverTargeting').that.deep.equals({'foo': 'bar'}); }); - it('registers client user syncs when client bid adapter is present', () => { + it('registers client user syncs when client bid adapter is present', function () { let rubiconAdapter = { registerSyncs: sinon.spy() }; @@ -864,7 +956,7 @@ describe('S2S Adapter', () => { adapterManager.getBidAdapter.restore(); }); - it('registers client user syncs when using OpenRTB endpoint', () => { + it('registers client user syncs when using OpenRTB endpoint', function () { let rubiconAdapter = { registerSyncs: sinon.spy() }; @@ -884,7 +976,7 @@ describe('S2S Adapter', () => { adapterManager.getBidAdapter.restore(); }); - it('registers bid responses when server requests cookie sync', () => { + it('registers bid responses when server requests cookie sync', function () { server.respondWith(JSON.stringify(RESPONSE_NO_PBS_COOKIE)); config.setConfig({s2sConfig: CONFIG}); @@ -903,31 +995,7 @@ describe('S2S Adapter', () => { expect(bid_request_passed).to.have.property('adId', '123'); }); - it('does not call cookieSet cookie sync when no_cookie response && not opted in', () => { - server.respondWith(JSON.stringify(RESPONSE_NO_PBS_COOKIE)); - - let myConfig = Object.assign({}, CONFIG); - - config.setConfig({s2sConfig: myConfig}); - adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax); - server.respond(); - sinon.assert.notCalled(cookie.cookieSet); - }); - - it('calls cookieSet cookie sync when no_cookie response && opted in', () => { - server.respondWith(JSON.stringify(RESPONSE_NO_PBS_COOKIE)); - let myConfig = Object.assign({ - cookieSet: true, - cookieSetUrl: 'https://acdn.adnxs.com/cookieset/cs.js' - }, CONFIG); - - config.setConfig({s2sConfig: myConfig}); - adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax); - server.respond(); - sinon.assert.calledOnce(cookie.cookieSet); - }); - - it('handles OpenRTB responses and call BIDDER_DONE', () => { + it('handles OpenRTB responses and call BIDDER_DONE', function () { const s2sConfig = Object.assign({}, CONFIG, { endpoint: 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction' }); @@ -950,7 +1018,7 @@ describe('S2S Adapter', () => { expect(response).to.have.property('cpm', 0.5); }); - it('handles OpenRTB video responses', () => { + it('handles OpenRTB video responses', function () { const s2sConfig = Object.assign({}, CONFIG, { endpoint: 'https://prebidserverurl/openrtb2/auction?querystring=param' }); @@ -970,7 +1038,7 @@ describe('S2S Adapter', () => { expect(response).to.have.property('cpm', 10); }); - it('should log warning for unsupported bidder', () => { + it('should log warning for unsupported bidder', function () { server.respondWith(JSON.stringify(RESPONSE_UNSUPPORTED_BIDDER)); const s2sConfig = Object.assign({}, CONFIG, { @@ -990,18 +1058,18 @@ describe('S2S Adapter', () => { }); }); - describe('s2sConfig', () => { + describe('s2sConfig', function () { let logErrorSpy; - beforeEach(() => { + beforeEach(function () { logErrorSpy = sinon.spy(utils, 'logError'); }); - afterEach(() => { + afterEach(function () { utils.logError.restore(); }); - it('should log an error when accountId is missing', () => { + it('should log an error when accountId is missing', function () { const options = { enabled: true, bidders: ['appnexus'], @@ -1014,7 +1082,7 @@ describe('S2S Adapter', () => { sinon.assert.calledOnce(logErrorSpy); }); - it('should log an error when bidders is missing', () => { + it('should log an error when bidders is missing', function () { const options = { accountId: '1', enabled: true, @@ -1027,7 +1095,7 @@ describe('S2S Adapter', () => { sinon.assert.calledOnce(logErrorSpy); }); - it('should log an error when endpoint is missing', () => { + it('should log an error when endpoint is missing', function () { const options = { accountId: '1', bidders: ['appnexus'], @@ -1040,7 +1108,7 @@ describe('S2S Adapter', () => { sinon.assert.calledOnce(logErrorSpy); }); - it('should log an error when using an unknown vendor', () => { + it('should log an error when using an unknown vendor', function () { const options = { accountId: '1', bidders: ['appnexus'], @@ -1051,7 +1119,7 @@ describe('S2S Adapter', () => { sinon.assert.calledOnce(logErrorSpy); }); - it('should configure the s2sConfig object with appnexus vendor defaults unless specified by user', () => { + it('should configure the s2sConfig object with appnexus vendor defaults unless specified by user', function () { const options = { accountId: '123', bidders: ['appnexus'], @@ -1066,15 +1134,13 @@ describe('S2S Adapter', () => { expect(vendorConfig).to.have.property('accountId', '123'); expect(vendorConfig).to.have.property('adapter', 'prebidServer'); expect(vendorConfig.bidders).to.deep.equal(['appnexus']); - expect(vendorConfig.cookieSet).to.be.false; - expect(vendorConfig.cookieSetUrl).to.be.undefined; expect(vendorConfig.enabled).to.be.true; expect(vendorConfig).to.have.property('endpoint', '//prebid.adnxs.com/pbs/v1/openrtb2/auction'); expect(vendorConfig).to.have.property('syncEndpoint', '//prebid.adnxs.com/pbs/v1/cookie_sync'); expect(vendorConfig).to.have.property('timeout', 750); }); - it('should configure the s2sConfig object with rubicon vendor defaults unless specified by user', () => { + it('should configure the s2sConfig object with rubicon vendor defaults unless specified by user', function () { const options = { accountId: 'abc', bidders: ['rubicon'], @@ -1089,12 +1155,63 @@ describe('S2S Adapter', () => { expect(vendorConfig).to.have.property('accountId', 'abc'); expect(vendorConfig).to.have.property('adapter', 'prebidServer'); expect(vendorConfig.bidders).to.deep.equal(['rubicon']); - expect(vendorConfig.cookieSet).to.be.false; - expect(vendorConfig.cookieSetUrl).to.be.undefined; expect(vendorConfig.enabled).to.be.true; - expect(vendorConfig).to.have.property('endpoint', '//prebid-server.rubiconproject.com/auction'); + expect(vendorConfig).to.have.property('endpoint', '//prebid-server.rubiconproject.com/openrtb2/auction'); expect(vendorConfig).to.have.property('syncEndpoint', '//prebid-server.rubiconproject.com/cookie_sync'); expect(vendorConfig).to.have.property('timeout', 750); }); + + it('should return proper defaults', function () { + expect(config.getConfig('s2sConfig')).to.deep.equal({ + 'accountId': 'abc', + 'adapter': 'prebidServer', + 'bidders': ['rubicon'], + 'defaultVendor': 'rubicon', + 'enabled': true, + 'endpoint': '//prebid-server.rubiconproject.com/openrtb2/auction', + 'syncEndpoint': '//prebid-server.rubiconproject.com/cookie_sync', + 'timeout': 750 + }) + }); + + it('should return default adapterOptions if not set', function () { + config.setConfig({ + s2sConfig: { + accountId: 'abc', + bidders: ['rubicon'], + defaultVendor: 'rubicon', + timeout: 750 + } + }); + expect(config.getConfig('s2sConfig')).to.deep.equal({ + enabled: true, + timeout: 750, + adapter: 'prebidServer', + accountId: 'abc', + bidders: ['rubicon'], + defaultVendor: 'rubicon', + endpoint: '//prebid-server.rubiconproject.com/openrtb2/auction', + syncEndpoint: '//prebid-server.rubiconproject.com/cookie_sync' + }) + }); + + it('should set adapterOptions', function () { + config.setConfig({ + s2sConfig: { + adapterOptions: { + rubicon: { + singleRequest: true, + foo: 'bar' + } + } + } + }); + expect(config.getConfig('s2sConfig').adapterOptions).to.deep.equal({ + rubicon: { + singleRequest: true, + foo: 'bar' + } + }) + }); }); }); diff --git a/test/spec/modules/pubCommonId_spec.js b/test/spec/modules/pubCommonId_spec.js index bdb9d4f0545..aaf296cfb43 100644 --- a/test/spec/modules/pubCommonId_spec.js +++ b/test/spec/modules/pubCommonId_spec.js @@ -18,7 +18,7 @@ const COOKIE_NAME = '_pubcid'; const TIMEOUT = 2000; describe('Publisher Common ID', function () { - afterEach(() => { + afterEach(function () { $$PREBID_GLOBAL$$.requestBids.removeHook(requestBidHook); }); describe('Decorate adUnits', function () { @@ -159,7 +159,7 @@ describe('Publisher Common ID', function () { getUserSyncs: () => {} }; - beforeEach(() => { + beforeEach(function () { adUnits = [{ code: 'adUnit-code', mediaTypes: { @@ -179,7 +179,7 @@ describe('Publisher Common ID', function () { registerBidder(sampleSpec); }); - afterEach(() => { + afterEach(function () { auctionModule.newAuction.restore(); }); diff --git a/test/spec/modules/pubmaticBidAdapter_spec.js b/test/spec/modules/pubmaticBidAdapter_spec.js index 5c1d668f435..912a6696bdd 100644 --- a/test/spec/modules/pubmaticBidAdapter_spec.js +++ b/test/spec/modules/pubmaticBidAdapter_spec.js @@ -1,15 +1,25 @@ import {expect} from 'chai'; import {spec} from 'modules/pubmaticBidAdapter'; import * as utils from 'src/utils'; +import {config} from 'src/config'; const constants = require('src/constants.json'); -describe('PubMatic adapter', () => { +describe('PubMatic adapter', function () { let bidRequests; let videoBidRequests; let multipleMediaRequests; let bidResponses; + let nativeBidRequests; + let nativeBidRequestsWithAllParams; + let nativeBidRequestsWithoutAsset; + let nativeBidRequestsWithRequiredParam; + let nativeBidResponse; + let validnativeBidImpression; + let validnativeBidImpressionWithRequiredParam; + let nativeBidImpressionWithoutRequiredParams; + let validnativeBidImpressionWithAllParams; - beforeEach(() => { + beforeEach(function () { bidRequests = [ { bidder: 'pubmatic', @@ -123,6 +133,145 @@ describe('PubMatic adapter', () => { } ]; + nativeBidRequests = [{ + code: '/19968336/prebid_native_example_1', + sizes: [ + [300, 250] + ], + mediaTypes: { + native: { + title: { + required: true, + length: 80 + }, + image: { + required: true, + sizes: [300, 250] + }, + sponsoredBy: { + required: true + } + } + }, + nativeParams: { + title: { required: true, length: 80 }, + image: { required: true, sizes: [300, 250] }, + sponsoredBy: { required: true } + }, + bidder: 'pubmatic', + params: { + publisherId: '5670', + adSlot: '/43743431/NativeAutomationPrebid@1x1', + }, + bidId: '2a5571261281d4', + requestId: 'B68287E1-DC39-4B38-9790-FE4F179739D6', + bidderRequestId: '1c56ad30b9b8ca8', + }]; + + nativeBidRequestsWithAllParams = [{ + code: '/19968336/prebid_native_example_1', + sizes: [ + [300, 250] + ], + mediaTypes: { + native: { + title: {required: true, len: 80, ext: {'title1': 'title2'}}, + icon: {required: true, sizes: [50, 50], ext: {'icon1': 'icon2'}}, + image: {required: true, sizes: [728, 90], ext: {'image1': 'image2'}, 'mimes': ['image/png', 'image/gif']}, + sponsoredBy: {required: true, len: 10, ext: {'sponsor1': 'sponsor2'}}, + body: {required: true, len: 10, ext: {'body1': 'body2'}}, + rating: {required: true, len: 10, ext: {'rating1': 'rating2'}}, + likes: {required: true, len: 10, ext: {'likes1': 'likes2'}}, + downloads: {required: true, len: 10, ext: {'downloads1': 'downloads2'}}, + price: {required: true, len: 10, ext: {'price1': 'price2'}}, + saleprice: {required: true, len: 10, ext: {'saleprice1': 'saleprice2'}}, + phone: {required: true, len: 10, ext: {'phone1': 'phone2'}}, + address: {required: true, len: 10, ext: {'address1': 'address2'}}, + desc2: {required: true, len: 10, ext: {'desc21': 'desc22'}}, + displayurl: {required: true, len: 10, ext: {'displayurl1': 'displayurl2'}} + } + }, + nativeParams: { + title: {required: true, len: 80, ext: {'title1': 'title2'}}, + icon: {required: true, sizes: [50, 50], ext: {'icon1': 'icon2'}}, + image: {required: true, sizes: [728, 90], ext: {'image1': 'image2'}, 'mimes': ['image/png', 'image/gif']}, + sponsoredBy: {required: true, len: 10, ext: {'sponsor1': 'sponsor2'}}, + body: {required: true, len: 10, ext: {'body1': 'body2'}}, + rating: {required: true, len: 10, ext: {'rating1': 'rating2'}}, + likes: {required: true, len: 10, ext: {'likes1': 'likes2'}}, + downloads: {required: true, len: 10, ext: {'downloads1': 'downloads2'}}, + price: {required: true, len: 10, ext: {'price1': 'price2'}}, + saleprice: {required: true, len: 10, ext: {'saleprice1': 'saleprice2'}}, + phone: {required: true, len: 10, ext: {'phone1': 'phone2'}}, + address: {required: true, len: 10, ext: {'address1': 'address2'}}, + desc2: {required: true, len: 10, ext: {'desc21': 'desc22'}}, + displayurl: {required: true, len: 10, ext: {'displayurl1': 'displayurl2'}} + }, + bidder: 'pubmatic', + params: { + publisherId: '5670', + adSlot: '/43743431/NativeAutomationPrebid@1x1', + }, + bidId: '2a5571261281d4', + requestId: 'B68287E1-DC39-4B38-9790-FE4F179739D6', + bidderRequestId: '1c56ad30b9b8ca8', + }]; + + nativeBidRequestsWithoutAsset = [{ + code: '/19968336/prebid_native_example_1', + sizes: [ + [300, 250] + ], + mediaTypes: { + native: { + type: 'image' + } + }, + nativeParams: { + title: { required: true }, + image: { required: true }, + sponsoredBy: { required: true }, + clickUrl: { required: true } + }, + bidder: 'pubmatic', + params: { + publisherId: '5670', + adSlot: '/43743431/NativeAutomationPrebid@1x1', + } + }]; + + nativeBidRequestsWithRequiredParam = [{ + code: '/19968336/prebid_native_example_1', + sizes: [ + [300, 250] + ], + mediaTypes: { + native: { + title: { + required: false, + length: 80 + }, + image: { + required: false, + sizes: [300, 250] + }, + sponsoredBy: { + required: true + } + } + }, + nativeParams: { + title: { required: false, length: 80 }, + image: { required: false, sizes: [300, 250] }, + sponsoredBy: { required: true } + }, + bidder: 'pubmatic', + params: { + publisherId: '5670', + adSlot: '/43743431/NativeAutomationPrebid@1x1', + } + }]; + bidResponses = { 'body': { 'id': '93D3BAD6-E2E2-49FB-9D89-920B1761C865', @@ -153,11 +302,57 @@ describe('PubMatic adapter', () => { }] } }; + + nativeBidResponse = { + 'body': { + 'id': '1544691825939', + 'seatbid': [{ + 'bid': [{ + 'id': 'B68287E1-DC39-4B38-9790-FE4F179739D6', + 'impid': '2a5571261281d4', + 'price': 0.01, + 'adm': "{\"native\":{\"assets\":[{\"id\":1,\"title\":{\"text\":\"Native Test Title\"}},{\"id\":2,\"img\":{\"h\":627,\"url\":\"http://stagingpub.net/native_ads/PM-Native-Ad-1200x627.png\",\"w\":1200}},{\"data\":{\"value\":\"Sponsored By PubMatic\"},\"id\":4}],\"imptrackers\":[\"http://imptracker.com/main/9bde02d0-6017-11e4-9df7-005056967c35\",\"http://172.16.4.213/AdServer/AdDisplayTrackerServlet?operId=1&pubId=5890&siteId=5892&adId=6016&adType=12&adServerId=243&kefact=0.010000&kaxefact=0.010000&kadNetFrequecy=0&kadwidth=0&kadheight=0&kadsizeid=7&kltstamp=1544692761&indirectAdId=0&adServerOptimizerId=2&ranreq=0.1&kpbmtpfact=1.000000&dcId=1&tldId=0&passback=0&svr=MADS1107&ekefact=GSQSXOLKDgBAvRnoiNj0LxtpAnNEO30u1ZI5sITloOsP7gzh&ekaxefact=GSQSXAXLDgD0fOZLCjgbnVJiyS3D65dqDkxfs2ArpC3iugXw&ekpbmtpfact=GSQSXCDLDgB5mcooOvXtCKmx7TnNDJDY2YuHFOL3o9ceoU4H&crID=campaign111&lpu=advertiserdomain.com&ucrid=273354366805642829&campaignId=16981&creativeId=0&pctr=0.000000&wDSPByrId=511&wDspId=6&wbId=0&wrId=0&wAdvID=1&isRTB=1&rtbId=C09BB577-B8C1-4C3E-A0FF-73F6F631C80A&imprId=B68287E1-DC39-4B38-9790-FE4F179739D6&oid=B68287E1-DC39-4B38-9790-FE4F179739D6&pageURL=http%3A%2F%2Ftest.com%2FTestPages%2Fnativead.html\"],\"jstracker\":\"', + 'ad': ``, 'ttl': 500, 'creativeId': '1234abcd', 'netRevenue': true, @@ -306,27 +404,54 @@ describe('SonobiBidAdapter', () => { 'cpm': 1.25, 'width': 300, 'height': 250, - 'ad': 'https://mco-1-apex.go.sonobi.com/vast.xml?vid=30292e432662bd5f86d90774b944b038&ref=http://localhost/', + 'ad': 'https://mco-1-apex.go.sonobi.com/vast.xml?vid=30292e432662bd5f86d90774b944b038&ref=http%3A%2F%2Flocalhost%2F', 'ttl': 500, 'creativeId': '30292e432662bd5f86d90774b944b038', 'netRevenue': true, 'currency': 'USD', 'dealId': 'dozerkey', 'aid': '30292e432662bd5f86d90774b944b038' - } + }, + { + 'requestId': '30b31c1838de1g', + 'cpm': 1.07, + 'width': 300, + 'height': 600, + 'ad': ``, + 'ttl': 500, + 'creativeId': '1234abcd', + 'netRevenue': true, + 'currency': 'USD', + 'aid': '30292e432662bd5f86d90774b944b038' + }, ]; - it('should map bidResponse to prebidResponse', () => { + it('should map bidResponse to prebidResponse', function () { const response = spec.interpretResponse(bidResponse, bidRequests); - response.forEach(resp => { - let regx = /http:\/\/localhost:9876\/.*?(?="|$)/ - resp.ad = resp.ad.replace(regx, 'http://localhost/'); + response.forEach((resp, i) => { + expect(resp.requestId).to.equal(prebidResponse[i].requestId); + expect(resp.cpm).to.equal(prebidResponse[i].cpm); + + expect(resp.ttl).to.equal(prebidResponse[i].ttl); + expect(resp.creativeId).to.equal(prebidResponse[i].creativeId); + expect(resp.netRevenue).to.equal(prebidResponse[i].netRevenue); + expect(resp.currency).to.equal(prebidResponse[i].currency); + expect(resp.aid).to.equal(prebidResponse[i].aid); + if (resp.mediaType === 'video') { + expect(resp.vastUrl.indexOf('vast.xml')).to.be.greaterThan(0); + expect(resp.ad).to.be.undefined; + expect(resp.width).to.be.undefined; + expect(resp.height).to.be.undefined; + } else { + expect(resp.ad.indexOf('localhost')).to.be.greaterThan(0); + expect(resp.width).to.equal(prebidResponse[i].width); + expect(resp.height).to.equal(prebidResponse[i].height); + } }); - expect(response).to.deep.equal(prebidResponse); - }) - }) + }); + }); - describe('.getUserSyncs', () => { + describe('.getUserSyncs', function () { let bidResponse = [{ 'body': { 'sbi_px': [{ @@ -338,35 +463,35 @@ describe('SonobiBidAdapter', () => { } }]; - it('should return one sync pixel', () => { + it('should return one sync pixel', function () { expect(spec.getUserSyncs({ pixelEnabled: true }, bidResponse)).to.deep.equal([{ type: 'image', url: 'https://pixel-test' }]); }) - it('should return an empty array when sync is enabled but there are no bidResponses', () => { + it('should return an empty array when sync is enabled but there are no bidResponses', function () { expect(spec.getUserSyncs({ pixelEnabled: true }, [])).to.have.length(0); }) - it('should return an empty array when sync is enabled but no sync pixel returned', () => { + it('should return an empty array when sync is enabled but no sync pixel returned', function () { const pixel = Object.assign({}, bidResponse); delete pixel[0].body.sbi_px; expect(spec.getUserSyncs({ pixelEnabled: true }, bidResponse)).to.have.length(0); }) - it('should return an empty array', () => { + it('should return an empty array', function () { expect(spec.getUserSyncs({ pixelEnabled: false }, bidResponse)).to.have.length(0); expect(spec.getUserSyncs({ pixelEnabled: true }, [])).to.have.length(0); }); }) - describe('_getPlatform', () => { - it('should return mobile', () => { + describe('_getPlatform', function () { + it('should return mobile', function () { expect(_getPlatform({innerWidth: 767})).to.equal('mobile') }) - it('should return tablet', () => { + it('should return tablet', function () { expect(_getPlatform({innerWidth: 800})).to.equal('tablet') }) - it('should return desktop', () => { + it('should return desktop', function () { expect(_getPlatform({innerWidth: 1000})).to.equal('desktop') }) }) diff --git a/test/spec/modules/sortableBidAdapter_spec.js b/test/spec/modules/sortableBidAdapter_spec.js index 6f1c9efba84..98695f44ee0 100644 --- a/test/spec/modules/sortableBidAdapter_spec.js +++ b/test/spec/modules/sortableBidAdapter_spec.js @@ -1,15 +1,14 @@ import { expect } from 'chai'; import { spec } from 'modules/sortableBidAdapter'; import { newBidder } from 'src/adapters/bidderFactory'; -import { REPO_AND_VERSION } from 'src/constants'; import * as utils from 'src/utils'; -const ENDPOINT = `//c.deployads.com/openrtb2/auction?src=${REPO_AND_VERSION}&host=${utils.getTopWindowLocation().host}`; +const ENDPOINT = `//c.deployads.com/openrtb2/auction?src=$$REPO_AND_VERSION$$&host=${utils.getTopWindowLocation().host}`; describe('sortableBidAdapter', function() { const adapter = newBidder(spec); - describe('isBidRequestValid', () => { + describe('isBidRequestValid', function () { function makeBid() { return { 'bidder': 'sortable', @@ -35,35 +34,35 @@ describe('sortableBidAdapter', function() { }; } - it('should return true when required params found', () => { + it('should return true when required params found', function () { expect(spec.isBidRequestValid(makeBid())).to.equal(true); }); - it('should return false when tagId not passed correctly', () => { + it('should return false when tagId not passed correctly', function () { let bid = makeBid(); delete bid.params.tagId; expect(spec.isBidRequestValid(bid)).to.equal(false); }); - it('should return false when sizes not passed correctly', () => { + it('should return false when sizes not passed correctly', function () { let bid = makeBid(); delete bid.sizes; expect(spec.isBidRequestValid(bid)).to.equal(false); }); - it('should return false when sizes are wrong length', () => { + it('should return false when sizes are wrong length', function () { let bid = makeBid(); bid.sizes = [[300]]; expect(spec.isBidRequestValid(bid)).to.equal(false); }); - it('should return false when require params are not passed', () => { + it('should return false when require params are not passed', function () { let bid = makeBid(); bid.params = {}; expect(spec.isBidRequestValid(bid)).to.equal(false); }); - it('should return false when the floorSizeMap is invalid', () => { + it('should return false when the floorSizeMap is invalid', function () { let bid = makeBid(); bid.params.floorSizeMap = { 'sixforty by foureighty': 1234 @@ -77,14 +76,14 @@ describe('sortableBidAdapter', function() { expect(spec.isBidRequestValid(bid)).to.equal(false); }); - it('should return true when the floorSizeMap is missing or empty', () => { + it('should return true when the floorSizeMap is missing or empty', function () { let bid = makeBid(); bid.params.floorSizeMap = {}; expect(spec.isBidRequestValid(bid)).to.equal(true); delete bid.params.floorSizeMap; expect(spec.isBidRequestValid(bid)).to.equal(true); }); - it('should return false when the keywords are invalid', () => { + it('should return false when the keywords are invalid', function () { let bid = makeBid(); bid.params.keywords = { 'badval': 1234 @@ -94,7 +93,7 @@ describe('sortableBidAdapter', function() { expect(spec.isBidRequestValid(bid)).to.equal(false); }); - it('should return true when the keywords are missing or empty', () => { + it('should return true when the keywords are missing or empty', function () { let bid = makeBid(); bid.params.keywords = {}; expect(spec.isBidRequestValid(bid)).to.equal(true); @@ -103,7 +102,7 @@ describe('sortableBidAdapter', function() { }); }); - describe('buildRequests', () => { + describe('buildRequests', function () { const bidRequests = [{ 'bidder': 'sortable', 'params': { @@ -130,25 +129,25 @@ describe('sortableBidAdapter', function() { const request = spec.buildRequests(bidRequests); const requestBody = JSON.parse(request.data); - it('sends bid request to our endpoint via POST', () => { + it('sends bid request to our endpoint via POST', function () { expect(request.method).to.equal('POST'); }); - it('attaches source and version to endpoint URL as query params', () => { + it('attaches source and version to endpoint URL as query params', function () { expect(request.url).to.equal(ENDPOINT); }); - it('sends screen dimensions', () => { + it('sends screen dimensions', function () { expect(requestBody.site.device.w).to.equal(screen.width); expect(requestBody.site.device.h).to.equal(screen.height); }); - it('includes the ad size in the bid request', () => { + it('includes the ad size in the bid request', function () { expect(requestBody.imp[0].banner.format[0].w).to.equal(300); expect(requestBody.imp[0].banner.format[0].h).to.equal(250); }); - it('includes the params in the bid request', () => { + it('includes the params in the bid request', function () { expect(requestBody.imp[0].ext.keywords).to.deep.equal( {'key1': 'val1', 'key2': 'val2'} @@ -158,7 +157,7 @@ describe('sortableBidAdapter', function() { expect(requestBody.imp[0].bidfloor).to.equal(0.21); }); - it('should have the floor size map set', () => { + it('should have the floor size map set', function () { expect(requestBody.imp[0].ext.floorSizeMap).to.deep.equal({ '728x90': 0.15, '300x250': 1.20 @@ -166,7 +165,7 @@ describe('sortableBidAdapter', function() { }); }); - describe('interpretResponse', () => { + describe('interpretResponse', function () { function makeResponse() { return { body: { @@ -208,13 +207,13 @@ describe('sortableBidAdapter', function() { 'ad': '
' }; - it('should get the correct bid response', () => { + it('should get the correct bid response', function () { let result = spec.interpretResponse(makeResponse()); expect(result.length).to.equal(1); expect(result[0]).to.deep.equal(expectedBid); }); - it('should handle a missing crid', () => { + it('should handle a missing crid', function () { let noCridResponse = makeResponse(); delete noCridResponse.body.seatbid[0].bid[0].crid; const fallbackCrid = noCridResponse.body.seatbid[0].bid[0].id; @@ -224,7 +223,7 @@ describe('sortableBidAdapter', function() { expect(result[0]).to.deep.equal(noCridResult); }); - it('should handle a missing nurl', () => { + it('should handle a missing nurl', function () { let noNurlResponse = makeResponse(); delete noNurlResponse.body.seatbid[0].bid[0].nurl; let noNurlResult = Object.assign({}, expectedBid); @@ -234,7 +233,7 @@ describe('sortableBidAdapter', function() { expect(result[0]).to.deep.equal(noNurlResult); }); - it('should handle a missing adm', () => { + it('should handle a missing adm', function () { let noAdmResponse = makeResponse(); delete noAdmResponse.body.seatbid[0].bid[0].adm; let noAdmResult = Object.assign({}, expectedBid); @@ -245,7 +244,7 @@ describe('sortableBidAdapter', function() { expect(result[0]).to.deep.equal(noAdmResult); }); - it('handles empty bid response', () => { + it('handles empty bid response', function () { let response = { body: { 'id': '5e5c23a5ba71e78', diff --git a/test/spec/modules/sovrnBidAdapter_spec.js b/test/spec/modules/sovrnBidAdapter_spec.js index dd3a43a3f0c..7179ec00bc3 100644 --- a/test/spec/modules/sovrnBidAdapter_spec.js +++ b/test/spec/modules/sovrnBidAdapter_spec.js @@ -1,14 +1,14 @@ import { expect } from 'chai'; -import { spec } from 'modules/sovrnBidAdapter'; +import { spec, LogError } from 'modules/sovrnBidAdapter'; import { newBidder } from 'src/adapters/bidderFactory'; -import { REPO_AND_VERSION } from 'src/constants'; +import { SSL_OP_SINGLE_ECDH_USE } from 'constants'; -const ENDPOINT = `//ap.lijit.com/rtb/bid?src=${REPO_AND_VERSION}`; +const ENDPOINT = `//ap.lijit.com/rtb/bid?src=$$REPO_AND_VERSION$$`; describe('sovrnBidAdapter', function() { const adapter = newBidder(spec); - describe('isBidRequestValid', () => { + describe('isBidRequestValid', function () { let bid = { 'bidder': 'sovrn', 'params': { @@ -16,30 +16,31 @@ describe('sovrnBidAdapter', function() { }, 'adUnitCode': 'adunit-code', 'sizes': [ - [300, 250] + [300, 250], + [300, 600] ], 'bidId': '30b31c1838de1e', 'bidderRequestId': '22edbae2733bf6', 'auctionId': '1d1a030790a475', }; - it('should return true when required params found', () => { + it('should return true when required params found', function () { expect(spec.isBidRequestValid(bid)).to.equal(true); }); - it('should return false when tagid not passed correctly', () => { + it('should return false when tagid not passed correctly', function () { bid.params.tagid = 'ABCD'; expect(spec.isBidRequestValid(bid)).to.equal(false); }); - it('should return false when require params are not passed', () => { + it('should return false when require params are not passed', function () { let bid = Object.assign({}, bid); bid.params = {}; expect(spec.isBidRequestValid(bid)).to.equal(false); }); }); - describe('buildRequests', () => { + describe('buildRequests', function () { const bidRequests = [{ 'bidder': 'sovrn', 'params': { @@ -47,7 +48,8 @@ describe('sovrnBidAdapter', function() { }, 'adUnitCode': 'adunit-code', 'sizes': [ - [300, 250] + [300, 250], + [300, 600] ], 'bidId': '30b31c1838de1e', 'bidderRequestId': '22edbae2733bf6', @@ -56,15 +58,42 @@ describe('sovrnBidAdapter', function() { const request = spec.buildRequests(bidRequests); - it('sends bid request to our endpoint via POST', () => { + it('sends bid request to our endpoint via POST', function () { expect(request.method).to.equal('POST'); }); - it('attaches source and version to endpoint URL as query params', () => { + it('attaches source and version to endpoint URL as query params', function () { expect(request.url).to.equal(ENDPOINT) }); - it('sends \'iv\' as query param if present', () => { + it('sets the proper banner object', function() { + const payload = JSON.parse(request.data); + expect(payload.imp[0].banner.format).to.deep.equal([{w: 300, h: 250}, {w: 300, h: 600}]) + expect(payload.imp[0].banner.w).to.equal(1) + expect(payload.imp[0].banner.h).to.equal(1) + }) + + it('accepts a single array as a size', function() { + const singleSize = [{ + 'bidder': 'sovrn', + 'params': { + 'tagid': '403370', + 'iv': 'vet' + }, + 'adUnitCode': 'adunit-code', + 'sizes': [300, 250], + 'bidId': '30b31c1838de1e', + 'bidderRequestId': '22edbae2733bf6', + 'auctionId': '1d1a030790a475' + }]; + const request = spec.buildRequests(singleSize) + const payload = JSON.parse(request.data) + expect(payload.imp[0].banner.format).to.deep.equal([{w: 300, h: 250}]) + expect(payload.imp[0].banner.w).to.equal(1) + expect(payload.imp[0].banner.h).to.equal(1) + }) + + it('sends \'iv\' as query param if present', function () { const ivBidRequests = [{ 'bidder': 'sovrn', 'params': { @@ -73,7 +102,8 @@ describe('sovrnBidAdapter', function() { }, 'adUnitCode': 'adunit-code', 'sizes': [ - [300, 250] + [300, 250], + [300, 600] ], 'bidId': '30b31c1838de1e', 'bidderRequestId': '22edbae2733bf6', @@ -84,7 +114,7 @@ describe('sovrnBidAdapter', function() { expect(request.url).to.contain('iv=vet') }); - it('sends gdpr info if exists', () => { + it('sends gdpr info if exists', function () { let consentString = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A=='; let bidderRequest = { 'bidderCode': 'sovrn', @@ -107,7 +137,7 @@ describe('sovrnBidAdapter', function() { expect(payload.user.ext.consent).to.equal(consentString); }); - it('converts tagid to string', () => { + it('converts tagid to string', function () { const ivBidRequests = [{ 'bidder': 'sovrn', 'params': { @@ -116,7 +146,8 @@ describe('sovrnBidAdapter', function() { }, 'adUnitCode': 'adunit-code', 'sizes': [ - [300, 250] + [300, 250], + [300, 600] ], 'bidId': '30b31c1838de1e', 'bidderRequestId': '22edbae2733bf6', @@ -128,9 +159,9 @@ describe('sovrnBidAdapter', function() { }) }); - describe('interpretResponse', () => { + describe('interpretResponse', function () { let response; - beforeEach(() => { + beforeEach(function () { response = { body: { 'id': '37386aade21a71', @@ -150,7 +181,7 @@ describe('sovrnBidAdapter', function() { }; }); - it('should get the correct bid response', () => { + it('should get the correct bid response', function () { let expectedResponse = [{ 'requestId': '263c448586f5a1', 'cpm': 0.45882675, @@ -169,7 +200,7 @@ describe('sovrnBidAdapter', function() { expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse[0])); }); - it('crid should default to the bid id if not on the response', () => { + it('crid should default to the bid id if not on the response', function () { delete response.body.seatbid[0].bid[0].crid; let expectedResponse = [{ 'requestId': '263c448586f5a1', @@ -189,7 +220,7 @@ describe('sovrnBidAdapter', function() { expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse[0])); }); - it('should get correct bid response when dealId is passed', () => { + it('should get correct bid response when dealId is passed', function () { response.body.dealid = 'baking'; let expectedResponse = [{ @@ -210,7 +241,7 @@ describe('sovrnBidAdapter', function() { expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse[0])); }); - it('handles empty bid response', () => { + it('handles empty bid response', function () { let response = { body: { 'id': '37386aade21a71', @@ -221,4 +252,146 @@ describe('sovrnBidAdapter', function() { expect(result.length).to.equal(0); }); }); -}); + + describe('getUserSyncs ', () => { + let syncOptions = {iframeEnabled: true, pixelEnabled: true}; + let iframeDisabledSyncOptions = {iframeEnabled: false, pixelEnabled: true}; + let serverResponse = [ + { + 'body': { + 'id': '546956d68c757f', + 'seatbid': [ + { + 'bid': [ + { + 'id': 'a_448326_16c2ada014224bee815a90d2248322f5', + 'impid': '2a3826aae345f4', + 'price': 1.0099999904632568, + 'nurl': 'http://localhost/rtb/impression?bannerid=220958&campaignid=3890&rtb_tid=15588614-75d2-40ab-b27e-13d2127b3c2e&rpid=1295&seatid=seat1&zoneid=448326&cb=26900712&tid=a_448326_16c2ada014224bee815a90d2248322f5', + 'adm': 'yo a creative', + 'crid': 'cridprebidrtb', + 'w': 160, + 'h': 600 + }, + { + 'id': 'a_430392_beac4c1515da4576acf6cb9c5340b40c', + 'impid': '3cf96fd26ed4c5', + 'price': 1.0099999904632568, + 'nurl': 'http://localhost/rtb/impression?bannerid=220957&campaignid=3890&rtb_tid=5bc0e68b-3492-448d-a6f9-26fa3fd0b646&rpid=1295&seatid=seat1&zoneid=430392&cb=62735099&tid=a_430392_beac4c1515da4576acf6cb9c5340b40c', + 'adm': 'yo a creative', + 'crid': 'cridprebidrtb', + 'w': 300, + 'h': 250 + }, + ] + } + ], + 'ext': { + 'iid': 13487408 + } + }, + 'headers': {} + } + ]; + it('should return if iid present on server response & iframe syncs enabled', () => { + let expectedReturnStatement = [ + { + 'type': 'iframe', + 'url': '//ap.lijit.com/beacon?informer=13487408&gdpr_consent=', + } + ] + let returnStatement = spec.getUserSyncs(syncOptions, serverResponse); + expect(returnStatement[0]).to.deep.equal(expectedReturnStatement[0]); + }) + + it('should not return if iid missing on server response', () => { + let returnStatement = spec.getUserSyncs(syncOptions, []) + expect(returnStatement).to.be.empty; + }) + + it('should not return if iframe syncs disabled', () => { + let returnStatement = spec.getUserSyncs(iframeDisabledSyncOptions, serverResponse) + expect(returnStatement).to.be.empty + }) + }) + describe('LogError', () => { + it('should build and append an error object', () => { + const thrown = { + message: 'message', + stack: 'stack' + } + const data = {name: 'Oscar Hathenswiotch'} + const err = new LogError(thrown, data) + err.append() + const errList = LogError.getErrPxls() + expect(errList.length).to.equal(1) + const errdata = JSON.parse(atob(errList[0].url.split('=')[1])) + expect(errdata.d.name).to.equal('Oscar Hathenswiotch') + }) + it('should drop data when there is too much', () => { + const thrown = { + message: 'message', + stack: 'stack' + } + const tooLong = () => { + let str = '' + for (let i = 0; i < 10000; i++) { + str = str + String.fromCharCode(i % 100) + } + return str + } + const data = {name: 'Oscar Hathenswiotch', tooLong: tooLong()} + const err = new LogError(thrown, data) + err.append() + const errList = LogError.getErrPxls() + expect(errList.length).to.equal(2) + const errdata = JSON.parse(atob(errList[1].url.split('=')[1])) + expect(errdata.d).to.be.an('undefined') + }) + it('should drop data and stack when there is too much', () => { + const thrown = { + message: 'message', + stack: 'stack' + } + const tooLong = () => { + let str = '' + for (let i = 0; i < 10000; i++) { + str = str + String.fromCharCode(i % 100) + } + return str + } + const data = {name: 'Oscar Hathenswiotch'} + thrown.stack = tooLong() + const err = new LogError(thrown, data) + err.append() + const errList = LogError.getErrPxls() + expect(errList.length).to.equal(3) + const errdata = JSON.parse(atob(errList[2].url.split('=')[1])) + expect(errdata.d).to.be.an('undefined') + expect(errdata.s).to.be.an('undefined') + }) + it('should drop send a reduced message when other reduction methods fail', () => { + const thrown = { + message: 'message', + stack: 'stack' + } + const tooLong = () => { + let str = '' + for (let i = 0; i < 10000; i++) { + str = str + String.fromCharCode(i % 100) + } + return str + } + const data = {name: 'Oscar Hathenswiotch'} + thrown.message = tooLong() + const err = new LogError(thrown, data) + err.append() + const errList = LogError.getErrPxls() + expect(errList.length).to.equal(4) + const errdata = JSON.parse(atob(errList[3].url.split('=')[1])) + expect(errdata.d).to.be.an('undefined') + expect(errdata.s).to.be.an('undefined') + expect(errdata.m).to.equal('unknown error message') + }) + }) +}) diff --git a/test/spec/modules/supply2BidAdapter_spec.js b/test/spec/modules/supply2BidAdapter_spec.js new file mode 100644 index 00000000000..8abbecd801c --- /dev/null +++ b/test/spec/modules/supply2BidAdapter_spec.js @@ -0,0 +1,332 @@ +import { expect } from 'chai'; +import { spec } from 'modules/supply2BidAdapter'; +import { newBidder } from 'src/adapters/bidderFactory'; + +describe('Supply2Adapter', 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('isBidRequestValid', function () { + let bid = { + 'bidder': 'supply2', + 'params': { + 'uid': '16' + }, + 'adUnitCode': 'adunit-code', + 'sizes': [[300, 250], [300, 600]], + 'bidId': '30b31c1838de1e', + 'bidderRequestId': '22edbae2733bf6', + 'auctionId': '1d1a030790a475', + }; + + it('should return true when required params found', function () { + expect(spec.isBidRequestValid(bid)).to.equal(true); + }); + + it('should return false when required params are not passed', function () { + let bid = Object.assign({}, bid); + delete bid.params; + bid.params = { + 'uid': 0 + }; + expect(spec.isBidRequestValid(bid)).to.equal(false); + }); + }); + + describe('buildRequests', function () { + function parseRequest(url) { + const res = {}; + url.split('&').forEach((it) => { + const couple = it.split('='); + res[couple[0]] = decodeURIComponent(couple[1]); + }); + return res; + } + let bidRequests = [ + { + 'bidder': 'supply2', + 'params': { + 'uid': '16' + }, + 'adUnitCode': 'adunit-code-1', + 'sizes': [[300, 250], [300, 600]], + 'bidId': '30b31c1838de1e', + 'bidderRequestId': '22edbae2733bf6', + 'auctionId': '1d1a030790a475', + }, + { + 'bidder': 'supply2', + 'params': { + 'uid': '16' + }, + 'adUnitCode': 'adunit-code-2', + 'sizes': [[728, 90]], + 'bidId': '3150ccb55da321', + 'bidderRequestId': '22edbae2733bf6', + 'auctionId': '1d1a030790a475', + }, + { + 'bidder': 'supply2', + 'params': { + 'uid': '17' + }, + 'adUnitCode': 'adunit-code-1', + 'sizes': [[300, 250], [300, 600]], + 'bidId': '42dbe3a7168a6a', + 'bidderRequestId': '22edbae2733bf6', + 'auctionId': '1d1a030790a475', + } + ]; + + it('should attach valid params to the tag', function () { + const request = spec.buildRequests([bidRequests[0]]); + expect(request.data).to.be.an('string'); + const payload = parseRequest(request.data); + expect(payload).to.have.property('u').that.is.a('string'); + expect(payload).to.have.property('pt', 'net'); + expect(payload).to.have.property('auids', '16'); + expect(payload).to.have.property('r', '22edbae2733bf6'); + }); + + it('auids must not be duplicated', function () { + const request = spec.buildRequests(bidRequests); + expect(request.data).to.be.an('string'); + const payload = parseRequest(request.data); + expect(payload).to.have.property('u').that.is.a('string'); + expect(payload).to.have.property('pt', 'net'); + expect(payload).to.have.property('auids', '16,17'); + expect(payload).to.have.property('r', '22edbae2733bf6'); + }); + + it('if timeout is present, payload must have wtimeout parameter', function () { + const request = spec.buildRequests(bidRequests, {timeout: 2000}); + expect(request.data).to.be.an('string'); + const payload = parseRequest(request.data); + expect(payload).to.have.property('wtimeout', '2000'); + }); + + it('pt parameter must be "gross" if params.priceType === "gross"', function () { + bidRequests[1].params.priceType = 'gross'; + const request = spec.buildRequests(bidRequests); + expect(request.data).to.be.an('string'); + const payload = parseRequest(request.data); + expect(payload).to.have.property('u').that.is.a('string'); + expect(payload).to.have.property('pt', 'gross'); + expect(payload).to.have.property('auids', '16,17'); + expect(payload).to.have.property('r', '22edbae2733bf6'); + delete bidRequests[1].params.priceType; + }); + + it('pt parameter must be "net" or "gross"', function () { + bidRequests[1].params.priceType = 'some'; + const request = spec.buildRequests(bidRequests); + expect(request.data).to.be.an('string'); + const payload = parseRequest(request.data); + expect(payload).to.have.property('u').that.is.a('string'); + expect(payload).to.have.property('pt', 'net'); + expect(payload).to.have.property('auids', '16,17'); + expect(payload).to.have.property('r', '22edbae2733bf6'); + delete bidRequests[1].params.priceType; + }); + + it('if gdprConsent is present payload must have gdpr params', function () { + const request = spec.buildRequests(bidRequests, {gdprConsent: {consentString: 'AAA', gdprApplies: true}}); + expect(request.data).to.be.an('string'); + const payload = parseRequest(request.data); + expect(payload).to.have.property('gdpr_consent', 'AAA'); + expect(payload).to.have.property('gdpr_applies', '1'); + }); + + it('if gdprApplies is false gdpr_applies must be 0', function () { + const request = spec.buildRequests(bidRequests, {gdprConsent: {consentString: 'AAA', gdprApplies: false}}); + expect(request.data).to.be.an('string'); + const payload = parseRequest(request.data); + expect(payload).to.have.property('gdpr_consent', 'AAA'); + expect(payload).to.have.property('gdpr_applies', '0'); + }); + + it('if gdprApplies is undefined gdpr_applies must be 1', function () { + const request = spec.buildRequests(bidRequests, {gdprConsent: {consentString: 'AAA'}}); + expect(request.data).to.be.an('string'); + const payload = parseRequest(request.data); + expect(payload).to.have.property('gdpr_consent', 'AAA'); + expect(payload).to.have.property('gdpr_applies', '1'); + }); + }); + + describe('interpretResponse', function () { + const responses = [ + {'bid': [{'price': 1.15, 'adm': '
test content 1
', 'auid': 23, 'h': 250, 'w': 300}], 'seat': '1'}, + {'bid': [{'price': 0.5, 'adm': '
test content 2
', 'auid': 24, 'h': 90, 'w': 728}], 'seat': '1'}, + {'bid': [{'price': 0, 'auid': 25, 'h': 250, 'w': 300}], 'seat': '1'}, + {'bid': [{'price': 0, 'adm': '
test content 4
', 'h': 250, 'w': 300}], 'seat': '1'}, + undefined, + {'bid': [], 'seat': '1'}, + {'seat': '1'}, + ]; + + it('should get correct bid response', function () { + const bidRequests = [ + { + 'bidder': 'supply2', + 'params': { + 'uid': '23' + }, + 'adUnitCode': 'adunit-code-1', + 'sizes': [[300, 250], [300, 600]], + 'bidId': '659423fff799cb', + 'bidderRequestId': '5f2009617a7c0a', + 'auctionId': '1cbd2feafe5e8b', + } + ]; + const request = spec.buildRequests(bidRequests); + const expectedResponse = [ + { + 'requestId': '659423fff799cb', + 'cpm': 1.15, + 'creativeId': 23, + 'dealId': undefined, + 'width': 300, + 'height': 250, + 'ad': '
test content 1
', + 'bidderCode': 'supply2', + 'currency': 'USD', + 'netRevenue': true, + 'ttl': 360, + } + ]; + + const result = spec.interpretResponse({'body': {'seatbid': [responses[0]]}}, request); + expect(result).to.deep.equal(expectedResponse); + }); + + it('should get correct multi bid response', function () { + const bidRequests = [ + { + 'bidder': 'supply2', + 'params': { + 'uid': '23' + }, + 'adUnitCode': 'adunit-code-1', + 'sizes': [[300, 250], [300, 600]], + 'bidId': '300bfeb0d71a5b', + 'bidderRequestId': '2c2bb1972df9a', + 'auctionId': '1fa09aee5c8c99', + }, + { + 'bidder': 'supply2', + 'params': { + 'uid': '24' + }, + 'adUnitCode': 'adunit-code-1', + 'sizes': [[300, 250], [300, 600]], + 'bidId': '4dff80cc4ee346', + 'bidderRequestId': '2c2bb1972df9a', + 'auctionId': '1fa09aee5c8c99', + }, + { + 'bidder': 'supply2', + 'params': { + 'uid': '23' + }, + 'adUnitCode': 'adunit-code-2', + 'sizes': [[728, 90]], + 'bidId': '5703af74d0472a', + 'bidderRequestId': '2c2bb1972df9a', + 'auctionId': '1fa09aee5c8c99', + } + ]; + const request = spec.buildRequests(bidRequests); + const expectedResponse = [ + { + 'requestId': '300bfeb0d71a5b', + 'cpm': 1.15, + 'creativeId': 23, + 'dealId': undefined, + 'width': 300, + 'height': 250, + 'ad': '
test content 1
', + 'bidderCode': 'supply2', + 'currency': 'USD', + 'netRevenue': true, + 'ttl': 360, + }, + { + 'requestId': '5703af74d0472a', + 'cpm': 1.15, + 'creativeId': 23, + 'dealId': undefined, + 'width': 300, + 'height': 250, + 'ad': '
test content 1
', + 'bidderCode': 'supply2', + 'currency': 'USD', + 'netRevenue': true, + 'ttl': 360, + }, + { + 'requestId': '4dff80cc4ee346', + 'cpm': 0.5, + 'creativeId': 24, + 'dealId': undefined, + 'width': 728, + 'height': 90, + 'ad': '
test content 2
', + 'bidderCode': 'supply2', + 'currency': 'USD', + 'netRevenue': true, + 'ttl': 360, + } + ]; + + const result = spec.interpretResponse({'body': {'seatbid': [responses[0], responses[1]]}}, request); + expect(result).to.deep.equal(expectedResponse); + }); + + it('handles wrong and nobid responses', function () { + const bidRequests = [ + { + 'bidder': 'supply2', + 'params': { + 'uid': '25' + }, + 'adUnitCode': 'adunit-code-1', + 'sizes': [[300, 250], [300, 600]], + 'bidId': '300bfeb0d7190gf', + 'bidderRequestId': '2c2bb1972d23af', + 'auctionId': '1fa09aee5c84d34', + }, + { + 'bidder': 'supply2', + 'params': { + 'uid': '26' + }, + 'adUnitCode': 'adunit-code-1', + 'sizes': [[300, 250], [300, 600]], + 'bidId': '300bfeb0d71321', + 'bidderRequestId': '2c2bb1972d23af', + 'auctionId': '1fa09aee5c84d34', + }, + { + 'bidder': 'supply2', + 'params': { + 'uid': '27' + }, + 'adUnitCode': 'adunit-code-2', + 'sizes': [[728, 90]], + 'bidId': '300bfeb0d7183bb', + 'bidderRequestId': '2c2bb1972d23af', + 'auctionId': '1fa09aee5c84d34', + } + ]; + const request = spec.buildRequests(bidRequests); + const result = spec.interpretResponse({'body': {'seatbid': responses.slice(2)}}, request); + expect(result.length).to.equal(0); + }); + }); +}); diff --git a/test/spec/modules/synacormediaBidAdapter_spec.js b/test/spec/modules/synacormediaBidAdapter_spec.js new file mode 100644 index 00000000000..9a95d1377e8 --- /dev/null +++ b/test/spec/modules/synacormediaBidAdapter_spec.js @@ -0,0 +1,198 @@ +import { assert, expect } from 'chai'; +import { BANNER } from 'src/mediaTypes'; +import { spec } from 'modules/synacormediaBidAdapter'; + +describe('synacormediaBidAdapter ', function () { + describe('isBidRequestValid', function () { + let bid; + beforeEach(function () { + bid = { + params: { + seatId: 'prebid', + placementId: '1234' + } + }; + }); + + it('should return true when params placementId and seatId are truthy', function () { + assert(spec.isBidRequestValid(bid)); + }); + + it('should return false when seatId param is missing', function () { + delete bid.params.seatId; + assert.isFalse(spec.isBidRequestValid(bid)); + }); + it('should return false when placementId param is missing', function () { + delete bid.params.placementId; + assert.isFalse(spec.isBidRequestValid(bid)); + }); + it('should return false when params is missing or null', function () { + assert.isFalse(spec.isBidRequestValid({ params: null })); + assert.isFalse(spec.isBidRequestValid({})); + assert.isFalse(spec.isBidRequestValid(null)); + }); + }); + describe('buildRequests', function () { + let validBidRequest = { + bidId: '9876abcd', + sizes: [[300, 250]], + params: { + seatId: 'prebid', + placementId: '1234' + } + }; + + let bidderRequest = { + auctionId: 'xyz123', + refererInfo: { + referer: 'https://test.com/foo/bar' + } + }; + + let expectedDataImp = { + banner: { + h: 250, + pos: 0, + w: 300, + }, + id: '9876abcd', + tagid: '1234' + }; + + it('should return valid request when valid bids are used', function () { + let req = spec.buildRequests([validBidRequest], bidderRequest); + expect(req).be.an('object'); + expect(req).to.have.property('method', 'POST'); + expect(req).to.have.property('url'); + expect(req.url).to.contain('//prebid.technoratimedia.com/openrtb/bids/prebid?'); + expect(req.data).to.exist.and.to.be.an('object'); + expect(req.data.id).to.equal('xyz123'); + expect(req.data.imp).to.eql([expectedDataImp]); + }); + + it('should return multiple bids when multiple valid requests with the same seatId are used', function () { + let secondBidRequest = { + bidId: 'foobar', + sizes: [[300, 600]], + params: { + seatId: validBidRequest.params.seatId, + placementId: '5678' + } + }; + let req = spec.buildRequests([validBidRequest, secondBidRequest], bidderRequest); + expect(req).to.exist.and.be.an('object'); + expect(req).to.have.property('method', 'POST'); + expect(req).to.have.property('url'); + expect(req.url).to.contain('//prebid.technoratimedia.com/openrtb/bids/prebid?'); + expect(req.data.id).to.equal('xyz123'); + expect(req.data.imp).to.eql([expectedDataImp, { + banner: { + h: 600, + pos: 0, + w: 300, + }, + id: 'foobar', + tagid: '5678' + }]); + }); + + it('should return only first bid when different seatIds are used', function () { + let mismatchedSeatBidRequest = { + bidId: 'foobar', + sizes: [[300, 250]], + params: { + seatId: 'somethingelse', + placementId: '5678' + } + }; + let req = spec.buildRequests([mismatchedSeatBidRequest, validBidRequest], bidderRequest); + expect(req).to.have.property('method', 'POST'); + expect(req).to.have.property('url'); + expect(req.url).to.contain('//prebid.technoratimedia.com/openrtb/bids/somethingelse?'); + expect(req.data.id).to.equal('xyz123'); + expect(req.data.imp).to.eql([ + { + banner: { + h: 250, + pos: 0, + w: 300, + }, + id: 'foobar', + tagid: '5678' + } + ]); + }); + + it('should not return a request when no valid bid request used', function () { + expect(spec.buildRequests([], bidderRequest)).to.be.undefined; + expect(spec.buildRequests([validBidRequest], null)).to.be.undefined; + }); + }); + + describe('interpretResponse', function () { + let bidResponse = { + id: '10865933907263896~9998~0', + impid: '9876abcd', + price: 0.13, + crid: '1022-250', + adm: '' + }; + spec.sizeMap['9876abcd'] = [300, 250]; + + let serverResponse; + beforeEach(function() { + serverResponse = { + body: { + id: 'abc123', + seatbid: [{ + seat: '9998', + bid: [], + }] + } + }; + }); + it('should return a bid when bid is in the response', function () { + serverResponse.body.seatbid[0].bid.push(bidResponse); + let resp = spec.interpretResponse(serverResponse); + expect(resp).to.be.an('array').that.is.not.empty; + expect(resp[0]).to.eql({ + requestId: '9876abcd', + cpm: 0.13, + width: 300, + height: 250, + creativeId: '9998~1022-250', + currency: 'USD', + netRevenue: true, + mediaType: BANNER, + ad: '', + ttl: 60 + }); + }); + it('should not return a bid when no bid is in the response', function () { + let resp = spec.interpretResponse(serverResponse); + expect(resp).to.be.an('array').that.is.empty; + }); + it('should not return a bid when there is no response body', function () { + expect(spec.interpretResponse({ body: null })).to.not.exist; + expect(spec.interpretResponse({ body: 'some error text' })).to.not.exist; + }); + }); + describe('getUserSyncs', function () { + it('should return a usersync when iframes is enabled', function () { + let usersyncs = spec.getUserSyncs({ + iframeEnabled: true + }, null); + expect(usersyncs).to.be.an('array').that.is.not.empty; + expect(usersyncs[0]).to.have.property('type', 'iframe'); + expect(usersyncs[0]).to.have.property('url'); + expect(usersyncs[0].url).to.contain('//prebid.technoratimedia.com/usersync/html'); + }); + + it('should not return a usersync when iframes are not enabled', function () { + let usersyncs = spec.getUserSyncs({ + pixelEnabled: true + }, null); + expect(usersyncs).to.be.an('array').that.is.empty; + }); + }); +}); diff --git a/test/spec/modules/taphypeBidAdapter_spec.js b/test/spec/modules/taphypeBidAdapter_spec.js new file mode 100644 index 00000000000..2fcdd964520 --- /dev/null +++ b/test/spec/modules/taphypeBidAdapter_spec.js @@ -0,0 +1,56 @@ +import { expect } from 'chai'; +import { spec } from 'modules/taphypeBidAdapter'; + +describe('taphypeBidAdapterTests', function () { + it('validate_pub_params', function () { + expect(spec.isBidRequestValid({ + bidder: 'taphype', + params: { + placementId: 12345 + } + })).to.equal(true); + }); + + it('validate_generated_params', function () { + let bidRequestData = [{ + bidId: 'bid12345', + bidder: 'taphype', + params: { + placementId: 12345 + }, + sizes: [[300, 250]] + }]; + + let request = spec.buildRequests(bidRequestData); + let req_data = request[0].data; + + expect(req_data.bidId).to.equal('bid12345'); + }); + + it('validate_response_params', function () { + let bidRequestData = { + data: { + bidId: 'bid12345' + } + }; + + let serverResponse = { + body: { + price: 1.23, + ad: '', + size: '300,250' + } + }; + + let bids = spec.interpretResponse(serverResponse, bidRequestData); + expect(bids).to.have.lengthOf(1); + let bid = bids[0]; + expect(bid.cpm).to.equal(1.23); + expect(bid.currency).to.equal('USD'); + expect(bid.width).to.equal('300'); + expect(bid.height).to.equal('250'); + expect(bid.netRevenue).to.equal(true); + expect(bid.requestId).to.equal('bid12345'); + expect(bid.ad).to.equal(''); + }); +}); diff --git a/test/spec/modules/teadsBidAdapter_spec.js b/test/spec/modules/teadsBidAdapter_spec.js new file mode 100644 index 00000000000..20fdbe947c0 --- /dev/null +++ b/test/spec/modules/teadsBidAdapter_spec.js @@ -0,0 +1,309 @@ +import {expect} from 'chai'; +import {spec} from 'modules/teadsBidAdapter'; +import {newBidder} from 'src/adapters/bidderFactory'; + +const ENDPOINT = '//a.teads.tv/hb/bid-request'; +const AD_SCRIPT = '"'; + +describe('teadsBidAdapter', 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('isBidRequestValid', function() { + let bid = { + 'bidder': 'teads', + 'params': { + 'placementId': 10433394, + 'pageId': 1234 + }, + 'adUnitCode': 'adunit-code', + 'sizes': [[300, 250], [300, 600]], + 'bidId': '30b31c1838de1e', + 'bidderRequestId': '22edbae2733bf6', + 'auctionId': '1d1a030790a475', + 'creativeId': 'er2ee' + }; + + it('should return true when required params found', function() { + expect(spec.isBidRequestValid(bid)).to.equal(true); + }); + + it('should return false when pageId is not valid (letters)', function() { + let bid = Object.assign({}, bid); + delete bid.params; + bid.params = { + 'placementId': 1234, + 'pageId': 'ABCD' + }; + + expect(spec.isBidRequestValid(bid)).to.equal(false); + }); + + it('should return false when placementId is not valid (letters)', function() { + let bid = Object.assign({}, bid); + delete bid.params; + bid.params = { + 'placementId': 'FCP', + 'pageId': 1234 + }; + + expect(spec.isBidRequestValid(bid)).to.equal(false); + }); + + it('should return false when placementId < 0 or pageId < 0', function() { + let bid = Object.assign({}, bid); + delete bid.params; + bid.params = { + 'placementId': -1, + 'pageId': -1 + }; + + expect(spec.isBidRequestValid(bid)).to.equal(false); + }); + + it('should return false when required params are not passed', function() { + let bid = Object.assign({}, bid); + delete bid.params; + + bid.params = { + 'placementId': 0 + }; + + expect(spec.isBidRequestValid(bid)).to.equal(false); + }); + }); + + describe('buildRequests', function() { + let bidRequests = [ + { + 'bidder': 'teads', + 'params': { + 'placementId': 10433394, + 'pageId': 1234 + }, + 'adUnitCode': 'adunit-code', + 'sizes': [[300, 250], [300, 600]], + 'bidId': '30b31c1838de1e', + 'bidderRequestId': '22edbae2733bf6', + 'auctionId': '1d1a030790a475', + 'creativeId': 'er2ee', + 'deviceWidth': 1680 + } + ]; + + let bidderResquestDefault = { + 'auctionId': '1d1a030790a475', + 'bidderRequestId': '22edbae2733bf6', + 'timeout': 3000 + }; + + it('sends bid request to ENDPOINT via POST', function() { + const request = spec.buildRequests(bidRequests, bidderResquestDefault); + + expect(request.url).to.equal(ENDPOINT); + expect(request.method).to.equal('POST'); + }); + + it('should send GDPR to endpoint', function() { + let consentString = 'JRJ8RKfDeBNsERRDCSAAZ+A=='; + let bidderRequest = { + 'auctionId': '1d1a030790a475', + 'bidderRequestId': '22edbae2733bf6', + 'timeout': 3000, + 'gdprConsent': { + 'consentString': consentString, + 'gdprApplies': true, + 'vendorData': { + 'hasGlobalConsent': false + } + } + }; + + const request = spec.buildRequests(bidRequests, bidderRequest); + const payload = JSON.parse(request.data); + + expect(payload.gdpr_iab).to.exist; + expect(payload.gdpr_iab.consent).to.equal(consentString); + expect(payload.gdpr_iab.status).to.equal(12); + }); + + it('should send GDPR to endpoint with 11 status', function() { + let consentString = 'JRJ8RKfDeBNsERRDCSAAZ+A=='; + let bidderRequest = { + 'auctionId': '1d1a030790a475', + 'bidderRequestId': '22edbae2733bf6', + 'timeout': 3000, + 'gdprConsent': { + 'consentString': consentString, + 'gdprApplies': true, + 'vendorData': { + 'hasGlobalScope': true + } + } + }; + + const request = spec.buildRequests(bidRequests, bidderRequest); + const payload = JSON.parse(request.data); + + expect(payload.gdpr_iab).to.exist; + expect(payload.gdpr_iab.consent).to.equal(consentString); + expect(payload.gdpr_iab.status).to.equal(11); + }); + + it('should send GDPR to endpoint with 22 status', function() { + let consentString = 'JRJ8RKfDeBNsERRDCSAAZ+A=='; + let bidderRequest = { + 'auctionId': '1d1a030790a475', + 'bidderRequestId': '22edbae2733bf6', + 'timeout': 3000, + 'gdprConsent': { + 'consentString': undefined, + 'gdprApplies': undefined, + 'vendorData': undefined + } + }; + + const request = spec.buildRequests(bidRequests, bidderRequest); + const payload = JSON.parse(request.data); + + expect(payload.gdpr_iab).to.exist; + expect(payload.gdpr_iab.consent).to.equal(''); + expect(payload.gdpr_iab.status).to.equal(22); + }); + + it('should send GDPR to endpoint with 0 status', function() { + let consentString = 'JRJ8RKfDeBNsERRDCSAAZ+A=='; + let bidderRequest = { + 'auctionId': '1d1a030790a475', + 'bidderRequestId': '22edbae2733bf6', + 'timeout': 3000, + 'gdprConsent': { + 'consentString': consentString, + 'gdprApplies': false, + 'vendorData': { + 'hasGlobalScope': false + } + } + }; + + const request = spec.buildRequests(bidRequests, bidderRequest); + const payload = JSON.parse(request.data); + + expect(payload.gdpr_iab).to.exist; + expect(payload.gdpr_iab.consent).to.equal(consentString); + expect(payload.gdpr_iab.status).to.equal(0); + }); + + it('should use good mediaTypes video playerSizes', function() { + const mediaTypesPlayerSize = { + 'mediaTypes': { + 'video': { + 'playerSize': [32, 34] + } + } + }; + checkMediaTypesSizes(mediaTypesPlayerSize, '32x34') + }); + + it('should use good mediaTypes video sizes', function() { + const mediaTypesVideoSizes = { + 'mediaTypes': { + 'video': { + 'sizes': [12, 14] + } + } + }; + checkMediaTypesSizes(mediaTypesVideoSizes, '12x14') + }); + + it('should use good mediaTypes banner sizes', function() { + const mediaTypesBannerSize = { + 'mediaTypes': { + 'banner': { + 'sizes': [46, 48] + } + } + }; + checkMediaTypesSizes(mediaTypesBannerSize, '46x48') + }); + + it('should use good mediaTypes for both video and banner sizes', function() { + const hybridMediaTypes = { + 'mediaTypes': { + 'banner': { + 'sizes': [46, 48] + }, + 'video': { + 'sizes': [[50, 34], [45, 45]] + } + } + }; + checkMediaTypesSizes(hybridMediaTypes, ['46x48', '50x34', '45x45']) + }); + + function checkMediaTypesSizes(mediaTypes, expectedSizes) { + const bidRequestWithBannerSizes = Object.assign(bidRequests[0], mediaTypes); + const requestWithBannerSizes = spec.buildRequests([bidRequestWithBannerSizes], bidderResquestDefault); + const payloadWithBannerSizes = JSON.parse(requestWithBannerSizes.data); + + return payloadWithBannerSizes.data.forEach(bid => { + if (Array.isArray(expectedSizes)) { + expect(JSON.stringify(bid.sizes)).to.equal(JSON.stringify(expectedSizes)); + } else { + expect(bid.sizes[0]).to.equal(expectedSizes); + } + }); + } + }); + + describe('interpretResponse', function() { + let bids = { + 'body': { + 'responses': [{ + 'ad': AD_SCRIPT, + 'cpm': 0.5, + 'currency': 'USD', + 'height': 250, + 'netRevenue': true, + 'requestId': '3ede2a3fa0db94', + 'ttl': 360, + 'width': 300, + 'creativeId': 'er2ee' + }] + } + }; + + it('should get correct bid response', function() { + let expectedResponse = [{ + 'cpm': 0.5, + 'width': 300, + 'height': 250, + 'currency': 'USD', + 'netRevenue': true, + 'ttl': 360, + 'ad': AD_SCRIPT, + 'requestId': '3ede2a3fa0db94', + 'creativeId': 'er2ee' + }]; + + let result = spec.interpretResponse(bids); + expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse[0])); + }); + + it('handles nobid responses', function() { + let bids = { + 'body': { + 'responses': [] + } + }; + + let result = spec.interpretResponse(bids); + expect(result.length).to.equal(0); + }); + }); +}); diff --git a/test/spec/modules/telariaBidAdapter_spec.js b/test/spec/modules/telariaBidAdapter_spec.js index 2483ec70e76..88b61844ea4 100644 --- a/test/spec/modules/telariaBidAdapter_spec.js +++ b/test/spec/modules/telariaBidAdapter_spec.js @@ -8,7 +8,12 @@ const SUPPLY_CODE = 'ssp-demo-rm6rh'; const SIZES = [640, 480]; const REQUEST = { 'code': 'video1', - 'sizes': [640, 480], + 'mediaTypes': { + 'video': { + 'playerSize': [[640, 480]], + 'context': 'instream' + } + }, 'mediaType': 'video', 'bids': [{ 'bidder': 'tremor', @@ -19,6 +24,12 @@ const REQUEST = { }] }; +const BIDDER_REQUEST = { + 'refererInfo': { + 'referer': 'www.test.com' + } +}; + const RESPONSE = { 'cur': 'USD', 'id': '3dba13e35f3d42f998bc7e65fd871889', @@ -73,8 +84,13 @@ describe('TelariaAdapter', () => { describe('buildRequests', () => { const stub = [{ + mediaTypes: { + video: { + playerSize: [[640, 480]], + context: 'instream' + } + }, bidder: 'tremor', - sizes: [[300, 250], [300, 600]], params: { supplyCode: 'ssp-demo-rm6rh', adCode: 'ssp-!demo!-lufip', @@ -86,13 +102,13 @@ describe('TelariaAdapter', () => { expect(spec.buildRequests).to.exist.and.to.be.a('function'); }); - it('requires supply code, ad code and sizes to make a request', () => { - const tempRequest = spec.buildRequests(stub); + it('requires supply code & ad code to make a request', () => { + const tempRequest = spec.buildRequests(stub, BIDDER_REQUEST); expect(tempRequest.length).to.equal(1); }); it('generates an array of requests with 4 params, method, url, bidId and vastUrl', () => { - const tempRequest = spec.buildRequests(stub); + const tempRequest = spec.buildRequests(stub, BIDDER_REQUEST); expect(tempRequest.length).to.equal(1); expect(tempRequest[0].method).to.equal('GET'); @@ -101,18 +117,21 @@ describe('TelariaAdapter', () => { expect(tempRequest[0].vastUrl).to.exist; }); - it('requires sizes to make a request', () => { + it('doesn\'t require player size but is highly recommended', () => { let tempBid = stub; - tempBid[0].sizes = null; - const tempRequest = spec.buildRequests(tempBid); + tempBid[0].mediaTypes.video.playerSize = null; + const tempRequest = spec.buildRequests(tempBid, BIDDER_REQUEST); - expect(tempRequest.length).to.equal(0); + expect(tempRequest.length).to.equal(1); }); it('generates a valid request with sizes as an array of two elements', () => { let tempBid = stub; - tempBid[0].sizes = [640, 480]; - expect(spec.buildRequests(tempBid).length).to.equal(1); + tempBid[0].mediaTypes.video.playerSize = [640, 480]; + tempBid[0].params.adCode = 'ssp-!demo!-lufip'; + tempBid[0].params.supplyCode = 'ssp-demo-rm6rh'; + let builtRequests = spec.buildRequests(tempBid, BIDDER_REQUEST); + expect(builtRequests.length).to.equal(1); }); it('requires ad code and supply code to make a request', () => { @@ -120,7 +139,7 @@ describe('TelariaAdapter', () => { tempBid[0].params.adCode = null; tempBid[0].params.supplyCode = null; - const tempRequest = spec.buildRequests(tempBid); + const tempRequest = spec.buildRequests(tempBid, BIDDER_REQUEST); expect(tempRequest.length).to.equal(0); }); @@ -129,8 +148,13 @@ describe('TelariaAdapter', () => { describe('interpretResponse', () => { const responseStub = RESPONSE; const stub = [{ + mediaTypes: { + video: { + playerSize: [[640, 480]], + context: 'instream' + } + }, bidder: 'tremor', - sizes: [[300, 250], [300, 600]], params: { supplyCode: 'ssp-demo-rm6rh', adCode: 'ssp-!demo!-lufip', @@ -143,7 +167,7 @@ describe('TelariaAdapter', () => { 'getStatusCode', 'getSize', 'requestId', 'cpm', 'creativeId', 'vastXml', 'vastUrl', 'currency', 'netRevenue', 'ttl', 'ad']; - let bidRequest = spec.buildRequests(stub)[0]; + let bidRequest = spec.buildRequests(stub, BIDDER_REQUEST)[0]; bidRequest.bidId = '1234'; let result = spec.interpretResponse({body: responseStub}, bidRequest); expect(Object.keys(result[0])).to.have.members(expectedResponseKeys); @@ -153,7 +177,7 @@ describe('TelariaAdapter', () => { let tempResponse = responseStub; tempResponse.seatbid = []; - let bidRequest = spec.buildRequests(stub)[0]; + let bidRequest = spec.buildRequests(stub, BIDDER_REQUEST)[0]; bidRequest.bidId = '1234'; let result = spec.interpretResponse({body: tempResponse}, bidRequest); diff --git a/test/spec/modules/trafficrootsBidAdapter_spec.js b/test/spec/modules/trafficrootsBidAdapter_spec.js new file mode 100644 index 00000000000..40d549e4a5a --- /dev/null +++ b/test/spec/modules/trafficrootsBidAdapter_spec.js @@ -0,0 +1,149 @@ +import { expect } from 'chai'; +import { spec } from 'modules/trafficrootsBidAdapter'; + +describe('trafficrootsAdapterTests', () => { + describe('bidRequestValidity', () => { + it('bidRequest with zoneId and deliveryUrl params', () => { + expect(spec.isBidRequestValid({ + bidder: 'trafficroots', + params: { + zoneId: 'aa0444af31', + deliveryUrl: 'https://service.trafficroosts.com/prebid' + } + })).to.equal(true); + }); + + it('bidRequest with only zoneId', () => { + expect(spec.isBidRequestValid({ + bidder: 'trafficroots', + params: { + zoneId: '8f527a4835' + } + })).to.equal(true); + }); + + it('bidRequest with only deliveryUrl', () => { + expect(spec.isBidRequestValid({ + bidder: 'trafficroots', + params: { + deliveryUrl: 'https://service.trafficroosts.com/prebid' + } + })).to.equal(false); + }); + }); + + describe('bidRequest', () => { + const bidRequests = [{ + 'bidder': 'trafficroots', + 'bidId': '29fa5c08928bde', + 'params': { + 'zoneId': 'aa0444af31', + }, + 'adUnitCode': 'div-gpt-ad-1460505748561-0', + 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', + 'sizes': [[300, 250], [300, 600]], + 'bidderRequestId': '418b37f85e772c', + 'auctionId': '18fd8b8b0bd757' + }, { + 'bidder': 'trafficroots', + 'bidId': '29fa5c08928bde', + 'params': { + 'zoneId': '8f527a4835', + 'deliveryUrl': 'https://service.trafficroosts.com/prebid' + }, + 'adUnitCode': 'div-gpt-ad-1460505748561-0', + 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', + 'sizes': [[300, 250], [300, 600]], + 'bidderRequestId': '418b37f85e772c', + 'auctionId': '18fd8b8b0bd757' + }]; + + it('bidRequest method', () => { + const request = spec.buildRequests(bidRequests); + expect(request.method).to.equal('GET'); + }); + + it('bidRequest url', () => { + const request = spec.buildRequests(bidRequests); + expect(request.url).to.match(new RegExp(`${bidRequests[1].params.deliveryUrl}`)); + }); + + it('bidRequest data', () => { + const request = spec.buildRequests(bidRequests); + expect(request.data).to.exists; + }); + + it('bidRequest zoneIds', () => { + const request = spec.buildRequests(bidRequests); + expect(request.data.zoneId).to.equal('aa0444af31;8f527a4835'); + }); + + it('bidRequest gdpr consent', () => { + const consentString = 'consentString'; + const bidderRequest = { + bidderCode: 'trafficroots', + auctionId: '18fd8b8b0bd757', + bidderRequestId: '418b37f85e772c', + timeout: 3000, + gdprConsent: { + consentString: consentString, + gdprApplies: true + } + }; + + const request = spec.buildRequests(bidRequests, bidderRequest); + + expect(request.data.gdpr).to.exist; + expect(request.data.gdpr.applies).to.exist.and.to.be.true; + expect(request.data.gdpr.consent).to.exist.and.to.equal(consentString); + }); + }); + + describe('interpretResponse', () => { + const bidRequest = [{ + 'bidder': 'trafficroots', + 'bidId': '29fa5c08928bde', + 'params': { + 'zoneId': 'aa0444af31', + }, + 'adUnitCode': 'div-gpt-ad-1460505748561-0', + 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', + 'sizes': [[300, 250], [300, 600]], + 'bidderRequestId': '418b37f85e772c', + 'auctionId': '18fd8b8b0bd757' + }]; + + const bidResponse = { + body: [{ + 'id': 'div-gpt-ad-1460505748561-0', + 'ad': 'test ad', + 'width': 320, + 'height': 250, + 'cpm': 5.2 + }], + headers: {} + }; + + it('required keys', () => { + const result = spec.interpretResponse(bidResponse, bidRequest); + + let requiredKeys = [ + 'requestId', + 'creativeId', + 'adId', + 'cpm', + 'width', + 'height', + 'currency', + 'netRevenue', + 'ttl', + 'ad' + ]; + + let resultKeys = Object.keys(result[0]); + resultKeys.forEach(function(key) { + expect(requiredKeys.indexOf(key) !== -1).to.equal(true); + }); + }) + }); +}); diff --git a/test/spec/modules/trionBidAdapter_spec.js b/test/spec/modules/trionBidAdapter_spec.js index 559122a2772..805ae70a339 100644 --- a/test/spec/modules/trionBidAdapter_spec.js +++ b/test/spec/modules/trionBidAdapter_spec.js @@ -35,22 +35,24 @@ const TRION_BID_RESPONSE = { }; -describe('Trion adapter tests', () => { +describe('Trion adapter tests', function () { let adapter; - beforeEach(() => { + beforeEach(function () { // adapter = trionAdapter.createNew(); sinon.stub(document.body, 'appendChild'); }); - afterEach(() => document.body.appendChild.restore()); + afterEach(function () { + document.body.appendChild.restore(); + }); - describe('isBidRequestValid', () => { - it('should return true with correct params', () => { + describe('isBidRequestValid', function () { + it('should return true with correct params', function () { expect(spec.isBidRequestValid(TRION_BID)).to.equal(true); }); - it('should return false when params are missing', () => { + it('should return false when params are missing', function () { TRION_BID.params = {}; expect(spec.isBidRequestValid(TRION_BID)).to.equal(false); @@ -60,7 +62,7 @@ describe('Trion adapter tests', () => { }; }); - it('should return false when pubId is missing', () => { + it('should return false when pubId is missing', function () { TRION_BID.params = { sectionId: '2' }; @@ -72,7 +74,7 @@ describe('Trion adapter tests', () => { }; }); - it('should return false when sectionId is missing', () => { + it('should return false when sectionId is missing', function () { TRION_BID.params = { pubId: '1' }; @@ -85,20 +87,20 @@ describe('Trion adapter tests', () => { }); }); - describe('buildRequests', () => { - it('should return bids requests with empty params', () => { + describe('buildRequests', function () { + it('should return bids requests with empty params', function () { let bidRequests = spec.buildRequests([]); expect(bidRequests.length).to.equal(0); }); - it('should include the base bidrequest url', () => { + it('should include the base bidrequest url', function () { let bidRequests = spec.buildRequests(TRION_BID_REQUEST); let bidUrl = bidRequests[0].url; expect(bidUrl).to.include(BID_REQUEST_BASE_URL); }); - it('should call buildRequests with the correct required params', () => { + it('should call buildRequests with the correct required params', function () { let bidRequests = spec.buildRequests(TRION_BID_REQUEST); let bidUrlParams = bidRequests[0].data; @@ -107,7 +109,7 @@ describe('Trion adapter tests', () => { expect(bidUrlParams).to.include('sizes=300x250,300x600'); }); - it('should call buildRequests with the correct optional params', () => { + it('should call buildRequests with the correct optional params', function () { let params = TRION_BID_REQUEST[0].params; params.re = 1; let bidRequests = spec.buildRequests(TRION_BID_REQUEST); @@ -119,13 +121,13 @@ describe('Trion adapter tests', () => { }); }); - describe('interpretResponse', () => { - it('when there is no response do not bid', () => { + describe('interpretResponse', function () { + it('when there is no response do not bid', function () { let response = spec.interpretResponse(null, {bidRequest: TRION_BID}); expect(response).to.deep.equal([]); }); - it('when place bid is returned as false', () => { + it('when place bid is returned as false', function () { TRION_BID_RESPONSE.result.placeBid = false; let response = spec.interpretResponse({body: TRION_BID_RESPONSE}, {bidRequest: TRION_BID}); @@ -134,21 +136,21 @@ describe('Trion adapter tests', () => { TRION_BID_RESPONSE.result.placeBid = true; }); - it('when no cpm is in the response', () => { + it('when no cpm is in the response', function () { TRION_BID_RESPONSE.result.cpm = 0; let response = spec.interpretResponse({body: TRION_BID_RESPONSE}, {bidRequest: TRION_BID}); expect(response).to.deep.equal([]); TRION_BID_RESPONSE.result.cpm = 1; }); - it('when no ad is in the response', () => { + it('when no ad is in the response', function () { TRION_BID_RESPONSE.result.ad = null; let response = spec.interpretResponse({body: TRION_BID_RESPONSE}, {bidRequest: TRION_BID}); expect(response).to.deep.equal([]); TRION_BID_RESPONSE.result.ad = 'test'; }); - it('height and width are appropriately set', () => { + it('height and width are appropriately set', function () { let bidWidth = '1'; let bidHeight = '2'; TRION_BID_RESPONSE.result.width = bidWidth; @@ -160,7 +162,7 @@ describe('Trion adapter tests', () => { TRION_BID_RESPONSE.result.height = '250'; }); - it('cpm is properly set and transformed to cents', () => { + it('cpm is properly set and transformed to cents', function () { let bidCpm = 2; TRION_BID_RESPONSE.result.cpm = bidCpm * 100; let response = spec.interpretResponse({body: TRION_BID_RESPONSE}, {bidRequest: TRION_BID}); @@ -169,15 +171,15 @@ describe('Trion adapter tests', () => { }); }); - describe('getUserSyncs', () => { + describe('getUserSyncs', function () { const USER_SYNC_URL = 'https://in-appadvertising.com/api/userSync.html'; const BASE_KEY = '_trion_'; - beforeEach(() => { + beforeEach(function () { delete window.TR_INT_T; }); - it('trion int is included in bid url', () => { + it('trion int is included in bid url', function () { window.TR_INT_T = 'test_user_sync'; let userTag = encodeURIComponent(window.TR_INT_T); let bidRequests = spec.buildRequests(TRION_BID_REQUEST); @@ -186,7 +188,7 @@ describe('Trion adapter tests', () => { expect(bidUrlParams).to.include(userTag); }); - it('should register trion user script', () => { + it('should register trion user script', function () { let syncs = spec.getUserSyncs({iframeEnabled: true}); let url = utils.getTopWindowUrl(); let pubId = 1; @@ -195,7 +197,7 @@ describe('Trion adapter tests', () => { expect(syncs[0]).to.deep.equal({type: 'iframe', url: USER_SYNC_URL + syncString}); }); - it('should except posted messages from user sync script', () => { + it('should except posted messages from user sync script', function () { let testId = 'testId'; let message = BASE_KEY + 'userId=' + testId; setStorageData(BASE_KEY + 'int_t', null); @@ -204,7 +206,7 @@ describe('Trion adapter tests', () => { expect(newKey).to.equal(testId); }); - it('should not try to post messages not from trion', () => { + it('should not try to post messages not from trion', function () { let testId = 'testId'; let badId = 'badId'; let message = 'Not Trion: userId=' + testId; diff --git a/test/spec/modules/tripleliftBidAdapter_spec.js b/test/spec/modules/tripleliftBidAdapter_spec.js index ed343f1ebf9..171a97bafd9 100644 --- a/test/spec/modules/tripleliftBidAdapter_spec.js +++ b/test/spec/modules/tripleliftBidAdapter_spec.js @@ -2,19 +2,20 @@ import { expect } from 'chai'; import { tripleliftAdapterSpec } from 'modules/tripleliftBidAdapter'; import { newBidder } from 'src/adapters/bidderFactory'; import { deepClone } from 'src/utils'; +import prebid from '../../../package.json'; const ENDPOINT = document.location.protocol + '//tlx.3lift.com/header/auction?'; -describe('triplelift adapter', () => { +describe('triplelift adapter', function () { const adapter = newBidder(tripleliftAdapterSpec); - describe('inherited functions', () => { - it('exists and is a function', () => { + describe('inherited functions', function () { + it('exists and is a function', function () { expect(adapter.callBids).to.exist.and.to.be.a('function'); }); }); - describe('isBidRequestValid', () => { + describe('isBidRequestValid', function () { let bid = { bidder: 'triplelift', params: { @@ -28,11 +29,11 @@ describe('triplelift adapter', () => { 'auctionId': '1d1a030790a475', }; - it('should return true for valid bid request', () => { + it('should return true for valid bid request', function () { expect(tripleliftAdapterSpec.isBidRequestValid(bid)).to.equal(true); }); - it('should return true when required params found', () => { + it('should return true when required params found', function () { let bid = Object.assign({}, bid); delete bid.params; bid.params = { @@ -42,7 +43,7 @@ describe('triplelift adapter', () => { expect(tripleliftAdapterSpec.isBidRequestValid(bid)).to.equal(true); }); - it('should return false when required params are not passed', () => { + it('should return false when required params are not passed', function () { let bid = Object.assign({}, bid); delete bid.params; bid.params = { @@ -52,7 +53,7 @@ describe('triplelift adapter', () => { }); }); - describe('buildRequests', () => { + describe('buildRequests', function () { let bidRequests = [ { bidder: 'triplelift', @@ -68,19 +69,42 @@ describe('triplelift adapter', () => { } ]; - it('exists and is an object', () => { - const request = tripleliftAdapterSpec.buildRequests(bidRequests); + let bidderRequest = { + bidderCode: 'triplelift', + auctionId: 'a7ebcd1d-66ff-4b5c-a82c-6a21a6ee5a18', + bidderRequestId: '5c55612f99bc11', + bids: [ + { + imp_id: 0, + cpm: 1.062, + width: 300, + height: 250, + ad: 'ad-markup', + iurl: 'https://s.adroll.com/a/IYR/N36/IYRN366MFVDITBAGNNT5U6.jpg' + } + ], + refererInfo: { + referer: 'http://examplereferer.com' + }, + gdprConsent: { + consentString: 'BOONm0NOONm0NABABAENAa-AAAARh7______b9_3__7_9uz_Kv_K7Vf7nnG072lPVA9LTOQ6gEaY', + gdprApplies: true + } + }; + + it('exists and is an object', function () { + const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); expect(request).to.exist.and.to.be.a('object'); }); - it('should only parse sizes that are of the proper length and format', () => { - const request = tripleliftAdapterSpec.buildRequests(bidRequests); + it('should only parse sizes that are of the proper length and format', function () { + const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); expect(request.data.imp[0].banner.format).to.have.length(2); expect(request.data.imp[0].banner.format).to.deep.equal([{w: 300, h: 250}, {w: 300, h: 600}]); }); - it('should be a post request and populate the payload', () => { - const request = tripleliftAdapterSpec.buildRequests(bidRequests); + it('should be a post request and populate the payload', function () { + const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); const payload = request.data; expect(payload).to.exist; expect(payload.imp[0].tagid).to.equal('12345'); @@ -88,20 +112,19 @@ describe('triplelift adapter', () => { expect(payload.imp[0].banner.format).to.deep.equal([{w: 300, h: 250}, {w: 300, h: 600}]); }); - it('should return a query string for TL call', () => { - const request = tripleliftAdapterSpec.buildRequests(bidRequests); + it('should return a query string for TL call', function () { + const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); const url = request.url; expect(url).to.exist; expect(url).to.be.a('string'); expect(url).to.match(/(?:tlx.3lift.com\/header\/auction)/) expect(url).to.match(/(?:lib=prebid)/) - expect(url).to.match(/(?:prebid.version)/) - // expect(url).to.match(/(?:fe=)/) // - expect(url).to.match(/(?:referrer)/) - }) + expect(url).to.match(new RegExp('(?:' + prebid.version + ')')) + expect(url).to.match(/(?:referrer)/); + }); }); - describe('interpretResponse', () => { + describe('interpretResponse', function () { let response = { body: { bids: [ @@ -130,13 +153,16 @@ describe('triplelift adapter', () => { iurl: 'https://s.adroll.com/a/IYR/N36/IYRN366MFVDITBAGNNT5U6.jpg' } ], + refererInfo: { + referer: 'http://examplereferer.com' + }, gdprConsent: { - consentString: 'BOONm0NOONma-AAAARh7______b9_3__7_9uz_Kv_K7Vf7nnG072lPVOQ6gEaY', + consentString: 'BOONm0NOONm0NABABAENAa-AAAARh7______b9_3__7_9uz_Kv_K7Vf7nnG072lPVA9LTOQ6gEaY', gdprApplies: true } }; - it('should get correct bid response', () => { + it('should get correct bid response', function () { let expectedResponse = [ { requestId: '3db3773286ee59', @@ -156,7 +182,7 @@ describe('triplelift adapter', () => { expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])); }); - it('should return multile responses to support SRA', () => { + it('should return multile responses to support SRA', function () { let response = { body: { bids: [ @@ -201,6 +227,9 @@ describe('triplelift adapter', () => { iurl: 'https://s.adroll.com/a/IYR/N36/IYRN366MFVDITBAGNNT5U6.jpg' } ], + refererInfo: { + referer: 'http://examplereferer.com' + }, gdprConsent: { consentString: 'BOONm0NOONm0NABABAENAa-AAAARh7______b9_3__7_9uz_Kv_K7Vf7nnG072lPVA9LTOQ6gEaY', gdprApplies: true diff --git a/test/spec/modules/trustxBidAdapter_spec.js b/test/spec/modules/trustxBidAdapter_spec.js index 75405850d7a..9f2fdca6a99 100644 --- a/test/spec/modules/trustxBidAdapter_spec.js +++ b/test/spec/modules/trustxBidAdapter_spec.js @@ -5,13 +5,13 @@ import { newBidder } from 'src/adapters/bidderFactory'; describe('TrustXAdapter', function () { const adapter = newBidder(spec); - describe('inherited functions', () => { - it('exists and is a function', () => { + describe('inherited functions', function () { + it('exists and is a function', function () { expect(adapter.callBids).to.exist.and.to.be.a('function'); }); }); - describe('isBidRequestValid', () => { + describe('isBidRequestValid', function () { let bid = { 'bidder': 'trustx', 'params': { @@ -24,11 +24,11 @@ describe('TrustXAdapter', function () { 'auctionId': '1d1a030790a475', }; - it('should return true when required params found', () => { + it('should return true when required params found', function () { expect(spec.isBidRequestValid(bid)).to.equal(true); }); - it('should return false when required params are not passed', () => { + it('should return false when required params are not passed', function () { let bid = Object.assign({}, bid); delete bid.params; bid.params = { @@ -38,7 +38,15 @@ describe('TrustXAdapter', function () { }); }); - describe('buildRequests', () => { + describe('buildRequests', function () { + function parseRequest(url) { + const res = {}; + url.split('&').forEach((it) => { + const couple = it.split('='); + res[couple[0]] = decodeURIComponent(couple[1]); + }); + return res; + } let bidRequests = [ { 'bidder': 'trustx', @@ -75,31 +83,31 @@ describe('TrustXAdapter', function () { } ]; - it('should attach valid params to the tag', () => { + it('should attach valid params to the tag', function () { const request = spec.buildRequests([bidRequests[0]]); - const payload = request.data; - expect(payload).to.be.an('object'); + expect(request.data).to.be.an('string'); + const payload = parseRequest(request.data); expect(payload).to.have.property('u').that.is.a('string'); expect(payload).to.have.property('pt', 'net'); expect(payload).to.have.property('auids', '43'); expect(payload).to.have.property('r', '22edbae2733bf6'); }); - it('auids must not be duplicated', () => { + it('auids must not be duplicated', function () { const request = spec.buildRequests(bidRequests); - const payload = request.data; - expect(payload).to.be.an('object'); + expect(request.data).to.be.an('string'); + const payload = parseRequest(request.data); expect(payload).to.have.property('u').that.is.a('string'); expect(payload).to.have.property('pt', 'net'); expect(payload).to.have.property('auids', '43,45'); expect(payload).to.have.property('r', '22edbae2733bf6'); }); - it('pt parameter must be "gross" if params.priceType === "gross"', () => { + it('pt parameter must be "gross" if params.priceType === "gross"', function () { bidRequests[1].params.priceType = 'gross'; const request = spec.buildRequests(bidRequests); - const payload = request.data; - expect(payload).to.be.an('object'); + expect(request.data).to.be.an('string'); + const payload = parseRequest(request.data); expect(payload).to.have.property('u').that.is.a('string'); expect(payload).to.have.property('pt', 'gross'); expect(payload).to.have.property('auids', '43,45'); @@ -107,11 +115,11 @@ describe('TrustXAdapter', function () { delete bidRequests[1].params.priceType; }); - it('pt parameter must be "net" or "gross"', () => { + it('pt parameter must be "net" or "gross"', function () { bidRequests[1].params.priceType = 'some'; const request = spec.buildRequests(bidRequests); - const payload = request.data; - expect(payload).to.be.an('object'); + expect(request.data).to.be.an('string'); + const payload = parseRequest(request.data); expect(payload).to.have.property('u').that.is.a('string'); expect(payload).to.have.property('pt', 'net'); expect(payload).to.have.property('auids', '43,45'); @@ -119,32 +127,32 @@ describe('TrustXAdapter', function () { delete bidRequests[1].params.priceType; }); - it('if gdprConsent is present payload must have gdpr params', () => { + it('if gdprConsent is present payload must have gdpr params', function () { const request = spec.buildRequests(bidRequests, {gdprConsent: {consentString: 'AAA', gdprApplies: true}}); - const payload = request.data; - expect(payload).to.be.an('object'); + expect(request.data).to.be.an('string'); + const payload = parseRequest(request.data); expect(payload).to.have.property('gdpr_consent', 'AAA'); - expect(payload).to.have.property('gdpr_applies', 1); + expect(payload).to.have.property('gdpr_applies', '1'); }); - it('if gdprApplies is false gdpr_applies must be 0', () => { + it('if gdprApplies is false gdpr_applies must be 0', function () { const request = spec.buildRequests(bidRequests, {gdprConsent: {consentString: 'AAA', gdprApplies: false}}); - const payload = request.data; - expect(payload).to.be.an('object'); + expect(request.data).to.be.an('string'); + const payload = parseRequest(request.data); expect(payload).to.have.property('gdpr_consent', 'AAA'); - expect(payload).to.have.property('gdpr_applies', 0); + expect(payload).to.have.property('gdpr_applies', '0'); }); - it('if gdprApplies is undefined gdpr_applies must be 1', () => { + it('if gdprApplies is undefined gdpr_applies must be 1', function () { const request = spec.buildRequests(bidRequests, {gdprConsent: {consentString: 'AAA'}}); - const payload = request.data; - expect(payload).to.be.an('object'); + expect(request.data).to.be.an('string'); + const payload = parseRequest(request.data); expect(payload).to.have.property('gdpr_consent', 'AAA'); - expect(payload).to.have.property('gdpr_applies', 1); + expect(payload).to.have.property('gdpr_applies', '1'); }); }); - describe('interpretResponse', () => { + describe('interpretResponse', function () { const responses = [ {'bid': [{'price': 1.15, 'adm': '
test content 1
', 'auid': 43, 'h': 250, 'w': 300}], 'seat': '1'}, {'bid': [{'price': 0.5, 'adm': '
test content 2
', 'auid': 44, 'h': 90, 'w': 728}], 'seat': '1'}, @@ -155,7 +163,7 @@ describe('TrustXAdapter', function () { {'seat': '1'}, ]; - it('should get correct bid response', () => { + it('should get correct bid response', function () { const bidRequests = [ { 'bidder': 'trustx', @@ -190,7 +198,7 @@ describe('TrustXAdapter', function () { expect(result).to.deep.equal(expectedResponse); }); - it('should get correct multi bid response', () => { + it('should get correct multi bid response', function () { const bidRequests = [ { 'bidder': 'trustx', @@ -273,7 +281,7 @@ describe('TrustXAdapter', function () { expect(result).to.deep.equal(expectedResponse); }); - it('handles wrong and nobid responses', () => { + it('handles wrong and nobid responses', function () { const bidRequests = [ { 'bidder': 'trustx', diff --git a/test/spec/modules/ucfunnelBidAdapter_spec.js b/test/spec/modules/ucfunnelBidAdapter_spec.js index e8a4624bf16..32daf5ecb96 100644 --- a/test/spec/modules/ucfunnelBidAdapter_spec.js +++ b/test/spec/modules/ucfunnelBidAdapter_spec.js @@ -89,34 +89,34 @@ const validNativeBidRes = { width: 1 }; -describe('ucfunnel Adapter', () => { - describe('request', () => { - it('should validate bid request', () => { +describe('ucfunnel Adapter', function () { + describe('request', function () { + it('should validate bid request', function () { expect(spec.isBidRequestValid(validBannerBidReq)).to.equal(true); }); - it('should not validate incorrect bid request', () => { + it('should not validate incorrect bid request', function () { expect(spec.isBidRequestValid(invalidBannerBidReq)).to.equal(false); }); }); - describe('build request', () => { + describe('build request', function () { const request = spec.buildRequests([validBannerBidReq]); - it('should create a POST request for every bid', () => { + it('should create a POST request for every bid', function () { expect(request[0].method).to.equal('GET'); expect(request[0].url).to.equal(location.protocol + spec.ENDPOINT); }); - it('should attach the bid request object', () => { + it('should attach the bid request object', function () { expect(request[0].bidRequest).to.equal(validBannerBidReq); }); - it('should attach request data', () => { + it('should attach request data', function () { const data = request[0].data; const [ width, height ] = validBannerBidReq.sizes[0]; expect(data.w).to.equal(width); expect(data.h).to.equal(height); }); - it('must parse bid size from a nested array', () => { + it('must parse bid size from a nested array', function () { const width = 640; const height = 480; validBannerBidReq.sizes = [[ width, height ]]; @@ -127,15 +127,15 @@ describe('ucfunnel Adapter', () => { }); }); - describe('interpretResponse', () => { - describe('should support banner', () => { + describe('interpretResponse', function () { + describe('should support banner', function () { const request = spec.buildRequests([ validBannerBidReq ]); const result = spec.interpretResponse({body: validBannerBidRes}, request[0]); - it('should build bid array for banner', () => { + it('should build bid array for banner', function () { expect(result.length).to.equal(1); }); - it('should have all relevant fields', () => { + it('should have all relevant fields', function () { const bid = result[0]; expect(bid.mediaType).to.equal(BANNER); @@ -147,14 +147,14 @@ describe('ucfunnel Adapter', () => { }); }); - describe('should support video', () => { + describe('should support video', function () { const request = spec.buildRequests([ validVideoBidReq ]); const result = spec.interpretResponse({body: validVideoBidRes}, request[0]); - it('should build bid array', () => { + it('should build bid array', function () { expect(result.length).to.equal(1); }); - it('should have all relevant fields', () => { + it('should have all relevant fields', function () { const bid = result[0]; expect(bid.mediaType).to.equal(VIDEO); @@ -167,14 +167,14 @@ describe('ucfunnel Adapter', () => { }); }); - describe('should support native', () => { + describe('should support native', function () { const request = spec.buildRequests([ validNativeBidReq ]); const result = spec.interpretResponse({body: validNativeBidRes}, request[0]); - it('should build bid array', () => { + it('should build bid array', function () { expect(result.length).to.equal(1); }); - it('should have all relevant fields', () => { + it('should have all relevant fields', function () { const bid = result[0]; expect(bid.mediaType).to.equal(NATIVE); diff --git a/test/spec/modules/underdogmediaBidAdapter_spec.js b/test/spec/modules/underdogmediaBidAdapter_spec.js index 8ccac8d4f08..6f4df57d316 100644 --- a/test/spec/modules/underdogmediaBidAdapter_spec.js +++ b/test/spec/modules/underdogmediaBidAdapter_spec.js @@ -1,11 +1,11 @@ import { expect } from 'chai'; import { spec } from 'modules/underdogmediaBidAdapter'; -describe('UnderdogMedia adapter', () => { +describe('UnderdogMedia adapter', function () { let bidRequests; let bidderRequest; - beforeEach(() => { + beforeEach(function () { bidRequests = [ { bidder: 'underdogmedia', @@ -35,9 +35,9 @@ describe('UnderdogMedia adapter', () => { } }); - describe('implementation', () => { - describe('for requests', () => { - it('should accept valid bid', () => { + describe('implementation', function () { + describe('for requests', function () { + it('should accept valid bid', function () { let validBid = { bidder: 'underdogmedia', params: { @@ -50,7 +50,7 @@ describe('UnderdogMedia adapter', () => { expect(isValid).to.equal(true); }); - it('should reject invalid bid missing sizes', () => { + it('should reject invalid bid missing sizes', function () { let invalidBid = { bidder: 'underdogmedia', params: { @@ -62,7 +62,7 @@ describe('UnderdogMedia adapter', () => { expect(isValid).to.equal(false); }); - it('should reject invalid bid missing siteId', () => { + it('should reject invalid bid missing siteId', function () { let invalidBid = { bidder: 'underdogmedia', params: {}, @@ -73,7 +73,7 @@ describe('UnderdogMedia adapter', () => { expect(isValid).to.equal(false); }); - it('request data should contain sid', () => { + it('request data should contain sid', function () { let bidRequests = [ { bidId: '3c9408cdbf2f68', @@ -91,7 +91,7 @@ describe('UnderdogMedia adapter', () => { expect(request.data.sid).to.equal('12143'); }); - it('request data should contain sizes', () => { + it('request data should contain sizes', function () { let bidRequests = [ { bidId: '3c9408cdbf2f68', @@ -109,7 +109,7 @@ describe('UnderdogMedia adapter', () => { expect(request.data.sizes).to.equal('300x250,728x90'); }); - it('request data should contain gdpr info', () => { + it('request data should contain gdpr info', function () { let bidRequests = [ { bidId: '3c9408cdbf2f68', @@ -129,7 +129,7 @@ describe('UnderdogMedia adapter', () => { expect(request.data.consentData).to.equal('consentDataString'); }); - it('should not build a request if no vendorConsent', () => { + it('should not build a request if no vendorConsent', function () { let bidRequests = [ { bidId: '3c9408cdbf2f68', @@ -160,7 +160,7 @@ describe('UnderdogMedia adapter', () => { expect(request).to.equal(undefined); }); - it('should properly build a request if no vendorConsent but no gdprApplies', () => { + it('should properly build a request if no vendorConsent but no gdprApplies', function () { let bidRequests = [ { bidId: '3c9408cdbf2f68', @@ -195,7 +195,7 @@ describe('UnderdogMedia adapter', () => { expect(request.data.consentData).to.equal('consentDataString'); }); - it('should properly build a request if gdprConsent empty', () => { + it('should properly build a request if gdprConsent empty', function () { let bidRequests = [ { bidId: '3c9408cdbf2f68', @@ -220,8 +220,8 @@ describe('UnderdogMedia adapter', () => { }); }); - describe('bid responses', () => { - it('should return complete bid response', () => { + describe('bid responses', function () { + it('should return complete bid response', function () { let serverResponse = { body: { mids: [ @@ -260,7 +260,7 @@ describe('UnderdogMedia adapter', () => { expect(bids[0].currency).to.equal('USD'); }); - it('should return empty bid response if mids empty', () => { + it('should return empty bid response if mids empty', function () { let serverResponse = { body: { mids: [] @@ -272,7 +272,7 @@ describe('UnderdogMedia adapter', () => { expect(bids).to.be.lengthOf(0); }); - it('should return empty bid response on incorrect size', () => { + it('should return empty bid response on incorrect size', function () { let serverResponse = { body: { mids: [ @@ -294,7 +294,7 @@ describe('UnderdogMedia adapter', () => { expect(bids).to.be.lengthOf(0); }); - it('should return empty bid response on 0 cpm', () => { + it('should return empty bid response on 0 cpm', function () { let serverResponse = { body: { mids: [ @@ -316,7 +316,7 @@ describe('UnderdogMedia adapter', () => { expect(bids).to.be.lengthOf(0); }); - it('should return empty bid response if no ad in response', () => { + it('should return empty bid response if no ad in response', function () { let serverResponse = { body: { mids: [ @@ -338,7 +338,7 @@ describe('UnderdogMedia adapter', () => { expect(bids).to.be.lengthOf(0); }); - it('ad html string should contain the notification urls', () => { + it('ad html string should contain the notification urls', function () { let serverResponse = { body: { mids: [ diff --git a/test/spec/modules/undertoneBidAdapter_spec.js b/test/spec/modules/undertoneBidAdapter_spec.js index 4a621fb4465..400e86567ea 100644 --- a/test/spec/modules/undertoneBidAdapter_spec.js +++ b/test/spec/modules/undertoneBidAdapter_spec.js @@ -44,6 +44,12 @@ const bidReq = [{ auctionId: '6c22f5a5-59df-4dc6-b92c-f433bcf0a874' }]; +const bidderReq = { + refererInfo: { + referer: 'http://prebid.org/dev-docs/bidder-adaptor.html' + } +}; + const validBidRes = { ad: '
Hello
', publisherId: 12345, @@ -87,25 +93,27 @@ const bidResArray = [ } ]; -describe('Undertone Adapter', () => { - describe('request', () => { - it('should validate bid request', () => { +describe('Undertone Adapter', function () { + describe('request', function () { + it('should validate bid request', function () { expect(spec.isBidRequestValid(validBidReq)).to.equal(true); }); - it('should not validate incorrect bid request', () => { + it('should not validate incorrect bid request', function () { expect(spec.isBidRequestValid(invalidBidReq)).to.equal(undefined); }); }); - describe('build request', () => { - it('should send request to correct url via POST', () => { - const request = spec.buildRequests(bidReq); - const domain = null; + describe('build request', function () { + it('should send request to correct url via POST', function () { + const request = spec.buildRequests(bidReq, bidderReq); + const domainStart = bidderReq.refererInfo.referer.indexOf('//'); + const domainEnd = bidderReq.refererInfo.referer.indexOf('/', domainStart + 2); + const domain = bidderReq.refererInfo.referer.substring(domainStart + 2, domainEnd); const REQ_URL = `${URL}?pid=${bidReq[0].params.publisherId}&domain=${domain}`; expect(request.url).to.equal(REQ_URL); expect(request.method).to.equal('POST'); }); - it('should have all relevant fields', () => { - const request = spec.buildRequests(bidReq); + it('should have all relevant fields', function () { + const request = spec.buildRequests(bidReq, bidderReq); const bid1 = JSON.parse(request.data)['x-ut-hb-params'][0]; expect(bid1.bidRequestId).to.equal('263be71e91dd9d'); expect(bid1.sizes.length).to.equal(2); @@ -121,13 +129,13 @@ describe('Undertone Adapter', () => { }); }); - describe('interpretResponse', () => { - it('should build bid array', () => { + describe('interpretResponse', function () { + it('should build bid array', function () { let result = spec.interpretResponse({body: bidResponse}); expect(result.length).to.equal(1); }); - it('should have all relevant fields', () => { + it('should have all relevant fields', function () { const result = spec.interpretResponse({body: bidResponse}); const bid = result[0]; @@ -141,13 +149,36 @@ describe('Undertone Adapter', () => { expect(bid.ttl).to.equal(360); }); - it('should return empty array when response is incorrect', () => { + it('should return empty array when response is incorrect', function () { expect(spec.interpretResponse({body: {}}).length).to.equal(0); expect(spec.interpretResponse({body: []}).length).to.equal(0); }); - it('should only use valid bid responses', () => { + it('should only use valid bid responses', function () { expect(spec.interpretResponse({ body: bidResArray }).length).to.equal(1); }); }); + + describe('getUserSyncs', () => { + it('verifies gdpr consent checked', () => { + const options = ({ iframeEnabled: true, pixelEnabled: true }); + expect(spec.getUserSyncs(options, {}, { gdprApplies: true }).length).to.equal(0); + }); + + it('Verifies sync iframe option', function () { + const result = spec.getUserSyncs({ iframeEnabled: true, pixelEnabled: true }); + expect(result).to.have.lengthOf(1); + expect(result[0].type).to.equal('iframe'); + expect(result[0].url).to.equal('//cdn.undertone.com/js/usersync.html'); + }); + + it('Verifies sync image option', function () { + const result = spec.getUserSyncs({ pixelEnabled: true }); + expect(result).to.have.lengthOf(2); + expect(result[0].type).to.equal('image'); + expect(result[0].url).to.equal('//usr.undertone.com/userPixel/syncOne?id=1&of=2'); + expect(result[1].type).to.equal('image'); + expect(result[1].url).to.equal('//usr.undertone.com/userPixel/syncOne?id=2&of=2'); + }); + }); }); diff --git a/test/spec/modules/unrulyBidAdapter_spec.js b/test/spec/modules/unrulyBidAdapter_spec.js index 3e39842bd0a..2c8fd9071d6 100644 --- a/test/spec/modules/unrulyBidAdapter_spec.js +++ b/test/spec/modules/unrulyBidAdapter_spec.js @@ -6,7 +6,7 @@ import { VIDEO } from 'src/mediaTypes' import { Renderer } from 'src/Renderer' import { adapter } from 'modules/unrulyBidAdapter' -describe('UnrulyAdapter', () => { +describe('UnrulyAdapter', function () { function createOutStreamExchangeBid({ adUnitCode = 'placement2', statusCode = 1, @@ -39,7 +39,7 @@ describe('UnrulyAdapter', () => { let sandbox; let fakeRenderer; - beforeEach(() => { + beforeEach(function () { sandbox = sinon.sandbox.create(); sandbox.stub(utils, 'logError'); sandbox.stub(Renderer, 'install'); @@ -50,12 +50,12 @@ describe('UnrulyAdapter', () => { Renderer.install.returns(fakeRenderer) }); - afterEach(() => { + afterEach(function () { sandbox.restore(); delete parent.window.unruly }); - it('should expose Unruly Bidder code', () => { + it('should expose Unruly Bidder code', function () { expect(adapter.code).to.equal('unruly') }); @@ -63,22 +63,22 @@ describe('UnrulyAdapter', () => { expect(adapter.supportedMediaTypes).to.deep.equal([ VIDEO ]) }); - describe('isBidRequestValid', () => { - it('should be a function', () => { + describe('isBidRequestValid', function () { + it('should be a function', function () { expect(typeof adapter.isBidRequestValid).to.equal('function') }); - it('should return false if bid is falsey', () => { + it('should return false if bid is falsey', function () { expect(adapter.isBidRequestValid()).to.be.false; }); - it('should return true if bid.mediaType is "video"', () => { + it('should return true if bid.mediaType is "video"', function () { const mockBid = { mediaType: 'video' }; expect(adapter.isBidRequestValid(mockBid)).to.be.true; }); - it('should return true if bid.mediaTypes.video.context is "outstream"', () => { + it('should return true if bid.mediaTypes.video.context is "outstream"', function () { const mockBid = { mediaTypes: { video: { @@ -91,19 +91,19 @@ describe('UnrulyAdapter', () => { }); }); - describe('buildRequests', () => { - it('should be a function', () => { + describe('buildRequests', function () { + it('should be a function', function () { expect(typeof adapter.buildRequests).to.equal('function'); }); - it('should return an object', () => { + it('should return an object', function () { const mockBidRequests = ['mockBid']; expect(typeof adapter.buildRequests(mockBidRequests)).to.equal('object') }); - it('should return a server request with a valid exchange url', () => { + it('should return a server request with a valid exchange url', function () { const mockBidRequests = ['mockBid']; expect(adapter.buildRequests(mockBidRequests).url).to.equal('https://targeting.unrulymedia.com/prebid') }); - it('should return a server request with method === POST', () => { + it('should return a server request with method === POST', function () { const mockBidRequests = ['mockBid']; expect(adapter.buildRequests(mockBidRequests).method).to.equal('POST'); }); @@ -113,7 +113,7 @@ describe('UnrulyAdapter', () => { contentType: 'application/json' }); }); - it('should return a server request with valid payload', () => { + it('should return a server request with valid payload', function () { const mockBidRequests = ['mockBid']; const mockBidderRequest = {bidderCode: 'mockBidder'}; expect(adapter.buildRequests(mockBidRequests, mockBidderRequest).data) @@ -121,18 +121,18 @@ describe('UnrulyAdapter', () => { }) }); - describe('interpretResponse', () => { - it('should be a function', () => { + describe('interpretResponse', function () { + it('should be a function', function () { expect(typeof adapter.interpretResponse).to.equal('function'); }); - it('should return empty array when serverResponse is undefined', () => { + it('should return empty array when serverResponse is undefined', function () { expect(adapter.interpretResponse()).to.deep.equal([]); }); - it('should return empty array when serverResponse has no bids', () => { + it('should return empty array when serverResponse has no bids', function () { const mockServerResponse = { body: { bids: [] } }; expect(adapter.interpretResponse(mockServerResponse)).to.deep.equal([]) }); - it('should return array of bids when receive a successful response from server', () => { + it('should return array of bids when receive a successful response from server', function () { const mockExchangeBid = createOutStreamExchangeBid({adUnitCode: 'video1', bidId: 'mockBidId'}); const mockServerResponse = createExchangeResponse(mockExchangeBid); expect(adapter.interpretResponse(mockServerResponse)).to.deep.equal([ @@ -151,7 +151,7 @@ describe('UnrulyAdapter', () => { ]) }); - it('should initialize and set the renderer', () => { + it('should initialize and set the renderer', function () { expect(Renderer.install).not.to.have.been.called; expect(fakeRenderer.setRender).not.to.have.been.called; @@ -172,7 +172,7 @@ describe('UnrulyAdapter', () => { sinon.assert.calledWithExactly(fakeRenderer.setRender, sinon.match.func) }); - it('bid is placed on the bid queue when render is called', () => { + it('bid is placed on the bid queue when render is called', function () { const exchangeBid = createOutStreamExchangeBid({ adUnitCode: 'video', vastUrl: 'value: vastUrl' }); const exchangeResponse = createExchangeResponse(exchangeBid); @@ -192,7 +192,7 @@ describe('UnrulyAdapter', () => { expect(sentRendererConfig.adUnitCode).to.equal('video') }) - it('should ensure that renderer is placed in Prebid supply mode', () => { + it('should ensure that renderer is placed in Prebid supply mode', function () { const mockExchangeBid = createOutStreamExchangeBid({adUnitCode: 'video1', bidId: 'mockBidId'}); const mockServerResponse = createExchangeResponse(mockExchangeBid); diff --git a/test/spec/modules/uolBidAdapter_spec.js b/test/spec/modules/uolBidAdapter_spec.js index 843f47682dc..e9341772e7d 100644 --- a/test/spec/modules/uolBidAdapter_spec.js +++ b/test/spec/modules/uolBidAdapter_spec.js @@ -1,13 +1,22 @@ import { expect } from 'chai'; import { spec } from 'modules/uolBidAdapter'; -import { newBidder } from 'src/adapters/bidderFactory'; const ENDPOINT = 'https://prebid.adilligo.com/v1/prebid.json'; -describe('UOL Bid Adapter', () => { - const adapter = newBidder(spec); +describe('UOL Bid Adapter', function () { + let sandbox; + let queryStub; + let getCurrentPositionStub; - describe('isBidRequestValid', () => { + beforeEach(function() { + sandbox = sinon.sandbox.create(); + }); + + afterEach(function() { + sandbox.restore(); + }); + + describe('isBidRequestValid', function () { let bid = { 'bidder': 'uol', 'params': { @@ -20,7 +29,7 @@ describe('UOL Bid Adapter', () => { 'auctionId': 'eb511c63-df7e-4240-9b65-2f8ae50303e4', }; - it('should return true for valid params', () => { + it('should return true for valid params', function () { let clonedBid = Object.assign({}, bid); expect(spec.isBidRequestValid(clonedBid)).to.equal(true); @@ -40,13 +49,13 @@ describe('UOL Bid Adapter', () => { expect(spec.isBidRequestValid(clonedBid)).to.equal(true); }); - it('should return false when required params are not passed', () => { + it('should return false when required params are not passed', function () { let clonedBid = Object.assign({}, bid); delete clonedBid.params; expect(spec.isBidRequestValid(clonedBid)).to.equal(false); }); - it('should return false when params are invalid', () => { + it('should return false when params are invalid', function () { let clonedBid = Object.assign({}, bid); delete clonedBid.params; clonedBid.params = { @@ -69,7 +78,7 @@ describe('UOL Bid Adapter', () => { expect(spec.isBidRequestValid(clonedBid)).to.equal(false); }); - it('should return false when cpmFactor is passed and test flag isn\'t active', () => { + it('should return false when cpmFactor is passed and test flag isn\'t active', function () { let clonedBid = Object.assign({}, bid); delete clonedBid.params; clonedBid.params = { @@ -80,39 +89,14 @@ describe('UOL Bid Adapter', () => { expect(spec.isBidRequestValid(clonedBid)).to.equal(false); }); - it('should not allow empty size', () => { + it('should not allow empty size', function () { let clonedBid = Object.assign({}, bid); delete clonedBid.sizes; expect(spec.isBidRequestValid(clonedBid)).to.equal(false); }); }); - describe('buildRequests', () => { - let queryPermission; - let cleanup = function() { - navigator.permissions.query = queryPermission; - }; - let grantTriangulation = function() { - queryPermission = navigator.permissions.query; - navigator.permissions.query = function(data) { - return new Promise((resolve, reject) => { - resolve({state: 'granted'}); - }); - } - }; - let denyTriangulation = function() { - queryPermission = navigator.permissions.query; - navigator.permissions.query = function(data) { - return new Promise((resolve, reject) => { - resolve({state: 'prompt'}); - }); - } - }; - let removeQuerySupport = function() { - queryPermission = navigator.permissions.query; - navigator.permissions.query = undefined; - } - + describe('buildRequests', function () { let bidRequests = [ { 'bidder': 'uol', @@ -148,61 +132,72 @@ describe('UOL Bid Adapter', () => { 'timeout': 3000 }; - describe('buildRequest basic params', () => { + describe('buildRequest basic params', function () { const requestObject = spec.buildRequests(bidRequests, bidderRequest); const payload = JSON.parse(requestObject.data); - it('should send bid requests to expected endpoint via POST method', () => { + it('should send bid requests to expected endpoint via POST method', function () { expect(requestObject.url).to.equal(ENDPOINT); expect(requestObject.method).to.equal('POST'); }); - it('should contain referrer URL', () => { + it('should contain referrer URL', function () { expect(payload.referrerURL).to.exist.and.to.match(/^http(s)?:\/\/.+$/) }); - it('should contain an array of requests with length equivalent to bid count', () => { + it('should contain an array of requests with length equivalent to bid count', function () { expect(payload.requests).to.have.length(bidRequests.length); }); - it('should return propper ad size if at least one entry is provided', () => { + it('should return propper ad size if at least one entry is provided', function () { expect(payload.requests[0].sizes).to.deep.equal(bidRequests[0].sizes); }); }); if (navigator.permissions && navigator.permissions.query && navigator.geolocation) { - describe('buildRequest geolocation param', () => { // shall only be tested if browser engine supports geolocation and permissions API. + describe('buildRequest geolocation param', function () { // shall only be tested if browser engine supports geolocation and permissions API. let geolocation = { lat: 4, long: 3, timestamp: 123121451 }; - it('should contain user coordinates if (i) DNT is off; (ii) browser supports implementation; (iii) localStorage contains geolocation history', () => { + beforeEach(function() { + getCurrentPositionStub = sandbox.stub(navigator.geolocation, 'getCurrentPosition'); + queryStub = sandbox.stub(navigator.permissions, 'query'); + }); + + it('should not contain user coordinates if browser doesnt support permission query', function () { localStorage.setItem('uolLocationTracker', JSON.stringify(geolocation)); - grantTriangulation(); + navigator.permissions.query = undefined; const requestObject = spec.buildRequests(bidRequests, bidderRequest); const payload = JSON.parse(requestObject.data); - expect(payload.geolocation).to.exist.and.not.be.empty; - cleanup(); + expect(payload.geolocation).to.not.exist; }) - it('should not contain user coordinates if localStorage is empty', () => { - localStorage.removeItem('uolLocationTracker'); - denyTriangulation(); + it('should contain user coordinates if (i) DNT is off; (ii) browser supports implementation; (iii) localStorage contains geolocation history', function (done) { + localStorage.setItem('uolLocationTracker', JSON.stringify(geolocation)); + queryStub.callsFake(function() { + return new Promise((resolve, reject) => { + resolve({state: 'granted'}); + }); + }); + getCurrentPositionStub.callsFake(() => done()); const requestObject = spec.buildRequests(bidRequests, bidderRequest); const payload = JSON.parse(requestObject.data); - expect(payload.geolocation).to.not.exist; - cleanup(); + expect(payload.geolocation).to.exist.and.not.be.empty; }) - it('should not contain user coordinates if browser doesnt support permission query', () => { - localStorage.setItem('uolLocationTracker', JSON.stringify(geolocation)); - removeQuerySupport(); + it('should not contain user coordinates if localStorage is empty', function () { + localStorage.removeItem('uolLocationTracker'); + queryStub.callsFake(function() { + return new Promise((resolve, reject) => { + resolve({state: 'prompt'}); + }); + }); const requestObject = spec.buildRequests(bidRequests, bidderRequest); const payload = JSON.parse(requestObject.data); expect(payload.geolocation).to.not.exist; - cleanup(); }) }) } - describe('buildRequest test params', () => { - it('should return test and cpmFactor params if defined', () => { + describe('buildRequest test params', function () { + it('should return test and cpmFactor params if defined', function () { let clonedBid = JSON.parse(JSON.stringify(bidRequests)); delete clonedBid[0].params; clonedBid.splice(1, 1); @@ -229,7 +224,7 @@ describe('UOL Bid Adapter', () => { }) }); - describe('interpretResponse', () => { + describe('interpretResponse', function () { let serverResponse = { 'body': { 'bidderRequestId': '2a21a2fc993ef9', @@ -261,7 +256,7 @@ describe('UOL Bid Adapter', () => { }; let bidRequest = {}; - it('should return the correct bid response structure', () => { + it('should return the correct bid response structure', function () { let expectedResponse = [ { 'requestId': '2a21a2fc993ef9', @@ -281,7 +276,7 @@ describe('UOL Bid Adapter', () => { expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])); }); - it('should corretly return an empty array of bidResponses if no ads were received', () => { + it('should corretly return an empty array of bidResponses if no ads were received', function () { let emptyResponse = Object.assign({}, serverResponse); emptyResponse.body.ads = []; let result = spec.interpretResponse(emptyResponse, {bidRequest}); @@ -289,15 +284,15 @@ describe('UOL Bid Adapter', () => { }); }); - describe('getUserSyncs', () => { + describe('getUserSyncs', function () { let syncOptions = { iframeEnabled: true }; let serverResponses = [{ body: { trackingPixel: 'https://www.uol.com.br' } }, { body: { trackingPixel: 'http://www.dynad.net/' } }]; - it('should return the two sync params for iframeEnabled bids with a trackingPixel response', () => { + it('should return the two sync params for iframeEnabled bids with a trackingPixel response', function () { expect(spec.getUserSyncs(syncOptions, serverResponses)).to.have.length(2); }) - it('should not return any sync params if iframe is disabled or no trackingPixel is received', () => { + it('should not return any sync params if iframe is disabled or no trackingPixel is received', function () { let cloneOptions = Object.assign({}, syncOptions); delete cloneOptions.iframeEnabled; expect(spec.getUserSyncs(cloneOptions, serverResponses)).to.have.length(0); diff --git a/test/spec/modules/vertamediaBidAdapter_spec.js b/test/spec/modules/vertamediaBidAdapter_spec.js index 271f1f2d04a..fefa8e446ed 100644 --- a/test/spec/modules/vertamediaBidAdapter_spec.js +++ b/test/spec/modules/vertamediaBidAdapter_spec.js @@ -96,45 +96,45 @@ const displayEqResponse = [{ cpm: 0.9 }]; -describe('vertamediaBidAdapter', () => { +describe('vertamediaBidAdapter', function () { const adapter = newBidder(spec); - describe('inherited functions', () => { - it('exists and is a function', () => { + describe('inherited functions', function () { + it('exists and is a function', function () { expect(adapter.callBids).to.exist.and.to.be.a('function'); }); }); - describe('isBidRequestValid', () => { - it('should return true when required params found', () => { + describe('isBidRequestValid', function () { + it('should return true when required params found', function () { expect(spec.isBidRequestValid(VIDEO_REQUEST)).to.equal(12345); }); - it('should return false when required params are not passed', () => { + it('should return false when required params are not passed', function () { let bid = Object.assign({}, VIDEO_REQUEST); delete bid.params; expect(spec.isBidRequestValid(bid)).to.equal(undefined); }); }); - describe('buildRequests', () => { + describe('buildRequests', function () { let videoBidRequests = [VIDEO_REQUEST]; let dispalyBidRequests = [DISPLAY_REQUEST]; const displayRequest = spec.buildRequests(dispalyBidRequests, {}); const videoRequest = spec.buildRequests(videoBidRequests, {}); - it('sends bid request to ENDPOINT via GET', () => { + it('sends bid request to ENDPOINT via GET', function () { expect(videoRequest.method).to.equal('GET'); expect(displayRequest.method).to.equal('GET'); }); - it('sends bid request to correct ENDPOINT', () => { + it('sends bid request to correct ENDPOINT', function () { expect(videoRequest.url).to.equal(ENDPOINT); expect(displayRequest.url).to.equal(ENDPOINT); }); - it('sends correct video bid parameters', () => { + it('sends correct video bid parameters', function () { const bid = Object.assign({}, videoRequest.data); delete bid.domain; @@ -148,7 +148,7 @@ describe('vertamediaBidAdapter', () => { expect(bid).to.deep.equal(eq); }); - it('sends correct display bid parameters', () => { + it('sends correct display bid parameters', function () { const bid = Object.assign({}, displayRequest.data); delete bid.domain; @@ -163,18 +163,18 @@ describe('vertamediaBidAdapter', () => { }); }); - describe('interpretResponse', () => { + describe('interpretResponse', function () { let serverResponse; let bidderRequest; let eqResponse; - afterEach(() => { + afterEach(function () { serverResponse = null; bidderRequest = null; eqResponse = null; }); - it('should get correct video bid response', () => { + it('should get correct video bid response', function () { serverResponse = SERVER_VIDEO_RESPONSE; bidderRequest = videoBidderRequest; eqResponse = videoEqResponse; @@ -182,7 +182,7 @@ describe('vertamediaBidAdapter', () => { bidServerResponseCheck(); }); - it('should get correct display bid response', () => { + it('should get correct display bid response', function () { serverResponse = SERVER_DISPLAY_RESPONSE; bidderRequest = displayBidderRequest; eqResponse = displayEqResponse; @@ -203,13 +203,13 @@ describe('vertamediaBidAdapter', () => { expect(noBidResult.length).to.equal(0); } - it('handles video nobid responses', () => { + it('handles video nobid responses', function () { bidderRequest = videoBidderRequest; nobidServerResponseCheck(); }); - it('handles display nobid responses', () => { + it('handles display nobid responses', function () { bidderRequest = displayBidderRequest; nobidServerResponseCheck(); diff --git a/test/spec/modules/vertozBidAdapter_spec.js b/test/spec/modules/vertozBidAdapter_spec.js index a84fc4847f5..1eb85b6b566 100644 --- a/test/spec/modules/vertozBidAdapter_spec.js +++ b/test/spec/modules/vertozBidAdapter_spec.js @@ -4,16 +4,16 @@ import { newBidder } from 'src/adapters/bidderFactory'; const BASE_URI = '//hb.vrtzads.com/vzhbidder/bid?'; -describe('VertozAdapter', () => { +describe('VertozAdapter', function () { const adapter = newBidder(spec); - describe('inherited functions', () => { - it('exists and is a function', () => { + describe('inherited functions', function () { + it('exists and is a function', function () { expect(adapter.callBids).to.exist.and.to.be.a('function'); }); }); - describe('isBidRequestValid', () => { + describe('isBidRequestValid', function () { let bid = { 'bidder': 'vertoz', 'params': { @@ -26,11 +26,11 @@ describe('VertozAdapter', () => { 'auctionId': '1d1a030790a475', }; - it('should return true when required params found', () => { + it('should return true when required params found', function () { expect(spec.isBidRequestValid(bid)).to.equal(true); }); - it('should return false when required params are not passed', () => { + it('should return false when required params are not passed', function () { let bid = Object.assign({}, bid); delete bid.params; bid.params = { @@ -40,7 +40,7 @@ describe('VertozAdapter', () => { }); }); - describe('buildRequests', () => { + describe('buildRequests', function () { let bidRequests = [ { 'bidder': 'vertoz', @@ -55,14 +55,14 @@ describe('VertozAdapter', () => { } ]; - it('sends bid request to ENDPOINT via POST', () => { + it('sends bid request to ENDPOINT via POST', function () { const request = spec.buildRequests(bidRequests)[0]; expect(request.url).to.equal(BASE_URI); expect(request.method).to.equal('POST'); }); }); - describe('interpretResponse', () => { + describe('interpretResponse', function () { let response = { 'vzhPlacementId': 'VZ-HB-B784382V6C6G3C', 'bid': '76021e56-adaf-4114-b68d-ccacd1b3e551_1', @@ -75,7 +75,7 @@ describe('VertozAdapter', () => { 'statusText': 'Vertoz:Success' }; - it('should get correct bid response', () => { + it('should get correct bid response', function () { let expectedResponse = [ { 'requestId': '44b3fcfd24aa93', @@ -97,7 +97,7 @@ describe('VertozAdapter', () => { expect(result[0].cpm).to.not.equal(null); }); - it('handles nobid responses', () => { + it('handles nobid responses', function () { let response = { 'vzhPlacementId': 'VZ-HB-I617046VBGE3EH', 'slotBidId': 'f00412ac86b79', diff --git a/test/spec/modules/viBidAdapter_spec.js b/test/spec/modules/viBidAdapter_spec.js index e8b0fbcc4b2..2468da0cfaf 100644 --- a/test/spec/modules/viBidAdapter_spec.js +++ b/test/spec/modules/viBidAdapter_spec.js @@ -7,7 +7,7 @@ const ENDPOINT = `//pb.vi-serve.com/prebid/bid`; describe('viBidAdapter', function() { newBidder(spec); - describe('isBidRequestValid', () => { + describe('isBidRequestValid', function () { let bid = { 'bidder': 'vi', 'params': { @@ -27,17 +27,17 @@ describe('viBidAdapter', function() { 'transactionId': '474da635-9cf0-4188-a3d9-58961be8f905' }; - it('should return true when required params found', () => { + it('should return true when required params found', function () { expect(spec.isBidRequestValid(bid)).to.equal(true); }); - it('should return false when pubId not passed', () => { + it('should return false when pubId not passed', function () { bid.params.pubId = undefined; expect(spec.isBidRequestValid(bid)).to.equal(false); }); }); - describe('buildRequests', () => { + describe('buildRequests', function () { let bidRequests = [{ 'bidder': 'vi', 'params': { @@ -59,16 +59,16 @@ describe('viBidAdapter', function() { const request = spec.buildRequests(bidRequests); - it('POST bid request to vi', () => { + it('POST bid request to vi', function () { expect(request.method).to.equal('POST'); }); - it('check endpoint URL', () => { + it('check endpoint URL', function () { expect(request.url).to.equal(ENDPOINT) }); }); - describe('buildRequests can handle size in 1-dim array', () => { + describe('buildRequests can handle size in 1-dim array', function () { let bidRequests = [{ 'bidder': 'vi', 'params': { @@ -88,16 +88,16 @@ describe('viBidAdapter', function() { const request = spec.buildRequests(bidRequests); - it('POST bid request to vi', () => { + it('POST bid request to vi', function () { expect(request.method).to.equal('POST'); }); - it('check endpoint URL', () => { + it('check endpoint URL', function () { expect(request.url).to.equal(ENDPOINT) }); }); - describe('interpretResponse', () => { + describe('interpretResponse', function () { let response = { body: [{ 'id': '29b891ad542377', @@ -109,7 +109,7 @@ describe('viBidAdapter', function() { }] }; - it('should get the correct bid response', () => { + it('should get the correct bid response', function () { let expectedResponse = [{ 'requestId': '29b891ad542377', 'cpm': 0.1, @@ -128,7 +128,7 @@ describe('viBidAdapter', function() { expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse[0])); }); - it('handles empty bid response', () => { + it('handles empty bid response', function () { let response = { body: [] }; diff --git a/test/spec/modules/vidazooBidAdapter_spec.js b/test/spec/modules/vidazooBidAdapter_spec.js index b857967a44e..d9c08ad924c 100644 --- a/test/spec/modules/vidazooBidAdapter_spec.js +++ b/test/spec/modules/vidazooBidAdapter_spec.js @@ -54,31 +54,31 @@ const SYNC_OPTIONS = { 'pixelEnabled': true }; -describe('VidazooBidAdapter', () => { - describe('validtae spec', () => { - it('exists and is a function', () => { +describe('VidazooBidAdapter', function () { + describe('validtae spec', function () { + it('exists and is a function', function () { expect(adapter.isBidRequestValid).to.exist.and.to.be.a('function'); }); - it('exists and is a function', () => { + it('exists and is a function', function () { expect(adapter.buildRequests).to.exist.and.to.be.a('function'); }); - it('exists and is a function', () => { + it('exists and is a function', function () { expect(adapter.interpretResponse).to.exist.and.to.be.a('function'); }); - it('exists and is a function', () => { + it('exists and is a function', function () { expect(adapter.getUserSyncs).to.exist.and.to.be.a('function'); }); - it('exists and is a string', () => { + it('exists and is a string', function () { expect(adapter.code).to.exist.and.to.be.a('string'); }); }); - describe('validate bid requests', () => { - it('should require cId', () => { + describe('validate bid requests', function () { + it('should require cId', function () { const isValid = adapter.isBidRequestValid({ params: { pId: 'pid' @@ -87,7 +87,7 @@ describe('VidazooBidAdapter', () => { expect(isValid).to.be.false; }); - it('should require pId', () => { + it('should require pId', function () { const isValid = adapter.isBidRequestValid({ params: { cId: 'cid' @@ -96,7 +96,7 @@ describe('VidazooBidAdapter', () => { expect(isValid).to.be.false; }); - it('should validate correctly', () => { + it('should validate correctly', function () { const isValid = adapter.isBidRequestValid({ params: { cId: 'cid', @@ -107,15 +107,15 @@ describe('VidazooBidAdapter', () => { }); }); - describe('build requests', () => { + describe('build requests', function () { let sandbox; - before(() => { + before(function () { sandbox = sinon.sandbox.create(); sandbox.stub(utils, 'getTopWindowUrl').returns('http://www.greatsite.com'); sandbox.stub(Date, 'now').returns(1000); }); - it('should build request for each size', () => { + it('should build request for each size', function () { const requests = adapter.buildRequests([BID], BIDDER_REQUEST); expect(requests).to.have.length(2); expect(requests[0]).to.deep.equal({ @@ -152,28 +152,28 @@ describe('VidazooBidAdapter', () => { }); }); - after(() => { + after(function () { sandbox.restore(); }); }); - describe('interpret response', () => { - it('should return empty array when there is no response', () => { + describe('interpret response', function () { + it('should return empty array when there is no response', function () { const responses = adapter.interpretResponse(null); expect(responses).to.be.empty; }); - it('should return empty array when there is no ad', () => { + it('should return empty array when there is no ad', function () { const responses = adapter.interpretResponse({price: 1, ad: ''}); expect(responses).to.be.empty; }); - it('should return empty array when there is no price', () => { + it('should return empty array when there is no price', function () { const responses = adapter.interpretResponse({price: null, ad: 'great ad'}); expect(responses).to.be.empty; }); - it('should return an array of interpreted responses', () => { + it('should return an array of interpreted responses', function () { const responses = adapter.interpretResponse(SERVER_RESPONSE, REQUEST); expect(responses).to.have.length(1); expect(responses[0]).to.deep.equal({ @@ -189,7 +189,7 @@ describe('VidazooBidAdapter', () => { }); }); - it('should take default TTL', () => { + it('should take default TTL', function () { const serverResponse = utils.deepClone(SERVER_RESPONSE); delete serverResponse.body.exp; const responses = adapter.interpretResponse(serverResponse, REQUEST); diff --git a/test/spec/modules/visxBidAdapter_spec.js b/test/spec/modules/visxBidAdapter_spec.js index 67b747b5130..93dbe5626c2 100755 --- a/test/spec/modules/visxBidAdapter_spec.js +++ b/test/spec/modules/visxBidAdapter_spec.js @@ -6,13 +6,13 @@ import { newBidder } from 'src/adapters/bidderFactory'; describe('VisxAdapter', function () { const adapter = newBidder(spec); - describe('inherited functions', () => { - it('exists and is a function', () => { + describe('inherited functions', function () { + it('exists and is a function', function () { expect(adapter.callBids).to.exist.and.to.be.a('function'); }); }); - describe('isBidRequestValid', () => { + describe('isBidRequestValid', function () { let bid = { 'bidder': 'visx', 'params': { @@ -25,11 +25,11 @@ describe('VisxAdapter', function () { 'auctionId': '1d1a030790a475', }; - it('should return true when required params found', () => { + it('should return true when required params found', function () { expect(spec.isBidRequestValid(bid)).to.equal(true); }); - it('should return false when required params are not passed', () => { + it('should return false when required params are not passed', function () { let bid = Object.assign({}, bid); delete bid.params; bid.params = { @@ -39,7 +39,7 @@ describe('VisxAdapter', function () { }); }); - describe('buildRequests', () => { + describe('buildRequests', function () { let bidRequests = [ { 'bidder': 'visx', @@ -76,7 +76,7 @@ describe('VisxAdapter', function () { } ]; - it('should attach valid params to the tag', () => { + it('should attach valid params to the tag', function () { const request = spec.buildRequests([bidRequests[0]]); const payload = request.data; expect(payload).to.be.an('object'); @@ -87,7 +87,7 @@ describe('VisxAdapter', function () { expect(payload).to.have.property('cur', 'EUR'); }); - it('auids must not be duplicated', () => { + it('auids must not be duplicated', function () { const request = spec.buildRequests(bidRequests); const payload = request.data; expect(payload).to.be.an('object'); @@ -98,21 +98,21 @@ describe('VisxAdapter', function () { expect(payload).to.have.property('cur', 'EUR'); }); - it('pt parameter must be "gross" if params.priceType === "gross"', () => { + it('pt parameter must be "net" if params.priceType === "gross"', function () { bidRequests[1].params.priceType = 'gross'; const request = spec.buildRequests(bidRequests); const payload = request.data; expect(payload).to.be.an('object'); expect(payload).to.have.property('u').that.is.a('string'); - expect(payload).to.have.property('pt', 'gross'); + expect(payload).to.have.property('pt', 'net'); expect(payload).to.have.property('auids', '903535,903536'); expect(payload).to.have.property('r', '22edbae2733bf6'); expect(payload).to.have.property('cur', 'EUR'); delete bidRequests[1].params.priceType; }); - it('pt parameter must be "net" or "gross"', () => { - bidRequests[1].params.priceType = 'some'; + it('pt parameter must be "net" if params.priceType === "net"', function () { + bidRequests[1].params.priceType = 'net'; const request = spec.buildRequests(bidRequests); const payload = request.data; expect(payload).to.be.an('object'); @@ -123,7 +123,21 @@ describe('VisxAdapter', function () { expect(payload).to.have.property('cur', 'EUR'); delete bidRequests[1].params.priceType; }); - it('should add currency from currency.bidderCurrencyDefault', () => { + + it('pt parameter must be "net" if params.priceType === "undefined"', function () { + bidRequests[1].params.priceType = 'undefined'; + const request = spec.buildRequests(bidRequests); + const payload = request.data; + expect(payload).to.be.an('object'); + expect(payload).to.have.property('u').that.is.a('string'); + expect(payload).to.have.property('pt', 'net'); + expect(payload).to.have.property('auids', '903535,903536'); + expect(payload).to.have.property('r', '22edbae2733bf6'); + expect(payload).to.have.property('cur', 'EUR'); + delete bidRequests[1].params.priceType; + }); + + it('should add currency from currency.bidderCurrencyDefault', function () { const getConfigStub = sinon.stub(config, 'getConfig').callsFake( arg => arg === 'currency.bidderCurrencyDefault.visx' ? 'JPY' : 'USD'); const request = spec.buildRequests(bidRequests); @@ -136,7 +150,8 @@ describe('VisxAdapter', function () { expect(payload).to.have.property('cur', 'JPY'); getConfigStub.restore(); }); - it('should add currency from currency.adServerCurrency', () => { + + it('should add currency from currency.adServerCurrency', function () { const getConfigStub = sinon.stub(config, 'getConfig').callsFake( arg => arg === 'currency.bidderCurrencyDefault.visx' ? '' : 'USD'); const request = spec.buildRequests(bidRequests); @@ -149,7 +164,8 @@ describe('VisxAdapter', function () { expect(payload).to.have.property('cur', 'USD'); getConfigStub.restore(); }); - it('if gdprConsent is present payload must have gdpr params', () => { + + it('if gdprConsent is present payload must have gdpr params', function () { const request = spec.buildRequests(bidRequests, {gdprConsent: {consentString: 'AAA', gdprApplies: true}}); const payload = request.data; expect(payload).to.be.an('object'); @@ -157,7 +173,7 @@ describe('VisxAdapter', function () { expect(payload).to.have.property('gdpr_applies', 1); }); - it('if gdprApplies is false gdpr_applies must be 0', () => { + it('if gdprApplies is false gdpr_applies must be 0', function () { const request = spec.buildRequests(bidRequests, {gdprConsent: {consentString: 'AAA', gdprApplies: false}}); const payload = request.data; expect(payload).to.be.an('object'); @@ -165,7 +181,7 @@ describe('VisxAdapter', function () { expect(payload).to.have.property('gdpr_applies', 0); }); - it('if gdprApplies is undefined gdpr_applies must be 1', () => { + it('if gdprApplies is undefined gdpr_applies must be 1', function () { const request = spec.buildRequests(bidRequests, {gdprConsent: {consentString: 'AAA'}}); const payload = request.data; expect(payload).to.be.an('object'); @@ -174,7 +190,7 @@ describe('VisxAdapter', function () { }); }); - describe('interpretResponse', () => { + describe('interpretResponse', function () { const responses = [ {'bid': [{'price': 1.15, 'adm': '
test content 1
', 'auid': 903535, 'h': 250, 'w': 300}], 'seat': '1'}, {'bid': [{'price': 0.5, 'adm': '
test content 2
', 'auid': 903536, 'h': 90, 'w': 728}], 'seat': '1'}, @@ -185,7 +201,7 @@ describe('VisxAdapter', function () { {'seat': '1'}, ]; - it('should get correct bid response', () => { + it('should get correct bid response', function () { const bidRequests = [ { 'bidder': 'visx', @@ -219,7 +235,7 @@ describe('VisxAdapter', function () { expect(result).to.deep.equal(expectedResponse); }); - it('should get correct multi bid response', () => { + it('should get correct multi bid response', function () { const bidRequests = [ { 'bidder': 'visx', @@ -299,7 +315,7 @@ describe('VisxAdapter', function () { expect(result).to.deep.equal(expectedResponse); }); - it('should return right currency', () => { + it('should return right currency', function () { const bidRequests = [ { 'bidder': 'visx', @@ -335,7 +351,7 @@ describe('VisxAdapter', function () { getConfigStub.restore(); }); - it('handles wrong and nobid responses', () => { + it('handles wrong and nobid responses', function () { const bidRequests = [ { 'bidder': 'visx', diff --git a/test/spec/modules/vubleAnalyticsAdapter_spec.js b/test/spec/modules/vubleAnalyticsAdapter_spec.js index 896f6e4ee87..841a53c6dee 100644 --- a/test/spec/modules/vubleAnalyticsAdapter_spec.js +++ b/test/spec/modules/vubleAnalyticsAdapter_spec.js @@ -1,36 +1,36 @@ import vubleAnalytics from 'modules/vubleAnalyticsAdapter'; import { expect } from 'chai'; let events = require('src/events'); -let adaptermanager = require('src/adaptermanager'); +let adapterManager = require('src/adapterManager').default; let constants = require('src/constants.json'); describe('Vuble Prebid Analytic', function () { let xhr; - before(() => { + before(function () { xhr = sinon.useFakeXMLHttpRequest(); }); - after(() => { + after(function () { vubleAnalytics.disableAnalytics(); xhr.restore(); }); describe('enableAnalytics', function () { - beforeEach(() => { + beforeEach(function () { sinon.spy(vubleAnalytics, 'track'); sinon.stub(events, 'getEvents').returns([]); }); - afterEach(() => { + afterEach(function () { vubleAnalytics.track.restore(); events.getEvents.restore(); }); it('should catch all events', function () { - adaptermanager.registerAnalyticsAdapter({ + adapterManager.registerAnalyticsAdapter({ code: 'vuble', adapter: vubleAnalytics }); - adaptermanager.enableAnalytics({ + adapterManager.enableAnalytics({ provider: 'vuble', options: { pubId: 18, diff --git a/test/spec/modules/vubleBidAdapter_spec.js b/test/spec/modules/vubleBidAdapter_spec.js index 6d266ca465e..8996c1b4957 100644 --- a/test/spec/modules/vubleBidAdapter_spec.js +++ b/test/spec/modules/vubleBidAdapter_spec.js @@ -4,23 +4,23 @@ import {expect} from 'chai'; import {spec as adapter} from 'modules/vubleBidAdapter'; import * as utils from 'src/utils'; -describe('VubleAdapter', () => { - describe('Check methods existance', () => { - it('exists and is a function', () => { +describe('VubleAdapter', function () { + describe('Check methods existance', function () { + it('exists and is a function', function () { expect(adapter.isBidRequestValid).to.exist.and.to.be.a('function'); }); - it('exists and is a function', () => { + it('exists and is a function', function () { expect(adapter.buildRequests).to.exist.and.to.be.a('function'); }); - it('exists and is a function', () => { + it('exists and is a function', function () { expect(adapter.interpretResponse).to.exist.and.to.be.a('function'); }); - it('exists and is a function', () => { + it('exists and is a function', function () { expect(adapter.getUserSyncs).to.exist.and.to.be.a('function'); }); }); - describe('Check method isBidRequestValid return', () => { + describe('Check method isBidRequestValid return', function () { let bid = { bidder: 'vuble', params: { @@ -37,11 +37,11 @@ describe('VubleAdapter', () => { }, }; - it('should be true', () => { + it('should be true', function () { expect(adapter.isBidRequestValid(bid)).to.be.true; }); - it('should be false because the sizes are missing or in the wrong format', () => { + it('should be false because the sizes are missing or in the wrong format', function () { let wrongBid = utils.deepClone(bid); wrongBid.sizes = '640360'; expect(adapter.isBidRequestValid(wrongBid)).to.be.false; @@ -51,7 +51,7 @@ describe('VubleAdapter', () => { expect(adapter.isBidRequestValid(wrongBid)).to.be.false; }); - it('should be false because the mediaType is missing or wrong', () => { + it('should be false because the mediaType is missing or wrong', function () { let wrongBid = utils.deepClone(bid); wrongBid.mediaTypes = {}; expect(adapter.isBidRequestValid(wrongBid)).to.be.false; @@ -61,7 +61,7 @@ describe('VubleAdapter', () => { expect(adapter.isBidRequestValid(wrongBid)).to.be.false; }); - it('should be false because the env is missing or wrong', () => { + it('should be false because the env is missing or wrong', function () { let wrongBid = utils.deepClone(bid); wrongBid.params.env = 'us'; expect(adapter.isBidRequestValid(wrongBid)).to.be.false; @@ -71,22 +71,22 @@ describe('VubleAdapter', () => { expect(adapter.isBidRequestValid(wrongBid)).to.be.false; }); - it('should be false because params.pubId is missing', () => { + it('should be false because params.pubId is missing', function () { let wrongBid = utils.deepClone(bid); delete wrongBid.params.pubId; expect(adapter.isBidRequestValid(wrongBid)).to.be.false; }); - it('should be false because params.zoneId is missing', () => { + it('should be false because params.zoneId is missing', function () { let wrongBid = utils.deepClone(bid); delete wrongBid.params.zoneId; expect(adapter.isBidRequestValid(wrongBid)).to.be.false; }); }); - describe('Check buildRequests method', () => { + describe('Check buildRequests method', function () { let sandbox; - before(() => { + before(function () { sandbox = sinon.sandbox.create(); sandbox.stub(utils, 'getTopWindowUrl').returns('http://www.vuble.tv/'); }); @@ -161,17 +161,17 @@ describe('VubleAdapter', () => { } }; - it('must return the right formatted requests', () => { + it('must return the right formatted requests', function () { let rs = adapter.buildRequests([bid1, bid2]); expect(adapter.buildRequests([bid1, bid2])).to.deep.equal([request1, request2]); }); - after(() => { + after(function () { sandbox.restore(); }); }); - describe('Check interpretResponse method return', () => { + describe('Check interpretResponse method return', function () { // Server's response let response = { body: { @@ -213,11 +213,11 @@ describe('VubleAdapter', () => { mediaType: 'video' }; - it('should equal to the expected formatted result', () => { + it('should equal to the expected formatted result', function () { expect(adapter.interpretResponse(response, bid)).to.deep.equal([result]); }); - it('should be empty because the status is missing or wrong', () => { + it('should be empty because the status is missing or wrong', function () { let wrongResponse = utils.deepClone(response); wrongResponse.body.status = 'ko'; expect(adapter.interpretResponse(wrongResponse, bid)).to.be.empty; @@ -227,7 +227,7 @@ describe('VubleAdapter', () => { expect(adapter.interpretResponse(wrongResponse, bid)).to.be.empty; }); - it('should be empty because the body is missing or wrong', () => { + it('should be empty because the body is missing or wrong', function () { let wrongResponse = utils.deepClone(response); wrongResponse.body = [1, 2, 3]; expect(adapter.interpretResponse(wrongResponse, bid)).to.be.empty; @@ -237,7 +237,7 @@ describe('VubleAdapter', () => { expect(adapter.interpretResponse(wrongResponse, bid)).to.be.empty; }); - it('should equal to the expected formatted result', () => { + it('should equal to the expected formatted result', function () { response.body.renderer_url = 'vuble_renderer.js'; result.adUnitCode = 'code'; let formattedResponses = adapter.interpretResponse(response, bid); @@ -245,7 +245,7 @@ describe('VubleAdapter', () => { }); }); - describe('Check getUserSyncs method return', () => { + describe('Check getUserSyncs method return', function () { // Sync options let syncOptions = { iframeEnabled: false @@ -265,7 +265,7 @@ describe('VubleAdapter', () => { url: 'http://player.mediabong.net/csifr?1234' }; - it('should return an empty array', () => { + it('should return an empty array', function () { expect(adapter.getUserSyncs({}, [])).to.be.empty; expect(adapter.getUserSyncs({}, [])).to.be.empty; expect(adapter.getUserSyncs(syncOptions, [response])).to.be.empty; @@ -275,7 +275,7 @@ describe('VubleAdapter', () => { expect(adapter.getUserSyncs(syncOptions, [response])).to.be.empty; }); - it('should be equal to the expected result', () => { + it('should be equal to the expected result', function () { response.body.iframeSync = 'http://player.mediabong.net/csifr?1234'; expect(adapter.getUserSyncs(syncOptions, [response])).to.deep.equal([result]); }) diff --git a/test/spec/modules/weboramaBidAdapter_spec.js b/test/spec/modules/weboramaBidAdapter_spec.js index ef8414eb487..d0b119825a6 100644 --- a/test/spec/modules/weboramaBidAdapter_spec.js +++ b/test/spec/modules/weboramaBidAdapter_spec.js @@ -1,7 +1,7 @@ import {expect} from 'chai'; import {spec} from '../../../modules/weboramaBidAdapter'; -describe('WeboramaAdapter', () => { +describe('WeboramaAdapter', function () { let bid = { bidId: '2dd581a2b6281d', bidder: 'weborama', @@ -16,31 +16,31 @@ describe('WeboramaAdapter', () => { transactionId: '3bb2f6da-87a6-4029-aeb0-bfe951372e62' }; - describe('isBidRequestValid', () => { - it('Should return true when placementId can be cast to a number', () => { + describe('isBidRequestValid', function () { + it('Should return true when placementId can be cast to a number', function () { expect(spec.isBidRequestValid(bid)).to.be.true; }); - it('Should return false when placementId is not a number', () => { + it('Should return false when placementId is not a number', function () { bid.params.placementId = 'aaa'; expect(spec.isBidRequestValid(bid)).to.be.false; }); }); - describe('buildRequests', () => { + describe('buildRequests', function () { let serverRequest = spec.buildRequests([bid]); - it('Creates a ServerRequest object with method, URL and data', () => { + it('Creates a ServerRequest object with method, URL and data', function () { expect(serverRequest).to.exist; expect(serverRequest.method).to.exist; expect(serverRequest.url).to.exist; expect(serverRequest.data).to.exist; }); - it('Returns POST method', () => { + it('Returns POST method', function () { expect(serverRequest.method).to.equal('POST'); }); - it('Returns valid URL', () => { + it('Returns valid URL', function () { expect(serverRequest.url).to.equal('//supply.nl.weborama.fr/?c=o&m=multi'); }); - it('Returns valid data if array of bids is valid', () => { + it('Returns valid data if array of bids is valid', function () { let data = serverRequest.data; expect(data).to.be.an('object'); expect(data).to.have.all.keys('deviceWidth', 'deviceHeight', 'secure', 'host', 'page', 'placements'); @@ -59,13 +59,13 @@ describe('WeboramaAdapter', () => { expect(placement.sizes).to.be.an('array'); } }); - it('Returns empty data if no valid requests are passed', () => { + it('Returns empty data if no valid requests are passed', function () { serverRequest = spec.buildRequests([]); let data = serverRequest.data; expect(data.placements).to.be.an('array').that.is.empty; }); }); - describe('interpretResponse', () => { + describe('interpretResponse', function () { let resObject = { body: [ { requestId: '123', @@ -81,7 +81,7 @@ describe('WeboramaAdapter', () => { } ] }; let serverResponses = spec.interpretResponse(resObject); - it('Returns an array of valid server responses if response object is valid', () => { + it('Returns an array of valid server responses if response object is valid', function () { expect(serverResponses).to.be.an('array').that.is.not.empty; for (let i = 0; i < serverResponses.length; i++) { let dataItem = serverResponses[i]; @@ -98,16 +98,16 @@ describe('WeboramaAdapter', () => { expect(dataItem.currency).to.be.a('string'); expect(dataItem.mediaType).to.be.a('string'); } - it('Returns an empty array if invalid response is passed', () => { + it('Returns an empty array if invalid response is passed', function () { serverResponses = spec.interpretResponse('invalid_response'); expect(serverResponses).to.be.an('array').that.is.empty; }); }); }); - describe('getUserSyncs', () => { + describe('getUserSyncs', function () { let userSync = spec.getUserSyncs(); - it('Returns valid URL and `', () => { + it('Returns valid URL and `', function () { expect(userSync).to.be.an('array').with.lengthOf(1); expect(userSync[0].type).to.exist; expect(userSync[0].url).to.exist; diff --git a/test/spec/modules/widespaceBidAdapter_spec.js b/test/spec/modules/widespaceBidAdapter_spec.js index 81d2528465e..dc0d547d47a 100644 --- a/test/spec/modules/widespaceBidAdapter_spec.js +++ b/test/spec/modules/widespaceBidAdapter_spec.js @@ -2,7 +2,7 @@ import { expect } from 'chai'; import { spec } from 'modules/widespaceBidAdapter'; import includes from 'core-js/library/fn/array/includes'; -describe('+widespaceAdatperTest', () => { +describe('+widespaceAdatperTest', function () { // Dummy bid request const bidRequest = [{ 'adUnitCode': 'div-gpt-ad-1460505748561-0', @@ -110,8 +110,8 @@ describe('+widespaceAdatperTest', () => { navigator.connection.type = 'wifi'; } - describe('+bidRequestValidity', () => { - it('bidRequest with sid and currency params', () => { + describe('+bidRequestValidity', function () { + it('bidRequest with sid and currency params', function () { expect(spec.isBidRequestValid({ bidder: 'widespace', params: { @@ -121,7 +121,7 @@ describe('+widespaceAdatperTest', () => { })).to.equal(true); }); - it('-bidRequest with missing sid', () => { + it('-bidRequest with missing sid', function () { expect(spec.isBidRequestValid({ bidder: 'widespace', params: { @@ -130,7 +130,7 @@ describe('+widespaceAdatperTest', () => { })).to.equal(false); }); - it('-bidRequest with missing currency', () => { + it('-bidRequest with missing currency', function () { expect(spec.isBidRequestValid({ bidder: 'widespace', params: { @@ -140,37 +140,37 @@ describe('+widespaceAdatperTest', () => { }); }); - describe('+bidRequest', () => { + describe('+bidRequest', function () { const request = spec.buildRequests(bidRequest, bidderRequest); const UrlRegExp = /^((ftp|http|https):)?\/\/[^ "]+$/; - it('-bidRequest method is POST', () => { + it('-bidRequest method is POST', function () { expect(request[0].method).to.equal('POST'); }); - it('-bidRequest url is valid', () => { + it('-bidRequest url is valid', function () { expect(UrlRegExp.test(request[0].url)).to.equal(true); }); - it('-bidRequest data exist', () => { + it('-bidRequest data exist', function () { expect(request[0].data).to.exists; }); - it('-bidRequest data is form data', () => { + it('-bidRequest data is form data', function () { expect(typeof request[0].data).to.equal('string'); }); - it('-bidRequest options have header type', () => { + it('-bidRequest options have header type', function () { expect(request[0].options.contentType).to.exists; }); - it('-cookie test for wsCustomData ', () => { + it('-cookie test for wsCustomData ', function () { expect(request[0].data.indexOf('hb.cd') > -1).to.equal(true); }); }); - describe('+interpretResponse', () => { - it('-required params available in response', () => { + describe('+interpretResponse', function () { + it('-required params available in response', function () { const result = spec.interpretResponse(bidResponse, bidRequest); let requiredKeys = [ 'requestId', @@ -201,19 +201,19 @@ describe('+widespaceAdatperTest', () => { }); }); - it('-empty result if noad responded', () => { + it('-empty result if noad responded', function () { const noAdResult = spec.interpretResponse(bidResponseNoAd, bidRequest); expect(noAdResult.length).to.equal(0); }); - it('-empty response should not breake anything in adapter', () => { + it('-empty response should not breake anything in adapter', function () { const noResponse = spec.interpretResponse({}, bidRequest); expect(noResponse.length).to.equal(0); }); }); - describe('+getUserSyncs', () => { - it('-always return an array', () => { + describe('+getUserSyncs', function () { + it('-always return an array', function () { const userSync_test1 = spec.getUserSyncs({}, [bidResponse]); expect(Array.isArray(userSync_test1)).to.equal(true); diff --git a/test/spec/modules/xendizBidAdapter_spec.js b/test/spec/modules/xendizBidAdapter_spec.js index 66b9dc62b88..4d1aa3c935f 100644 --- a/test/spec/modules/xendizBidAdapter_spec.js +++ b/test/spec/modules/xendizBidAdapter_spec.js @@ -34,39 +34,39 @@ const bidResponse = { const noBidResponse = { body: { id: '1d1a030790a475', bids: [] } }; -describe('xendizBidAdapter', () => { +describe('xendizBidAdapter', function () { const adapter = newBidder(spec); - describe('inherited functions', () => { - it('exists and is a function', () => { + describe('inherited functions', function () { + it('exists and is a function', function () { expect(adapter.callBids).to.exist.and.to.be.a('function'); }); }); - describe('isBidRequestValid', () => { - it('should return false', () => { + describe('isBidRequestValid', function () { + it('should return false', function () { let bid = Object.assign({}, bidRequest); bid.params = {}; expect(spec.isBidRequestValid(bid)).to.equal(false); }); - it('should return true', () => { + it('should return true', function () { expect(spec.isBidRequestValid(bidRequest)).to.equal(true); }); }); - describe('buildRequests', () => { - it('should format valid url', () => { + describe('buildRequests', function () { + it('should format valid url', function () { const request = spec.buildRequests([bidRequest]); expect(request.url).to.equal(VALID_ENDPOINT); }); - it('should format valid url', () => { + it('should format valid url', function () { const request = spec.buildRequests([bidRequest]); expect(request.url).to.equal(VALID_ENDPOINT); }); - it('should format valid request body', () => { + it('should format valid request body', function () { const request = spec.buildRequests([bidRequest]); const payload = JSON.parse(request.data); expect(payload.id).to.exist; @@ -74,7 +74,7 @@ describe('xendizBidAdapter', () => { expect(payload.device).to.exist; }); - it('should attach valid device info', () => { + it('should attach valid device info', function () { const request = spec.buildRequests([bidRequest]); const payload = JSON.parse(request.data); expect(payload.device).to.deep.equal([ @@ -84,7 +84,7 @@ describe('xendizBidAdapter', () => { ]); }); - it('should transform sizes', () => { + it('should transform sizes', function () { const request = spec.buildRequests([bidRequest]); const payload = JSON.parse(request.data); const item = payload.items[0]; @@ -92,8 +92,8 @@ describe('xendizBidAdapter', () => { }); }); - describe('interpretResponse', () => { - it('should get correct bid response', () => { + describe('interpretResponse', function () { + it('should get correct bid response', function () { const result = spec.interpretResponse(bidResponse); const validResponse = [{ requestId: '30b31c1838de1e', @@ -111,7 +111,7 @@ describe('xendizBidAdapter', () => { expect(result).to.deep.equal(validResponse); }); - it('handles nobid responses', () => { + it('handles nobid responses', function () { let result = spec.interpretResponse(noBidResponse); expect(result.length).to.equal(0); }); diff --git a/test/spec/modules/xhbBidAdapter_spec.js b/test/spec/modules/xhbBidAdapter_spec.js index 98bc744224c..e48d3011ed2 100644 --- a/test/spec/modules/xhbBidAdapter_spec.js +++ b/test/spec/modules/xhbBidAdapter_spec.js @@ -5,16 +5,16 @@ import { deepClone } from 'src/utils'; const ENDPOINT = '//ib.adnxs.com/ut/v3/prebid'; -describe('xhbAdapter', () => { +describe('xhbAdapter', function () { const adapter = newBidder(spec); - describe('inherited functions', () => { - it('exists and is a function', () => { + describe('inherited functions', function () { + it('exists and is a function', function () { expect(adapter.callBids).to.exist.and.to.be.a('function'); }); }); - describe('isBidRequestValid', () => { + describe('isBidRequestValid', function () { let bid = { 'bidder': 'xhb', 'params': { @@ -27,11 +27,11 @@ describe('xhbAdapter', () => { 'auctionId': '1d1a030790a475', }; - it('should return true when required params found', () => { + it('should return true when required params found', function () { expect(spec.isBidRequestValid(bid)).to.equal(true); }); - it('should return true when required params found', () => { + it('should return true when required params found', function () { let bid = Object.assign({}, bid); delete bid.params; bid.params = { @@ -42,7 +42,7 @@ describe('xhbAdapter', () => { expect(spec.isBidRequestValid(bid)).to.equal(true); }); - it('should return false when required params are not passed', () => { + it('should return false when required params are not passed', function () { let bid = Object.assign({}, bid); delete bid.params; bid.params = { @@ -52,7 +52,7 @@ describe('xhbAdapter', () => { }); }); - describe('buildRequests', () => { + describe('buildRequests', function () { let bidRequests = [ { 'bidder': 'xhb', @@ -67,7 +67,7 @@ describe('xhbAdapter', () => { } ]; - it('should parse out private sizes', () => { + it('should parse out private sizes', function () { let bidRequest = Object.assign({}, bidRequests[0], { @@ -85,7 +85,7 @@ describe('xhbAdapter', () => { expect(payload.tags[0].private_sizes).to.deep.equal([{width: 300, height: 250}]); }); - it('should add source and verison to the tag', () => { + it('should add source and verison to the tag', function () { const request = spec.buildRequests(bidRequests); const payload = JSON.parse(request.data); expect(payload.sdk).to.exist; @@ -95,7 +95,7 @@ describe('xhbAdapter', () => { }); }); - it('should populate the ad_types array on all requests', () => { + it('should populate the ad_types array on all requests', function () { ['banner', 'video', 'native'].forEach(type => { const bidRequest = Object.assign({}, bidRequests[0]); bidRequest.mediaTypes = {}; @@ -108,7 +108,7 @@ describe('xhbAdapter', () => { }); }); - it('should populate the ad_types array on outstream requests', () => { + it('should populate the ad_types array on outstream requests', function () { const bidRequest = Object.assign({}, bidRequests[0]); bidRequest.mediaTypes = {}; bidRequest.mediaTypes.video = {context: 'outstream'}; @@ -119,13 +119,13 @@ describe('xhbAdapter', () => { expect(payload.tags[0].ad_types).to.deep.equal(['video']); }); - it('sends bid request to ENDPOINT via POST', () => { + it('sends bid request to ENDPOINT via POST', function () { const request = spec.buildRequests(bidRequests); expect(request.url).to.equal(ENDPOINT); expect(request.method).to.equal('POST'); }); - it('should attach valid video params to the tag', () => { + it('should attach valid video params to the tag', function () { let bidRequest = Object.assign({}, bidRequests[0], { @@ -148,7 +148,7 @@ describe('xhbAdapter', () => { }); }); - it('should attach valid user params to the tag', () => { + it('should attach valid user params to the tag', function () { let bidRequest = Object.assign({}, bidRequests[0], { @@ -171,7 +171,7 @@ describe('xhbAdapter', () => { }); }); - it('should attach native params to the request', () => { + it('should attach native params to the request', function () { let bidRequest = Object.assign({}, bidRequests[0], { @@ -198,7 +198,7 @@ describe('xhbAdapter', () => { }); }); - it('sets minimum native asset params when not provided on adunit', () => { + it('sets minimum native asset params when not provided on adunit', function () { let bidRequest = Object.assign({}, bidRequests[0], { @@ -217,7 +217,7 @@ describe('xhbAdapter', () => { }); }); - it('does not overwrite native ad unit params with mimimum params', () => { + it('does not overwrite native ad unit params with mimimum params', function () { let bidRequest = Object.assign({}, bidRequests[0], { @@ -249,7 +249,7 @@ describe('xhbAdapter', () => { }); }); - it('should convert keyword params to proper form and attaches to request', () => { + it('should convert keyword params to proper form and attaches to request', function () { let bidRequest = Object.assign({}, bidRequests[0], { @@ -288,7 +288,7 @@ describe('xhbAdapter', () => { }]); }); - it('should add payment rules to the request', () => { + it('should add payment rules to the request', function () { let bidRequest = Object.assign({}, bidRequests[0], { @@ -305,7 +305,7 @@ describe('xhbAdapter', () => { expect(payload.tags[0].use_pmt_rule).to.equal(true); }); - it('should add gdpr consent information to the request', () => { + it('should add gdpr consent information to the request', function () { let consentString = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A=='; let bidderRequest = { 'bidderCode': 'xhb', @@ -328,7 +328,7 @@ describe('xhbAdapter', () => { }); }); - describe('interpretResponse', () => { + describe('interpretResponse', function () { let response = { 'version': '3.0.0', 'tags': [ @@ -373,7 +373,7 @@ describe('xhbAdapter', () => { ] }; - it('should get correct bid response', () => { + it('should get correct bid response', function () { let expectedResponse = [ { 'requestId': '3db3773286ee59', @@ -397,7 +397,7 @@ describe('xhbAdapter', () => { expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])); }); - it('handles nobid responses', () => { + it('handles nobid responses', function () { let response = { 'version': '0.0.1', 'tags': [{ @@ -413,7 +413,7 @@ describe('xhbAdapter', () => { expect(result.length).to.equal(0); }); - it('handles non-banner media responses', () => { + it('handles non-banner media responses', function () { let response = { 'tags': [{ 'uuid': '84ab500420319d', @@ -437,7 +437,7 @@ describe('xhbAdapter', () => { expect(result[0]).to.have.property('mediaType', 'video'); }); - it('handles native responses', () => { + it('handles native responses', function () { let response1 = deepClone(response); response1.tags[0].ads[0].ad_type = 'native'; response1.tags[0].ads[0].rtb.native = { @@ -471,7 +471,7 @@ describe('xhbAdapter', () => { expect(result[0].native.image.url).to.equal('http://cdn.adnxs.com/img.png'); }); - it('supports configuring outstream renderers', () => { + it('supports configuring outstream renderers', function () { const outstreamResponse = deepClone(response); outstreamResponse.tags[0].ads[0].rtb.video = {}; outstreamResponse.tags[0].ads[0].renderer_url = 'renderer.js'; diff --git a/test/spec/modules/gambidBidAdapter_spec.js b/test/spec/modules/yieldNexusBidAdapter_spec.js similarity index 67% rename from test/spec/modules/gambidBidAdapter_spec.js rename to test/spec/modules/yieldNexusBidAdapter_spec.js index 4c15d2113f1..b966d890e7a 100644 --- a/test/spec/modules/gambidBidAdapter_spec.js +++ b/test/spec/modules/yieldNexusBidAdapter_spec.js @@ -1,52 +1,44 @@ import { expect } from 'chai'; -import { spec } from 'modules/gambidBidAdapter'; +import { spec } from 'modules/yieldNexusBidAdapter'; import * as utils from 'src/utils'; -const supplyPartnerId = '123'; +const spid = '123'; -describe('GambidAdapter', () => { +describe('YieldNexusAdapter', () => { describe('isBidRequestValid', () => { - it('should validate supply-partner ID', () => { + it('should validate supply', () => { expect(spec.isBidRequestValid({ params: {} })).to.equal(false); - expect(spec.isBidRequestValid({ params: { supplyPartnerId: 123 } })).to.equal(false); - expect(spec.isBidRequestValid({ params: { supplyPartnerId: '123' } })).to.equal(true); - }); - it('should validate RTB endpoint', () => { - expect(spec.isBidRequestValid({ params: { supplyPartnerId: '123' } })).to.equal(true); // RTB endpoint has a default - expect(spec.isBidRequestValid({ params: { supplyPartnerId: '123', rtbEndpoint: 123 } })).to.equal(false); - expect(spec.isBidRequestValid({ params: { supplyPartnerId: '123', rtbEndpoint: 'https://some.url.com' } })).to.equal(true); + expect(spec.isBidRequestValid({ params: { spid: 123 } })).to.equal(false); + expect(spec.isBidRequestValid({ params: { spid: '123' } })).to.equal(true); }); it('should validate bid floor', () => { - expect(spec.isBidRequestValid({ params: { supplyPartnerId: '123' } })).to.equal(true); // bidfloor has a default - expect(spec.isBidRequestValid({ params: { supplyPartnerId: '123', bidfloor: '123' } })).to.equal(false); - expect(spec.isBidRequestValid({ params: { supplyPartnerId: '123', bidfloor: 0.1 } })).to.equal(true); + expect(spec.isBidRequestValid({ params: { spid: '123' } })).to.equal(true); // bidfloor has a default + expect(spec.isBidRequestValid({ params: { spid: '123', bidfloor: '123' } })).to.equal(false); + expect(spec.isBidRequestValid({ params: { spid: '123', bidfloor: 0.1 } })).to.equal(true); }); it('should validate adpos', () => { - expect(spec.isBidRequestValid({ params: { supplyPartnerId: '123' } })).to.equal(true); // adpos has a default - expect(spec.isBidRequestValid({ params: { supplyPartnerId: '123', adpos: '123' } })).to.equal(false); - expect(spec.isBidRequestValid({ params: { supplyPartnerId: '123', adpos: 0.1 } })).to.equal(true); + expect(spec.isBidRequestValid({ params: { spid: '123' } })).to.equal(true); // adpos has a default + expect(spec.isBidRequestValid({ params: { spid: '123', adpos: '123' } })).to.equal(false); + expect(spec.isBidRequestValid({ params: { spid: '123', adpos: 0.1 } })).to.equal(true); }); it('should validate instl', () => { - expect(spec.isBidRequestValid({ params: { supplyPartnerId: '123' } })).to.equal(true); // adpos has a default - expect(spec.isBidRequestValid({ params: { supplyPartnerId: '123', instl: '123' } })).to.equal(false); - expect(spec.isBidRequestValid({ params: { supplyPartnerId: '123', instl: -1 } })).to.equal(false); - expect(spec.isBidRequestValid({ params: { supplyPartnerId: '123', instl: 0 } })).to.equal(true); - expect(spec.isBidRequestValid({ params: { supplyPartnerId: '123', instl: 1 } })).to.equal(true); - expect(spec.isBidRequestValid({ params: { supplyPartnerId: '123', instl: 2 } })).to.equal(false); + expect(spec.isBidRequestValid({ params: { spid: '123' } })).to.equal(true); // adpos has a default + expect(spec.isBidRequestValid({ params: { spid: '123', instl: '123' } })).to.equal(false); + expect(spec.isBidRequestValid({ params: { spid: '123', instl: -1 } })).to.equal(false); + expect(spec.isBidRequestValid({ params: { spid: '123', instl: 0 } })).to.equal(true); + expect(spec.isBidRequestValid({ params: { spid: '123', instl: 1 } })).to.equal(true); + expect(spec.isBidRequestValid({ params: { spid: '123', instl: 2 } })).to.equal(false); }); }); describe('buildRequests', () => { const bidRequest = { 'adUnitCode': 'adunit-code', - 'auctionId': '1d1a030790a475', + 'auctionId': 'fdkhjg3s7ahjja', 'mediaTypes': { banner: {} }, - 'params': { - 'supplyPartnerId': supplyPartnerId - }, - 'sizes': [ [ 300, 250 ], [ 300, 600 ] ], - 'transactionId': 'a123456789' + 'params': { spid }, + 'sizes': [ [ 300, 250 ], [ 300, 600 ] ] }; it('returns an array', () => { @@ -67,18 +59,11 @@ describe('GambidAdapter', () => { expect(response.length).to.equal(2); }); - it('targets correct endpoint', () => { - let response; - - response = spec.buildRequests([ bidRequest ])[ 0 ]; + it('uses yieldnexus dns', () => { + const response = spec.buildRequests([ bidRequest ])[ 0 ]; expect(response.method).to.equal('POST'); - expect(response.url).to.match(new RegExp(`^https://rtb\\.gambid\\.io/r/${supplyPartnerId}/bidr\\?rformat=open_rtb&reqformat=rtb_json&bidder=prebid$`, 'g')); + expect(response.url).to.match(new RegExp(`^https://ssp\\.ynxs\\.io/r/${spid}/bidr\\?bidder=prebid&rformat=open_rtb&reqformat=rtb_json$`, 'g')); expect(response.data.id).to.equal(bidRequest.auctionId); - - const bidRequestWithEndpoint = utils.deepClone(bidRequest); - bidRequestWithEndpoint.params.rtbEndpoint = 'https://rtb2.gambid.io/a12'; - response = spec.buildRequests([ bidRequestWithEndpoint ])[ 0 ]; - expect(response.url).to.match(new RegExp(`^https://rtb2\\.gambid\\.io/a12/r/${supplyPartnerId}/bidr\\?rformat=open_rtb&reqformat=rtb_json&bidder=prebid$`, 'g')); }); it('builds request correctly', () => { @@ -161,28 +146,26 @@ describe('GambidAdapter', () => { describe('interpretResponse', () => { const bannerBidRequest = { 'adUnitCode': 'adunit-code', - 'auctionId': '1d1a030790a475', + 'auctionId': 'fdkhjg3s7ahjja', 'mediaTypes': { banner: {} }, 'params': { - 'supplyPartnerId': supplyPartnerId + 'spid': spid }, 'sizes': [ [ 300, 250 ], [ 300, 600 ] ], - 'transactionId': 'a123456789', 'bidId': '111' }; const videoBidRequest = { 'adUnitCode': 'adunit-code', - 'auctionId': '1d1a030790a475', + 'auctionId': 'fdkhjg3s7ahjja', 'mediaTypes': { video: {} }, 'params': { - 'supplyPartnerId': supplyPartnerId + 'spid': spid }, 'sizes': [ [ 300, 250 ], [ 300, 600 ] ], - 'transactionId': 'a123456789', 'bidId': '111' }; const rtbResponse = { @@ -191,57 +174,46 @@ describe('GambidAdapter', () => { 'cur': 'USD', 'ext': { 'utrk': [ - { 'type': 'iframe', 'url': '//p.gsh.io/user/sync/1' }, - { 'type': 'image', 'url': '//p.gsh.io/user/sync/2' } + { 'type': 'iframe', 'url': '//ssp.ynxs.io/user/sync/1' }, + { 'type': 'image', 'url': '//ssp.ynxs.io/user/sync/2' } ] }, 'seatbid': [ { - 'seat': 'seat1', - 'group': 0, + 'seat': 'testSeatBidA', 'bid': [ { 'id': '0', 'impid': '1', 'price': 2.016, - 'adid': '579ef31bfa788b9d2000d562', - 'nurl': 'https://p.gsh.io/pix/monitoring/win_notice/imp_5b05b9fde4b09084267a556f/im.gif?r=imp_5b05b9fde4b09084267a556f&i=1&a=579ef31bfa788b9d2000d562&b=0&p=${AUCTION_PRICE}', - 'adm': ' ', - 'adomain': [ 'aaa.com' ], - 'cid': '579ef268fa788b9d2000d55c', - 'crid': '579ef31bfa788b9d2000d562', - 'attr': [], + 'adm': '', + 'adomain': [ 'nike.com' ], 'h': 600, 'w': 120, 'ext': { - 'vast_url': 'http://my.vast.com', + 'vast_url': 'http://vast.tag.com', 'utrk': [ - { 'type': 'iframe', 'url': '//p.partner1.io/user/sync/1' } + { 'type': 'iframe', 'url': '//pix.usersync.io/user-sync' } ] } } ] }, { - 'seat': 'seat2', - 'group': 0, + 'seat': 'testSeatBidB', 'bid': [ { 'id': '1', 'impid': '1', 'price': 3, 'adid': '542jlhdfd2112jnjf3x', - 'nurl': 'https://p.gsh.io/pix/monitoring/win_notice/imp_5b05b9fde4b09084267a556f/im.gif?r=imp_5b05b9fde4b09084267a556f&i=1&a=579ef31bfa788b9d2000d562&b=0&p=${AUCTION_PRICE}', - 'adm': ' ', - 'adomain': [ 'bbb.com' ], - 'cid': 'fgdlwjh2498ydjhg1', - 'crid': 'kjh34297ydh2133d', - 'attr': [], + 'adm': '', + 'adomain': [ 'adidas.com' ], 'h': 250, 'w': 300, 'ext': { 'utrk': [ - { 'type': 'image', 'url': '//p.partner2.io/user/sync/1' } + { 'type': 'image', 'url': '//pix.usersync.io/user-sync' } ] } } @@ -249,7 +221,7 @@ describe('GambidAdapter', () => { } ] }; - it('returns an empty array on missing response', () => { + it('fails gracefully on empty response body', () => { let response; response = spec.interpretResponse(undefined, { bidRequest: bannerBidRequest }); @@ -260,7 +232,7 @@ describe('GambidAdapter', () => { expect(Array.isArray(response)).to.equal(true); expect(response.length).to.equal(0); }); - it('aggregates banner bids from all seat bids', () => { + it('collects banner bids', () => { const response = spec.interpretResponse({ body: rtbResponse }, { bidRequest: bannerBidRequest }); expect(Array.isArray(response)).to.equal(true); expect(response.length).to.equal(2); @@ -270,7 +242,7 @@ describe('GambidAdapter', () => { expect(ad0.cpm).to.equal(rtbResponse.seatbid[ 0 ].bid[ 0 ].price); expect(ad0.width).to.equal(rtbResponse.seatbid[ 0 ].bid[ 0 ].w); expect(ad0.height).to.equal(rtbResponse.seatbid[ 0 ].bid[ 0 ].h); - expect(ad0.ttl).to.equal(60 * 10); + expect(ad0.ttl).to.equal(15 * 60); expect(ad0.creativeId).to.equal(rtbResponse.seatbid[ 0 ].bid[ 0 ].crid); expect(ad0.netRevenue).to.equal(true); expect(ad0.currency).to.equal(rtbResponse.seatbid[ 0 ].bid[ 0 ].cur || rtbResponse.cur || 'USD'); @@ -281,7 +253,7 @@ describe('GambidAdapter', () => { expect(ad1.cpm).to.equal(rtbResponse.seatbid[ 1 ].bid[ 0 ].price); expect(ad1.width).to.equal(rtbResponse.seatbid[ 1 ].bid[ 0 ].w); expect(ad1.height).to.equal(rtbResponse.seatbid[ 1 ].bid[ 0 ].h); - expect(ad1.ttl).to.equal(60 * 10); + expect(ad1.ttl).to.equal(15 * 60); expect(ad1.creativeId).to.equal(rtbResponse.seatbid[ 1 ].bid[ 0 ].crid); expect(ad1.netRevenue).to.equal(true); expect(ad1.currency).to.equal(rtbResponse.seatbid[ 1 ].bid[ 0 ].cur || rtbResponse.cur || 'USD'); @@ -291,7 +263,7 @@ describe('GambidAdapter', () => { // expect(ad1.ad).to.be.an('undefined'); // expect(ad1.vastXml).to.equal(rtbResponse.seatbid[ 1 ].bid[ 0 ].adm); }); - it('aggregates video bids from all seat bids', () => { + it('collects video bids', () => { const response = spec.interpretResponse({ body: rtbResponse }, { bidRequest: videoBidRequest }); expect(Array.isArray(response)).to.equal(true); expect(response.length).to.equal(2); @@ -301,7 +273,7 @@ describe('GambidAdapter', () => { expect(ad0.cpm).to.equal(rtbResponse.seatbid[ 0 ].bid[ 0 ].price); expect(ad0.width).to.equal(rtbResponse.seatbid[ 0 ].bid[ 0 ].w); expect(ad0.height).to.equal(rtbResponse.seatbid[ 0 ].bid[ 0 ].h); - expect(ad0.ttl).to.equal(60 * 10); + expect(ad0.ttl).to.equal(15 * 60); expect(ad0.creativeId).to.equal(rtbResponse.seatbid[ 0 ].bid[ 0 ].crid); expect(ad0.netRevenue).to.equal(true); expect(ad0.currency).to.equal(rtbResponse.seatbid[ 0 ].bid[ 0 ].cur || rtbResponse.cur || 'USD'); @@ -313,7 +285,7 @@ describe('GambidAdapter', () => { expect(ad1.cpm).to.equal(rtbResponse.seatbid[ 1 ].bid[ 0 ].price); expect(ad1.width).to.equal(rtbResponse.seatbid[ 1 ].bid[ 0 ].w); expect(ad1.height).to.equal(rtbResponse.seatbid[ 1 ].bid[ 0 ].h); - expect(ad1.ttl).to.equal(60 * 10); + expect(ad1.ttl).to.equal(15 * 60); expect(ad1.creativeId).to.equal(rtbResponse.seatbid[ 1 ].bid[ 0 ].crid); expect(ad1.netRevenue).to.equal(true); expect(ad1.currency).to.equal(rtbResponse.seatbid[ 1 ].bid[ 0 ].cur || rtbResponse.cur || 'USD'); @@ -321,7 +293,7 @@ describe('GambidAdapter', () => { expect(ad1.vastXml).to.equal(rtbResponse.seatbid[ 1 ].bid[ 0 ].adm); expect(ad1.vastUrl).to.equal(rtbResponse.seatbid[ 1 ].bid[ 0 ].ext.vast_url); }); - it('aggregates user-sync pixels', () => { + it('applies user-syncs', () => { const response = spec.getUserSyncs({}, [ { body: rtbResponse } ]); expect(Array.isArray(response)).to.equal(true); expect(response.length).to.equal(4); diff --git a/test/spec/modules/yieldbotBidAdapter_spec.js b/test/spec/modules/yieldbotBidAdapter_spec.js index 2977e4ef30d..2548bb31fdc 100644 --- a/test/spec/modules/yieldbotBidAdapter_spec.js +++ b/test/spec/modules/yieldbotBidAdapter_spec.js @@ -1,7 +1,7 @@ import { expect } from 'chai'; import find from 'core-js/library/fn/array/find'; import { newBidder } from 'src/adapters/bidderFactory'; -import AdapterManager from 'src/adaptermanager'; +import AdapterManager from 'src/adapterManager'; import { newAuctionManager } from 'src/auctionManager'; import * as utils from 'src/utils'; import * as urlUtils from 'src/url'; @@ -1059,6 +1059,16 @@ describe('Yieldbot Adapter Unit Tests', function() { expect(edgeServerUrlPrefix).to.match(beginsRegex); expect(responses[0].ad).to.match(containsRegex); }); + + it('should not use document.open() in ad markup', function() { + FIXTURE_SERVER_RESPONSE.body.url_prefix = 'http://close.edge.adserver.com/'; + const responses = YieldbotAdapter.interpretResponse( + FIXTURE_SERVER_RESPONSE, + FIXTURE_BID_REQUEST + ); + expect(responses[0].ad).to.not.match(/var innerFrameDoc=innerFrame\.contentWindow\.document;innerFrameDoc\.open\(\);innerFrameDoc\.write\(iframeHtml\);innerFrameDoc\.close\(\);/); + expect(responses[0].ad).to.match(/var innerFrameDoc=innerFrame\.contentWindow\.document;innerFrameDoc\.write\(iframeHtml\);innerFrameDoc\.close\(\);/); + }); }); describe('getUserSyncs', function() { diff --git a/test/spec/modules/yieldlabBidAdapter_spec.js b/test/spec/modules/yieldlabBidAdapter_spec.js index a58a10ae153..497e9c7b894 100644 --- a/test/spec/modules/yieldlabBidAdapter_spec.js +++ b/test/spec/modules/yieldlabBidAdapter_spec.js @@ -29,17 +29,17 @@ const RESPONSE = { pid: 2222 } -describe('yieldlabBidAdapter', () => { +describe('yieldlabBidAdapter', function () { const adapter = newBidder(spec) - describe('inherited functions', () => { - it('exists and is a function', () => { + describe('inherited functions', function () { + it('exists and is a function', function () { expect(adapter.callBids).to.exist.and.to.be.a('function') }) }) - describe('isBidRequestValid', () => { - it('should return true when required params found', () => { + describe('isBidRequestValid', function () { + it('should return true when required params found', function () { const request = { 'params': { 'adslotId': '1111', @@ -50,24 +50,24 @@ describe('yieldlabBidAdapter', () => { expect(spec.isBidRequestValid(request)).to.equal(true) }) - it('should return false when required params are not passed', () => { + it('should return false when required params are not passed', function () { expect(spec.isBidRequestValid({})).to.equal(false) }) }) - describe('buildRequests', () => { + describe('buildRequests', function () { const bidRequests = [REQUEST] const request = spec.buildRequests(bidRequests) - it('sends bid request to ENDPOINT via GET', () => { + it('sends bid request to ENDPOINT via GET', function () { expect(request.method).to.equal('GET') }) - it('returns a list of valid requests', () => { + it('returns a list of valid requests', function () { expect(request.validBidRequests).to.eql([REQUEST]) }) - it('passes targeting to bid request', () => { + it('passes targeting to bid request', function () { expect(request.url).to.include('t=key1%3Dvalue1%26key2%3Dvalue2') }) @@ -78,24 +78,43 @@ describe('yieldlabBidAdapter', () => { } }) - it('passes gdpr flag and consent if present', () => { + it('passes gdpr flag and consent if present', function () { expect(gdprRequest.url).to.include('consent=BN5lERiOMYEdiAKAWXEND1AAAAE6DABACMA') expect(gdprRequest.url).to.include('gdpr=true') }) }) - describe('interpretResponse', () => { - const validRequests = { - validBidRequests: [REQUEST] - } - - it('handles nobid responses', () => { + describe('interpretResponse', function () { + it('handles nobid responses', function () { expect(spec.interpretResponse({body: {}}, {validBidRequests: []}).length).to.equal(0) expect(spec.interpretResponse({body: []}, {validBidRequests: []}).length).to.equal(0) }) - it('should get correct bid response', () => { - const result = spec.interpretResponse({body: [RESPONSE]}, validRequests) + it('should get correct bid response', function () { + const result = spec.interpretResponse({body: [RESPONSE]}, {validBidRequests: [REQUEST]}) + + expect(result[0].requestId).to.equal('2d925f27f5079f') + expect(result[0].cpm).to.equal(0.01) + expect(result[0].width).to.equal(728) + expect(result[0].height).to.equal(90) + expect(result[0].creativeId).to.equal('1111') + expect(result[0].dealId).to.equal(2222) + expect(result[0].currency).to.equal('EUR') + expect(result[0].netRevenue).to.equal(false) + expect(result[0].ttl).to.equal(300) + expect(result[0].referrer).to.equal('') + expect(result[0].ad).to.include('
', - creativeId: '9874652394875' + creative_id: '9874652394875' }], header: 'header?' }; }) - it('should correctly reorder the server response', () => { + it('should correctly reorder the server response', function () { const newResponse = spec.interpretResponse(serverResponse); expect(newResponse.length).to.be.equal(1); expect(newResponse[0]).to.deep.equal({ @@ -126,7 +126,7 @@ describe('YieldmoAdapter', () => { }); }); - it('should not add responses if the cpm is 0 or null', () => { + it('should not add responses if the cpm is 0 or null', function () { serverResponse.body[0].cpm = 0; let response = spec.interpretResponse(serverResponse); expect(response).to.deep.equal([]); @@ -137,14 +137,14 @@ describe('YieldmoAdapter', () => { }); }); - describe('getUserSync', () => { + describe('getUserSync', function () { const SYNC_ENDPOINT = 'https://static.yieldmo.com/blank.min.html?orig='; let options = { iframeEnabled: true, pixelEnabled: true }; - it('should return a tracker with type and url as parameters', () => { + it('should return a tracker with type and url as parameters', function () { if (/iPhone|iPad|iPod/i.test(window.navigator.userAgent)) { expect(spec.getUserSync(options)).to.deep.equal([{ type: 'iframe', diff --git a/test/spec/modules/yieldoneBidAdapter_spec.js b/test/spec/modules/yieldoneBidAdapter_spec.js index e763257f097..19756b86bc1 100644 --- a/test/spec/modules/yieldoneBidAdapter_spec.js +++ b/test/spec/modules/yieldoneBidAdapter_spec.js @@ -3,52 +3,49 @@ import { spec } from 'modules/yieldoneBidAdapter'; import { newBidder } from 'src/adapters/bidderFactory'; const ENDPOINT = '//y.one.impact-ad.jp/h_bid'; +const USER_SYNC_URL = '//y.one.impact-ad.jp/push_sync'; describe('yieldoneBidAdapter', function() { const adapter = newBidder(spec); - describe('isBidRequestValid', () => { + describe('isBidRequestValid', function () { let bid = { 'bidder': 'yieldone', 'params': { - placementId: '44082' + placementId: '36891' }, 'adUnitCode': 'adunit-code', - 'sizes': [ - [300, 250] - ], + 'sizes': [[300, 250], [336, 280]], 'bidId': '23beaa6af6cdde', 'bidderRequestId': '19c0c1efdf37e7', 'auctionId': '61466567-d482-4a16-96f0-fe5f25ffbdf1', }; - it('should return true when required params found', () => { + it('should return true when required params found', function () { expect(spec.isBidRequestValid(bid)).to.equal(true); }); - it('should return false when placementId not passed correctly', () => { + it('should return false when placementId not passed correctly', function () { bid.params.placementId = ''; expect(spec.isBidRequestValid(bid)).to.equal(false); }); - it('should return false when require params are not passed', () => { + it('should return false when require params are not passed', function () { let bid = Object.assign({}, bid); bid.params = {}; expect(spec.isBidRequestValid(bid)).to.equal(false); }); }); - describe('buildRequests', () => { + describe('buildRequests', function () { let bidRequests = [ { 'bidder': 'yieldone', 'params': { - placementId: '44082' + placementId: '36891' }, 'adUnitCode': 'adunit-code1', - 'sizes': [ - [300, 250] - ], + 'sizes': [[300, 250], [336, 280]], 'bidId': '23beaa6af6cdde', 'bidderRequestId': '19c0c1efdf37e7', 'auctionId': '61466567-d482-4a16-96f0-fe5f25ffbdf1', @@ -56,12 +53,10 @@ describe('yieldoneBidAdapter', function() { { 'bidder': 'yieldone', 'params': { - placementId: '44337' + placementId: '47919' }, 'adUnitCode': 'adunit-code2', - 'sizes': [ - [300, 250] - ], + 'sizes': [[300, 250]], 'bidId': '382091349b149f"', 'bidderRequestId': '"1f9c98192de251"', 'auctionId': '61466567-d482-4a16-96f0-fe5f25ffbdf1', @@ -70,27 +65,40 @@ describe('yieldoneBidAdapter', function() { const request = spec.buildRequests(bidRequests); - it('sends bid request to our endpoint via GET', () => { + it('sends bid request to our endpoint via GET', function () { expect(request[0].method).to.equal('GET'); expect(request[1].method).to.equal('GET'); }); - it('attaches source and version to endpoint URL as query params', () => { + it('attaches source and version to endpoint URL as query params', function () { expect(request[0].url).to.equal(ENDPOINT); expect(request[1].url).to.equal(ENDPOINT); }); + + it('parameter sz has more than one size on banner requests', function () { + expect(request[0].data.sz).to.equal('300x250,336x280'); + expect(request[1].data.sz).to.equal('300x250'); + }); + + it('width and height should be set as separate parameters on outstream requests', function () { + const bidRequest = Object.assign({}, bidRequests[0]); + bidRequest.mediaTypes = {}; + bidRequest.mediaTypes.video = {context: 'outstream'}; + const request = spec.buildRequests([bidRequest]); + expect(request[0].data.w).to.equal('300'); + expect(request[0].data.h).to.equal('250'); + }); }); - describe('interpretResponse', () => { - let bidRequest = [ + describe('interpretResponse', function () { + let bidRequestBanner = [ { 'method': 'GET', 'url': '//y.one.impact-ad.jp/h_bid', 'data': { 'v': 'hb1', - 'p': '44082', - 'w': '300', - 'h': '250', + 'p': '36891', + 'sz': '300x250,336x280', 'cb': 12892917383, 'r': 'http%3A%2F%2Flocalhost%3A9876%2F%3Fid%3D74552836', 'uid': '23beaa6af6cdde', @@ -99,37 +107,92 @@ describe('yieldoneBidAdapter', function() { } ]; - let serverResponse = { + let serverResponseBanner = { body: { 'adTag': '', + 'uid': '23beaa6af6cdde', + 'height': 250, + 'width': 300, 'cpm': 0.0536616, 'crid': '2494768', + 'currency': 'JPY', 'statusMessage': 'Bid available', - 'uid': '23beaa6af6cdde', - 'width': 300, - 'height': 250 + 'dealId': 'P1-FIX-7800-DSP-MON' } }; - it('should get the correct bid response', () => { + it('should get the correct bid response for banner', function () { let expectedResponse = [{ 'requestId': '23beaa6af6cdde', 'cpm': 53.6616, 'width': 300, 'height': 250, 'creativeId': '2494768', - 'dealId': '', + 'dealId': 'P1-FIX-7800-DSP-MON', 'currency': 'JPY', 'netRevenue': true, 'ttl': 3000, 'referrer': '', + 'mediaType': 'banner', 'ad': '' }]; - let result = spec.interpretResponse(serverResponse, bidRequest[0]); - expect(Object.keys(result)).to.deep.equal(Object.keys(expectedResponse)); + let result = spec.interpretResponse(serverResponseBanner, bidRequestBanner[0]); + expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse[0])); + expect(result[0].mediaType).to.equal(expectedResponse[0].mediaType); + }); + + let serverResponseVideo = { + body: { + 'uid': '23beaa6af6cdde', + 'height': 360, + 'width': 640, + 'cpm': 0.0536616, + 'dealId': 'P1-FIX-766-DSP-MON', + 'crid': '2494768', + 'currency': 'JPY', + 'statusMessage': 'Bid available', + 'adm': '' + } + }; + + let bidRequestVideo = [ + { + 'method': 'GET', + 'url': '//y.one.impact-ad.jp/h_bid', + 'data': { + 'v': 'hb1', + 'p': '41993', + 'w': '640', + 'h': '360', + 'cb': 12892917383, + 'r': 'http%3A%2F%2Flocalhost%3A9876%2F%3Fid%3D74552836', + 'uid': '23beaa6af6cdde', + 't': 'i' + } + } + ]; + + it('should get the correct bid response for video', function () { + let expectedResponse = [{ + 'requestId': '23beaa6af6cdde', + 'cpm': 53.6616, + 'width': 640, + 'height': 360, + 'creativeId': '2494768', + 'dealId': 'P1-FIX-7800-DSP-MON', + 'currency': 'JPY', + 'netRevenue': true, + 'ttl': 3000, + 'referrer': '', + 'mediaType': 'video', + 'vastXml': '' + }]; + let result = spec.interpretResponse(serverResponseVideo, bidRequestVideo[0]); + expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse[0])); + expect(result[0].mediaType).to.equal(expectedResponse[0].mediaType); }); - it('handles empty bid response', () => { + it('handles empty bid response', function () { let response = { body: { 'uid': '2c0b634db95a01', @@ -140,8 +203,22 @@ describe('yieldoneBidAdapter', function() { 'cpm': 0 } }; - let result = spec.interpretResponse(response, bidRequest[0]); + let result = spec.interpretResponse(response, bidRequestBanner[0]); expect(result.length).to.equal(0); }); }); + + describe('getUserSyncs', function () { + it('handles empty sync options', function () { + expect(spec.getUserSyncs({})).to.be.empty; + }); + + it('should return a sync url if iframe syncs are enabled', function () { + expect(spec.getUserSyncs({ + 'iframeEnabled': true + })).to.deep.equal([{ + type: 'iframe', url: USER_SYNC_URL + }]); + }); + }); }); diff --git a/test/spec/modules/yuktamediaAnalyticsAdaptor_spec.js b/test/spec/modules/yuktamediaAnalyticsAdaptor_spec.js index 29d23d66bd2..f6efa077f35 100644 --- a/test/spec/modules/yuktamediaAnalyticsAdaptor_spec.js +++ b/test/spec/modules/yuktamediaAnalyticsAdaptor_spec.js @@ -1,48 +1,48 @@ import yuktamediaAnalyticsAdapter from 'modules/yuktamediaAnalyticsAdapter'; import { expect } from 'chai'; -let adaptermanager = require('src/adaptermanager'); +let adapterManager = require('src/adapterManager').default; let events = require('src/events'); let constants = require('src/constants.json'); -describe('YuktaMedia analytics adapter', () => { +describe('YuktaMedia analytics adapter', function () { let xhr; let requests; - beforeEach(() => { + beforeEach(function () { xhr = sinon.useFakeXMLHttpRequest(); requests = []; xhr.onCreate = request => requests.push(request); sinon.stub(events, 'getEvents').returns([]); }); - afterEach(() => { + afterEach(function () { xhr.restore(); events.getEvents.restore(); }); - describe('track', () => { + describe('track', function () { let initOptions = { pubId: '1', pubKey: 'ZXlKaGJHY2lPaUpJVXpJMU5pSjkuT==' }; - adaptermanager.registerAnalyticsAdapter({ + adapterManager.registerAnalyticsAdapter({ code: 'yuktamedia', adapter: yuktamediaAnalyticsAdapter }); - beforeEach(() => { - adaptermanager.enableAnalytics({ + beforeEach(function () { + adapterManager.enableAnalytics({ provider: 'yuktamedia', options: initOptions }); }); - afterEach(() => { + afterEach(function () { yuktamediaAnalyticsAdapter.disableAnalytics(); }); - it('builds and sends auction data', () => { + it('builds and sends auction data', function () { let auctionTimestamp = 1496510254313; let bidRequest = { 'bidderCode': 'appnexus', diff --git a/test/spec/modules/zedoBidAdapter_spec.js b/test/spec/modules/zedoBidAdapter_spec.js index 6d0ab7c68f6..8e6578d9b2c 100644 --- a/test/spec/modules/zedoBidAdapter_spec.js +++ b/test/spec/modules/zedoBidAdapter_spec.js @@ -1,9 +1,9 @@ import { expect } from 'chai'; import { spec } from 'modules/zedoBidAdapter'; -describe('The ZEDO bidding adapter', () => { - describe('isBidRequestValid', () => { - it('should return false when given an invalid bid', () => { +describe('The ZEDO bidding adapter', function () { + describe('isBidRequestValid', function () { + it('should return false when given an invalid bid', function () { const bid = { bidder: 'zedo', }; @@ -11,7 +11,7 @@ describe('The ZEDO bidding adapter', () => { expect(isValid).to.equal(false); }); - it('should return true when given a channelcode bid', () => { + it('should return true when given a channelcode bid', function () { const bid = { bidder: 'zedo', params: { @@ -24,12 +24,12 @@ describe('The ZEDO bidding adapter', () => { }); }); - describe('buildRequests', () => { + describe('buildRequests', function () { const bidderRequest = { timeout: 3000, }; - it('should properly build a channelCode request for dim Id with type not defined', () => { + it('should properly build a channelCode request for dim Id with type not defined', function () { const bidRequests = [ { bidder: 'zedo', @@ -43,13 +43,13 @@ describe('The ZEDO bidding adapter', () => { }, ]; const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.url).to.match(/^\/\/z2.zedo.com\/asw\/fmb.json/); + expect(request.url).to.match(/^\/\/saxp.zedo.com\/asw\/fmh.json/); expect(request.method).to.equal('GET'); const zedoRequest = request.data; expect(zedoRequest).to.equal('g={"placements":[{"network":20,"channel":0,"width":300,"height":200,"dimension":10,"version":"$prebid.version$","keyword":"","transactionId":"12345667","renderers":[{"name":"display"}]}]}'); }); - it('should properly build a channelCode request for video with type defined', () => { + it('should properly build a channelCode request for video with type defined', function () { const bidRequests = [ { bidder: 'zedo', @@ -68,13 +68,13 @@ describe('The ZEDO bidding adapter', () => { }, ]; const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.url).to.match(/^\/\/z2.zedo.com\/asw\/fmb.json/); + expect(request.url).to.match(/^\/\/saxp.zedo.com\/asw\/fmh.json/); expect(request.method).to.equal('GET'); const zedoRequest = request.data; expect(zedoRequest).to.equal('g={"placements":[{"network":20,"channel":0,"width":640,"height":480,"dimension":85,"version":"$prebid.version$","keyword":"","transactionId":"12345667","renderers":[{"name":"Inarticle"}]}]}'); }); - describe('buildGDPRRequests', () => { + describe('buildGDPRRequests', function () { let consentString = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A=='; const bidderRequest = { timeout: 3000, @@ -84,7 +84,7 @@ describe('The ZEDO bidding adapter', () => { } }; - it('should properly build request with gdpr consent', () => { + it('should properly build request with gdpr consent', function () { const bidRequests = [ { bidder: 'zedo', @@ -104,15 +104,15 @@ describe('The ZEDO bidding adapter', () => { }); }); }); - describe('interpretResponse', () => { - it('should return an empty array when there is bid response', () => { + describe('interpretResponse', function () { + it('should return an empty array when there is bid response', function () { const response = {}; const request = { bidRequests: [] }; const bids = spec.interpretResponse(response, request); expect(bids).to.have.lengthOf(0); }); - it('should properly parse a bid response with no valid creative', () => { + it('should properly parse a bid response with no valid creative', function () { const response = { body: { ad: [ @@ -156,7 +156,7 @@ describe('The ZEDO bidding adapter', () => { expect(bids).to.have.lengthOf(0); }); - it('should properly parse a bid response with valid display creative', () => { + it('should properly parse a bid response with valid display creative', function () { const response = { body: { ad: [ @@ -199,7 +199,7 @@ describe('The ZEDO bidding adapter', () => { expect(bids[0].height).to.equal('600'); }); - it('should properly parse a bid response with valid video creative', () => { + it('should properly parse a bid response with valid video creative', function () { const response = { body: { ad: [ @@ -234,19 +234,22 @@ describe('The ZEDO bidding adapter', () => { }, }] }; + const bids = spec.interpretResponse(response, request); expect(bids).to.have.lengthOf(1); expect(bids[0].requestId).to.equal('ad1d762'); expect(bids[0].cpm).to.equal(0.78); expect(bids[0].width).to.equal('640'); expect(bids[0].height).to.equal('480'); + expect(bids[0].adType).to.equal('VAST'); expect(bids[0].vastXml).to.not.equal(''); expect(bids[0].ad).to.be.an('undefined'); + expect(bids[0].renderer).not.to.be.an('undefined'); }); }); - describe('user sync', () => { - it('should register the iframe sync url', () => { + describe('user sync', function () { + it('should register the iframe sync url', function () { let syncs = spec.getUserSyncs({ iframeEnabled: true }); @@ -255,7 +258,7 @@ describe('The ZEDO bidding adapter', () => { expect(syncs[0].type).to.equal('iframe'); }); - it('should pass gdpr params', () => { + it('should pass gdpr params', function () { let syncs = spec.getUserSyncs({ iframeEnabled: true }, {}, { gdprApplies: false, consentString: 'test' }); @@ -265,4 +268,86 @@ describe('The ZEDO bidding adapter', () => { expect(syncs[0].url).to.contains('gdpr=0'); }); }); + + describe('bid events', function () { + it('should trigger a win pixel', function () { + const bid = { + 'bidderCode': 'zedo', + 'width': '300', + 'height': '250', + 'statusMessage': 'Bid available', + 'adId': '148018fe5e', + 'cpm': 0.5, + 'ad': 'dummy data', + 'ad_id': '12345', + 'sizeId': '15', + 'adResponse': + { + 'creatives': [ + { + 'adId': '12345', + 'height': '480', + 'width': '640', + 'isFoc': true, + 'creativeDetails': { + 'type': 'VAST', + 'adContent': '' + }, + 'seeder': { + 'network': 1234, + 'servedChan': 1234567, + }, + 'cpm': '1200000', + 'servedChan': 1234, + }] + }, + 'params': [{ + 'channelCode': '123456', + 'dimId': '85' + }], + 'requestTimestamp': 1540401686, + 'responseTimestamp': 1540401687, + 'timeToRespond': 6253, + 'pbLg': '0.50', + 'pbMg': '0.50', + 'pbHg': '0.53', + 'adUnitCode': '/123456/header-bid-tag-0', + 'bidder': 'zedo', + 'size': '300x250', + 'adserverTargeting': { + 'hb_bidder': 'zedo', + 'hb_adid': '148018fe5e', + 'hb_pb': '10.00', + } + }; + spec.onBidWon(bid); + spec.onTimeout(bid); + }); + it('should trigger a timeout pixel', function () { + const bid = { + 'bidderCode': 'zedo', + 'width': '300', + 'height': '250', + 'statusMessage': 'Bid available', + 'adId': '148018fe5e', + 'cpm': 0.5, + 'ad': 'dummy data', + 'ad_id': '12345', + 'sizeId': '15', + 'params': [{ + 'channelCode': '123456', + 'dimId': '85' + }], + 'timeout': 1, + 'requestTimestamp': 1540401686, + 'responseTimestamp': 1540401687, + 'timeToRespond': 6253, + 'adUnitCode': '/123456/header-bid-tag-0', + 'bidder': 'zedo', + 'size': '300x250', + }; + spec.onBidWon(bid); + spec.onTimeout(bid); + }); + }); }); diff --git a/test/spec/native_spec.js b/test/spec/native_spec.js index 653f858576f..68653808c06 100644 --- a/test/spec/native_spec.js +++ b/test/spec/native_spec.js @@ -1,5 +1,6 @@ import { expect } from 'chai'; import { fireNativeTrackers, getNativeTargeting, nativeBidIsValid } from 'src/native'; +import CONSTANTS from 'src/constants.json'; const utils = require('src/utils'); const bid = { @@ -15,42 +16,65 @@ const bid = { } }; -describe('native.js', () => { +const bidWithUndefinedFields = { + native: { + title: 'Native Creative', + body: undefined, + cta: undefined, + sponsoredBy: 'AppNexus', + clickUrl: 'https://www.link.example', + clickTrackers: ['https://tracker.example'], + impressionTrackers: ['https://impression.example'], + javascriptTrackers: '' + } +}; + +describe('native.js', function () { let triggerPixelStub; let insertHtmlIntoIframeStub; - beforeEach(() => { + beforeEach(function () { triggerPixelStub = sinon.stub(utils, 'triggerPixel'); insertHtmlIntoIframeStub = sinon.stub(utils, 'insertHtmlIntoIframe'); }); - afterEach(() => { + afterEach(function () { utils.triggerPixel.restore(); utils.insertHtmlIntoIframe.restore(); }); - it('gets native targeting keys', () => { + it('gets native targeting keys', function () { const targeting = getNativeTargeting(bid); - expect(targeting.hb_native_title).to.equal(bid.native.title); - expect(targeting.hb_native_body).to.equal(bid.native.body); - expect(targeting.hb_native_linkurl).to.equal(bid.native.clickUrl); + expect(targeting[CONSTANTS.NATIVE_KEYS.title]).to.equal(bid.native.title); + expect(targeting[CONSTANTS.NATIVE_KEYS.body]).to.equal(bid.native.body); + expect(targeting[CONSTANTS.NATIVE_KEYS.clickUrl]).to.equal(bid.native.clickUrl); + }); + + it('should only include native targeting keys with values', function () { + const targeting = getNativeTargeting(bidWithUndefinedFields); + + expect(Object.keys(targeting)).to.deep.equal([ + CONSTANTS.NATIVE_KEYS.title, + CONSTANTS.NATIVE_KEYS.sponsoredBy, + CONSTANTS.NATIVE_KEYS.clickUrl + ]); }); - it('fires impression trackers', () => { + it('fires impression trackers', function () { fireNativeTrackers({}, bid); sinon.assert.calledOnce(triggerPixelStub); sinon.assert.calledWith(triggerPixelStub, bid.native.impressionTrackers[0]); sinon.assert.calledWith(insertHtmlIntoIframeStub, bid.native.javascriptTrackers); }); - it('fires click trackers', () => { + it('fires click trackers', function () { fireNativeTrackers({ action: 'click' }, bid); sinon.assert.calledOnce(triggerPixelStub); sinon.assert.calledWith(triggerPixelStub, bid.native.clickTrackers[0]); }); }); -describe('validate native', () => { +describe('validate native', function () { let bidReq = [{ bids: [{ bidderCode: 'test_bidder', @@ -149,11 +173,11 @@ describe('validate native', () => { } }; - beforeEach(() => {}); + beforeEach(function () {}); - afterEach(() => {}); + afterEach(function () {}); - it('should reject bid if no image sizes are defined', () => { + it('should reject bid if no image sizes are defined', function () { let result = nativeBidIsValid(validBid, bidReq); expect(result).to.be.true; result = nativeBidIsValid(noIconDimBid, bidReq); diff --git a/test/spec/refererDetection_spec.js b/test/spec/refererDetection_spec.js new file mode 100644 index 00000000000..b2ef4e2058f --- /dev/null +++ b/test/spec/refererDetection_spec.js @@ -0,0 +1,87 @@ +import { detectReferer } from 'src/refererDetection'; +import { expect } from 'chai'; + +var mocks = { + createFakeWindow: function (referrer, href) { + return { + document: { + referrer: referrer + }, + location: { + href: href, + // TODO: add ancestorOrigins to increase test coverage + }, + parent: null, + top: null + }; + } +} + +describe('referer detection', () => { + it('should return referer details in nested friendly iframes', function() { + // Fake window object to test friendly iframes + // - Main page http://example.com/page.html + // - - Iframe1 http://example.com/iframe1.html + // - - - Iframe2 http://example.com/iframe2.html + let mockIframe2WinObject = mocks.createFakeWindow('http://example.com/iframe1.html', 'http://example.com/iframe2.html'); + let mockIframe1WinObject = mocks.createFakeWindow('http://example.com/page.html', 'http://example.com/iframe1.html'); + let mainWinObject = mocks.createFakeWindow('http://example.com/page.html', 'http://example.com/page.html'); + mainWinObject.document.querySelector = function() { + return { + href: 'http://prebid.org' + } + } + mockIframe2WinObject.parent = mockIframe1WinObject; + mockIframe2WinObject.top = mainWinObject; + mockIframe1WinObject.parent = mainWinObject; + mockIframe1WinObject.top = mainWinObject; + mainWinObject.top = mainWinObject; + + const getRefererInfo = detectReferer(mockIframe2WinObject); + let result = getRefererInfo(); + let expectedResult = { + referer: 'http://example.com/page.html', + reachedTop: true, + numIframes: 2, + stack: [ + 'http://example.com/page.html', + 'http://example.com/iframe1.html', + 'http://example.com/iframe2.html' + ], + canonicalUrl: 'http://prebid.org' + }; + expect(result).to.deep.equal(expectedResult); + }); + + it('should return referer details in nested cross domain iframes', function() { + // Fake window object to test cross domain iframes. + // - Main page http://example.com/page.html + // - - Iframe1 http://aaa.com/iframe1.html + // - - - Iframe2 http://bbb.com/iframe2.html + let mockIframe2WinObject = mocks.createFakeWindow('http://aaa.com/iframe1.html', 'http://bbb.com/iframe2.html'); + // Sinon cannot throw exception when accessing a propery so passing null to create cross domain + // environment for refererDetection module + let mockIframe1WinObject = mocks.createFakeWindow(null, null); + let mainWinObject = mocks.createFakeWindow(null, null); + mockIframe2WinObject.parent = mockIframe1WinObject; + mockIframe2WinObject.top = mainWinObject; + mockIframe1WinObject.parent = mainWinObject; + mockIframe1WinObject.top = mainWinObject; + mainWinObject.top = mainWinObject; + + const getRefererInfo = detectReferer(mockIframe2WinObject); + let result = getRefererInfo(); + let expectedResult = { + referer: 'http://aaa.com/iframe1.html', + reachedTop: false, + numIframes: 2, + stack: [ + null, + 'http://aaa.com/iframe1.html', + 'http://bbb.com/iframe2.html' + ], + canonicalUrl: undefined + }; + expect(result).to.deep.equal(expectedResult); + }); +}); diff --git a/test/spec/renderer_spec.js b/test/spec/renderer_spec.js index a511a1b214c..7a7354add31 100644 --- a/test/spec/renderer_spec.js +++ b/test/spec/renderer_spec.js @@ -1,107 +1,131 @@ import { expect } from 'chai'; import { Renderer } from 'src/Renderer'; -const adloader = require('../../src/adloader'); - -describe('Renderer: A renderer installed on a bid response', () => { - let testRenderer1; - let testRenderer2; - let spyRenderFn; - let spyEventHandler; - - let loadScriptStub; - - beforeEach(() => { - loadScriptStub = sinon.stub(adloader, 'loadScript').callsFake((...args) => { - args[1](); +import * as utils from 'src/utils'; + +describe('Renderer', function () { + describe('Renderer: A renderer installed on a bid response', function () { + let testRenderer1; + let testRenderer2; + let spyRenderFn; + let spyEventHandler; + + beforeEach(function () { + testRenderer1 = Renderer.install({ + url: 'https://httpbin.org/post', + config: { test: 'config1' }, + id: 1 + }); + testRenderer2 = Renderer.install({ + url: 'https://httpbin.org/post', + config: { test: 'config2' }, + id: 2 + }); + + spyRenderFn = sinon.spy(); + spyEventHandler = sinon.spy(); }); - testRenderer1 = Renderer.install({ - url: 'https://httpbin.org/post', - config: { test: 'config1' }, - id: 1 + it('is an instance of Renderer', function () { + expect(testRenderer1 instanceof Renderer).to.equal(true); }); - testRenderer2 = Renderer.install({ - url: 'https://httpbin.org/post', - config: { test: 'config2' }, - id: 2 + + it('has expected properties ', function () { + expect(testRenderer1.url).to.equal('https://httpbin.org/post'); + expect(testRenderer1.config).to.deep.equal({ test: 'config1' }); + expect(testRenderer1.id).to.equal(1); }); - spyRenderFn = sinon.spy(); - spyEventHandler = sinon.spy(); - }); + it('returns config from getConfig method', function () { + expect(testRenderer1.getConfig()).to.deep.equal({ test: 'config1' }); + expect(testRenderer2.getConfig()).to.deep.equal({ test: 'config2' }); + }); - afterEach(() => { - loadScriptStub.restore(); - }); + it('sets a render function with setRender method', function () { + testRenderer1.setRender(spyRenderFn); + expect(typeof testRenderer1.render).to.equal('function'); + testRenderer1.render(); + expect(spyRenderFn.called).to.equal(true); + }); - it('is an instance of Renderer', () => { - expect(testRenderer1 instanceof Renderer).to.equal(true); - }); + it('sets event handlers with setEventHandlers method and handles events with installed handlers', function () { + testRenderer1.setEventHandlers({ + testEvent: spyEventHandler + }); - it('has expected properties ', () => { - expect(testRenderer1.url).to.equal('https://httpbin.org/post'); - expect(testRenderer1.config).to.deep.equal({ test: 'config1' }); - expect(testRenderer1.id).to.equal(1); - }); + expect(testRenderer1.handlers).to.deep.equal({ + testEvent: spyEventHandler + }); - it('returns config from getConfig method', () => { - expect(testRenderer1.getConfig()).to.deep.equal({ test: 'config1' }); - expect(testRenderer2.getConfig()).to.deep.equal({ test: 'config2' }); - }); + testRenderer1.handleVideoEvent({ id: 1, eventName: 'testEvent' }); + expect(spyEventHandler.called).to.equal(true); + }); - it('sets a render function with setRender method', () => { - testRenderer1.setRender(spyRenderFn); - expect(typeof testRenderer1.render).to.equal('function'); - testRenderer1.render(); - expect(spyRenderFn.called).to.equal(true); - }); + it('pushes commands to queue if renderer is not loaded', function () { + testRenderer1.loaded = false; + testRenderer1.push(spyRenderFn); + expect(testRenderer1.cmd.length).to.equal(1); - it('sets event handlers with setEventHandlers method and handles events with installed handlers', () => { - testRenderer1.setEventHandlers({ - testEvent: spyEventHandler + // clear queue for next tests + testRenderer1.cmd = []; }); - expect(testRenderer1.handlers).to.deep.equal({ - testEvent: spyEventHandler - }); + it('fires commands immediately if the renderer is loaded', function () { + const func = sinon.spy(); - testRenderer1.handleVideoEvent({ id: 1, eventName: 'testEvent' }); - expect(spyEventHandler.called).to.equal(true); - }); + testRenderer1.loaded = true; + testRenderer1.push(func); - it('pushes commands to queue if renderer is not loaded', () => { - testRenderer1.loaded = false; - testRenderer1.push(spyRenderFn); - expect(testRenderer1.cmd.length).to.equal(1); + expect(testRenderer1.cmd.length).to.equal(0); - // clear queue for next tests - testRenderer1.cmd = []; - }); + sinon.assert.calledOnce(func); + }); - it('fires commands immediately if the renderer is loaded', () => { - const func = sinon.spy(); + it('processes queue by calling each function in queue', function () { + testRenderer1.loaded = false; + const func1 = sinon.spy(); + const func2 = sinon.spy(); - testRenderer1.loaded = true; - testRenderer1.push(func); + testRenderer1.push(func1); + testRenderer1.push(func2); + expect(testRenderer1.cmd.length).to.equal(2); - expect(testRenderer1.cmd.length).to.equal(0); + testRenderer1.process(); - sinon.assert.calledOnce(func); + sinon.assert.calledOnce(func1); + sinon.assert.calledOnce(func2); + expect(testRenderer1.cmd.length).to.equal(0); + }); }); - it('processes queue by calling each function in queue', () => { - testRenderer1.loaded = false; - const func1 = sinon.spy(); - const func2 = sinon.spy(); - - testRenderer1.push(func1); - testRenderer1.push(func2); - expect(testRenderer1.cmd.length).to.equal(2); + describe('3rd party renderer', function () { + let adUnitsOld; + let utilsSpy; + before(function () { + adUnitsOld = $$PREBID_GLOBAL$$.adUnits; + utilsSpy = sinon.spy(utils, 'logWarn'); + }); - testRenderer1.process(); + after(function() { + $$PREBID_GLOBAL$$.adUnits = adUnitsOld; + utilsSpy.restore(); + }); - sinon.assert.calledOnce(func1); - sinon.assert.calledOnce(func2); - expect(testRenderer1.cmd.length).to.equal(0); + it('should not load renderer and log warn message', function() { + $$PREBID_GLOBAL$$.adUnits = [{ + code: 'video1', + renderer: { + url: 'http://cdn.adnxs.com/renderer/video/ANOutstreamVideo.js', + render: sinon.spy() + } + }] + + let testRenderer = Renderer.install({ + url: 'https://httpbin.org/post', + config: { test: 'config1' }, + id: 1, + adUnitCode: 'video1' + }); + expect(utilsSpy.callCount).to.equal(1); + }); }); }); diff --git a/test/spec/sizeMapping_spec.js b/test/spec/sizeMapping_spec.js index 74b86a8c5aa..aca4ccf8f54 100644 --- a/test/spec/sizeMapping_spec.js +++ b/test/spec/sizeMapping_spec.js @@ -1,12 +1,16 @@ import { expect } from 'chai'; -import { resolveStatus, setSizeConfig } from 'src/sizeMapping'; +import { resolveStatus, setSizeConfig, sizeSupported } from 'src/sizeMapping'; import includes from 'core-js/library/fn/array/includes'; let utils = require('src/utils'); let deepClone = utils.deepClone; -describe('sizeMapping', () => { - var testSizes = [[970, 90], [728, 90], [300, 250], [300, 100], [80, 80]]; +describe('sizeMapping', function () { + var testSizes = { + banner: { + sizes: [[970, 90], [728, 90], [300, 250], [300, 100], [80, 80]] + } + }; var sizeConfig = [{ 'mediaQuery': '(min-width: 1200px)', @@ -49,7 +53,7 @@ describe('sizeMapping', () => { let sandbox, matchMediaOverride; - beforeEach(() => { + beforeEach(function () { setSizeConfig(sizeConfig); sandbox = sinon.sandbox.create(); @@ -64,146 +68,177 @@ describe('sizeMapping', () => { }); }); - afterEach(() => { + afterEach(function () { setSizeConfig([]); sandbox.restore(); }); - describe('when handling sizes', () => { - it('should log a warning when mediaQuery property missing from sizeConfig', () => { + describe('when handling sizes', function () { + it('should allow us to validate a single size', function() { + matchMediaOverride = (str) => str === '(min-width: 1200px)' ? {matches: true} : {matches: false}; + + expect(sizeSupported([300, 250])).to.equal(true); + expect(sizeSupported([80, 80])).to.equal(false); + }); + + it('should log a warning when mediaQuery property missing from sizeConfig', function () { let errorConfig = deepClone(sizeConfig); delete errorConfig[0].mediaQuery; sandbox.stub(utils, 'logWarn'); - resolveStatus(undefined, testSizes, errorConfig); + resolveStatus(undefined, testSizes, undefined, errorConfig); expect(utils.logWarn.firstCall.args[0]).to.match(/missing.+?mediaQuery/); }); - it('when one mediaQuery block matches, it should filter the adUnit.sizes passed in', () => { + it('should allow deprecated adUnit.sizes', function() { matchMediaOverride = (str) => str === '(min-width: 1200px)' ? {matches: true} : {matches: false}; - let status = resolveStatus(undefined, testSizes, sizeConfig); + let status = resolveStatus(undefined, undefined, testSizes.banner.sizes, sizeConfig); - expect(status).to.deep.equal({ - active: true, - sizes: [[970, 90], [728, 90], [300, 250]] - }) + expect(status.active).to.equal(true); + expect(status.mediaTypes).to.deep.equal({ + banner: { + sizes: [[970, 90], [728, 90], [300, 250]] + } + }); + }); + + it('when one mediaQuery block matches, it should filter the adUnit.sizes passed in', function () { + matchMediaOverride = (str) => str === '(min-width: 1200px)' ? {matches: true} : {matches: false}; + + let status = resolveStatus(undefined, testSizes, undefined, sizeConfig); + + expect(status.active).to.equal(true); + expect(status.mediaTypes).to.deep.equal({ + banner: { + sizes: [[970, 90], [728, 90], [300, 250]] + } + }); }); - it('when multiple mediaQuery block matches, it should filter a union of the matched sizesSupported', () => { + it('when multiple mediaQuery block matches, it should filter a union of the matched sizesSupported', function () { matchMediaOverride = (str) => includes([ '(min-width: 1200px)', '(min-width: 768px) and (max-width: 1199px)' ], str) ? {matches: true} : {matches: false}; - let status = resolveStatus(undefined, testSizes, sizeConfig); - expect(status).to.deep.equal({ - active: true, - sizes: [[970, 90], [728, 90], [300, 250], [300, 100]] - }) + let status = resolveStatus(undefined, testSizes, undefined, sizeConfig); + expect(status.active).to.equal(true); + expect(status.mediaTypes).to.deep.equal({ + banner: { + sizes: [[970, 90], [728, 90], [300, 250], [300, 100]] + } + }); }); - it('if no mediaQueries match, it should allow all sizes specified', () => { + it('if no mediaQueries match, it should allow all sizes specified', function () { matchMediaOverride = () => ({matches: false}); - let status = resolveStatus(undefined, testSizes, sizeConfig); - expect(status).to.deep.equal({ - active: true, - sizes: testSizes - }) + let status = resolveStatus(undefined, testSizes, undefined, sizeConfig); + expect(status.active).to.equal(true); + expect(status.mediaTypes).to.deep.equal(testSizes); }); - it('if a mediaQuery matches and has sizesSupported: [], it should filter all sizes', () => { + it('if a mediaQuery matches and has sizesSupported: [], it should filter all sizes', function () { matchMediaOverride = (str) => str === '(min-width: 0px) and (max-width: 767px)' ? {matches: true} : {matches: false}; - let status = resolveStatus(undefined, testSizes, sizeConfig); - expect(status).to.deep.equal({ - active: false, - sizes: [] - }) + let status = resolveStatus(undefined, testSizes, undefined, sizeConfig); + expect(status.active).to.equal(false); + expect(status.mediaTypes).to.deep.equal({ + banner: { + sizes: [] + } + }); }); - it('if a mediaQuery matches and no sizesSupported specified, it should not effect adUnit.sizes', () => { + it('should filter all banner sizes but not disable adUnit if multiple mediaTypes are present', function () { + matchMediaOverride = (str) => str === '(min-width: 0px) and (max-width: 767px)' ? {matches: true} : {matches: false}; + + let status = resolveStatus(undefined, Object.assign({}, testSizes, { + native: { + type: 'image' + } + }), undefined, sizeConfig); + expect(status.active).to.equal(true); + expect(status.mediaTypes).to.deep.equal({ + banner: { + sizes: [] + }, + native: { + type: 'image' + } + }); + }); + + it('if a mediaQuery matches and no sizesSupported specified, it should not affect adUnit.sizes', function () { matchMediaOverride = (str) => str === '(min-width: 1200px)' ? {matches: true} : {matches: false}; - let status = resolveStatus(undefined, testSizes, sizeConfigWithLabels); - expect(status).to.deep.equal({ - active: true, - sizes: testSizes - }) + let status = resolveStatus(undefined, testSizes, undefined, sizeConfigWithLabels); + expect(status.active).to.equal(true); + expect(status.mediaTypes).to.deep.equal(testSizes); }); }); - describe('when handling labels', () => { - it('should activate/deactivate adUnits/bidders based on sizeConfig.labels', () => { + describe('when handling labels', function () { + it('should activate/deactivate adUnits/bidders based on sizeConfig.labels', function () { matchMediaOverride = (str) => str === '(min-width: 1200px)' ? {matches: true} : {matches: false}; let status = resolveStatus({ labels: ['desktop'] - }, testSizes, sizeConfigWithLabels); + }, testSizes, undefined, sizeConfigWithLabels); expect(status).to.deep.equal({ active: true, - sizes: testSizes + mediaTypes: testSizes }); status = resolveStatus({ labels: ['tablet'] - }, testSizes, sizeConfigWithLabels); + }, testSizes, undefined, sizeConfigWithLabels); - expect(status).to.deep.equal({ - active: false, - sizes: testSizes - }); + expect(status.active).to.equal(false); + expect(status.mediaTypes).to.deep.equal(testSizes); }); - it('should active/deactivate adUnits/bidders based on requestBids labels', () => { + it('should active/deactivate adUnits/bidders based on requestBids labels', function () { let activeLabels = ['us-visitor', 'desktop', 'smart']; let status = resolveStatus({ labels: ['uk-visitor'], activeLabels - }, testSizes, sizeConfigWithLabels); + }, testSizes, undefined, sizeConfigWithLabels); - expect(status).to.deep.equal({ - active: false, - sizes: testSizes - }); + expect(status.active).to.equal(false); + expect(status.mediaTypes).to.deep.equal(testSizes); status = resolveStatus({ labels: ['us-visitor'], activeLabels - }, testSizes, sizeConfigWithLabels); + }, testSizes, undefined, sizeConfigWithLabels); - expect(status).to.deep.equal({ - active: true, - sizes: testSizes - }); + expect(status.active).to.equal(true); + expect(status.mediaTypes).to.deep.equal(testSizes); status = resolveStatus({ labels: ['us-visitor', 'tablet'], labelAll: true, activeLabels - }, testSizes, sizeConfigWithLabels); + }, testSizes, undefined, sizeConfigWithLabels); - expect(status).to.deep.equal({ - active: false, - sizes: testSizes - }); + expect(status.active).to.equal(false); + expect(status.mediaTypes).to.deep.equal(testSizes); status = resolveStatus({ labels: ['us-visitor', 'desktop'], labelAll: true, activeLabels - }, testSizes, sizeConfigWithLabels); + }, testSizes, undefined, sizeConfigWithLabels); - expect(status).to.deep.equal({ - active: true, - sizes: testSizes - }); + expect(status.active).to.equal(true); + expect(status.mediaTypes).to.deep.equal(testSizes); }); }); }); diff --git a/test/spec/unit/adServerManager_spec.js b/test/spec/unit/adServerManager_spec.js index 72a3b61ce41..928050ee93c 100644 --- a/test/spec/unit/adServerManager_spec.js +++ b/test/spec/unit/adServerManager_spec.js @@ -4,12 +4,12 @@ import { registerVideoSupport } from 'src/adServerManager'; const prebid = getGlobal(); -describe('The ad server manager', () => { - beforeEach(() => { +describe('The ad server manager', function () { + beforeEach(function () { delete prebid.adServers; }); - it('should register video support to the proper place on the API', () => { + it('should register video support to the proper place on the API', function () { function videoSupport() { } registerVideoSupport('dfp', { buildVideoUrl: videoSupport }); @@ -18,7 +18,7 @@ describe('The ad server manager', () => { expect(prebid.adServers.dfp).to.have.property('buildVideoUrl', videoSupport); }); - it('should keep the first function when we try to add a second', () => { + it('should keep the first function when we try to add a second', function () { function videoSupport() { } registerVideoSupport('dfp', { buildVideoUrl: videoSupport }); registerVideoSupport('dfp', { buildVideoUrl: function noop() { } }); diff --git a/test/spec/unit/adUnits_spec.js b/test/spec/unit/adUnits_spec.js new file mode 100644 index 00000000000..ff77315ba4a --- /dev/null +++ b/test/spec/unit/adUnits_spec.js @@ -0,0 +1,23 @@ +import { expect } from 'chai'; +import { adunitCounter } from 'src/adUnits'; + +describe('Adunit Counter', function () { + const ADUNIT_ID_1 = 'test1'; + const ADUNIT_ID_2 = 'test2'; + + it('increments and checks counter of adunit 1', function () { + adunitCounter.incrementCounter(ADUNIT_ID_1); + expect(adunitCounter.getCounter(ADUNIT_ID_1)).to.be.equal(1); + }); + it('checks counter of adunit 2', function () { + expect(adunitCounter.getCounter(ADUNIT_ID_2)).to.be.equal(0); + }); + it('increments and checks counter of adunit 1', function () { + adunitCounter.incrementCounter(ADUNIT_ID_1); + expect(adunitCounter.getCounter(ADUNIT_ID_1)).to.be.equal(2); + }); + it('increments and checks counter of adunit 2', function () { + adunitCounter.incrementCounter(ADUNIT_ID_2); + expect(adunitCounter.getCounter(ADUNIT_ID_2)).to.be.equal(1); + }); +}); diff --git a/test/spec/unit/core/adapterManager_spec.js b/test/spec/unit/core/adapterManager_spec.js index 51b34f8d1b8..31209bbf9c7 100644 --- a/test/spec/unit/core/adapterManager_spec.js +++ b/test/spec/unit/core/adapterManager_spec.js @@ -1,6 +1,8 @@ import { expect } from 'chai'; -import AdapterManager from 'src/adaptermanager'; -import { checkBidRequestSizes } from 'src/adaptermanager'; +import adapterManager, { + gdprDataHandler, + checkBidRequestSizes +} from 'src/adapterManager'; import { getAdUnits } from 'test/fixtures/fixtures'; import CONSTANTS from 'src/constants.json'; import * as utils from 'src/utils'; @@ -9,9 +11,8 @@ import { registerBidder } from 'src/adapters/bidderFactory'; import { setSizeConfig } from 'src/sizeMapping'; import find from 'core-js/library/fn/array/find'; import includes from 'core-js/library/fn/array/includes'; -var s2sTesting = require('../../../../modules/s2sTesting'); +import s2sTesting from 'modules/s2sTesting'; var events = require('../../../../src/events'); -const adloader = require('../../../../src/adloader'); const CONFIG = { enabled: true, @@ -39,49 +40,44 @@ var rubiconAdapterMock = { bidder: 'rubicon', callBids: sinon.stub() }; -let loadScriptStub; -describe('adapterManager tests', () => { +describe('adapterManager tests', function () { let orgAppnexusAdapter; let orgAdequantAdapter; let orgPrebidServerAdapter; let orgRubiconAdapter; - before(() => { - orgAppnexusAdapter = AdapterManager.bidderRegistry['appnexus']; - orgAdequantAdapter = AdapterManager.bidderRegistry['adequant']; - orgPrebidServerAdapter = AdapterManager.bidderRegistry['prebidServer']; - orgRubiconAdapter = AdapterManager.bidderRegistry['rubicon']; - loadScriptStub = sinon.stub(adloader, 'loadScript').callsFake((...args) => { - args[1](); - }); + before(function () { + orgAppnexusAdapter = adapterManager.bidderRegistry['appnexus']; + orgAdequantAdapter = adapterManager.bidderRegistry['adequant']; + orgPrebidServerAdapter = adapterManager.bidderRegistry['prebidServer']; + orgRubiconAdapter = adapterManager.bidderRegistry['rubicon']; }); - after(() => { - AdapterManager.bidderRegistry['appnexus'] = orgAppnexusAdapter; - AdapterManager.bidderRegistry['adequant'] = orgAdequantAdapter; - AdapterManager.bidderRegistry['prebidServer'] = orgPrebidServerAdapter; - AdapterManager.bidderRegistry['rubicon'] = orgRubiconAdapter; - loadScriptStub.restore(); + after(function () { + adapterManager.bidderRegistry['appnexus'] = orgAppnexusAdapter; + adapterManager.bidderRegistry['adequant'] = orgAdequantAdapter; + adapterManager.bidderRegistry['prebidServer'] = orgPrebidServerAdapter; + adapterManager.bidderRegistry['rubicon'] = orgRubiconAdapter; config.setConfig({s2sConfig: { enabled: false }}); }); - describe('callBids', () => { - before(() => { + describe('callBids', function () { + before(function () { config.setConfig({s2sConfig: { enabled: false }}); }); - beforeEach(() => { + beforeEach(function () { sinon.stub(utils, 'logError'); appnexusAdapterMock.callBids.reset(); - AdapterManager.bidderRegistry['appnexus'] = appnexusAdapterMock; + adapterManager.bidderRegistry['appnexus'] = appnexusAdapterMock; }); - afterEach(() => { + afterEach(function () { utils.logError.restore(); - delete AdapterManager.bidderRegistry['appnexus']; + delete adapterManager.bidderRegistry['appnexus']; }); - it('should log an error if a bidder is used that does not exist', () => { + it('should log an error if a bidder is used that does not exist', function () { const adUnits = [{ code: 'adUnit-code', sizes: [[728, 90]], @@ -91,13 +87,13 @@ describe('adapterManager tests', () => { ] }]; - let bidRequests = AdapterManager.makeBidRequests(adUnits, 1111, 2222, 1000); + let bidRequests = adapterManager.makeBidRequests(adUnits, 1111, 2222, 1000); expect(bidRequests.length).to.equal(1); expect(bidRequests[0].bidderCode).to.equal('appnexus'); sinon.assert.called(utils.logError); }); - it('should emit BID_REQUESTED event', () => { + it('should emit BID_REQUESTED event', function () { // function to count BID_REQUESTED events let cnt = 0; let count = () => cnt++; @@ -133,21 +129,123 @@ describe('adapterManager tests', () => { {bidder: 'appnexus', params: {placementId: 'id'}}, ] }]; - AdapterManager.callBids(adUnits, bidRequests, () => {}, () => {}); + adapterManager.callBids(adUnits, bidRequests, () => {}, () => {}); expect(cnt).to.equal(1); sinon.assert.calledOnce(appnexusAdapterMock.callBids); events.off(CONSTANTS.EVENTS.BID_REQUESTED, count); }); }); - describe('S2S tests', () => { - beforeEach(() => { + describe('callTimedOutBidders', function () { + var criteoSpec = { onTimeout: sinon.stub() } + var criteoAdapter = { + bidder: 'criteo', + getSpec: function() { return criteoSpec; } + } + before(function () { + config.setConfig({s2sConfig: { enabled: false }}); + }); + + beforeEach(function () { + adapterManager.bidderRegistry['criteo'] = criteoAdapter; + }); + + afterEach(function () { + delete adapterManager.bidderRegistry['criteo']; + }); + + it('should call spec\'s onTimeout callback when callTimedOutBidders is called', function () { + const adUnits = [{ + code: 'adUnit-code', + sizes: [[728, 90]], + bids: [ + {bidder: 'criteo', params: {placementId: 'id'}}, + ] + }]; + const timedOutBidders = [{ + bidId: 'bidId', + bidder: 'criteo', + adUnitCode: adUnits[0].code, + auctionId: 'auctionId', + }]; + adapterManager.callTimedOutBidders(adUnits, timedOutBidders, CONFIG.timeout); + sinon.assert.called(criteoSpec.onTimeout); + }); + }); // end callTimedOutBidders + + describe('onBidWon', function () { + var criteoSpec = { onBidWon: sinon.stub() } + var criteoAdapter = { + bidder: 'criteo', + getSpec: function() { return criteoSpec; } + } + before(function () { + config.setConfig({s2sConfig: { enabled: false }}); + }); + + beforeEach(function () { + adapterManager.bidderRegistry['criteo'] = criteoAdapter; + }); + + afterEach(function () { + delete adapterManager.bidderRegistry['criteo']; + }); + + it('should call spec\'s onBidWon callback when a bid is won', function () { + const bids = [ + {bidder: 'criteo', params: {placementId: 'id'}}, + ]; + const adUnits = [{ + code: 'adUnit-code', + sizes: [[728, 90]], + bids + }]; + + adapterManager.callBidWonBidder(bids[0].bidder, bids[0], adUnits); + sinon.assert.called(criteoSpec.onBidWon); + }); + }); // end onBidWon + + describe('onSetTargeting', function () { + var criteoSpec = { onSetTargeting: sinon.stub() } + var criteoAdapter = { + bidder: 'criteo', + getSpec: function() { return criteoSpec; } + } + before(function () { + config.setConfig({s2sConfig: { enabled: false }}); + }); + + beforeEach(function () { + adapterManager.bidderRegistry['criteo'] = criteoAdapter; + }); + + afterEach(function () { + delete adapterManager.bidderRegistry['criteo']; + }); + + it('should call spec\'s onSetTargeting callback when setTargeting is called', function () { + const bids = [ + {bidder: 'criteo', params: {placementId: 'id'}}, + ]; + const adUnits = [{ + code: 'adUnit-code', + sizes: [[728, 90]], + bids + }]; + adapterManager.callSetTargetingBidder(bids[0].bidder, bids[0], adUnits); + sinon.assert.called(criteoSpec.onSetTargeting); + }); + }); // end onSetTargeting + + describe('S2S tests', function () { + beforeEach(function () { config.setConfig({s2sConfig: CONFIG}); - AdapterManager.bidderRegistry['prebidServer'] = prebidServerAdapterMock; + adapterManager.bidderRegistry['prebidServer'] = prebidServerAdapterMock; prebidServerAdapterMock.callBids.reset(); }); - it('invokes callBids on the S2S adapter', () => { + it('invokes callBids on the S2S adapter', function () { let bidRequests = [{ 'bidderCode': 'appnexus', 'auctionId': '1863e370099523', @@ -175,7 +273,7 @@ describe('adapterManager tests', () => { 'placementId': '543221', 'test': 'me' }, - 'placementCode': '/19968336/header-bid-tag1', + 'adUnitCode': '/19968336/header-bid-tag1', 'sizes': [ [ 728, @@ -213,7 +311,7 @@ describe('adapterManager tests', () => { 'params': { 'placementId': '5324321' }, - 'placementCode': '/19968336/header-bid-tag-0', + 'adUnitCode': '/19968336/header-bid-tag-0', 'sizes': [ [ 300, @@ -285,7 +383,7 @@ describe('adapterManager tests', () => { 'start': 1462918897460 }]; - AdapterManager.callBids( + adapterManager.callBids( getAdUnits(), bidRequests, () => {}, @@ -295,7 +393,7 @@ describe('adapterManager tests', () => { }); // Enable this test when prebidServer adapter is made 1.0 compliant - it('invokes callBids with only s2s bids', () => { + it('invokes callBids with only s2s bids', function () { const adUnits = getAdUnits(); // adUnit without appnexus bidder adUnits.push({ @@ -339,7 +437,7 @@ describe('adapterManager tests', () => { 'placementId': '543221', 'test': 'me' }, - 'placementCode': '/19968336/header-bid-tag1', + 'adUnitCode': '/19968336/header-bid-tag1', 'sizes': [ [ 728, @@ -377,7 +475,7 @@ describe('adapterManager tests', () => { 'params': { 'placementId': '5324321' }, - 'placementCode': '/19968336/header-bid-tag-0', + 'adUnitCode': '/19968336/header-bid-tag-0', 'sizes': [ [ 300, @@ -449,7 +547,7 @@ describe('adapterManager tests', () => { 'start': 1462918897460 }]; - AdapterManager.callBids( + adapterManager.callBids( adUnits, bidRequests, () => {}, @@ -460,49 +558,49 @@ describe('adapterManager tests', () => { sinon.assert.calledOnce(prebidServerAdapterMock.callBids); }); - describe('BID_REQUESTED event', () => { + describe('BID_REQUESTED event', function () { // function to count BID_REQUESTED events let cnt, count = () => cnt++; - beforeEach(() => { + beforeEach(function () { prebidServerAdapterMock.callBids.reset(); cnt = 0; events.on(CONSTANTS.EVENTS.BID_REQUESTED, count); }); - afterEach(() => { + afterEach(function () { events.off(CONSTANTS.EVENTS.BID_REQUESTED, count); }); - it('should fire for s2s requests', () => { + it('should fire for s2s requests', function () { let adUnits = utils.deepClone(getAdUnits()).map(adUnit => { adUnit.bids = adUnit.bids.filter(bid => includes(['appnexus'], bid.bidder)); return adUnit; }) - let bidRequests = AdapterManager.makeBidRequests(adUnits, 1111, 2222, 1000); - AdapterManager.callBids(adUnits, bidRequests, () => {}, () => {}); + let bidRequests = adapterManager.makeBidRequests(adUnits, 1111, 2222, 1000); + adapterManager.callBids(adUnits, bidRequests, () => {}, () => {}); expect(cnt).to.equal(1); sinon.assert.calledOnce(prebidServerAdapterMock.callBids); }); - it('should fire for simultaneous s2s and client requests', () => { - AdapterManager.bidderRegistry['adequant'] = adequantAdapterMock; + it('should fire for simultaneous s2s and client requests', function () { + adapterManager.bidderRegistry['adequant'] = adequantAdapterMock; let adUnits = utils.deepClone(getAdUnits()).map(adUnit => { adUnit.bids = adUnit.bids.filter(bid => includes(['adequant', 'appnexus'], bid.bidder)); return adUnit; }) - let bidRequests = AdapterManager.makeBidRequests(adUnits, 1111, 2222, 1000); - AdapterManager.callBids(adUnits, bidRequests, () => {}, () => {}); + let bidRequests = adapterManager.makeBidRequests(adUnits, 1111, 2222, 1000); + adapterManager.callBids(adUnits, bidRequests, () => {}, () => {}); expect(cnt).to.equal(2); sinon.assert.calledOnce(prebidServerAdapterMock.callBids); sinon.assert.calledOnce(adequantAdapterMock.callBids); adequantAdapterMock.callBids.reset(); - delete AdapterManager.bidderRegistry['adequant']; + delete adapterManager.bidderRegistry['adequant']; }); }); }); // end s2s tests - describe('s2sTesting', () => { + describe('s2sTesting', function () { let doneStub = sinon.stub(); let ajaxStub = sinon.stub(); @@ -516,8 +614,8 @@ describe('adapterManager tests', () => { } function callBids(adUnits = getTestAdUnits()) { - let bidRequests = AdapterManager.makeBidRequests(adUnits, 1111, 2222, 1000); - AdapterManager.callBids(adUnits, bidRequests, doneStub, ajaxStub); + let bidRequests = adapterManager.makeBidRequests(adUnits, 1111, 2222, 1000); + adapterManager.callBids(adUnits, bidRequests, doneStub, ajaxStub); } function checkServerCalled(numAdUnits, numBids) { @@ -543,12 +641,12 @@ describe('adapterManager tests', () => { }); let stubGetSourceBidderMap; - beforeEach(() => { + beforeEach(function () { config.setConfig({s2sConfig: TESTING_CONFIG}); - AdapterManager.bidderRegistry['prebidServer'] = prebidServerAdapterMock; - AdapterManager.bidderRegistry['adequant'] = adequantAdapterMock; - AdapterManager.bidderRegistry['appnexus'] = appnexusAdapterMock; - AdapterManager.bidderRegistry['rubicon'] = rubiconAdapterMock; + adapterManager.bidderRegistry['prebidServer'] = prebidServerAdapterMock; + adapterManager.bidderRegistry['adequant'] = adequantAdapterMock; + adapterManager.bidderRegistry['appnexus'] = appnexusAdapterMock; + adapterManager.bidderRegistry['rubicon'] = rubiconAdapterMock; stubGetSourceBidderMap = sinon.stub(s2sTesting, 'getSourceBidderMap'); @@ -558,12 +656,12 @@ describe('adapterManager tests', () => { rubiconAdapterMock.callBids.reset(); }); - afterEach(() => { + afterEach(function () { config.setConfig({s2sConfig: {}}); s2sTesting.getSourceBidderMap.restore(); }); - it('calls server adapter if no sources defined', () => { + it('calls server adapter if no sources defined', function () { stubGetSourceBidderMap.returns({[s2sTesting.CLIENT]: [], [s2sTesting.SERVER]: []}); callBids(); @@ -577,7 +675,7 @@ describe('adapterManager tests', () => { sinon.assert.notCalled(adequantAdapterMock.callBids); }); - it('calls client adapter if one client source defined', () => { + it('calls client adapter if one client source defined', function () { stubGetSourceBidderMap.returns({[s2sTesting.CLIENT]: ['appnexus'], [s2sTesting.SERVER]: []}); callBids(); @@ -591,7 +689,7 @@ describe('adapterManager tests', () => { sinon.assert.notCalled(adequantAdapterMock.callBids); }); - it('calls client adapters if client sources defined', () => { + it('calls client adapters if client sources defined', function () { stubGetSourceBidderMap.returns({[s2sTesting.CLIENT]: ['appnexus', 'adequant'], [s2sTesting.SERVER]: []}); callBids(); @@ -605,7 +703,7 @@ describe('adapterManager tests', () => { checkClientCalled(adequantAdapterMock, 2); }); - it('calls client adapters if client sources defined', () => { + it('calls client adapters if client sources defined', function () { stubGetSourceBidderMap.returns({[s2sTesting.CLIENT]: ['appnexus', 'adequant'], [s2sTesting.SERVER]: []}); callBids(); @@ -619,7 +717,7 @@ describe('adapterManager tests', () => { checkClientCalled(adequantAdapterMock, 2); }); - it('does not call server adapter for bidders that go to client', () => { + it('does not call server adapter for bidders that go to client', function () { stubGetSourceBidderMap.returns({[s2sTesting.CLIENT]: ['appnexus', 'adequant'], [s2sTesting.SERVER]: []}); var adUnits = getTestAdUnits(); adUnits[0].bids[0].finalSource = s2sTesting.CLIENT; @@ -638,7 +736,7 @@ describe('adapterManager tests', () => { checkClientCalled(adequantAdapterMock, 2); }); - it('does not call client adapters for bidders that go to server', () => { + it('does not call client adapters for bidders that go to server', function () { stubGetSourceBidderMap.returns({[s2sTesting.CLIENT]: ['appnexus', 'adequant'], [s2sTesting.SERVER]: []}); var adUnits = getTestAdUnits(); adUnits[0].bids[0].finalSource = s2sTesting.SERVER; @@ -657,13 +755,13 @@ describe('adapterManager tests', () => { sinon.assert.notCalled(adequantAdapterMock.callBids); }); - it('calls client and server adapters for bidders that go to both', () => { + it('calls client and server adapters for bidders that go to both', function () { stubGetSourceBidderMap.returns({[s2sTesting.CLIENT]: ['appnexus', 'adequant'], [s2sTesting.SERVER]: []}); var adUnits = getTestAdUnits(); - adUnits[0].bids[0].finalSource = s2sTesting.BOTH; - adUnits[0].bids[1].finalSource = s2sTesting.BOTH; - adUnits[1].bids[0].finalSource = s2sTesting.BOTH; - adUnits[1].bids[1].finalSource = s2sTesting.BOTH; + // adUnits[0].bids[0].finalSource = s2sTesting.BOTH; + // adUnits[0].bids[1].finalSource = s2sTesting.BOTH; + // adUnits[1].bids[0].finalSource = s2sTesting.BOTH; + // adUnits[1].bids[1].finalSource = s2sTesting.BOTH; callBids(adUnits); // server adapter @@ -676,7 +774,7 @@ describe('adapterManager tests', () => { checkClientCalled(adequantAdapterMock, 2); }); - it('makes mixed client/server adapter calls for mixed bidder sources', () => { + it('makes mixed client/server adapter calls for mixed bidder sources', function () { stubGetSourceBidderMap.returns({[s2sTesting.CLIENT]: ['appnexus', 'adequant'], [s2sTesting.SERVER]: []}); var adUnits = getTestAdUnits(); adUnits[0].bids[0].finalSource = s2sTesting.CLIENT; @@ -702,7 +800,7 @@ describe('adapterManager tests', () => { describe('using bidderFactory', function() { let spec; - beforeEach(() => { + beforeEach(function () { spec = { code: CODE, isBidRequestValid: () => {}, @@ -716,65 +814,85 @@ describe('adapterManager tests', () => { let thisSpec = Object.assign(spec, { supportedMediaTypes: ['video'] }); registerBidder(thisSpec); const alias = 'aliasBidder'; - AdapterManager.aliasBidAdapter(CODE, alias); - expect(AdapterManager.bidderRegistry).to.have.property(alias); - expect(AdapterManager.videoAdapters).to.include(alias); + adapterManager.aliasBidAdapter(CODE, alias); + expect(adapterManager.bidderRegistry).to.have.property(alias); + expect(adapterManager.videoAdapters).to.include(alias); }); }); - describe('special case for s2s-only bidders', () => { - beforeEach(() => { + describe('special case for s2s-only bidders', function () { + beforeEach(function () { sinon.stub(utils, 'logError'); }); - afterEach(() => { + afterEach(function () { config.resetConfig(); utils.logError.restore(); }); - it('should allow an alias if alias is part of s2sConfig.bidders', () => { + it('should allow an alias if alias is part of s2sConfig.bidders', function () { let testS2sConfig = utils.deepClone(CONFIG); testS2sConfig.bidders = ['s2sAlias']; config.setConfig({s2sConfig: testS2sConfig}); - AdapterManager.aliasBidAdapter('s2sBidder', 's2sAlias'); - expect(AdapterManager.aliasRegistry).to.have.property('s2sAlias'); + adapterManager.aliasBidAdapter('s2sBidder', 's2sAlias'); + expect(adapterManager.aliasRegistry).to.have.property('s2sAlias'); }); - it('should throw an error if alias + bidder are unknown and not part of s2sConfig.bidders', () => { + it('should throw an error if alias + bidder are unknown and not part of s2sConfig.bidders', function () { let testS2sConfig = utils.deepClone(CONFIG); testS2sConfig.bidders = ['s2sAlias']; config.setConfig({s2sConfig: testS2sConfig}); - AdapterManager.aliasBidAdapter('s2sBidder1', 's2sAlias1'); + adapterManager.aliasBidAdapter('s2sBidder1', 's2sAlias1'); sinon.assert.calledOnce(utils.logError); - expect(AdapterManager.aliasRegistry).to.not.have.property('s2sAlias1'); + expect(adapterManager.aliasRegistry).to.not.have.property('s2sAlias1'); }); }); }); - describe('makeBidRequests', () => { + describe('makeBidRequests', function () { let adUnits; - beforeEach(() => { + beforeEach(function () { adUnits = utils.deepClone(getAdUnits()).map(adUnit => { adUnit.bids = adUnit.bids.filter(bid => includes(['appnexus', 'rubicon'], bid.bidder)); return adUnit; }) }); - describe('setBidderSequence', () => { - beforeEach(() => { + it('should make separate bidder request objects for each bidder', () => { + adUnits = [utils.deepClone(getAdUnits()[0])]; + + let bidRequests = adapterManager.makeBidRequests( + adUnits, + Date.now(), + utils.getUniqueIdentifierStr(), + function callback() {}, + [] + ); + + let sizes1 = bidRequests[1].bids[0].sizes; + let sizes2 = bidRequests[0].bids[0].sizes; + + // mutate array + sizes1.splice(0, 1); + + expect(sizes1).not.to.deep.equal(sizes2); + }); + + describe('setBidderSequence', function () { + beforeEach(function () { sinon.spy(utils, 'shuffle'); }); - afterEach(() => { + afterEach(function () { config.resetConfig(); utils.shuffle.restore(); }); - it('setting to `random` uses shuffled order of adUnits', () => { + it('setting to `random` uses shuffled order of adUnits', function () { config.setConfig({ bidderSequence: 'random' }); - let bidRequests = AdapterManager.makeBidRequests( + let bidRequests = adapterManager.makeBidRequests( adUnits, Date.now(), utils.getUniqueIdentifierStr(), @@ -785,19 +903,19 @@ describe('adapterManager tests', () => { }); }); - describe('sizeMapping', () => { - beforeEach(() => { + describe('sizeMapping', function () { + beforeEach(function () { sinon.stub(window, 'matchMedia').callsFake(() => ({matches: true})); }); - afterEach(() => { + afterEach(function () { matchMedia.restore(); config.resetConfig(); setSizeConfig([]); }); - it('should not filter bids w/ no labels', () => { - let bidRequests = AdapterManager.makeBidRequests( + it('should not filter bids w/ no labels', function () { + let bidRequests = adapterManager.makeBidRequests( adUnits, Date.now(), utils.getUniqueIdentifierStr(), @@ -816,7 +934,7 @@ describe('adapterManager tests', () => { expect(appnexusBidRequests.bids[1].sizes).to.deep.equal(find(adUnits, adUnit => adUnit.code === appnexusBidRequests.bids[1].adUnitCode).sizes); }); - it('should filter sizes using size config', () => { + it('should filter sizes using size config', function () { let validSizes = [ [728, 90], [300, 250] @@ -833,7 +951,7 @@ describe('adapterManager tests', () => { 'labels': ['tablet', 'phone'] }]); - let bidRequests = AdapterManager.makeBidRequests( + let bidRequests = adapterManager.makeBidRequests( adUnits, Date.now(), utils.getUniqueIdentifierStr(), @@ -856,7 +974,7 @@ describe('adapterManager tests', () => { 'labels': ['tablet', 'phone'] }]); - bidRequests = AdapterManager.makeBidRequests( + bidRequests = adapterManager.makeBidRequests( adUnits, Date.now(), utils.getUniqueIdentifierStr(), @@ -868,13 +986,13 @@ describe('adapterManager tests', () => { expect(bidRequests.length).to.equal(0); }); - it('should filter adUnits/bidders based on applied labels', () => { + it('should filter adUnits/bidders based on applied labels', function () { adUnits[0].labelAll = ['visitor-uk', 'mobile']; adUnits[1].labelAny = ['visitor-uk', 'desktop']; adUnits[1].bids[0].labelAny = ['mobile']; adUnits[1].bids[1].labelAll = ['desktop']; - let bidRequests = AdapterManager.makeBidRequests( + let bidRequests = adapterManager.makeBidRequests( adUnits, Date.now(), utils.getUniqueIdentifierStr(), @@ -889,7 +1007,7 @@ describe('adapterManager tests', () => { expect(bidRequests[0].bids[0].adUnitCode).to.equal(adUnits[1].code); }); - it('should filter adUnits/bidders based on applid labels for s2s requests', () => { + it('should filter adUnits/bidders based on applid labels for s2s requests', function () { adUnits[0].labelAll = ['visitor-uk', 'mobile']; adUnits[1].labelAny = ['visitor-uk', 'desktop']; adUnits[1].bids[0].labelAny = ['mobile']; @@ -899,7 +1017,7 @@ describe('adapterManager tests', () => { TESTING_CONFIG.bidders = ['appnexus', 'rubicon']; config.setConfig({ s2sConfig: TESTING_CONFIG }); - let bidRequests = AdapterManager.makeBidRequests( + let bidRequests = adapterManager.makeBidRequests( adUnits, Date.now(), utils.getUniqueIdentifierStr(), @@ -911,20 +1029,20 @@ describe('adapterManager tests', () => { expect(bidRequests[0].adUnitsS2SCopy.length).to.equal(1); expect(bidRequests[0].adUnitsS2SCopy[0].bids.length).to.equal(1); expect(bidRequests[0].adUnitsS2SCopy[0].bids[0].bidder).to.equal('rubicon'); - expect(bidRequests[0].adUnitsS2SCopy[0].bids[0].placementCode).to.equal(adUnits[1].code); + expect(bidRequests[0].adUnitsS2SCopy[0].bids[0].adUnitCode).to.equal(adUnits[1].code); expect(bidRequests[0].adUnitsS2SCopy[0].bids[0].bid_id).to.equal(bidRequests[0].bids[0].bid_id); expect(bidRequests[0].adUnitsS2SCopy[0].labelAny).to.deep.equal(['visitor-uk', 'desktop']); }); }); - describe('gdpr consent module', () => { - it('inserts gdprConsent object to bidRequest only when module was enabled', () => { - AdapterManager.gdprDataHandler.setConsentData({ + describe('gdpr consent module', function () { + it('inserts gdprConsent object to bidRequest only when module was enabled', function () { + gdprDataHandler.setConsentData({ consentString: 'abc123def456', consentRequired: true }); - let bidRequests = AdapterManager.makeBidRequests( + let bidRequests = adapterManager.makeBidRequests( adUnits, Date.now(), utils.getUniqueIdentifierStr(), @@ -934,9 +1052,9 @@ describe('adapterManager tests', () => { expect(bidRequests[0].gdprConsent.consentString).to.equal('abc123def456'); expect(bidRequests[0].gdprConsent.consentRequired).to.be.true; - AdapterManager.gdprDataHandler.setConsentData(null); + gdprDataHandler.setConsentData(null); - bidRequests = AdapterManager.makeBidRequests( + bidRequests = adapterManager.makeBidRequests( adUnits, Date.now(), utils.getUniqueIdentifierStr(), @@ -948,17 +1066,17 @@ describe('adapterManager tests', () => { }); }); - describe('isValidBidRequest', () => { - describe('positive tests for validating bid request', () => { - beforeEach(() => { + describe('isValidBidRequest', function () { + describe('positive tests for validating bid request', function () { + beforeEach(function () { sinon.stub(utils, 'logInfo'); }); - afterEach(() => { + afterEach(function () { utils.logInfo.restore(); }); - it('should maintain adUnit structure and adUnits.sizes is replaced', () => { + it('should maintain adUnit structure and adUnits.sizes is replaced', function () { let fullAdUnit = [{ sizes: [[300, 250], [300, 600]], mediaTypes: { @@ -1043,7 +1161,7 @@ describe('adapterManager tests', () => { sinon.assert.calledOnce(utils.logInfo); }); - it('should normalize adUnit.sizes and adUnit.mediaTypes.banner.sizes', () => { + it('should normalize adUnit.sizes and adUnit.mediaTypes.banner.sizes', function () { let fullAdUnit = [{ sizes: [300, 250], mediaTypes: { @@ -1058,16 +1176,16 @@ describe('adapterManager tests', () => { }); }); - describe('negative tests for validating bid requests', () => { - beforeEach(() => { + describe('negative tests for validating bid requests', function () { + beforeEach(function () { sinon.stub(utils, 'logError'); }); - afterEach(() => { + afterEach(function () { utils.logError.restore(); }); - it('should throw error message and delete an object/property', () => { + it('should throw error message and delete an object/property', function () { let badBanner = [{ sizes: [[300, 250], [300, 600]], mediaTypes: { diff --git a/test/spec/unit/core/bidderFactory_spec.js b/test/spec/unit/core/bidderFactory_spec.js index d1422cb1496..5149bbd38a6 100644 --- a/test/spec/unit/core/bidderFactory_spec.js +++ b/test/spec/unit/core/bidderFactory_spec.js @@ -1,5 +1,5 @@ import { newBidder, registerBidder } from 'src/adapters/bidderFactory'; -import adaptermanager from 'src/adaptermanager'; +import adapterManager from 'src/adapterManager'; import * as ajax from 'src/ajax'; import { expect } from 'chai'; import { STATUS } from 'src/constants'; @@ -29,13 +29,13 @@ const MOCK_BIDS_REQUEST = { ] } -describe('bidders created by newBidder', () => { +describe('bidders created by newBidder', function () { let spec; let bidder; let addBidResponseStub; let doneStub; - beforeEach(() => { + beforeEach(function () { spec = { code: CODE, isBidRequestValid: sinon.stub(), @@ -48,20 +48,20 @@ describe('bidders created by newBidder', () => { doneStub = sinon.stub(); }); - describe('when the ajax response is irrelevant', () => { + describe('when the ajax response is irrelevant', function () { let ajaxStub; - beforeEach(() => { + beforeEach(function () { ajaxStub = sinon.stub(ajax, 'ajax'); addBidResponseStub.reset(); doneStub.reset(); }); - afterEach(() => { + afterEach(function () { ajaxStub.restore(); }); - it('should handle bad bid requests gracefully', () => { + it('should handle bad bid requests gracefully', function () { const bidder = newBidder(spec); spec.getUserSyncs.returns([]); @@ -75,7 +75,7 @@ describe('bidders created by newBidder', () => { expect(spec.interpretResponse.called).to.equal(false); }); - it('should call buildRequests(bidRequest) the params are valid', () => { + it('should call buildRequests(bidRequest) the params are valid', function () { const bidder = newBidder(spec); spec.isBidRequestValid.returns(true); @@ -89,7 +89,7 @@ describe('bidders created by newBidder', () => { expect(spec.buildRequests.firstCall.args[0]).to.deep.equal(MOCK_BIDS_REQUEST.bids); }); - it('should not call buildRequests the params are invalid', () => { + it('should not call buildRequests the params are invalid', function () { const bidder = newBidder(spec); spec.isBidRequestValid.returns(false); @@ -102,7 +102,7 @@ describe('bidders created by newBidder', () => { expect(spec.buildRequests.called).to.equal(false); }); - it('should filter out invalid bids before calling buildRequests', () => { + it('should filter out invalid bids before calling buildRequests', function () { const bidder = newBidder(spec); spec.isBidRequestValid.onFirstCall().returns(true); @@ -117,7 +117,7 @@ describe('bidders created by newBidder', () => { expect(spec.buildRequests.firstCall.args[0]).to.deep.equal([MOCK_BIDS_REQUEST.bids[0]]); }); - it('should make no server requests if the spec doesn\'t return any', () => { + it('should make no server requests if the spec doesn\'t return any', function () { const bidder = newBidder(spec); spec.isBidRequestValid.returns(true); @@ -128,7 +128,7 @@ describe('bidders created by newBidder', () => { expect(ajaxStub.called).to.equal(false); }); - it('should make the appropriate POST request', () => { + it('should make the appropriate POST request', function () { const bidder = newBidder(spec); const url = 'test.url.com'; const data = { arg: 2 }; @@ -151,7 +151,7 @@ describe('bidders created by newBidder', () => { }); }); - it('should make the appropriate POST request when options are passed', () => { + it('should make the appropriate POST request when options are passed', function () { const bidder = newBidder(spec); const url = 'test.url.com'; const data = { arg: 2 }; @@ -176,7 +176,7 @@ describe('bidders created by newBidder', () => { }); }); - it('should make the appropriate GET request', () => { + it('should make the appropriate GET request', function () { const bidder = newBidder(spec); const url = 'test.url.com'; const data = { arg: 2 }; @@ -198,7 +198,7 @@ describe('bidders created by newBidder', () => { }); }); - it('should make the appropriate GET request when options are passed', () => { + it('should make the appropriate GET request when options are passed', function () { const bidder = newBidder(spec); const url = 'test.url.com'; const data = { arg: 2 }; @@ -222,7 +222,7 @@ describe('bidders created by newBidder', () => { }); }); - it('should make multiple calls if the spec returns them', () => { + it('should make multiple calls if the spec returns them', function () { const bidder = newBidder(spec); const url = 'test.url.com'; const data = { arg: 2 }; @@ -245,7 +245,7 @@ describe('bidders created by newBidder', () => { expect(ajaxStub.calledTwice).to.equal(true); }); - it('should not add bids for each placement code if no requests are given', () => { + it('should not add bids for each placement code if no requests are given', function () { const bidder = newBidder(spec); spec.isBidRequestValid.returns(true); @@ -259,12 +259,12 @@ describe('bidders created by newBidder', () => { }); }); - describe('when the ajax call succeeds', () => { + describe('when the ajax call succeeds', function () { let ajaxStub; let userSyncStub; let logErrorSpy; - beforeEach(() => { + beforeEach(function () { ajaxStub = sinon.stub(ajax, 'ajax').callsFake(function(url, callbacks) { const fakeResponse = sinon.stub(); fakeResponse.returns('headerContent'); @@ -276,13 +276,13 @@ describe('bidders created by newBidder', () => { logErrorSpy = sinon.spy(utils, 'logError'); }); - afterEach(() => { + afterEach(function () { ajaxStub.restore(); userSyncStub.restore(); utils.logError.restore(); }); - it('should call spec.interpretResponse() with the response content', () => { + it('should call spec.interpretResponse() with the response content', function () { const bidder = newBidder(spec); spec.isBidRequestValid.returns(true); @@ -307,7 +307,7 @@ describe('bidders created by newBidder', () => { expect(doneStub.calledOnce).to.equal(true); }); - it('should call spec.interpretResponse() once for each request made', () => { + it('should call spec.interpretResponse() once for each request made', function () { const bidder = newBidder(spec); spec.isBidRequestValid.returns(true); @@ -331,7 +331,7 @@ describe('bidders created by newBidder', () => { expect(doneStub.calledOnce).to.equal(true); }); - it('should only add bids for valid adUnit code into the auction, even if the bidder doesn\'t bid on all of them', () => { + it('should only add bids for valid adUnit code into the auction, even if the bidder doesn\'t bid on all of them', function () { const bidder = newBidder(spec); const bid = { @@ -364,7 +364,7 @@ describe('bidders created by newBidder', () => { expect(logErrorSpy.callCount).to.equal(0); }); - it('should call spec.getUserSyncs() with the response', () => { + it('should call spec.getUserSyncs() with the response', function () { const bidder = newBidder(spec); spec.isBidRequestValid.returns(true); @@ -384,7 +384,7 @@ describe('bidders created by newBidder', () => { expect(spec.getUserSyncs.firstCall.args[1][0].headers.get).to.be.a('function'); }); - it('should register usersync pixels', () => { + it('should register usersync pixels', function () { const bidder = newBidder(spec); spec.isBidRequestValid.returns(false); @@ -402,7 +402,7 @@ describe('bidders created by newBidder', () => { expect(userSyncStub.firstCall.args[2]).to.equal('usersync.com'); }); - it('should logError when required bid response params are missing', () => { + it('should logError when required bid response params are missing', function () { const bidder = newBidder(spec); const bid = { @@ -428,7 +428,7 @@ describe('bidders created by newBidder', () => { expect(logErrorSpy.calledOnce).to.equal(true); }); - it('should logError when required bid response params are undefined', () => { + it('should logError when required bid response params are undefined', function () { const bidder = newBidder(spec); const bid = { @@ -459,10 +459,10 @@ describe('bidders created by newBidder', () => { }); }); - describe('when the ajax call fails', () => { + describe('when the ajax call fails', function () { let ajaxStub; - beforeEach(() => { + beforeEach(function () { ajaxStub = sinon.stub(ajax, 'ajax').callsFake(function(url, callbacks) { callbacks.error('ajax call failed.'); }); @@ -470,11 +470,11 @@ describe('bidders created by newBidder', () => { doneStub.reset(); }); - afterEach(() => { + afterEach(function () { ajaxStub.restore(); }); - it('should not spec.interpretResponse()', () => { + it('should not spec.interpretResponse()', function () { const bidder = newBidder(spec); spec.isBidRequestValid.returns(true); @@ -491,7 +491,7 @@ describe('bidders created by newBidder', () => { expect(doneStub.calledOnce).to.equal(true); }); - it('should not add bids for each adunit code into the auction', () => { + it('should not add bids for each adunit code into the auction', function () { const bidder = newBidder(spec); spec.isBidRequestValid.returns(true); @@ -509,7 +509,7 @@ describe('bidders created by newBidder', () => { expect(doneStub.calledOnce).to.equal(true); }); - it('should call spec.getUserSyncs() with no responses', () => { + it('should call spec.getUserSyncs() with no responses', function () { const bidder = newBidder(spec); spec.isBidRequestValid.returns(true); @@ -529,16 +529,16 @@ describe('bidders created by newBidder', () => { }); }); -describe('registerBidder', () => { +describe('registerBidder', function () { let registerBidAdapterStub; let aliasBidAdapterStub; - beforeEach(() => { - registerBidAdapterStub = sinon.stub(adaptermanager, 'registerBidAdapter'); - aliasBidAdapterStub = sinon.stub(adaptermanager, 'aliasBidAdapter'); + beforeEach(function () { + registerBidAdapterStub = sinon.stub(adapterManager, 'registerBidAdapter'); + aliasBidAdapterStub = sinon.stub(adapterManager, 'aliasBidAdapter'); }); - afterEach(() => { + afterEach(function () { registerBidAdapterStub.restore(); aliasBidAdapterStub.restore(); }); @@ -552,7 +552,7 @@ describe('registerBidder', () => { }; } - it('should register a bidder with the adapterManager', () => { + it('should register a bidder with the adapterManager', function () { registerBidder(newEmptySpec()); expect(registerBidAdapterStub.calledOnce).to.equal(true); expect(registerBidAdapterStub.firstCall.args[0]).to.have.property('callBids'); @@ -562,14 +562,14 @@ describe('registerBidder', () => { expect(registerBidAdapterStub.firstCall.args[2]).to.be.undefined; }); - it('should register a bidder with the appropriate mediaTypes', () => { + it('should register a bidder with the appropriate mediaTypes', function () { const thisSpec = Object.assign(newEmptySpec(), { supportedMediaTypes: ['video'] }); registerBidder(thisSpec); expect(registerBidAdapterStub.calledOnce).to.equal(true); expect(registerBidAdapterStub.firstCall.args[2]).to.deep.equal({supportedMediaTypes: ['video']}); }); - it('should register bidders with the appropriate aliases', () => { + it('should register bidders with the appropriate aliases', function () { const thisSpec = Object.assign(newEmptySpec(), { aliases: ['foo', 'bar'] }); registerBidder(thisSpec); @@ -586,7 +586,7 @@ describe('registerBidder', () => { }); }) -describe('validate bid response: ', () => { +describe('validate bid response: ', function () { let spec; let bidder; let addBidResponseStub; @@ -606,7 +606,7 @@ describe('validate bid response: ', () => { 'ttl': 360 }]; - beforeEach(() => { + beforeEach(function () { spec = { code: CODE, isBidRequestValid: sinon.stub(), @@ -631,12 +631,12 @@ describe('validate bid response: ', () => { logErrorSpy = sinon.spy(utils, 'logError'); }); - afterEach(() => { + afterEach(function () { ajaxStub.restore(); logErrorSpy.restore(); }); - it('should add native bids that do have required assets', () => { + it('should add native bids that do have required assets', function () { let bidRequest = { bids: [{ bidId: 1, @@ -673,7 +673,7 @@ describe('validate bid response: ', () => { expect(logErrorSpy.callCount).to.equal(0); }); - it('should not add native bids that do not have required assets', () => { + it('should not add native bids that do not have required assets', function () { let bidRequest = { bids: [{ bidId: 1, @@ -709,7 +709,7 @@ describe('validate bid response: ', () => { expect(logErrorSpy.callCount).to.equal(1); }); - it('should add bid when renderer is present on outstream bids', () => { + it('should add bid when renderer is present on outstream bids', function () { let bidRequest = { bids: [{ bidId: 1, @@ -743,7 +743,7 @@ describe('validate bid response: ', () => { expect(logErrorSpy.callCount).to.equal(0); }); - it('should add banner bids that have no width or height but single adunit size', () => { + it('should add banner bids that have no width or height but single adunit size', function () { let bidRequest = { bids: [{ bidder: CODE, diff --git a/test/spec/unit/core/targeting_spec.js b/test/spec/unit/core/targeting_spec.js index 0ba5e23159f..c7e1ad9e2e7 100644 --- a/test/spec/unit/core/targeting_spec.js +++ b/test/spec/unit/core/targeting_spec.js @@ -1,10 +1,9 @@ import { expect } from 'chai'; -import { targeting as targetingInstance } from 'src/targeting'; +import { targeting as targetingInstance, filters } from 'src/targeting'; import { config } from 'src/config'; import { getAdUnits, createBidReceived } from 'test/fixtures/fixtures'; import CONSTANTS from 'src/constants.json'; import { auctionManager } from 'src/auctionManager'; -import * as targetingModule from 'src/targeting'; import * as utils from 'src/utils'; const bid1 = { @@ -27,10 +26,11 @@ const bid1 = { 'bidder': 'rubicon', 'size': '300x250', 'adserverTargeting': { - 'hb_bidder': 'rubicon', - 'hb_adid': '148018fe5e', - 'hb_pb': '0.53', - 'foobar': '300x250' + 'foobar': '300x250', + [CONSTANTS.TARGETING_KEYS.BIDDER]: 'rubicon', + [CONSTANTS.TARGETING_KEYS.AD_ID]: '148018fe5e', + [CONSTANTS.TARGETING_KEYS.PRICE_BUCKET]: '0.53', + [CONSTANTS.TARGETING_KEYS.DEAL]: '1234' }, 'netRevenue': true, 'currency': 'USD', @@ -57,10 +57,10 @@ const bid2 = { 'bidder': 'rubicon', 'size': '300x250', 'adserverTargeting': { - 'hb_bidder': 'rubicon', - 'hb_adid': '5454545', - 'hb_pb': '0.25', - 'foobar': '300x250' + 'foobar': '300x250', + [CONSTANTS.TARGETING_KEYS.BIDDER]: 'rubicon', + [CONSTANTS.TARGETING_KEYS.AD_ID]: '5454545', + [CONSTANTS.TARGETING_KEYS.PRICE_BUCKET]: '0.25' }, 'netRevenue': true, 'currency': 'USD', @@ -87,78 +87,116 @@ const bid3 = { 'bidder': 'rubicon', 'size': '300x600', 'adserverTargeting': { - 'hb_bidder': 'rubicon', - 'hb_adid': '48747745', - 'hb_pb': '0.75', - 'foobar': '300x600' + 'foobar': '300x600', + [CONSTANTS.TARGETING_KEYS.BIDDER]: 'rubicon', + [CONSTANTS.TARGETING_KEYS.AD_ID]: '48747745', + [CONSTANTS.TARGETING_KEYS.PRICE_BUCKET]: '0.75' }, 'netRevenue': true, 'currency': 'USD', 'ttl': 300 }; -describe('targeting tests', () => { - describe('getAllTargeting', () => { +describe('targeting tests', function () { + let sandbox; + let enableSendAllBids = false; + let useBidCache; + + beforeEach(function() { + sandbox = sinon.sandbox.create(); + + useBidCache = true; + // enableSendAllBids = false; + + let origGetConfig = config.getConfig; + sandbox.stub(config, 'getConfig').callsFake(function (key) { + if (key === 'enableSendAllBids') { + return enableSendAllBids; + } + if (key === 'useBidCache') { + return useBidCache; + } + return origGetConfig.apply(config, arguments); + }); + }); + + afterEach(function () { + sandbox.restore(); + }); + + describe('getAllTargeting', function () { let amBidsReceivedStub; let amGetAdUnitsStub; let bidExpiryStub; + let bidsReceived; - beforeEach(() => { - $$PREBID_GLOBAL$$._sendAllBids = false; - amBidsReceivedStub = sinon.stub(auctionManager, 'getBidsReceived').callsFake(function() { - return [bid1, bid2, bid3]; + beforeEach(function () { + bidsReceived = [bid1, bid2, bid3]; + + amBidsReceivedStub = sandbox.stub(auctionManager, 'getBidsReceived').callsFake(function() { + return bidsReceived; }); - amGetAdUnitsStub = sinon.stub(auctionManager, 'getAdUnitCodes').callsFake(function() { + amGetAdUnitsStub = sandbox.stub(auctionManager, 'getAdUnitCodes').callsFake(function() { return ['/123456/header-bid-tag-0']; }); - bidExpiryStub = sinon.stub(targetingModule, 'isBidNotExpired').returns(true); + bidExpiryStub = sandbox.stub(filters, 'isBidNotExpired').returns(true); }); - afterEach(() => { - auctionManager.getBidsReceived.restore(); - auctionManager.getAdUnitCodes.restore(); - targetingModule.isBidNotExpired.restore(); + describe('when hb_deal is present in bid.adserverTargeting', function () { + let bid4; + + beforeEach(function() { + bid4 = utils.deepClone(bid1); + bid4.adserverTargeting['hb_bidder'] = bid4.bidder = bid4.bidderCode = 'appnexus'; + bid4.cpm = 0; + enableSendAllBids = true; + + bidsReceived.push(bid4); + }); + + it('returns targeting with both hb_deal and hb_deal_{bidder_code}', function () { + const targeting = targetingInstance.getAllTargeting(['/123456/header-bid-tag-0']); + + // We should add both keys rather than one or the other + expect(targeting['/123456/header-bid-tag-0']).to.contain.keys('hb_deal', `hb_deal_${bid1.bidderCode}`, `hb_deal_${bid4.bidderCode}`); + + // We should assign both keys the same value + expect(targeting['/123456/header-bid-tag-0']['hb_deal']).to.deep.equal(targeting['/123456/header-bid-tag-0'][`hb_deal_${bid1.bidderCode}`]); + }); }); - it('selects the top bid when _sendAllBids true', () => { - config.setConfig({ enableSendAllBids: true }); + it('selects the top bid when enableSendAllBids true', function () { + enableSendAllBids = true; let targeting = targetingInstance.getAllTargeting(['/123456/header-bid-tag-0']); // we should only get the targeting data for the one requested adunit expect(Object.keys(targeting).length).to.equal(1); - let sendAllBidCpm = Object.keys(targeting['/123456/header-bid-tag-0']).filter(key => key.indexOf('hb_pb_') != -1) + let sendAllBidCpm = Object.keys(targeting['/123456/header-bid-tag-0']).filter(key => key.indexOf(CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_') != -1) // we shouldn't get more than 1 key for hb_pb_${bidder} expect(sendAllBidCpm.length).to.equal(1); // expect the winning CPM to be equal to the sendAllBidCPM - expect(targeting['/123456/header-bid-tag-0']['hb_pb_rubicon']).to.deep.equal(targeting['/123456/header-bid-tag-0']['hb_pb']); + expect(targeting['/123456/header-bid-tag-0'][CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_rubicon']).to.deep.equal(targeting['/123456/header-bid-tag-0'][CONSTANTS.TARGETING_KEYS.PRICE_BUCKET]); }); }); // end getAllTargeting tests - describe('getAllTargeting without bids return empty object', () => { + describe('getAllTargeting without bids return empty object', function () { let amBidsReceivedStub; let amGetAdUnitsStub; let bidExpiryStub; - beforeEach(() => { - $$PREBID_GLOBAL$$._sendAllBids = false; - amBidsReceivedStub = sinon.stub(auctionManager, 'getBidsReceived').callsFake(function() { + beforeEach(function () { + amBidsReceivedStub = sandbox.stub(auctionManager, 'getBidsReceived').callsFake(function() { return []; }); - amGetAdUnitsStub = sinon.stub(auctionManager, 'getAdUnitCodes').callsFake(function() { + amGetAdUnitsStub = sandbox.stub(auctionManager, 'getAdUnitCodes').callsFake(function() { return ['/123456/header-bid-tag-0']; }); - bidExpiryStub = sinon.stub(targetingModule, 'isBidNotExpired').returns(true); - }); - - afterEach(() => { - auctionManager.getBidsReceived.restore(); - auctionManager.getAdUnitCodes.restore(); - targetingModule.isBidNotExpired.restore(); + bidExpiryStub = sandbox.stub(filters, 'isBidNotExpired').returns(true); }); - it('returns targetingSet correctly', () => { + it('returns targetingSet correctly', function () { let targeting = targetingInstance.getAllTargeting(['/123456/header-bid-tag-0']); // we should only get the targeting data for the one requested adunit to at least exist even though it has no keys to set @@ -166,21 +204,16 @@ describe('targeting tests', () => { }); }); // end getAllTargeting without bids return empty object - describe('Targeting in concurrent auctions', () => { - describe('check getOldestBid', () => { + describe('Targeting in concurrent auctions', function () { + describe('check getOldestBid', function () { let bidExpiryStub; let auctionManagerStub; - beforeEach(() => { - bidExpiryStub = sinon.stub(targetingModule, 'isBidNotExpired').returns(true); - auctionManagerStub = sinon.stub(auctionManager, 'getBidsReceived'); + beforeEach(function () { + bidExpiryStub = sandbox.stub(filters, 'isBidNotExpired').returns(true); + auctionManagerStub = sandbox.stub(auctionManager, 'getBidsReceived'); }); - afterEach(() => { - bidExpiryStub.restore(); - auctionManagerStub.restore(); - }); - - it('should use bids from pool to get Winning Bid', () => { + it('should use bids from pool to get Winning Bid', function () { let bidsReceived = [ createBidReceived({bidder: 'appnexus', cpm: 7, auctionId: 1, responseTimestamp: 100, adUnitCode: 'code-0', adId: 'adid-1'}), createBidReceived({bidder: 'rubicon', cpm: 6, auctionId: 1, responseTimestamp: 101, adUnitCode: 'code-1', adId: 'adid-2'}), @@ -196,7 +229,31 @@ describe('targeting tests', () => { expect(bids[1].adId).to.equal('adid-2'); }); - it('should not use rendered bid to get winning bid', () => { + it('should honor useBidCache', function() { + useBidCache = true; + + auctionManagerStub.returns([ + createBidReceived({bidder: 'appnexus', cpm: 7, auctionId: 1, responseTimestamp: 100, adUnitCode: 'code-0', adId: 'adid-1'}), + createBidReceived({bidder: 'appnexus', cpm: 5, auctionId: 2, responseTimestamp: 102, adUnitCode: 'code-0', adId: 'adid-2'}), + ]); + + let adUnitCodes = ['code-0']; + targetingInstance.setLatestAuctionForAdUnit('code-0', 2); + + let bids = targetingInstance.getWinningBids(adUnitCodes); + + expect(bids.length).to.equal(1); + expect(bids[0].adId).to.equal('adid-1'); + + useBidCache = false; + + bids = targetingInstance.getWinningBids(adUnitCodes); + + expect(bids.length).to.equal(1); + expect(bids[0].adId).to.equal('adid-2'); + }); + + it('should not use rendered bid to get winning bid', function () { let bidsReceived = [ createBidReceived({bidder: 'appnexus', cpm: 8, auctionId: 1, responseTimestamp: 100, adUnitCode: 'code-0', adId: 'adid-1', status: 'rendered'}), createBidReceived({bidder: 'rubicon', cpm: 6, auctionId: 1, responseTimestamp: 101, adUnitCode: 'code-1', adId: 'adid-2'}), @@ -213,7 +270,7 @@ describe('targeting tests', () => { expect(bids[1].adId).to.equal('adid-3'); }); - it('should use highest cpm bid from bid pool to get winning bid', () => { + it('should use highest cpm bid from bid pool to get winning bid', function () { // Pool is having 4 bids from 2 auctions. There are 2 bids from rubicon, #2 which is highest cpm bid will be selected to take part in auction. let bidsReceived = [ createBidReceived({bidder: 'appnexus', cpm: 8, auctionId: 1, responseTimestamp: 100, adUnitCode: 'code-0', adId: 'adid-1'}), @@ -231,19 +288,15 @@ describe('targeting tests', () => { }); }); - describe('check bidExpiry', () => { + describe('check bidExpiry', function () { let auctionManagerStub; let timestampStub; - beforeEach(() => { - auctionManagerStub = sinon.stub(auctionManager, 'getBidsReceived'); - timestampStub = sinon.stub(utils, 'timestamp'); + beforeEach(function () { + auctionManagerStub = sandbox.stub(auctionManager, 'getBidsReceived'); + timestampStub = sandbox.stub(utils, 'timestamp'); }); - afterEach(() => { - auctionManagerStub.restore(); - timestampStub.restore(); - }); - it('should not include expired bids in the auction', () => { + it('should not include expired bids in the auction', function () { timestampStub.returns(200000); // Pool is having 4 bids from 2 auctions. All the bids are expired and only bid #3 is passing the bidExpiry check. let bidsReceived = [ diff --git a/test/spec/unit/pbjs_api_spec.js b/test/spec/unit/pbjs_api_spec.js index d46a8d740a5..ff9dac55029 100644 --- a/test/spec/unit/pbjs_api_spec.js +++ b/test/spec/unit/pbjs_api_spec.js @@ -9,12 +9,12 @@ import { createBidReceived } from 'test/fixtures/fixtures'; import { auctionManager, newAuctionManager } from 'src/auctionManager'; -import { targeting, newTargeting, RENDERED } from 'src/targeting'; +import { targeting, newTargeting, filters } from 'src/targeting'; import { config as configObj } from 'src/config'; import * as ajaxLib from 'src/ajax'; import * as auctionModule from 'src/auction'; import { newBidder, registerBidder } from 'src/adapters/bidderFactory'; -import * as targetingModule from 'src/targeting'; +import find from 'core-js/library/fn/array/find'; var assert = require('chai').assert; var expect = require('chai').expect; @@ -23,10 +23,9 @@ var urlParse = require('url-parse'); var prebid = require('src/prebid'); var utils = require('src/utils'); -// var bidmanager = require('src/bidmanager'); var bidfactory = require('src/bidfactory'); -var adloader = require('src/adloader'); -var adaptermanager = require('src/adaptermanager'); +var adloader = require('test/mocks/adloaderStub'); +var adapterManager = require('src/adapterManager').default; var events = require('src/events'); var adserver = require('src/adserver'); var CONSTANTS = require('src/constants.json'); @@ -134,39 +133,51 @@ var createTagAST = function() { window.apntag = { keywords: [], tags: createTagAST(), - setKeywords: function(key, params) { + setKeywords: function(key, params, options) { var self = this; if (!self.tags.hasOwnProperty(key)) { return; } self.tags[key].keywords = this.tags[key].keywords || {}; - utils._each(params, function(param, id) { - if (!self.tags[key].keywords.hasOwnProperty(id)) { self.tags[key].keywords[id] = param; } else if (!utils.isArray(self.tags[key].keywords[id])) { self.tags[key].keywords[id] = [self.tags[key].keywords[id]].concat(param); } else { self.tags[key].keywords[id] = self.tags[key].keywords[id].concat(param); } - }); + if (typeof options === 'object' && options !== null && options.overrideKeyValue === true) { + utils._each(params, function(param, id) { + self.tags[key].keywords[id] = param; + }); + } else { + utils._each(params, function (param, id) { + if (!self.tags[key].keywords.hasOwnProperty(id)) { + self.tags[key].keywords[id] = param; + } else if (!utils.isArray(self.tags[key].keywords[id])) { + self.tags[key].keywords[id] = [self.tags[key].keywords[id]].concat(param); + } else { + self.tags[key].keywords[id] = self.tags[key].keywords[id].concat(param); + } + }) + } } -}; +} describe('Unit: Prebid Module', function () { let bidExpiryStub; - before(() => { - bidExpiryStub = sinon.stub(targetingModule, 'isBidNotExpired').callsFake(() => true); + before(function () { + bidExpiryStub = sinon.stub(filters, 'isBidNotExpired').callsFake(() => true); }); after(function() { $$PREBID_GLOBAL$$.adUnits = []; - targetingModule.isBidNotExpired.restore(); + bidExpiryStub.restore(); }); describe('getAdserverTargetingForAdUnitCodeStr', function () { - beforeEach(() => { + beforeEach(function () { resetAuction(); }); it('should return targeting info as a string', function () { const adUnitCode = config.adUnitCodes[0]; $$PREBID_GLOBAL$$.setConfig({ enableSendAllBids: true }); - var expected = 'foobar=0x0%2C300x250%2C300x600&hb_size=300x250&hb_pb=10.00&hb_adid=233bcbee889d46d&hb_bidder=appnexus&hb_size_triplelift=0x0&hb_pb_triplelift=10.00&hb_adid_triplelift=222bb26f9e8bd&hb_bidder_triplelift=triplelift&hb_size_appnexus=300x250&hb_pb_appnexus=10.00&hb_adid_appnexus=233bcbee889d46d&hb_bidder_appnexus=appnexus&hb_size_pagescience=300x250&hb_pb_pagescience=10.00&hb_adid_pagescience=25bedd4813632d7&hb_bidder_pagescienc=pagescience&hb_size_brightcom=300x250&hb_pb_brightcom=10.00&hb_adid_brightcom=26e0795ab963896&hb_bidder_brightcom=brightcom&hb_size_brealtime=300x250&hb_pb_brealtime=10.00&hb_adid_brealtime=275bd666f5a5a5d&hb_bidder_brealtime=brealtime&hb_size_pubmatic=300x250&hb_pb_pubmatic=10.00&hb_adid_pubmatic=28f4039c636b6a7&hb_bidder_pubmatic=pubmatic&hb_size_rubicon=300x600&hb_pb_rubicon=10.00&hb_adid_rubicon=29019e2ab586a5a&hb_bidder_rubicon=rubicon'; + var expected = 'foobar=0x0%2C300x250%2C300x600&' + CONSTANTS.TARGETING_KEYS.SIZE + '=300x250&' + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '=10.00&' + CONSTANTS.TARGETING_KEYS.AD_ID + '=233bcbee889d46d&' + CONSTANTS.TARGETING_KEYS.BIDDER + '=appnexus&' + CONSTANTS.TARGETING_KEYS.SIZE + '_triplelift=0x0&' + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_triplelift=10.00&' + CONSTANTS.TARGETING_KEYS.AD_ID + '_triplelift=222bb26f9e8bd&' + CONSTANTS.TARGETING_KEYS.BIDDER + '_triplelift=triplelift&' + CONSTANTS.TARGETING_KEYS.SIZE + '_appnexus=300x250&' + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_appnexus=10.00&' + CONSTANTS.TARGETING_KEYS.AD_ID + '_appnexus=233bcbee889d46d&' + CONSTANTS.TARGETING_KEYS.BIDDER + '_appnexus=appnexus&' + CONSTANTS.TARGETING_KEYS.SIZE + '_pagescience=300x250&' + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_pagescience=10.00&' + CONSTANTS.TARGETING_KEYS.AD_ID + '_pagescience=25bedd4813632d7&' + CONSTANTS.TARGETING_KEYS.BIDDER + '_pagescienc=pagescience&' + CONSTANTS.TARGETING_KEYS.SIZE + '_brightcom=300x250&' + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_brightcom=10.00&' + CONSTANTS.TARGETING_KEYS.AD_ID + '_brightcom=26e0795ab963896&' + CONSTANTS.TARGETING_KEYS.BIDDER + '_brightcom=brightcom&' + CONSTANTS.TARGETING_KEYS.SIZE + '_brealtime=300x250&' + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_brealtime=10.00&' + CONSTANTS.TARGETING_KEYS.AD_ID + '_brealtime=275bd666f5a5a5d&' + CONSTANTS.TARGETING_KEYS.BIDDER + '_brealtime=brealtime&' + CONSTANTS.TARGETING_KEYS.SIZE + '_pubmatic=300x250&' + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_pubmatic=10.00&' + CONSTANTS.TARGETING_KEYS.AD_ID + '_pubmatic=28f4039c636b6a7&' + CONSTANTS.TARGETING_KEYS.BIDDER + '_pubmatic=pubmatic&' + CONSTANTS.TARGETING_KEYS.SIZE + '_rubicon=300x600&' + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_rubicon=10.00&' + CONSTANTS.TARGETING_KEYS.AD_ID + '_rubicon=29019e2ab586a5a&' + CONSTANTS.TARGETING_KEYS.BIDDER + '_rubicon=rubicon'; var result = $$PREBID_GLOBAL$$.getAdserverTargetingForAdUnitCodeStr(adUnitCode); assert.equal(expected, result, 'returns expected string of ad targeting info'); }); @@ -192,11 +203,11 @@ describe('Unit: Prebid Module', function () { }); describe('getAdServerTargeting', function () { - beforeEach(() => { + beforeEach(function () { resetAuction(); }); - afterEach(() => { + afterEach(function () { resetAuction(); }); @@ -207,35 +218,35 @@ describe('Unit: Prebid Module', function () { assert.deepEqual(targeting, expected, 'targeting ok'); }); - it('should return correct targeting with default settings', () => { + it('should return correct targeting with default settings', function () { var targeting = $$PREBID_GLOBAL$$.getAdserverTargeting(['/19968336/header-bid-tag-0', '/19968336/header-bid-tag1']); var expected = { '/19968336/header-bid-tag-0': { foobar: '0x0,300x250,300x600', - hb_size: '300x250', - hb_pb: '10.00', - hb_adid: '233bcbee889d46d', - hb_bidder: 'appnexus' + [CONSTANTS.TARGETING_KEYS.SIZE]: '300x250', + [CONSTANTS.TARGETING_KEYS.PRICE_BUCKET]: '10.00', + [CONSTANTS.TARGETING_KEYS.AD_ID]: '233bcbee889d46d', + [CONSTANTS.TARGETING_KEYS.BIDDER]: 'appnexus' }, '/19968336/header-bid-tag1': { foobar: '728x90', - hb_size: '728x90', - hb_pb: '10.00', - hb_adid: '24bd938435ec3fc', - hb_bidder: 'appnexus' + [CONSTANTS.TARGETING_KEYS.SIZE]: '728x90', + [CONSTANTS.TARGETING_KEYS.PRICE_BUCKET]: '10.00', + [CONSTANTS.TARGETING_KEYS.AD_ID]: '24bd938435ec3fc', + [CONSTANTS.TARGETING_KEYS.BIDDER]: 'appnexus' } }; assert.deepEqual(targeting, expected); }); - it('should return correct targeting with bid landscape targeting on', () => { + it('should return correct targeting with bid landscape targeting on', function () { $$PREBID_GLOBAL$$.setConfig({ enableSendAllBids: true }); var targeting = $$PREBID_GLOBAL$$.getAdserverTargeting(['/19968336/header-bid-tag-0', '/19968336/header-bid-tag1']); var expected = getAdServerTargeting(['/19968336/header-bid-tag-0', '/19968336/header-bid-tag1']); assert.deepEqual(targeting, expected); }); - it("should include a losing bid's custom ad targeting key", () => { + it("should include a losing bid's custom ad targeting key", function () { // Let's make sure we're getting the expected losing bid. assert.equal(auction.getBidsReceived()[0]['bidderCode'], 'triplelift'); assert.equal(auction.getBidsReceived()[0]['cpm'], 0.112256); @@ -259,24 +270,24 @@ describe('Unit: Prebid Module', function () { var expected = { '/19968336/header-bid-tag-0': { foobar: '300x250,300x600', - hb_size: '300x250', - hb_pb: '10.00', - hb_adid: '233bcbee889d46d', - hb_bidder: 'appnexus', - always_use_me: 'abc' + always_use_me: 'abc', + [CONSTANTS.TARGETING_KEYS.SIZE]: '300x250', + [CONSTANTS.TARGETING_KEYS.PRICE_BUCKET]: '10.00', + [CONSTANTS.TARGETING_KEYS.AD_ID]: '233bcbee889d46d', + [CONSTANTS.TARGETING_KEYS.BIDDER]: 'appnexus' }, '/19968336/header-bid-tag1': { foobar: '728x90', - hb_size: '728x90', - hb_pb: '10.00', - hb_adid: '24bd938435ec3fc', - hb_bidder: 'appnexus' + [CONSTANTS.TARGETING_KEYS.SIZE]: '728x90', + [CONSTANTS.TARGETING_KEYS.PRICE_BUCKET]: '10.00', + [CONSTANTS.TARGETING_KEYS.AD_ID]: '24bd938435ec3fc', + [CONSTANTS.TARGETING_KEYS.BIDDER]: 'appnexus' } }; assert.deepEqual(targeting, expected); }); - it('should not overwrite winning bids custom keys targeting key', () => { + it('should not overwrite winning bids custom keys targeting key', function () { resetAuction(); // mimic a bidderSetting.standard key here for each bid and alwaysUseBid true for every bid let _bidsReceived = getBidResponses(); @@ -289,7 +300,7 @@ describe('Unit: Prebid Module', function () { $$PREBID_GLOBAL$$.bidderSettings = { 'standard': { adserverTargeting: [{ - key: 'hb_bidder', + key: CONSTANTS.TARGETING_KEYS.BIDDER, val: function(bidResponse) { return bidResponse.bidderCode; } @@ -299,7 +310,7 @@ describe('Unit: Prebid Module', function () { return bidResponse.adId; } }, { - key: 'hb_pb', + key: CONSTANTS.TARGETING_KEYS.PRICE_BUCKET, val: function(bidResponse) { return bidResponse.pbMg; } @@ -317,27 +328,26 @@ describe('Unit: Prebid Module', function () { var expected = { '/19968336/header-bid-tag-0': { foobar: '300x250', - hb_size: '300x250', - hb_pb: '10.00', - hb_adid: '233bcbee889d46d', - hb_bidder: 'appnexus', - custom_ad_id: '233bcbee889d46d' + custom_ad_id: '233bcbee889d46d', + [CONSTANTS.TARGETING_KEYS.SIZE]: '300x250', + [CONSTANTS.TARGETING_KEYS.PRICE_BUCKET]: '10.00', + [CONSTANTS.TARGETING_KEYS.AD_ID]: '233bcbee889d46d', + [CONSTANTS.TARGETING_KEYS.BIDDER]: 'appnexus' }, '/19968336/header-bid-tag1': { foobar: '728x90', - hb_size: '728x90', - hb_pb: '10.00', - hb_adid: '24bd938435ec3fc', - hb_bidder: 'appnexus', + [CONSTANTS.TARGETING_KEYS.SIZE]: '728x90', + [CONSTANTS.TARGETING_KEYS.PRICE_BUCKET]: '10.00', + [CONSTANTS.TARGETING_KEYS.AD_ID]: '24bd938435ec3fc', + [CONSTANTS.TARGETING_KEYS.BIDDER]: 'appnexus', custom_ad_id: '24bd938435ec3fc' } }; - assert.deepEqual(targeting, expected); $$PREBID_GLOBAL$$.bidderSettings = {}; }); - it('should not send standard targeting keys when the bid has `sendStandardTargeting` set to `false`', () => { + it('should not send standard targeting keys when the bid has `sendStandardTargeting` set to `false`', function () { let _bidsReceived = getBidResponses(); _bidsReceived.forEach(bid => { bid.adserverTargeting.custom_ad_id = bid.adId; @@ -411,11 +421,11 @@ describe('Unit: Prebid Module', function () { }] }; - before(() => { + before(function () { $$PREBID_GLOBAL$$.bidderSettings = {}; currentPriceBucket = configObj.getConfig('priceGranularity'); configObj.setConfig({ priceGranularity: customConfigObject }); - sinon.stub(adaptermanager, 'makeBidRequests').callsFake(() => ([{ + sinon.stub(adapterManager, 'makeBidRequests').callsFake(() => ([{ 'bidderCode': 'appnexus', 'auctionId': '20882439e3238c', 'bidderRequestId': '331f3cf3f1d9c8', @@ -447,12 +457,12 @@ describe('Unit: Prebid Module', function () { )); }); - after(() => { + after(function () { configObj.setConfig({ priceGranularity: currentPriceBucket }); - adaptermanager.makeBidRequests.restore(); + adapterManager.makeBidRequests.restore(); }) - beforeEach(() => { + beforeEach(function () { let auctionManagerInstance = newAuctionManager(); targeting = newTargeting(auctionManagerInstance); let adUnits = [{ @@ -476,36 +486,36 @@ describe('Unit: Prebid Module', function () { }); }); - afterEach(() => { + afterEach(function () { ajaxStub.restore(); }); - it('should get correct hb_pb when using bid.cpm is between 0 to 5', () => { + it('should get correct ' + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + ' when using bid.cpm is between 0 to 5', function() { RESPONSE.tags[0].ads[0].cpm = 2.1234; auction.callBids(cbTimeout); let bidTargeting = targeting.getAllTargeting(); - expect(bidTargeting['div-gpt-ad-1460505748561-0']['hb_pb']).to.equal('2.12'); + expect(bidTargeting['div-gpt-ad-1460505748561-0'][CONSTANTS.TARGETING_KEYS.PRICE_BUCKET]).to.equal('2.12'); }); - it('should get correct hb_pb when using bid.cpm is between 5 to 8', () => { + it('should get correct ' + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + ' when using bid.cpm is between 5 to 8', function() { RESPONSE.tags[0].ads[0].cpm = 6.78; auction.callBids(cbTimeout); let bidTargeting = targeting.getAllTargeting(); - expect(bidTargeting['div-gpt-ad-1460505748561-0']['hb_pb']).to.equal('6.75'); + expect(bidTargeting['div-gpt-ad-1460505748561-0'][CONSTANTS.TARGETING_KEYS.PRICE_BUCKET]).to.equal('6.75'); }); - it('should get correct hb_pb when using bid.cpm is between 8 to 20', () => { + it('should get correct ' + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + ' when using bid.cpm is between 8 to 20', function() { RESPONSE.tags[0].ads[0].cpm = 19.5234; auction.callBids(cbTimeout); let bidTargeting = targeting.getAllTargeting(); - expect(bidTargeting['div-gpt-ad-1460505748561-0']['hb_pb']).to.equal('19.50'); + expect(bidTargeting['div-gpt-ad-1460505748561-0'][CONSTANTS.TARGETING_KEYS.PRICE_BUCKET]).to.equal('19.50'); }); - it('should get correct hb_pb when using bid.cpm is between 20 to 25', () => { + it('should get correct ' + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + ' when using bid.cpm is between 20 to 25', function() { RESPONSE.tags[0].ads[0].cpm = 21.5234; auction.callBids(cbTimeout); let bidTargeting = targeting.getAllTargeting(); - expect(bidTargeting['div-gpt-ad-1460505748561-0']['hb_pb']).to.equal('21.00'); + expect(bidTargeting['div-gpt-ad-1460505748561-0'][CONSTANTS.TARGETING_KEYS.PRICE_BUCKET]).to.equal('21.00'); }); }); @@ -678,9 +688,9 @@ describe('Unit: Prebid Module', function () { }); }; - before(() => { + before(function () { currentPriceBucket = configObj.getConfig('priceGranularity'); - sinon.stub(adaptermanager, 'makeBidRequests').callsFake(() => ([{ + sinon.stub(adapterManager, 'makeBidRequests').callsFake(() => ([{ 'bidderCode': 'appnexus', 'auctionId': '20882439e3238c', 'bidderRequestId': '331f3cf3f1d9c8', @@ -711,16 +721,16 @@ describe('Unit: Prebid Module', function () { }])); }); - after(() => { + after(function () { configObj.setConfig({ priceGranularity: currentPriceBucket }); - adaptermanager.makeBidRequests.restore(); + adapterManager.makeBidRequests.restore(); }) - afterEach(() => { + afterEach(function () { ajaxStub.restore(); }); - it('should get correct hb_pb with cpm between 0 - 5', () => { + it('should get correct ' + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + ' with cpm between 0 - 5', function() { initTestConfig({ adUnits: [createAdUnit('div-gpt-ad-1460505748561-0')], adUnitCodes: ['div-gpt-ad-1460505748561-0'] @@ -731,10 +741,10 @@ describe('Unit: Prebid Module', function () { auction.callBids(cbTimeout); let bidTargeting = targeting.getAllTargeting(); - expect(bidTargeting['div-gpt-ad-1460505748561-0']['hb_pb']).to.equal('3.25'); + expect(bidTargeting['div-gpt-ad-1460505748561-0'][CONSTANTS.TARGETING_KEYS.PRICE_BUCKET]).to.equal('3.25'); }); - it('should get correct hb_pb with cpm between 21 - 100', () => { + it('should get correct ' + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + ' with cpm between 21 - 100', function() { initTestConfig({ adUnits: [createAdUnit('div-gpt-ad-1460505748561-0')], adUnitCodes: ['div-gpt-ad-1460505748561-0'] @@ -745,10 +755,10 @@ describe('Unit: Prebid Module', function () { auction.callBids(cbTimeout); let bidTargeting = targeting.getAllTargeting(); - expect(bidTargeting['div-gpt-ad-1460505748561-0']['hb_pb']).to.equal('43.00'); + expect(bidTargeting['div-gpt-ad-1460505748561-0'][CONSTANTS.TARGETING_KEYS.PRICE_BUCKET]).to.equal('43.00'); }); - it('should only apply price granularity if bid media type matches', () => { + it('should only apply price granularity if bid media type matches', function () { initTestConfig({ adUnits: [ createAdUnit('div-gpt-ad-1460505748561-0', 'video') ], adUnitCodes: ['div-gpt-ad-1460505748561-0'] @@ -759,7 +769,7 @@ describe('Unit: Prebid Module', function () { auction.callBids(cbTimeout); let bidTargeting = targeting.getAllTargeting(); - expect(bidTargeting['div-gpt-ad-1460505748561-0']['hb_pb']).to.equal('3.00'); + expect(bidTargeting['div-gpt-ad-1460505748561-0'][CONSTANTS.TARGETING_KEYS.PRICE_BUCKET]).to.equal('3.00'); }); }); @@ -770,7 +780,7 @@ describe('Unit: Prebid Module', function () { assert.deepEqual(result, compare, 'expected bid responses are returned'); }); - it('should return bid responses for most recent requestId only', () => { + it('should return bid responses for most recent requestId only', function () { const responses = $$PREBID_GLOBAL$$.getBidResponses(); assert.equal(responses[Object.keys(responses)[0]].bids.length, 4); }); @@ -789,12 +799,12 @@ describe('Unit: Prebid Module', function () { describe('setTargetingForGPTAsync', function () { let logErrorSpy; - beforeEach(() => { + beforeEach(function () { logErrorSpy = sinon.spy(utils, 'logError'); resetAuction(); }); - afterEach(() => { + afterEach(function () { utils.logError.restore(); resetAuction(); }); @@ -821,7 +831,7 @@ describe('Unit: Prebid Module', function () { $$PREBID_GLOBAL$$.setConfig({ enableSendAllBids: true }); $$PREBID_GLOBAL$$.setTargetingForGPTAsync('/19968336/header-bid-tag-0'); - expect(slots[0].spySetTargeting.args).to.deep.contain.members([['hb_bidder', 'appnexus'], ['hb_adid_appnexus', '233bcbee889d46d'], ['hb_pb_appnexus', '10.00']]); + expect(slots[0].spySetTargeting.args).to.deep.contain.members([[CONSTANTS.TARGETING_KEYS.BIDDER, 'appnexus'], [CONSTANTS.TARGETING_KEYS.AD_ID + '_appnexus', '233bcbee889d46d'], [CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_appnexus', '10.00']]); }); it('should set targeting when passed an array of ad unit codes with enableSendAllBids', function () { @@ -830,7 +840,7 @@ describe('Unit: Prebid Module', function () { $$PREBID_GLOBAL$$.setConfig({ enableSendAllBids: true }); $$PREBID_GLOBAL$$.setTargetingForGPTAsync(['/19968336/header-bid-tag-0']); - expect(slots[0].spySetTargeting.args).to.deep.contain.members([['hb_bidder', 'appnexus'], ['hb_adid_appnexus', '233bcbee889d46d'], ['hb_pb_appnexus', '10.00']]); + expect(slots[0].spySetTargeting.args).to.deep.contain.members([[CONSTANTS.TARGETING_KEYS.BIDDER, 'appnexus'], [CONSTANTS.TARGETING_KEYS.AD_ID + '_appnexus', '233bcbee889d46d'], [CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_appnexus', '10.00']]); }); it('should set targeting from googletag data', function () { @@ -877,19 +887,19 @@ describe('Unit: Prebid Module', function () { var expected = [ [ - 'hb_bidder', + CONSTANTS.TARGETING_KEYS.BIDDER, 'appnexus' ], [ - 'hb_adid', + CONSTANTS.TARGETING_KEYS.AD_ID, '233bcbee889d46d' ], [ - 'hb_pb', + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET, '10.00' ], [ - 'hb_size', + CONSTANTS.TARGETING_KEYS.SIZE, '300x250' ], [ @@ -936,7 +946,7 @@ describe('Unit: Prebid Module', function () { var spyLogError = null; var spyLogMessage = null; var inIframe = true; - let triggerPixelStub; + var triggerPixelStub; function pushBidResponseToAuction(obj) { adResponse = Object.assign({ @@ -976,7 +986,7 @@ describe('Unit: Prebid Module', function () { inIframe = true; sinon.stub(utils, 'inIframe').callsFake(() => inIframe); - triggerPixelStub = sinon.stub(utils, 'triggerPixel'); + triggerPixelStub = sinon.stub(utils.internal, 'triggerPixel'); }); afterEach(function () { @@ -984,7 +994,7 @@ describe('Unit: Prebid Module', function () { utils.logError.restore(); utils.logMessage.restore(); utils.inIframe.restore(); - utils.triggerPixel.restore(); + triggerPixelStub.restore(); }); it('should require doc and id params', function () { @@ -1024,7 +1034,7 @@ describe('Unit: Prebid Module', function () { assert.ok(spyLogError.calledWith(error), 'expected error was logged'); }); - it('should log an error when not in an iFrame', () => { + it('should log an error when not in an iFrame', function () { pushBidResponseToAuction({ ad: "" }); @@ -1034,7 +1044,7 @@ describe('Unit: Prebid Module', function () { assert.ok(spyLogError.calledWith(error), 'expected error was logged'); }); - it('should not render videos', () => { + it('should not render videos', function () { pushBidResponseToAuction({ mediatype: 'video' }); @@ -1070,7 +1080,7 @@ describe('Unit: Prebid Module', function () { assert.deepEqual($$PREBID_GLOBAL$$.getAllWinningBids()[0], adResponse); }); - it('fires billing url if present on s2s bid', () => { + it('fires billing url if present on s2s bid', function () { const burl = 'http://www.example.com/burl'; pushBidResponseToAuction({ ad: '
ad
', @@ -1085,7 +1095,7 @@ describe('Unit: Prebid Module', function () { }); }); - describe('requestBids', () => { + describe('requestBids', function () { let logMessageSpy; let makeRequestsStub; let xhr; @@ -1128,9 +1138,9 @@ describe('Unit: Prebid Module', function () { 'start': 1000 }]; - beforeEach(() => { + beforeEach(function () { logMessageSpy = sinon.spy(utils, 'logMessage'); - makeRequestsStub = sinon.stub(adaptermanager, 'makeBidRequests'); + makeRequestsStub = sinon.stub(adapterManager, 'makeBidRequests'); makeRequestsStub.returns(bidRequests); xhr = sinon.useFakeXMLHttpRequest(); @@ -1151,21 +1161,22 @@ describe('Unit: Prebid Module', function () { createAuctionStub.returns(auction); }); - afterEach(() => { + afterEach(function () { clock.restore(); - adaptermanager.makeBidRequests.restore(); + adapterManager.makeBidRequests.restore(); auctionModule.newAuction.restore(); utils.logMessage.restore(); xhr.restore(); }); - it('should execute callback after timeout', () => { + it('should execute callback after timeout', function () { let spec = { code: BIDDER_CODE, isBidRequestValid: sinon.stub(), buildRequests: sinon.stub(), interpretResponse: sinon.stub(), - getUserSyncs: sinon.stub() + getUserSyncs: sinon.stub(), + onTimeout: sinon.stub() }; registerBidder(spec); @@ -1190,20 +1201,103 @@ describe('Unit: Prebid Module', function () { expect(bidsBackHandlerStub.getCall(0).args[1]).to.equal(true, 'bidsBackHandler should be called with timedOut=true'); + + sinon.assert.called(spec.onTimeout); + }); + + it('should execute callback after setTargeting', function () { + let spec = { + code: BIDDER_CODE, + isBidRequestValid: sinon.stub(), + buildRequests: sinon.stub(), + interpretResponse: sinon.stub(), + onSetTargeting: sinon.stub() + }; + + registerBidder(spec); + spec.buildRequests.returns([{'id': 123, 'method': 'POST'}]); + spec.isBidRequestValid.returns(true); + spec.interpretResponse.returns(bids); + + const bidId = 1; + const auctionId = 1; + let adResponse = Object.assign({ + auctionId: auctionId, + adId: String(bidId), + width: 300, + height: 250, + adUnitCode: bidRequests[0].bids[0].adUnitCode, + adserverTargeting: { + 'hb_bidder': BIDDER_CODE, + 'hb_adid': bidId, + 'hb_pb': bids[0].cpm, + 'hb_size': '300x250', + }, + bidder: bids[0].bidderCode, + }, bids[0]); + auction.getBidsReceived = function() { return [adResponse]; } + auction.getAuctionId = () => auctionId; + + clock = sinon.useFakeTimers(); + let requestObj = { + bidsBackHandler: null, // does not need to be defined because of newAuction mock in beforeEach + timeout: 2000, + adUnits: adUnits + }; + + $$PREBID_GLOBAL$$.requestBids(requestObj); + $$PREBID_GLOBAL$$.setTargetingForGPTAsync(); + + sinon.assert.called(spec.onSetTargeting); }); }) - describe('requestBids', () => { + describe('requestBids', function () { + let sandbox; + beforeEach(function () { + sandbox = sinon.sandbox.create(); + }); + afterEach(function () { + sandbox.restore(); + }); + describe('bidRequests is empty', function () { + it('should log warning message and execute callback if bidRequests is empty', function () { + let bidsBackHandler = function bidsBackHandlerCallback() {}; + let spyExecuteCallback = sinon.spy(bidsBackHandler); + let logWarnSpy = sandbox.spy(utils, 'logWarn'); + + $$PREBID_GLOBAL$$.requestBids({ + adUnits: [ + { + code: 'test1', + bids: [], + }, { + code: 'test2', + bids: [], + } + ], + bidsBackHandler: spyExecuteCallback + }); + + assert.ok(logWarnSpy.calledWith('No valid bid requests returned for auction'), 'expected warning message was logged'); + assert.ok(spyExecuteCallback.calledOnce, 'callback executed when bidRequests is empty'); + }); + }); + }); + + describe('requestBids', function () { let xhr; let requests; - beforeEach(() => { + beforeEach(function () { xhr = sinon.useFakeXMLHttpRequest(); requests = []; xhr.onCreate = request => requests.push(request); }); - afterEach(() => xhr.restore()); + afterEach(function () { + xhr.restore(); + }); var adUnitsBackup; var auctionManagerStub; let logMessageSpy @@ -1217,10 +1311,10 @@ describe('Unit: Prebid Module', function () { }; registerBidder(spec); - describe('part 1', () => { + describe('part 1', function () { let auctionArgs; - beforeEach(() => { + beforeEach(function () { adUnitsBackup = auction.getAdUnits auctionManagerStub = sinon.stub(auctionManager, 'createAuction').callsFake(function() { auctionArgs = arguments[0]; @@ -1229,14 +1323,14 @@ describe('Unit: Prebid Module', function () { logMessageSpy = sinon.spy(utils, 'logMessage'); }); - afterEach(() => { + afterEach(function () { auction.getAdUnits = adUnitsBackup; auctionManager.createAuction.restore(); utils.logMessage.restore(); resetAuction(); }); - it('should log message when adUnits not configured', () => { + it('should log message when adUnits not configured', function () { $$PREBID_GLOBAL$$.adUnits = []; try { $$PREBID_GLOBAL$$.requestBids({}); @@ -1246,7 +1340,7 @@ describe('Unit: Prebid Module', function () { assert.ok(logMessageSpy.calledWith('No adUnits configured. No bids requested.'), 'expected message was logged'); }); - it('should attach transactionIds to ads (or pass through transactionId if it already exists)', () => { + it('should always attach new transactionIds to adUnits passed to requestBids', function () { $$PREBID_GLOBAL$$.requestBids({ adUnits: [ { @@ -1261,12 +1355,36 @@ describe('Unit: Prebid Module', function () { }); expect(auctionArgs.adUnits[0]).to.have.property('transactionId') - .and.to.equal('d0676a3c-ff32-45a5-af65-8175a8e7ddca'); + .and.to.match(/[a-f0-9\-]{36}/i) + .and.not.to.equal('d0676a3c-ff32-45a5-af65-8175a8e7ddca'); expect(auctionArgs.adUnits[1]).to.have.property('transactionId') .and.to.match(/[a-f0-9\-]{36}/i); }); - it('should execute callback immediately if adUnits is empty', () => { + it('should notify targeting of the latest auction for each adUnit', function () { + let latestStub = sinon.stub(targeting, 'setLatestAuctionForAdUnit'); + let getAuctionStub = sinon.stub(auction, 'getAuctionId').returns(2); + + $$PREBID_GLOBAL$$.requestBids({ + adUnits: [ + { + code: 'test1', + bids: [] + }, { + code: 'test2', + bids: [] + } + ] + }); + + expect(latestStub.firstCall.calledWith('test1', 2)).to.equal(true); + expect(latestStub.secondCall.calledWith('test2', 2)).to.equal(true); + + latestStub.restore(); + getAuctionStub.restore(); + }); + + it('should execute callback immediately if adUnits is empty', function () { var bidsBackHandler = function bidsBackHandlerCallback() {}; var spyExecuteCallback = sinon.spy(bidsBackHandler); @@ -1279,7 +1397,7 @@ describe('Unit: Prebid Module', function () { ' empty'); }); - it('should not propagate exceptions from bidsBackHandler', () => { + it('should not propagate exceptions from bidsBackHandler', function () { $$PREBID_GLOBAL$$.adUnits = []; var requestObj = { @@ -1295,12 +1413,12 @@ describe('Unit: Prebid Module', function () { }); }); - describe('multiformat requests', () => { + describe('multiformat requests', function () { let spyCallBids; let createAuctionStub; let adUnits; - beforeEach(() => { + beforeEach(function () { adUnits = [{ code: 'adUnit-code', mediaTypes: { @@ -1316,34 +1434,34 @@ describe('Unit: Prebid Module', function () { adUnitCodes = ['adUnit-code']; configObj.setConfig({maxRequestsPerOrigin: Number.MAX_SAFE_INTEGER || 99999999}); let auction = auctionModule.newAuction({adUnits, adUnitCodes, callback: function() {}, cbTimeout: timeout}); - spyCallBids = sinon.spy(adaptermanager, 'callBids'); + spyCallBids = sinon.spy(adapterManager, 'callBids'); createAuctionStub = sinon.stub(auctionModule, 'newAuction'); createAuctionStub.returns(auction); }) - afterEach(() => { + afterEach(function () { auctionModule.newAuction.restore(); - adaptermanager.callBids.restore(); + adapterManager.callBids.restore(); }); - it('bidders that support one of the declared formats are allowed to participate', () => { + it('bidders that support one of the declared formats are allowed to participate', function () { $$PREBID_GLOBAL$$.requestBids({adUnits}); - sinon.assert.calledOnce(adaptermanager.callBids); + sinon.assert.calledOnce(adapterManager.callBids); - const spyArgs = adaptermanager.callBids.getCall(0); + const spyArgs = adapterManager.callBids.getCall(0); const biddersCalled = spyArgs.args[0][0].bids; // appnexus and sampleBidder both support banner expect(biddersCalled.length).to.equal(2); }); - it('bidders that do not support one of the declared formats are dropped', () => { + it('bidders that do not support one of the declared formats are dropped', function () { delete adUnits[0].mediaTypes.banner; $$PREBID_GLOBAL$$.requestBids({adUnits}); - sinon.assert.calledOnce(adaptermanager.callBids); + sinon.assert.calledOnce(adapterManager.callBids); - const spyArgs = adaptermanager.callBids.getCall(0); + const spyArgs = adapterManager.callBids.getCall(0); const biddersCalled = spyArgs.args[0][0].bids; // only appnexus supports native @@ -1351,12 +1469,12 @@ describe('Unit: Prebid Module', function () { }); }); - describe('part 2', () => { + describe('part 2', function () { let spyCallBids; let createAuctionStub; let adUnits; - before(() => { + before(function () { adUnits = [{ code: 'adUnit-code', sizes: [[300, 250], [300, 600]], @@ -1387,24 +1505,24 @@ describe('Unit: Prebid Module', function () { createAuctionStub.returns(auction); }); - after(() => { + after(function () { auctionModule.newAuction.restore(); }); - beforeEach(() => { - spyCallBids = sinon.spy(adaptermanager, 'callBids'); + beforeEach(function () { + spyCallBids = sinon.spy(adapterManager, 'callBids'); }) - afterEach(() => { - adaptermanager.callBids.restore(); + afterEach(function () { + adapterManager.callBids.restore(); }) - it('should callBids if a native adUnit has all native bidders', () => { + it('should callBids if a native adUnit has all native bidders', function () { $$PREBID_GLOBAL$$.requestBids({adUnits}); - sinon.assert.calledOnce(adaptermanager.callBids); + sinon.assert.calledOnce(adapterManager.callBids); }); - it('should call callBids function on adaptermanager', () => { + it('should call callBids function on adapterManager', function () { let adUnits = [{ code: 'adUnit-code', sizes: [[300, 250], [300, 600]], @@ -1413,10 +1531,10 @@ describe('Unit: Prebid Module', function () { ] }]; $$PREBID_GLOBAL$$.requestBids({adUnits}); - assert.ok(spyCallBids.called, 'called adaptermanager.callBids'); + assert.ok(spyCallBids.called, 'called adapterManager.callBids'); }); - it('splits native type to individual native assets', () => { + it('splits native type to individual native assets', function () { let adUnits = [{ code: 'adUnit-code', nativeParams: {type: 'image'}, @@ -1426,7 +1544,7 @@ describe('Unit: Prebid Module', function () { ] }]; $$PREBID_GLOBAL$$.requestBids({adUnits}); - const spyArgs = adaptermanager.callBids.getCall(0); + const spyArgs = adapterManager.callBids.getCall(0); const nativeRequest = spyArgs.args[1][0].bids[0].nativeParams; expect(nativeRequest).to.deep.equal({ image: {required: true}, @@ -1440,7 +1558,7 @@ describe('Unit: Prebid Module', function () { }); }); - describe('part-3', () => { + describe('part-3', function () { let auctionManagerInstance = newAuctionManager(); let auctionManagerStub; let adUnits1 = getAdUnits().filter((adUnit) => { @@ -1489,7 +1607,7 @@ describe('Unit: Prebid Module', function () { }; beforeEach(function() { - spyCallBids = sinon.spy(adaptermanager, 'callBids'); + spyCallBids = sinon.spy(adapterManager, 'callBids'); auctionManagerStub = sinon.stub(auctionManager, 'createAuction'); auctionManagerStub.onCall(0).returns(auction1); auctionManagerStub.onCall(1).returns(auction2); @@ -1497,10 +1615,10 @@ describe('Unit: Prebid Module', function () { afterEach(function() { auctionManager.createAuction.restore(); - adaptermanager.callBids.restore(); + adapterManager.callBids.restore(); }); - it('should not queue bid requests when a previous bid request is in process', () => { + it('should not queue bid requests when a previous bid request is in process', function () { var requestObj1 = { bidsBackHandler: function bidsBackHandlerCallback() {}, timeout: 2000, @@ -1525,16 +1643,16 @@ describe('Unit: Prebid Module', function () { let expected = { '/19968336/header-bid-tag-0': { 'foobar': '0x0,300x250,300x600', - 'hb_size': '300x250', - 'hb_pb': '10.00', - 'hb_adid': '233bcbee889d46d', - 'hb_bidder': 'appnexus' + [CONSTANTS.TARGETING_KEYS.SIZE]: '300x250', + [CONSTANTS.TARGETING_KEYS.PRICE_BUCKET]: '10.00', + [CONSTANTS.TARGETING_KEYS.AD_ID]: '233bcbee889d46d', + [CONSTANTS.TARGETING_KEYS.BIDDER]: 'appnexus' }, '/19968336/header-bid-tag1': { - 'hb_bidder': 'appnexus', - 'hb_adid': '24bd938435ec3fc', - 'hb_pb': '10.00', - 'hb_size': '728x90', + [CONSTANTS.TARGETING_KEYS.BIDDER]: 'appnexus', + [CONSTANTS.TARGETING_KEYS.AD_ID]: '24bd938435ec3fc', + [CONSTANTS.TARGETING_KEYS.PRICE_BUCKET]: '10.00', + [CONSTANTS.TARGETING_KEYS.SIZE]: '728x90', 'foobar': '728x90' } } @@ -1543,8 +1661,8 @@ describe('Unit: Prebid Module', function () { }); }); - describe('onEvent', () => { - it('should log an error when handler is not a function', () => { + describe('onEvent', function () { + it('should log an error when handler is not a function', function () { var spyLogError = sinon.spy(utils, 'logError'); var event = 'testEvent'; $$PREBID_GLOBAL$$.onEvent(event); @@ -1553,7 +1671,7 @@ describe('Unit: Prebid Module', function () { utils.logError.restore(); }); - it('should log an error when id provided is not valid for event', () => { + it('should log an error when id provided is not valid for event', function () { var spyLogError = sinon.spy(utils, 'logError'); var event = 'bidWon'; $$PREBID_GLOBAL$$.onEvent(event, Function, 'testId'); @@ -1562,7 +1680,7 @@ describe('Unit: Prebid Module', function () { utils.logError.restore(); }); - it('should call events.on with valid parameters', () => { + it('should call events.on with valid parameters', function () { var spyEventsOn = sinon.spy(events, 'on'); $$PREBID_GLOBAL$$.onEvent('bidWon', Function); assert.ok(spyEventsOn.calledWith('bidWon', Function)); @@ -1570,15 +1688,15 @@ describe('Unit: Prebid Module', function () { }); }); - describe('offEvent', () => { - it('should return when id provided is not valid for event', () => { + describe('offEvent', function () { + it('should return when id provided is not valid for event', function () { var spyEventsOff = sinon.spy(events, 'off'); $$PREBID_GLOBAL$$.offEvent('bidWon', Function, 'testId'); assert.ok(spyEventsOff.notCalled); events.off.restore(); }); - it('should call events.off with valid parameters', () => { + it('should call events.off with valid parameters', function () { var spyEventsOff = sinon.spy(events, 'off'); $$PREBID_GLOBAL$$.offEvent('bidWon', Function); assert.ok(spyEventsOff.calledWith('bidWon', Function)); @@ -1586,24 +1704,24 @@ describe('Unit: Prebid Module', function () { }); }); - describe('emit', () => { - it('should be able to emit event without arguments', () => { + describe('emit', function () { + it('should be able to emit event without arguments', function () { var spyEventsEmit = sinon.spy(events, 'emit'); - events.emit(CONSTANTS.EVENTS.AUCTION_END); - assert.ok(spyEventsEmit.calledWith('auctionEnd')); + events.emit(CONSTANTS.EVENTS.REQUEST_BIDS); + assert.ok(spyEventsEmit.calledWith('requestBids')); events.emit.restore(); }); }); - describe('registerBidAdapter', () => { - it('should register bidAdaptor with adaptermanager', () => { - var registerBidAdapterSpy = sinon.spy(adaptermanager, 'registerBidAdapter'); + describe('registerBidAdapter', function () { + it('should register bidAdaptor with adapterManager', function () { + var registerBidAdapterSpy = sinon.spy(adapterManager, 'registerBidAdapter'); $$PREBID_GLOBAL$$.registerBidAdapter(Function, 'biddercode'); - assert.ok(registerBidAdapterSpy.called, 'called adaptermanager.registerBidAdapter'); - adaptermanager.registerBidAdapter.restore(); + assert.ok(registerBidAdapterSpy.called, 'called adapterManager.registerBidAdapter'); + adapterManager.registerBidAdapter.restore(); }); - it('should catch thrown errors', () => { + it('should catch thrown errors', function () { var spyLogError = sinon.spy(utils, 'logError'); var errorObject = { message: 'bidderAdaptor error' }; var bidderAdaptor = sinon.stub().throws(errorObject); @@ -1616,8 +1734,8 @@ describe('Unit: Prebid Module', function () { }); }); - describe('createBid', () => { - it('should return a bid object', () => { + describe('createBid', function () { + it('should return a bid object', function () { const statusCode = 1; const bid = $$PREBID_GLOBAL$$.createBid(statusCode); assert.isObject(bid, 'bid is an object'); @@ -1629,31 +1747,29 @@ describe('Unit: Prebid Module', function () { }); }); - describe('loadScript', () => { - it('should call adloader.loadScript', () => { - const loadScriptSpy = sinon.spy(adloader, 'loadScript'); + describe('loadScript', function () { + it('should call adloader.loadScript', function () { const tagSrc = ''; const callback = Function; const useCache = false; $$PREBID_GLOBAL$$.loadScript(tagSrc, callback, useCache); - assert.ok(loadScriptSpy.calledWith(tagSrc, callback, useCache), 'called adloader.loadScript'); - adloader.loadScript.restore(); + assert.ok(adloader.loadScriptStub.calledWith(tagSrc, callback, useCache), 'called adloader.loadScript'); }); }); - describe('aliasBidder', () => { - it('should call adaptermanager.aliasBidder', () => { - const aliasBidAdapterSpy = sinon.spy(adaptermanager, 'aliasBidAdapter'); + describe('aliasBidder', function () { + it('should call adapterManager.aliasBidder', function () { + const aliasBidAdapterSpy = sinon.spy(adapterManager, 'aliasBidAdapter'); const bidderCode = 'testcode'; const alias = 'testalias'; $$PREBID_GLOBAL$$.aliasBidder(bidderCode, alias); - assert.ok(aliasBidAdapterSpy.calledWith(bidderCode, alias), 'called adaptermanager.aliasBidAdapterSpy'); - adaptermanager.aliasBidAdapter.restore(); + assert.ok(aliasBidAdapterSpy.calledWith(bidderCode, alias), 'called adapterManager.aliasBidAdapterSpy'); + adapterManager.aliasBidAdapter(); }); - it('should log error when not passed correct arguments', () => { + it('should log error when not passed correct arguments', function () { const logErrorSpy = sinon.spy(utils, 'logError'); const error = 'bidderCode and alias must be passed as arguments'; @@ -1663,8 +1779,8 @@ describe('Unit: Prebid Module', function () { }); }); - describe('setPriceGranularity', () => { - it('should log error when not passed granularity', () => { + describe('setPriceGranularity', function () { + it('should log error when not passed granularity', function () { const logErrorSpy = sinon.spy(utils, 'logError'); const error = 'Prebid Error: no value passed to `setPriceGranularity()`'; @@ -1673,7 +1789,7 @@ describe('Unit: Prebid Module', function () { utils.logError.restore(); }); - it('should log error when not passed a valid config object', () => { + it('should log error when not passed a valid config object', function () { const logErrorSpy = sinon.spy(utils, 'logError'); const error = 'Invalid custom price value passed to `setPriceGranularity()`'; const badConfig = { @@ -1696,7 +1812,7 @@ describe('Unit: Prebid Module', function () { utils.logError.restore(); }); - it('should set customPriceBucket with custom config buckets', () => { + it('should set customPriceBucket with custom config buckets', function () { let customPriceBucket = configObj.getConfig('customPriceBucket'); const goodConfig = { 'buckets': [{ @@ -1715,21 +1831,21 @@ describe('Unit: Prebid Module', function () { }); }); - describe('emit event', () => { + describe('emit event', function () { let auctionManagerStub; - beforeEach(() => { + beforeEach(function () { auctionManagerStub = sinon.stub(auctionManager, 'createAuction').callsFake(function() { return auction; }); }); - afterEach(() => { + afterEach(function () { auctionManager.createAuction.restore(); }); }); - describe('removeAdUnit', () => { - it('should remove given adUnit in adUnits array', () => { + describe('removeAdUnit', function () { + it('should remove given adUnit in adUnits array', function () { const adUnit1 = { code: 'adUnit1', bids: [{ @@ -1757,16 +1873,16 @@ describe('Unit: Prebid Module', function () { }); }); - describe('getDealTargeting', () => { - beforeEach(() => { + describe('getDealTargeting', function () { + beforeEach(function () { resetAuction(); }); - afterEach(() => { + afterEach(function () { resetAuction(); }); - it('should truncate deal keys', () => { + it('should truncate deal keys', function () { $$PREBID_GLOBAL$$._bidsReceived = [ { 'bidderCode': 'appnexusDummyName', @@ -1791,12 +1907,12 @@ describe('Unit: Prebid Module', function () { 'alwaysUseBid': true, 'auctionId': 123456, 'adserverTargeting': { - 'hb_bidder': 'appnexus', - 'hb_adid': '233bcbee889d46d', - 'hb_pb': '10.00', - 'hb_size': '300x250', 'foobar': '300x250', - 'hb_deal_appnexusDummyName': '1234' + [CONSTANTS.TARGETING_KEYS.BIDDER]: 'appnexus', + [CONSTANTS.TARGETING_KEYS.AD_ID]: '233bcbee889d46d', + [CONSTANTS.TARGETING_KEYS.PRICE_BUCKET]: '10.00', + [CONSTANTS.TARGETING_KEYS.SIZE]: '300x250', + [CONSTANTS.TARGETING_KEYS.DEAL + '_appnexusDummyName']: '1234' } } ]; @@ -1816,18 +1932,18 @@ describe('Unit: Prebid Module', function () { // expect(highestCpmBids[1]).to.deep.equal(auctionManager.getBidsReceived()[2]); // }); - it('returns an array containing the highest bid object for the given adUnitCode', () => { + it('returns an array containing the highest bid object for the given adUnitCode', function () { const highestCpmBids = $$PREBID_GLOBAL$$.getHighestCpmBids('/19968336/header-bid-tag-0'); expect(highestCpmBids.length).to.equal(1); expect(highestCpmBids[0]).to.deep.equal(auctionManager.getBidsReceived()[1]); }); - it('returns an empty array when the given adUnit is not found', () => { + it('returns an empty array when the given adUnit is not found', function () { const highestCpmBids = $$PREBID_GLOBAL$$.getHighestCpmBids('/stallone'); expect(highestCpmBids.length).to.equal(0); }); - it('returns an empty array when the given adUnit has no bids', () => { + it('returns an empty array when the given adUnit has no bids', function () { let _bidsReceived = getBidResponses()[0]; _bidsReceived.cpm = 0; auction.getBidsReceived = function() { return _bidsReceived }; @@ -1838,8 +1954,8 @@ describe('Unit: Prebid Module', function () { }); }); - describe('markWinningBidAsUsed', () => { - it('marks the bid object as used for the given adUnitCode/adId combination', () => { + describe('markWinningBidAsUsed', function () { + it('marks the bid object as used for the given adUnitCode/adId combination', function () { // make sure the auction has "state" and does not reload the fixtures const adUnitCode = '/19968336/header-bid-tag-0'; const bidsReceived = $$PREBID_GLOBAL$$.getBidResponsesForAdUnitCode(adUnitCode); @@ -1848,30 +1964,28 @@ describe('Unit: Prebid Module', function () { // mark the bid and verify the state has changed to RENDERED const winningBid = targeting.getWinningBids(adUnitCode)[0]; $$PREBID_GLOBAL$$.markWinningBidAsUsed({ adUnitCode, adId: winningBid.adId }); - const markedBid = $$PREBID_GLOBAL$$.getBidResponsesForAdUnitCode(adUnitCode) - .bids - .find(bid => bid.adId === winningBid.adId); + const markedBid = find($$PREBID_GLOBAL$$.getBidResponsesForAdUnitCode(adUnitCode).bids, + bid => bid.adId === winningBid.adId); - expect(markedBid.status).to.equal(RENDERED); + expect(markedBid.status).to.equal(CONSTANTS.BID_STATUS.RENDERED); resetAuction(); }); - it('try and mark the bid object, but fail because we supplied the wrong adId', () => { + it('try and mark the bid object, but fail because we supplied the wrong adId', function () { const adUnitCode = '/19968336/header-bid-tag-0'; const bidsReceived = $$PREBID_GLOBAL$$.getBidResponsesForAdUnitCode(adUnitCode); auction.getBidsReceived = function() { return bidsReceived.bids }; const winningBid = targeting.getWinningBids(adUnitCode)[0]; $$PREBID_GLOBAL$$.markWinningBidAsUsed({ adUnitCode, adId: 'miss' }); - const markedBid = $$PREBID_GLOBAL$$.getBidResponsesForAdUnitCode(adUnitCode) - .bids - .find(bid => bid.adId === winningBid.adId); + const markedBid = find($$PREBID_GLOBAL$$.getBidResponsesForAdUnitCode(adUnitCode).bids, + bid => bid.adId === winningBid.adId); - expect(markedBid.status).to.not.equal(RENDERED); + expect(markedBid.status).to.not.equal(CONSTANTS.BID_STATUS.RENDERED); resetAuction(); }); - it('marks the winning bid object as used for the given adUnitCode', () => { + it('marks the winning bid object as used for the given adUnitCode', function () { // make sure the auction has "state" and does not reload the fixtures const adUnitCode = '/19968336/header-bid-tag-0'; const bidsReceived = $$PREBID_GLOBAL$$.getBidResponsesForAdUnitCode(adUnitCode); @@ -1880,15 +1994,14 @@ describe('Unit: Prebid Module', function () { // mark the bid and verify the state has changed to RENDERED const winningBid = targeting.getWinningBids(adUnitCode)[0]; $$PREBID_GLOBAL$$.markWinningBidAsUsed({ adUnitCode }); - const markedBid = $$PREBID_GLOBAL$$.getBidResponsesForAdUnitCode(adUnitCode) - .bids - .find(bid => bid.adId === winningBid.adId); + const markedBid = find($$PREBID_GLOBAL$$.getBidResponsesForAdUnitCode(adUnitCode).bids, + bid => bid.adId === winningBid.adId); - expect(markedBid.status).to.equal(RENDERED); + expect(markedBid.status).to.equal(CONSTANTS.BID_STATUS.RENDERED); resetAuction(); }); - it('marks a bid object as used for the given adId', () => { + it('marks a bid object as used for the given adId', function () { // make sure the auction has "state" and does not reload the fixtures const adUnitCode = '/19968336/header-bid-tag-0'; const bidsReceived = $$PREBID_GLOBAL$$.getBidResponsesForAdUnitCode(adUnitCode); @@ -1897,20 +2010,19 @@ describe('Unit: Prebid Module', function () { // mark the bid and verify the state has changed to RENDERED const winningBid = targeting.getWinningBids(adUnitCode)[0]; $$PREBID_GLOBAL$$.markWinningBidAsUsed({ adId: winningBid.adId }); - const markedBid = $$PREBID_GLOBAL$$.getBidResponsesForAdUnitCode(adUnitCode) - .bids - .find(bid => bid.adId === winningBid.adId); + const markedBid = find($$PREBID_GLOBAL$$.getBidResponsesForAdUnitCode(adUnitCode).bids, + bid => bid.adId === winningBid.adId); - expect(markedBid.status).to.equal(RENDERED); + expect(markedBid.status).to.equal(CONSTANTS.BID_STATUS.RENDERED); resetAuction(); }); }); - describe('setTargetingForAst', () => { + describe('setTargetingForAst', function () { let targeting; let auctionManagerInstance; - beforeEach(() => { + beforeEach(function () { resetAuction(); auctionManagerInstance = newAuctionManager(); sinon.stub(auctionManagerInstance, 'getBidsReceived').callsFake(function() { @@ -1925,13 +2037,13 @@ describe('Unit: Prebid Module', function () { targeting = newTargeting(auctionManagerInstance); }); - afterEach(() => { + afterEach(function () { auctionManagerInstance.getBidsReceived.restore(); auctionManagerInstance.getAdUnitCodes.restore(); resetAuction(); }); - it('should set targeting for appnexus apntag object', () => { + it('should set targeting for appnexus apntag object', function () { const bids = auctionManagerInstance.getBidsReceived(); const adUnitCode = '/19968336/header-bid-tag-0'; @@ -1950,11 +2062,11 @@ describe('Unit: Prebid Module', function () { expect(newAdserverTargeting).to.deep.equal(window.apntag.tags[adUnitCode].keywords); }); - it('should not find hb_adid key in lowercase for all bidders', () => { + it('should not find ' + CONSTANTS.TARGETING_KEYS.AD_ID + ' key in lowercase for all bidders', function() { const adUnitCode = '/19968336/header-bid-tag-0'; $$PREBID_GLOBAL$$.setConfig({ enableSendAllBids: true }); targeting.setTargetingForAst(); - const keywords = Object.keys(window.apntag.tags[adUnitCode].keywords).filter(keyword => (keyword.substring(0, 'hb_adid'.length) === 'hb_adid')); + const keywords = Object.keys(window.apntag.tags[adUnitCode].keywords).filter(keyword => (keyword.substring(0, CONSTANTS.TARGETING_KEYS.AD_ID.length) === CONSTANTS.TARGETING_KEYS.AD_ID)); expect(keywords.length).to.equal(0); }); }); @@ -1993,17 +2105,17 @@ describe('Unit: Prebid Module', function () { }); }); - describe('getAllPrebidWinningBids', () => { + describe('getAllPrebidWinningBids', function () { let auctionManagerStub; - beforeEach(() => { + beforeEach(function () { auctionManagerStub = sinon.stub(auctionManager, 'getBidsReceived'); }); - afterEach(() => { + afterEach(function () { auctionManagerStub.restore(); }); - it('should return prebid auction winning bids', () => { + it('should return prebid auction winning bids', function () { let bidsReceived = [ createBidReceived({bidder: 'appnexus', cpm: 7, auctionId: 1, responseTimestamp: 100, adUnitCode: 'code-0', adId: 'adid-1', status: 'targetingSet'}), createBidReceived({bidder: 'rubicon', cpm: 6, auctionId: 1, responseTimestamp: 101, adUnitCode: 'code-1', adId: 'adid-2'}), diff --git a/test/spec/url_spec.js b/test/spec/url_spec.js index cfa1b0c80b4..90047273043 100644 --- a/test/spec/url_spec.js +++ b/test/spec/url_spec.js @@ -1,31 +1,31 @@ import {format, parse} from '../../src/url'; import { expect } from 'chai'; -describe('helpers.url', () => { - describe('parse()', () => { +describe('helpers.url', function () { + describe('parse()', function () { let parsed; - beforeEach(() => { + beforeEach(function () { parsed = parse('http://example.com:3000/pathname/?search=test&foo=bar&bar=foo%26foo%3Dxxx#hash'); }); - it('extracts the protocol', () => { + it('extracts the protocol', function () { expect(parsed).to.have.property('protocol', 'http'); }); - it('extracts the hostname', () => { + it('extracts the hostname', function () { expect(parsed).to.have.property('hostname', 'example.com'); }); - it('extracts the port', () => { + it('extracts the port', function () { expect(parsed).to.have.property('port', 3000); }); - it('extracts the pathname', () => { + it('extracts the pathname', function () { expect(parsed).to.have.property('pathname', '/pathname/'); }); - it('extracts the search query', () => { + it('extracts the search query', function () { expect(parsed).to.have.property('search'); expect(parsed.search).to.eql({ foo: 'xxx', @@ -34,23 +34,23 @@ describe('helpers.url', () => { }); }); - it('extracts the hash', () => { + it('extracts the hash', function () { expect(parsed).to.have.property('hash', 'hash'); }); - it('extracts the host', () => { + it('extracts the host', function () { expect(parsed).to.have.property('host', 'example.com:3000'); }); }); - describe('parse(url, {noDecodeWholeURL: true})', () => { + describe('parse(url, {noDecodeWholeURL: true})', function () { let parsed; - beforeEach(() => { + beforeEach(function () { parsed = parse('http://example.com:3000/pathname/?search=test&foo=bar&bar=foo%26foo%3Dxxx#hash', {noDecodeWholeURL: true}); }); - it('extracts the search query', () => { + it('extracts the search query', function () { expect(parsed).to.have.property('search'); expect(parsed.search).to.eql({ foo: 'bar', @@ -60,8 +60,8 @@ describe('helpers.url', () => { }); }); - describe('format()', () => { - it('formats an object in to a URL', () => { + describe('format()', function () { + it('formats an object in to a URL', function () { expect(format({ protocol: 'http', hostname: 'example.com', @@ -72,21 +72,21 @@ describe('helpers.url', () => { })).to.equal('http://example.com:3000/pathname/?foo=bar&search=test&bar=foo%26foo%3Dxxx#hash'); }); - it('will use defaults for missing properties', () => { + it('will use defaults for missing properties', function () { expect(format({ hostname: 'example.com' })).to.equal('http://example.com'); }); }); - describe('parse(url, {decodeSearchAsString: true})', () => { + describe('parse(url, {decodeSearchAsString: true})', function () { let parsed; - beforeEach(() => { + beforeEach(function () { parsed = parse('http://example.com:3000/pathname/?search=test&foo=bar&bar=foo%26foo%3Dxxx#hash', {decodeSearchAsString: true}); }); - it('extracts the search query', () => { + it('extracts the search query', function () { expect(parsed).to.have.property('search'); expect(parsed.search).to.equal('?search=test&foo=bar&bar=foo&foo=xxx'); }); diff --git a/test/spec/userSync_spec.js b/test/spec/userSync_spec.js index 60e07441e0c..dfe6372288f 100644 --- a/test/spec/userSync_spec.js +++ b/test/spec/userSync_spec.js @@ -4,7 +4,7 @@ import { config } from 'src/config'; const utils = require('../../src/utils'); let { newUserSync } = require('../../src/userSync'); -describe('user sync', () => { +describe('user sync', function () { let triggerPixelStub; let logWarnStub; let timeoutStub; @@ -25,15 +25,15 @@ describe('user sync', () => { }) } let clock; - before(() => { + before(function () { clock = sinon.useFakeTimers(); }); - after(() => { + after(function () { clock.restore(); }); - beforeEach(() => { + beforeEach(function () { triggerPixelStub = sinon.stub(utils, 'triggerPixel'); logWarnStub = sinon.stub(utils, 'logWarn'); shuffleStub = sinon.stub(utils, 'shuffle').callsFake((array) => array.reverse()); @@ -41,7 +41,7 @@ describe('user sync', () => { insertUserSyncIframeStub = sinon.stub(utils, 'insertUserSyncIframe'); }); - afterEach(() => { + afterEach(function () { triggerPixelStub.restore(); logWarnStub.restore(); shuffleStub.restore(); @@ -49,7 +49,7 @@ describe('user sync', () => { insertUserSyncIframeStub.restore(); }); - it('should register and fire a pixel URL', () => { + it('should register and fire a pixel URL', function () { const userSync = newTestUserSync(); userSync.registerSync('image', 'testBidder', 'http://example.com'); userSync.syncUsers(); @@ -57,13 +57,13 @@ describe('user sync', () => { expect(triggerPixelStub.getCall(0).args[0]).to.exist.and.to.equal('http://example.com'); }); - it('should clear queue after sync', () => { + it('should clear queue after sync', function () { const userSync = newTestUserSync(); userSync.syncUsers(); expect(triggerPixelStub.callCount).to.equal(0); }); - it('should delay firing a pixel by the expected amount', () => { + it('should delay firing a pixel by the expected amount', function () { const userSync = newTestUserSync(); userSync.registerSync('image', 'testBidder', 'http://example.com'); // This implicitly tests cookie and browser support @@ -72,7 +72,7 @@ describe('user sync', () => { expect(triggerPixelStub.getCall(0)).to.not.be.null; }); - it('should register and fires multiple pixel URLs', () => { + it('should register and fires multiple pixel URLs', function () { const userSync = newTestUserSync(); userSync.registerSync('image', 'testBidder', 'http://example.com/1'); userSync.registerSync('image', 'testBidder', 'http://example.com/2'); @@ -84,21 +84,21 @@ describe('user sync', () => { expect(triggerPixelStub.getCall(2)).to.be.null; }); - it('should not register pixel URL since it is not supported', () => { + it('should not register pixel URL since it is not supported', function () { const userSync = newTestUserSync({pixelEnabled: false}); userSync.registerSync('image', 'testBidder', 'http://example.com'); userSync.syncUsers(); expect(triggerPixelStub.getCall(0)).to.be.null; }); - it('should register and load an iframe', () => { + it('should register and load an iframe', function () { const userSync = newTestUserSync({iframeEnabled: true}); userSync.registerSync('iframe', 'testBidder', 'http://example.com/iframe'); userSync.syncUsers(); expect(insertUserSyncIframeStub.getCall(0).args[0]).to.equal('http://example.com/iframe'); }); - it('should only trigger syncs once per page', () => { + it('should only trigger syncs once per page', function () { const userSync = newTestUserSync({pixelEnabled: true}); userSync.registerSync('image', 'testBidder', 'http://example.com/1'); userSync.syncUsers(); @@ -109,20 +109,20 @@ describe('user sync', () => { expect(triggerPixelStub.getCall(1)).to.be.null; }); - it('should not fire syncs if cookies are not supported', () => { + it('should not fire syncs if cookies are not supported', function () { const userSync = newTestUserSync({pixelEnabled: true}, true); userSync.registerSync('image', 'testBidder', 'http://example.com'); userSync.syncUsers(); expect(triggerPixelStub.getCall(0)).to.be.null; }); - it('should prevent registering invalid type', () => { + it('should prevent registering invalid type', function () { const userSync = newTestUserSync(); userSync.registerSync('invalid', 'testBidder', 'http://example.com'); expect(logWarnStub.getCall(0).args[0]).to.exist; }); - it('should expose the syncUsers method for the publisher to manually trigger syncs', () => { + it('should expose the syncUsers method for the publisher to manually trigger syncs', function () { // triggerUserSyncs should do nothing by default let userSync = newTestUserSync(); let syncUsersSpy = sinon.spy(userSync, 'syncUsers'); @@ -135,7 +135,7 @@ describe('user sync', () => { expect(syncUsersSpy.called).to.be.true; }); - it('should limit the sync per bidder', () => { + it('should limit the number of syncs per bidder', function () { const userSync = newTestUserSync({syncsPerBidder: 2}); userSync.registerSync('image', 'testBidder', 'http://example.com/1'); userSync.registerSync('image', 'testBidder', 'http://example.com/2'); @@ -148,7 +148,21 @@ describe('user sync', () => { expect(triggerPixelStub.getCall(2)).to.be.null; }); - it('should balance out bidder requests', () => { + it('should not limit the number of syncs per bidder when set to 0', function() { + const userSync = newTestUserSync({syncsPerBidder: 0}); + userSync.registerSync('image', 'testBidder', 'http://example.com/1'); + userSync.registerSync('image', 'testBidder', 'http://example.com/2'); + userSync.registerSync('image', 'testBidder', 'http://example.com/3'); + userSync.syncUsers(); + expect(triggerPixelStub.getCall(0)).to.not.be.null; + expect(triggerPixelStub.getCall(0).args[0]).to.exist.and.to.match(/^http:\/\/example\.com\/[1|2|3]/); + expect(triggerPixelStub.getCall(1)).to.not.be.null; + expect(triggerPixelStub.getCall(1).args[0]).to.exist.and.to.match(/^http:\/\/example\.com\/[1|2|3]/); + expect(triggerPixelStub.getCall(2)).to.not.be.null; + expect(triggerPixelStub.getCall(2).args[0]).to.exist.and.to.match(/^http:\/\/example\.com\/[1|2|3]/); + }); + + it('should balance out bidder requests', function () { const userSync = newTestUserSync(); userSync.registerSync('image', 'atestBidder', 'http://example.com/1'); userSync.registerSync('image', 'atestBidder', 'http://example.com/3'); @@ -164,7 +178,7 @@ describe('user sync', () => { expect(triggerPixelStub.getCall(3)).to.be.null; }); - it('should disable user sync', () => { + it('should disable user sync', function () { const userSync = newTestUserSync({syncEnabled: false}); userSync.registerSync('pixel', 'testBidder', 'http://example.com'); expect(logWarnStub.getCall(0).args[0]).to.exist; @@ -172,7 +186,7 @@ describe('user sync', () => { expect(triggerPixelStub.getCall(0)).to.be.null; }); - it('should only sync enabled bidders', () => { + it('should only sync enabled bidders', function () { const userSync = newTestUserSync({enabledBidders: ['testBidderA']}); userSync.registerSync('image', 'testBidderA', 'http://example.com/1'); userSync.registerSync('image', 'testBidderB', 'http://example.com/2'); @@ -182,7 +196,7 @@ describe('user sync', () => { expect(triggerPixelStub.getCall(1)).to.be.null; }); - it('should register config set after instantiation', () => { + it('should register config set after instantiation', function () { // start with userSync off const userSync = newTestUserSync({syncEnabled: false}); // turn it on with setConfig() @@ -193,7 +207,7 @@ describe('user sync', () => { expect(triggerPixelStub.getCall(0).args[0]).to.exist.and.to.equal('http://example.com'); }); - it('should register both image and iframe pixels with filterSettings.all config', () => { + it('should register both image and iframe pixels with filterSettings.all config', function () { const userSync = newTestUserSync({ filterSettings: { all: { @@ -211,7 +225,7 @@ describe('user sync', () => { expect(insertUserSyncIframeStub.getCall(0).args[0]).to.equal('http://example.com/iframe'); }); - it('should register iframe and not register image pixels based on filterSettings config', () => { + it('should register iframe and not register image pixels based on filterSettings config', function () { const userSync = newTestUserSync({ filterSettings: { image: { @@ -231,7 +245,7 @@ describe('user sync', () => { expect(insertUserSyncIframeStub.getCall(0).args[0]).to.equal('http://example.com/iframe'); }); - it('should throw a warning and default to basic resgistration rules when filterSettings config is invalid', () => { + it('should throw a warning and default to basic resgistration rules when filterSettings config is invalid', function () { // invalid config - passed invalid filter option const userSync1 = newTestUserSync({ filterSettings: { @@ -317,7 +331,7 @@ describe('user sync', () => { expect(insertUserSyncIframeStub.getCall(0)).to.be.null; }); - it('should overwrite logic of deprecated fields when filterSettings is defined', () => { + it('should overwrite logic of deprecated fields when filterSettings is defined', function () { const userSync = newTestUserSync({ pixelsEnabled: false, iframeEnabled: true, diff --git a/test/spec/utils_spec.js b/test/spec/utils_spec.js index 454d6ed4136..df1c9b66b28 100755 --- a/test/spec/utils_spec.js +++ b/test/spec/utils_spec.js @@ -1,8 +1,9 @@ import { getAdServerTargeting } from 'test/fixtures/fixtures'; import { expect } from 'chai'; +import CONSTANTS from 'src/constants.json'; +import * as utils from 'src/utils'; var assert = require('assert'); -var utils = require('src/utils'); describe('Utils', function () { var obj_string = 's', @@ -101,7 +102,7 @@ describe('Utils', function () { var obj = getAdServerTargeting(); var output = utils.transformAdServerTargetingObj(obj[Object.keys(obj)[0]]); - var expected = 'foobar=0x0%2C300x250%2C300x600&hb_size=300x250&hb_pb=10.00&hb_adid=233bcbee889d46d&hb_bidder=appnexus&hb_size_triplelift=0x0&hb_pb_triplelift=10.00&hb_adid_triplelift=222bb26f9e8bd&hb_bidder_triplelift=triplelift&hb_size_appnexus=300x250&hb_pb_appnexus=10.00&hb_adid_appnexus=233bcbee889d46d&hb_bidder_appnexus=appnexus&hb_size_pagescience=300x250&hb_pb_pagescience=10.00&hb_adid_pagescience=25bedd4813632d7&hb_bidder_pagescienc=pagescience&hb_size_brightcom=300x250&hb_pb_brightcom=10.00&hb_adid_brightcom=26e0795ab963896&hb_bidder_brightcom=brightcom&hb_size_brealtime=300x250&hb_pb_brealtime=10.00&hb_adid_brealtime=275bd666f5a5a5d&hb_bidder_brealtime=brealtime&hb_size_pubmatic=300x250&hb_pb_pubmatic=10.00&hb_adid_pubmatic=28f4039c636b6a7&hb_bidder_pubmatic=pubmatic&hb_size_rubicon=300x600&hb_pb_rubicon=10.00&hb_adid_rubicon=29019e2ab586a5a&hb_bidder_rubicon=rubicon'; + var expected = 'foobar=0x0%2C300x250%2C300x600&' + CONSTANTS.TARGETING_KEYS.SIZE + '=300x250&' + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '=10.00&' + CONSTANTS.TARGETING_KEYS.AD_ID + '=233bcbee889d46d&' + CONSTANTS.TARGETING_KEYS.BIDDER + '=appnexus&' + CONSTANTS.TARGETING_KEYS.SIZE + '_triplelift=0x0&' + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_triplelift=10.00&' + CONSTANTS.TARGETING_KEYS.AD_ID + '_triplelift=222bb26f9e8bd&' + CONSTANTS.TARGETING_KEYS.BIDDER + '_triplelift=triplelift&' + CONSTANTS.TARGETING_KEYS.SIZE + '_appnexus=300x250&' + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_appnexus=10.00&' + CONSTANTS.TARGETING_KEYS.AD_ID + '_appnexus=233bcbee889d46d&' + CONSTANTS.TARGETING_KEYS.BIDDER + '_appnexus=appnexus&' + CONSTANTS.TARGETING_KEYS.SIZE + '_pagescience=300x250&' + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_pagescience=10.00&' + CONSTANTS.TARGETING_KEYS.AD_ID + '_pagescience=25bedd4813632d7&' + CONSTANTS.TARGETING_KEYS.BIDDER + '_pagescienc=pagescience&' + CONSTANTS.TARGETING_KEYS.SIZE + '_brightcom=300x250&' + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_brightcom=10.00&' + CONSTANTS.TARGETING_KEYS.AD_ID + '_brightcom=26e0795ab963896&' + CONSTANTS.TARGETING_KEYS.BIDDER + '_brightcom=brightcom&' + CONSTANTS.TARGETING_KEYS.SIZE + '_brealtime=300x250&' + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_brealtime=10.00&' + CONSTANTS.TARGETING_KEYS.AD_ID + '_brealtime=275bd666f5a5a5d&' + CONSTANTS.TARGETING_KEYS.BIDDER + '_brealtime=brealtime&' + CONSTANTS.TARGETING_KEYS.SIZE + '_pubmatic=300x250&' + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_pubmatic=10.00&' + CONSTANTS.TARGETING_KEYS.AD_ID + '_pubmatic=28f4039c636b6a7&' + CONSTANTS.TARGETING_KEYS.BIDDER + '_pubmatic=pubmatic&' + CONSTANTS.TARGETING_KEYS.SIZE + '_rubicon=300x600&' + CONSTANTS.TARGETING_KEYS.PRICE_BUCKET + '_rubicon=10.00&' + CONSTANTS.TARGETING_KEYS.AD_ID + '_rubicon=29019e2ab586a5a&' + CONSTANTS.TARGETING_KEYS.BIDDER + '_rubicon=rubicon'; assert.equal(output, expected); }); @@ -639,8 +640,8 @@ describe('Utils', function () { }); }); - describe('getDefinedParams', () => { - it('builds an object consisting of defined params', () => { + describe('getDefinedParams', function () { + it('builds an object consisting of defined params', function () { const adUnit = { mediaType: 'video', comeWithMe: 'ifuwant2live', @@ -658,8 +659,8 @@ describe('Utils', function () { }); }); - describe('deepClone', () => { - it('deep copies objects', () => { + describe('deepClone', function () { + it('deep copies objects', function () { const adUnit = [{ code: 'swan', mediaTypes: {video: {context: 'outstream'}}, @@ -679,7 +680,7 @@ describe('Utils', function () { }); }); - describe('getUserConfiguredParams', () => { + describe('getUserConfiguredParams', function () { const adUnits = [{ code: 'adUnit1', bids: [{ @@ -692,7 +693,7 @@ describe('Utils', function () { }] }]; - it('should return params configured', () => { + it('should return params configured', function () { const output = utils.getUserConfiguredParams(adUnits, 'adUnit1', 'bidder1'); const expected = [{ key1: 'value1' @@ -700,38 +701,38 @@ describe('Utils', function () { assert.deepEqual(output, expected); }); - it('should return array containting empty object, if bidder present and no params are configured', () => { + it('should return array containting empty object, if bidder present and no params are configured', function () { const output = utils.getUserConfiguredParams(adUnits, 'adUnit1', 'bidder2'); const expected = [{}]; assert.deepEqual(output, expected); }); - it('should return empty array, if bidder is not present', () => { + it('should return empty array, if bidder is not present', function () { const output = utils.getUserConfiguredParams(adUnits, 'adUnit1', 'bidder3'); const expected = []; assert.deepEqual(output, expected); }); - it('should return empty array, if adUnit is not present', () => { + it('should return empty array, if adUnit is not present', function () { const output = utils.getUserConfiguredParams(adUnits, 'adUnit2', 'bidder3'); const expected = []; assert.deepEqual(output, expected); }); }); - describe('getTopWindowLocation', () => { + describe('getTopWindowLocation', function () { let sandbox; - beforeEach(() => { + beforeEach(function () { sandbox = sinon.sandbox.create(); }); - afterEach(() => { + afterEach(function () { sandbox.restore(); }); - it('returns window.location if not in iFrame', () => { - sandbox.stub(utils, 'getWindowLocation').returns({ + it('returns window.location if not in iFrame', function () { + sandbox.stub(utils.internal, 'getWindowLocation').returns({ href: 'https://www.google.com/', ancestorOrigins: {}, origin: 'https://www.google.com', @@ -744,10 +745,10 @@ describe('Utils', function () { hash: '' }); let windowSelfAndTopObject = { self: 'is same as top' }; - sandbox.stub(utils, 'getWindowSelf').returns( + sandbox.stub(utils.internal, 'getWindowSelf').returns( windowSelfAndTopObject ); - sandbox.stub(utils, 'getWindowTop').returns( + sandbox.stub(utils.internal, 'getWindowTop').returns( windowSelfAndTopObject ); var topWindowLocation = utils.getTopWindowLocation(); @@ -762,14 +763,14 @@ describe('Utils', function () { expect(topWindowLocation.host).to.equal('www.google.com'); }); - it('returns parsed dom string from ancestorOrigins if in iFrame & ancestorOrigins is populated', () => { - sandbox.stub(utils, 'getWindowSelf').returns( + it('returns parsed dom string from ancestorOrigins if in iFrame & ancestorOrigins is populated', function () { + sandbox.stub(utils.internal, 'getWindowSelf').returns( { self: 'is not same as top' } ); - sandbox.stub(utils, 'getWindowTop').returns( + sandbox.stub(utils.internal, 'getWindowTop').returns( { top: 'is not same as self' } ); - sandbox.stub(utils, 'getAncestorOrigins').returns('https://www.google.com/a/umich.edu/acs'); + sandbox.stub(utils.internal, 'getAncestorOrigins').returns('https://www.google.com/a/umich.edu/acs'); var topWindowLocation = utils.getTopWindowLocation(); expect(topWindowLocation).to.be.a('object'); expect(topWindowLocation.pathname).to.equal('/a/umich.edu/acs'); @@ -783,15 +784,15 @@ describe('Utils', function () { expect(topWindowLocation.host).to.be.oneOf(['www.google.com', 'www.google.com:443']); }); - it('returns parsed referrer string if in iFrame but no ancestorOrigins', () => { - sandbox.stub(utils, 'getWindowSelf').returns( + it('returns parsed referrer string if in iFrame but no ancestorOrigins', function () { + sandbox.stub(utils.internal, 'getWindowSelf').returns( { self: 'is not same as top' } ); - sandbox.stub(utils, 'getWindowTop').returns( + sandbox.stub(utils.internal, 'getWindowTop').returns( { top: 'is not same as self' } ); - sandbox.stub(utils, 'getAncestorOrigins').returns(null); - sandbox.stub(utils, 'getTopFrameReferrer').returns('https://www.example.com/'); + sandbox.stub(utils.internal, 'getAncestorOrigins').returns(null); + sandbox.stub(utils.internal, 'getTopFrameReferrer').returns('https://www.example.com/'); var topWindowLocation = utils.getTopWindowLocation(); expect(topWindowLocation).to.be.a('object'); expect(topWindowLocation.href).to.equal('https://www.example.com/'); @@ -806,8 +807,8 @@ describe('Utils', function () { }); }); - describe('convertCamelToUnderscore', () => { - it('returns converted string value using underscore syntax instead of camelCase', () => { + describe('convertCamelToUnderscore', function () { + it('returns converted string value using underscore syntax instead of camelCase', function () { let var1 = 'placementIdTest'; let test1 = utils.convertCamelToUnderscore(var1); expect(test1).to.equal('placement_id_test'); @@ -818,18 +819,18 @@ describe('Utils', function () { }); }); - describe('getAdUnitSizes', () => { - it('returns an empty response when adUnits is undefined', () => { + describe('getAdUnitSizes', function () { + it('returns an empty response when adUnits is undefined', function () { let sizes = utils.getAdUnitSizes(); expect(sizes).to.be.undefined; }); - it('returns an empty array when invalid data is present in adUnit object', () => { + it('returns an empty array when invalid data is present in adUnit object', function () { let sizes = utils.getAdUnitSizes({ sizes: 300 }); expect(sizes).to.deep.equal([]); }); - it('retuns an array of arrays when reading from adUnit.sizes', () => { + it('retuns an array of arrays when reading from adUnit.sizes', function () { let sizes = utils.getAdUnitSizes({ sizes: [300, 250] }); expect(sizes).to.deep.equal([[300, 250]]); @@ -837,7 +838,7 @@ describe('Utils', function () { expect(sizes).to.deep.equal([[300, 250], [300, 600]]); }); - it('returns an array of arrays when reading from adUnit.mediaTypes.banner.sizes', () => { + it('returns an array of arrays when reading from adUnit.mediaTypes.banner.sizes', function () { let sizes = utils.getAdUnitSizes({ mediaTypes: { banner: { sizes: [300, 250] } } }); expect(sizes).to.deep.equal([[300, 250]]); @@ -845,4 +846,94 @@ describe('Utils', function () { expect(sizes).to.deep.equal([[300, 250], [300, 600]]); }); }); + + describe('transformBidderParamKeywords', function () { + it('returns an array of objects when keyvalue is an array', function () { + let keywords = { + genre: ['rock', 'pop'] + }; + let result = utils.transformBidderParamKeywords(keywords); + expect(result).to.deep.equal([{ + key: 'genre', + value: ['rock', 'pop'] + }]); + }); + + it('returns an array of objects when keyvalue is a string', function () { + let keywords = { + genre: 'opera' + }; + let result = utils.transformBidderParamKeywords(keywords); + expect(result).to.deep.equal([{ + key: 'genre', + value: ['opera'] + }]); + }); + + it('returns an array of objects when keyvalue is a number', function () { + let keywords = { + age: 15 + }; + let result = utils.transformBidderParamKeywords(keywords); + expect(result).to.deep.equal([{ + key: 'age', + value: ['15'] + }]); + }); + + it('returns an array of objects when using multiple keys with values of differing types', function () { + let keywords = { + genre: 'classical', + mix: ['1', 2, '3', 4], + age: 10 + }; + let result = utils.transformBidderParamKeywords(keywords); + expect(result).to.deep.equal([{ + key: 'genre', + value: ['classical'] + }, { + key: 'mix', + value: ['1', '2', '3', '4'] + }, { + key: 'age', + value: ['10'] + }]); + }); + + it('returns an array of objects when the keyvalue uses an empty string', function() { + let keywords = { + test: [''], + test2: '' + }; + let result = utils.transformBidderParamKeywords(keywords); + expect(result).to.deep.equal([{ + key: 'test', + value: [''] + }, { + key: 'test2', + value: [''] + }]); + }); + + describe('insertElement', function () { + it('returns a node at the top of the target by default', function () { + const toInsert = document.createElement('div'); + const target = document.getElementsByTagName('body')[0]; + const inserted = utils.insertElement(toInsert, document, 'body'); + expect(inserted).to.equal(target.firstChild); + }); + it('returns a node at bottom of target if 4th argument is true', function () { + const toInsert = document.createElement('div'); + const target = document.getElementsByTagName('html')[0]; + const inserted = utils.insertElement(toInsert, document, 'html', true); + expect(inserted).to.equal(target.lastChild); + }); + it('returns a node at top of the head if no target is given', function () { + const toInsert = document.createElement('div'); + const target = document.getElementsByTagName('head')[0]; + const inserted = utils.insertElement(toInsert); + expect(inserted).to.equal(target.firstChild); + }); + }); + }); }); diff --git a/test/spec/videoCache_spec.js b/test/spec/videoCache_spec.js index b853da708fc..163cb326740 100644 --- a/test/spec/videoCache_spec.js +++ b/test/spec/videoCache_spec.js @@ -1,11 +1,11 @@ -import 'mocha'; +import 'mocha/mocha'; import chai from 'chai'; import { getCacheUrl, store } from 'src/videoCache'; import { config } from 'src/config'; const should = chai.should(); -describe('The video cache', () => { +describe('The video cache', function () { function assertError(callbackSpy) { callbackSpy.calledOnce.should.equal(true); callbackSpy.firstCall.args[0].should.be.an('error'); @@ -16,19 +16,21 @@ describe('The video cache', () => { should.not.exist(callbackSpy.firstCall.args[0]); } - describe('when the cache server is unreachable', () => { + describe('when the cache server is unreachable', function () { let xhr; let requests; - beforeEach(() => { + beforeEach(function () { xhr = sinon.useFakeXMLHttpRequest(); requests = []; xhr.onCreate = (request) => requests.push(request); }); - afterEach(() => xhr.restore()); + afterEach(function () { + xhr.restore(); + }); - it('should execute the callback with an error when store() is called', () => { + it('should execute the callback with an error when store() is called', function () { const callback = sinon.spy(); store([ { vastUrl: 'my-mock-url.com' } ], callback); @@ -41,11 +43,11 @@ describe('The video cache', () => { }); }); - describe('when the cache server is available', () => { + describe('when the cache server is available', function () { let xhr; let requests; - beforeEach(() => { + beforeEach(function () { xhr = sinon.useFakeXMLHttpRequest(); requests = []; xhr.onCreate = (request) => requests.push(request); @@ -56,12 +58,12 @@ describe('The video cache', () => { }) }); - afterEach(() => { + afterEach(function () { xhr.restore(); config.resetConfig(); }); - it('should execute the callback with a successful result when store() is called', () => { + it('should execute the callback with a successful result when store() is called', function () { const uuid = 'c488b101-af3e-4a99-b538-00423e5a3371'; const callback = fakeServerCall( { vastUrl: 'my-mock-url.com' }, @@ -71,7 +73,7 @@ describe('The video cache', () => { callback.firstCall.args[1].should.deep.equal([{ uuid: uuid }]); }); - it('should execute the callback with an error if the cache server response has no responses property', () => { + it('should execute the callback with an error if the cache server response has no responses property', function () { const callback = fakeServerCall( { vastUrl: 'my-mock-url.com' }, '{"broken":[{"uuid":"c488b101-af3e-4a99-b538-00423e5a3371"}]}'); @@ -79,7 +81,7 @@ describe('The video cache', () => { callback.firstCall.args[1].should.deep.equal([]); }); - it('should execute the callback with an error if the cache server responds with malformed JSON', () => { + it('should execute the callback with an error if the cache server responds with malformed JSON', function () { const callback = fakeServerCall( { vastUrl: 'my-mock-url.com' }, 'Not JSON here'); @@ -87,7 +89,7 @@ describe('The video cache', () => { callback.firstCall.args[1].should.deep.equal([]); }); - it('should make the expected request when store() is called on an ad with a vastUrl', () => { + it('should make the expected request when store() is called on an ad with a vastUrl', function () { const expectedValue = ` @@ -98,10 +100,10 @@ describe('The video cache', () => { `; - assertRequestMade({ vastUrl: 'my-mock-url.com' }, expectedValue) + assertRequestMade({ vastUrl: 'my-mock-url.com', ttl: 25 }, expectedValue) }); - it('should make the expected request when store() is called on an ad with a vastUrl and a vastImpUrl', () => { + it('should make the expected request when store() is called on an ad with a vastUrl and a vastImpUrl', function () { const expectedValue = ` @@ -112,12 +114,12 @@ describe('The video cache', () => { `; - assertRequestMade({ vastUrl: 'my-mock-url.com', vastImpUrl: 'imptracker.com' }, expectedValue) + assertRequestMade({ vastUrl: 'my-mock-url.com', vastImpUrl: 'imptracker.com', ttl: 25 }, expectedValue) }); - it('should make the expected request when store() is called on an ad with vastXml', () => { + it('should make the expected request when store() is called on an ad with vastXml', function () { const vastXml = ''; - assertRequestMade({ vastXml: vastXml }, vastXml); + assertRequestMade({ vastXml: vastXml, ttl: 25 }, vastXml); }); function assertRequestMade(bid, expectedValue) { @@ -132,6 +134,7 @@ describe('The video cache', () => { puts: [{ type: 'xml', value: expectedValue, + ttlseconds: 25 }], }); } @@ -150,8 +153,8 @@ describe('The video cache', () => { }); }); -describe('The getCache function', () => { - beforeEach(() => { +describe('The getCache function', function () { + beforeEach(function () { config.setConfig({ cache: { url: 'https://prebid.adnxs.com/pbc/v1/cache' @@ -159,11 +162,11 @@ describe('The getCache function', () => { }) }); - afterEach(() => { + afterEach(function () { config.resetConfig(); }); - it('should return the expected URL', () => { + it('should return the expected URL', function () { const uuid = 'c488b101-af3e-4a99-b538-00423e5a3371'; const url = getCacheUrl(uuid); url.should.equal(`https://prebid.adnxs.com/pbc/v1/cache?uuid=${uuid}`); diff --git a/test/spec/video_spec.js b/test/spec/video_spec.js index 06cd653f444..3d6ed04ffae 100644 --- a/test/spec/video_spec.js +++ b/test/spec/video_spec.js @@ -1,7 +1,7 @@ import { isValidVideoBid } from 'src/video'; -describe('video.js', () => { - it('validates valid instream bids', () => { +describe('video.js', function () { + it('validates valid instream bids', function () { const bid = { adId: '123abc', vastUrl: 'http://www.example.com/vastUrl' @@ -19,7 +19,7 @@ describe('video.js', () => { expect(valid).to.equal(true); }); - it('catches invalid instream bids', () => { + it('catches invalid instream bids', function () { const bid = { adId: '123abc' }; @@ -36,7 +36,7 @@ describe('video.js', () => { expect(valid).to.equal(false); }); - it('catches invalid bids when prebid-cache is disabled', () => { + it('catches invalid bids when prebid-cache is disabled', function () { const bidRequests = [{ bids: [{ bidder: 'vastOnlyVideoBidder', @@ -49,7 +49,7 @@ describe('video.js', () => { expect(valid).to.equal(false); }); - it('validates valid outstream bids', () => { + it('validates valid outstream bids', function () { const bid = { adId: '123abc', renderer: { @@ -70,7 +70,7 @@ describe('video.js', () => { expect(valid).to.equal(true); }); - it('catches invalid outstream bids', () => { + it('catches invalid outstream bids', function () { const bid = { adId: '123abc' }; diff --git a/test/test_index.js b/test/test_index.js index 51323d87437..f6a48a7542b 100644 --- a/test/test_index.js +++ b/test/test_index.js @@ -1,4 +1,5 @@ require('test/helpers/prebidGlobal.js'); +require('test/mocks/adloaderStub.js'); var testsContext = require.context('.', true, /_spec$/); testsContext.keys().forEach(testsContext); diff --git a/webpack.conf.js b/webpack.conf.js index 4b53aabef22..4e082981197 100644 --- a/webpack.conf.js +++ b/webpack.conf.js @@ -1,5 +1,4 @@ var prebid = require('./package.json'); -var StringReplacePlugin = require('string-replace-webpack-plugin'); var path = require('path'); var webpack = require('webpack'); var helpers = require('./gulpHelpers'); @@ -19,7 +18,7 @@ module.exports = { ], }, output: { - jsonpFunction: prebid.globalVarName+"Chunk" + jsonpFunction: prebid.globalVarName + "Chunk" }, module: { rules: [ @@ -40,47 +39,10 @@ module.exports = { loader: 'babel-loader', } ], - }, - { - test: /\.json$/, - loader: 'json-loader' - }, - { - test: /\.md$/, - loader: 'ignore-loader' - }, - { - test: /constants.json$/, - include: /(src)/, - loader: StringReplacePlugin.replace({ - replacements: [ - { - pattern: /%%REPO_AND_VERSION%%/g, - replacement: function (match, p1, offset, string) { - return `${prebid.repository.url.split('/')[3]}_prebid_${prebid.version}`; - } - } - ] - }) - }, - { - test: /\.js$/, - include: /(src|test|modules|integrationExamples)/, - loader: StringReplacePlugin.replace({ - replacements: [ - { - pattern: /\$\$PREBID_GLOBAL\$\$/g, - replacement: function (match, p1, offset, string) { - return prebid.globalVarName; - } - } - ] - }) } ] }, plugins: [ - new StringReplacePlugin(), new RequireEnsureWithoutJsonp(), // this plugin must be last so it can be easily removed for karma unit tests @@ -88,7 +50,7 @@ module.exports = { name: 'prebid', filename: 'prebid-core.js', minChunks: function(module, count) { - return !(count < 2 || neverBundle.includes(path.basename(module.resource))) + return !(count < 2 || neverBundle.indexOf(path.basename(module.resource)) !== -1) } }) ]