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){ for(var rev in this.savedRevisions){
savedRev.push(this.savedRevisions[rev].revNum); savedRev.push(this.savedRevisions[rev].revNum);
} }
savedRev.sort(function(a, b) {
return a - b;
});
return savedRev; return savedRev;
}; };

View File

@ -48,33 +48,38 @@ describe('Permission', function(){
-> deletePad -- This gives us a guaranteed clear environment -> deletePad -- This gives us a guaranteed clear environment
-> createPad -> createPad
-> getRevisions -- Should be 0 -> getRevisions -- Should be 0
-> getHTML -- Should be the default pad text in HTML format -> getSavedRevisionsCount(padID) -- Should be 0
-> deletePad -- Should just delete a pad -> listSavedRevisions(padID) -- Should be an empty array
-> getHTML -- Should return an error -> getHTML -- Should be the default pad text in HTML format
-> createPad(withText) -> deletePad -- Should just delete a pad
-> getText -- Should have the text specified above as the pad text -> getHTML -- Should return an error
-> setText -> createPad(withText)
-> getText -- Should be the text set before -> getText -- Should have the text specified above as the pad text
-> getRevisions -- Should be 0 still? -> setText
-> padUsersCount -- Should be 0 -> getText -- Should be the text set before
-> getReadOnlyId -- Should be a value -> getRevisions -- Should be 0 still?
-> listAuthorsOfPad(padID) -- should be empty array? -> saveRevision
-> getLastEdited(padID) -- Should be when pad was made -> getSavedRevisionsCount(padID) -- Should be 0 still?
-> setText(padId) -> listSavedRevisions(padID) -- Should be an empty array still ?
-> getLastEdited(padID) -- Should be when setText was performed -> padUsersCount -- Should be 0
-> padUsers(padID) -- Should be when setText was performed -> getReadOnlyId -- Should be a value
-> listAuthorsOfPad(padID) -- should be empty array?
-> setText(padId, "hello world")
-> getLastEdited(padID) -- Should be when pad was made -> getLastEdited(padID) -- Should be when pad was made
-> getText(padId) -- Should be "hello world" -> setText(padId)
-> movePad(padID, newPadId) -- Should provide consistant pad data -> getLastEdited(padID) -- Should be when setText was performed
-> getText(newPadId) -- Should be "hello world" -> padUsers(padID) -- Should be when setText was performed
-> movePad(newPadID, originalPadId) -- Should provide consistant pad data
-> getText(originalPadId) -- Should be "hello world" -> setText(padId, "hello world")
-> getLastEdited(padID) -- Should not be 0 -> getLastEdited(padID) -- Should be when pad was made
-> setHTML(padID) -- Should fail on invalid HTML -> getText(padId) -- Should be "hello world"
-> setHTML(padID) *3 -- Should fail on invalid HTML -> movePad(padID, newPadId) -- Should provide consistant pad data
-> getHTML(padID) -- Should return HTML close to posted HTML -> 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(){ describe('getHTML', function(){
it('get the HTML of Pad', function(done) { it('get the HTML of Pad', function(done) {
api.get(endPoint('getHTML')+"&padID="+testPadId) api.get(endPoint('getHTML')+"&padID="+testPadId)
.expect(function(res){ .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('Content-Type', /json/)
.expect(200, done) .expect(200, done)
@ -187,16 +216,50 @@ describe('getText', function(){
}) })
describe('getRevisionsCount', 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) api.get(endPoint('getRevisionsCount')+"&padID="+testPadId)
.expect(function(res){ .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('Content-Type', /json/)
.expect(200, done) .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(){ describe('padUsersCount', function(){
it('gets User Count of a Pad', function(done) { it('gets User Count of a Pad', function(done) {
api.get(endPoint('padUsersCount')+"&padID="+testPadId) api.get(endPoint('padUsersCount')+"&padID="+testPadId)
@ -461,3 +524,25 @@ function generateLongText(){
} }
return text; 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;
}