mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-08 22:45:25 +00:00
fix: improve file upload handling in prepare-request to use streaming (#5637)
* fix: improve file upload handling in prepare-request to use streaming * feat: add unit tests --------- Co-authored-by: Bijin Bruno <bijin@usebruno.com>
This commit is contained in:
50
packages/bruno-cli/tests/utils/filesystem.spec.js
Normal file
50
packages/bruno-cli/tests/utils/filesystem.spec.js
Normal file
@@ -0,0 +1,50 @@
|
||||
const { isLargeFile } = require('../../src/utils/filesystem');
|
||||
const fs = require('fs-extra');
|
||||
|
||||
describe('isLargeFile', () => {
|
||||
let existsSyncSpy;
|
||||
let lstatSyncSpy;
|
||||
let statSyncSpy;
|
||||
|
||||
beforeEach(() => {
|
||||
existsSyncSpy = jest.spyOn(fs, 'existsSync');
|
||||
lstatSyncSpy = jest.spyOn(fs, 'lstatSync');
|
||||
statSyncSpy = jest.spyOn(fs, 'statSync');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
it('should return false when file size is below default threshold (10MB)', () => {
|
||||
existsSyncSpy.mockReturnValue(true);
|
||||
lstatSyncSpy.mockReturnValue({ isFile: () => true });
|
||||
statSyncSpy.mockReturnValue({ size: 5 * 1024 * 1024 }); // 5MB
|
||||
|
||||
expect(isLargeFile('/path/small.bin')).toBe(false);
|
||||
});
|
||||
|
||||
it('should return true when file size is above default threshold (10MB)', () => {
|
||||
existsSyncSpy.mockReturnValue(true);
|
||||
lstatSyncSpy.mockReturnValue({ isFile: () => true });
|
||||
statSyncSpy.mockReturnValue({ size: 15 * 1024 * 1024 }); // 15MB
|
||||
|
||||
expect(isLargeFile('/path/large.bin')).toBe(true);
|
||||
});
|
||||
|
||||
it('should respect custom threshold (args true or false)', () => {
|
||||
existsSyncSpy.mockReturnValue(true);
|
||||
lstatSyncSpy.mockReturnValue({ isFile: () => true });
|
||||
statSyncSpy.mockReturnValue({ size: 50 });
|
||||
|
||||
expect(isLargeFile('/path/file.bin', 100)).toBe(false); // 50 < 100
|
||||
expect(isLargeFile('/path/file.bin', 10)).toBe(true); // 50 > 10
|
||||
});
|
||||
|
||||
it('should throw on invalid values (not a file)', () => {
|
||||
existsSyncSpy.mockReturnValue(false);
|
||||
lstatSyncSpy.mockReturnValue({ isFile: () => false });
|
||||
|
||||
expect(() => isLargeFile('/path/not-a-file.bin')).toThrow('File /path/not-a-file.bin is not a file');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user