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:
Pascal Jufer
2022-11-15 23:20:45 +01:00
committed by GitHub
parent e79720735a
commit 45eb4941fc
13 changed files with 86 additions and 120 deletions

View File

@@ -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);
});