From 6537781976d65dd990dfe54d7a59eb00de30b2ac Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sat, 24 Aug 2024 13:06:11 +0200 Subject: [PATCH] Adapt tests --- ...aln-buy-and-sell-in-two-activities.spec.ts | 23 +++++++++---------- ...folio-calculator-baln-buy-and-sell.spec.ts | 23 +++++++++---------- .../twr/portfolio-calculator-baln-buy.spec.ts | 14 ++--------- ...ator-btcusd-buy-and-sell-partially.spec.ts | 22 +++++++++--------- .../twr/portfolio-calculator-fee.spec.ts | 19 ++++++++------- .../portfolio-calculator-googl-buy.spec.ts | 23 +++++++++---------- .../twr/portfolio-calculator-item.spec.ts | 19 ++++++++------- ...-calculator-msft-buy-with-dividend.spec.ts | 7 ++++++ .../portfolio-calculator-no-orders.spec.ts | 10 ++------ ...ulator-novn-buy-and-sell-partially.spec.ts | 23 +++++++++---------- ...folio-calculator-novn-buy-and-sell.spec.ts | 23 +++++++++---------- 11 files changed, 99 insertions(+), 107 deletions(-) diff --git a/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-baln-buy-and-sell-in-two-activities.spec.ts b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-baln-buy-and-sell-in-two-activities.spec.ts index a83183b16..9f3f33ec0 100644 --- a/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-baln-buy-and-sell-in-two-activities.spec.ts +++ b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-baln-buy-and-sell-in-two-activities.spec.ts @@ -17,6 +17,7 @@ import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate- import { parseDate } from '@ghostfolio/common/helper'; import { Big } from 'big.js'; +import { last } from 'lodash'; jest.mock('@ghostfolio/api/app/portfolio/current-rate.service', () => { return { @@ -136,19 +137,7 @@ describe('PortfolioCalculator', () => { expect(portfolioSnapshot).toMatchObject({ currentValueInBaseCurrency: new Big('0'), errors: [], - grossPerformance: new Big('-12.6'), - grossPerformancePercentage: new Big('-0.04408677396780965649'), - grossPerformancePercentageWithCurrencyEffect: new Big( - '-0.04408677396780965649' - ), - grossPerformanceWithCurrencyEffect: new Big('-12.6'), hasErrors: false, - netPerformance: new Big('-15.8'), - netPerformancePercentage: new Big('-0.05528341497550734703'), - netPerformancePercentageWithCurrencyEffect: new Big( - '-0.05528341497550734703' - ), - netPerformanceWithCurrencyEffect: new Big('-15.8'), positions: [ { averagePrice: new Big('0'), @@ -200,6 +189,16 @@ describe('PortfolioCalculator', () => { totalValuablesWithCurrencyEffect: new Big('0') }); + expect(last(portfolioSnapshot.historicalData)).toMatchObject( + expect.objectContaining({ + netPerformance: -15.8, + netPerformanceInPercentage: -0.05528341497550734703, + netPerformanceInPercentageWithCurrencyEffect: -0.05528341497550734703, + netPerformanceWithCurrencyEffect: -15.8, + totalInvestmentValueWithCurrencyEffect: 0 + }) + ); + expect(investments).toEqual([ { date: '2021-11-22', investment: new Big('285.8') }, { date: '2021-11-30', investment: new Big('0') } diff --git a/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-baln-buy-and-sell.spec.ts b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-baln-buy-and-sell.spec.ts index 77a5cd852..0c1ed1716 100644 --- a/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-baln-buy-and-sell.spec.ts +++ b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-baln-buy-and-sell.spec.ts @@ -17,6 +17,7 @@ import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate- import { parseDate } from '@ghostfolio/common/helper'; import { Big } from 'big.js'; +import { last } from 'lodash'; jest.mock('@ghostfolio/api/app/portfolio/current-rate.service', () => { return { @@ -121,19 +122,7 @@ describe('PortfolioCalculator', () => { expect(portfolioSnapshot).toMatchObject({ currentValueInBaseCurrency: new Big('0'), errors: [], - grossPerformance: new Big('-12.6'), - grossPerformancePercentage: new Big('-0.0440867739678096571'), - grossPerformancePercentageWithCurrencyEffect: new Big( - '-0.0440867739678096571' - ), - grossPerformanceWithCurrencyEffect: new Big('-12.6'), hasErrors: false, - netPerformance: new Big('-15.8'), - netPerformancePercentage: new Big('-0.0552834149755073478'), - netPerformancePercentageWithCurrencyEffect: new Big( - '-0.0552834149755073478' - ), - netPerformanceWithCurrencyEffect: new Big('-15.8'), positions: [ { averagePrice: new Big('0'), @@ -183,6 +172,16 @@ describe('PortfolioCalculator', () => { totalValuablesWithCurrencyEffect: new Big('0') }); + expect(last(portfolioSnapshot.historicalData)).toMatchObject( + expect.objectContaining({ + netPerformance: -15.8, + netPerformanceInPercentage: -0.05528341497550734703, + netPerformanceInPercentageWithCurrencyEffect: -0.05528341497550734703, + netPerformanceWithCurrencyEffect: -15.8, + totalInvestmentValueWithCurrencyEffect: 0 + }) + ); + expect(investments).toEqual([ { date: '2021-11-22', investment: new Big('285.8') }, { date: '2021-11-30', investment: new Big('0') } diff --git a/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-baln-buy.spec.ts b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-baln-buy.spec.ts index c6175c5d0..4548bc995 100644 --- a/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-baln-buy.spec.ts +++ b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-baln-buy.spec.ts @@ -107,19 +107,7 @@ describe('PortfolioCalculator', () => { expect(portfolioSnapshot).toMatchObject({ currentValueInBaseCurrency: new Big('297.8'), errors: [], - grossPerformance: new Big('24.6'), - grossPerformancePercentage: new Big('0.09004392386530014641'), - grossPerformancePercentageWithCurrencyEffect: new Big( - '0.09004392386530014641' - ), - grossPerformanceWithCurrencyEffect: new Big('24.6'), hasErrors: false, - netPerformance: new Big('23.05'), - netPerformancePercentage: new Big('0.08437042459736456808'), - netPerformancePercentageWithCurrencyEffect: new Big( - '0.08437042459736456808' - ), - netPerformanceWithCurrencyEffect: new Big('23.05'), positions: [ { averagePrice: new Big('136.6'), @@ -177,6 +165,8 @@ describe('PortfolioCalculator', () => { expect(last(portfolioSnapshot.historicalData)).toMatchObject( expect.objectContaining({ + netPerformance: 23.05, + netPerformanceInPercentage: 0.08437042459736457, netPerformanceInPercentageWithCurrencyEffect: 0.08437042459736457, netPerformanceWithCurrencyEffect: 23.05, totalInvestmentValueWithCurrencyEffect: 273.2 diff --git a/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-btcusd-buy-and-sell-partially.spec.ts b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-btcusd-buy-and-sell-partially.spec.ts index 04484bfe9..d3ec0a9cc 100644 --- a/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-btcusd-buy-and-sell-partially.spec.ts +++ b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-btcusd-buy-and-sell-partially.spec.ts @@ -18,6 +18,7 @@ import { ExchangeRateDataServiceMock } from '@ghostfolio/api/services/exchange-r import { parseDate } from '@ghostfolio/common/helper'; import { Big } from 'big.js'; +import { last } from 'lodash'; jest.mock('@ghostfolio/api/app/portfolio/current-rate.service', () => { return { @@ -135,19 +136,8 @@ describe('PortfolioCalculator', () => { expect(portfolioSnapshot).toMatchObject({ currentValueInBaseCurrency: new Big('13298.425356'), errors: [], - grossPerformance: new Big('27172.74').mul(0.97373), - grossPerformancePercentage: new Big('42.41983590271396609433'), - grossPerformancePercentageWithCurrencyEffect: new Big( - '41.64017412624815597854' - ), grossPerformanceWithCurrencyEffect: new Big('26516.208701400000064086'), hasErrors: false, - netPerformance: new Big('27172.74').mul(0.97373), - netPerformancePercentage: new Big('42.41983590271396609433'), - netPerformancePercentageWithCurrencyEffect: new Big( - '41.64017412624815597854' - ), - netPerformanceWithCurrencyEffect: new Big('26516.208701400000064086'), positions: [ { averagePrice: new Big('320.43'), @@ -203,6 +193,16 @@ describe('PortfolioCalculator', () => { totalValuablesWithCurrencyEffect: new Big('0') }); + expect(last(portfolioSnapshot.historicalData)).toMatchObject( + expect.objectContaining({ + netPerformance: new Big('27172.74').mul(0.97373).toNumber(), + netPerformanceInPercentage: 42.41983590271396609433, + netPerformanceInPercentageWithCurrencyEffect: 41.64017412624815597854, + netPerformanceWithCurrencyEffect: 26516.208701400000064086, + totalInvestmentValueWithCurrencyEffect: 318.542667299999967957 + }) + ); + expect(investments).toEqual([ { date: '2015-01-01', investment: new Big('640.86') }, { date: '2017-12-31', investment: new Big('320.43') } diff --git a/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-fee.spec.ts b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-fee.spec.ts index 194bf47cf..7afb9e1c6 100644 --- a/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-fee.spec.ts +++ b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-fee.spec.ts @@ -17,6 +17,7 @@ import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate- import { parseDate } from '@ghostfolio/common/helper'; import { Big } from 'big.js'; +import { last } from 'lodash'; jest.mock('@ghostfolio/api/app/portfolio/current-rate.service', () => { return { @@ -99,15 +100,7 @@ describe('PortfolioCalculator', () => { expect(portfolioSnapshot).toMatchObject({ currentValueInBaseCurrency: new Big('0'), errors: [], - grossPerformance: new Big('0'), - grossPerformancePercentage: new Big('0'), - grossPerformancePercentageWithCurrencyEffect: new Big('0'), - grossPerformanceWithCurrencyEffect: new Big('0'), hasErrors: true, - netPerformance: new Big('0'), - netPerformancePercentage: new Big('0'), - netPerformancePercentageWithCurrencyEffect: new Big('0'), - netPerformanceWithCurrencyEffect: new Big('0'), positions: [ { averagePrice: new Big('0'), @@ -148,6 +141,16 @@ describe('PortfolioCalculator', () => { totalLiabilitiesWithCurrencyEffect: new Big('0'), totalValuablesWithCurrencyEffect: new Big('0') }); + + expect(last(portfolioSnapshot.historicalData)).toMatchObject( + expect.objectContaining({ + netPerformance: 0, + netPerformanceInPercentage: 0, + netPerformanceInPercentageWithCurrencyEffect: 0, + netPerformanceWithCurrencyEffect: 0, + totalInvestmentValueWithCurrencyEffect: 0 + }) + ); }); }); }); diff --git a/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-googl-buy.spec.ts b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-googl-buy.spec.ts index a4acc2312..fc757b82b 100644 --- a/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-googl-buy.spec.ts +++ b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-googl-buy.spec.ts @@ -18,6 +18,7 @@ import { ExchangeRateDataServiceMock } from '@ghostfolio/api/services/exchange-r import { parseDate } from '@ghostfolio/common/helper'; import { Big } from 'big.js'; +import { last } from 'lodash'; jest.mock('@ghostfolio/api/app/portfolio/current-rate.service', () => { return { @@ -119,19 +120,7 @@ describe('PortfolioCalculator', () => { expect(portfolioSnapshot).toMatchObject({ currentValueInBaseCurrency: new Big('103.10483'), errors: [], - grossPerformance: new Big('27.33').mul(0.8854), - grossPerformancePercentage: new Big('0.3066651705565529623'), - grossPerformancePercentageWithCurrencyEffect: new Big( - '0.25235044599563974109' - ), - grossPerformanceWithCurrencyEffect: new Big('20.775774'), hasErrors: false, - netPerformance: new Big('26.33').mul(0.8854), - netPerformancePercentage: new Big('0.29544434470377019749'), - netPerformancePercentageWithCurrencyEffect: new Big( - '0.24112962014285697628' - ), - netPerformanceWithCurrencyEffect: new Big('19.851974'), positions: [ { averagePrice: new Big('89.12'), @@ -181,6 +170,16 @@ describe('PortfolioCalculator', () => { totalValuablesWithCurrencyEffect: new Big('0') }); + expect(last(portfolioSnapshot.historicalData)).toMatchObject( + expect.objectContaining({ + netPerformance: new Big('26.33').mul(0.8854).toNumber(), + netPerformanceInPercentage: 0.29544434470377019749, + netPerformanceInPercentageWithCurrencyEffect: 0.24112962014285697628, + netPerformanceWithCurrencyEffect: 19.851974, + totalInvestmentValueWithCurrencyEffect: 82.329056 + }) + ); + expect(investments).toEqual([ { date: '2023-01-03', investment: new Big('89.12') } ]); diff --git a/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-item.spec.ts b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-item.spec.ts index 0e45d209f..bfae94ad8 100644 --- a/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-item.spec.ts +++ b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-item.spec.ts @@ -17,6 +17,7 @@ import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate- import { parseDate } from '@ghostfolio/common/helper'; import { Big } from 'big.js'; +import { last } from 'lodash'; jest.mock('@ghostfolio/api/app/portfolio/current-rate.service', () => { return { @@ -99,15 +100,7 @@ describe('PortfolioCalculator', () => { expect(portfolioSnapshot).toMatchObject({ currentValueInBaseCurrency: new Big('0'), errors: [], - grossPerformance: new Big('0'), - grossPerformancePercentage: new Big('0'), - grossPerformancePercentageWithCurrencyEffect: new Big('0'), - grossPerformanceWithCurrencyEffect: new Big('0'), hasErrors: true, - netPerformance: new Big('0'), - netPerformancePercentage: new Big('0'), - netPerformancePercentageWithCurrencyEffect: new Big('0'), - netPerformanceWithCurrencyEffect: new Big('0'), positions: [ { averagePrice: new Big('500000'), @@ -148,6 +141,16 @@ describe('PortfolioCalculator', () => { totalLiabilitiesWithCurrencyEffect: new Big('0'), totalValuablesWithCurrencyEffect: new Big('0') }); + + expect(last(portfolioSnapshot.historicalData)).toMatchObject( + expect.objectContaining({ + netPerformance: 0, + netPerformanceInPercentage: 0, + netPerformanceInPercentageWithCurrencyEffect: 0, + netPerformanceWithCurrencyEffect: 0, + totalInvestmentValueWithCurrencyEffect: 0 + }) + ); }); }); }); diff --git a/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-msft-buy-with-dividend.spec.ts b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-msft-buy-with-dividend.spec.ts index 81d0b302a..8a1c5a517 100644 --- a/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-msft-buy-with-dividend.spec.ts +++ b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-msft-buy-with-dividend.spec.ts @@ -18,6 +18,7 @@ import { ExchangeRateDataServiceMock } from '@ghostfolio/api/services/exchange-r import { parseDate } from '@ghostfolio/common/helper'; import { Big } from 'big.js'; +import { last } from 'lodash'; jest.mock('@ghostfolio/api/app/portfolio/current-rate.service', () => { return { @@ -153,6 +154,12 @@ describe('PortfolioCalculator', () => { totalLiabilitiesWithCurrencyEffect: new Big('0'), totalValuablesWithCurrencyEffect: new Big('0') }); + + expect(last(portfolioSnapshot.historicalData)).toMatchObject( + expect.objectContaining({ + totalInvestmentValueWithCurrencyEffect: 298.58 + }) + ); }); }); }); diff --git a/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-no-orders.spec.ts b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-no-orders.spec.ts index f939487fd..a25e31dd3 100644 --- a/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-no-orders.spec.ts +++ b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-no-orders.spec.ts @@ -13,6 +13,7 @@ import { parseDate } from '@ghostfolio/common/helper'; import { Big } from 'big.js'; import { subDays } from 'date-fns'; +import { last } from 'lodash'; jest.mock('@ghostfolio/api/app/portfolio/current-rate.service', () => { return { @@ -83,15 +84,8 @@ describe('PortfolioCalculator', () => { expect(portfolioSnapshot).toMatchObject({ currentValueInBaseCurrency: new Big(0), - grossPerformance: new Big(0), - grossPerformancePercentage: new Big(0), - grossPerformancePercentageWithCurrencyEffect: new Big(0), - grossPerformanceWithCurrencyEffect: new Big(0), hasErrors: false, - netPerformance: new Big(0), - netPerformancePercentage: new Big(0), - netPerformancePercentageWithCurrencyEffect: new Big(0), - netPerformanceWithCurrencyEffect: new Big(0), + historicalData: [], positions: [], totalFeesWithCurrencyEffect: new Big('0'), totalInterestWithCurrencyEffect: new Big('0'), 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.ts index 51d8d141d..e142255c4 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 @@ -17,6 +17,7 @@ import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate- import { parseDate } from '@ghostfolio/common/helper'; import { Big } from 'big.js'; +import { last } from 'lodash'; jest.mock('@ghostfolio/api/app/portfolio/current-rate.service', () => { return { @@ -121,19 +122,7 @@ describe('PortfolioCalculator', () => { expect(portfolioSnapshot).toMatchObject({ currentValueInBaseCurrency: new Big('87.8'), errors: [], - grossPerformance: new Big('21.93'), - grossPerformancePercentage: new Big('0.15113417083448194384'), - grossPerformancePercentageWithCurrencyEffect: new Big( - '0.15113417083448194384' - ), - grossPerformanceWithCurrencyEffect: new Big('21.93'), hasErrors: false, - netPerformance: new Big('17.68'), - netPerformancePercentage: new Big('0.12184460284330327256'), - netPerformancePercentageWithCurrencyEffect: new Big( - '0.12184460284330327256' - ), - netPerformanceWithCurrencyEffect: new Big('17.68'), positions: [ { averagePrice: new Big('75.80'), @@ -185,6 +174,16 @@ describe('PortfolioCalculator', () => { totalValuablesWithCurrencyEffect: new Big('0') }); + expect(last(portfolioSnapshot.historicalData)).toMatchObject( + expect.objectContaining({ + netPerformance: 17.68, + netPerformanceInPercentage: 0.12184460284330327256, + netPerformanceInPercentageWithCurrencyEffect: 0.12184460284330327256, + netPerformanceWithCurrencyEffect: 17.68, + totalInvestmentValueWithCurrencyEffect: 75.8 + }) + ); + expect(investments).toEqual([ { date: '2022-03-07', investment: new Big('151.6') }, { date: '2022-04-08', investment: new Big('75.8') } diff --git a/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-novn-buy-and-sell.spec.ts b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-novn-buy-and-sell.spec.ts index 175b519cf..930ef6da7 100644 --- a/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-novn-buy-and-sell.spec.ts +++ b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-novn-buy-and-sell.spec.ts @@ -17,6 +17,7 @@ import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate- import { parseDate } from '@ghostfolio/common/helper'; import { Big } from 'big.js'; +import { last } from 'lodash'; jest.mock('@ghostfolio/api/app/portfolio/current-rate.service', () => { return { @@ -170,19 +171,7 @@ describe('PortfolioCalculator', () => { expect(portfolioSnapshot).toMatchObject({ currentValueInBaseCurrency: new Big('0'), errors: [], - grossPerformance: new Big('19.86'), - grossPerformancePercentage: new Big('0.13100263852242744063'), - grossPerformancePercentageWithCurrencyEffect: new Big( - '0.13100263852242744063' - ), - grossPerformanceWithCurrencyEffect: new Big('19.86'), hasErrors: false, - netPerformance: new Big('19.86'), - netPerformancePercentage: new Big('0.13100263852242744063'), - netPerformancePercentageWithCurrencyEffect: new Big( - '0.13100263852242744063' - ), - netPerformanceWithCurrencyEffect: new Big('19.86'), positions: [ { averagePrice: new Big('0'), @@ -232,6 +221,16 @@ describe('PortfolioCalculator', () => { totalValuablesWithCurrencyEffect: new Big('0') }); + expect(last(portfolioSnapshot.historicalData)).toMatchObject( + expect.objectContaining({ + netPerformance: 19.86, + netPerformanceInPercentage: 0.13100263852242744063, + netPerformanceInPercentageWithCurrencyEffect: 0.13100263852242744063, + netPerformanceWithCurrencyEffect: 19.86, + totalInvestmentValueWithCurrencyEffect: 0 + }) + ); + expect(investments).toEqual([ { date: '2022-03-07', investment: new Big('151.6') }, { date: '2022-04-08', investment: new Big('0') }