Add note.test.ts

This commit is contained in:
Alex Gleason 2024-05-18 11:56:22 -05:00
parent 942260aa54
commit c8f9483795
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
2 changed files with 29 additions and 1 deletions

28
src/utils/note.test.ts Normal file
View File

@ -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',
},
},
]);
});

View File

@ -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;