Advertisement
CSenshi

tmp_test

Apr 28th, 2020
705
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if (typeof require !== 'undefined') {
  2.   var Validator = require('../src/validator.js');
  3.   var expect = require('chai').expect;
  4. } else {
  5.   var Validator = window.Validator;
  6.   var expect = window.chai.expect;
  7. }
  8.  
  9. describe('IP Validation rules', function () {
  10.  
  11.   describe('IPv4 Validation rule', function () {
  12.     it('should accept localhost ipv4 addres', function () {
  13.       var validator = new Validator({
  14.         ipAddr: '127.0.0.1'
  15.       }, {
  16.         ipAddr: 'ipv4'
  17.       });
  18.       expect(validator.passes()).to.be.true;
  19.     });
  20.  
  21.     it('should accept maximum ip range ', function () {
  22.       var validator = new Validator({
  23.         ipAddr: '255.255.255.255'
  24.       }, {
  25.         ipAddr: 'ipv4'
  26.       });
  27.       expect(validator.passes()).to.be.true;
  28.     });
  29.  
  30.     it('should accept random ip address withing range ', function () {
  31.       var validator = new Validator({
  32.         ipAddr: '192.168.33.10'
  33.       }, {
  34.         ipAddr: 'ipv4'
  35.       });
  36.       expect(validator.passes()).to.be.true;
  37.     });
  38.  
  39.     it('should fail ip address containing non integer octants', function () {
  40.       var validator = new Validator({
  41.         ipAddr: '192.fail.33.10'
  42.       }, {
  43.         ipAddr: 'ipv4'
  44.       });
  45.       expect(validator.passes()).to.be.fail;
  46.     });
  47.  
  48.     it('should fail ip address containing non integer octants', function () {
  49.       var validator = new Validator({
  50.         ipAddr: '192.fail.33.10'
  51.       }, {
  52.         ipAddr: 'ipv4'
  53.       });
  54.       expect(validator.passes()).to.be.fail;
  55.     });
  56.  
  57.     it('should fail ip address more than 4 octants', function () {
  58.       var validator = new Validator({
  59.         ipAddr: '192.168.33.10.10'
  60.       }, {
  61.         ipAddr: 'ipv4'
  62.       });
  63.       expect(validator.passes()).to.be.fail;
  64.     });
  65.  
  66.     it('should fail ip address less than 4 octants', function () {
  67.       var validator = new Validator({
  68.         ipAddr: '192.168.10'
  69.       }, {
  70.         ipAddr: 'ipv4'
  71.       });
  72.       expect(validator.passes()).to.be.fail;
  73.     });
  74.  
  75.     it('should fail ip address which contains octant values more than 255', function () {
  76.       var validator = new Validator({
  77.         ipAddr: '256.168.10.0'
  78.       }, {
  79.         ipAddr: 'ipv4'
  80.       });
  81.       expect(validator.passes()).to.be.fail;
  82.     });
  83.  
  84.     it('should fail ip address which contains empty octants', function () {
  85.       var validator = new Validator({
  86.         ipAddr: '256...0'
  87.       }, {
  88.         ipAddr: 'ipv4'
  89.       });
  90.       expect(validator.passes()).to.be.fail;
  91.     });
  92.   });
  93. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement