mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-05 12:21:31 +08:00
test: add template enclosure test cases
This commit is contained in:
@@ -45,7 +45,8 @@ module.exports = async (ctx, next) => {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -49,6 +49,17 @@ module.exports = async (ctx) => {
|
||||
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') {
|
||||
item = [
|
||||
{
|
||||
@@ -60,6 +71,7 @@ module.exports = async (ctx) => {
|
||||
|
||||
ctx.state.data = {
|
||||
title: `Test ${ctx.params.id}`,
|
||||
itunes_author: ctx.params.id === 'enclosure' ? 'DIYgod' : null,
|
||||
link: 'https://github.com/DIYgod/RSSHub',
|
||||
item,
|
||||
allowEmpty: ctx.params.id === 'allow_empty',
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
<link>{{ $value.link }}</link>
|
||||
{{ 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.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 typeof $value.category === 'string' }}
|
||||
<category>{{ $value.category }}</category>
|
||||
|
||||
@@ -68,4 +68,13 @@ describe('template', () => {
|
||||
const parsed = await parser.parseString(response.text);
|
||||
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');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user