test: filter and filterout combination cases
This commit is contained in:
parent
8881b5953d
commit
923b07eec4
|
|
@ -136,7 +136,7 @@ module.exports = async (ctx, next) => {
|
|||
const description = item.description || title;
|
||||
const author = item.author || '';
|
||||
const isFilter = title.match(makeRegex(ctx.query.filter)) || description.match(makeRegex(ctx.query.filter)) || author.match(makeRegex(ctx.query.filter));
|
||||
return isFilter !== null;
|
||||
return isFilter;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -150,7 +150,7 @@ module.exports = async (ctx, next) => {
|
|||
ctx.query.filter_title && (isFilter = isFilter && title.match(makeRegex(ctx.query.filter_title)));
|
||||
ctx.query.filter_description && (isFilter = isFilter && description.match(makeRegex(ctx.query.filter_description)));
|
||||
ctx.query.filter_author && (isFilter = isFilter && author.match(makeRegex(ctx.query.filter_author)));
|
||||
return isFilter !== null;
|
||||
return isFilter;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,24 @@ module.exports = async (ctx) => {
|
|||
});
|
||||
}
|
||||
let item = [];
|
||||
if (ctx.params.id === 'long') {
|
||||
if (ctx.params.id === 'filter') {
|
||||
item = [
|
||||
{
|
||||
title: 'Filter Title1',
|
||||
description: 'Description1',
|
||||
pubDate: new Date(`2019-3-1`).toUTCString(),
|
||||
link: `https://github.com/DIYgod/RSSHub/issues/-1`,
|
||||
author: `DIYgod0`,
|
||||
},
|
||||
{
|
||||
title: 'Filter Title2',
|
||||
description: 'Description2',
|
||||
pubDate: new Date(`2019-3-1`).toUTCString(),
|
||||
link: `https://github.com/DIYgod/RSSHub/issues/0`,
|
||||
author: `DIYgod0`,
|
||||
},
|
||||
];
|
||||
} else if (ctx.params.id === 'long') {
|
||||
item.push({
|
||||
title: `Long Title `.repeat(50),
|
||||
description: `Long Description `.repeat(10),
|
||||
|
|
|
|||
|
|
@ -184,6 +184,20 @@ describe('filter', () => {
|
|||
expect(parsed.items[1].title).toBe('Title2');
|
||||
expect(parsed.items[2].title).toBe('Title3');
|
||||
});
|
||||
|
||||
it(`filter combination`, async () => {
|
||||
const response = await request.get('/test/filter?filter_title=Filter&filter_description=Description1');
|
||||
const parsed = await parser.parseString(response.text);
|
||||
expect(parsed.items.length).toBe(1);
|
||||
expect(parsed.items[0].title).toBe('Filter Title1');
|
||||
});
|
||||
|
||||
it(`filterout combination`, async () => {
|
||||
const response = await request.get('/test/filter?filterout_title=Filter&filterout_description=Description1');
|
||||
const parsed = await parser.parseString(response.text);
|
||||
expect(parsed.items.length).toBe(4);
|
||||
expect(parsed.items[0].title).toBe('Title2');
|
||||
});
|
||||
});
|
||||
|
||||
describe('limit', () => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue