Browse Source
Task/improve comment validation of MCP import tool (#8004)
Improve comment validation
pull/8006/head
Thomas Kaul
6 days ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with
32 additions and
1 deletions
-
apps/api/src/app/endpoints/mcp/mcp.schemas.spec.ts
-
apps/api/src/app/endpoints/mcp/mcp.schemas.ts
|
|
|
@ -1,4 +1,5 @@ |
|
|
|
import { |
|
|
|
COMMENT_MAXIMUM_LENGTH, |
|
|
|
DEFAULT_DATE_RANGE, |
|
|
|
MCP_MAX_ACTIVITIES, |
|
|
|
SEARCH_QUERY_MAXIMUM_LENGTH, |
|
|
|
@ -92,6 +93,30 @@ describe('IMPORT_ACTIVITIES_PARAMETERS', () => { |
|
|
|
return IMPORT_ACTIVITIES_PARAMETERS.safeParse({ activities }).success; |
|
|
|
} |
|
|
|
|
|
|
|
it(`Accepts a comment of ${COMMENT_MAXIMUM_LENGTH} characters with spaces at the start and the end`, () => { |
|
|
|
expect( |
|
|
|
parse([ |
|
|
|
createActivity({ comment: ` ${'A'.repeat(COMMENT_MAXIMUM_LENGTH)} ` }) |
|
|
|
]) |
|
|
|
).toBe(true); |
|
|
|
}); |
|
|
|
|
|
|
|
it(`Refuses a comment longer than ${COMMENT_MAXIMUM_LENGTH} characters`, () => { |
|
|
|
expect( |
|
|
|
parse([ |
|
|
|
createActivity({ comment: 'A'.repeat(COMMENT_MAXIMUM_LENGTH + 1) }) |
|
|
|
]) |
|
|
|
).toBe(false); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Removes spaces at the start and the end of a comment', () => { |
|
|
|
expect( |
|
|
|
IMPORT_ACTIVITIES_PARAMETERS.parse({ |
|
|
|
activities: [createActivity({ comment: ' note ' })] |
|
|
|
}).activities[0].comment |
|
|
|
).toBe('note'); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Refuses a currency in lower case', () => { |
|
|
|
expect(parse([createActivity({ currency: 'usd' })])).toBe(false); |
|
|
|
}); |
|
|
|
|
|
|
|
@ -1,5 +1,6 @@ |
|
|
|
import { DATE_RANGE_PATTERN } from '@ghostfolio/api/dtos/date-range-filter.dto'; |
|
|
|
import { |
|
|
|
COMMENT_MAXIMUM_LENGTH, |
|
|
|
DATE_RANGES, |
|
|
|
DEFAULT_DATE_RANGE, |
|
|
|
MCP_MAX_ACCOUNTS, |
|
|
|
@ -124,7 +125,12 @@ export const IMPORT_ACTIVITIES_PARAMETERS = z.object({ |
|
|
|
.min(1) |
|
|
|
.optional() |
|
|
|
.describe('The identifier of the account of the activity'), |
|
|
|
comment: z.string().optional().describe('The comment of the activity'), |
|
|
|
comment: z |
|
|
|
.string() |
|
|
|
.trim() |
|
|
|
.max(COMMENT_MAXIMUM_LENGTH) |
|
|
|
.optional() |
|
|
|
.describe('The comment of the activity'), |
|
|
|
currency: z |
|
|
|
.string() |
|
|
|
.refine(isValidCurrencyCode) |
|
|
|
|