Something went wrong. Try again.
Bluesky app fork with some witchin' additions 💫
Something went wrong. Try again.
1.8 kB · 53 lines
TypeScript
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354import {resolveThemeReference} from './themeReference'import {THEME_COLLECTION} from './types'
const did = 'did:plc:themeauthor'const uri = `at://${did}/${THEME_COLLECTION}/testtheme`
it('converts a shared theme link and resolves its handle', async () => { const resolve = jest.fn().mockResolvedValue(did) await expect( resolveThemeReference( ' https://witchsky.app/profile/example.com/theme/testtheme?shared=1 ', resolve, ), ).resolves.toBe(uri) expect(resolve).toHaveBeenCalledWith('example.com')})
it('keeps DID-based AT URIs without resolving a handle', async () => { const resolve = jest.fn() await expect(resolveThemeReference(uri, resolve)).resolves.toBe(uri) expect(resolve).not.toHaveBeenCalled()})
it('resolves handles in AT URIs as well as links', async () => { await expect( resolveThemeReference( `at://example.com/${THEME_COLLECTION}/testtheme`, jest.fn().mockResolvedValue(did), ), ).resolves.toBe(uri)})
it('allows clearing the optional pair', async () => { await expect(resolveThemeReference(' ', jest.fn())).resolves.toBeUndefined()})
it.each([ 'https://witchsky.app/profile/example.com/post/testtheme', `at://${did}/app.bsky.feed.post/testtheme`, `at://${did}/${THEME_COLLECTION}`, 'not a theme',])('rejects invalid theme references: %s', async input => { await expect(resolveThemeReference(input, jest.fn())).rejects.toThrow()})
it('propagates handle resolution failures instead of saving a broken pair', async () => { await expect( resolveThemeReference( 'https://witchsky.app/profile/example.com/theme/testtheme', jest.fn().mockRejectedValue(new Error('Handle not found')), ), ).rejects.toThrow('Handle not found')})