From e7474ef46587bbfd81abef0d8dfa6e82cec755fd Mon Sep 17 00:00:00 2001 From: dchau Date: Wed, 29 Jun 2016 16:47:13 -0700 Subject: [PATCH] [PBI-1824c] CR changes --- js/ssai_pulse.js | 14 +- .../unit-test-helpers/mock_responses/ssai.xml | 133 ++++++++++++++++++ utils/VastParser.js | 42 +++--- 3 files changed, 161 insertions(+), 28 deletions(-) create mode 100644 test/unit-test-helpers/mock_responses/ssai.xml diff --git a/js/ssai_pulse.js b/js/ssai_pulse.js index 4a53144..1d6a3d2 100644 --- a/js/ssai_pulse.js +++ b/js/ssai_pulse.js @@ -82,8 +82,8 @@ OO.Ads.manager(function(_, $) // Denotes that an ad request is waiting for a response WAITING: "waiting", - // Denotes that a response has returned for an ad request and the ad has "played" - PLAYED: "played" + // Denotes that a response has returned for an ad request and the ad is "playing" + PLAYING: "playing" }; // variable to store the timeout used to keep track of how long an SSAI ad plays @@ -182,6 +182,7 @@ OO.Ads.manager(function(_, $) if (this.currentAd.ad) { this.currentAd.ad.id3AdId = this.currentId3Object.adId; + _handleTrackingUrls(this.currentAd, ["impression", "start"]); amc.notifyLinearAdStarted(this.currentAd.id, { name: this.currentAd.ad.name, @@ -191,7 +192,6 @@ OO.Ads.manager(function(_, $) isLive: this.currentAd.ad.isLive } ); - _handleTrackingUrls(this.currentAd, ["impression", "start"]); } } }; @@ -281,8 +281,8 @@ OO.Ads.manager(function(_, $) { if (amcAd && amcAd.ad) { - window.open(amcAd.ad.clickthrough); _handleTrackingUrls(amcAd, ["linearClickTracking"]); + window.open(amcAd.ad.clickthrough); } }; @@ -386,8 +386,8 @@ OO.Ads.manager(function(_, $) * Called if the ajax call succeeds * @public * @method SsaiPulse#onResponse - * @param {XMLDocument} xml The xml returned from loading the ad * @param {object} id3Object The ID3 object + * @param {XMLDocument} xml The xml returned from loading the ad */ this.onResponse = function(id3Object, xml) { @@ -413,7 +413,7 @@ OO.Ads.manager(function(_, $) ssaiAd.name = _getTitle(adObject); } - this.adIdDictionary[id3Object.adId] = STATE.PLAYED; + this.adIdDictionary[id3Object.adId] = STATE.PLAYING; amc.forceAdToPlay(this.name, ssaiAd, amc.ADTYPE.LINEAR_VIDEO, {}, id3Object.duration); //_forceMockAd(id3Object); @@ -798,7 +798,7 @@ OO.Ads.manager(function(_, $) /** * Helper function to retrieve the ad object's tracking urls under a specific event name. * @private - * @method SsaiPulse#_getTrackingEventUrls + * @method SsaiPulse#_getLinearTrackingEventUrls * @param {object} adObject The ad metadata * @param {string} trackingEventName The name of the tracking event * @returns {string[]|null} The array of tracking urls associated with the event name. Returns null if no URLs exist. diff --git a/test/unit-test-helpers/mock_responses/ssai.xml b/test/unit-test-helpers/mock_responses/ssai.xml new file mode 100644 index 0000000..b0101f3 --- /dev/null +++ b/test/unit-test-helpers/mock_responses/ssai.xml @@ -0,0 +1,133 @@ + + + + Videoplaza Karbon + FE_Sports + errorUrl + impressionUrl + impressionUrl2 + + + + 00:00:15 + + startUrl + startUrl2 + firstQuartileUrl + firstQuartileUrl2 + midpointUrl + midpointUrl2 + thirdQuartileUrl + thirdQuartileUrl2 + completeUrl + completeUrl2 + muteUrl + unmuteUrl + fullscreenUrl + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + linearClickTrackingUrl + + + + + + + + + + + + diff --git a/utils/VastParser.js b/utils/VastParser.js index fd79431..d7a454b 100644 --- a/utils/VastParser.js +++ b/utils/VastParser.js @@ -243,7 +243,7 @@ // there could be an element in the vast response var noAdsErrorURL = $(vastXML).find("Error").text(); if (noAdsErrorURL) { - this.pingURL(this.ERROR_CODES.WRAPPER_NO_ADS, noAdsErrorURL); + this.pingErrorURL(this.ERROR_CODES.WRAPPER_NO_ADS, noAdsErrorURL); } // if the ad response came from a wrapper, then go up the chain and ping those error urls //this.trackError(this.ERROR_CODES.WRAPPER_NO_ADS, this.wrapperParentId); @@ -255,11 +255,11 @@ /** * Helper function to ping error URL. Replaces error macro if it exists. * @public - * @method VastParser#pingURL + * @method VastParser#pingErrorURL * @param {number} code Error code * @param {string} url URL to ping */ - this.pingURL = function(code, url) { + this.pingErrorURL = function(code, url) { url = url.replace(/\[ERRORCODE\]/, code); OO.pixelPing(url); }; @@ -267,13 +267,13 @@ /** * Helper function to ping error URLs. * @public - * @method VastParser#pingURLs + * @method VastParser#pingErrorURLs * @param {number} code Error code * @param {string[]} urls URLs to ping */ - this.pingURLs = function(code, urls) { + this.pingErrorURLs = function(code, urls) { _.each(urls, function() { - pingURL(code, url); + this.pingErrorURL(code, url); }, this); }; @@ -283,7 +283,7 @@ * Note: can only live in three places: directly under , , or elements. * tags are also optional so they may not always exist. * @public - * @method Vast#getErrorTrackingInfo + * @method VastParser#getErrorTrackingInfo * @param {XMLDocument} vastXML Contains the vast ad data to be parsed * @param {object} ads A jQuery object which contains the collection of ad elements found */ @@ -306,7 +306,7 @@ /** * Helper function to verify that XML is valid * @public - * @method Vast#isValidVastXML + * @method VastParser#isValidVastXML * @param {XMLDocument} vastXML Contains the vast ad data to be parsed * @returns {boolean} Returns true if the xml is valid otherwise it returns false. */ @@ -317,7 +317,7 @@ /** * Helper function to verify XML has valid VAST root tag. * @public - * @method Vast#isValidRootTagName + * @method VastParser#isValidRootTagName * @param {XMLDocument} vastXML Contains the vast ad data to be parsed * @returns {boolean} Returns true if the root tag is valid otherwise it returns false. */ @@ -333,7 +333,7 @@ /** * Helper function to verify XML is a valid VAST version. * @public - * @method Vast#isValidVastVersion + * @method VastParser#isValidVastVersion * @param {XMLDocument} vastXML Contains the vast ad data to be parsed * @returns {boolean} Returns true if the VAST version is valid otherwise it returns false. */ @@ -350,7 +350,7 @@ /** * Returns the Vast version of the provided XML. * @private - * @method Vast#getVastVersion + * @method VastParser#getVastVersion * @param {XMLDocument} vastXML Contains the vast ad data to be parsed * @returns {string} The Vast version. */ @@ -362,7 +362,7 @@ /** * Helper function to get the VAST root element. * @private - * @method Vast#getVastRoot + * @method VastParser#getVastRoot * @param {XMLDocument} vastXML Contains the vast ad data to be parsed * @returns {object} null if a VAST tag is absent, or if there are multiple VAST tags. Otherwise, * returns the VAST root element. @@ -383,7 +383,7 @@ /** * Returns the Vast major version. For example, the '3' in 3.0. * @private - * @method Vast#getMajorVersion + * @method VastParser#getMajorVersion * @param {string} version The Vast version as parsed from the XML * @returns {string} The major version. */ @@ -396,7 +396,7 @@ /** * Checks to see if this ad manager supports a given Vast version. * @private - * @method Vast#supportsVersion + * @method VastParser#supportsVersion * @param {string} version The Vast version as parsed from the XML * @returns {boolean} true if the version is supported by this ad manager, false otherwise. */ @@ -408,7 +408,7 @@ * Checks to see if the given Vast version supports the podded ads functionality, as per Vast specs * for different versions. * @private - * @method Vast#supportsPoddedAds + * @method VastParser#supportsPoddedAds * @returns {boolean} true if the podded ads functionality is supported in the specified Vast version, * false otherwise */ @@ -420,7 +420,7 @@ * Checks to see if the given Vast version supports the ad fallback functionality, as per Vast specs * for different versions. * @private - * @method Vast#supportsAdFallback + * @method VastParser#supportsAdFallback * @returns {boolean} true if the ad fallback functionality is supported in the specified Vast version, * false otherwise */ @@ -431,7 +431,7 @@ /** * Default template to use when creating the vast ad object. * @private - * @method Vast#getVastTemplate + * @method VastParser#getVastTemplate * @returns {object} The ad object that is formated to what we expect vast to look like. */ var getVastTemplate = _.bind(function() { @@ -448,7 +448,7 @@ /** * Helper function to remove empty items. * @private - * @method Vast#filterEmpty + * @method VastParser#filterEmpty * @param {Array} array An array that is the be checked if it is empty * @returns {Array} The filtered array. */ @@ -459,7 +459,7 @@ /** * While getting the ad data the manager needs to parse the companion ad data as well and add it to the object. * @private - * @method Vast#parseCompanionAd + * @method VastParser#parseCompanionAd * @param {XMLDocument} companionAdXML XML that contains the companion ad data * @returns {object} The ad object with companion ad. */ @@ -495,7 +495,7 @@ * Checks if there is any companion ads associated with the ad and if one is found, it will call the Ad Manager * Controller to show it. * @public - * @method Vast#checkCompanionAds + * @method VastParser#checkCompanionAds * @param {object} adInfo The Ad metadata */ this.checkCompanionAds = function(adInfo) { @@ -517,7 +517,7 @@ /** * The xml is parsed to find any tracking events and then returned as part of an object. * @private - * @method Vast#parseTrackingEvents + * @method VastParser#parseTrackingEvents * @param {object} tracking The tracking object to be mutated * @param {XMLDocument} xml The data of the ad with tracking info * @param {string[]} trackingEvents List of events that are tracked, if null then it uses the global one