mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-24 09:26:14 -04:00
tidy up and re-organize
This commit is contained in:
parent
c0679980bf
commit
5434d2118d
3 changed files with 40 additions and 42 deletions
213
tests/backend/specs/api/pad.js
Normal file
213
tests/backend/specs/api/pad.js
Normal file
|
@ -0,0 +1,213 @@
|
|||
var assert = require('assert')
|
||||
supertest = require('supertest'),
|
||||
fs = require('fs'),
|
||||
api = supertest('http://localhost:9001');
|
||||
path = require('path');
|
||||
|
||||
var filePath = path.join(__dirname, '../../../../APIKEY.txt');
|
||||
|
||||
var apiKey = fs.readFileSync(filePath, {encoding: 'utf-8'});
|
||||
var apiVersion = 1;
|
||||
var testPadId = makeid();
|
||||
|
||||
describe('Connectivity', function(){
|
||||
it('errors if can not connect', function(done) {
|
||||
api.get('/api/')
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200, done)
|
||||
});
|
||||
})
|
||||
|
||||
describe('API Versioning', function(){
|
||||
it('errors if can not connect', function(done) {
|
||||
api.get('/api/')
|
||||
.expect(function(res){
|
||||
apiVersion = res.body.currentVersion;
|
||||
if (!res.body.currentVersion) throw new Error("No version set in API");
|
||||
return;
|
||||
})
|
||||
.expect(200, done)
|
||||
});
|
||||
})
|
||||
|
||||
describe('Permission', function(){
|
||||
it('errors if can connect without correct APIKey', function(done) {
|
||||
// This is broken because Etherpad doesn't handle HTTP codes properly see #2343
|
||||
// If your APIKey is password you deserve to fail all tests anyway
|
||||
var permErrorURL = '/api/'+apiVersion+'/createPad?apikey=password&padID=test';
|
||||
api.get(permErrorURL)
|
||||
.expect(401, done)
|
||||
});
|
||||
})
|
||||
|
||||
/* Pad Tests Order of execution
|
||||
-> deletePad -- This gives us a guaranteed clear environment
|
||||
-> createPad
|
||||
-> getRevisions(0) -- 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
|
||||
*/
|
||||
|
||||
describe('deletePad', function(){
|
||||
it('deletes a Pad', function(done) {
|
||||
api.get(endPoint('deletePad')+"&padID="+testPadId)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200, done)
|
||||
});
|
||||
})
|
||||
|
||||
describe('createPad', function(){
|
||||
it('creates a new Pad', function(done) {
|
||||
api.get(endPoint('createPad')+"&padID="+testPadId)
|
||||
.expect(function(res){
|
||||
if(res.body.code !== 0) throw new Error("Unable to create new Pad");
|
||||
})
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200, done)
|
||||
});
|
||||
})
|
||||
|
||||
describe('getRevisionsCount', function(){
|
||||
it('gets revision count of Pad', function(done) {
|
||||
api.get(endPoint('getRevisionsCount')+"&padID="+testPadId)
|
||||
.expect(function(res){
|
||||
if(res.body.code !== 0) throw new Error("Unable to get Revision Count");
|
||||
if(res.body.data.revisions !== 0) throw new Error("Incorrect Revision Count");
|
||||
})
|
||||
.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");
|
||||
})
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200, done)
|
||||
});
|
||||
})
|
||||
|
||||
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)
|
||||
});
|
||||
})
|
||||
|
||||
describe('getHTML', function(){
|
||||
it('get the HTML of a Pad -- Should return a failure', function(done) {
|
||||
api.get(endPoint('getHTML')+"&padID="+testPadId)
|
||||
.expect(function(res){
|
||||
if(res.body.code !== 1) throw new Error("Pad deletion failed")
|
||||
})
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200, done)
|
||||
});
|
||||
})
|
||||
|
||||
describe('createPad', function(){
|
||||
it('creates a new Pad with text', function(done) {
|
||||
api.get(endPoint('createPad')+"&padID="+testPadId+"&text=testText")
|
||||
.expect(function(res){
|
||||
if(res.body.code !== 0) throw new Error("Pad Creation failed")
|
||||
})
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200, done)
|
||||
});
|
||||
})
|
||||
|
||||
describe('getText', function(){
|
||||
it('gets the Pad text and expect it to be testText with \n which is a line break', function(done) {
|
||||
api.get(endPoint('getText')+"&padID="+testPadId)
|
||||
.expect(function(res){
|
||||
if(res.body.data.text !== "testText\n") throw new Error("Pad Creation with text")
|
||||
})
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200, done)
|
||||
});
|
||||
})
|
||||
|
||||
describe('setText', function(){
|
||||
it('creates a new Pad with text', function(done) {
|
||||
api.get(endPoint('setText')+"&padID="+testPadId+"&text=testTextTwo")
|
||||
.expect(function(res){
|
||||
if(res.body.code !== 0) throw new Error("Pad setting text failed");
|
||||
})
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200, done)
|
||||
});
|
||||
})
|
||||
|
||||
describe('getText', function(){
|
||||
it('gets the Pad text', function(done) {
|
||||
api.get(endPoint('getText')+"&padID="+testPadId)
|
||||
.expect(function(res){
|
||||
if(res.body.data.text !== "testTextTwo\n") throw new Error("Setting Text")
|
||||
})
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200, done)
|
||||
});
|
||||
})
|
||||
|
||||
describe('getRevisionsCount', function(){
|
||||
it('gets Revision Coutn 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")
|
||||
})
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200, done)
|
||||
});
|
||||
})
|
||||
|
||||
describe('padUsersCount', function(){
|
||||
it('gets Revision Coutn of a Pad', function(done) {
|
||||
api.get(endPoint('padUsersCount')+"&padID="+testPadId)
|
||||
.expect(function(res){
|
||||
if(res.body.data.padUsersCount !== 0) throw new Error("Incorrect Pad User count")
|
||||
})
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200, done)
|
||||
});
|
||||
})
|
||||
|
||||
describe('getReadOnlyID', function(){
|
||||
it('Gets the Read Only ID of a Pad', function(done) {
|
||||
api.get(endPoint('getReadOnlyID')+"&padID="+testPadId)
|
||||
.expect(function(res){
|
||||
if(!res.body.data.readOnlyID) throw new Error("No Read Only ID for Pad")
|
||||
})
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200, done)
|
||||
});
|
||||
})
|
||||
|
||||
var endPoint = function(point){
|
||||
return '/api/'+apiVersion+'/'+point+'?apikey='+apiKey;
|
||||
}
|
||||
|
||||
function makeid()
|
||||
{
|
||||
var text = "";
|
||||
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
|
||||
for( var i=0; i < 5; i++ ){
|
||||
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
||||
}
|
||||
return text;
|
||||
}
|
38
tests/backend/specs/api/sessionsAndGroups.js
Normal file
38
tests/backend/specs/api/sessionsAndGroups.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
/* Endpoints Still to interact with..
|
||||
padUsersCount(padID)
|
||||
setPublicStatus(padID, publicStatus)
|
||||
getPublicStatus(padID)
|
||||
setPassword(padID, password)
|
||||
isPasswordProtected(padID)
|
||||
listAuthorsOfPad(padID)
|
||||
getLastEdited(padID)
|
||||
listSessionsOfGroup(groupID)
|
||||
getSessionInfo(sessionID)
|
||||
deleteSession(sessionID)
|
||||
createSession(groupID, authorID, validUntil)
|
||||
listPadsOfAuthor(authorID)
|
||||
createAuthorIfNotExistsFor(authorMapper [, name])
|
||||
createAuthor([name])
|
||||
createGroupPad(groupID, padName [, text])
|
||||
listPads(groupID)
|
||||
deleteGroup(groupID)
|
||||
createGroupIfNotExistsFor(groupMapper)
|
||||
createGroup()
|
||||
*/
|
||||
|
||||
|
||||
var endPoint = function(point){
|
||||
return '/api/'+apiVersion+'/'+point+'?apikey='+apiKey;
|
||||
}
|
||||
|
||||
function makeid()
|
||||
{
|
||||
var text = "";
|
||||
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
|
||||
for( var i=0; i < 5; i++ ){
|
||||
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue