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 {
activityDummyData,
loadActivityExportFile,
symbolProfileDummyData,
userDummyData
} 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 { last } from 'lodash';
import { join } from 'path';
jest.mock('@ghostfolio/api/app/portfolio/current-rate.service', () => {
return {
@ -52,6 +55,8 @@ jest.mock('@ghostfolio/api/app/redis-cache/redis-cache.service', () => {
});
describe('PortfolioCalculator', () => {
let activityDtos: CreateOrderDto[];
let configurationService: ConfigurationService;
let currentRateService: CurrentRateService;
let exchangeRateDataService: ExchangeRateDataService;
@ -59,6 +64,15 @@ describe('PortfolioCalculator', () => {
let portfolioSnapshotService: PortfolioSnapshotService;
let redisCacheService: RedisCacheService;
beforeAll(() => {
activityDtos = loadActivityExportFile(
join(
__dirname,
'../../../../../../../test/import/ok-novn-buy-and-sell-partially.json'
)
);
});
beforeEach(() => {
configurationService = new ConfigurationService();
@ -88,38 +102,18 @@ describe('PortfolioCalculator', () => {
it.only('with NOVN.SW buy and sell partially', async () => {
jest.useFakeTimers().setSystemTime(parseDate('2022-04-11').getTime());
const activities: Activity[] = [
{
const activities: Activity[] = activityDtos.map((activity) => ({
...activityDummyData,
date: new Date('2022-03-07'),
fee: 1.3,
quantity: 2,
...activity,
date: parseDate(activity.date),
SymbolProfile: {
...symbolProfileDummyData,
currency: 'CHF',
dataSource: 'YAHOO',
currency: activity.currency,
dataSource: activity.dataSource,
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
symbol: activity.symbol
}
];
}));
const portfolioCalculator = portfolioCalculatorFactory.createCalculator({
activities,

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

Loading…
Cancel
Save