Release 0.5.1
This commit is contained in:
1 parent
5a9d7735d4
commit
fb24d171ae
36 files changed
+5099
-263
No files matched your search
@@ -0,0 +1,61 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import {
|
||||
buildEmbedUrl,
|
||||
detectVideoProvider,
|
||||
extractMetadataFromHtml,
|
||||
fetchPresentationMetadata
|
||||
} from './presentation.js';
|
||||
|
||||
describe('presentation metadata and providers', () => {
|
||||
it('recognizes supported YouTube URL forms and creates privacy-enhanced embeds with start time', () => {
|
||||
for (const url of [
|
||||
'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
|
||||
'https://youtu.be/dQw4w9WgXcQ',
|
||||
'https://www.youtube.com/shorts/dQw4w9WgXcQ',
|
||||
'https://youtube.com/live/dQw4w9WgXcQ'
|
||||
]) {
|
||||
expect(detectVideoProvider(url)).toEqual({ provider: 'youtube', id: 'dQw4w9WgXcQ' });
|
||||
}
|
||||
expect(buildEmbedUrl('youtube', 'dQw4w9WgXcQ', 75)).toBe(
|
||||
'https://www.youtube-nocookie.com/embed/dQw4w9WgXcQ?start=75'
|
||||
);
|
||||
expect(detectVideoProvider('https://evil.example/watch?v=dQw4w9WgXcQ')).toBeNull();
|
||||
expect(detectVideoProvider('https://youtube.com/watch?v=invalid')).toBeNull();
|
||||
});
|
||||
|
||||
it('recognizes canonical TikTok videos without inventing a start parameter', () => {
|
||||
expect(
|
||||
detectVideoProvider('https://www.tiktok.com/@scout2015/video/6718335390845095173')
|
||||
).toEqual({ provider: 'tiktok', id: '6718335390845095173' });
|
||||
expect(buildEmbedUrl('tiktok', '6718335390845095173', 90)).toBe(
|
||||
'https://www.tiktok.com/player/v1/6718335390845095173?autoplay=0&controls=1'
|
||||
);
|
||||
});
|
||||
|
||||
it('extracts generic metadata from local HTML and tolerates a missing image', async () => {
|
||||
const metadata = await extractMetadataFromHtml(
|
||||
`<!doctype html><html><head>
|
||||
<meta property="og:title" content="Lokale Vorschau">
|
||||
<meta property="og:description" content="Ein kurzer Anreißer">
|
||||
<meta property="og:site_name" content="Testseite">
|
||||
</head></html>`,
|
||||
'https://example.com/artikel'
|
||||
);
|
||||
expect(metadata).toMatchObject({
|
||||
title: 'Lokale Vorschau',
|
||||
description: 'Ein kurzer Anreißer',
|
||||
imageUrl: '',
|
||||
siteName: 'Testseite'
|
||||
});
|
||||
});
|
||||
|
||||
it('rejects malformed and private metadata targets before a network request', async () => {
|
||||
await expect(fetchPresentationMetadata('keine-url')).rejects.toThrow('FETCH_INVALID_URL');
|
||||
await expect(fetchPresentationMetadata('http://127.0.0.1/private')).rejects.toThrow(
|
||||
'FETCH_BLOCKED'
|
||||
);
|
||||
await expect(fetchPresentationMetadata('http://[::1]/private')).rejects.toThrow(
|
||||
'FETCH_BLOCKED'
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user