From 3822183095f3d8a9761108e785264c8f57160a3a Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 27 Nov 2023 10:46:36 +0100 Subject: [PATCH] refs #5878 test: improve bodyValidator fn --- .../client/specs/bodyValidator.spec.js | 134 +++++++++++++++++- 1 file changed, 132 insertions(+), 2 deletions(-) diff --git a/modules/client/back/methods/client/specs/bodyValidator.spec.js b/modules/client/back/methods/client/specs/bodyValidator.spec.js index 716597f10..f4c84975f 100644 --- a/modules/client/back/methods/client/specs/bodyValidator.spec.js +++ b/modules/client/back/methods/client/specs/bodyValidator.spec.js @@ -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',