@ -185,32 +185,38 @@ describe('Post\'s', function () {
} ) ;
describe ( 'delete/restore/purge' , function ( ) {
var tid ;
var mainPid ;
var replyPid ;
var socketPosts = require ( '../src/socket.io/posts' ) ;
before ( function ( done ) {
function createTopicWithReply ( callback ) {
topics . post ( {
uid : voterUid ,
cid : cid ,
title : 'topic to delete/restore/purge' ,
content : 'A post to delete/restore/purge'
} , function ( err , d ata) {
} , function ( err , topicPostD ata) {
assert . ifError ( err ) ;
tid = data . topicData . tid ;
mainPid = data . postData . pid ;
topics . reply ( {
uid : voterUid ,
tid : topic Data. tid ,
tid : topic PostData. topic Data. tid ,
timestamp : Date . now ( ) ,
content : 'A post to delete/restore and purge'
} , function ( err , d ata) {
} , function ( err , replyD ata) {
assert . ifError ( err ) ;
replyPid = data . pid ;
privileges . categories . give ( [ 'purge' ] , cid , 'registered-users' , done ) ;
callback ( topicPostData , replyData ) ;
} ) ;
} ) ;
}
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 ) {
@ -242,31 +248,52 @@ 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 ) {
assert . ifError ( err ) ;
topics. getTopicField ( t id, 'deleted' , function ( err , deleted ) {
posts. getPostField ( replyP id, 'deleted' , function ( err , deleted ) {
assert . ifError ( err ) ;
assert . equal ( parseInt ( deleted , 10 ) , 1 ) ;
done ( ) ;
posts . getPostField ( mainPid , 'deleted' , function ( err , deleted ) {
assert . ifError ( err ) ;
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 ) {
it ( 'should delete topic if last main post is deleted' , function ( done ) {
topics . post ( { uid : voterUid , cid : cid , title : 'test topic' , content : 'test topic' } , function ( err , data ) {
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 ) ;
posts. exists ( 'post:' + replyPid , function ( err , exists ) {
topics. getTopicField ( data . topicData . tid , 'deleted' , function ( err , deleted ) {
assert . ifError ( err ) ;
assert . equal ( exists , false ) ;
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 ) ;
posts . exists ( 'post:' + replyData . pid , function ( err , exists ) {
assert . ifError ( err ) ;
assert . equal ( exists , false ) ;
topics . getTopicField ( topicPostData . topicData . tid , 'deleted' , function ( err , deleted ) {
assert . ifError ( err ) ;
assert . equal ( parseInt ( deleted , 10 ) , 1 ) ;
done ( ) ;
} ) ;
} ) ;
} ) ;
} ) ;
} ) ;
} ) ;
describe ( 'edit' , function ( ) {