Skip to content

Commit

Permalink
Merge pull request #125 from MailOnline/next-release
Browse files Browse the repository at this point in the history
Next release
  • Loading branch information
carpasse committed Dec 24, 2018
2 parents 1fc0852 + ea67108 commit 89a4925
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 9 deletions.
42 changes: 38 additions & 4 deletions src/runner/__tests__/runWaterfall.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
/* eslint-disable max-nested-callbacks */
import {
vastWrapperXML,
vastInlineXML,
wrapperParsedXML,
inlineAd,
inlineParsedXML,
vastInlineXML,
vastVpaidInlineXML,
vastWrapperXML,
vpaidInlineAd,
vpaidInlineParsedXML,
wrapperAd,
inlineAd
wrapperParsedXML
} from '../../../fixtures';
import defer from '../../utils/defer';
import requestAd from '../../vastRequest/requestAd';
Expand Down Expand Up @@ -117,6 +120,37 @@ describe('runWaterfall', () => {
});

describe('after fetching Vast response', () => {
test('must throw if it gets a vpaid ad with vpaidEnabled flag set to false', async () => {
const onError = jest.fn();
const vpaidChain = [
{
ad: vpaidInlineAd,
errorCode: null,
parsedXML: vpaidInlineParsedXML,
requestTag: 'https://test.example.com/vastadtaguri',
XML: vastVpaidInlineXML
}
];

requestAd.mockReturnValue(Promise.resolve(vpaidChain));

await runWaterfall(adTag, placeholder, {
...options,
onError,
vpaidEnabled: false
});
expect(onError).toHaveBeenCalledTimes(1);

const error = onError.mock.calls[0][0];

expect(error.code).toBe(200);
expect(error.message).toBe('VPAID ads are not supported by the current player');
expect(trackError).toHaveBeenCalledWith(vpaidChain, expect.objectContaining({
errorCode: 200,
tracker: options.tracker
}));
});

test('must call onError if Vast response is undefined', async () => {
const onError = jest.fn();

Expand Down
15 changes: 15 additions & 0 deletions src/runner/runWaterfall.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,26 @@
import {trackError} from '../tracker';
import requestAd from '../vastRequest/requestAd';
import requestNextAd from '../vastRequest/requestNextAd';
import {getInteractiveFiles} from '../vastSelectors';
import isIOS from '../utils/isIOS';
import run from './run';

const isVpaid = (vastChain) => Boolean(getInteractiveFiles(vastChain[0].ad));
const validateVastChain = (vastChain, options) => {
if (!vastChain || vastChain.length === 0) {
throw new Error('Invalid VastChain');
}

const lastVastResponse = vastChain[0];

if (!options.vpaidEnabled && isVpaid(vastChain)) {
const error = new Error('VPAID ads are not supported by the current player');

error.code = 200;
lastVastResponse.errorCode = 200;
lastVastResponse.error = error;
}

if (Boolean(lastVastResponse.error)) {
throw lastVastResponse.error;
}
Expand Down Expand Up @@ -138,6 +148,8 @@ const waterfall = async (fetchVastChain, placeholder, options, isCanceled) => {
* Defaults to `false`
* @param {number} [options.timeout] - timeout number in milliseconds. If set, the video ad will time out if it doesn't start within the specified time.
* @param {TrackerFn} [options.tracker] - If provided it will be used to track the VAST events instead of the default {@link pixelTracker}.
* @param {boolean} [options.vpaidEnabled] - if false and it gets a VPAID ad, it will throw an error before starting the ad and continue down in the waterfall.
* Defaults to `true`.
* @param {Object} [options.hooks] - Optional map with hooks to configure the behaviour of the ad.
* @param {Function} [options.hooks.createSkipControl] - If provided it will be called to generate the skip control. Must return a clickable [HTMLElement](https://developer.mozilla.org/es/docs/Web/API/HTMLElement) that is detached from the DOM.
* @param {Function} [options.hooks.validateVastResponse] - If provided it will be called for each valid vast response. Must throw if there is a problem with the vast response. If the Error instance has an `errorCode` number then it will be tracked using the error macros in the Vast response. It will also call {@link runWaterfall~onError} with the thrown error.
Expand All @@ -153,8 +165,11 @@ const runWaterfall = (adTag, placeholder, options) => {
adUnit = newAdUnit;
onAdStartHandler(adUnit);
};

const opts = {
vpaidEnabled: true,
...options,
// eslint-disable-next-line sort-keys
onAdReady: callbackHandler(options.onAdReady),
onAdStart,
onError: callbackHandler(options.onError),
Expand Down
2 changes: 2 additions & 0 deletions src/tracker/helpers/pixelTracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import parseMacro from './parseMacro';
/**
* Creates a tracking image with the passed URL macro.
*
* @global
* @typedef pixelTracker
* @type TrackerFn
* @name pixelTracker
* @param {string} URLMacro - URL Macro that need to be tracked.
Expand Down
10 changes: 5 additions & 5 deletions src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/

/**
* From [VAST specification]{@link https://www.iab.com/guidelines/digital-video-ad-serving-template-vast-4-0/}:
* From [VAST specification]{@link https://iabtechlab.com/standards/vast/}:
*
* Sometimes ad servers would like to collect metadata from the video player when tracking
* event URIs are accessed. For example, the position of the video player playhead at the time
Expand Down Expand Up @@ -76,7 +76,7 @@

/**
* VastIcon.
* For more info please take a look at the [VAST specification]{@link https://www.iab.com/guidelines/digital-video-ad-serving-template-vast-4-0/}
* For more info please take a look at the [VAST specification]{@link https://iabtechlab.com/standards/vast/}
*
* @global
* @typedef VastIcon
Expand Down Expand Up @@ -106,7 +106,7 @@

/**
* VAST MediaFile representation.
* For more info please take a look at the [VAST specification]{@link https://www.iab.com/guidelines/digital-video-ad-serving-template-vast-4-0/}
* For more info please take a look at the [VAST specification]{@link https://iabtechlab.com/standards/vast/}
*
* @global
* @typedef MediaFile
Expand All @@ -130,7 +130,7 @@

/**
* VastTrackingEvent.
* For more info please take a look at the [VAST specification]{@link https://www.iab.com/guidelines/digital-video-ad-serving-template-vast-4-0/}
* For more info please take a look at the [VAST specification]{@link https://iabtechlab.com/standards/vast/}
*
* @global
* @typedef VastTrackingEvent
Expand Down Expand Up @@ -195,7 +195,7 @@

/**
* {@link VastChain} details object. You can think of it as a summary of the VAST Chain. Useful for debugging purposes and tracking.
* for more info about the returned properties please check [VAST specification]{@link https://www.iab.com/guidelines/digital-video-ad-serving-template-vast-4-0/}
* for more info about the returned properties please check [VAST specification]{@link https://iabtechlab.com/standards/vast/}
*
* @global
* @typedef VastChainDetails
Expand Down
2 changes: 2 additions & 0 deletions src/xml/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const parser = new DOMParser();
/**
* Parses the passed xml text.
*
* @global
* @typedef parseXml
* @throws if there is an error parsing the xml.
* @param {string} xmlText - XML text to be parsed.
* @returns {Object} - Returns the parsed xml document as a js object.
Expand Down

0 comments on commit 89a4925

Please sign in to comment.