app

Local-first trade for farms and co-ops
git clone https://radroots.dev/git/app.git
Log | Files | Refs | README | LICENSE

chronological-query.test.ts (1681B)


      1 import { describe, expect, it } from 'vitest';
      2 import {
      3   chronologicalSearchQuery,
      4   requireChronologicalSearchQuery
      5 } from '../../src/lib/nostr/chronological-query.ts';
      6 
      7 describe('bounded chronological queries', () => {
      8   it('requests a detached kind30402 window of200 without keyword or tag constraints', () => {
      9     expect(chronologicalSearchQuery()).toEqual([
     10       { kinds: [30402], limit: 200 }
     11     ]);
     12     expect(chronologicalSearchQuery(123)).toEqual([
     13       { kinds: [30402], limit: 200, until: 123 }
     14     ]);
     15     const one = chronologicalSearchQuery();
     16     one[0].kinds![0] = 5;
     17     expect(chronologicalSearchQuery()[0].kinds).toEqual([30402]);
     18   });
     19   it('preserves zero/inclusive safe integer boundaries and refuses unsupported time', () => {
     20     expect(chronologicalSearchQuery(0)[0].until).toBe(0);
     21     for (const value of [-1, 1.5, NaN, Infinity, Number.MAX_SAFE_INTEGER + 1])
     22       expect(() => chronologicalSearchQuery(value)).toThrow(
     23         'chronological_boundary_invalid'
     24       );
     25   });
     26   it('refuses externally supplied skip cursors and extra keyword constraints', () => {
     27     expect(
     28       requireChronologicalSearchQuery(
     29         [{ limit: 200, kinds: [30402], until: 123 }],
     30         123
     31       )
     32     ).toEqual(chronologicalSearchQuery(123));
     33     for (const value of [
     34       [],
     35       [{ kinds: [30402], limit: 201 }],
     36       [{ kinds: [5], limit: 200 }],
     37       [{ kinds: [30402], limit: 200, search: 'carrots' }],
     38       [{ kinds: [30402], limit: 200, since: 1 }],
     39       [{ kinds: [30402], limit: 200, until: 122 }]
     40     ])
     41       expect(() => requireChronologicalSearchQuery(value, 123)).toThrow(
     42         'food_search_chronological_filter'
     43       );
     44   });
     45 });