A downstream fork of Tranquil PDS for use in margin.cafe margin.cafe
Something went wrong. Try again.
12345678910111213141516171819202122232425import { describe, expect, it, vi } from 'vitest'import { imageBlobUrl, readActorProfile } from '../../public/actor-profile.js'
describe('public actor profiles', () => { it('loads the profile without credentials and serves avatar blobs from the local PDS', async () => { const fetcher = vi.fn<typeof fetch>(async () => new Response(JSON.stringify({ value: { displayName: 'Alex', avatar: { ref: { $link: 'bafyexample' }, mimeType: 'image/jpeg' }, } }))) const profile = await readActorProfile('did:plc:alex', fetcher) expect(profile.displayName).toBe('Alex') expect(profile.avatarUrl).toBe('/xrpc/com.atproto.sync.getBlob?did=did%3Aplc%3Aalex&cid=bafyexample') expect(fetcher.mock.calls[0]?.[0]).toContain('collection=app.bsky.actor.profile&rkey=self') expect(fetcher.mock.calls[0]?.[1]).toMatchObject({ credentials: 'omit' }) }) it('keeps the account usable when profiles are absent or unavailable', async () => { expect(await readActorProfile('did:plc:missing', vi.fn(async () => new Response('', { status: 404 })))).toEqual({}) expect(await readActorProfile('did:plc:missing', vi.fn().mockRejectedValue(new Error('offline')))).toEqual({}) }) it('rejects non-image blobs and external avatar URLs', () => { expect(imageBlobUrl('did:plc:alex', { ref: { $link: 'bafyexample' }, mimeType: 'text/html' })).toBeNull() expect(imageBlobUrl('did:plc:alex', 'https://untrusted.example/avatar')).toBeNull() expect(imageBlobUrl('did:plc:alex', { cid: '../invalid', mimeType: 'image/png' })).toBeNull() })})