import { describe, expect, it } from 'vitest' import { didFromAtUri, isOwnThread } from './gate' const AUTHOR = 'did:plc:nlzmjyfv6loqtxyzvdcznwgf' const OTHER = 'did:plc:ewvi7nxzyoun6zhxrhs64oiz' const THREAD = `at://${AUTHOR}/app.bsky.feed.post/3mvohsymmis2b` describe('didFromAtUri', () => { it('reads the authority of an at-uri', () => { expect(didFromAtUri(THREAD)).toBe(AUTHOR) }) it('rejects a non-at-uri or a handle authority', () => { expect(didFromAtUri('https://bsky.app/profile/alice.bsky.social')).toBeUndefined() expect(didFromAtUri('at://alice.bsky.social/app.bsky.feed.post/abc')).toBeUndefined() }) }) describe('isOwnThread', () => { it('allows the author and refuses another account', () => { expect(isOwnThread(THREAD, AUTHOR)).toBe(true) expect(isOwnThread(THREAD, OTHER)).toBe(false) }) it('refuses an empty session or a malformed uri', () => { expect(isOwnThread(THREAD, '')).toBe(false) expect(isOwnThread('not-an-at-uri', AUTHOR)).toBe(false) }) })