more user tests

v1.18.x
barisusakli 8 years ago
parent bce1208e2f
commit 4369a6d290

@ -39,12 +39,17 @@ userController.getUserByEmail = function (req, res, next) {
};
function byType(type, req, res, next) {
userController.getUserDataByField(req.uid, type, req.params[type], function (err, data) {
if (err || !data) {
return next(err);
async.waterfall([
function (next) {
userController.getUserDataByField(req.uid, type, req.params[type], next);
},
function (data, next) {
if (!data) {
return next();
}
res.json(data);
}
res.json(data);
});
], next);
}
userController.getUserDataByField = function (callerUid, field, fieldValue, callback) {

@ -27,7 +27,7 @@ describe('Controllers', function () {
}, next);
},
user: function (next) {
user.create({ username: 'foo', password: 'barbar' }, next);
user.create({ username: 'foo', password: 'barbar', email: 'foo@test.com' }, next);
},
navigation: function (next) {
var navigation = require('../src/navigation/admin');
@ -911,6 +911,42 @@ describe('Controllers', function () {
},
], done);
});
it('should 404 if user does not exist', function (done) {
request(nconf.get('url') + '/api/user/email/doesnotexist', function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 404);
assert(body);
done();
});
});
it('should load user by uid', function (done) {
request(nconf.get('url') + '/api/user/uid/' + fooUid, function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body);
done();
});
});
it('should load user by username', function (done) {
request(nconf.get('url') + '/api/user/username/foo', function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body);
done();
});
});
it('should load user by email', function (done) {
request(nconf.get('url') + '/api/user/email/foo@test.com', function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body);
done();
});
});
});
describe('account follow page', function () {

Loading…
Cancel
Save