Skip to content

Commit 0dd89d6

Browse files
authored
Merge pull request #15 from Serra19/patch-1
Fix getItemPublished function for atom parser
2 parents 4452290 + 50ced7d commit 0dd89d6

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

parsers/atomv1.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ function getItemPublished(node) {
159159
var pub = utils.getElementTextContent(node, 'updated');
160160

161161
if(pub === '' || pub === undefined){
162-
utils.getElementTextContent(node, 'published');
162+
pub = utils.getElementTextContent(node, 'published');
163163
}
164164

165165
return pub;
@@ -201,4 +201,4 @@ function mapItems(document) {
201201
itunes: itunesParser.parseItem(item)
202202
};
203203
});
204-
}
204+
}

test/samples/atomv1-no-updated.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
exports.feed = `
2+
<?xml version="1.0" encoding="utf-8"?>
3+
<feed xmlns="http://www.w3.org/2005/Atom">
4+
<title>ATOM title</title>
5+
<subtitle>A sample ATOM feed</subtitle>
6+
<logo>https://b.thumbs.redditmedia.com/ntr1FkBiO3nk4t4Vgy5GXoPQ_j2hirENH9iT8rXNf8M.png</logo>
7+
<generator uri="http://jekyllrb.com" version="3.1.2">Jekyll</generator>
8+
<link href="http://bakery-store.example.com/" rel="alternate" type="text/html" />
9+
<updated>2016-05-13T16:22:08+12:00</updated>
10+
<id>http://bakery-store.example.com/</id>
11+
<entry>
12+
<title>Where Did The Cookie Come From</title>
13+
<link href="http://bakery-store.example.com/information/2016/01/02/where-did-the-cookie-come-from.html" rel="alternate" type="text/html" title="Where Did The Cookie Come From" />
14+
<link href="https://www.example.com/audio.mp3" rel="enclosure" type="audio/mpeg" length="1234" />
15+
<published>2016-01-02T00:00:00+13:00</published>
16+
<id>http://bakery-store.example.com/information/2016/01/02/where-did-the-cookie-come-from</id>
17+
<icon>https://b.thumbs.redditmedia.com/ntr1FkBiO3nk4t4Vgy5GXoPQ_j2hirENH9iT8rXNf8.png</icon>
18+
<content type="html" xml:base="http://bakery-store.example.com/information/2016/01/02/where-did-the-cookie-come-from.html">&lt;p&gt;The chocolate chip cookie was invented by Ruth Graves Wakefield. She owned the Toll House Inn, in Whitman, Massachusetts, a very popular restaurant that featured home cooking in the 1930s. Her cookbook, Toll House Tried and True Recipes, was first published in 1936 by M. Barrows &amp;amp; Company, New York. The 1938 edition of the cookbook was the first to include the recipe “Toll House Chocolate Crunch Cookie” which rapidly became a favorite cookie in American homes.&lt;/p&gt;
19+
20+
&lt;p&gt;Source / Read more &lt;a href=&quot;https://en.wikipedia.org/wiki/Chocolate_chip_cookie&quot;&gt;Wikipedia&lt;/a&gt;&lt;/p&gt;
21+
</content>
22+
<category term="Information" />
23+
<summary>The chocolate chip cookie was invented by Ruth Graves Wakefield.</summary>
24+
</entry>
25+
<entry>
26+
<title>What Is Sour Dough</title>
27+
<link href="http://bakery-store.example.com/information/2016/01/01/what-is-sour-dough.html" rel="alternate" type="text/html" title="What Is Sour Dough" />
28+
<published>2016-01-01T00:00:00+13:00</published>
29+
<updated>2016-01-01T00:00:00+13:00</updated>
30+
<id>http://bakery-store.example.com/information/2016/01/01/what-is-sour-dough</id>
31+
<content type="html" xml:base="http://bakery-store.example.com/information/2016/01/01/what-is-sour-dough.html">&lt;p&gt;Sourdough bread is made by the fermentation of dough using naturally-occurring lactobacilli and yeast. Sourdough bread has a mildly sour taste not present in most breads made with baker’s yeast and better inherent keeping qualities than other breads, due to the lactic acid produced by the lactobacilli.&lt;/p&gt;
32+
33+
&lt;p&gt;Source / Read more &lt;a href=&quot;https://en.wikipedia.org/wiki/Sourdough&quot;&gt;Wikipedia&lt;/a&gt;&lt;/p&gt;
34+
</content>
35+
<category term="Information" />
36+
<summary>Sourdough bread is made by the fermentation of dough using naturally-occurring lactobacilli and yeast. Sourdough bread has a mildly sour taste not present in most breads made with baker’s yeast and better inherent keeping qualities than other breads, due to the lactic acid produced by the lactobacilli.</summary>
37+
</entry>
38+
</feed>
39+
`;

test/test-parser-atomv1.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var assert = require('assert');
22
var atomv1 = require('./samples/atomv1');
33
var atomv1WithItunes = require('./samples/atomv1-with-itunes');
4+
var atomv1NoUpdated = require('./samples/atomv1-no-updated');
45
var huffpost = require('./samples/huffpost');
56
var rssParser = require('../index');
67

@@ -27,6 +28,7 @@ describe('when parse ATOM', function() {
2728
assert.equal(result.items[0].enclosures[0].length, '1234');
2829
assert.equal(result.items[0].description, 'The chocolate chip cookie was invented by Ruth Graves Wakefield.');
2930
assert.equal(result.items[1].title, 'What Is Sour Dough');
31+
assert.equal(result.items[0].published, '2016-01-02T00:00:00+13:00');
3032
});
3133
});
3234
});
@@ -88,4 +90,13 @@ describe('when parse ATOM', function() {
8890
});
8991
});
9092
});
93+
94+
describe('when item has no updated element', function() {
95+
it('should return published element', function() {
96+
return rssParser.parse(atomv1NoUpdated.feed)
97+
.then((result) => {
98+
assert.equal(result.items[0].published, '2016-01-02T00:00:00+13:00');
99+
});
100+
});
101+
});
91102
});

0 commit comments

Comments
 (0)