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.1 kB View raw
1import { describe, expect, it, vi, beforeEach } from 'vitest'; 2import { fetchActorProfile } from './profile'; 3import { getRecord } from './records'; 4 5vi.mock( './records', () => ( { getRecord: vi.fn() } ) ); 6 7const mockedGetRecord = getRecord as unknown as ReturnType< typeof vi.fn >; 8const PDS = 'https://pds.example'; 9const DID = 'did:plc:me'; 10 11beforeEach( () => { 12 mockedGetRecord.mockReset(); 13} ); 14 15describe( 'fetchActorProfile', () => { 16 it( 'reads app.bsky.actor.profile/self and resolves blobs to getBlob URLs', async () => { 17 mockedGetRecord.mockResolvedValue( { 18 uri: `at://${ DID }/app.bsky.actor.profile/self`, 19 cid: 'bafy', 20 value: { 21 displayName: 'Jane Rivera', 22 description: ' Writer & gardener ', 23 avatar: { $type: 'blob', ref: { $link: 'bafyavatar' }, mimeType: 'image/png', size: 1 }, 24 banner: { $type: 'blob', ref: { $link: 'bafybanner' }, mimeType: 'image/png', size: 1 }, 25 }, 26 } ); 27 const profile = await fetchActorProfile( PDS, DID ); 28 29 expect( mockedGetRecord ).toHaveBeenCalledWith( 30 PDS, 31 DID, 32 'app.bsky.actor.profile', 33 'self' 34 ); 35 expect( profile.displayName ).toBe( 'Jane Rivera' ); 36 expect( profile.description ).toBe( 'Writer & gardener' ); // trimmed 37 expect( profile.avatar ).toContain( 'cid=bafyavatar' ); 38 expect( profile.banner ).toContain( 'cid=bafybanner' ); 39 } ); 40 41 it( 'returns all-null when the profile record is missing', async () => { 42 mockedGetRecord.mockResolvedValue( null ); 43 const profile = await fetchActorProfile( PDS, DID ); 44 expect( profile ).toEqual( { 45 displayName: null, 46 description: null, 47 avatar: null, 48 banner: null, 49 } ); 50 } ); 51 52 it( 'coerces empty strings and missing blobs to null', async () => { 53 mockedGetRecord.mockResolvedValue( { 54 uri: 'x', 55 cid: 'y', 56 value: { displayName: ' ', description: '' }, 57 } ); 58 const profile = await fetchActorProfile( PDS, DID ); 59 expect( profile.displayName ).toBeNull(); 60 expect( profile.description ).toBeNull(); 61 expect( profile.avatar ).toBeNull(); 62 expect( profile.banner ).toBeNull(); 63 } ); 64} );