diff --git a/CHANGELOG.md b/CHANGELOG.md index f47f0fec99..1a5e984fb2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- Fixed the calculation of the interest in the account detail dialog for activities with a quantity other than one - Fixed the positive performance from the all time high in the watchlist - Fixed the portfolio calculation for holdings with historical market prices between the chart dates - Fixed the asset profile identifier in the historical market data gathering of the `POST api/v1/activities` endpoint diff --git a/apps/api/src/app/portfolio/portfolio.service.spec.ts b/apps/api/src/app/portfolio/portfolio.service.spec.ts index ccd26e0345..19af3615bc 100644 --- a/apps/api/src/app/portfolio/portfolio.service.spec.ts +++ b/apps/api/src/app/portfolio/portfolio.service.spec.ts @@ -260,6 +260,66 @@ describe('PortfolioService', () => { AND: [whereActivityOfAssetClass, whereActivityOfTag] }); }); + + it('should calculate the dividend and the interest of an account as quantity times unit price', async () => { + jest.spyOn(accountService, 'accounts').mockResolvedValue([ + { + activities: [ + { + currency: 'USD', + date: new Date('2024-01-02'), + quantity: 2, + SymbolProfile: { currency: 'USD' }, + tags: [], + type: 'DIVIDEND', + unitPrice: 10 + }, + { + currency: 'USD', + date: new Date('2024-01-03'), + quantity: 3, + SymbolProfile: { currency: 'USD' }, + tags: [], + type: 'INTEREST', + unitPrice: 5 + } + ], + balance: 0, + currency: 'USD', + id: 'account-id', + name: 'Account' + } + ] as unknown as Awaited>); + + jest.spyOn(portfolioService, 'getDetails').mockResolvedValue({ + accounts: {} + } as unknown as Awaited>); + + jest.spyOn(userService, 'user').mockResolvedValue({ + settings: { settings: { baseCurrency: 'USD' } } + } as unknown as Awaited>); + + jest + .spyOn(exchangeRateDataService, 'toCurrencyAtDate') + .mockImplementation(async (value) => { + return value; + }); + + jest + .spyOn(exchangeRateDataService, 'toCurrency') + .mockImplementation((value) => { + return value; + }); + + const [account] = await portfolioService.getAccounts({ + userId: userDummyData.id + }); + + expect(account).toMatchObject({ + dividendInBaseCurrency: 20, + interestInBaseCurrency: 15 + }); + }); }); describe('getAggregatedMarkets', () => { diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index 72c5b5946a..d906fd6aef 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -334,7 +334,7 @@ export class PortfolioService { case ActivityType.INTEREST: interestInBaseCurrency += (await this.exchangeRateDataService.toCurrencyAtDate( - unitPrice, + new Big(quantity).mul(unitPrice).toNumber(), currency ?? SymbolProfile.currency, userCurrency, date