Icontem

File: test/objectsValidation.js

Recommend this page to a friend!
  Classes of Harcharan Singh  >  Node Input Validator  >  test/objectsValidation.js  >  Download  
File: test/objectsValidation.js
Role: Example script
Content type: text/plain
Description: Example script
Class: Node Input Validator
Validate submitted input values in Node.js
Author: By
Last change:
Date: 4 months ago
Size: 1,425 bytes
 

Contents

Class file image Download
const assert = require('assert');

const Validator = require('../index');

let r = {};

describe('Objects', function () {



    it('Validate object properties', async () => {

        let v = new Validator(
            {
                product: { id: '1', name: '', price: '', active: 'yes' }
            },
            {
                'product': 'required|object',
                'product.id': 'required|integer',
                'product.name': 'required',
                'product.price': 'required|integer',
                'product.active': 'required|integer'
            });

        let matched = await v.check();

        v.errors.should.have.keys('product.name', 'product.price', 'product.active');

        assert.equal(matched, false);

    });

    it('Validate object:false case', async () => {

        let v = new Validator(
            {
                product: ''
            },
            {
                'product': 'required|object',

            });

        let matched = await v.check();

        v.errors.should.have.keys('product');

        assert.equal(matched, false);

    });

    it('Validate object:true case', async () => {

        let v = new Validator(
            {
                product: {}
            },
            {
                'product': 'required|object',

            });

        let matched = await v.check();


        assert.equal(matched, true);

    });



});