feat(FEAT-MO-001): 增加市场概览分模块接口
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
import type { INestApplication } from '@nestjs/common';
|
||||
import { Test } from '@nestjs/testing';
|
||||
import request from 'supertest';
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { MarketOverviewController } from '../src/market-overview/market-overview.controller';
|
||||
import { MarketOverviewService, TDX_CLIENT_PORT } from '../src/market-overview/market-overview.service';
|
||||
|
||||
describe('市场概览 HTTP API', () => {
|
||||
let app: INestApplication | undefined;
|
||||
|
||||
afterEach(async () => {
|
||||
await app?.close();
|
||||
app = undefined;
|
||||
});
|
||||
|
||||
it('按模块返回指数和 TDX 来源元数据', async () => {
|
||||
const client = {
|
||||
request: vi.fn().mockResolvedValue({
|
||||
ErrorId: '0',
|
||||
Value: {
|
||||
'000001.SH': {
|
||||
Date: ['20260817', '20260818'],
|
||||
Open: ['3350', '3370'],
|
||||
High: ['3385', '3400'],
|
||||
Low: ['3340', '3360'],
|
||||
Close: ['3360', '3380'],
|
||||
Amount: ['100', '120'],
|
||||
Volume: ['1000', '1100'],
|
||||
},
|
||||
'399001.SZ': {
|
||||
Date: ['20260817', '20260818'],
|
||||
Open: ['10000', '10100'],
|
||||
High: ['10200', '10300'],
|
||||
Low: ['9900', '10050'],
|
||||
Close: ['10000', '10200'],
|
||||
Amount: ['100', '120'],
|
||||
Volume: ['1000', '1100'],
|
||||
},
|
||||
'399006.SZ': {
|
||||
Date: ['20260817', '20260818'],
|
||||
Open: ['2100', '2110'],
|
||||
High: ['2120', '2130'],
|
||||
Low: ['2090', '2100'],
|
||||
Close: ['2100', '2120'],
|
||||
Amount: ['100', '120'],
|
||||
Volume: ['1000', '1100'],
|
||||
},
|
||||
},
|
||||
}),
|
||||
};
|
||||
const moduleRef = await Test.createTestingModule({
|
||||
controllers: [MarketOverviewController],
|
||||
providers: [MarketOverviewService, { provide: TDX_CLIENT_PORT, useValue: client }],
|
||||
}).compile();
|
||||
app = moduleRef.createNestApplication();
|
||||
app.setGlobalPrefix('api/v1');
|
||||
await app.init();
|
||||
|
||||
const response = await request(app.getHttpServer()).get('/api/v1/market-overview/indices').expect(200);
|
||||
|
||||
expect(response.body).toMatchObject({ source: 'tdx', status: 'fresh', data: { items: expect.any(Array) } });
|
||||
expect(JSON.stringify(response.body)).not.toContain('127.0.0.1');
|
||||
});
|
||||
|
||||
it('未提供的板块能力返回可读的不可用状态', async () => {
|
||||
const moduleRef = await Test.createTestingModule({
|
||||
controllers: [MarketOverviewController],
|
||||
providers: [
|
||||
MarketOverviewService,
|
||||
{ provide: TDX_CLIENT_PORT, useValue: { request: vi.fn() } },
|
||||
],
|
||||
}).compile();
|
||||
app = moduleRef.createNestApplication();
|
||||
app.setGlobalPrefix('api/v1');
|
||||
await app.init();
|
||||
|
||||
const response = await request(app.getHttpServer()).get('/api/v1/market-overview/sectors').expect(200);
|
||||
|
||||
expect(response.body).toMatchObject({ source: 'tdx', status: 'unavailable', data: null });
|
||||
expect(response.body.warnings[0]).toContain('板块排行');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user