mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
fix(spec): breaking tests
This commit is contained in:
@@ -17,8 +17,10 @@ describe('Admin Controllers', function () {
|
|||||||
var tid;
|
var tid;
|
||||||
var cid;
|
var cid;
|
||||||
var pid;
|
var pid;
|
||||||
|
let regularPid;
|
||||||
var adminUid;
|
var adminUid;
|
||||||
var regularUid;
|
var regularUid;
|
||||||
|
let regular2Uid;
|
||||||
var moderatorUid;
|
var moderatorUid;
|
||||||
var jar;
|
var jar;
|
||||||
|
|
||||||
@@ -36,24 +38,30 @@ describe('Admin Controllers', function () {
|
|||||||
regularUid: function (next) {
|
regularUid: function (next) {
|
||||||
user.create({ username: 'regular' }, next);
|
user.create({ username: 'regular' }, next);
|
||||||
},
|
},
|
||||||
|
regular2Uid: function (next) {
|
||||||
|
user.create({ username: 'regular2' }, next);
|
||||||
|
},
|
||||||
moderatorUid: function (next) {
|
moderatorUid: function (next) {
|
||||||
user.create({ username: 'moderator', password: 'modmod' }, next);
|
user.create({ username: 'moderator', password: 'modmod' }, next);
|
||||||
},
|
},
|
||||||
}, function (err, results) {
|
}, async function (err, results) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return done(err);
|
return done(err);
|
||||||
}
|
}
|
||||||
adminUid = results.adminUid;
|
adminUid = results.adminUid;
|
||||||
regularUid = results.regularUid;
|
regularUid = results.regularUid;
|
||||||
|
regular2Uid = results.regular2Uid;
|
||||||
moderatorUid = results.moderatorUid;
|
moderatorUid = results.moderatorUid;
|
||||||
cid = results.category.cid;
|
cid = results.category.cid;
|
||||||
|
|
||||||
topics.post({ uid: adminUid, title: 'test topic title', content: 'test topic content', cid: results.category.cid }, function (err, result) {
|
const adminPost = await topics.post({ uid: adminUid, title: 'test topic title', content: 'test topic content', cid: results.category.cid });
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
tid = result.topicData.tid;
|
tid = adminPost.topicData.tid;
|
||||||
pid = result.postData.pid;
|
pid = adminPost.postData.pid;
|
||||||
done();
|
|
||||||
});
|
const regularPost = await topics.post({ uid: regular2Uid, title: 'regular user\'s test topic title', content: 'test topic content', cid: results.category.cid });
|
||||||
|
regularPid = regularPost.postData.pid;
|
||||||
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -610,12 +618,22 @@ describe('Admin Controllers', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should error when you attempt to flag a privileged user\'s post', async () => {
|
||||||
|
var socketFlags = require('../src/socket.io/flags');
|
||||||
|
var oldValue = meta.config['min:rep:flag'];
|
||||||
|
try {
|
||||||
|
await socketFlags.create({ uid: regularUid }, { id: pid, type: 'post', reason: 'spam' });
|
||||||
|
} catch (err) {
|
||||||
|
assert.strictEqual(err.message, '[[error:cant-flag-privileged]]');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
it('should error with not enough reputation to flag', function (done) {
|
it('should error with not enough reputation to flag', function (done) {
|
||||||
var socketFlags = require('../src/socket.io/flags');
|
var socketFlags = require('../src/socket.io/flags');
|
||||||
var oldValue = meta.config['min:rep:flag'];
|
var oldValue = meta.config['min:rep:flag'];
|
||||||
meta.config['min:rep:flag'] = 1000;
|
meta.config['min:rep:flag'] = 1000;
|
||||||
socketFlags.create({ uid: regularUid }, { id: pid, type: 'post', reason: 'spam' }, function (err) {
|
socketFlags.create({ uid: regularUid }, { id: regularPid, type: 'post', reason: 'spam' }, function (err) {
|
||||||
assert.equal(err.message, '[[error:not-enough-reputation-to-flag]]');
|
assert.strictEqual(err.message, '[[error:not-enough-reputation-to-flag]]');
|
||||||
meta.config['min:rep:flag'] = oldValue;
|
meta.config['min:rep:flag'] = oldValue;
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -625,7 +643,7 @@ describe('Admin Controllers', function () {
|
|||||||
var socketFlags = require('../src/socket.io/flags');
|
var socketFlags = require('../src/socket.io/flags');
|
||||||
var oldValue = meta.config['min:rep:flag'];
|
var oldValue = meta.config['min:rep:flag'];
|
||||||
meta.config['min:rep:flag'] = 0;
|
meta.config['min:rep:flag'] = 0;
|
||||||
socketFlags.create({ uid: regularUid }, { id: pid, type: 'post', reason: 'spam' }, function (err, flagId) {
|
socketFlags.create({ uid: regularUid }, { id: regularPid, type: 'post', reason: 'spam' }, function (err, flagId) {
|
||||||
meta.config['min:rep:flag'] = oldValue;
|
meta.config['min:rep:flag'] = oldValue;
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
request(nconf.get('url') + '/api/flags/' + flagId, { jar: moderatorJar, json: true }, function (err, res, body) {
|
request(nconf.get('url') + '/api/flags/' + flagId, { jar: moderatorJar, json: true }, function (err, res, body) {
|
||||||
@@ -633,7 +651,7 @@ describe('Admin Controllers', function () {
|
|||||||
assert(body);
|
assert(body);
|
||||||
assert(body.reports);
|
assert(body.reports);
|
||||||
assert(Array.isArray(body.reports));
|
assert(Array.isArray(body.reports));
|
||||||
assert.equal(body.reports[0].reporter.username, 'regular');
|
assert.strictEqual(body.reports[0].reporter.username, 'regular');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user