fix(FEAT-MO-001): 修复TDX数据完整性与状态展示

This commit is contained in:
2026-08-18 19:30:34 +08:00
parent ff8ada8316
commit 49f6be9c43
20 changed files with 557 additions and 113 deletions
@@ -118,6 +118,26 @@ describe('市场概览服务', () => {
);
});
it('市场宽度排除畸形快照并标记部分数据', async () => {
const client = {
request: vi
.fn()
.mockResolvedValueOnce(breadthSnapshot('10', '5'))
.mockResolvedValueOnce({ ErrorId: '0', UpHome: '', DownHome: '3' })
.mockRejectedValueOnce(new Error('raw network detail')),
};
const service = new MarketOverviewService(client);
const response = await service.getBreadth();
expect(response).toMatchObject({
status: 'partial',
data: { advancing: 10, declining: 5, unchanged: null },
});
expect(response.warnings[0]).toContain('深证市场、北证市场');
expect(response.warnings.join(' ')).not.toContain('raw network detail');
});
it('按一级行业涨跌幅排序板块并保留 TDX 代码', async () => {
const client = {
request: vi.fn().mockResolvedValueOnce(sectorResult).mockResolvedValueOnce(sectorKlineResult),
@@ -142,6 +162,46 @@ describe('市场概览服务', () => {
});
});
it('一级行业目录为空时返回不可用而不是 fresh 空数据', async () => {
const client = { request: vi.fn().mockResolvedValue({ ErrorId: '0', Value: [] }) };
const service = new MarketOverviewService(client);
const response = await service.getSectors();
expect(response).toMatchObject({ status: 'unavailable', data: null });
expect(response.warnings).toEqual(['一级行业目录为空']);
expect(client.request).toHaveBeenCalledTimes(1);
});
it('一级行业强弱结果最多展示前八项', async () => {
const definitions = Array.from({ length: 9 }, (_, index) => ({
Code: `88100${index}.SH`,
Name: `行业${index}`,
}));
const value = Object.fromEntries(
definitions.map(({ Code }, index) => [
Code,
{
...indexSeries,
Close: ['100', `${101 + index}`],
},
]),
);
const client = {
request: vi
.fn()
.mockResolvedValueOnce({ ErrorId: '0', Value: definitions })
.mockResolvedValueOnce({ ErrorId: '0', Value: value }),
};
const service = new MarketOverviewService(client);
const response = await service.getSectors();
expect(response.status).toBe('fresh');
expect(response.data?.items).toHaveLength(8);
expect(response.data?.items[0].name).toBe('行业8');
});
it('按交易所指数成交额计算亿元级趋势而不宣称主力净流入', async () => {
const client = { request: vi.fn().mockResolvedValue(turnoverResult) };
const service = new MarketOverviewService(client);
@@ -156,8 +216,26 @@ describe('市场概览服务', () => {
previousAmount: 30,
changePercent: 20,
unit: '亿元',
marketCount: 3,
tradeDate: '20260818',
previousTradeDate: '20260817',
},
});
expect(response.warnings).toEqual([]);
});
it('成交额缺少一个市场时标记 partial 并展示实际市场数', async () => {
const partialResult = structuredClone(turnoverResult);
delete partialResult.Value['899050.BJ'];
const client = { request: vi.fn().mockResolvedValue(partialResult) };
const service = new MarketOverviewService(client);
const response = await service.getFunds();
expect(response).toMatchObject({
status: 'partial',
data: { currentAmount: 24, previousAmount: 20, marketCount: 2, tradeDate: '20260818' },
});
expect(response.warnings).toEqual(['部分市场成交额不可用,当前汇总 2 个市场']);
});
});