Skip to content

Commit

Permalink
fewgfew
Browse files Browse the repository at this point in the history
  • Loading branch information
vishvamsinh28 committed Nov 1, 2024
1 parent 5407af0 commit fb49686
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 11 deletions.
29 changes: 29 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"clsx": "^2.1.0",
"cssnano": "^6.0.3",
"dotenv": "^16.4.4",
"fast-xml-parser": "^4.5.0",
"fs-extra": "^11.2.0",
"fuse.js": "^7.0.0",
"googleapis": "^133.0.0",
Expand Down
2 changes: 1 addition & 1 deletion scripts/build-rss.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ module.exports = async function rssFeed(type, title, desc, outputPath) {
);

if (invalidPosts.length > 0) {
throw new Error('Missing required fields in post data');
throw new Error(`Missing required fields in posts: ${invalidPosts.map(p => p.title || p.slug).join(', ')}`);
}

for (let post of posts) {
Expand Down
24 changes: 14 additions & 10 deletions tests/build-rss.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const fs = require('fs');
const path = require('path');
const rssFeed = require('../scripts/build-rss');
const { XMLParser } = require('fast-xml-parser');
const parser = new XMLParser({ ignoreAttributes: false });
const { mockRssData, title, type, desc, missingDateMockData, incompletePostMockData } = require('./fixtures/rssData');

describe('rssFeed', () => {
Expand Down Expand Up @@ -49,11 +51,12 @@ describe('rssFeed', () => {
const filePath = path.join(__dirname, '..', 'public', outputPath);
const fileContent = fs.readFileSync(filePath, 'utf8');

const itemTitles = fileContent.match(/<title>(.*?)<\/title>/g);
const parsedContent = parser.parse(fileContent);
const itemTitles = parsedContent.rss.channel.item.map(item => item.title);

expect(itemTitles[1]).toContain('Test Post 1');
expect(itemTitles[2]).toContain('Another Featured Post');
expect(itemTitles[3]).toContain('Non-Featured Post 1');
expect(itemTitles[0]).toContain('Test Post 1');
expect(itemTitles[1]).toContain('Another Featured Post');
expect(itemTitles[2]).toContain('Non-Featured Post 1');
});

it('should sort posts by date in descending order', async () => {
Expand All @@ -64,13 +67,14 @@ describe('rssFeed', () => {
const filePath = path.join(__dirname, '..', 'public', outputPath);
const fileContent = fs.readFileSync(filePath, 'utf8');

const itemTitles = fileContent.match(/<title>(.*?)<\/title>/g);
const parsedContent = parser.parse(fileContent);
const itemTitles = parsedContent.rss.channel.item.map(item => item.title);

expect(itemTitles[1]).toContain('Test Post 1');
expect(itemTitles[2]).toContain('Another Featured Post');
expect(itemTitles[3]).toContain('Non-Featured Post 1');
expect(itemTitles[4]).toContain('Non-Featured Post 3');
expect(itemTitles[5]).toContain('Non-Featured Post 2');
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');
});

it('should set correct enclosure type based on image extension', async () => {
Expand Down

0 comments on commit fb49686

Please sign in to comment.