refs #5878 test: improve bodyValidator fn

This commit is contained in:
Javier Segarra 2023-11-27 10:46:36 +01:00
parent f8bf2e02de
commit 3822183095
1 changed files with 132 additions and 2 deletions

View File

@ -1,5 +1,136 @@
/* eslint-disable jasmine/no-spec-dupes */
const validatorBodyModel = require('../body_model_validator');
fdescribe('Validation Model', () => {
describe('should be number', () => {
it('success', () => {
let {isValid} = validatorBodyModel([{
arg: 'property',
type: 'number'
}], {property: 1});
expect(isValid).toBeTrue();
});
it('fail', () => {
let {isValid} = validatorBodyModel([{
arg: 'property',
type: 'number'
}], {property: null});
expect(isValid).toBeFalse();
});
});
describe('should be string', () => {
it('success as number', () => {
let {isValid} = validatorBodyModel([{
arg: 'property',
type: 'string'
}], {property: '1234'});
expect(isValid).toBeTrue();
});
it('success as string', () => {
let {isValid} = validatorBodyModel([{
arg: 'property',
type: 'string'
}], {property: 'null'});
expect(isValid).toBeTrue();
});
it('fail', () => {
let {isValid} = validatorBodyModel([{
arg: 'property',
type: 'string'
}], {property: null});
expect(isValid).toBeFalse();
});
});
describe('should be date', () => {
it('success', () => {
let {isValid} = validatorBodyModel([{
arg: 'property',
type: 'date'
}], {property: new Date()});
expect(isValid).toBeTrue();
});
it('fail', () => {
let {isValid} = validatorBodyModel([{
arg: 'property',
type: 'date'
}], {property: null});
expect(isValid).toBeFalse();
});
});
describe('should be boolean', () => {
it('success as true', () => {
let {isValid} = validatorBodyModel([{
arg: 'property',
type: 'boolean'
}], {property: true});
expect(isValid).toBeTrue();
});
it('success as false', () => {
let {isValid} = validatorBodyModel([{
arg: 'property',
type: 'boolean'
}], {property: false});
expect(isValid).toBeTrue();
});
it('fail', () => {
let {isValid} = validatorBodyModel([{
arg: 'property',
type: 'boolean'
}], {property: null});
expect(isValid).toBeFalse();
});
});
describe('should be any', () => {
it('success', () => {
let {isValid} = validatorBodyModel([{
arg: 'property',
type: 'any'
}], {property: '1234'});
expect(isValid).toBeTrue();
});
it('fail', () => {
let {isValid} = validatorBodyModel([{
arg: 'property',
type: 'any'
}], {property: null});
expect(isValid).toBeFalse();
});
});
});
describe('Validation Client Create', () => {
const newAccount = {
userName: 'Deadpool',
@ -120,7 +251,6 @@ describe('Validation Client Create', () => {
it('should not be able to create a user if exists', async() => {
let isValid = false;
let error;
isValid = validatorBodyModel(CLIENT_MODEL, newAccount).isValid;
@ -147,7 +277,7 @@ fdescribe('Validation Worker Create', () => {
// payMethodFk: 1,
// roleFk: 1
};
const WORKER_MODEL =[
const WORKER_MODEL = [
{
arg: 'fi',
type: 'string',