Feature/Refactor test ok-novn-buy-and-sell-partially to load json file (#3935)

* Refactor test to load json file
pull/3939/head
Thomas Kaul 1 month ago committed by GitHub
parent 0403117e8c
commit 6696a4447a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1,6 +1,8 @@
import { CreateOrderDto } from '@ghostfolio/api/app/order/create-order.dto';
import { Activity } from '@ghostfolio/api/app/order/interfaces/activities.interface'; import { Activity } from '@ghostfolio/api/app/order/interfaces/activities.interface';
import { import {
activityDummyData, activityDummyData,
loadActivityExportFile,
symbolProfileDummyData, symbolProfileDummyData,
userDummyData userDummyData
} from '@ghostfolio/api/app/portfolio/calculator/portfolio-calculator-test-utils'; } from '@ghostfolio/api/app/portfolio/calculator/portfolio-calculator-test-utils';
@ -20,6 +22,7 @@ import { parseDate } from '@ghostfolio/common/helper';
import { Big } from 'big.js'; import { Big } from 'big.js';
import { last } from 'lodash'; import { last } from 'lodash';
import { join } from 'path';
jest.mock('@ghostfolio/api/app/portfolio/current-rate.service', () => { jest.mock('@ghostfolio/api/app/portfolio/current-rate.service', () => {
return { return {
@ -52,6 +55,8 @@ jest.mock('@ghostfolio/api/app/redis-cache/redis-cache.service', () => {
}); });
describe('PortfolioCalculator', () => { describe('PortfolioCalculator', () => {
let activityDtos: CreateOrderDto[];
let configurationService: ConfigurationService; let configurationService: ConfigurationService;
let currentRateService: CurrentRateService; let currentRateService: CurrentRateService;
let exchangeRateDataService: ExchangeRateDataService; let exchangeRateDataService: ExchangeRateDataService;
@ -59,6 +64,15 @@ describe('PortfolioCalculator', () => {
let portfolioSnapshotService: PortfolioSnapshotService; let portfolioSnapshotService: PortfolioSnapshotService;
let redisCacheService: RedisCacheService; let redisCacheService: RedisCacheService;
beforeAll(() => {
activityDtos = loadActivityExportFile(
join(
__dirname,
'../../../../../../../test/import/ok-novn-buy-and-sell-partially.json'
)
);
});
beforeEach(() => { beforeEach(() => {
configurationService = new ConfigurationService(); configurationService = new ConfigurationService();
@ -88,38 +102,18 @@ describe('PortfolioCalculator', () => {
it.only('with NOVN.SW buy and sell partially', async () => { it.only('with NOVN.SW buy and sell partially', async () => {
jest.useFakeTimers().setSystemTime(parseDate('2022-04-11').getTime()); jest.useFakeTimers().setSystemTime(parseDate('2022-04-11').getTime());
const activities: Activity[] = [ const activities: Activity[] = activityDtos.map((activity) => ({
{ ...activityDummyData,
...activityDummyData, ...activity,
date: new Date('2022-03-07'), date: parseDate(activity.date),
fee: 1.3, SymbolProfile: {
quantity: 2, ...symbolProfileDummyData,
SymbolProfile: { currency: activity.currency,
...symbolProfileDummyData, dataSource: activity.dataSource,
currency: 'CHF', name: 'Novartis AG',
dataSource: 'YAHOO', symbol: activity.symbol
name: 'Novartis AG',
symbol: 'NOVN.SW'
},
type: 'BUY',
unitPrice: 75.8
},
{
...activityDummyData,
date: new Date('2022-04-08'),
fee: 2.95,
quantity: 1,
SymbolProfile: {
...symbolProfileDummyData,
currency: 'CHF',
dataSource: 'YAHOO',
name: 'Novartis AG',
symbol: 'NOVN.SW'
},
type: 'SELL',
unitPrice: 85.73
} }
]; }));
const portfolioCalculator = portfolioCalculatorFactory.createCalculator({ const portfolioCalculator = portfolioCalculatorFactory.createCalculator({
activities, activities,

@ -5,23 +5,23 @@
}, },
"activities": [ "activities": [
{ {
"fee": 0, "fee": 1.3,
"quantity": 1, "quantity": 1,
"type": "SELL", "type": "SELL",
"unitPrice": 85.73, "unitPrice": 85.73,
"currency": "CHF", "currency": "CHF",
"dataSource": "YAHOO", "dataSource": "YAHOO",
"date": "2022-04-07T22:00:00.000Z", "date": "2022-04-08T00:00:00.000Z",
"symbol": "NOVN.SW" "symbol": "NOVN.SW"
}, },
{ {
"fee": 0, "fee": 2.95,
"quantity": 2, "quantity": 2,
"type": "BUY", "type": "BUY",
"unitPrice": 75.8, "unitPrice": 75.8,
"currency": "CHF", "currency": "CHF",
"dataSource": "YAHOO", "dataSource": "YAHOO",
"date": "2022-03-06T23:00:00.000Z", "date": "2022-03-07T00:00:00.000Z",
"symbol": "NOVN.SW" "symbol": "NOVN.SW"
} }
] ]

Loading…
Cancel
Save