A calm place to write long-form, and publish it to the open social web. skypress.blog/
0

Configure Feed

Select the types of activity you want to include in your feed.

at trunk 2.0 kB View raw
1import { describe, expect, it } from 'vitest'; 2import { detectEmbed } from './registry'; 3 4describe( 'detectEmbed', () => { 5 it( 'recognises a bsky.app post URL', () => { 6 expect( detectEmbed( 'https://bsky.app/profile/jeremy.herve.bzh/post/3momrv24o4wlj' ) ).toEqual( 7 { kind: 'atproto', id: 'jeremy.herve.bzh/3momrv24o4wlj' } 8 ); 9 } ); 10 11 it( 'recognises a mu.social post URL', () => { 12 expect( detectEmbed( 'https://mu.social/profile/renderg.host/post/3mokzwgfyck2e' ) ).toEqual( 13 { kind: 'atproto', id: 'renderg.host/3mokzwgfyck2e' } 14 ); 15 } ); 16 17 it( 'recognises a DID-based post URL', () => { 18 expect( detectEmbed( 'https://bsky.app/profile/did:plc:abc123/post/xyz' ) ).toEqual( 19 { kind: 'atproto', id: 'did:plc:abc123/xyz' } 20 ); 21 } ); 22 23 it( 'recognises a raw at:// post URI', () => { 24 expect( detectEmbed( 'at://did:plc:abc123/app.bsky.feed.post/xyz' ) ).toEqual( 25 { kind: 'atproto', id: 'did:plc:abc123/xyz' } 26 ); 27 } ); 28 29 it( 'recognises youtube watch + youtu.be + nocookie URLs', () => { 30 expect( detectEmbed( 'https://www.youtube.com/watch?v=dQw4w9WgXcQ' ) ).toEqual( { kind: 'youtube', id: 'dQw4w9WgXcQ' } ); 31 expect( detectEmbed( 'https://youtu.be/dQw4w9WgXcQ' ) ).toEqual( { kind: 'youtube', id: 'dQw4w9WgXcQ' } ); 32 } ); 33 34 it( 'recognises a vimeo URL', () => { 35 expect( detectEmbed( 'https://vimeo.com/123456789' ) ).toEqual( { kind: 'vimeo', id: '123456789' } ); 36 } ); 37 38 it( 'does NOT match look-alike hosts (dot-boundary safety)', () => { 39 expect( detectEmbed( 'https://notbsky.app/profile/a/post/b' ) ).toBeNull(); 40 expect( detectEmbed( 'https://bsky.app.evil.com/profile/a/post/b' ) ).toBeNull(); 41 expect( detectEmbed( 'https://evil-youtube.com/watch?v=x' ) ).toBeNull(); 42 } ); 43 44 it( 'returns null for unrelated or malformed URLs', () => { 45 expect( detectEmbed( 'https://example.com/article' ) ).toBeNull(); 46 expect( detectEmbed( 'not a url' ) ).toBeNull(); 47 expect( detectEmbed( 'https://bsky.app/profile/alice.bsky.social' ) ).toBeNull(); // profile, not a post 48 } ); 49} );