jevstrudel.git / worker / src / activity.test.ts
1import { describe, expect, it } from 'vitest';
2import { merge, type Activity } from './activity';
3
4const item = (at: number, kind: Activity['kind'] = 'pitch'): Activity =>
5  ({ kind, at, id: String(at), author: { id: 'u', name: 'Link' }, screen: 'fine', body: 'x' }) as Activity;
6
7describe('the activity merge', () => {
8  it('takes the newest of every source, newest first', () => {
9    const { items } = merge([[item(5), item(1)], [item(4), item(3)], [item(9)]], 3);
10    expect(items.map((i) => i.at)).toEqual([9, 5, 4]);
11  });
12
13  it('answers the next page from the oldest shown, only when the page is full', () => {
14    expect(merge([[item(5), item(4)], [item(3)]], 2).next).toBe(4);
15    expect(merge([[item(5)]], 2).next).toBeNull();
16  });
17});