Some checks failed
- Add buyPrice and buyDate to positions for PnL tracking - Implement backend analytics service for real-time portfolio performance - Add server-side security screener with filtering, sorting, and pagination - Update frontend UI with analytics summaries and sortable screener table - Optimize MOEX API calls with batch fetching and portfolio-specific caching - Add unit tests for analytics and screener services
54 lines
1.5 KiB
TypeScript
54 lines
1.5 KiB
TypeScript
import { Test, TestingModule } from '@nestjs/testing';
|
|
import { SecuritiesController } from './securities.controller';
|
|
import { SecuritiesService } from './securities.service';
|
|
import { ScreenerService } from './screener.service';
|
|
import { SecurityType } from './dto/search-query.dto';
|
|
|
|
describe('SecuritiesController', () => {
|
|
let controller: SecuritiesController;
|
|
let service: SecuritiesService;
|
|
|
|
const mockResults = [
|
|
{
|
|
secid: 'SBER',
|
|
isin: 'RU0009029540',
|
|
shortName: 'Сбербанк',
|
|
type: 'share',
|
|
listLevel: 1,
|
|
currency: 'RUB',
|
|
price: null,
|
|
},
|
|
];
|
|
|
|
const mockService = {
|
|
search: vi.fn().mockResolvedValue(mockResults),
|
|
};
|
|
|
|
const mockScreenerService = {
|
|
screen: vi.fn(),
|
|
};
|
|
|
|
beforeEach(async () => {
|
|
const module: TestingModule = await Test.createTestingModule({
|
|
controllers: [SecuritiesController],
|
|
providers: [
|
|
{ provide: SecuritiesService, useValue: mockService },
|
|
{ provide: ScreenerService, useValue: mockScreenerService },
|
|
],
|
|
}).compile();
|
|
|
|
controller = module.get<SecuritiesController>(SecuritiesController);
|
|
service = module.get<SecuritiesService>(SecuritiesService);
|
|
});
|
|
|
|
it('should be defined', () => {
|
|
expect(controller).toBeDefined();
|
|
});
|
|
|
|
it('should return search results', async () => {
|
|
const result = await controller.search({ q: 'SBER', type: SecurityType.ALL, limit: 5 });
|
|
expect(result.data).toEqual(mockResults);
|
|
expect(service.search).toHaveBeenCalledWith('SBER', SecurityType.ALL, 5);
|
|
});
|
|
});
|