mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Small clean-up after Jest to Vitest switch in API (#16462)
Co-authored-by: Rijk van Zanten <rijkvanzanten@me.com>
This commit is contained in:
@@ -1,14 +1,11 @@
|
||||
// @ts-nocheck
|
||||
|
||||
import { multipartHandler } from './files';
|
||||
import { InvalidPayloadException } from '../exceptions/invalid-payload';
|
||||
import { PassThrough } from 'stream';
|
||||
import FormData from 'form-data';
|
||||
import { vi, describe, expect, it } from 'vitest';
|
||||
import { Request, Response } from 'express';
|
||||
|
||||
vi.mock('../../src/cache');
|
||||
vi.mock('../../src/database');
|
||||
vi.mock('../../src/utils/validate-env');
|
||||
|
||||
describe('multipartHandler', () => {
|
||||
it(`Errors out if request doesn't contain any files to upload`, () => {
|
||||
@@ -21,13 +18,14 @@ describe('multipartHandler', () => {
|
||||
is: vi.fn().mockReturnValue(true),
|
||||
body: fakeForm.getBuffer(),
|
||||
params: {},
|
||||
pipe: (input) => stream.pipe(input),
|
||||
};
|
||||
pipe: (input: NodeJS.WritableStream) => stream.pipe(input),
|
||||
} as unknown as Request;
|
||||
const res = {} as Response;
|
||||
|
||||
const stream = new PassThrough();
|
||||
stream.push(fakeForm.getBuffer());
|
||||
|
||||
multipartHandler(req, {}, (err) => {
|
||||
multipartHandler(req, res, (err) => {
|
||||
expect(err.message).toBe('No files where included in the body');
|
||||
expect(err).toBeInstanceOf(InvalidPayloadException);
|
||||
});
|
||||
@@ -48,13 +46,14 @@ describe('multipartHandler', () => {
|
||||
is: vi.fn().mockReturnValue(true),
|
||||
body: fakeForm.getBuffer(),
|
||||
params: {},
|
||||
pipe: (input) => stream.pipe(input),
|
||||
};
|
||||
pipe: (input: NodeJS.WritableStream) => stream.pipe(input),
|
||||
} as unknown as Request;
|
||||
const res = {} as Response;
|
||||
|
||||
const stream = new PassThrough();
|
||||
stream.push(fakeForm.getBuffer());
|
||||
|
||||
multipartHandler(req, {}, (err) => {
|
||||
multipartHandler(req, res, (err) => {
|
||||
expect(err.message).toBe('File is missing filename');
|
||||
expect(err).toBeInstanceOf(InvalidPayloadException);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user