From d731f9c8b776d8f3dcb454d9e5116638f4f4fc00 Mon Sep 17 00:00:00 2001 From: LightAir Date: Tue, 24 Apr 2018 20:02:54 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B0=20=D1=82?= =?UTF-8?q?=D0=B5=D1=81=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/index.js | 2 +- test/expectedOutput/customElements.xml | 37 -- test/expectedOutput/customNamespaces.xml | 37 -- test/expectedOutput/default.xml | 2 +- test/expectedOutput/defaultItem.xml | 1 + test/expectedOutput/defaultOneItem.xml | 2 +- .../enclosure_mimetype_override.xml | 29 -- test/expectedOutput/enclosures.xml | 37 -- test/expectedOutput/latLong.xml | 29 -- test/expectedOutput/pubSubHubbub.xml | 11 - test/expectedOutput/simpleFeed.xml | 1 - test/expectedOutput/simpleFeedFormated.xml | 70 ---- test/index.js | 319 +----------------- 13 files changed, 11 insertions(+), 566 deletions(-) delete mode 100644 test/expectedOutput/customElements.xml delete mode 100644 test/expectedOutput/customNamespaces.xml create mode 100644 test/expectedOutput/defaultItem.xml delete mode 100644 test/expectedOutput/enclosure_mimetype_override.xml delete mode 100644 test/expectedOutput/enclosures.xml delete mode 100644 test/expectedOutput/latLong.xml delete mode 100644 test/expectedOutput/pubSubHubbub.xml delete mode 100644 test/expectedOutput/simpleFeed.xml delete mode 100644 test/expectedOutput/simpleFeedFormated.xml diff --git a/lib/index.js b/lib/index.js index b41c5ca..bf6b24a 100755 --- a/lib/index.js +++ b/lib/index.js @@ -13,7 +13,7 @@ function generateXML(data) { let channel = []; channel.push({title: {_cdata: data.title}}); - channel.push({link: data.link || 'http://github.com/lightair/yandex-turbo'}); + channel.push({link: data.link || 'http://github.com/LightAir/turbo-rss'}); channel.push({description: {_cdata: data.description || data.title}}); channel.push({language: 'ru'}); diff --git a/test/expectedOutput/customElements.xml b/test/expectedOutput/customElements.xml deleted file mode 100644 index fed80ae..0000000 --- a/test/expectedOutput/customElements.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - <![CDATA[title]]> - - http://example.com - RSS for Node - Wed, 10 Dec 2014 19:04:57 GMT - - - Sun, 20 May 2012 04:00:00 GMT - - 60 - A show about everything - John Doe - All About Everything is a show about everything. Each week we dive into any subject known to man and talk about it as much as we can. Look for our podcast in the Podcasts app or in the iTunes Store - - John Doe - john.doe@example.com - - - - - - - <![CDATA[item 1]]> - - http://example.com/article1 - http://example.com/article1 - - Thu, 24 May 2012 04:00:00 GMT - John Doe - A short primer on table spices - - 7:04 - - - \ No newline at end of file diff --git a/test/expectedOutput/customNamespaces.xml b/test/expectedOutput/customNamespaces.xml deleted file mode 100644 index 7fe75b6..0000000 --- a/test/expectedOutput/customNamespaces.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - <![CDATA[title]]> - - http://example.com - RSS for Node - Wed, 10 Dec 2014 19:04:57 GMT - - - Sun, 20 May 2012 04:00:00 GMT - - 60 - A show about everything - John Doe - All About Everything is a show about everything. Each week we dive into any subject known to man and talk about it as much as we can. Look for our podcast in the Podcasts app or in the iTunes Store - - John Doe - john.doe@example.com - - - - - - - <![CDATA[item 1]]> - - http://example.com/article1 - http://example.com/article1 - - Thu, 24 May 2012 04:00:00 GMT - John Doe - A short primer on table spices - - 7:04 - - - \ No newline at end of file diff --git a/test/expectedOutput/default.xml b/test/expectedOutput/default.xml index 56a9a27..6f79df5 100644 --- a/test/expectedOutput/default.xml +++ b/test/expectedOutput/default.xml @@ -1 +1 @@ -<![CDATA[Channel Yandex RSS]]>https://github.com/Lightair/yandex-turboru \ No newline at end of file +<![CDATA[Channel Yandex RSS]]>http://github.com/LightAir/turbo-rssru diff --git a/test/expectedOutput/defaultItem.xml b/test/expectedOutput/defaultItem.xml new file mode 100644 index 0000000..b272205 --- /dev/null +++ b/test/expectedOutput/defaultItem.xml @@ -0,0 +1 @@ +<![CDATA[title]]>http://example.com/rss.xmlru

No title

undefined]]>
diff --git a/test/expectedOutput/defaultOneItem.xml b/test/expectedOutput/defaultOneItem.xml index 6f721d9..abe3fcd 100644 --- a/test/expectedOutput/defaultOneItem.xml +++ b/test/expectedOutput/defaultOneItem.xml @@ -1 +1 @@ -<![CDATA[Untitled RSS Feed]]>http://github.com/dylang/node-rssRSS for NodeWed, 10 Dec 2014 19:04:57 GMT<![CDATA[No title]]>No title \ No newline at end of file +<![CDATA[Channel Yandex RSS]]>http://github.com/LightAir/turbo-rssru

