forked from nestjs/nest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
file-type.validator.spec.ts
53 lines (42 loc) 路 1.5 KB
/
file-type.validator.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { FileTypeValidator } from '../../../pipes';
import { expect } from 'chai';
describe('FileTypeValidator', () => {
describe('isValid', () => {
it('should return true when the file mimetype is the same as the specified', () => {
const fileTypeValidator = new FileTypeValidator({
fileType: 'image/jpeg',
});
const requestFile = {
mimetype: 'image/jpeg',
};
expect(fileTypeValidator.isValid(requestFile)).to.equal(true);
});
it('should return false when the file mimetype is different from the specified', () => {
const fileTypeValidator = new FileTypeValidator({
fileType: 'image/jpeg',
});
const requestFile = {
mimetype: 'image/png',
};
expect(fileTypeValidator.isValid(requestFile)).to.equal(false);
});
it('should return false when the file mimetype was not provided', () => {
const fileTypeValidator = new FileTypeValidator({
fileType: 'image/jpeg',
});
const requestFile = {};
expect(fileTypeValidator.isValid(requestFile)).to.equal(false);
});
});
describe('buildErrorMessage', () => {
it('should return a string with the format "Validation failed (expected type is #fileType)"', () => {
const fileType = 'image/jpeg';
const fileTypeValidator = new FileTypeValidator({
fileType,
});
expect(fileTypeValidator.buildErrorMessage()).to.equal(
`Validation failed (expected type is ${fileType})`,
);
});
});
});