Icontem

File: test/rules/dateBeforeToday.js

Recommend this page to a friend!
  Classes of Harcharan Singh  >  Node Input Validator  >  test/rules/dateBeforeToday.js  >  Download  
File: test/rules/dateBeforeToday.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: coverage improved
Date: 1 month ago
Size: 1,057 bytes
 

Contents

Class file image Download
const Validator = require('../../index');
const assert = require('assert');

const moment = require('moment');

//console.log('=================================================================');
//console.log(moment().subtract(1, 'days').format('YYYY-MM-DD'), moment().format('YYYY-MM-DD'))

describe('#dateBeforeToday', function () {

    it('should return true', async () => {

        let v, matched;

        v = new Validator({ dob: moment().subtract(1, 'days').format('YYYY-MM-DD') }, { dob: 'required|dateFormat:YYYY-MM-DD|dateBeforeToday:1' });

        matched = await v.check();
        assert.equal(matched, true);

    });


    it('should return false', async () => {

        let v = new Validator({ dob: moment().format('YYYY-MM-DD') }, { dob: 'required|dateFormat:YYYY-MM-DD|dateBeforeToday:2,days' });

        let matched = await v.check();

        assert.equal(matched, false);

        assert.equal(v.errors.dob.message, v.parseExistingMessageOnly('dateBeforeToday', 'dob', moment().format('YYYY-MM-DD'), ['2', 'days']));

    });

});