test: add template enclosure test cases

This commit is contained in:
DIYgod
2019-08-23 15:44:52 +08:00
parent 9a03bd4fe9
commit 745eb0d52a
4 changed files with 24 additions and 2 deletions

View File

@@ -45,7 +45,8 @@ module.exports = async (ctx, next) => {
} }
if (item.enclosure_length) { if (item.enclosure_length) {
const itunes_duration = Math.floor(item.enclosure_length / 3600) + ':' + Math.floor((item.enclosure_length % 3600) / 60) + ':' + (((item.enclosure_length % 3600) % 60) / 100).toFixed(2).slice(-2); const itunes_duration =
Math.floor(item.enclosure_length / 3600) + ':' + (Math.floor((item.enclosure_length % 3600) / 60) / 100).toFixed(2).slice(-2) + ':' + (((item.enclosure_length % 3600) % 60) / 100).toFixed(2).slice(-2);
item.itunes_duration = itunes_duration; item.itunes_duration = itunes_duration;
} }
}); });

View File

@@ -49,6 +49,17 @@ module.exports = async (ctx) => {
item = null; item = null;
} }
if (ctx.params.id === 'enclosure') {
item = [
{
title: '',
link: 'https://github.com/DIYgod/RSSHub/issues/1',
enclosure_url: 'https://github.com/DIYgod/RSSHub/issues/1',
enclosure_length: 3661,
},
];
}
if (ctx.query.mode === 'fulltext') { if (ctx.query.mode === 'fulltext') {
item = [ item = [
{ {
@@ -60,6 +71,7 @@ module.exports = async (ctx) => {
ctx.state.data = { ctx.state.data = {
title: `Test ${ctx.params.id}`, title: `Test ${ctx.params.id}`,
itunes_author: ctx.params.id === 'enclosure' ? 'DIYgod' : null,
link: 'https://github.com/DIYgod/RSSHub', link: 'https://github.com/DIYgod/RSSHub',
item, item,
allowEmpty: ctx.params.id === 'allow_empty', allowEmpty: ctx.params.id === 'allow_empty',

View File

@@ -32,7 +32,7 @@
<link>{{ $value.link }}</link> <link>{{ $value.link }}</link>
{{ if $value.itunes_item_image }}<itunes:image href="{{ $value.itunes_item_image }}"/>{{ /if }} {{ if $value.itunes_item_image }}<itunes:image href="{{ $value.itunes_item_image }}"/>{{ /if }}
{{ if $value.enclosure_url }}<enclosure url="{{ $value.enclosure_url }}" {{ if $value.enclosure_length }}length="{{ $value.enclosure_length }}"{{ /if }} {{ if $value.enclosure_type }}type="{{ $value.enclosure_type }}"{{ /if }} />{{ /if }} {{ if $value.enclosure_url }}<enclosure url="{{ $value.enclosure_url }}" {{ if $value.enclosure_length }}length="{{ $value.enclosure_length }}"{{ /if }} {{ if $value.enclosure_type }}type="{{ $value.enclosure_type }}"{{ /if }} />{{ /if }}
{{ if $value.itunes_duration }}<itunes:duration>{{ $value.itunes_duration }}</itunes:duration> {{ /if }} {{ if itunes_author && $value.itunes_duration }}<itunes:duration>{{ $value.itunes_duration }}</itunes:duration> {{ /if }}
{{ if $value.author }}<author><![CDATA[{{ $value.author }}]]></author>{{ /if }} {{ if $value.author }}<author><![CDATA[{{ $value.author }}]]></author>{{ /if }}
{{ if typeof $value.category === 'string' }} {{ if typeof $value.category === 'string' }}
<category>{{ $value.category }}</category> <category>{{ $value.category }}</category>

View File

@@ -68,4 +68,13 @@ describe('template', () => {
const parsed = await parser.parseString(response.text); const parsed = await parser.parseString(response.text);
expect(parsed.items[0].title.length).toBe(103); expect(parsed.items[0].title.length).toBe(103);
}); });
it(`enclosure`, async () => {
const response = await request.get('/test/enclosure');
const parsed = await parser.parseString(response.text);
expect(parsed.itunes.author).toBe('DIYgod');
expect(parsed.items[0].enclosure.url).toBe('https://github.com/DIYgod/RSSHub/issues/1');
expect(parsed.items[0].enclosure.length).toBe('3661');
expect(parsed.items[0].itunes.duration).toBe('1:01:01');
});
}); });