summaryrefslogtreecommitdiff
path: root/frontend/src/lib/coverage.test.ts
blob: cf59d5442172ccbcf07942bfb2a18fb0d8465681 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { describe, expect, it } from 'vitest';
import { summarizeCoverage, type CoverageEntry } from './coverage';

describe('summarizeCoverage', () => {
  const entry = (o: Partial<CoverageEntry>): CoverageEntry => ({
    instrument: '600000',
    market: 'SH',
    asset_type: 'stock',
    requested_start: '',
    requested_end: '',
    actual_start: '',
    actual_end: '',
    row_count: 1,
    ...o
  });

  it('lists unaligned starts without invented dates', () => {
    const rows = [
      entry({ instrument: 'A', actual_start: '2018-01-02', actual_end: '2024-12-31', requested_start: '2015-01-01' }),
      entry({ instrument: 'B', actual_start: '2020-01-02', actual_end: '2024-12-31', requested_start: '2015-01-01' })
    ];
    const s = summarizeCoverage(rows);
    expect(s.common.start).toBe('2020-01-02');
    expect(s.common.end).toBe('2024-12-31');
    expect(s.warnings.includes('B 起始数据较其他标的更晚(2020-01-02)')).toBe(true);
  });

  it('reports missing rows', () => {
    const rows = [entry({ instrument: 'C', row_count: 0, actual_start: '', actual_end: '' })];
    const s = summarizeCoverage(rows);
    expect(s.warnings.includes('C 没有返回任何数据行')).toBe(true);
    expect(s.common.start).toBeNull();
  });

  it('reports different end dates', () => {
    const rows = [
      entry({ instrument: 'A', actual_start: '2020-01-02', actual_end: '2024-12-31' }),
      entry({ instrument: 'B', actual_start: '2020-01-02', actual_end: '2024-11-29' })
    ];
    const s = summarizeCoverage(rows);
    expect(s.warnings.some((w) => w.includes('B 较早结束'))).toBe(true);
  });
});