add test case
This commit is contained in:
parent
e26cb841fc
commit
88447f0db6
@ -1,6 +1,6 @@
|
|||||||
import { ArgumentMetadata, BadRequestException, Paramtype, ValidationPipe } from '@nestjs/common';
|
import { ArgumentMetadata, BadRequestException, Paramtype, ValidationPipe } from '@nestjs/common';
|
||||||
|
|
||||||
import { isObject, omit } from 'lodash';
|
import { isNil, isObject, isString, omit } from 'lodash';
|
||||||
|
|
||||||
import { DTO_VALIDATION_OPTIONS } from '../contants';
|
import { DTO_VALIDATION_OPTIONS } from '../contants';
|
||||||
import { deepMerge } from '../helpers';
|
import { deepMerge } from '../helpers';
|
||||||
@ -31,6 +31,9 @@ export class AppPipe extends ValidationPipe {
|
|||||||
if (isObject(val) && 'mimetype' in val) {
|
if (isObject(val) && 'mimetype' in val) {
|
||||||
return [key, omit(val, ['fields'])];
|
return [key, omit(val, ['fields'])];
|
||||||
}
|
}
|
||||||
|
if (key === 'name' && isString(val)) {
|
||||||
|
return [key, isNil(val) ? val : val.trim()];
|
||||||
|
}
|
||||||
return [key, val];
|
return [key, val];
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
@ -218,10 +218,7 @@ describe('nest app test', () => {
|
|||||||
body: { name: '' },
|
body: { name: '' },
|
||||||
});
|
});
|
||||||
expect(result.json()).toEqual({
|
expect(result.json()).toEqual({
|
||||||
message: [
|
message: ['The classification name cannot be empty'],
|
||||||
'The classification name cannot be empty',
|
|
||||||
'The length of the category name shall not exceed 25',
|
|
||||||
],
|
|
||||||
error: 'Bad Request',
|
error: 'Bad Request',
|
||||||
statusCode: 400,
|
statusCode: 400,
|
||||||
});
|
});
|
||||||
@ -234,10 +231,7 @@ describe('nest app test', () => {
|
|||||||
body: { name: ' ' },
|
body: { name: ' ' },
|
||||||
});
|
});
|
||||||
expect(result.json()).toEqual({
|
expect(result.json()).toEqual({
|
||||||
message: [
|
message: ['The classification name cannot be empty'],
|
||||||
'The classification name cannot be empty',
|
|
||||||
'The length of the category name shall not exceed 25',
|
|
||||||
],
|
|
||||||
error: 'Bad Request',
|
error: 'Bad Request',
|
||||||
statusCode: 400,
|
statusCode: 400,
|
||||||
});
|
});
|
||||||
@ -355,10 +349,7 @@ describe('nest app test', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
expect(result.json()).toEqual({
|
expect(result.json()).toEqual({
|
||||||
message: [
|
message: ['The format of the parent category ID is incorrect.'],
|
||||||
'The format of the parent category ID is incorrect.',
|
|
||||||
'The parent category does not exist',
|
|
||||||
],
|
|
||||||
error: 'Bad Request',
|
error: 'Bad Request',
|
||||||
statusCode: 400,
|
statusCode: 400,
|
||||||
});
|
});
|
||||||
@ -402,7 +393,7 @@ describe('nest app test', () => {
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: '/category',
|
url: '/category',
|
||||||
body: {
|
body: {
|
||||||
name: 'New Category',
|
name: 'Category with float customOrder',
|
||||||
customOrder: 5.5,
|
customOrder: 5.5,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -418,7 +409,7 @@ describe('nest app test', () => {
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: '/category',
|
url: '/category',
|
||||||
body: {
|
body: {
|
||||||
name: 'New Category',
|
name: 'Category with negative customOrder',
|
||||||
customOrder: -1,
|
customOrder: -1,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -448,7 +439,7 @@ describe('nest app test', () => {
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: '/category',
|
url: '/category',
|
||||||
body: {
|
body: {
|
||||||
name: 'New Category',
|
name: 'Category large customOrder',
|
||||||
customOrder: 999999,
|
customOrder: 999999,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -515,7 +506,11 @@ describe('nest app test', () => {
|
|||||||
body: { name: 'Updated Category' },
|
body: { name: 'Updated Category' },
|
||||||
});
|
});
|
||||||
expect(result.json()).toEqual({
|
expect(result.json()).toEqual({
|
||||||
message: ['The ID must be specified'],
|
message: [
|
||||||
|
'The ID must be specified',
|
||||||
|
'The ID format is incorrect',
|
||||||
|
'The Category names are duplicated',
|
||||||
|
],
|
||||||
error: 'Bad Request',
|
error: 'Bad Request',
|
||||||
statusCode: 400,
|
statusCode: 400,
|
||||||
});
|
});
|
||||||
@ -531,7 +526,7 @@ describe('nest app test', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
expect(result.json()).toEqual({
|
expect(result.json()).toEqual({
|
||||||
message: ['The ID format is incorrect'],
|
message: ['The ID format is incorrect', 'The Category names are duplicated'],
|
||||||
error: 'Bad Request',
|
error: 'Bad Request',
|
||||||
statusCode: 400,
|
statusCode: 400,
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user