Feature/Set up unit test that loads activity from exported json file (#3901)
* Set up unit test that loads activity from exported json file * Update changelog
This commit is contained in:
parent
d158d0c326
commit
7a11bb93d5
@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
- Added the name to the tooltip of the chart of the holdings tab on the home page (experimental)
|
- Added the name to the tooltip of the chart of the holdings tab on the home page (experimental)
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Improved the portfolio unit tests to work with exported activity files
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Considered the language of the user settings on login with _Security Token_
|
- Considered the language of the user settings on login with _Security Token_
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import { readFileSync } from 'fs';
|
||||||
|
|
||||||
export const activityDummyData = {
|
export const activityDummyData = {
|
||||||
accountId: undefined,
|
accountId: undefined,
|
||||||
accountUserId: undefined,
|
accountUserId: undefined,
|
||||||
@ -29,3 +31,7 @@ export const symbolProfileDummyData = {
|
|||||||
export const userDummyData = {
|
export const userDummyData = {
|
||||||
id: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
|
id: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function loadActivityExportFile(filePath: string) {
|
||||||
|
return JSON.parse(readFileSync(filePath, 'utf8')).activities;
|
||||||
|
}
|
||||||
|
@ -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.json'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
configurationService = new ConfigurationService();
|
configurationService = new ConfigurationService();
|
||||||
|
|
||||||
@ -88,38 +102,18 @@ describe('PortfolioCalculator', () => {
|
|||||||
it.only('with NOVN.SW buy and sell', async () => {
|
it.only('with NOVN.SW buy and sell', 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,
|
||||||
date: new Date('2022-03-07'),
|
...activity,
|
||||||
fee: 0,
|
date: parseDate(activity.date),
|
||||||
quantity: 2,
|
|
||||||
SymbolProfile: {
|
SymbolProfile: {
|
||||||
...symbolProfileDummyData,
|
...symbolProfileDummyData,
|
||||||
currency: 'CHF',
|
currency: activity.currency,
|
||||||
dataSource: 'YAHOO',
|
dataSource: activity.dataSource,
|
||||||
name: 'Novartis AG',
|
name: 'Novartis AG',
|
||||||
symbol: 'NOVN.SW'
|
symbol: activity.symbol
|
||||||
},
|
|
||||||
type: 'BUY',
|
|
||||||
unitPrice: 75.8
|
|
||||||
},
|
|
||||||
{
|
|
||||||
...activityDummyData,
|
|
||||||
date: new Date('2022-04-08'),
|
|
||||||
fee: 0,
|
|
||||||
quantity: 2,
|
|
||||||
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,
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
"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"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -21,7 +21,7 @@
|
|||||||
"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…
x
Reference in New Issue
Block a user