import { CurrentRateService } from '@ghostfolio/api/app/portfolio/current-rate.service'; import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data/exchange-rate-data.service'; import { parseDate } from '@ghostfolio/common/helper'; import Big from 'big.js'; import { CurrentRateServiceMock } from './current-rate.service.mock'; import { PortfolioCalculator } from './portfolio-calculator'; jest.mock('@ghostfolio/api/app/portfolio/current-rate.service', () => { return { // eslint-disable-next-line @typescript-eslint/naming-convention CurrentRateService: jest.fn().mockImplementation(() => { return CurrentRateServiceMock; }) }; }); describe('PortfolioCalculator', () => { let currentRateService: CurrentRateService; let exchangeRateDataService: ExchangeRateDataService; beforeEach(() => { currentRateService = new CurrentRateService(null, null); exchangeRateDataService = new ExchangeRateDataService( null, null, null, null ); }); describe('get current positions', () => { it('with no orders', async () => { const portfolioCalculator = new PortfolioCalculator({ currentRateService, exchangeRateDataService, currency: 'CHF', orders: [] }); portfolioCalculator.computeTransactionPoints(); const spy = jest .spyOn(Date, 'now') .mockImplementation(() => parseDate('2021-12-18').getTime()); const chartData = await portfolioCalculator.getChartData({ start: new Date() }); const currentPositions = await portfolioCalculator.getCurrentPositions( new Date() ); const investments = portfolioCalculator.getInvestments(); const investmentsByMonth = portfolioCalculator.getInvestmentsByGroup({ data: chartData, groupBy: 'month' }); spy.mockRestore(); expect(currentPositions).toEqual({ currentValue: new Big(0), grossPerformance: new Big(0), grossPerformancePercentage: new Big(0), grossPerformancePercentageWithCurrencyEffect: new Big(0), grossPerformanceWithCurrencyEffect: new Big(0), hasErrors: false, netPerformance: new Big(0), netPerformancePercentage: new Big(0), netPerformancePercentageWithCurrencyEffect: new Big(0), netPerformanceWithCurrencyEffect: new Big(0), positions: [], totalInvestment: new Big(0) }); expect(investments).toEqual([]); expect(investmentsByMonth).toEqual([]); }); }); });