Feature: Copy Pad without history (#4295)

New feature to copy a pad without copying entire history.  This is useful to perform a low CPU intensive operation while still copying current pad state.
This commit is contained in:
Joas Souza 2020-09-16 15:24:09 -03:00 committed by GitHub
parent b80a37173e
commit 8c04fe8775
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 259 additions and 36 deletions

View file

@ -427,6 +427,7 @@ describe('deletePad', function(){
var originalPadId = testPadId;
var newPadId = makeid();
var copiedPadId = makeid();
describe('createPad', function(){
it('creates a new Pad with text', function(done) {
@ -681,12 +682,126 @@ describe('createPad', function(){
});
})
describe('copyPad', function(){
it('copies the content of a existent pad', function(done) {
api.get(endPoint('copyPad')+"&sourceID="+testPadId+"&destinationID="+copiedPadId+"&force=true")
.expect(function(res){
if(res.body.code !== 0) throw new Error("Copy Pad Failed")
})
.expect('Content-Type', /json/)
.expect(200, done)
});
})
describe('copyPadWithoutHistory', function(){
var sourcePadId = makeid();
var newPad;
before(function(done) {
createNewPadWithHtml(sourcePadId, ulHtml, done);
});
beforeEach(function() {
newPad = makeid();
})
it('returns a successful response', function(done) {
api.get(endPoint('copyPadWithoutHistory')+"&sourceID="+sourcePadId+"&destinationID="+newPad+"&force=false")
.expect(function(res){
if(res.body.code !== 0) throw new Error("Copy Pad Without History Failed")
})
.expect('Content-Type', /json/)
.expect(200, done)
});
// this test validates if the source pad's text and attributes are kept
it('creates a new pad with the same content as the source pad', function(done) {
api.get(endPoint('copyPadWithoutHistory')+"&sourceID="+sourcePadId+"&destinationID="+newPad+"&force=false")
.expect(function(res){
if(res.body.code !== 0) throw new Error("Copy Pad Without History Failed")
})
.end(function() {
api.get(endPoint('getHTML')+"&padID="+newPad)
.expect(function(res){
var receivedHtml = res.body.data.html.replace("<br><br></body>", "</body>").toLowerCase();
if (receivedHtml !== expectedHtml) {
throw new Error(`HTML received from export is not the one we were expecting.
Received:
${receivedHtml}
Expected:
${expectedHtml}
Which is a slightly modified version of the originally imported one:
${ulHtml}`);
}
})
.expect(200, done);
});
});
context('when try copy a pad with a group that does not exist', function() {
var padId = makeid();
var padWithNonExistentGroup = `notExistentGroup$${padId}`
it('throws an error', function(done) {
api.get(endPoint('copyPadWithoutHistory')+"&sourceID="+sourcePadId+"&destinationID="+padWithNonExistentGroup+"&force=true")
.expect(function(res){
// code 1, it means an error has happened
if(res.body.code !== 1) throw new Error("It should report an error")
})
.expect(200, done);
})
});
context('when try copy a pad and destination pad already exist', function() {
var padIdExistent = makeid();
before(function(done) {
createNewPadWithHtml(padIdExistent, ulHtml, done);
});
context('and force is false', function() {
it('throws an error', function(done) {
api.get(endPoint('copyPadWithoutHistory')+"&sourceID="+sourcePadId+"&destinationID="+padIdExistent+"&force=false")
.expect(function(res){
// code 1, it means an error has happened
if(res.body.code !== 1) throw new Error("It should report an error")
})
.expect(200, done);
});
});
context('and force is true', function() {
it('returns a successful response', function(done) {
api.get(endPoint('copyPadWithoutHistory')+"&sourceID="+sourcePadId+"&destinationID="+padIdExistent+"&force=true")
.expect(function(res){
// code 1, it means an error has happened
if(res.body.code !== 0) throw new Error("Copy pad without history with force true failed")
})
.expect(200, done);
});
});
})
})
/*
-> movePadForce Test
*/
var createNewPadWithHtml = function(padId, html, cb) {
api.get(endPoint('createPad')+"&padID="+padId)
.end(function() {
api.post(endPoint('setHTML'))
.send({
"padID": padId,
"html": html,
})
.end(cb);
})
}
var endPoint = function(point, version){
version = version || apiVersion;
return '/api/'+version+'/'+point+'?apikey='+apiKey;