Browse Source
Feature/add MCP tool to get performance (part 2) (#8001)
Add MCP tool to get performance
pull/8002/head
Thomas Kaul
7 days ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with
48 additions and
3 deletions
-
apps/api/src/app/endpoints/mcp/mcp.schemas.spec.ts
-
apps/api/src/app/endpoints/mcp/mcp.service.spec.ts
-
apps/api/src/app/endpoints/mcp/mcp.service.ts
|
|
|
@ -68,6 +68,22 @@ describe('GET_PERFORMANCE_PARAMETERS', () => { |
|
|
|
false |
|
|
|
); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Refuses an empty symbol of the holding', () => { |
|
|
|
expect( |
|
|
|
GET_PERFORMANCE_PARAMETERS.safeParse({ |
|
|
|
holding: { dataSource: DataSource.YAHOO, symbol: '' } |
|
|
|
}).success |
|
|
|
).toBe(false); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Refuses a symbol of the holding that contains only spaces', () => { |
|
|
|
expect( |
|
|
|
GET_PERFORMANCE_PARAMETERS.safeParse({ |
|
|
|
holding: { dataSource: DataSource.YAHOO, symbol: ' ' } |
|
|
|
}).success |
|
|
|
).toBe(false); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
describe('IMPORT_ACTIVITIES_PARAMETERS', () => { |
|
|
|
|
|
|
|
@ -260,6 +260,36 @@ describe('McpService', () => { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Resolves the mask of the data source of the Ghostfolio data provider', async () => { |
|
|
|
configuration.DATA_SOURCES_GHOSTFOLIO_DATA_PROVIDER = [DataSource.YAHOO]; |
|
|
|
configuration.ENABLE_FEATURE_SUBSCRIPTION = true; |
|
|
|
|
|
|
|
await mcpService.getPerformance({ |
|
|
|
userId, |
|
|
|
holding: { dataSource: DataSource.GHOSTFOLIO, symbol: 'AAPL' }, |
|
|
|
range: 'max' |
|
|
|
}); |
|
|
|
|
|
|
|
expect(apiService.buildFiltersFromQueryParams).toHaveBeenCalledWith( |
|
|
|
expect.objectContaining({ filterByDataSource: DataSource.YAHOO }) |
|
|
|
); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Keeps the data source if the subscription is not enabled', async () => { |
|
|
|
configuration.DATA_SOURCES_GHOSTFOLIO_DATA_PROVIDER = [DataSource.YAHOO]; |
|
|
|
configuration.ENABLE_FEATURE_SUBSCRIPTION = false; |
|
|
|
|
|
|
|
await mcpService.getPerformance({ |
|
|
|
userId, |
|
|
|
holding: { dataSource: DataSource.GHOSTFOLIO, symbol: 'AAPL' }, |
|
|
|
range: 'max' |
|
|
|
}); |
|
|
|
|
|
|
|
expect(apiService.buildFiltersFromQueryParams).toHaveBeenCalledWith( |
|
|
|
expect.objectContaining({ filterByDataSource: DataSource.GHOSTFOLIO }) |
|
|
|
); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Gives the table of the performance of the filters in the range', async () => { |
|
|
|
expect( |
|
|
|
await mcpService.getPerformance({ userId, range: '2024' }) |
|
|
|
|
|
|
|
@ -104,10 +104,9 @@ export class McpService { |
|
|
|
userId |
|
|
|
}: z.infer<typeof GET_PERFORMANCE_PARAMETERS> & { userId: string }) { |
|
|
|
const filters = this.apiService.buildFiltersFromQueryParams({ |
|
|
|
...this.getHoldingFilterParameters({ holding }), |
|
|
|
filterByAccounts: accountIds, |
|
|
|
filterByAssetClasses: assetClasses, |
|
|
|
filterByDataSource: holding?.dataSource, |
|
|
|
filterBySymbol: holding?.symbol |
|
|
|
filterByAssetClasses: assetClasses |
|
|
|
}); |
|
|
|
|
|
|
|
const table = await this.portfolioTableService.getPerformanceTable({ |
|
|
|
|