openmaic-custom/tests/document/text-extractor.test.ts
jackefn 3b7a0ca0c0
feat(document): add multi-format course material upload (#741)
* feat(document): add multi-format course material upload

* fix(document): support office uploads with mineru cloud

* fix(document): handle mineru cloud office edge cases

* fix(document): align mineru cloud artifact metadata

---------

Co-authored-by: Yanpeng Wang <yanpg.wang@gmail.com>
2026-07-02 17:58:58 +08:00

59 lines
1.6 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { extractDocument } from '@/lib/document';
describe('plain text document extractor', () => {
it('extracts TXT content locally', async () => {
const artifact = await extractDocument({
buffer: Buffer.from('Hello OpenMAIC\nLine 2', 'utf-8'),
fileName: 'test.txt',
fileSize: 20,
mimeType: 'text/plain',
config: { providerId: 'plain-text' },
});
expect(artifact.metadata).toMatchObject({
fileName: 'test.txt',
mimeType: 'text/plain',
providerId: 'plain-text',
});
expect(artifact.blocks).toEqual([
{
id: 'text_1',
type: 'text',
text: 'Hello OpenMAIC\nLine 2',
},
]);
});
it('extracts Markdown content locally as markdown blocks', async () => {
const artifact = await extractDocument({
buffer: Buffer.from('# Title', 'utf-8'),
fileName: 'test.md',
fileSize: 7,
mimeType: 'text/markdown',
config: { providerId: 'plain-text' },
});
expect(artifact.blocks[0]).toMatchObject({
type: 'markdown',
text: '# Title',
});
});
it('detects UTF-16LE text from a BOM when MIME charset has been normalized away', async () => {
const artifact = await extractDocument({
buffer: Buffer.from([0xff, 0xfe, 0x60, 0x4f, 0x7d, 0x59]),
fileName: 'test.txt',
fileSize: 6,
mimeType: 'text/plain',
config: { providerId: 'plain-text' },
});
expect(artifact.blocks[0]).toMatchObject({
type: 'text',
text: '你好',
});
});
});