|
|
@ -185,32 +185,38 @@ describe('Post\'s', function () {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('delete/restore/purge', function () {
|
|
|
|
describe('delete/restore/purge', function () {
|
|
|
|
var tid;
|
|
|
|
function createTopicWithReply(callback) {
|
|
|
|
var mainPid;
|
|
|
|
|
|
|
|
var replyPid;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var socketPosts = require('../src/socket.io/posts');
|
|
|
|
|
|
|
|
before(function (done) {
|
|
|
|
|
|
|
|
topics.post({
|
|
|
|
topics.post({
|
|
|
|
uid: voterUid,
|
|
|
|
uid: voterUid,
|
|
|
|
cid: cid,
|
|
|
|
cid: cid,
|
|
|
|
title: 'topic to delete/restore/purge',
|
|
|
|
title: 'topic to delete/restore/purge',
|
|
|
|
content: 'A post to delete/restore/purge'
|
|
|
|
content: 'A post to delete/restore/purge'
|
|
|
|
}, function (err, data) {
|
|
|
|
}, function (err, topicPostData) {
|
|
|
|
assert.ifError(err);
|
|
|
|
assert.ifError(err);
|
|
|
|
tid = data.topicData.tid;
|
|
|
|
|
|
|
|
mainPid = data.postData.pid;
|
|
|
|
|
|
|
|
topics.reply({
|
|
|
|
topics.reply({
|
|
|
|
uid: voterUid,
|
|
|
|
uid: voterUid,
|
|
|
|
tid: topicData.tid,
|
|
|
|
tid: topicPostData.topicData.tid,
|
|
|
|
timestamp: Date.now(),
|
|
|
|
timestamp: Date.now(),
|
|
|
|
content: 'A post to delete/restore and purge'
|
|
|
|
content: 'A post to delete/restore and purge'
|
|
|
|
}, function (err, data) {
|
|
|
|
}, function (err, replyData) {
|
|
|
|
assert.ifError(err);
|
|
|
|
assert.ifError(err);
|
|
|
|
replyPid = data.pid;
|
|
|
|
callback(topicPostData, replyData);
|
|
|
|
privileges.categories.give(['purge'], cid, 'registered-users', done);
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var tid;
|
|
|
|
|
|
|
|
var mainPid;
|
|
|
|
|
|
|
|
var replyPid;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var socketPosts = require('../src/socket.io/posts');
|
|
|
|
|
|
|
|
before(function (done) {
|
|
|
|
|
|
|
|
createTopicWithReply(function (topicPostData, replyData) {
|
|
|
|
|
|
|
|
tid = topicPostData.topicData.tid;
|
|
|
|
|
|
|
|
mainPid = topicPostData.postData.pid;
|
|
|
|
|
|
|
|
replyPid = replyData.pid;
|
|
|
|
|
|
|
|
privileges.categories.give(['purge'], cid, 'registered-users', done);
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should error with invalid data', function (done) {
|
|
|
|
it('should error with invalid data', function (done) {
|
|
|
@ -242,32 +248,53 @@ describe('Post\'s', function () {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should delete posts and topic', function (done) {
|
|
|
|
it('should delete posts', function (done) {
|
|
|
|
socketPosts.deletePosts({uid: globalModUid}, {pids: [replyPid, mainPid], tid: tid}, function (err) {
|
|
|
|
socketPosts.deletePosts({uid: globalModUid}, {pids: [replyPid, mainPid], tid: tid}, function (err) {
|
|
|
|
assert.ifError(err);
|
|
|
|
assert.ifError(err);
|
|
|
|
topics.getTopicField(tid, 'deleted', function (err, deleted) {
|
|
|
|
posts.getPostField(replyPid, 'deleted', function (err, deleted) {
|
|
|
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
|
|
|
assert.equal(parseInt(deleted, 10), 1);
|
|
|
|
|
|
|
|
posts.getPostField(mainPid, 'deleted', function (err, deleted) {
|
|
|
|
assert.ifError(err);
|
|
|
|
assert.ifError(err);
|
|
|
|
assert.equal(parseInt(deleted, 10), 1);
|
|
|
|
assert.equal(parseInt(deleted, 10), 1);
|
|
|
|
done();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should purge posts', function (done) {
|
|
|
|
it('should delete topic if last main post is deleted', function (done) {
|
|
|
|
var socketTopics = require('../src/socket.io/topics');
|
|
|
|
topics.post({uid: voterUid, cid: cid, title: 'test topic', content: 'test topic'}, function (err, data) {
|
|
|
|
socketTopics.restore({uid: globalModUid}, {tids: [tid], cid: cid}, function (err) {
|
|
|
|
|
|
|
|
assert.ifError(err);
|
|
|
|
assert.ifError(err);
|
|
|
|
socketPosts.purgePosts({uid: voterUid}, {pids: [replyPid, mainPid], tid: tid}, function (err) {
|
|
|
|
socketPosts.deletePosts({uid: globalModUid}, {pids: [data.postData.pid], tid: data.topicData.tid}, function (err) {
|
|
|
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
|
|
|
topics.getTopicField(data.topicData.tid, 'deleted', function (err, deleted) {
|
|
|
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
|
|
|
assert.equal(parseInt(deleted, 10), 1);
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('should purge posts and delete topic', function (done) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
createTopicWithReply(function (topicPostData, replyData) {
|
|
|
|
|
|
|
|
socketPosts.purgePosts({uid: voterUid}, {pids: [replyData.pid, topicPostData.postData.pid], tid: topicPostData.topicData.tid}, function (err) {
|
|
|
|
assert.ifError(err);
|
|
|
|
assert.ifError(err);
|
|
|
|
posts.exists('post:' + replyPid, function (err, exists) {
|
|
|
|
posts.exists('post:' + replyData.pid, function (err, exists) {
|
|
|
|
assert.ifError(err);
|
|
|
|
assert.ifError(err);
|
|
|
|
assert.equal(exists, false);
|
|
|
|
assert.equal(exists, false);
|
|
|
|
|
|
|
|
topics.getTopicField(topicPostData.topicData.tid, 'deleted', function (err, deleted) {
|
|
|
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
|
|
|
assert.equal(parseInt(deleted, 10), 1);
|
|
|
|
done();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('edit', function () {
|
|
|
|
describe('edit', function () {
|
|
|
|
var pid;
|
|
|
|
var pid;
|
|
|
|