From 40e7d13aa2d340af78fac30a31677f903754d440 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sat, 3 Jan 2026 11:45:58 +0100 Subject: [PATCH] Refactoring --- .../roai/portfolio-calculator-cash.spec.ts | 23 ++++++++----------- .../src/app/portfolio/portfolio.service.ts | 4 +++- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-cash.spec.ts b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-cash.spec.ts index 1e8e49d04..db6e08151 100644 --- a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-cash.spec.ts +++ b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-cash.spec.ts @@ -207,20 +207,19 @@ describe('PortfolioCalculator', () => { userId: userDummyData.id }); - const portfolioSnapshot = await portfolioCalculator.computeSnapshot(); + const { historicalData } = await portfolioCalculator.computeSnapshot(); - const historicalData20231231 = portfolioSnapshot.historicalData.find( - ({ date }) => date === '2023-12-31' - ); - const historicalData20240101 = portfolioSnapshot.historicalData.find( - ({ date }) => date === '2024-01-01' - ); - const historicalData20241231 = portfolioSnapshot.historicalData.find( - ({ date }) => date === '2024-12-31' - ); + const historicalData20231231 = historicalData.find(({ date }) => { + return date === '2023-12-31'; + }); + const historicalData20240101 = historicalData.find(({ date }) => { + return date === '2024-01-01'; + }); + const historicalData20241231 = historicalData.find(({ date }) => { + return date === '2024-12-31'; + }); /** - * Expected logic: * Investment value with currency effect: 1000 USD * 0.85 = 850 CHF * Total investment: 1000 USD * 0.91 = 910 CHF * Value (current): 1000 USD * 0.91 = 910 CHF @@ -242,7 +241,6 @@ describe('PortfolioCalculator', () => { }); /** - * Expected logic: * Net performance with currency effect: (1000 * 0.86) - (1000 * 0.85) = 10 CHF * Total investment: 1000 USD * 0.91 = 910 CHF * Total investment value with currency effect: 1000 USD * 0.85 = 850 CHF @@ -265,7 +263,6 @@ describe('PortfolioCalculator', () => { }); /** - * Expected logic: * Investment value with currency effect: 1000 USD * 0.90 = 900 CHF * Net performance: (1000 USD * 1.0) - (1000 USD * 1.0) = 0 CHF * Net performance with currency effect: (1000 USD * 0.9) - (1000 USD * 0.85) = 50 CHF diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index 5bfd32b39..5613af9e7 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -1542,7 +1542,9 @@ export class PortfolioService { return cashSymbols.map((currency) => { const account = cashDetails.accounts.find( - ({ currency: accountCurrency }) => accountCurrency === currency + ({ currency: accountCurrency }) => { + return accountCurrency === currency; + } ); return {