-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
/
max-file-size.validator.spec.ts
56 lines (44 loc) 路 1.54 KB
/
max-file-size.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
54
55
56
import { expect } from 'chai';
import { MaxFileSizeValidator } from '../../../pipes';
describe('MaxFileSizeValidator', () => {
const oneKb = 1024;
describe('isValid', () => {
it('should return true when the file size is less than the maximum size', () => {
const maxFileSizeValidator = new MaxFileSizeValidator({
maxSize: oneKb,
});
const requestFile = {
size: 100,
};
expect(maxFileSizeValidator.isValid(requestFile)).to.equal(true);
});
it('should return false when the file size is greater than the maximum size', () => {
const maxFileSizeValidator = new MaxFileSizeValidator({
maxSize: oneKb,
});
const requestFile = {
size: oneKb + 1,
};
expect(maxFileSizeValidator.isValid(requestFile)).to.equal(false);
});
it('should return false when the file size is equal to the maximum size', () => {
const maxFileSizeValidator = new MaxFileSizeValidator({
maxSize: oneKb,
});
const requestFile = {
size: oneKb,
};
expect(maxFileSizeValidator.isValid(requestFile)).to.equal(false);
});
});
describe('buildErrorMessage', () => {
it('should return a string with the format "Validation failed (expected size is less than #maxSize")', () => {
const maxFileSizeValidator = new MaxFileSizeValidator({
maxSize: oneKb,
});
expect(maxFileSizeValidator.buildErrorMessage()).to.equal(
`Validation failed (expected size is less than ${oneKb})`,
);
});
});
});