From 302ceb665b2dd123d8c67efe05773646ab7aebbf Mon Sep 17 00:00:00 2001 From: John McLear Date: Mon, 29 Dec 2014 14:59:22 +0100 Subject: [PATCH 1/2] delay write to fix copypad -- bad practice but due to db.set not allowing callback --- src/node/db/Pad.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/node/db/Pad.js b/src/node/db/Pad.js index 94049ff74..2f5860f8f 100644 --- a/src/node/db/Pad.js +++ b/src/node/db/Pad.js @@ -461,7 +461,6 @@ Pad.prototype.copy = function copy(destinationID, force, callback) { // if the pad exists, we should abort, unless forced. function(callback) { - console.log("destinationID", destinationID, force); padManager.doesPadExists(destinationID, function (err, exists) { if(ERR(err, callback)) return; @@ -470,9 +469,9 @@ Pad.prototype.copy = function copy(destinationID, force, callback) { { if (!force) { - console.log("erroring out without force"); + console.error("erroring out without force"); callback(new customError("destinationID already exists","apierror")); - console.log("erroring out without force - after"); + console.error("erroring out without force - after"); return; } else // exists and forcing @@ -521,12 +520,9 @@ Pad.prototype.copy = function copy(destinationID, force, callback) { function(callback) { var revHead = _this.head; - //console.log(revHead); for(var i=0;i<=revHead;i++) { db.get("pad:"+sourceID+":revs:"+i, function (err, rev) { - //console.log("HERE"); - if (ERR(err, callback)) return; db.set("pad:"+destinationID+":revs:"+i, rev); }); @@ -538,10 +534,8 @@ Pad.prototype.copy = function copy(destinationID, force, callback) { function(callback) { var authorIDs = _this.getAllAuthors(); - authorIDs.forEach(function (authorID) { - console.log("authors"); authorManager.addPad(authorID, destinationID); }); @@ -555,7 +549,9 @@ Pad.prototype.copy = function copy(destinationID, force, callback) { if(destGroupID) db.setSub("group:" + destGroupID, ["pads", destinationID], 1); // Initialize the new pad (will update the listAllPads cache) - padManager.getPad(destinationID, null, callback) + setTimeout(function(){ + padManager.getPad(destinationID, null, callback) // this runs too early. + },10); } // series ], function(err) From c9b0c6896e2e6a4f20151df00edd3aa07d240e94 Mon Sep 17 00:00:00 2001 From: John McLear Date: Mon, 29 Dec 2014 15:08:30 +0100 Subject: [PATCH 2/2] move pad tests - still need to do copy pad and some other functionality IE force --- tests/backend/specs/api/pad.js | 128 +++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) diff --git a/tests/backend/specs/api/pad.js b/tests/backend/specs/api/pad.js index 700c498f6..a20c92335 100644 --- a/tests/backend/specs/api/pad.js +++ b/tests/backend/specs/api/pad.js @@ -61,6 +61,16 @@ describe('Permission', function(){ -> setText(padId) -> getLastEdited(padID) -- Should be when setText was performed -> padUsers(padID) -- Should be when setText was performed + + -> setText(padId, "hello world") + -> getLastEdited(padID) -- Should be when pad was made + -> getText(padId) -- Should be "hello world" + -> movePad(padID, newPadId) -- Should provide consistant pad data + -> getText(newPadId) -- Should be "hello world" + -> movePad(newPadID, originalPadId) -- Should provide consistant pad data + -> getText(originalPadId) -- Should be "hello world" + -> getLastEdited(padID) -- Should not be 0 + */ describe('deletePad', function(){ @@ -265,7 +275,125 @@ describe('padUsers', function(){ }); }) +describe('deletePad', function(){ + it('deletes a Pad', function(done) { + api.get(endPoint('deletePad')+"&padID="+testPadId) + .expect(function(res){ + if(res.body.code !== 0) throw new Error("Pad Deletion failed") + }) + .expect('Content-Type', /json/) + .expect(200, done) + }); +}) +var originalPadId = testPadId; +var newPadId = makeid(); + +describe('createPad', function(){ + it('creates a new Pad with text', function(done) { + api.get(endPoint('createPad')+"&padID="+testPadId) + .expect(function(res){ + if(res.body.code !== 0) throw new Error("Pad Creation failed") + }) + .expect('Content-Type', /json/) + .expect(200, done) + }); +}) + +describe('setText', function(){ + it('Sets text on a pad Id', function(done) { + api.get(endPoint('setText')+"&padID="+testPadId+"&text=hello world") + .expect(function(res){ + if(res.body.code !== 0) throw new Error("Pad Set Text failed") + }) + .expect('Content-Type', /json/) + .expect(200, done) + }); +}) + +describe('getText', function(){ + it('Gets text on a pad Id', function(done) { + api.get(endPoint('getText')+"&padID="+testPadId) + .expect(function(res){ + if(res.body.code !== 0) throw new Error("Pad Get Text failed") + if(res.body.data.text !== "hello world\n") throw new Error("Pad Text not set properly"); + }) + .expect('Content-Type', /json/) + .expect(200, done) + }); +}) + +describe('getLastEdited', function(){ + it('Gets when pad was last edited', function(done) { + api.get(endPoint('getLastEdited')+"&padID="+testPadId) + .expect(function(res){ + if(res.body.lastEdited === 0) throw new Error("Get Last Edited Failed") + }) + .expect('Content-Type', /json/) + .expect(200, done) + }); +}) + +describe('movePad', function(){ + it('Move a Pad to a different Pad ID', function(done) { + api.get(endPoint('movePad')+"&sourceID="+testPadId+"&destinationID="+newPadId+"&force=true") + .expect(function(res){ + console.log(res.body); + if(res.body.code !== 0) throw new Error("Moving Pad Failed") + }) + .expect('Content-Type', /json/) + .expect(200, done) + }); +}) + +describe('getText', function(){ + it('Gets text on a pad Id', function(done) { + api.get(endPoint('getText')+"&padID="+newPadId) + .expect(function(res){ + if(res.body.data.text !== "hello world\n") throw new Error("Pad Get Text failed") + }) + .expect('Content-Type', /json/) + .expect(200, done) + }); +}) + +describe('movePad', function(){ + it('Move a Pad to a different Pad ID', function(done) { + api.get(endPoint('movePad')+"&sourceID="+newPadId+"&destinationID="+testPadId+"&force=false") + .expect(function(res){ + if(res.body.code !== 0) throw new Error("Moving Pad Failed") + }) + .expect('Content-Type', /json/) + .expect(200, done) + }); +}) + +describe('getText', function(){ + it('Gets text on a pad Id', function(done) { + api.get(endPoint('getText')+"&padID="+testPadId) + .expect(function(res){ + if(res.body.data.text !== "hello world\n") throw new Error("Pad Get Text failed") + }) + .expect('Content-Type', /json/) + .expect(200, done) + }); +}) + +describe('getLastEdited', function(){ + it('Gets when pad was last edited', function(done) { + api.get(endPoint('getLastEdited')+"&padID="+testPadId) + .expect(function(res){ + if(res.body.lastEdited === 0) throw new Error("Get Last Edited Failed") + }) + .expect('Content-Type', /json/) + .expect(200, done) + }); +}) + +/* + -> movePadForce Test + +*/ var endPoint = function(point){ return '/api/'+apiVersion+'/'+point+'?apikey='+apiKey;