feat(FEAT-MO-001): 增加市场概览分模块接口

This commit is contained in:
2026-08-18 13:31:24 +08:00
parent c2fa929936
commit 15a25002ce
12 changed files with 834 additions and 1 deletions
@@ -0,0 +1,44 @@
import { describe, expect, it, vi } from 'vitest';
import { MarketOverviewService } from './market-overview.service';
const indexSeries = {
Date: ['20260817', '20260818'],
Open: ['3350', '3370'],
High: ['3385', '3400'],
Low: ['3340', '3360'],
Close: ['3360', '3380'],
Amount: ['100', '120'],
Volume: ['1000', '1100'],
};
const indexResult = {
ErrorId: '0',
Value: Object.fromEntries(
['000001.SH', '399001.SZ', '399006.SZ'].map((code) => [code, indexSeries]),
),
};
describe('市场概览服务', () => {
it('读取指数并返回统一快照元数据', async () => {
const client = { request: vi.fn().mockResolvedValue(indexResult) };
const service = new MarketOverviewService(client);
const response = await service.getIndices();
expect(response).toMatchObject({ source: 'tdx', status: 'fresh', data: { items: expect.any(Array) } });
expect(response.snapshotId).toMatch(/^20260818-/);
expect(client.request).toHaveBeenCalledWith('get_market_data', expect.objectContaining({ count: 5 }));
});
it('对未验证的市场宽度能力返回不可用而不是伪造数据', async () => {
const client = { request: vi.fn() };
const service = new MarketOverviewService(client);
const response = await service.getBreadth();
expect(response).toMatchObject({ source: 'tdx', status: 'unavailable', data: null });
expect(response.warnings[0]).toContain('市场宽度');
expect(client.request).not.toHaveBeenCalled();
});
});