This repository has been archived by the owner on Aug 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #799 from lirantal/feature/users_module_tests_4
Adding suite of tests for the e-mail validation field in the users model
- Loading branch information
Showing
1 changed file
with
255 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -155,6 +155,261 @@ describe('User Model Unit Tests:', function () { | |
|
||
}); | ||
|
||
describe("User E-mail Validation Tests", function() { | ||
it('should not allow invalid email address - "123"', function (done) { | ||
var _user = new User(user); | ||
|
||
_user.email = '123'; | ||
_user.save(function (err) { | ||
if (!err) { | ||
_user.remove(function (err_remove) { | ||
should.not.exist(err_remove); | ||
done(); | ||
}); | ||
} else { | ||
should.exist(err); | ||
done(); | ||
} | ||
}); | ||
|
||
}); | ||
|
||
it('should not allow invalid email address - "123@123"', function (done) { | ||
var _user = new User(user); | ||
|
||
_user.email = '123@123'; | ||
_user.save(function (err) { | ||
if (!err) { | ||
_user.remove(function (err_remove) { | ||
should.not.exist(err_remove); | ||
done(); | ||
}); | ||
} else { | ||
should.exist(err); | ||
done(); | ||
} | ||
}); | ||
|
||
}); | ||
|
||
it('should not allow invalid email address - "123.com"', function (done) { | ||
var _user = new User(user); | ||
|
||
_user.email = '123.com'; | ||
_user.save(function (err) { | ||
if (!err) { | ||
_user.remove(function (err_remove) { | ||
should.not.exist(err_remove); | ||
done(); | ||
}); | ||
} else { | ||
should.exist(err); | ||
done(); | ||
} | ||
}); | ||
|
||
}); | ||
|
||
it('should not allow invalid email address - "@123.com"', function (done) { | ||
var _user = new User(user); | ||
|
||
_user.email = '@123.com'; | ||
_user.save(function (err) { | ||
if (!err) { | ||
_user.remove(function (err_remove) { | ||
should.not.exist(err_remove); | ||
done(); | ||
}); | ||
} else { | ||
should.exist(err); | ||
done(); | ||
} | ||
}); | ||
|
||
}); | ||
|
||
it('should not allow invalid email address - "abc@[email protected]"', function (done) { | ||
var _user = new User(user); | ||
|
||
_user.email = 'abc@[email protected]'; | ||
_user.save(function (err) { | ||
if (!err) { | ||
_user.remove(function (err_remove) { | ||
should.not.exist(err_remove); | ||
done(); | ||
}); | ||
} else { | ||
should.exist(err); | ||
done(); | ||
} | ||
}); | ||
|
||
}); | ||
|
||
it('should not allow invalid characters in email address - "abc~@#$%^&*()[email protected]"', function (done) { | ||
var _user = new User(user); | ||
|
||
_user.email = 'abc~@#$%^&*()[email protected]'; | ||
_user.save(function (err) { | ||
if (!err) { | ||
_user.remove(function (err_remove) { | ||
should.not.exist(err_remove); | ||
done(); | ||
}); | ||
} else { | ||
should.exist(err); | ||
done(); | ||
} | ||
}); | ||
|
||
}); | ||
|
||
it('should not allow space characters in email address - "abc [email protected]"', function (done) { | ||
var _user = new User(user); | ||
|
||
_user.email = 'abc [email protected]'; | ||
_user.save(function (err) { | ||
if (!err) { | ||
_user.remove(function (err_remove) { | ||
should.not.exist(err_remove); | ||
done(); | ||
}); | ||
} else { | ||
should.exist(err); | ||
done(); | ||
} | ||
}); | ||
|
||
}); | ||
|
||
it('should not allow single quote characters in email address - "abc\'[email protected]"', function (done) { | ||
var _user = new User(user); | ||
|
||
_user.email = 'abc\'[email protected]'; | ||
_user.save(function (err) { | ||
if (!err) { | ||
_user.remove(function (err_remove) { | ||
should.not.exist(err_remove); | ||
done(); | ||
}); | ||
} else { | ||
should.exist(err); | ||
done(); | ||
} | ||
}); | ||
|
||
}); | ||
|
||
it('should not allow doudble quote characters in email address - "abc\"[email protected]"', function (done) { | ||
var _user = new User(user); | ||
|
||
_user.email = 'abc\"[email protected]'; | ||
_user.save(function (err) { | ||
if (!err) { | ||
_user.remove(function (err_remove) { | ||
should.not.exist(err_remove); | ||
done(); | ||
}); | ||
} else { | ||
should.exist(err); | ||
done(); | ||
} | ||
}); | ||
|
||
}); | ||
|
||
it('should not allow double dotted characters in email address - "[email protected]"', function (done) { | ||
var _user = new User(user); | ||
|
||
_user.email = '[email protected]'; | ||
_user.save(function (err) { | ||
if (!err) { | ||
_user.remove(function (err_remove) { | ||
should.not.exist(err_remove); | ||
done(); | ||
}); | ||
} else { | ||
should.exist(err); | ||
done(); | ||
} | ||
}); | ||
|
||
}); | ||
|
||
it('should allow valid email address - "[email protected]"', function (done) { | ||
var _user = new User(user); | ||
|
||
_user.email = '[email protected]'; | ||
_user.save(function (err) { | ||
if (!err) { | ||
_user.remove(function (err_remove) { | ||
should.not.exist(err_remove); | ||
done(); | ||
}); | ||
} else { | ||
should.exist(err); | ||
done(); | ||
} | ||
}); | ||
|
||
}); | ||
|
||
it('should allow valid email address - "[email protected]"', function (done) { | ||
var _user = new User(user); | ||
|
||
_user.email = '[email protected]'; | ||
_user.save(function (err) { | ||
if (!err) { | ||
_user.remove(function (err_remove) { | ||
should.not.exist(err_remove); | ||
done(); | ||
}); | ||
} else { | ||
should.exist(err); | ||
done(); | ||
} | ||
}); | ||
|
||
}); | ||
|
||
it('should allow valid email address - "[email protected]"', function (done) { | ||
var _user = new User(user); | ||
|
||
_user.email = '[email protected]'; | ||
_user.save(function (err) { | ||
if (!err) { | ||
_user.remove(function (err_remove) { | ||
should.not.exist(err_remove); | ||
done(); | ||
}); | ||
} else { | ||
should.exist(err); | ||
done(); | ||
} | ||
}); | ||
|
||
}); | ||
|
||
it('should allow valid email address - "[email protected]"', function (done) { | ||
var _user = new User(user); | ||
|
||
_user.email = '[email protected]'; | ||
_user.save(function (err) { | ||
if (!err) { | ||
_user.remove(function (err_remove) { | ||
should.not.exist(err_remove); | ||
done(); | ||
}); | ||
} else { | ||
should.exist(err); | ||
done(); | ||
} | ||
}); | ||
|
||
}); | ||
|
||
}); | ||
|
||
after(function (done) { | ||
User.remove().exec(done); | ||
}); | ||
|