No title

undefined]]>
diff --git a/test/expectedOutput/enclosure_mimetype_override.xml b/test/expectedOutput/enclosure_mimetype_override.xml deleted file mode 100644 index b1ba477..0000000 --- a/test/expectedOutput/enclosure_mimetype_override.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - <![CDATA[title]]> - - http://example.com - RSS for Node - Wed, 10 Dec 2014 19:04:57 GMT - - - - <![CDATA[item 1]]> - - http://example.com/article1 - http://example.com/article1 - - Thu, 24 May 2012 04:00:00 GMT - - - - <![CDATA[item 2]]> - - http://example.com/article1 - http://example.com/article1 - - Thu, 24 May 2012 04:00:00 GMT - - - - \ No newline at end of file diff --git a/test/expectedOutput/enclosures.xml b/test/expectedOutput/enclosures.xml deleted file mode 100644 index be32a38..0000000 --- a/test/expectedOutput/enclosures.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - <![CDATA[title]]> - - http://example.com - RSS for Node - Wed, 10 Dec 2014 19:04:57 GMT - - - - <![CDATA[item 1]]> - - http://example.com/article1 - http://example.com/article1 - - Thu, 24 May 2012 04:00:00 GMT - - - <![CDATA[item 2]]> - - http://example.com/article1 - http://example.com/article1 - - Thu, 24 May 2012 04:00:00 GMT - - - - <![CDATA[item 3]]> - - http://example.com/article1 - http://example.com/article1 - - Thu, 24 May 2012 04:00:00 GMT - - - - \ No newline at end of file diff --git a/test/expectedOutput/latLong.xml b/test/expectedOutput/latLong.xml deleted file mode 100644 index 7183953..0000000 --- a/test/expectedOutput/latLong.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - <![CDATA[title]]> - - http://example.com - RSS for Node - Wed, 10 Dec 2014 19:04:57 GMT - - - - <![CDATA[item 1]]> - - http://example.com/article1 - http://example.com/article1 - - Thu, 24 May 2012 04:00:00 GMT - 12232 - 13333.23323 - - - <![CDATA[item 2]]> - - http://example.com/article1 - http://example.com/article1 - - Thu, 24 May 2012 04:00:00 GMT - - - \ No newline at end of file diff --git a/test/expectedOutput/pubSubHubbub.xml b/test/expectedOutput/pubSubHubbub.xml deleted file mode 100644 index dafc2a1..0000000 --- a/test/expectedOutput/pubSubHubbub.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - <![CDATA[title]]> - - http://example.com - RSS for Node - Wed, 10 Dec 2014 19:04:57 GMT - - - - \ No newline at end of file diff --git a/test/expectedOutput/simpleFeed.xml b/test/expectedOutput/simpleFeed.xml deleted file mode 100644 index 7db75e8..0000000 --- a/test/expectedOutput/simpleFeed.xml +++ /dev/null @@ -1 +0,0 @@ -<![CDATA[title]]>http://example.comhttp://example.com/icon.pngtitlehttp://example.comExample GeneratorWed, 10 Dec 2014 19:04:57 GMTSun, 20 May 2012 04:00:00 GMThttp://example.com/rss/docs.html60<![CDATA[item 1]]>http://example.com/article1http://example.com/article1Thu, 24 May 2012 04:00:00 GMT<![CDATA[item 2]]>http://example.com/article2http://example.com/article2Fri, 25 May 2012 04:00:00 GMT<![CDATA[item 3]]>http://example.com/article3item3Sat, 26 May 2012 04:00:00 GMT<![CDATA[item 4 & html test with <strong>]]>html]]>http://example.com/article4?this&thathttp://example.com/article4?this&thatSun, 27 May 2012 04:00:00 GMT<![CDATA[item 5 & test for categories]]>http://example.com/article5http://example.com/article5Mon, 28 May 2012 04:00:00 GMT \ No newline at end of file diff --git a/test/expectedOutput/simpleFeedFormated.xml b/test/expectedOutput/simpleFeedFormated.xml deleted file mode 100644 index b788381..0000000 --- a/test/expectedOutput/simpleFeedFormated.xml +++ /dev/null @@ -1,70 +0,0 @@ - - - <![CDATA[title]]> - - http://example.com - - http://example.com/icon.png - title - http://example.com - - Example Generator - Wed, 10 Dec 2014 19:04:57 GMT - - - Sun, 20 May 2012 04:00:00 GMT - - - - - http://example.com/rss/docs.html - 60 - - - - - <![CDATA[item 1]]> - - http://example.com/article1 - http://example.com/article1 - - Thu, 24 May 2012 04:00:00 GMT - - - <![CDATA[item 2]]> - - http://example.com/article2 - http://example.com/article2 - - Fri, 25 May 2012 04:00:00 GMT - - - <![CDATA[item 3]]> - - http://example.com/article3 - item3 - - Sat, 26 May 2012 04:00:00 GMT - - - <![CDATA[item 4 & html test with <strong>]]> - html]]> - http://example.com/article4?this&that - http://example.com/article4?this&that - - Sun, 27 May 2012 04:00:00 GMT - - - <![CDATA[item 5 & test for categories]]> - - http://example.com/article5 - http://example.com/article5 - - - - - - Mon, 28 May 2012 04:00:00 GMT - - - \ No newline at end of file diff --git a/test/index.js b/test/index.js index e3cb13e..136eaa8 100644 --- a/test/index.js +++ b/test/index.js @@ -3,337 +3,32 @@ var test = require('tape'); var YTurbo = require('..'); -var xml2js = require('xml2js'); -var q = require('q'); var includeFolder = require('include-folder'); var expectedOutput = includeFolder(__dirname + '/expectedOutput', /.*\.xml$/); -// Dates in XML files will always be this value. require('mockdate').set('Wed, 10 Dec 2014 19:04:57 GMT'); test('empty feed', function(t) { t.plan(2); var feed = new YTurbo(); - t.equal(feed.xml(), expectedOutput.default); + t.equal(feed.xml(), expectedOutput.default.trim()); feed.item(); - t.equal(feed.xml(), expectedOutput.defaultOneItem); + t.equal(feed.xml(), expectedOutput.defaultOneItem.trim()); }); -test('indentation', function(t) { - t.plan(4); - var feed = new YTurbo({ - title: 'title', - description: 'description', - generator: 'Example Generator', - feed_url: 'http://example.com/rss.xml', - site_url: 'http://example.com', - image_url: 'http://example.com/icon.png', - author: 'Dylan Greene', - categories: ['Category 1','Category 2','Category 3'], - pubDate: 'May 20, 2012 04:00:00 GMT', - docs: 'http://example.com/rss/docs.html', - copyright: '2013 Dylan Green', - language: 'en', - managingEditor: 'Dylan Green', - webMaster: 'Dylan Green', - ttl: '60' - }); - - feed.item({ - title: 'item 1', - description: 'description 1', - url: 'http://example.com/article1', - date: 'May 24, 2012 04:00:00 GMT' - }) - .item({ - title: 'item 2', - description: 'description 2', - url: 'http://example.com/article2', - date: 'May 25, 2012 04:00:00 GMT' - }) - .item({ - title: 'item 3', - description: 'description 3', - url: 'http://example.com/article3', - guid: 'item3', - date: 'May 26, 2012 04:00:00 GMT' - }) - .item({ - title: 'item 4 & html test with ', - description: 'description 4 uses some html', - url: 'http://example.com/article4?this&that', - author: 'Guest Author', - date: 'May 27, 2012 04:00:00 GMT' - }) - .item({ - title: 'item 5 & test for categories', - description: 'description 5', - url: 'http://example.com/article5', - categories: ['Category 1','Category 2','Category 3','Category 4'], - author: 'Guest Author', - date: 'May 28, 2012 04:00:00 GMT' - }); - - var qParseXml = q.nbind(xml2js.parseString, xml2js); - - var xmlWithoutIndents = feed.xml({indent: false}); - var xmlWithIndents = feed.xml({indent: true}); - - t.notEqual(xmlWithoutIndents, xmlWithIndents); - t.equal(xmlWithoutIndents, expectedOutput.simpleFeed); - t.equal(xmlWithIndents, expectedOutput.simpleFeedFormated); - - q.all([ - qParseXml(xmlWithoutIndents), - qParseXml(xmlWithIndents) - ]) - .spread(function (fromWithoutIndents, fromWithIndents){ - t.deepEqual(JSON.stringify(fromWithoutIndents), JSON.stringify(fromWithIndents)); - }); -}); - -test('enclosure', function(t) { - //if (typeof window) return; +test('default item', function(t) { t.plan(1); var feed = new YTurbo({ title: 'title', description: 'description', - feed_url: 'http://example.com/rss.xml', - site_url: 'http://example.com', - author: 'Dylan Greene' + link: 'http://example.com/rss.xml', + site_url: 'http://example.com' }); - feed.item({ - title: 'item 1', - description: 'description 1', - url: 'http://example.com/article1', - date: 'May 24, 2012 04:00:00 GMT', - enclosure : 'incorrect value' - }); + feed.item({}); - feed.item({ - title: 'item 2', - description: 'description 2', - url: 'http://example.com/article1', - date: 'May 24, 2012 04:00:00 GMT', - enclosure : {url: '/media/some-file.flv'} - }); - - feed.item({ - title: 'item 3', - description: 'description 3', - url: 'http://example.com/article1', - date: 'May 24, 2012 04:00:00 GMT', - enclosure : { - url: '/media/image.png', - file: __dirname + '/image.png', - size: 16650 // this is optional - } - }); - - t.equal(feed.xml({indent: true}), expectedOutput.enclosures); -}); - -test('enclosure_mimetype_override', function(t) { - //if (typeof window) return; - - t.plan(1); - - var feed = new YTurbo({ - title: 'title', - description: 'description', - feed_url: 'http://example.com/rss.xml', - site_url: 'http://example.com', - author: 'Dylan Greene' - }); - - - feed.item({ - title: 'item 1', - description: 'description 1', - url: 'http://example.com/article1', - date: 'May 24, 2012 04:00:00 GMT', - enclosure : {url: '/media/some-file-without-extension', type: 'custom-video/x-flv'} - }); - - feed.item({ - title: 'item 2', - description: 'description 2', - url: 'http://example.com/article1', - date: 'May 24, 2012 04:00:00 GMT', - enclosure : { - url: '/media/image.png', - file: __dirname + '/image.png', - size: 16650, // this is optional - type: 'image/jpeg' // we set this just to prove that the override works - } - }); - - t.equal(feed.xml({indent: true}), expectedOutput.enclosure_mimetype_override); -}); - -test('geoRSS', function(t) { - t.plan(1); - var feed = new YTurbo({ - title: 'title', - description: 'description', - feed_url: 'http://example.com/rss.xml', - site_url: 'http://example.com', - author: 'Dylan Greene' - }); - - feed.item({ - title: 'item 1', - description: 'description 1', - url: 'http://example.com/article1', - date: 'May 24, 2012 04:00:00 GMT', - lat: 12232, - long: 13333.23323 - }); - - feed.item({ - title: 'item 2', - description: 'description 2', - url: 'http://example.com/article1', - date: 'May 24, 2012 04:00:00 GMT' - }); - - t.equal(feed.xml({indent: true}), expectedOutput.latLong); -}); - -test('PubSubHubbub hub', function(t) { - t.plan(1); - - var feed = new YTurbo({ - title: 'title', - description: 'description', - feed_url: 'http://example.com/rss.xml', - site_url: 'http://example.com', - hub: 'http://example.com/hub' - }); - - t.equal(feed.xml({indent: true}), expectedOutput.pubSubHubbub); -}); - - -test('custom elements', function(t) { - t.plan(1); - - var feed = new YTurbo({ - title: 'title', - description: 'description', - feed_url: 'http://example.com/rss.xml', - site_url: 'http://example.com', - author: 'Dylan Greene', - pubDate: 'May 20, 2012 04:00:00 GMT', - language: 'en', - ttl: '60', - custom_elements: [ - {'itunes:subtitle': 'A show about everything'}, - {'itunes:author': 'John Doe'}, - {'itunes:summary': 'All About Everything is a show about everything. Each week we dive into any subject known to man and talk about it as much as we can. Look for our podcast in the Podcasts app or in the iTunes Store'}, - {'itunes:owner': [ - {'itunes:name': 'John Doe'}, - {'itunes:email': 'john.doe@example.com'} - ]}, - {'itunes:image': { - _attr: { - href: 'http://example.com/podcasts/everything/AllAboutEverything.jpg' - } - }}, - {'itunes:category': [ - {_attr: { - text: 'Technology' - }}, - {'itunes:category': { - _attr: { - text: 'Gadgets' - } - }} - ]} - ] - }); - - feed.item({ - title: 'item 1', - description: 'description 1', - url: 'http://example.com/article1', - date: 'May 24, 2012 04:00:00 GMT', - custom_elements: [ - {'itunes:author': 'John Doe'}, - {'itunes:subtitle': 'A short primer on table spices'}, - {'itunes:image': { - _attr: { - href: 'http://example.com/podcasts/everything/AllAboutEverything/Episode1.jpg' - } - }}, - {'itunes:duration': '7:04'} - ] - }); - - t.equal(feed.xml({indent: true}), expectedOutput.customElements); -}); - -test('custom namespaces', function(t) { - t.plan(1); - - var feed = new YTurbo({ - title: 'title', - description: 'description', - feed_url: 'http://example.com/rss.xml', - site_url: 'http://example.com', - author: 'Dylan Greene', - pubDate: 'May 20, 2012 04:00:00 GMT', - language: 'en', - ttl: '60', - custom_namespaces: { - 'itunes': 'http://www.itunes.com/dtds/podcast-1.0.dtd' - }, - custom_elements: [ - {'itunes:subtitle': 'A show about everything'}, - {'itunes:author': 'John Doe'}, - {'itunes:summary': 'All About Everything is a show about everything. Each week we dive into any subject known to man and talk about it as much as we can. Look for our podcast in the Podcasts app or in the iTunes Store'}, - {'itunes:owner': [ - {'itunes:name': 'John Doe'}, - {'itunes:email': 'john.doe@example.com'} - ]}, - {'itunes:image': { - _attr: { - href: 'http://example.com/podcasts/everything/AllAboutEverything.jpg' - } - }}, - {'itunes:category': [ - {_attr: { - text: 'Technology' - }}, - {'itunes:category': { - _attr: { - text: 'Gadgets' - } - }} - ]} - ] - }); - - feed.item({ - title: 'item 1', - description: 'description 1', - url: 'http://example.com/article1', - date: 'May 24, 2012 04:00:00 GMT', - custom_elements: [ - {'itunes:author': 'John Doe'}, - {'itunes:subtitle': 'A short primer on table spices'}, - {'itunes:image': { - _attr: { - href: 'http://example.com/podcasts/everything/AllAboutEverything/Episode1.jpg' - } - }}, - {'itunes:duration': '7:04'} - ] - }); - - t.equal(feed.xml({indent: true}), expectedOutput.customNamespaces); + t.equal(feed.xml(), expectedOutput.defaultItem.trim()); });