diff --git a/index.js b/index.js index 85d0430..b2acc98 100644 --- a/index.js +++ b/index.js @@ -58,7 +58,7 @@ var xml = function(options) { icon.element(r.type, r.uri, (r.creativeType) ? { creativeType : r.creativeType } : {}); }); }); - creativeType.element('Duration', c.Duration); + if (c.Duration) creativeType.element('Duration', c.Duration); var trackingEvents = creativeType.element('TrackingEvents'); c.trackingEvents.forEach(function(trackingEvent){ if (track) { @@ -72,10 +72,12 @@ var xml = function(options) { c.videoClicks.forEach(function(videoClick){ videoClicks.element(videoClick.type, videoClick.url, { id : videoClick.id }); }); - var mediaFiles = creativeType.element('MediaFiles'); - c.mediaFiles.forEach(function(mediaFile) { - mediaFiles.element('MediaFile', mediaFile.attributes).cdata(mediaFile.url); - }); + if (c.mediaFiles && c.mediaFiles.length > 0) { + var mediaFiles = creativeType.element('MediaFiles'); + c.mediaFiles.forEach(function(mediaFile) { + mediaFiles.element('MediaFile', mediaFile.attributes).cdata(mediaFile.url); + }); + } }); nonLinearCreatives.forEach(function(c){ diff --git a/lib/creative.js b/lib/creative.js index 1d963eb..b757c60 100644 --- a/lib/creative.js +++ b/lib/creative.js @@ -9,7 +9,7 @@ function Creative(type, settings) { if (settings.Duration) { this.Duration = settings.Duration; - } else if (type === 'Linear') { + } else if (type === 'Linear' && !settings.Wrapper) { throw new Error('A Duration is required for all creatives. Consider defaulting to "00:00:00"'); } this.attributes = {}; diff --git a/test/wrapper.test.js b/test/wrapper.test.js index ae10dce..794275c 100644 --- a/test/wrapper.test.js +++ b/test/wrapper.test.js @@ -1,6 +1,8 @@ var test = require('tap').test , VAST = require('../index.js') - , vast = new VAST(); + , vast = new VAST() + , ad + , creative; test('Validate ad settings', function(t){ t.throws(function(){ @@ -21,7 +23,7 @@ test('Validate ad settings', function(t){ t.end(); }); -vast.attachAd({ +ad = vast.attachAd({ structure : 'wrapper' , AdSystem : 'Common name of the ad' , sequence : 23 @@ -29,4 +31,6 @@ vast.attachAd({ , VASTAdTagURI : 'http://example.com' }).attachImpression({ id: Date.now(), url : 'http://impression.com' }); +creative = ad.attachCreative('Linear', { Wrapper : true } ) + module.exports = vast;