moex-vibe/apps/frontend/src/test/factories.ts

147 lines
3.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import type {
ShareResponse,
BondResponse,
BondMarketData,
StockMarketData,
CandleItem,
DividendItem,
SearchResultItem,
UserResponse,
AuthResponse,
} from '@/shared/api/responses';
export function createMockMarketData(overrides: Partial<StockMarketData> = {}): StockMarketData {
return {
price: 289.5,
change: 2.5,
changePercent: 0.87,
open: 287,
high: 291,
low: 286.5,
volume: 15000000,
value: 4350000000,
issueCapitalization: 6250000000000,
updatedAt: '2024-01-15T10:00:00Z',
...overrides,
};
}
export function createMockShare(overrides: Partial<ShareResponse> = {}): ShareResponse {
return {
secid: 'SBER',
isin: 'RU0009029540',
name: 'Сбер Банк',
shortName: 'Сбер',
latName: 'Sberbank',
listLevel: 1,
issueSize: 21586900000,
faceValue: 3,
faceUnit: 'RUB',
type: 'common_share',
marketData: createMockMarketData(),
...overrides,
};
}
export function createMockBondMarketData(overrides: Partial<BondMarketData> = {}): BondMarketData {
return {
price: 98.5,
yieldToMaturity: 8.2,
duration: 3.5,
accruedInt: 8.45,
couponValue: 36.9,
couponPercent: 7.5,
nextCouponDate: '2024-07-15',
open: 98.0,
high: 99.0,
low: 97.5,
volume: 1000000,
updatedAt: '2024-01-15T10:00:00Z',
...overrides,
};
}
export function createMockBond(overrides: Partial<BondResponse> = {}): BondResponse {
return {
secid: 'SU26238RMFS5',
isin: 'RU000A101XU7',
name: 'ОФЗ 26238',
shortName: 'ОФЗ 26238',
latName: null,
listLevel: 1,
issueSize: 500000000,
faceValue: 1000,
faceUnit: 'RUB',
matDate: '2027-05-15',
couponValue: 36.9,
couponPercent: 7.5,
couponPeriod: 182,
nextCoupon: '2024-07-15',
accruedInt: 8.45,
bondType: 'ОФЗ',
bondSubType: 'ОФЗ-ПД',
offerDate: null,
buybackDate: null,
marketData: createMockBondMarketData(),
...overrides,
};
}
export function createMockUser(overrides: Partial<UserResponse> = {}): UserResponse {
return {
id: 1,
email: 'user@test.com',
name: 'Test User',
role: 'user',
...overrides,
};
}
export function createMockAuth(overrides: Partial<AuthResponse> = {}): AuthResponse {
return {
user: createMockUser(),
accessToken: 'mock-token',
...overrides,
};
}
export function createMockCandles(count = 2): CandleItem[] {
return Array.from({ length: count }, (_, i) => ({
open: 280 + i,
high: 290 + i,
low: 278 + i,
close: 289.5 + i,
volume: 1000000,
value: 280000000,
begin: `2024-01-${15 + i}T10:00:00Z`,
end: `2024-01-${15 + i}T18:00:00Z`,
}));
}
export function createMockDividends(): DividendItem[] {
return [{ registryCloseDate: '2024-07-10', value: 35.0, currency: 'RUB' }];
}
export function createMockSearchResults(): SearchResultItem[] {
return [
{
secid: 'SBER',
isin: 'RU0009029540',
shortName: 'Сбер',
type: 'share',
listLevel: 1,
currency: 'RUB',
price: 289.5,
},
{
secid: 'VTBR',
isin: 'RU000A0JP5V6',
shortName: 'ВТБ',
type: 'share',
listLevel: 1,
currency: 'RUB',
price: 0.0234,
},
];
}