Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Commit

Permalink
Merge pull request #799 from lirantal/feature/users_module_tests_4
Browse files Browse the repository at this point in the history
Adding suite of tests for the e-mail validation field in the users model
  • Loading branch information
lirantal committed Aug 14, 2015
2 parents 7200426 + 89050d5 commit d9a8647
Showing 1 changed file with 255 additions and 0 deletions.
255 changes: 255 additions & 0 deletions modules/users/tests/server/user.server.model.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down

0 comments on commit d9a8647

Please sign in to comment.