mirror of
https://gitlab.silvrtree.co.uk/martind2000/obrandDBWork.git
synced 2025-01-10 21:45:08 +00:00
342 lines
5.6 KiB
JavaScript
342 lines
5.6 KiB
JavaScript
/**
|
|
*
|
|
* User: Martin Donnelly
|
|
* Date: 2016-03-09
|
|
* Time: 14:37
|
|
*
|
|
*/
|
|
"use strict";
|
|
var mdValidate = require('node-validator');
|
|
|
|
var should = require('should');
|
|
var assert = require('assert');
|
|
var expect = require('expect');
|
|
|
|
var phone = [
|
|
'A',
|
|
'AA',
|
|
'AAA',
|
|
'AAAA',
|
|
'AAAAA',
|
|
'AAAAAA',
|
|
'0',
|
|
'01',
|
|
'012',
|
|
'0123',
|
|
'01234',
|
|
'012345',
|
|
'0123456',
|
|
'01234567',
|
|
'012345678',
|
|
'01134960000',
|
|
'01134960500',
|
|
'01134960999',
|
|
'01144960000',
|
|
'01144960500',
|
|
'01144960999',
|
|
'01154960000',
|
|
'01154960500',
|
|
'01154960999',
|
|
'01164960000',
|
|
'01164960500',
|
|
'01164960999',
|
|
'01174960000',
|
|
'01174960500',
|
|
'01174960999',
|
|
'01184960000',
|
|
'01184960500',
|
|
'01184960999',
|
|
'01214960000',
|
|
'01214960500',
|
|
'01214960999',
|
|
'01314960000',
|
|
'01314960500',
|
|
'01314960999',
|
|
'01414960000',
|
|
'01414960500',
|
|
'01414960999',
|
|
'01514960000',
|
|
'01514960500',
|
|
'01514960999',
|
|
'01614960000',
|
|
'01614960500',
|
|
'01614960999',
|
|
'02079460000',
|
|
'02079460500',
|
|
'02079460999',
|
|
'01914980000',
|
|
'01914980500',
|
|
'01914980999',
|
|
'02890180000',
|
|
'02890180500',
|
|
'02890180999',
|
|
'02920180000',
|
|
'02920180500',
|
|
'02920180999',
|
|
'01632960000',
|
|
'01632960500',
|
|
'01632960999',
|
|
'07700900000',
|
|
'07700900500',
|
|
'07700900999',
|
|
'08081570000',
|
|
'08081570555',
|
|
'08081570999',
|
|
'09098790000',
|
|
'09098790500',
|
|
'09098790999',
|
|
'03069990000',
|
|
'03069990500',
|
|
'03069990999',
|
|
'08002323636',
|
|
'09002323636',
|
|
'06002323636',
|
|
"00254745856",
|
|
"+254745856"
|
|
];
|
|
|
|
var validPhone = ['01389703002', '07944577934', '01412807000', '02071539996'];
|
|
|
|
var postcodes = [
|
|
'A',
|
|
'AA',
|
|
'AAA',
|
|
'AAAA',
|
|
'AAAAA',
|
|
'AAAAAA',
|
|
'Q1 1AA',
|
|
'V1 1AA',
|
|
'X1 1AA',
|
|
'M1 CAA',
|
|
'M1 IAA',
|
|
'M1 KAA',
|
|
'M1 MAA',
|
|
'M1 OAA',
|
|
'M1 VAA',
|
|
|
|
'Q60 1NW',
|
|
'V60 1NW',
|
|
'X60 1NW',
|
|
'M60 1CW',
|
|
'M60 1IW',
|
|
'M60 1KW',
|
|
'M60 1MW',
|
|
'M60 1OW',
|
|
'M60 1VW',
|
|
'M60 1NC',
|
|
'M60 1NI',
|
|
'M60 1NK',
|
|
'M60 1NM',
|
|
'M60 1NO',
|
|
'M60 1NV',
|
|
|
|
'QR2 6XH',
|
|
'VR2 6XH',
|
|
'XR2 6XH',
|
|
'CI2 6XH',
|
|
'CJ2 6XH',
|
|
'CZ2 6XH',
|
|
'CR2 6CH',
|
|
'CR2 6IH',
|
|
'CR2 6KH',
|
|
'CR2 6MH',
|
|
'CR2 6OH',
|
|
'CR2 6VH',
|
|
'CR2 6XC',
|
|
'CR2 6XI',
|
|
'CR2 6XK',
|
|
'CR2 6XM',
|
|
'CR2 6XO',
|
|
'CR2 6XV',
|
|
|
|
'QN55 1PT',
|
|
'VN55 1PT',
|
|
'XN55 1PT',
|
|
'DI55 1PT',
|
|
'DJ55 1PT',
|
|
'DZ55 1PT',
|
|
'DN55 1CT',
|
|
'DN55 1IT',
|
|
'DN55 1KT',
|
|
'DN55 1MT',
|
|
'DN55 1OT',
|
|
'DN55 1VT',
|
|
'DN55 1PC',
|
|
'DN55 1PI',
|
|
'DN55 1PK',
|
|
'DN55 1PM',
|
|
'D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A'
|
|
|
|
];
|
|
|
|
// taken from http://blogs.msdn.com/b/testing123/archive/2009/02/05/email-address-test-cases.aspx
|
|
// having difficulty invalidating /*'あいうえお@domain.com',*/
|
|
// Several test cases for the email address have been removed as they should really be fixed by the mail system
|
|
// and they would be costly to fix in code at the moment
|
|
|
|
var invalidEmail = [
|
|
'plainaddress',
|
|
'#@%^%#$@#$@#.com',
|
|
'@domain.com',
|
|
'Joe Smith <email@domain.com>',
|
|
'email.domain.com',
|
|
'email@domain@domain.com',
|
|
'.email@domain.com',
|
|
'email.@domain.com',
|
|
'email..email@domain.com',
|
|
'email@domain.com (Joe Smith)',
|
|
'email@domain',
|
|
'email@-domain.com',
|
|
/*'email@domain.web',*/
|
|
'email@111.222.333.44444',
|
|
'email@domain..com'
|
|
];
|
|
|
|
var validEmail = [
|
|
'email@domain.com',
|
|
'firstname.lastname@domain.com',
|
|
'email@subdomain.domain.com',
|
|
'firstname+lastname@domain.com',
|
|
'email@123.123.123.123',
|
|
/*'email@[123.123.123.123]',*/
|
|
/*'"email"@domain.com',*/
|
|
'1234567890@domain.com',
|
|
'email@domain-one.com',
|
|
'_______@domain.com',
|
|
/*'email@domain.name',*/
|
|
'email@domain.co.uk',
|
|
'firstname-lastname@domain.com'
|
|
];
|
|
|
|
var emailOne = ['m@g.com', 'm@g.co.uk', 'bob@g.com'];
|
|
var emailTwo = ['m@g.co.uk', 'bob@g.com', 'm@g.com'];
|
|
|
|
describe('MD-Validator', function() {
|
|
it('should not validate an incorrect email address', function(done) {
|
|
|
|
for (var i in invalidEmail) {
|
|
mdValidate.Email(invalidEmail[i]).should.not.be.ok();
|
|
|
|
}
|
|
done();
|
|
});
|
|
|
|
it('should validate a correct email address', function(done) {
|
|
|
|
for (var i in validEmail) {
|
|
mdValidate.Email(validEmail[i]).should.be.ok();
|
|
|
|
}
|
|
done();
|
|
});
|
|
|
|
it('should not validate an incorrect phone number', function(done) {
|
|
|
|
for (var i in phone) {
|
|
mdValidate.checkUKTelephone(phone[i]).should.not.be.ok();
|
|
|
|
}
|
|
done();
|
|
});
|
|
|
|
it('should validate a correct phone number', function(done) {
|
|
|
|
for (var i in validPhone) {
|
|
mdValidate.checkUKTelephone(validPhone[i]).should.be.ok();
|
|
|
|
}
|
|
done();
|
|
});
|
|
|
|
it('should not validate an incorrect postcode', function(done) {
|
|
|
|
for (var i in postcodes) {
|
|
mdValidate.checkPostCode(postcodes[i]).should.not.be.ok();
|
|
|
|
}
|
|
done();
|
|
});
|
|
|
|
it('should validate a correct postcode', function(done) {
|
|
|
|
for (var i in validPostcodes) {
|
|
mdValidate.checkPostCode(validPostcodes[i]).should.be.ok();
|
|
|
|
}
|
|
done();
|
|
});
|
|
|
|
});
|