first commit
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
import { encodeBinaryData, processResponseData } from '../GenericFunctions';
|
||||
|
||||
describe('Mistral OCR Generic Functions', () => {
|
||||
describe('encodeBinaryData', () => {
|
||||
const binaryBuffer = Buffer.from('testdata');
|
||||
const base64 = binaryBuffer.toString('base64');
|
||||
|
||||
const context = {
|
||||
getNodeParameter: jest.fn(),
|
||||
helpers: {
|
||||
assertBinaryData: jest.fn(),
|
||||
getBinaryDataBuffer: jest.fn(),
|
||||
},
|
||||
} as any;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('should encode binary data to a data URL', async () => {
|
||||
context.getNodeParameter.mockReturnValue('binaryProp1');
|
||||
context.helpers.assertBinaryData.mockReturnValue({
|
||||
mimeType: 'image/png',
|
||||
fileName: 'file.png',
|
||||
});
|
||||
context.helpers.getBinaryDataBuffer.mockResolvedValue(binaryBuffer);
|
||||
|
||||
const result = await encodeBinaryData.call(context, 0);
|
||||
|
||||
expect(context.getNodeParameter).toHaveBeenCalledWith('binaryProperty', 0);
|
||||
expect(context.helpers.assertBinaryData).toHaveBeenCalledWith(0, 'binaryProp1');
|
||||
expect(context.helpers.getBinaryDataBuffer).toHaveBeenCalledWith(0, 'binaryProp1');
|
||||
|
||||
expect(result).toEqual({
|
||||
dataUrl: `data:image/png;base64,${base64}`,
|
||||
fileName: 'file.png',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('processResponseData', () => {
|
||||
it('should extract text and page count from pages', () => {
|
||||
const input = {
|
||||
pages: [
|
||||
{ markdown: 'Page 1 markdown', text: 'Page 1 text' },
|
||||
{ markdown: 'Page 2 markdown', text: 'Page 2 text' },
|
||||
],
|
||||
otherProp: 'test',
|
||||
};
|
||||
|
||||
const result = processResponseData(input);
|
||||
|
||||
expect(result.extractedText).toBe('Page 1 markdown\n\nPage 2 markdown');
|
||||
expect(result.pageCount).toBe(2);
|
||||
expect(result.otherProp).toBe('test');
|
||||
});
|
||||
|
||||
it('should handle empty pages array', () => {
|
||||
const input = { pages: [] };
|
||||
|
||||
const result = processResponseData(input);
|
||||
|
||||
expect(result.extractedText).toBe('');
|
||||
expect(result.pageCount).toBe(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user