Add backend tests for new API functions

These new functions are:
* getSavedRevisionsCount
* listSavedRevisions
* saveRevision

+ typo fixing in backend tests
This commit is contained in:
Luc Didry 2015-02-25 01:05:58 +01:00
parent 845788c39d
commit 92022e493e
2 changed files with 117 additions and 29 deletions

View File

@ -63,6 +63,9 @@ Pad.prototype.getSavedRevisionsList = function getSavedRevisionsList() {
for(var rev in this.savedRevisions){
savedRev.push(this.savedRevisions[rev].revNum);
}
savedRev.sort(function(a, b) {
return a - b;
});
return savedRev;
};

View File

@ -48,33 +48,38 @@ describe('Permission', function(){
-> deletePad -- This gives us a guaranteed clear environment
-> createPad
-> getRevisions -- Should be 0
-> getHTML -- Should be the default pad text in HTML format
-> deletePad -- Should just delete a pad
-> getHTML -- Should return an error
-> createPad(withText)
-> getText -- Should have the text specified above as the pad text
-> setText
-> getText -- Should be the text set before
-> getRevisions -- Should be 0 still?
-> padUsersCount -- Should be 0
-> getReadOnlyId -- Should be a value
-> listAuthorsOfPad(padID) -- should be empty array?
-> getLastEdited(padID) -- Should be when pad was made
-> setText(padId)
-> getLastEdited(padID) -- Should be when setText was performed
-> padUsers(padID) -- Should be when setText was performed
-> setText(padId, "hello world")
-> getSavedRevisionsCount(padID) -- Should be 0
-> listSavedRevisions(padID) -- Should be an empty array
-> getHTML -- Should be the default pad text in HTML format
-> deletePad -- Should just delete a pad
-> getHTML -- Should return an error
-> createPad(withText)
-> getText -- Should have the text specified above as the pad text
-> setText
-> getText -- Should be the text set before
-> getRevisions -- Should be 0 still?
-> saveRevision
-> getSavedRevisionsCount(padID) -- Should be 0 still?
-> listSavedRevisions(padID) -- Should be an empty array still ?
-> padUsersCount -- Should be 0
-> getReadOnlyId -- Should be a value
-> listAuthorsOfPad(padID) -- should be empty array?
-> 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
-> setHTML(padID) -- Should fail on invalid HTML
-> setHTML(padID) *3 -- Should fail on invalid HTML
-> getHTML(padID) -- Should return HTML close to posted HTML
-> 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
-> setHTML(padID) -- Should fail on invalid HTML
-> setHTML(padID) *3 -- Should fail on invalid HTML
-> getHTML(padID) -- Should return HTML close to posted HTML
*/
@ -109,11 +114,35 @@ describe('getRevisionsCount', function(){
});
})
describe('getSavedRevisionsCount', function(){
it('gets saved revisions count of Pad', function(done) {
api.get(endPoint('getSavedRevisionsCount')+"&padID="+testPadId)
.expect(function(res){
if(res.body.code !== 0) throw new Error("Unable to get Saved Revisions Count");
if(res.body.data.savedRevisions !== 0) throw new Error("Incorrect Saved Revisions Count");
})
.expect('Content-Type', /json/)
.expect(200, done)
});
})
describe('listSavedRevisions', function(){
it('gets saved revision list of Pad', function(done) {
api.get(endPoint('listSavedRevisions')+"&padID="+testPadId)
.expect(function(res){
if(res.body.code !== 0) throw new Error("Unable to get Saved Revisions List");
if(!res.body.data.savedRevisions.equals([])) throw new Error("Incorrect Saved Revisions List");
})
.expect('Content-Type', /json/)
.expect(200, done)
});
})
describe('getHTML', function(){
it('get the HTML of Pad', function(done) {
api.get(endPoint('getHTML')+"&padID="+testPadId)
.expect(function(res){
if(res.body.data.html.length <= 1) throw new Error("Unable to get Revision Count");
if(res.body.data.html.length <= 1) throw new Error("Unable to get the HTML");
})
.expect('Content-Type', /json/)
.expect(200, done)
@ -187,16 +216,50 @@ describe('getText', function(){
})
describe('getRevisionsCount', function(){
it('gets Revision Coutn of a Pad', function(done) {
it('gets Revision Count of a Pad', function(done) {
api.get(endPoint('getRevisionsCount')+"&padID="+testPadId)
.expect(function(res){
if(res.body.data.revisions !== 1) throw new Error("Unable to set text revision count")
if(res.body.data.revisions !== 1) throw new Error("Unable to get text revision count")
})
.expect('Content-Type', /json/)
.expect(200, done)
});
})
describe('saveRevision', function(){
it('saves Revision', function(done) {
api.get(endPoint('saveRevision')+"&padID="+testPadId)
.expect(function(res){
if(res.body.code !== 0) throw new Error("Unable to save Revision");
})
.expect('Content-Type', /json/)
.expect(200, done)
});
})
describe('getSavedRevisionsCount', function(){
it('gets saved revisions count of Pad', function(done) {
api.get(endPoint('getSavedRevisionsCount')+"&padID="+testPadId)
.expect(function(res){
if(res.body.code !== 0) throw new Error("Unable to get Saved Revisions Count");
if(res.body.data.savedRevisions !== 1) throw new Error("Incorrect Saved Revisions Count");
})
.expect('Content-Type', /json/)
.expect(200, done)
});
})
describe('listSavedRevisions', function(){
it('gets saved revision list of Pad', function(done) {
api.get(endPoint('listSavedRevisions')+"&padID="+testPadId)
.expect(function(res){
if(res.body.code !== 0) throw new Error("Unable to get Saved Revisions List");
if(!res.body.data.savedRevisions.equals([1])) throw new Error("Incorrect Saved Revisions List");
})
.expect('Content-Type', /json/)
.expect(200, done)
});
})
describe('padUsersCount', function(){
it('gets User Count of a Pad', function(done) {
api.get(endPoint('padUsersCount')+"&padID="+testPadId)
@ -461,3 +524,25 @@ function generateLongText(){
}
return text;
}
// Need this to compare arrays (listSavedRevisions test)
Array.prototype.equals = function (array) {
// if the other array is a falsy value, return
if (!array)
return false;
// compare lengths - can save a lot of time
if (this.length != array.length)
return false;
for (var i = 0, l=this.length; i < l; i++) {
// Check if we have nested arrays
if (this[i] instanceof Array && array[i] instanceof Array) {
// recurse into the nested arrays
if (!this[i].equals(array[i]))
return false;
} else if (this[i] != array[i]) {
// Warning - two different object instances will never be equal: {x:20} != {x:20}
return false;
}
}
return true;
}