mirror of
https://github.com/withastro/astro.git
synced 2025-01-13 22:11:20 -05:00
24663c9695
* fix(rss): make title optional if description is provided * feat(rss): simplify schema * fix(rss): update tests to match new behavior * Update packages/astro-rss/test/pagesGlobToRssItems.test.js Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com> * Update packages/astro-rss/test/pagesGlobToRssItems.test.js Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com> * feat: make link and pubDate optional * feat: improve item normalization * Update shy-spoons-sort.md * Fix test fail * Update .changeset/shy-spoons-sort.md Co-authored-by: Emanuele Stoppa <my.burning@gmail.com> --------- Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com> Co-authored-by: bluwy <bjornlu.dev@gmail.com> Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
119 lines
2.9 KiB
JavaScript
119 lines
2.9 KiB
JavaScript
import chai from 'chai';
|
|
import chaiPromises from 'chai-as-promised';
|
|
import { phpFeedItem, web1FeedItem } from './test-utils.js';
|
|
import { pagesGlobToRssItems } from '../dist/index.js';
|
|
|
|
chai.use(chaiPromises);
|
|
|
|
describe('pagesGlobToRssItems', () => {
|
|
it('should generate on valid result', async () => {
|
|
const globResult = {
|
|
'./posts/php.md': () =>
|
|
new Promise((resolve) =>
|
|
resolve({
|
|
url: phpFeedItem.link,
|
|
frontmatter: {
|
|
title: phpFeedItem.title,
|
|
pubDate: phpFeedItem.pubDate,
|
|
description: phpFeedItem.description,
|
|
},
|
|
})
|
|
),
|
|
'./posts/nested/web1.md': () =>
|
|
new Promise((resolve) =>
|
|
resolve({
|
|
url: web1FeedItem.link,
|
|
frontmatter: {
|
|
title: web1FeedItem.title,
|
|
pubDate: web1FeedItem.pubDate,
|
|
description: web1FeedItem.description,
|
|
},
|
|
})
|
|
),
|
|
};
|
|
|
|
const items = await pagesGlobToRssItems(globResult);
|
|
|
|
chai.expect(items.sort((a, b) => a.pubDate - b.pubDate)).to.deep.equal([
|
|
{
|
|
title: phpFeedItem.title,
|
|
link: phpFeedItem.link,
|
|
pubDate: new Date(phpFeedItem.pubDate),
|
|
description: phpFeedItem.description,
|
|
},
|
|
{
|
|
title: web1FeedItem.title,
|
|
link: web1FeedItem.link,
|
|
pubDate: new Date(web1FeedItem.pubDate),
|
|
description: web1FeedItem.description,
|
|
},
|
|
]);
|
|
});
|
|
|
|
it('should fail on missing "url"', () => {
|
|
const globResult = {
|
|
'./posts/php.md': () =>
|
|
new Promise((resolve) =>
|
|
resolve({
|
|
url: undefined,
|
|
frontmatter: {
|
|
pubDate: phpFeedItem.pubDate,
|
|
description: phpFeedItem.description,
|
|
},
|
|
})
|
|
),
|
|
};
|
|
return chai.expect(pagesGlobToRssItems(globResult)).to.be.rejected;
|
|
});
|
|
|
|
it('should fail on missing "title" key and "description"', () => {
|
|
const globResult = {
|
|
'./posts/php.md': () =>
|
|
new Promise((resolve) =>
|
|
resolve({
|
|
url: phpFeedItem.link,
|
|
frontmatter: {
|
|
title: undefined,
|
|
pubDate: phpFeedItem.pubDate,
|
|
description: undefined,
|
|
},
|
|
})
|
|
),
|
|
};
|
|
return chai.expect(pagesGlobToRssItems(globResult)).to.be.rejected;
|
|
});
|
|
|
|
it('should not fail on missing "title" key if "description" is present', () => {
|
|
const globResult = {
|
|
'./posts/php.md': () =>
|
|
new Promise((resolve) =>
|
|
resolve({
|
|
url: phpFeedItem.link,
|
|
frontmatter: {
|
|
title: undefined,
|
|
pubDate: phpFeedItem.pubDate,
|
|
description: phpFeedItem.description,
|
|
},
|
|
})
|
|
),
|
|
};
|
|
return chai.expect(pagesGlobToRssItems(globResult)).to.not.be.rejected;
|
|
});
|
|
|
|
it('should fail on missing "description" key if "title" is present', () => {
|
|
const globResult = {
|
|
'./posts/php.md': () =>
|
|
new Promise((resolve) =>
|
|
resolve({
|
|
url: phpFeedItem.link,
|
|
frontmatter: {
|
|
title: phpFeedItem.title,
|
|
pubDate: phpFeedItem.pubDate,
|
|
description: undefined,
|
|
},
|
|
})
|
|
),
|
|
};
|
|
return chai.expect(pagesGlobToRssItems(globResult)).to.not.be.rejected;
|
|
});
|
|
});
|