diff --git a/CHANGELOG.md b/CHANGELOG.md index a4143899e7..c746f731aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Upgraded `yahoo-finance2` from version `4.0.2` to `4.0.5` + +## 3.94.0 - 2026-10-28 + +### Changed + - Improved the data source filter in the historical market data table of the admin control panel to only list the data providers in use - Restricted the health check endpoint of the AI service (`GET api/v1/health/ai`) to administrators - Increased the timeout in the health check endpoint of the AI service to 30 seconds @@ -16,11 +22,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Deprecated the `api/v1/account` and `api/v1/account-balance` endpoints in favor of the `api/v1/accounts` endpoints - Improved the performance of the code style check in the build workflow by skipping the warning-level rules of _ESLint_ - Refreshed the cryptocurrencies list -- Upgraded `yahoo-finance2` from version `4.0.2` to `4.0.5` +- Upgraded `undici` from version `8.12.2` to `8.12.3` ### Fixed - Fixed the double submission of forms in the account detail dialog, the create or update access dialog, the historical market data editor, the import activities dialog, the coupon system and the create asset profile dialog of the admin control panel +- Fixed an issue where the benchmarks in the markets overview were not updated after adding or deleting a benchmark - Fixed an issue where users could grant a private access to themselves - Fixed the status code of the endpoints to add and delete a benchmark if the asset profile does not exist - Fixed the git-hook via `husky` to lint and check the formatting of the uncommitted changes before a commit diff --git a/apps/api/src/services/benchmark/benchmark.service.spec.ts b/apps/api/src/services/benchmark/benchmark.service.spec.ts index 27124e89e4..6124ee9add 100644 --- a/apps/api/src/services/benchmark/benchmark.service.spec.ts +++ b/apps/api/src/services/benchmark/benchmark.service.spec.ts @@ -1,10 +1,33 @@ +import { PrismaService } from '@ghostfolio/api/services/prisma/prisma.service'; +import { PropertyService } from '@ghostfolio/api/services/property/property.service'; +import { RedisCacheService } from '@ghostfolio/api/services/redis-cache/redis-cache.service'; +import { PROPERTY_BENCHMARKS } from '@ghostfolio/common/config'; + +import { DataSource } from '@prisma/client'; + import { BenchmarkService } from './benchmark.service'; describe('BenchmarkService', () => { let benchmarkService: BenchmarkService; + let findFirst: jest.Mock; + let getByKey: jest.Mock; + let put: jest.Mock; + let remove: jest.Mock; + + beforeEach(() => { + findFirst = jest.fn(); + getByKey = jest.fn(); + put = jest.fn().mockResolvedValue(undefined); + remove = jest.fn().mockResolvedValue(true); - beforeAll(async () => { - benchmarkService = new BenchmarkService(null, null, null, null, null, null); + benchmarkService = new BenchmarkService( + null, + null, + { symbolProfile: { findFirst } } as unknown as PrismaService, + { getByKey, put } as unknown as PropertyService, + { remove } as unknown as RedisCacheService, + null + ); }); it('calculateChangeInPercentage', async () => { @@ -34,4 +57,78 @@ describe('BenchmarkService', () => { -0.1 ); }); + + describe('addBenchmark', () => { + it('stores the benchmark and removes the cached benchmarks', async () => { + findFirst.mockResolvedValue({ id: 'profile-id', name: 'S&P 500' }); + getByKey.mockResolvedValue([{ symbolProfileId: 'other-profile-id' }]); + + await benchmarkService.addBenchmark({ + dataSource: DataSource.YAHOO, + symbol: '^GSPC' + }); + + expect(put).toHaveBeenCalledWith({ + key: PROPERTY_BENCHMARKS, + value: JSON.stringify([ + { symbolProfileId: 'other-profile-id' }, + { symbolProfileId: 'profile-id' } + ]) + }); + expect(remove).toHaveBeenCalledWith('BENCHMARKS'); + expect(put.mock.invocationCallOrder[0]).toBeLessThan( + remove.mock.invocationCallOrder[0] + ); + }); + + it('keeps the cached benchmarks if the asset profile is not found', async () => { + findFirst.mockResolvedValue(null); + + const result = await benchmarkService.addBenchmark({ + dataSource: DataSource.YAHOO, + symbol: '^GSPC' + }); + + expect(result).toBeNull(); + expect(put).not.toHaveBeenCalled(); + expect(remove).not.toHaveBeenCalled(); + }); + }); + + describe('deleteBenchmark', () => { + it('stores the remaining benchmarks and removes the cached benchmarks', async () => { + findFirst.mockResolvedValue({ id: 'profile-id', name: 'S&P 500' }); + getByKey.mockResolvedValue([ + { symbolProfileId: 'other-profile-id' }, + { symbolProfileId: 'profile-id' } + ]); + + await benchmarkService.deleteBenchmark({ + dataSource: DataSource.YAHOO, + symbol: '^GSPC' + }); + + expect(put).toHaveBeenCalledWith({ + key: PROPERTY_BENCHMARKS, + value: JSON.stringify([{ symbolProfileId: 'other-profile-id' }]) + }); + expect(remove).toHaveBeenCalledWith('BENCHMARKS'); + expect(put.mock.invocationCallOrder[0]).toBeLessThan( + remove.mock.invocationCallOrder[0] + ); + }); + + it('keeps the cached benchmarks if the asset profile is not found', async () => { + findFirst.mockResolvedValue(null); + + const result = await benchmarkService.deleteBenchmark({ + dataSource: DataSource.YAHOO, + symbol: '^GSPC' + }); + + expect(result).toBeNull(); + expect(put).not.toHaveBeenCalled(); + expect(remove).not.toHaveBeenCalled(); + }); + }); }); diff --git a/apps/api/src/services/benchmark/benchmark.service.ts b/apps/api/src/services/benchmark/benchmark.service.ts index ea7bbaec12..e0120bf127 100644 --- a/apps/api/src/services/benchmark/benchmark.service.ts +++ b/apps/api/src/services/benchmark/benchmark.service.ts @@ -335,5 +335,7 @@ export class BenchmarkService { key: PROPERTY_BENCHMARKS, value: JSON.stringify(benchmarks) }); + + await this.redisCacheService.remove(this.CACHE_KEY_BENCHMARKS); } } diff --git a/package-lock.json b/package-lock.json index 85db3f7c67..93a2b316f8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "ghostfolio", - "version": "3.93.0", + "version": "3.94.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "ghostfolio", - "version": "3.93.0", + "version": "3.94.0", "hasInstallScript": true, "license": "AGPL-3.0", "dependencies": { @@ -104,7 +104,7 @@ "svgmap": "2.21.0", "tablemark": "4.1.0", "twitter-api-v2": "1.29.1", - "undici": "8.12.2", + "undici": "8.12.3", "uuid": "14.0.2", "yahoo-finance2": "4.0.5", "zod": "4.6.7", @@ -33742,9 +33742,9 @@ "license": "MIT" }, "node_modules/undici": { - "version": "8.12.2", - "resolved": "https://registry.npmjs.org/undici/-/undici-8.12.2.tgz", - "integrity": "sha512-XtuDWVdqTLr3NAxm2ly9/hU6kUsJOgGh1RASzMBbsw6aWCOaQzHdW+QQDfdERjfJ2V5vL5pRPa4RetO9UfivDg==", + "version": "8.12.3", + "resolved": "https://registry.npmjs.org/undici/-/undici-8.12.3.tgz", + "integrity": "sha512-+fdndUTwBP86cVjihTp21hZHo7d6oj1c/47XPA3lL8mM0XHs+C4EkcjmgRsFnFk2f/UONGDy9ItBItmXsLOQHw==", "license": "MIT", "engines": { "node": ">=22.19.0" diff --git a/package.json b/package.json index 4bc7fb34eb..27a010630b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ghostfolio", - "version": "3.93.0", + "version": "3.94.0", "homepage": "https://ghostfol.io", "license": "AGPL-3.0", "repository": "https://github.com/ghostfolio/ghostfolio", @@ -148,7 +148,7 @@ "svgmap": "2.21.0", "tablemark": "4.1.0", "twitter-api-v2": "1.29.1", - "undici": "8.12.2", + "undici": "8.12.3", "uuid": "14.0.2", "yahoo-finance2": "4.0.5", "zod": "4.6.7",