1
This commit is contained in:
@@ -19,14 +19,24 @@ test('creation agent document input validation accepts supported text documents'
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
test('creation agent document input validation rejects unsupported documents', () => {
|
||||
test('creation agent document input validation accepts docx documents', () => {
|
||||
expect(() => {
|
||||
validateCreationAgentDocumentInputFile(
|
||||
new File(['binary'], '世界设定.docx', {
|
||||
type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||
}),
|
||||
);
|
||||
}).toThrow('暂时只支持 txt、md、csv、json 文本文档。');
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
test('creation agent document input validation rejects unsupported documents', () => {
|
||||
expect(() => {
|
||||
validateCreationAgentDocumentInputFile(
|
||||
new File(['binary'], '世界设定.pdf', {
|
||||
type: 'application/pdf',
|
||||
}),
|
||||
);
|
||||
}).toThrow('暂时只支持 txt、md、docx、csv、json 文档。');
|
||||
});
|
||||
|
||||
test('creation agent document input validation rejects oversized documents', () => {
|
||||
@@ -44,8 +54,8 @@ test('creation agent document input parse skips network for unsupported files',
|
||||
vi.stubGlobal('fetch', fetchSpy);
|
||||
|
||||
await expect(
|
||||
parseCreationAgentDocumentInput(new File(['binary'], '世界设定.docx')),
|
||||
).rejects.toThrow('暂时只支持 txt、md、csv、json 文本文档。');
|
||||
parseCreationAgentDocumentInput(new File(['binary'], '世界设定.pdf')),
|
||||
).rejects.toThrow('暂时只支持 txt、md、docx、csv、json 文档。');
|
||||
|
||||
expect(fetchSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -11,6 +11,7 @@ const SUPPORTED_DOCUMENT_INPUT_EXTENSIONS = new Set([
|
||||
'txt',
|
||||
'md',
|
||||
'markdown',
|
||||
'docx',
|
||||
'csv',
|
||||
'json',
|
||||
]);
|
||||
@@ -52,7 +53,7 @@ export function validateCreationAgentDocumentInputFile(file: File) {
|
||||
: '';
|
||||
|
||||
if (!extension || !SUPPORTED_DOCUMENT_INPUT_EXTENSIONS.has(extension)) {
|
||||
throw new Error('暂时只支持 txt、md、csv、json 文本文档。');
|
||||
throw new Error('暂时只支持 txt、md、docx、csv、json 文档。');
|
||||
}
|
||||
|
||||
if (file.size <= 0) {
|
||||
|
||||
Reference in New Issue
Block a user