From 1f98c6ee4eab546da10d2732b4a534b1ec1e582b Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sat, 3 Oct 2026 17:01:45 +0200 Subject: [PATCH] Refactoring --- .../api/src/helper/data-source.helper.spec.ts | 22 +++++++++++++++ apps/api/src/helper/data-source.helper.ts | 28 +++++++++---------- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/apps/api/src/helper/data-source.helper.spec.ts b/apps/api/src/helper/data-source.helper.spec.ts index 02d979441e..3bfef82add 100644 --- a/apps/api/src/helper/data-source.helper.spec.ts +++ b/apps/api/src/helper/data-source.helper.spec.ts @@ -83,6 +83,28 @@ describe('DataSourceHelper', () => { }) ).toBeUndefined(); }); + + it('Decodes an encoded data source if the subscription is not enabled', () => { + expect( + transformDataSourceInRequest({ + configurationService: createConfigurationService({ + isSubscriptionEnabled: false + }), + dataSource: encodeDataSource(DataSource.COINGECKO) + }) + ).toBe(DataSource.COINGECKO); + }); + + it('Keeps the data source GHOSTFOLIO if the subscription is not enabled', () => { + expect( + transformDataSourceInRequest({ + configurationService: createConfigurationService({ + isSubscriptionEnabled: false + }), + dataSource: DataSource.GHOSTFOLIO + }) + ).toBe(DataSource.GHOSTFOLIO); + }); }); describe('transformDataSourceInResponse', () => { diff --git a/apps/api/src/helper/data-source.helper.ts b/apps/api/src/helper/data-source.helper.ts index 19a26816d9..fb0ded3f1f 100644 --- a/apps/api/src/helper/data-source.helper.ts +++ b/apps/api/src/helper/data-source.helper.ts @@ -48,6 +48,18 @@ function getGhostfolioDataSources({ : []; } +function getUnmaskedGhostfolioDataSource({ + dataSource, + ghostfolioDataSources +}: { + dataSource?: DataSource; + ghostfolioDataSources: string[]; +}) { + return dataSource === DataSource.GHOSTFOLIO && ghostfolioDataSources?.[0] + ? (ghostfolioDataSources[0] as DataSource) + : dataSource; +} + function hashDataSource(dataSource: DataSource) { return createHash('sha256').update(dataSource).digest('hex').slice(0, 8); } @@ -84,18 +96,6 @@ export function getMaskedGhostfolioDataSource({ : dataSource; } -export function getUnmaskedGhostfolioDataSource({ - dataSource, - ghostfolioDataSources -}: { - dataSource?: DataSource; - ghostfolioDataSources: string[]; -}) { - return dataSource === DataSource.GHOSTFOLIO && ghostfolioDataSources?.[0] - ? (ghostfolioDataSources[0] as DataSource) - : dataSource; -} - export function isDataGatheringSupported({ dataSource, scraperConfiguration @@ -118,8 +118,8 @@ export function isValidEncodedDataSource(encodedDataSource: string) { /** * Gives the data source of a request without a transformation: an encoded data - * source is decoded, and the mask of the Ghostfolio data provider is resolved - * (see the TransformDataSourceInRequestInterceptor) + * source is decoded, and the mask of the Ghostfolio data provider is resolved if + * the subscription is enabled (see the TransformDataSourceInRequestInterceptor) */ export function transformDataSourceInRequest({ configurationService,