From 15446e0dea1b87a061f975382a76a1506342d152 Mon Sep 17 00:00:00 2001 From: Michael Vial Date: Wed, 25 Jun 2014 17:11:00 +0200 Subject: [PATCH 1/2] Fixed unvalid trackingEvents property for Wrapped Companions --- src/parser.coffee | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/parser.coffee b/src/parser.coffee index a35578a7..02044e95 100644 --- a/src/parser.coffee +++ b/src/parser.coffee @@ -102,9 +102,10 @@ class VASTParser if ad.trackingEvents? for creative in wrappedAd.creatives - for eventName in Object.keys ad.trackingEvents - creative.trackingEvents[eventName] or= [] - creative.trackingEvents[eventName] = creative.trackingEvents[eventName].concat ad.trackingEvents[eventName] + if creative.type is 'linear' + for eventName in Object.keys ad.trackingEvents + creative.trackingEvents[eventName] or= [] + creative.trackingEvents[eventName] = creative.trackingEvents[eventName].concat ad.trackingEvents[eventName] response.ads.splice index, 0, wrappedAd From ad67e8ddea029fd4be6912aa2c9451c4c2a69531 Mon Sep 17 00:00:00 2001 From: Michael Vial Date: Thu, 26 Jun 2014 09:32:30 +0200 Subject: [PATCH 2/2] Added some test cases for parser --- test/parser.coffee | 85 ++++++++++++++++++++++++++++++++++++---------- test/sample.xml | 11 ++++++ 2 files changed, 78 insertions(+), 18 deletions(-) diff --git a/test/parser.coffee b/test/parser.coffee index 8871280f..45962cef 100644 --- a/test/parser.coffee +++ b/test/parser.coffee @@ -9,6 +9,7 @@ urlfor = (relpath) -> describe 'VASTParser', -> describe '#parse', -> @response = null + _response = null @templateFilterCalls = [] before (done) => @@ -16,6 +17,7 @@ describe 'VASTParser', -> @templateFilterCalls.push url return url VASTParser.parse urlfor('wrapper.xml'), (@response) => + _response = @response done() after () => @@ -43,28 +45,75 @@ describe 'VASTParser', -> it 'should have merged impression URLs', => @response.ads[0].impressionURLTemplates.should.eql ["http://example.com/wrapper-impression", "http://example.com/impression1", "http://example.com/impression2", "http://example.com/impression3"] - it 'should have a single creative', => - @response.ads[0].creatives.should.have.length 1 + it 'should have a two creatives', => + @response.ads[0].creatives.should.have.length 2 - it 'should have 1 media file', => - @response.ads[0].creatives[0].mediaFiles.should.have.length 1 + #Linear + describe '#Linear', -> + linear = null - it 'should have a duration of s', => - @response.ads[0].creatives[0].duration.should.equal 90.123 + before (done) => + linear = _response.ads[0].creatives[0] + done() + + it 'should have linear type', => + linear.type.should.equal "linear" + + it 'should have 1 media file', => + linear.mediaFiles.should.have.length 1 + + it 'should have a duration of s', => + linear.duration.should.equal 90.123 + + it 'should have parsed media file attributes', => + mediaFile = linear.mediaFiles[0] + mediaFile.width.should.equal 512 + mediaFile.height.should.equal 288 + mediaFile.mimeType.should.equal "video/mp4" + mediaFile.fileURL.should.equal "http://example.com/asset.mp4" + + it 'should have 6 tracking events', => + linear.trackingEvents.should.have.keys 'start', 'close', 'midpoint', 'complete', 'firstQuartile', 'thirdQuartile' + + it 'should have 2 urls for start event', => + linear.trackingEvents['start'].should.eql ['http://example.com/start', 'http://example.com/wrapper-start'] + + it 'should have 2 urls for complete event', => + linear.trackingEvents['complete'].should.eql ['http://example.com/complete', 'http://example.com/wrapper-complete'] + + #Companions + describe '#Companions', -> + companions = null + + before (done) => + companions = _response.ads[0].creatives[1] + done() + + it 'should have companion type', => + companions.type.should.equal "companion" + + it 'should have 1 variation', => + companions.variations.should.have.length 1 + + #Companion + describe '#Companion', -> + companion = null + + before (done) => + companion = companions.variations[0] + done() - it 'should have parsed media file attributes', => - mediaFile = @response.ads[0].creatives[0].mediaFiles[0] - mediaFile.width.should.equal 512 - mediaFile.height.should.equal 288 - mediaFile.mimeType.should.equal "video/mp4" - mediaFile.fileURL.should.equal "http://example.com/asset.mp4" + it 'should have parsed size and type attributes', => + companion.width.should.equal '300' + companion.height.should.equal '60' + companion.type.should.equal 'image/jpeg' - it 'should have 6 tracking events', => - @response.ads[0].creatives[0].trackingEvents.should.have.keys 'start', 'close', 'midpoint', 'complete', 'firstQuartile', 'thirdQuartile' + it 'should have 1 tracking event', => + companion.trackingEvents.should.have.keys 'creativeView' - it 'should have 2 urls for start event', => - @response.ads[0].creatives[0].trackingEvents['start'].should.eql ['http://example.com/start', 'http://example.com/wrapper-start'] + it 'should have 1 url for creativeView event', => + companion.trackingEvents['creativeView'].should.eql ['http://example.com/creativeview'] - it 'should have 2 urls for complete event', => - @response.ads[0].creatives[0].trackingEvents['complete'].should.eql ['http://example.com/complete', 'http://example.com/wrapper-complete'] + it 'should have 1 companion clickthrough url', => + companion.companionClickThroughURLTemplate.should.equal 'http://example.com/companion-clickthrough' diff --git a/test/sample.xml b/test/sample.xml index debee51a..cb84c39b 100644 --- a/test/sample.xml +++ b/test/sample.xml @@ -29,6 +29,17 @@ + + + + + + + + + + +