Some checks failed
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
30 lines
1.5 KiB
TypeScript
30 lines
1.5 KiB
TypeScript
import type { IBinaryData, IRequestOptions } from 'n8n-workflow';
|
|
|
|
import { setFilename } from '../../V3/utils/binaryData';
|
|
|
|
describe('setFilename', () => {
|
|
it('returns filename from URI if fileName is missing and URI ends with fileExtension', () => {
|
|
const preparedBinaryData = { fileExtension: 'png' } as IBinaryData;
|
|
const requestOptions = { uri: 'https://example.com/image.png' } as IRequestOptions;
|
|
expect(setFilename(preparedBinaryData, requestOptions, undefined)).toBe('image.png');
|
|
});
|
|
|
|
it('returns constructed filename if fileName is missing and URI does not end with fileExtension', () => {
|
|
const preparedBinaryData = { fileExtension: 'jpg' } as IBinaryData;
|
|
const requestOptions = { uri: 'https://example.com/image.png' } as IRequestOptions;
|
|
expect(setFilename(preparedBinaryData, requestOptions, 'response')).toBe('response.jpg');
|
|
});
|
|
|
|
it('returns constructed filename with default "data" if responseFileName is undefined', () => {
|
|
const preparedBinaryData = { fileExtension: 'txt' } as IBinaryData;
|
|
const requestOptions = { uri: 'https://example.com/file' } as IRequestOptions;
|
|
expect(setFilename(preparedBinaryData, requestOptions, undefined)).toBe('data.txt');
|
|
});
|
|
|
|
it('returns fileName if it exists', () => {
|
|
const preparedBinaryData = { fileName: 'myfile.pdf', fileExtension: 'pdf' } as IBinaryData;
|
|
const requestOptions = { uri: 'https://example.com/file.pdf' } as IRequestOptions;
|
|
expect(setFilename(preparedBinaryData, requestOptions, 'response')).toBe('myfile.pdf');
|
|
});
|
|
});
|