profile-query.test.ts (1399B)
1 import { describe, expect, it } from 'vitest'; 2 import { finalizeEvent } from 'applesauce-core/helpers'; 3 import { publisherProfileQuery } from '../../src/lib/nostr/profile-query.ts'; 4 function author() { 5 const key = crypto.getRandomValues(new Uint8Array(32)); 6 try { 7 return finalizeEvent( 8 { kind: 0, created_at: 1, tags: [], content: '{}' }, 9 key 10 ).pubkey; 11 } finally { 12 key.fill(0); 13 } 14 } 15 describe('bounded publisher profile query', () => { 16 it('coalesces twenty page authors into one bounded generic metadata filter', () => { 17 const authors = Array.from({ length: 20 }, () => author()); 18 expect(publisherProfileQuery(authors)).toEqual([ 19 { kinds: [0], authors, limit: 200 } 20 ]); 21 expect(publisherProfileQuery([authors[0], authors[0]])).toEqual([ 22 { kinds: [0], authors: [authors[0]], limit: 200 } 23 ]); 24 const query = publisherProfileQuery(authors); 25 query[0].authors![0] = authors[1]; 26 expect(publisherProfileQuery(authors)[0].authors![0]).toBe(authors[0]); 27 expect(publisherProfileQuery([])).toEqual([]); 28 }); 29 it('rejects oversized or malformed admission before request effects', () => { 30 const key = author(); 31 for (const values of [ 32 Array.from({ length: 21 }, () => key), 33 ['wrong'], 34 [key.toUpperCase()], 35 ['0'.repeat(64)] 36 ]) 37 expect(() => publisherProfileQuery(values)).toThrow(); 38 }); 39 });