Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
SettingDust committed Jan 1, 2019
1 parent f9c0b30 commit 02867a2
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 14 deletions.
4 changes: 2 additions & 2 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ router.get('/bilibili/audio/:id', require('./routes/bilibili/audio'));
router.get('/bangumi/calendar/today', require('./routes/bangumi/calendar/today'));
router.get('/bangumi/subject/:id/:type', require('./routes/bangumi/subject'));
router.get('/bangumi/person/:id', require('./routes/bangumi/person'));
router.get('/bangumi/topic/:id', require('./routes/bangumi/group/reply.js'));
router.get('/bangumi/group/:id', require('./routes/bangumi/group/topic.js'));
router.get('/bangumi/topic/:id', require('./routes/bangumi/group/reply'));
router.get('/bangumi/group/:id', require('./routes/bangumi/group/topic'));
router.get('/bangumi/subject/:id', require('./routes/bangumi/subject'));

// 微博
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/bangumi/group/topic.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = async (ctx) => {
.map((_, elem) => ({
link: resolve_url(base_url, $('.subject a', elem).attr('href')),
title: $('.subject a', elem).attr('title'),
pubDate: DateTime.fromFormat($('.time', elem).text(), 'yyyy-L-dd'),
pubDate: DateTime.fromFormat($('.lastpost .time', elem).text(), 'yyyy-L-dd'),
description: 'Author: ' + $('.author a', elem).text() + '<br>' + 'Replay: ' + $('.posts', elem).text(),
}))
.get(),
Expand Down
16 changes: 9 additions & 7 deletions lib/routes/bangumi/person/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = async (ctx) => {
const $workEl = $el.find('.l');
return {
work: $workEl.text(),
workURL: `https://bgm.tv/${$workEl.attr('href')}`,
workURL: `https://bgm.tv${$workEl.attr('href')}`,
workInfo: $el.find('p.info').text(),
job: $el.find('.badge_job').text(),
};
Expand All @@ -24,11 +24,13 @@ module.exports = async (ctx) => {
ctx.state.data = {
title: `${personName}参与的作品`,
link,
item: works.map((c) => ({
title: `${personName}${c.job}的身份参与了作品《${c.work}》`,
description: c.workInfo,
link: c.workURL,
pubDate: new Date(c.workInfo.subString(0, c.workInfo.indexOf(' /'))),
})),
item: works.map((c) => {
return {
title: `${personName}${c.job}的身份参与了作品《${c.work}》`,
description: c.workInfo,
link: c.workURL,
pubDate: new Date(c.workInfo.substring(0, c.workInfo.indexOf(' /'))).toUTCString(),
};
}),
};
};
2 changes: 1 addition & 1 deletion test/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ describe('response', () => {
it(`GET ${url}`, async () => {
const response = await request.get(url);
await check(response);
});
}, 10e4);
});
});
9 changes: 6 additions & 3 deletions test/rules/rss.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function checkDate(date) {
expect(Date.parse(date)).toEqual(expect.any(Number));
// expect(new Date() - new Date(date)).toBeGreaterThan(0);
// date must be in 1 year
expect(new Date() - new Date(date)).toBeLessThan(1000 * 60 * 60 * 24 * 30 * 12);
// expect(new Date() - new Date(date)).toBeLessThan(1000 * 60 * 60 * 24 * 30 * 12);
}

module.exports = async (response) => {
Expand All @@ -28,9 +28,12 @@ module.exports = async (response) => {
expect(item.title).toEqual(expect.any(String));
expect(item.link).toEqual(expect.any(String));
expect(item.content).toEqual(expect.any(String));
expect(item.pubDate).toEqual(expect.any(String));
expect(item.guid).toEqual(expect.any(String));
checkDate(item.pubDate);
if (item.pubDate) {
console.log(item.pubDate);
expect(item.pubDate).toEqual(expect.any(String));
checkDate(item.pubDate);
}

// guid must be unique
expect(guids).not.toContain(item.guid);
Expand Down

0 comments on commit 02867a2

Please sign in to comment.