ban tests, user/info test

v1.18.x
barisusakli 8 years ago
parent d5ec36f45a
commit a4dfe608e9

@ -97,7 +97,7 @@ module.exports = function (User) {
User.getBannedReason = function (uid, callback) {
// Grabs the latest ban reason
db.getSortedSetRevRange('banned:' + uid + ':reasons', 0, 1, function (err, reasons) {
db.getSortedSetRevRange('banned:' + uid + ':reasons', 0, 0, function (err, reasons) {
if (err) {
return callback(err);
}

@ -18,6 +18,7 @@ describe('Admin Controllers', function () {
var cid;
var pid;
var adminUid;
var regularUid;
var jar;
before(function (done) {
@ -28,21 +29,18 @@ describe('Admin Controllers', function () {
description: 'Test category created by testing script'
}, next);
},
user: function (next) {
async.waterfall([
function (next) {
user.create({username: 'admin', password: 'barbar'}, next);
},
function (_uid, next) {
adminUid = _uid;
next();
}
], next);
adminUid: function (next) {
user.create({username: 'admin', password: 'barbar'}, next);
},
regularUid: function (next) {
user.create({username: 'regular'}, next);
}
}, function (err, results) {
if (err) {
return done(err);
}
adminUid = results.adminUid;
regularUid = results.regularUid;
cid = results.category.cid;
topics.post({uid: adminUid, title: 'test topic title', content: 'test topic content', cid: results.category.cid}, function (err, result) {
@ -115,6 +113,19 @@ describe('Admin Controllers', function () {
});
});
it('should load info page for a user', function (done) {
request(nconf.get('url') + '/api/user/regular/info', {jar: jar, json: true}, function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body.history);
assert(Array.isArray(body.history.flags));
assert(Array.isArray(body.history.bans));
assert(Array.isArray(body.history.reasons));
assert(Array.isArray(body.sessions));
done();
});
});
after(function (done) {
db.emptydb(done);
});

@ -18,12 +18,14 @@ var user = require('../src/user');
var groups = require('../src/groups');
var categories = require('../src/categories');
describe('socket.io', function () {
var io;
var cid;
var tid;
var adminUid;
var regularUid;
before(function (done) {
async.series([
@ -38,6 +40,7 @@ describe('socket.io', function () {
return done(err);
}
adminUid = data[0];
regularUid = data[1];
cid = data[2].cid;
groups.join('administrators', data[0], done);
@ -132,6 +135,42 @@ describe('socket.io', function () {
});
});
it('should ban a user', function (done) {
var socketUser = require('../src/socket.io/user');
socketUser.banUsers({uid: adminUid}, {uids: [regularUid], reason: 'spammer'}, function (err) {
assert.ifError(err);
user.getLatestBanInfo(regularUid, function (err, data) {
assert.ifError(err);
assert(data.uid);
assert(data.timestamp);
assert(data.hasOwnProperty('expiry'));
assert(data.hasOwnProperty('expiry_readable'));
assert.equal(data.reason, 'spammer');
done();
});
});
});
it('should return ban reason', function (done) {
user.getBannedReason(regularUid, function (err, reason) {
assert.ifError(err);
assert.equal(reason, 'spammer');
done();
});
});
it('should unban a user', function (done) {
var socketUser = require('../src/socket.io/user');
socketUser.unbanUsers({uid: adminUid}, [regularUid], function (err) {
assert.ifError(err);
user.isBanned(regularUid, function (err, isBanned) {
assert.ifError(err);
assert(!isBanned);
done();
});
});
});
after(function (done) {
db.emptydb(done);
});

Loading…
Cancel
Save