HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux ip-10-0-8-47 6.8.0-1021-aws #23~22.04.1-Ubuntu SMP Tue Dec 10 16:31:58 UTC 2024 aarch64
User: ubuntu (1000)
PHP: 8.1.2-1ubuntu2.22
Disabled: NONE
Upload Files
File: /var/www/javago_test/node_modules/node-input-validator/test/rules/dateAfterToday.js
const assert = require('assert');

const moment = require('moment');
const { Validator } = require('../../lib/index');

describe('#dateAfterToday', () => {
  it('should pass with valida date', async () => {
    const v = new Validator(
      {
        dob: moment().add(2, 'days').format('YYYY-MM-DD'),
      }, {
        dob: 'required|dateFormat:YYYY-MM-DD|dateAfterToday:1,days',
      },
    );

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

  it('should pass with optional seed', async () => {
    const v = new Validator(
      {
        dob: moment().add(2, 'days').format('YYYY-MM-DD'),
      }, {
        dob: 'required|dateFormat:YYYY-MM-DD|dateAfterToday:1',
      },
    );

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

  it('should fail', async () => {
    const v = new Validator(
      {
        dob: '2019-02-28',
      }, {
        dob: 'required|dateFormat:YYYY-MM-DD|dateAfterToday:2,days',
      },
    );

    const matched = await v.check();

    assert.equal(matched, false);
  });

  it('message should exist', async () => {
    const v = new Validator(
      {
        dob: '2019-02-28',
      }, {
        dob: 'required|dateFormat:YYYY-MM-DD|dateAfterToday:2,days',
      },
    );

    const matched = await v.check();

    assert.equal(matched, false);
    assert.equal(
      v.errors.dob.message,
      v.getExistinParsedMessage({
        rule: 'dateAfterToday',
        value: '2019-02-28',
        attr: 'dob',
        args: ['2', 'days'],
      }),
    );
  });
});