Something went wrong. Try again.
Central platform for European atproto.<cc> country community websites
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243import { describe, expect, it } from 'vitest';import { mergeFeed } from './feed';import type { FeedPost } from './types';
function post(uri: string, createdAt: string): FeedPost { return { uri, cid: 'cid', author: { did: 'did:plc:x', handle: 'a.test' }, text: 't', createdAt, likeCount: 0, repostCount: 0, replyCount: 0, };}
describe('mergeFeed', () => { it('sorts newest first across authors', () => { const a = [post('a', '2026-01-01T00:00:00Z')]; const b = [post('b', '2026-02-01T00:00:00Z')]; expect(mergeFeed([a, b]).map((p) => p.uri)).toEqual(['b', 'a']); });
it('dedupes by uri (keeps first seen)', () => { const a = [post('dup', '2026-01-01T00:00:00Z')]; const b = [post('dup', '2026-02-01T00:00:00Z')]; expect(mergeFeed([a, b])).toHaveLength(1); });
it('caps at limit', () => { const feed = Array.from({ length: 10 }, (_, i) => post(`p${i}`, `2026-01-${String(i + 1).padStart(2, '0')}T00:00:00Z`), ); expect(mergeFeed([feed], 3)).toHaveLength(3); });
it('handles empty input', () => { expect(mergeFeed([])).toEqual([]); expect(mergeFeed([[], []])).toEqual([]); });});