mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-05-07 01:05:36 +02:00
Merge branch 'master' into develop
This commit is contained in:
@@ -437,6 +437,14 @@ describe('Admin Controllers', function () {
|
||||
});
|
||||
|
||||
|
||||
it('should load /posts/flags', function (done) {
|
||||
request(nconf.get('url') + '/api/posts/flags', {jar: jar, json: true}, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert(body);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
after(function (done) {
|
||||
db.emptydb(done);
|
||||
});
|
||||
|
||||
@@ -162,26 +162,68 @@ describe('Post\'s', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('post tools', function () {
|
||||
var socketPosts = require('../src/socket.io/posts');
|
||||
|
||||
it('should error if data is invalid', function (done) {
|
||||
socketPosts.loadPostTools({uid: globalModUid}, null, function (err) {
|
||||
assert.equal(err.message, '[[error:invalid-data]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should load post tools', function (done) {
|
||||
socketPosts.loadPostTools({uid: globalModUid}, {pid: postData.pid, cid: cid}, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert(data.posts.display_edit_tools);
|
||||
assert(data.posts.display_delete_tools);
|
||||
assert(data.posts.display_moderator_tools);
|
||||
assert(data.posts.display_move_tools);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('delete/restore/purge', function () {
|
||||
var pid;
|
||||
var tid;
|
||||
var mainPid;
|
||||
var replyPid;
|
||||
|
||||
var socketPosts = require('../src/socket.io/posts');
|
||||
before(function (done) {
|
||||
topics.reply({
|
||||
topics.post({
|
||||
uid: voterUid,
|
||||
tid: topicData.tid,
|
||||
timestamp: Date.now(),
|
||||
content: 'A post to delete/restore and purge'
|
||||
cid: cid,
|
||||
title: 'topic to delete/restore/purge',
|
||||
content: 'A post to delete/restore/purge'
|
||||
}, function (err, data) {
|
||||
assert.ifError(err);
|
||||
pid = data.pid;
|
||||
privileges.categories.give(['purge'], cid, 'registered-users', done);
|
||||
tid = data.topicData.tid;
|
||||
mainPid = data.postData.pid;
|
||||
topics.reply({
|
||||
uid: voterUid,
|
||||
tid: topicData.tid,
|
||||
timestamp: Date.now(),
|
||||
content: 'A post to delete/restore and purge'
|
||||
}, function (err, data) {
|
||||
assert.ifError(err);
|
||||
replyPid = data.pid;
|
||||
privileges.categories.give(['purge'], cid, 'registered-users', done);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should error with invalid data', function (done) {
|
||||
socketPosts.delete({uid: voterUid}, null, function (err) {
|
||||
assert.equal(err.message, '[[error:invalid-data]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should delete a post', function (done) {
|
||||
socketPosts.delete({uid: voterUid}, {pid: pid, tid: topicData.tid}, function (err) {
|
||||
socketPosts.delete({uid: voterUid}, {pid: replyPid, tid: tid}, function (err) {
|
||||
assert.ifError(err);
|
||||
posts.getPostField(pid, 'deleted', function (err, isDeleted) {
|
||||
posts.getPostField(replyPid, 'deleted', function (err, isDeleted) {
|
||||
assert.ifError(err);
|
||||
assert.equal(parseInt(isDeleted, 10), 1);
|
||||
done();
|
||||
@@ -190,9 +232,9 @@ describe('Post\'s', function () {
|
||||
});
|
||||
|
||||
it('should restore a post', function (done) {
|
||||
socketPosts.restore({uid: voterUid}, {pid: pid, tid: topicData.tid}, function (err) {
|
||||
socketPosts.restore({uid: voterUid}, {pid: replyPid, tid: tid}, function (err) {
|
||||
assert.ifError(err);
|
||||
posts.getPostField(pid, 'deleted', function (err, isDeleted) {
|
||||
posts.getPostField(replyPid, 'deleted', function (err, isDeleted) {
|
||||
assert.ifError(err);
|
||||
assert.equal(parseInt(isDeleted, 10), 0);
|
||||
done();
|
||||
@@ -200,16 +242,31 @@ describe('Post\'s', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should purge a post', function (done) {
|
||||
socketPosts.purge({uid: voterUid}, {pid: pid}, function (err) {
|
||||
it('should delete posts and topic', function (done) {
|
||||
socketPosts.deletePosts({uid: globalModUid}, {pids: [replyPid, mainPid], tid: tid}, function (err) {
|
||||
assert.ifError(err);
|
||||
posts.exists('post:' + pid, function (err, exists) {
|
||||
topics.getTopicField(tid, 'deleted', function (err, deleted) {
|
||||
assert.ifError(err);
|
||||
assert.equal(exists, false);
|
||||
assert.equal(parseInt(deleted, 10), 1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should purge posts', function (done) {
|
||||
var socketTopics = require('../src/socket.io/topics');
|
||||
socketTopics.restore({uid: globalModUid}, {tids: [tid], cid: cid}, function (err) {
|
||||
assert.ifError(err);
|
||||
socketPosts.purgePosts({uid: voterUid}, {pids: [replyPid, mainPid], tid: tid}, function (err) {
|
||||
assert.ifError(err);
|
||||
posts.exists('post:' + replyPid, function (err, exists) {
|
||||
assert.ifError(err);
|
||||
assert.equal(exists, false);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('edit', function () {
|
||||
|
||||
@@ -61,7 +61,7 @@ describe('Search', function () {
|
||||
cid: cid1,
|
||||
title: 'nodebb mongodb bugs',
|
||||
content: 'avocado cucumber apple orange fox',
|
||||
tags: ['nodebb', 'bug', 'plugin', 'nodebb-plugin']
|
||||
tags: ['nodebb', 'bug', 'plugin', 'nodebb-plugin', 'jquery']
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
@@ -73,7 +73,7 @@ describe('Search', function () {
|
||||
cid: cid2,
|
||||
title: 'java mongodb redis',
|
||||
content: 'avocado cucumber carrot armadillo',
|
||||
tags: ['nodebb', 'bug', 'plugin', 'nodebb-plugin']
|
||||
tags: ['nodebb', 'bug', 'plugin', 'nodebb-plugin', 'javascript']
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
@@ -155,6 +155,18 @@ describe('Search', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should search with tags filter', function (done) {
|
||||
search.search({
|
||||
query: 'mongodb',
|
||||
searchIn: 'titles',
|
||||
hasTags: ['nodebb', 'javascript']
|
||||
}, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert.equal(data.posts[0].tid, topic2Data.tid);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
after(function (done) {
|
||||
db.emptydb(done);
|
||||
});
|
||||
|
||||
@@ -364,12 +364,54 @@ describe('socket.io', function () {
|
||||
|
||||
it('should return error', function (done) {
|
||||
var socketAdmin = require('../src/socket.io/admin');
|
||||
socketAdmin.before({uid: 10}, 'someMethod', {}, function (err) {
|
||||
assert.equal(err.message, '[[error:no-privileges]]');
|
||||
done();
|
||||
});
|
||||
socketAdmin.before({uid: 10}, 'someMethod', {}, function (err) {
|
||||
assert.equal(err.message, '[[error:no-privileges]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should get room stats', function (done) {
|
||||
var socketAdmin = require('../src/socket.io/admin');
|
||||
|
||||
io.emit('meta.rooms.enter', {enter: 'topic_1'}, function (err) {
|
||||
assert.ifError(err);
|
||||
socketAdmin.rooms.getAll({uid: 10}, {}, function (err) {
|
||||
assert.ifError(err);
|
||||
setTimeout(function () {
|
||||
socketAdmin.rooms.getAll({uid: 10}, {}, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert(data.hasOwnProperty('onlineGuestCount'));
|
||||
assert(data.hasOwnProperty('onlineRegisteredCount'));
|
||||
assert(data.hasOwnProperty('socketCount'));
|
||||
assert(data.hasOwnProperty('topics'));
|
||||
assert(data.hasOwnProperty('users'));
|
||||
assert.equal(data.topics['1'].title, 'test topic title');
|
||||
done();
|
||||
});
|
||||
}, 1000);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should get room stats', function (done) {
|
||||
var socketAdmin = require('../src/socket.io/admin');
|
||||
|
||||
io.emit('meta.rooms.enter', {enter: 'category_1'}, function (err) {
|
||||
assert.ifError(err);
|
||||
socketAdmin.rooms.getAll({uid: 10}, {}, function (err) {
|
||||
assert.ifError(err);
|
||||
setTimeout(function () {
|
||||
socketAdmin.rooms.getAll({uid: 10}, {}, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert.equal(data.users.category, 1);
|
||||
done();
|
||||
});
|
||||
}, 1000);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
after(function (done) {
|
||||
db.emptydb(done);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user