diff --git a/tests/build-rss.test.js b/tests/build-rss.test.js index 8468bf3365a4..67e042252f00 100644 --- a/tests/build-rss.test.js +++ b/tests/build-rss.test.js @@ -44,37 +44,41 @@ describe('rssFeed', () => { it('should prioritize featured posts over non-featured ones', async () => { jest.doMock('../config/posts.json', () => mockRssData, { virtual: true }); - - await expect(rssFeed(type, title, desc, outputPath)).resolves.toBeUndefined() - - + + await expect(rssFeed(type, title, desc, outputPath)).resolves.toBeUndefined(); + const filePath = path.join(__dirname, '..', 'public', outputPath); const fileContent = fs.readFileSync(filePath, 'utf8'); - + const parsedContent = parser.parse(fileContent); const itemTitles = parsedContent.rss.channel.item.map(item => item.title); - - expect(itemTitles[0]).toContain('Test Post 1'); - expect(itemTitles[1]).toContain('Another Featured Post'); - expect(itemTitles[2]).toContain('Non-Featured Post 1'); + + expect(itemTitles[0]).toBe('Test Post 1'); + expect(itemTitles[1]).toBe('Another Featured Post'); + + expect(itemTitles[2]).toBe('Post with Special Characters: & < > "'); + expect(itemTitles[3]).toBe('Post with UTC Date Format'); + expect(itemTitles[4]).toBe('Non-Featured Post 1'); + expect(itemTitles[5]).toBe('Non-Featured Post 3'); }); - + it('should sort posts by date in descending order', async () => { jest.doMock('../config/posts.json', () => mockRssData, { virtual: true }); - - await expect(rssFeed(type, title, desc, outputPath)).resolves.toBeUndefined() - + + await expect(rssFeed(type, title, desc, outputPath)).resolves.toBeUndefined(); + const filePath = path.join(__dirname, '..', 'public', outputPath); const fileContent = fs.readFileSync(filePath, 'utf8'); - + const parsedContent = parser.parse(fileContent); const itemTitles = parsedContent.rss.channel.item.map(item => item.title); - - expect(itemTitles[0]).toContain('Test Post 1'); - expect(itemTitles[1]).toContain('Another Featured Post'); - expect(itemTitles[2]).toContain('Non-Featured Post 1'); - expect(itemTitles[3]).toContain('Non-Featured Post 3'); - expect(itemTitles[4]).toContain('Non-Featured Post 2'); + + expect(itemTitles[0]).toBe('Test Post 1'); + expect(itemTitles[1]).toBe('Another Featured Post') + expect(itemTitles[2]).toBe('Post with Special Characters: & < > "'); + expect(itemTitles[3]).toBe('Post with UTC Date Format'); + expect(itemTitles[4]).toBe('Non-Featured Post 1'); + expect(itemTitles[5]).toBe('Non-Featured Post 3'); }); it('should set correct enclosure type based on image extension', async () => { diff --git a/tests/fixtures/rssData.js b/tests/fixtures/rssData.js index 1c49f4430685..89717784e51b 100644 --- a/tests/fixtures/rssData.js +++ b/tests/fixtures/rssData.js @@ -4,14 +4,14 @@ const mockRssData = { title: 'Non-Featured Post 1', slug: '/blog/non-featured-post-1', excerpt: 'This is a non-featured post', - date: '2024-07-05', + date: '2023-07-05', featured: false, }, { title: 'Test Post 1', slug: '/blog/test-post-1', excerpt: 'This is a featured test post', - date: '2024-07-07', + date: '2023-07-07', featured: true, cover: '/img/test-cover.jpg', }, @@ -19,7 +19,7 @@ const mockRssData = { title: 'Another Featured Post', slug: '/blog/another-featured-post', excerpt: 'This is another featured post', - date: '2024-07-06', + date: '2023-07-06', featured: true, cover: '/img/test-cover.svg', }, @@ -27,7 +27,7 @@ const mockRssData = { title: 'Non-Featured Post 2', slug: '/blog/non-featured-post-2', excerpt: 'This is another non-featured post', - date: '2024-07-03', + date: '2023-07-03', featured: false, cover: '/img/test-cover.webp', }, @@ -35,10 +35,24 @@ const mockRssData = { title: 'Non-Featured Post 3', slug: '/blog/non-featured-post-3', excerpt: 'This is yet another non-featured post', - date: '2024-07-04', + date: '2023-07-04', featured: false, cover: '/img/test-cover.png', }, + { + title: 'Post with Special Characters: & < > "', + slug: '/blog/special-chars', + excerpt: 'Testing HTML entities & encoding', + date: '2023-07-06T12:00:00Z', + featured: false, + }, + { + title: 'Post with UTC Date Format', + slug: '/blog/utc-date-format', + excerpt: 'This post uses a UTC date format', + date: 'Wed, 05 Jul 2023 12:00:00 GMT', + featured: false, + }, ], };