Permalink
Browse files

normalise rss/atom links

  • Loading branch information...
Michael Hughes Michael Hughes
Michael Hughes authored and Michael Hughes committed Mar 18, 2013
1 parent d666e9b commit d456f7d86df0263a378e0935c3712cbc6f687c32
Showing with 23 additions and 9 deletions.
  1. +8 −8 src/server/RSSCollector.coffee
  2. +15 −1 test/server/unit/RSSCollector_test.coffee
@@ -29,14 +29,14 @@ exports.createRSSCollector = ->
fun("Unable to parse feed",null)
parseAtom:(data)->
- {
- title:data.title
- entry:_.flatten([data.entry])
- }
+ title: data.title
+ entry: @parseEntry(e) for e in _.flatten([data.entry])
+
+ parseEntry:(e)->
+ title: e.title
+ link: e.link.$.href
parseRSS:(data)->
- {
- title:data.title
- entry:_.flatten([data.item])
- }
+ title: data.title
+ entry: _.flatten([data.item])
@@ -36,12 +36,15 @@ describe 'A RSS collector', ->
expect(err).to.be.null
expect(result.title,"title").to.equal("BBC News - Home")
expect(result.entry[0].title).to.equal("Cameron halts press regulation talks")
+ expect(result.entry[1].link).to.equal("http://www.bbc.co.uk/news/world-europe-21793224#sa-ns_mchannel=rss&ns_source=PublicRSS20-sa")
done()
+
it 'should be able to retrieve and parse some RSS XML', (done)->
@collector.requestFeed FakeRSS,(err,result)->
expect(err,err).to.be.null
expect(result,"result").to.exist
done()
+
it 'should be able to parse some Atom XML', (done)->
data =
"""
@@ -69,4 +72,15 @@ describe 'A RSS collector', ->
expect(err).to.be.null
expect(result.title,"title").to.equal("Example Feed")
expect(result.entry[0].title).to.equal("Atom-Powered Robots Run Amok")
- done()
+ expect(result.entry[0].link).to.equal("http://example.org/2003/12/13/atom03")
+ done()
+
+ it 'should convert an atom entry link from attribute to element', ()->
+ entry = {
+ title:"abc"
+ link:{"$": {"href": "http://example.org/2003/12/13/atom03"}}
+ }
+ expect(@collector.parseEntry entry).to.eql {
+ title:"abc"
+ link:"http://example.org/2003/12/13/atom03"
+ }

0 comments on commit d456f7d

Please sign in to comment.