feat(FEAT-MO-001): 完成TDX市场概览首屏
This commit is contained in:
@@ -26,9 +26,16 @@ describe('市场概览服务', () => {
|
||||
|
||||
const response = await service.getIndices();
|
||||
|
||||
expect(response).toMatchObject({ source: 'tdx', status: 'fresh', data: { items: expect.any(Array) } });
|
||||
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 }));
|
||||
expect(client.request).toHaveBeenCalledWith(
|
||||
'get_market_data',
|
||||
expect.objectContaining({ count: 5 }),
|
||||
);
|
||||
});
|
||||
|
||||
it('对未验证的市场宽度能力返回不可用而不是伪造数据', async () => {
|
||||
|
||||
@@ -23,7 +23,10 @@ export type MarketOverviewResponse<TData> = {
|
||||
warnings: string[];
|
||||
};
|
||||
|
||||
function createSnapshotMeta(): Pick<MarketOverviewResponse<never>, 'snapshotId' | 'asOf' | 'source'> {
|
||||
function createSnapshotMeta(): Pick<
|
||||
MarketOverviewResponse<never>,
|
||||
'snapshotId' | 'asOf' | 'source'
|
||||
> {
|
||||
const asOf = new Date().toISOString();
|
||||
const snapshotId = `${asOf.slice(0, 10).replaceAll('-', '')}-${asOf.slice(11, 19).replaceAll(':', '')}`;
|
||||
return { snapshotId, asOf, source: 'tdx' };
|
||||
@@ -76,9 +79,15 @@ export class MarketOverviewService {
|
||||
const averageChange = changes.length
|
||||
? Math.round((changes.reduce((sum, value) => sum + value, 0) / changes.length) * 100) / 100
|
||||
: null;
|
||||
const marketStatus = averageChange === null ? '指数数据不完整' : averageChange >= 0 ? '指数偏强' : '指数偏弱';
|
||||
const marketStatus =
|
||||
averageChange === null ? '指数数据不完整' : averageChange >= 0 ? '指数偏强' : '指数偏弱';
|
||||
const summary: SummaryDataDto = {
|
||||
verdict: averageChange === null ? '市场状态待确认' : averageChange >= 0 ? '市场维持偏强震荡' : '市场维持偏弱震荡',
|
||||
verdict:
|
||||
averageChange === null
|
||||
? '市场状态待确认'
|
||||
: averageChange >= 0
|
||||
? '市场维持偏强震荡'
|
||||
: '市场维持偏弱震荡',
|
||||
marketStatus,
|
||||
volumeStatus: '成交量口径待接入',
|
||||
sentimentStatus: '市场情绪口径待接入',
|
||||
|
||||
@@ -12,19 +12,21 @@ function response(body: unknown, init?: ResponseInit): Response {
|
||||
|
||||
describe('TDX 客户端', () => {
|
||||
it('发送固定 JSON 请求并返回业务结果', async () => {
|
||||
const fetchImpl = vi.fn<typeof fetch>().mockResolvedValue(
|
||||
response({ id: 1, result: { ErrorId: '0', Value: {} } }),
|
||||
);
|
||||
const fetchImpl = vi
|
||||
.fn<typeof fetch>()
|
||||
.mockResolvedValue(response({ id: 1, result: { ErrorId: '0', Value: {} } }));
|
||||
const client = createTdxClient({
|
||||
baseUrl: 'http://127.0.0.1:17710',
|
||||
timeoutMs: 5_000,
|
||||
fetchImpl,
|
||||
});
|
||||
|
||||
await expect(client.request('get_market_data', { stock_list: ['600519.SH'] })).resolves.toEqual({
|
||||
ErrorId: '0',
|
||||
Value: {},
|
||||
});
|
||||
await expect(client.request('get_market_data', { stock_list: ['600519.SH'] })).resolves.toEqual(
|
||||
{
|
||||
ErrorId: '0',
|
||||
Value: {},
|
||||
},
|
||||
);
|
||||
|
||||
expect(fetchImpl).toHaveBeenCalledWith(
|
||||
'http://127.0.0.1:17710/',
|
||||
@@ -42,9 +44,11 @@ describe('TDX 客户端', () => {
|
||||
});
|
||||
|
||||
it('将 TDX 错误响应转换为脱敏协议错误', async () => {
|
||||
const fetchImpl = vi.fn<typeof fetch>().mockResolvedValue(
|
||||
response({ id: 1, error: { code: 'bad_request', message: '内部连接信息' } }),
|
||||
);
|
||||
const fetchImpl = vi
|
||||
.fn<typeof fetch>()
|
||||
.mockResolvedValue(
|
||||
response({ id: 1, error: { code: 'bad_request', message: '内部连接信息' } }),
|
||||
);
|
||||
const client = createTdxClient({
|
||||
baseUrl: 'http://127.0.0.1:17710',
|
||||
timeoutMs: 5_000,
|
||||
@@ -60,7 +64,9 @@ describe('TDX 客户端', () => {
|
||||
});
|
||||
|
||||
it('将 AbortError 转换为超时错误', async () => {
|
||||
const fetchImpl = vi.fn<typeof fetch>().mockRejectedValue(new DOMException('aborted', 'AbortError'));
|
||||
const fetchImpl = vi
|
||||
.fn<typeof fetch>()
|
||||
.mockRejectedValue(new DOMException('aborted', 'AbortError'));
|
||||
const client = createTdxClient({
|
||||
baseUrl: 'http://127.0.0.1:17710',
|
||||
timeoutMs: 50,
|
||||
|
||||
Reference in New Issue
Block a user