mirror of
https://github.com/directus/directus.git
synced 2026-02-08 00:15:04 -05:00
* Throw error on file upload if the number of uploaded files is 0 Fixes #12678 * Add unit test * Mock env * Fix mocks
36 lines
959 B
TypeScript
36 lines
959 B
TypeScript
// @ts-nocheck
|
|
|
|
jest.mock('../../src/cache');
|
|
jest.mock('../../src/database');
|
|
jest.mock('../../src/utils/validate-env');
|
|
|
|
import { multipartHandler } from '../../src/controllers/files';
|
|
import { InvalidPayloadException } from '../../src/exceptions/invalid-payload';
|
|
import { PassThrough } from 'stream';
|
|
|
|
import FormData from 'form-data';
|
|
|
|
describe('multipartHandler', () => {
|
|
it(`Errors out if request doesn't contain any files to upload`, () => {
|
|
const fakeForm = new FormData();
|
|
|
|
fakeForm.append('field', 'test');
|
|
|
|
const req = {
|
|
headers: fakeForm.getHeaders(),
|
|
is: jest.fn().mockReturnValue(true),
|
|
body: fakeForm.getBuffer(),
|
|
params: {},
|
|
pipe: (input) => stream.pipe(input),
|
|
};
|
|
|
|
const stream = new PassThrough();
|
|
stream.push(fakeForm.getBuffer());
|
|
|
|
multipartHandler(req, {}, (err) => {
|
|
expect(err.message).toBe('No files where included in the body');
|
|
expect(err).toBeInstanceOf(InvalidPayloadException);
|
|
});
|
|
});
|
|
});
|