Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍
TypeScript angularetffinancefintechghostfoliohacktoberfestinvestingnestjsosspersonal-financeportfolioprismasoftwarestocktrackertradingtypescriptwealth-managementweb
Feature/Refactor test ok-novn-buy-and-sell-partially to load json file (#3935)
Thomas Kaul6696a4447a78
diff --git a/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-novn-buy-and-sell-partially.spec.ts b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-novn-buy-and-sell-partially.spec.tsindex 30eb79754e..f9f99ee45f 100644--- a/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-novn-buy-and-sell-partially.spec.ts+++ b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-novn-buy-and-sell-partially.spec.ts@@ -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[] = [- {- ...activityDummyData,- date: new Date('2022-03-07'),- fee: 1.3,- quantity: 2,- SymbolProfile: {- ...symbolProfileDummyData,- currency: 'CHF',- dataSource: 'YAHOO',- 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 activities: Activity[] = activityDtos.map((activity) => ({+ ...activityDummyData,+ ...activity,+ date: parseDate(activity.date),+ SymbolProfile: {+ ...symbolProfileDummyData,+ currency: activity.currency,+ dataSource: activity.dataSource,+ name: 'Novartis AG',+ symbol: activity.symbol}- ];+ }));const portfolioCalculator = portfolioCalculatorFactory.createCalculator({activities,diff --git a/test/import/ok-novn-buy-and-sell-partially.json b/test/import/ok-novn-buy-and-sell-partially.jsonindex c184b4ba4b..06cbc75ea0 100644--- a/test/import/ok-novn-buy-and-sell-partially.json+++ b/test/import/ok-novn-buy-and-sell-partially.json@@ -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"}]