|
@ -9,11 +9,11 @@ import { RedisCacheService } from '@ghostfolio/api/app/redis-cache/redis-cache.s |
|
|
import { RedisCacheServiceMock } from '@ghostfolio/api/app/redis-cache/redis-cache.service.mock'; |
|
|
import { RedisCacheServiceMock } from '@ghostfolio/api/app/redis-cache/redis-cache.service.mock'; |
|
|
import { ConfigurationService } from '@ghostfolio/api/services/configuration/configuration.service'; |
|
|
import { ConfigurationService } from '@ghostfolio/api/services/configuration/configuration.service'; |
|
|
import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data/exchange-rate-data.service'; |
|
|
import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data/exchange-rate-data.service'; |
|
|
|
|
|
import { PortfolioSnapshotService } from '@ghostfolio/api/services/portfolio-snapshot/portfolio-snapshot.service'; |
|
|
|
|
|
import { PortfolioSnapshotServiceMock } from '@ghostfolio/api/services/portfolio-snapshot/portfolio-snapshot.service.mock'; |
|
|
import { parseDate } from '@ghostfolio/common/helper'; |
|
|
import { parseDate } from '@ghostfolio/common/helper'; |
|
|
|
|
|
|
|
|
import { Big } from 'big.js'; |
|
|
import { Big } from 'big.js'; |
|
|
import { subDays } from 'date-fns'; |
|
|
|
|
|
import { last } from 'lodash'; |
|
|
|
|
|
|
|
|
|
|
|
jest.mock('@ghostfolio/api/app/portfolio/current-rate.service', () => { |
|
|
jest.mock('@ghostfolio/api/app/portfolio/current-rate.service', () => { |
|
|
return { |
|
|
return { |
|
@ -24,6 +24,18 @@ jest.mock('@ghostfolio/api/app/portfolio/current-rate.service', () => { |
|
|
}; |
|
|
}; |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
jest.mock( |
|
|
|
|
|
'@ghostfolio/api/services/portfolio-snapshot/portfolio-snapshot.service', |
|
|
|
|
|
() => { |
|
|
|
|
|
return { |
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
|
|
|
|
PortfolioSnapshotService: jest.fn().mockImplementation(() => { |
|
|
|
|
|
return PortfolioSnapshotServiceMock; |
|
|
|
|
|
}) |
|
|
|
|
|
}; |
|
|
|
|
|
} |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
jest.mock('@ghostfolio/api/app/redis-cache/redis-cache.service', () => { |
|
|
jest.mock('@ghostfolio/api/app/redis-cache/redis-cache.service', () => { |
|
|
return { |
|
|
return { |
|
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
@ -37,7 +49,8 @@ describe('PortfolioCalculator', () => { |
|
|
let configurationService: ConfigurationService; |
|
|
let configurationService: ConfigurationService; |
|
|
let currentRateService: CurrentRateService; |
|
|
let currentRateService: CurrentRateService; |
|
|
let exchangeRateDataService: ExchangeRateDataService; |
|
|
let exchangeRateDataService: ExchangeRateDataService; |
|
|
let factory: PortfolioCalculatorFactory; |
|
|
let portfolioCalculatorFactory: PortfolioCalculatorFactory; |
|
|
|
|
|
let portfolioSnapshotService: PortfolioSnapshotService; |
|
|
let redisCacheService: RedisCacheService; |
|
|
let redisCacheService: RedisCacheService; |
|
|
|
|
|
|
|
|
beforeEach(() => { |
|
|
beforeEach(() => { |
|
@ -52,12 +65,15 @@ describe('PortfolioCalculator', () => { |
|
|
null |
|
|
null |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
portfolioSnapshotService = new PortfolioSnapshotService(null); |
|
|
|
|
|
|
|
|
redisCacheService = new RedisCacheService(null, null); |
|
|
redisCacheService = new RedisCacheService(null, null); |
|
|
|
|
|
|
|
|
factory = new PortfolioCalculatorFactory( |
|
|
portfolioCalculatorFactory = new PortfolioCalculatorFactory( |
|
|
configurationService, |
|
|
configurationService, |
|
|
currentRateService, |
|
|
currentRateService, |
|
|
exchangeRateDataService, |
|
|
exchangeRateDataService, |
|
|
|
|
|
portfolioSnapshotService, |
|
|
redisCacheService |
|
|
redisCacheService |
|
|
); |
|
|
); |
|
|
}); |
|
|
}); |
|
@ -66,14 +82,14 @@ describe('PortfolioCalculator', () => { |
|
|
it('with no orders', async () => { |
|
|
it('with no orders', async () => { |
|
|
jest.useFakeTimers().setSystemTime(parseDate('2021-12-18').getTime()); |
|
|
jest.useFakeTimers().setSystemTime(parseDate('2021-12-18').getTime()); |
|
|
|
|
|
|
|
|
const portfolioCalculator = factory.createCalculator({ |
|
|
const portfolioCalculator = portfolioCalculatorFactory.createCalculator({ |
|
|
activities: [], |
|
|
activities: [], |
|
|
calculationType: PerformanceCalculationType.TWR, |
|
|
calculationType: PerformanceCalculationType.TWR, |
|
|
currency: 'CHF', |
|
|
currency: 'CHF', |
|
|
userId: userDummyData.id |
|
|
userId: userDummyData.id |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
const portfolioSnapshot = await portfolioCalculator.getSnapshot(); |
|
|
const portfolioSnapshot = await portfolioCalculator.computeSnapshot(); |
|
|
|
|
|
|
|
|
const investments = portfolioCalculator.getInvestments(); |
|
|
const investments = portfolioCalculator.getInvestments(); |
|
|
|
|
|
|
|
|