mirror of
https://github.com/layer-systems/website.git
synced 2026-09-12 05:33:12 +02:00
* Initial plan * Add Images app for picture posts Co-authored-by: mroxso <24775431+mroxso@users.noreply.github.com> * Add Images detail navigation Co-authored-by: mroxso <24775431+mroxso@users.noreply.github.com> * Address Images review feedback Co-authored-by: mroxso <24775431+mroxso@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: mroxso <24775431+mroxso@users.noreply.github.com>
24 lines
1.1 KiB
TypeScript
24 lines
1.1 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import type { NostrEvent } from '@nostrify/nostrify';
|
|
import { isPicturePost, pictureTags, pictureUrl } from './picturePosts';
|
|
|
|
function event(kind: number, tags: string[][]): NostrEvent {
|
|
return { id: 'id', pubkey: 'author', created_at: 0, kind, tags, content: '', sig: '' };
|
|
}
|
|
|
|
describe('picture posts', () => {
|
|
it('accepts a Kind 20 post with a safe NIP-68 image URL', () => {
|
|
const post = event(20, [['imeta', 'url https://images.example/picture.jpg'], ['t', 'sunset']]);
|
|
expect(pictureUrl(post)).toBe('https://images.example/picture.jpg');
|
|
expect(isPicturePost(post)).toBe(true);
|
|
expect(pictureTags(post)).toEqual(['sunset']);
|
|
});
|
|
|
|
it('rejects non-picture kinds and unsafe image URLs', () => {
|
|
expect(isPicturePost(event(1, [['imeta', 'url https://images.example/picture.jpg']]))).toBe(false);
|
|
expect(isPicturePost(event(20, [['imeta', 'url javascript:alert(1)']]))).toBe(false);
|
|
expect(isPicturePost(event(20, [['imeta', 'url mailto:image@example.com']]))).toBe(false);
|
|
expect(isPicturePost(event(20, [['imeta', 'url /picture.jpg']]))).toBe(false);
|
|
});
|
|
});
|