/*
use nodeunit to run tests.
*/
var RSS = require('../lib/rss');
module.exports = {
'empty feed': function(test) {
var feed = new RSS();
test.equal(feed.xml(), '\nhttp://github.com/dylan/node-rssNodeJS RSS Module' + new Date().toUTCString() +'');
feed.item();
test.equal(feed.xml(), '\nhttp://github.com/dylan/node-rssNodeJS RSS Module' + new Date().toUTCString() +'- No title
');
test.done();
},
'easy test': function(test) {
var feed = new RSS({
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 expectedResult = '\nhttp://example.comhttp://example.com/icon.pngtitlehttp://example.comExample Generator' + new Date().toUTCString() +'Sun, 20 May 2012 04:00:00 GMThttp://example.com/rss/docs.html60- http://example.com/article1http://example.com/article1Thu, 24 May 2012 04:00:00 GMT
- http://example.com/article2http://example.com/article2Fri, 25 May 2012 04:00:00 GMT
- http://example.com/article3item3Sat, 26 May 2012 04:00:00 GMT
- ]]>html
]]>http://example.com/article4?this&thathttp://example.com/article4?this&thatSun, 27 May 2012 04:00:00 GMT- http://example.com/article5http://example.com/article5Mon, 28 May 2012 04:00:00 GMT
';
var result = feed.xml();
test.equal(result.length, expectedResult.length);
test.equal(result, expectedResult);
test.done();
},
'easy test without image_url': function(test) {
var feed = new RSS({
title: 'title',
description: 'description',
feed_url: 'http://example.com/rss.xml',
site_url: 'http://example.com',
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 expectedResult = '\nhttp://example.comNodeJS RSS Module' + new Date().toUTCString() +'Sun, 20 May 2012 04:00:00 GMThttp://example.com/rss/docs.html60- http://example.com/article1http://example.com/article1Thu, 24 May 2012 04:00:00 GMT
- http://example.com/article2http://example.com/article2Fri, 25 May 2012 04:00:00 GMT
- http://example.com/article3item3Sat, 26 May 2012 04:00:00 GMT
- ]]>html
]]>http://example.com/article4?this&thathttp://example.com/article4?this&thatSun, 27 May 2012 04:00:00 GMT- http://example.com/article5http://example.com/article5Mon, 28 May 2012 04:00:00 GMT
';
var result = feed.xml();
test.equal(result.length, expectedResult.length);
test.equal(result, expectedResult);
test.done();
},
'test with enclosure' : function(test) {
var feed = new RSS({
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 : 'incorrect value'
});
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'}
});
var expectedResult = '\nhttp://example.comNodeJS RSS Module' + new Date().toUTCString() +''+
'' +
'- http://example.com/article1http://example.com/article1Thu, 24 May 2012 04:00:00 GMT
'+
'- http://example.com/article1http://example.com/article1Thu, 24 May 2012 04:00:00 GMT
'+
'- http://example.com/article1http://example.com/article1Thu, 24 May 2012 04:00:00 GMT
'+
'';
var result = feed.xml();
test.equal(result.length, expectedResult.length);
test.equal(result, expectedResult);
test.done();
}
};