Skip to content

Node.js based forum software built for the modern web

more user tests

barisusakli4369a6d2908b
diff --git a/src/controllers/user.js b/src/controllers/user.js
index c1049adffe..008faa4a06 100644
--- a/src/controllers/user.js
+++ b/src/controllers/user.js
@@ -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) {
diff --git a/test/controllers.js b/test/controllers.js
index b745004d59..e86ae0c00e 100644
--- a/test/controllers.js
+++ b/test/controllers.js
@@ -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: '[email protected]' }, 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/[email protected]', function (err, res, body) {
+ assert.ifError(err);
+ assert.equal(res.statusCode, 200);
+ assert(body);
+ done();
+ });
+ });
});
describe('account follow page', function () {