|
| 1 | +import { describe, it } from 'node:test'; |
| 2 | +import assert from 'node:assert'; |
| 3 | +import { parse } from '../index.js'; |
| 4 | + |
| 5 | +describe('syndication', () => { |
| 6 | + it('should parse syndication updatePeriod', () => { |
| 7 | + const xml = `<?xml version="1.0"?> |
| 8 | + <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" |
| 9 | + xmlns="http://purl.org/rss/1.0/" |
| 10 | + xmlns:syn="http://purl.org/rss/1.0/modules/syndication/"> |
| 11 | + <channel> |
| 12 | + <title>Test Feed</title> |
| 13 | + <link>https://example.com</link> |
| 14 | + <syn:updatePeriod>daily</syn:updatePeriod> |
| 15 | + </channel> |
| 16 | + </rdf:RDF>`; |
| 17 | + |
| 18 | + const feed = parse(xml); |
| 19 | + assert.ok(feed.feed.syndication); |
| 20 | + assert.strictEqual(feed.feed.syndication.updatePeriod, 'daily'); |
| 21 | + }); |
| 22 | + |
| 23 | + it('should parse syndication updateFrequency', () => { |
| 24 | + const xml = `<?xml version="1.0"?> |
| 25 | + <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" |
| 26 | + xmlns="http://purl.org/rss/1.0/" |
| 27 | + xmlns:syn="http://purl.org/rss/1.0/modules/syndication/"> |
| 28 | + <channel> |
| 29 | + <title>Test Feed</title> |
| 30 | + <link>https://example.com</link> |
| 31 | + <syn:updateFrequency>2</syn:updateFrequency> |
| 32 | + </channel> |
| 33 | + </rdf:RDF>`; |
| 34 | + |
| 35 | + const feed = parse(xml); |
| 36 | + assert.ok(feed.feed.syndication); |
| 37 | + assert.strictEqual(feed.feed.syndication.updateFrequency, 2); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should parse complete syndication metadata', () => { |
| 41 | + const xml = `<?xml version="1.0"?> |
| 42 | + <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" |
| 43 | + xmlns="http://purl.org/rss/1.0/" |
| 44 | + xmlns:syn="http://purl.org/rss/1.0/modules/syndication/"> |
| 45 | + <channel> |
| 46 | + <title>Test Feed</title> |
| 47 | + <link>https://example.com</link> |
| 48 | + <syn:updatePeriod>hourly</syn:updatePeriod> |
| 49 | + <syn:updateFrequency>1</syn:updateFrequency> |
| 50 | + <syn:updateBase>2024-01-01T00:00:00Z</syn:updateBase> |
| 51 | + </channel> |
| 52 | + </rdf:RDF>`; |
| 53 | + |
| 54 | + const feed = parse(xml); |
| 55 | + const syn = feed.feed.syndication; |
| 56 | + assert.ok(syn); |
| 57 | + assert.strictEqual(syn.updatePeriod, 'hourly'); |
| 58 | + assert.strictEqual(syn.updateFrequency, 1); |
| 59 | + assert.strictEqual(syn.updateBase, '2024-01-01T00:00:00Z'); |
| 60 | + }); |
| 61 | + |
| 62 | + it('should return undefined when syndication data is missing', () => { |
| 63 | + const xml = `<?xml version="1.0"?> |
| 64 | + <rss version="2.0"> |
| 65 | + <channel> |
| 66 | + <title>Test Feed</title> |
| 67 | + <link>https://example.com</link> |
| 68 | + </channel> |
| 69 | + </rss>`; |
| 70 | + |
| 71 | + const feed = parse(xml); |
| 72 | + assert.strictEqual(feed.feed.syndication, undefined); |
| 73 | + }); |
| 74 | + |
| 75 | + it('should parse Dublin Core fields', () => { |
| 76 | + const xml = `<?xml version="1.0"?> |
| 77 | + <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" |
| 78 | + xmlns="http://purl.org/rss/1.0/" |
| 79 | + xmlns:dc="http://purl.org/dc/elements/1.1/"> |
| 80 | + <channel rdf:about="https://example.com"> |
| 81 | + <title>Test Feed</title> |
| 82 | + <link>https://example.com</link> |
| 83 | + <dc:creator>John Doe</dc:creator> |
| 84 | + <dc:publisher>ACME Corp</dc:publisher> |
| 85 | + <dc:rights>Copyright 2024</dc:rights> |
| 86 | + </channel> |
| 87 | + </rdf:RDF>`; |
| 88 | + |
| 89 | + const feed = parse(xml); |
| 90 | + assert.strictEqual(feed.feed.dcCreator, 'John Doe'); |
| 91 | + assert.strictEqual(feed.feed.dcPublisher, 'ACME Corp'); |
| 92 | + assert.strictEqual(feed.feed.dcRights, 'Copyright 2024'); |
| 93 | + }); |
| 94 | +}); |
0 commit comments