Add note.test.ts
This commit is contained in:
parent
942260aa54
commit
c8f9483795
|
@ -0,0 +1,28 @@
|
|||
import { assertEquals } from '@std/assert';
|
||||
|
||||
import { getMediaLinks, parseNoteContent } from '@/utils/note.ts';
|
||||
|
||||
Deno.test('parseNoteContent', () => {
|
||||
const { html, links, firstUrl } = parseNoteContent('Hello, world!');
|
||||
assertEquals(html, 'Hello, world!');
|
||||
assertEquals(links, []);
|
||||
assertEquals(firstUrl, undefined);
|
||||
});
|
||||
|
||||
Deno.test('getMediaLinks', () => {
|
||||
const links = [
|
||||
{ href: 'https://example.com/image.png' },
|
||||
{ href: 'https://example.com/index.html' },
|
||||
{ href: 'https://example.com/yolo' },
|
||||
{ href: 'https://example.com/' },
|
||||
];
|
||||
const mediaLinks = getMediaLinks(links);
|
||||
assertEquals(mediaLinks, [
|
||||
{
|
||||
url: 'https://example.com/image.png',
|
||||
data: {
|
||||
mime: 'image/png',
|
||||
},
|
||||
},
|
||||
]);
|
||||
});
|
|
@ -58,7 +58,7 @@ function parseNoteContent(content: string): ParsedNoteContent {
|
|||
};
|
||||
}
|
||||
|
||||
function getMediaLinks(links: Link[]): DittoAttachment[] {
|
||||
function getMediaLinks(links: Pick<Link, 'href'>[]): DittoAttachment[] {
|
||||
return links.reduce<DittoAttachment[]>((acc, link) => {
|
||||
const mediaType = getUrlMediaType(link.href);
|
||||
if (!mediaType) return acc;
|
||||
|
|
Loading…
Reference in New Issue