mirror of
https://github.com/LightAir/turbo-rss.git
synced 2026-02-04 03:56:19 +00:00
Правка тестов
This commit is contained in:
@@ -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'});
|
||||
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
|
||||
<channel>
|
||||
<title><![CDATA[title]]></title>
|
||||
<description><![CDATA[description]]></description>
|
||||
<link>http://example.com</link>
|
||||
<generator>RSS for Node</generator>
|
||||
<lastBuildDate>Wed, 10 Dec 2014 19:04:57 GMT</lastBuildDate>
|
||||
<atom:link href="http://example.com/rss.xml" rel="self" type="application/rss+xml"/>
|
||||
<author><![CDATA[Dylan Greene]]></author>
|
||||
<pubDate>Sun, 20 May 2012 04:00:00 GMT</pubDate>
|
||||
<language><![CDATA[en]]></language>
|
||||
<ttl>60</ttl>
|
||||
<itunes:subtitle>A show about everything</itunes:subtitle>
|
||||
<itunes:author>John Doe</itunes:author>
|
||||
<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:summary>
|
||||
<itunes:owner>
|
||||
<itunes:name>John Doe</itunes:name>
|
||||
<itunes:email>john.doe@example.com</itunes:email>
|
||||
</itunes:owner>
|
||||
<itunes:image href="http://example.com/podcasts/everything/AllAboutEverything.jpg"/>
|
||||
<itunes:category text="Technology">
|
||||
<itunes:category text="Gadgets"/>
|
||||
</itunes:category>
|
||||
<item>
|
||||
<title><![CDATA[item 1]]></title>
|
||||
<description><![CDATA[description 1]]></description>
|
||||
<link>http://example.com/article1</link>
|
||||
<guid isPermaLink="true">http://example.com/article1</guid>
|
||||
<dc:creator><![CDATA[Dylan Greene]]></dc:creator>
|
||||
<pubDate>Thu, 24 May 2012 04:00:00 GMT</pubDate>
|
||||
<itunes:author>John Doe</itunes:author>
|
||||
<itunes:subtitle>A short primer on table spices</itunes:subtitle>
|
||||
<itunes:image href="http://example.com/podcasts/everything/AllAboutEverything/Episode1.jpg"/>
|
||||
<itunes:duration>7:04</itunes:duration>
|
||||
</item>
|
||||
</channel>
|
||||
</rss>
|
||||
@@ -1,37 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
|
||||
<channel>
|
||||
<title><![CDATA[title]]></title>
|
||||
<description><![CDATA[description]]></description>
|
||||
<link>http://example.com</link>
|
||||
<generator>RSS for Node</generator>
|
||||
<lastBuildDate>Wed, 10 Dec 2014 19:04:57 GMT</lastBuildDate>
|
||||
<atom:link href="http://example.com/rss.xml" rel="self" type="application/rss+xml"/>
|
||||
<author><![CDATA[Dylan Greene]]></author>
|
||||
<pubDate>Sun, 20 May 2012 04:00:00 GMT</pubDate>
|
||||
<language><![CDATA[en]]></language>
|
||||
<ttl>60</ttl>
|
||||
<itunes:subtitle>A show about everything</itunes:subtitle>
|
||||
<itunes:author>John Doe</itunes:author>
|
||||
<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:summary>
|
||||
<itunes:owner>
|
||||
<itunes:name>John Doe</itunes:name>
|
||||
<itunes:email>john.doe@example.com</itunes:email>
|
||||
</itunes:owner>
|
||||
<itunes:image href="http://example.com/podcasts/everything/AllAboutEverything.jpg"/>
|
||||
<itunes:category text="Technology">
|
||||
<itunes:category text="Gadgets"/>
|
||||
</itunes:category>
|
||||
<item>
|
||||
<title><![CDATA[item 1]]></title>
|
||||
<description><![CDATA[description 1]]></description>
|
||||
<link>http://example.com/article1</link>
|
||||
<guid isPermaLink="true">http://example.com/article1</guid>
|
||||
<dc:creator><![CDATA[Dylan Greene]]></dc:creator>
|
||||
<pubDate>Thu, 24 May 2012 04:00:00 GMT</pubDate>
|
||||
<itunes:author>John Doe</itunes:author>
|
||||
<itunes:subtitle>A short primer on table spices</itunes:subtitle>
|
||||
<itunes:image href="http://example.com/podcasts/everything/AllAboutEverything/Episode1.jpg"/>
|
||||
<itunes:duration>7:04</itunes:duration>
|
||||
</item>
|
||||
</channel>
|
||||
</rss>
|
||||
@@ -1 +1 @@
|
||||
<rss xmlns:yandex="http://news.yandex.ru" xmlns:media="http://search.yahoo.com/mrss/" xmlns:turbo="http://turbo.yandex.ru" version="2.0"><channel><title><![CDATA[Channel Yandex RSS]]></title><link>https://github.com/Lightair/yandex-turbo</link><description><![CDATA[Channel Yandex RSS]]></description><language>ru</language></channel></rss>
|
||||
<rss xmlns:yandex="http://news.yandex.ru" xmlns:media="http://search.yahoo.com/mrss/" xmlns:turbo="http://turbo.yandex.ru" version="2.0"><channel><title><![CDATA[Channel Yandex RSS]]></title><link>http://github.com/LightAir/turbo-rss</link><description><![CDATA[Channel Yandex RSS]]></description><language>ru</language></channel></rss>
|
||||
|
||||
1
test/expectedOutput/defaultItem.xml
Normal file
1
test/expectedOutput/defaultItem.xml
Normal file
@@ -0,0 +1 @@
|
||||
<rss xmlns:yandex="http://news.yandex.ru" xmlns:media="http://search.yahoo.com/mrss/" xmlns:turbo="http://turbo.yandex.ru" version="2.0"><channel><title><![CDATA[title]]></title><link>http://example.com/rss.xml</link><description><![CDATA[description]]></description><language>ru</language><item turbo="true"><link></link><turbo:source></turbo:source><turbo:content><![CDATA[<header> <h1>No title</h1>undefined</header>]]></turbo:content></item></channel></rss>
|
||||
@@ -1 +1 @@
|
||||
<rss xmlns:yandex="http://news.yandex.ru" xmlns:media="http://search.yahoo.com/mrss/" xmlns:turbo="http://turbo.yandex.ru" version="2.0"><channel><title><![CDATA[Untitled RSS Feed]]></title><description><![CDATA[Untitled RSS Feed]]></description><link>http://github.com/dylang/node-rss</link><generator>RSS for Node</generator><lastBuildDate>Wed, 10 Dec 2014 19:04:57 GMT</lastBuildDate><item><title><![CDATA[No title]]></title><guid isPermaLink="false">No title</guid></item></channel></rss>
|
||||
<rss xmlns:yandex="http://news.yandex.ru" xmlns:media="http://search.yahoo.com/mrss/" xmlns:turbo="http://turbo.yandex.ru" version="2.0"><channel><title><![CDATA[Channel Yandex RSS]]></title><link>http://github.com/LightAir/turbo-rss</link><description><![CDATA[Channel Yandex RSS]]></description><language>ru</language><item turbo="true"><link></link><turbo:source></turbo:source><turbo:content><![CDATA[<header> <h1>No title</h1>undefined</header>]]></turbo:content></item></channel></rss>
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
|
||||
<channel>
|
||||
<title><![CDATA[title]]></title>
|
||||
<description><![CDATA[description]]></description>
|
||||
<link>http://example.com</link>
|
||||
<generator>RSS for Node</generator>
|
||||
<lastBuildDate>Wed, 10 Dec 2014 19:04:57 GMT</lastBuildDate>
|
||||
<atom:link href="http://example.com/rss.xml" rel="self" type="application/rss+xml"/>
|
||||
<author><![CDATA[Dylan Greene]]></author>
|
||||
<item>
|
||||
<title><![CDATA[item 1]]></title>
|
||||
<description><![CDATA[description 1]]></description>
|
||||
<link>http://example.com/article1</link>
|
||||
<guid isPermaLink="true">http://example.com/article1</guid>
|
||||
<dc:creator><![CDATA[Dylan Greene]]></dc:creator>
|
||||
<pubDate>Thu, 24 May 2012 04:00:00 GMT</pubDate>
|
||||
<enclosure url="/media/some-file-without-extension" length="0" type="custom-video/x-flv"/>
|
||||
</item>
|
||||
<item>
|
||||
<title><![CDATA[item 2]]></title>
|
||||
<description><![CDATA[description 2]]></description>
|
||||
<link>http://example.com/article1</link>
|
||||
<guid isPermaLink="true">http://example.com/article1</guid>
|
||||
<dc:creator><![CDATA[Dylan Greene]]></dc:creator>
|
||||
<pubDate>Thu, 24 May 2012 04:00:00 GMT</pubDate>
|
||||
<enclosure url="/media/image.png" length="16650" type="image/jpeg"/>
|
||||
</item>
|
||||
</channel>
|
||||
</rss>
|
||||
@@ -1,37 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
|
||||
<channel>
|
||||
<title><![CDATA[title]]></title>
|
||||
<description><![CDATA[description]]></description>
|
||||
<link>http://example.com</link>
|
||||
<generator>RSS for Node</generator>
|
||||
<lastBuildDate>Wed, 10 Dec 2014 19:04:57 GMT</lastBuildDate>
|
||||
<atom:link href="http://example.com/rss.xml" rel="self" type="application/rss+xml"/>
|
||||
<author><![CDATA[Dylan Greene]]></author>
|
||||
<item>
|
||||
<title><![CDATA[item 1]]></title>
|
||||
<description><![CDATA[description 1]]></description>
|
||||
<link>http://example.com/article1</link>
|
||||
<guid isPermaLink="true">http://example.com/article1</guid>
|
||||
<dc:creator><![CDATA[Dylan Greene]]></dc:creator>
|
||||
<pubDate>Thu, 24 May 2012 04:00:00 GMT</pubDate>
|
||||
</item>
|
||||
<item>
|
||||
<title><![CDATA[item 2]]></title>
|
||||
<description><![CDATA[description 2]]></description>
|
||||
<link>http://example.com/article1</link>
|
||||
<guid isPermaLink="true">http://example.com/article1</guid>
|
||||
<dc:creator><![CDATA[Dylan Greene]]></dc:creator>
|
||||
<pubDate>Thu, 24 May 2012 04:00:00 GMT</pubDate>
|
||||
<enclosure url="/media/some-file.flv" length="0" type="video/x-flv"/>
|
||||
</item>
|
||||
<item>
|
||||
<title><![CDATA[item 3]]></title>
|
||||
<description><![CDATA[description 3]]></description>
|
||||
<link>http://example.com/article1</link>
|
||||
<guid isPermaLink="true">http://example.com/article1</guid>
|
||||
<dc:creator><![CDATA[Dylan Greene]]></dc:creator>
|
||||
<pubDate>Thu, 24 May 2012 04:00:00 GMT</pubDate>
|
||||
<enclosure url="/media/image.png" length="16650" type="image/png"/>
|
||||
</item>
|
||||
</channel>
|
||||
</rss>
|
||||
@@ -1,29 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
|
||||
<channel>
|
||||
<title><![CDATA[title]]></title>
|
||||
<description><![CDATA[description]]></description>
|
||||
<link>http://example.com</link>
|
||||
<generator>RSS for Node</generator>
|
||||
<lastBuildDate>Wed, 10 Dec 2014 19:04:57 GMT</lastBuildDate>
|
||||
<atom:link href="http://example.com/rss.xml" rel="self" type="application/rss+xml"/>
|
||||
<author><![CDATA[Dylan Greene]]></author>
|
||||
<item>
|
||||
<title><![CDATA[item 1]]></title>
|
||||
<description><![CDATA[description 1]]></description>
|
||||
<link>http://example.com/article1</link>
|
||||
<guid isPermaLink="true">http://example.com/article1</guid>
|
||||
<dc:creator><![CDATA[Dylan Greene]]></dc:creator>
|
||||
<pubDate>Thu, 24 May 2012 04:00:00 GMT</pubDate>
|
||||
<geo:lat>12232</geo:lat>
|
||||
<geo:long>13333.23323</geo:long>
|
||||
</item>
|
||||
<item>
|
||||
<title><![CDATA[item 2]]></title>
|
||||
<description><![CDATA[description 2]]></description>
|
||||
<link>http://example.com/article1</link>
|
||||
<guid isPermaLink="true">http://example.com/article1</guid>
|
||||
<dc:creator><![CDATA[Dylan Greene]]></dc:creator>
|
||||
<pubDate>Thu, 24 May 2012 04:00:00 GMT</pubDate>
|
||||
</item>
|
||||
</channel>
|
||||
</rss>
|
||||
@@ -1,11 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
|
||||
<channel>
|
||||
<title><![CDATA[title]]></title>
|
||||
<description><![CDATA[description]]></description>
|
||||
<link>http://example.com</link>
|
||||
<generator>RSS for Node</generator>
|
||||
<lastBuildDate>Wed, 10 Dec 2014 19:04:57 GMT</lastBuildDate>
|
||||
<atom:link href="http://example.com/rss.xml" rel="self" type="application/rss+xml"/>
|
||||
<atom:link href="http://example.com/hub" rel="hub"/>
|
||||
</channel>
|
||||
</rss>
|
||||
@@ -1 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[title]]></title><description><![CDATA[description]]></description><link>http://example.com</link><image><url>http://example.com/icon.png</url><title>title</title><link>http://example.com</link></image><generator>Example Generator</generator><lastBuildDate>Wed, 10 Dec 2014 19:04:57 GMT</lastBuildDate><atom:link href="http://example.com/rss.xml" rel="self" type="application/rss+xml"/><author><![CDATA[Dylan Greene]]></author><pubDate>Sun, 20 May 2012 04:00:00 GMT</pubDate><copyright><![CDATA[2013 Dylan Green]]></copyright><language><![CDATA[en]]></language><managingEditor><![CDATA[Dylan Green]]></managingEditor><webMaster><![CDATA[Dylan Green]]></webMaster><docs>http://example.com/rss/docs.html</docs><ttl>60</ttl><category><![CDATA[Category 1]]></category><category><![CDATA[Category 2]]></category><category><![CDATA[Category 3]]></category><item><title><![CDATA[item 1]]></title><description><![CDATA[description 1]]></description><link>http://example.com/article1</link><guid isPermaLink="true">http://example.com/article1</guid><dc:creator><![CDATA[Dylan Greene]]></dc:creator><pubDate>Thu, 24 May 2012 04:00:00 GMT</pubDate></item><item><title><![CDATA[item 2]]></title><description><![CDATA[description 2]]></description><link>http://example.com/article2</link><guid isPermaLink="true">http://example.com/article2</guid><dc:creator><![CDATA[Dylan Greene]]></dc:creator><pubDate>Fri, 25 May 2012 04:00:00 GMT</pubDate></item><item><title><![CDATA[item 3]]></title><description><![CDATA[description 3]]></description><link>http://example.com/article3</link><guid isPermaLink="false">item3</guid><dc:creator><![CDATA[Dylan Greene]]></dc:creator><pubDate>Sat, 26 May 2012 04:00:00 GMT</pubDate></item><item><title><![CDATA[item 4 & html test with <strong>]]></title><description><![CDATA[description 4 uses some <strong>html</strong>]]></description><link>http://example.com/article4?this&that</link><guid isPermaLink="true">http://example.com/article4?this&that</guid><dc:creator><![CDATA[Guest Author]]></dc:creator><pubDate>Sun, 27 May 2012 04:00:00 GMT</pubDate></item><item><title><![CDATA[item 5 & test for categories]]></title><description><![CDATA[description 5]]></description><link>http://example.com/article5</link><guid isPermaLink="true">http://example.com/article5</guid><category><![CDATA[Category 1]]></category><category><![CDATA[Category 2]]></category><category><![CDATA[Category 3]]></category><category><![CDATA[Category 4]]></category><dc:creator><![CDATA[Guest Author]]></dc:creator><pubDate>Mon, 28 May 2012 04:00:00 GMT</pubDate></item></channel></rss>
|
||||
@@ -1,70 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
|
||||
<channel>
|
||||
<title><![CDATA[title]]></title>
|
||||
<description><![CDATA[description]]></description>
|
||||
<link>http://example.com</link>
|
||||
<image>
|
||||
<url>http://example.com/icon.png</url>
|
||||
<title>title</title>
|
||||
<link>http://example.com</link>
|
||||
</image>
|
||||
<generator>Example Generator</generator>
|
||||
<lastBuildDate>Wed, 10 Dec 2014 19:04:57 GMT</lastBuildDate>
|
||||
<atom:link href="http://example.com/rss.xml" rel="self" type="application/rss+xml"/>
|
||||
<author><![CDATA[Dylan Greene]]></author>
|
||||
<pubDate>Sun, 20 May 2012 04:00:00 GMT</pubDate>
|
||||
<copyright><![CDATA[2013 Dylan Green]]></copyright>
|
||||
<language><![CDATA[en]]></language>
|
||||
<managingEditor><![CDATA[Dylan Green]]></managingEditor>
|
||||
<webMaster><![CDATA[Dylan Green]]></webMaster>
|
||||
<docs>http://example.com/rss/docs.html</docs>
|
||||
<ttl>60</ttl>
|
||||
<category><![CDATA[Category 1]]></category>
|
||||
<category><![CDATA[Category 2]]></category>
|
||||
<category><![CDATA[Category 3]]></category>
|
||||
<item>
|
||||
<title><![CDATA[item 1]]></title>
|
||||
<description><![CDATA[description 1]]></description>
|
||||
<link>http://example.com/article1</link>
|
||||
<guid isPermaLink="true">http://example.com/article1</guid>
|
||||
<dc:creator><![CDATA[Dylan Greene]]></dc:creator>
|
||||
<pubDate>Thu, 24 May 2012 04:00:00 GMT</pubDate>
|
||||
</item>
|
||||
<item>
|
||||
<title><![CDATA[item 2]]></title>
|
||||
<description><![CDATA[description 2]]></description>
|
||||
<link>http://example.com/article2</link>
|
||||
<guid isPermaLink="true">http://example.com/article2</guid>
|
||||
<dc:creator><![CDATA[Dylan Greene]]></dc:creator>
|
||||
<pubDate>Fri, 25 May 2012 04:00:00 GMT</pubDate>
|
||||
</item>
|
||||
<item>
|
||||
<title><![CDATA[item 3]]></title>
|
||||
<description><![CDATA[description 3]]></description>
|
||||
<link>http://example.com/article3</link>
|
||||
<guid isPermaLink="false">item3</guid>
|
||||
<dc:creator><![CDATA[Dylan Greene]]></dc:creator>
|
||||
<pubDate>Sat, 26 May 2012 04:00:00 GMT</pubDate>
|
||||
</item>
|
||||
<item>
|
||||
<title><![CDATA[item 4 & html test with <strong>]]></title>
|
||||
<description><![CDATA[description 4 uses some <strong>html</strong>]]></description>
|
||||
<link>http://example.com/article4?this&that</link>
|
||||
<guid isPermaLink="true">http://example.com/article4?this&that</guid>
|
||||
<dc:creator><![CDATA[Guest Author]]></dc:creator>
|
||||
<pubDate>Sun, 27 May 2012 04:00:00 GMT</pubDate>
|
||||
</item>
|
||||
<item>
|
||||
<title><![CDATA[item 5 & test for categories]]></title>
|
||||
<description><![CDATA[description 5]]></description>
|
||||
<link>http://example.com/article5</link>
|
||||
<guid isPermaLink="true">http://example.com/article5</guid>
|
||||
<category><![CDATA[Category 1]]></category>
|
||||
<category><![CDATA[Category 2]]></category>
|
||||
<category><![CDATA[Category 3]]></category>
|
||||
<category><![CDATA[Category 4]]></category>
|
||||
<dc:creator><![CDATA[Guest Author]]></dc:creator>
|
||||
<pubDate>Mon, 28 May 2012 04:00:00 GMT</pubDate>
|
||||
</item>
|
||||
</channel>
|
||||
</rss>
|
||||
319
test/index.js
319
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 <strong>',
|
||||
description: 'description 4 uses some <strong>html</strong>',
|
||||
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());
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user