Browse Source

Bugfix/start date of investment timeline (#8122)

* Fix start date of investment timeline

* Update changelog
pull/8147/head
Thomas Kaul 3 days ago
committed by GitHub
parent
commit
62e3f70d24
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 46
      apps/api/src/app/portfolio/portfolio.service.spec.ts
  3. 3
      apps/api/src/app/portfolio/portfolio.service.ts

1
CHANGELOG.md

@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Fixed the border color of the drop area in the import activities dialog (dark mode)
- Fixed the start date of the investment timeline chart on the analysis page
- Fixed the matching of assets and accounts in the import of activities with _Ghostfolio AI_ (experimental)
- Fixed an issue where the update of an activity could change the asset class and asset sub class of an asset profile which does not belong to the user

46
apps/api/src/app/portfolio/portfolio.service.spec.ts

@ -23,7 +23,7 @@ import {
Filter,
PortfolioSummary
} from '@ghostfolio/common/interfaces';
import { AccountWithBalance } from '@ghostfolio/common/types';
import { AccountWithBalance, DateRange } from '@ghostfolio/common/types';
import { AssetClass, DataSource, Prisma } from '@prisma/client';
import { Big } from 'big.js';
@ -842,6 +842,50 @@ describe('PortfolioService', () => {
});
});
describe('getInvestments', () => {
afterEach(() => {
jest.useRealTimers();
});
it.each(['2025', 'ytd'] as DateRange[])(
'should exclude the investment of the start date of the date range %s',
async (dateRange) => {
jest.useFakeTimers().setSystemTime(parseDate('2025-06-15').getTime());
jest
.spyOn(activitiesService, 'getActivitiesForPortfolioCalculator')
.mockResolvedValue({ activities: [{} as Activity], count: 1 });
jest
.spyOn(portfolioCalculatorFactory, 'createCalculator')
.mockReturnValue({
getSnapshot: jest.fn().mockResolvedValue({
historicalData: [
{ date: '2024-12-31', investmentValueWithCurrencyEffect: 100 },
{ date: '2025-01-01', investmentValueWithCurrencyEffect: 200 }
]
})
} as unknown as PortfolioCalculator);
jest.spyOn(userService, 'user').mockResolvedValue({
id: userDummyData.id,
settings: {
settings: {
baseCurrency: 'CHF'
}
}
} as unknown as Awaited<ReturnType<typeof userService.user>>);
const { investments } = await portfolioService.getInvestments({
dateRange,
userId: userDummyData.id
});
expect(investments).toEqual([{ date: '2025-01-01', investment: 200 }]);
}
);
});
describe('getPerformance', () => {
let getPerformanceOfCalculator: jest.Mock;

3
apps/api/src/app/portfolio/portfolio.service.ts

@ -98,7 +98,6 @@ import {
endOfDay,
format,
isAfter,
isBefore,
isSameMonth,
isSameYear,
min,
@ -564,7 +563,7 @@ export class PortfolioService {
const date = resetHours(parseDate(historicalDataItem.date));
return (
!isBefore(date, resetHours(startDate)) &&
isAfter(date, resetHours(startDate)) &&
!isAfter(date, resetHours(endDate))
);
});

Loading…
Cancel
Save