flag controller tests

This commit is contained in:
Barış Soner Uşaklı
2017-05-09 14:31:32 -04:00
parent 5a9b7b673a
commit bf78786a68
4 changed files with 128 additions and 57 deletions

View File

@@ -18,6 +18,7 @@ describe('Admin Controllers', function () {
var pid;
var adminUid;
var regularUid;
var moderatorUid;
var jar;
before(function (done) {
@@ -35,12 +36,16 @@ describe('Admin Controllers', function () {
regularUid: function (next) {
user.create({ username: 'regular' }, next);
},
moderatorUid: function (next) {
user.create({ username: 'moderator', password: 'modmod' }, next);
},
}, function (err, results) {
if (err) {
return done(err);
}
adminUid = results.adminUid;
regularUid = results.regularUid;
moderatorUid = results.moderatorUid;
cid = results.category.cid;
topics.post({ uid: adminUid, title: 'test topic title', content: 'test topic content', cid: results.category.cid }, function (err, result) {
@@ -128,7 +133,7 @@ describe('Admin Controllers', function () {
});
it('should 404 for edit/email page if user does not exist', function (done) {
request(nconf.get('url') + '/api/user/doesnotexist/edit/email', { jar: jar, json: true }, function (err, res, body) {
request(nconf.get('url') + '/api/user/doesnotexist/edit/email', { jar: jar, json: true }, function (err, res) {
assert.ifError(err);
assert.equal(res.statusCode, 404);
done();
@@ -446,6 +451,74 @@ describe('Admin Controllers', function () {
});
});
describe('mods page', function () {
var moderatorJar;
before(function (done) {
helpers.loginUser('moderator', 'modmod', function (err, _jar) {
assert.ifError(err);
moderatorJar = _jar;
groups.join('cid:' + cid + ':privileges:mods', moderatorUid, done);
});
});
it('should error with no privileges', function (done) {
request(nconf.get('url') + '/api/flags', { json: true }, function (err, res, body) {
assert.ifError(err);
assert.equal(body.error, '[[error:no-privileges]]');
done();
});
});
it('should load flags page data', function (done) {
request(nconf.get('url') + '/api/flags', { jar: moderatorJar, json: true }, function (err, res, body) {
assert.ifError(err);
assert(body);
assert(body.flags);
assert(body.categories);
assert(body.filters);
assert.equal(body.categories[cid], 'Test Category');
assert.equal(body.filters.cid.indexOf(cid), -1);
done();
});
});
it('should return invalid data if flag does not exist', function (done) {
request(nconf.get('url') + '/api/flags/123123123', { jar: moderatorJar, json: true }, function (err, res, body) {
assert.ifError(err);
assert.equal(body.error, '[[error:invalid-data]]');
done();
});
});
it('should error with not enough reputation to flag', function (done) {
var socketFlags = require('../src/socket.io/flags');
socketFlags.create({ uid: regularUid }, { id: pid, type: 'post', reason: 'spam' }, function (err) {
assert.equal(err.message, '[[error:not-enough-reputation-to-flag]]');
done();
});
});
it('should return flag details', function (done) {
var meta = require('../src/meta');
var socketFlags = require('../src/socket.io/flags');
var oldValue = meta.config['privileges:flag'];
meta.config['privileges:flag'] = 0;
socketFlags.create({ uid: regularUid }, { id: pid, type: 'post', reason: 'spam' }, function (err, data) {
meta.config['privileges:flag'] = oldValue;
assert.ifError(err);
request(nconf.get('url') + '/api/flags/' + data.flagId, { jar: moderatorJar, json: true }, function (err, res, body) {
assert.ifError(err);
assert(body);
assert.equal(body.reporter.username, 'regular');
done();
});
});
});
});
after(function (done) {
db.emptydb(done);
});