Files
NodeBB/tests/user.js

49 lines
1.2 KiB
JavaScript
Raw Normal View History

2013-11-04 01:32:31 +02:00
// this test currently needs to talk to the redis database.
// get the redis config info from root directory's config.json:
var winston = require('winston');
process.on('uncaughtException', function (err) {
winston.error('Encountered error while running test suite: ' + err.message);
});
var assert = require('assert'),
db = require('../mocks/databasemock');
2013-11-04 01:32:31 +02:00
var User = require('../src/user');
describe('User', function() {
var userData;
beforeEach(function(){
userData = {
2014-03-06 14:51:43 -05:00
username: 'John Smith',
2013-11-04 01:32:31 +02:00
password: 'swordfish',
email: 'john@example.com',
callback: undefined
};
});
describe('when created', function() {
2014-03-06 14:51:43 -05:00
it('should be created properly', function(done) {
User.create({username: userData.username, password: userData.password, email: userData.email}, function(error,userId){
2013-11-04 01:32:31 +02:00
assert.equal(error, null, 'was created with error');
assert.ok(userId);
done();
});
});
it('should have a valid email, if using an email', function() {
2013-11-04 01:32:31 +02:00
assert.throws(
2014-03-06 14:51:43 -05:00
User.create({username: userData.username, password: userData.password, email: 'fakeMail'},function(){}),
2013-11-04 01:32:31 +02:00
Error,
'does not validate email'
);
});
});
after(function() {
db.flushdb();
2013-11-04 01:32:31 +02:00
});
2014-04-10 20:31:57 +01:00
});