From 3e140162149009a7c4bb12d5e23c906c85c7089e Mon Sep 17 00:00:00 2001
From: Richard Hansen
Date: Fri, 9 Oct 2020 18:19:46 -0400
Subject: [PATCH] tests: Include the filename in the test output
Also some minor consistency cleanups.
---
tests/backend/specs/api/api.js | 70 +-
tests/backend/specs/api/characterEncoding.js | 138 +-
tests/backend/specs/api/chat.js | 150 +-
tests/backend/specs/api/importexport.js | 100 +-
.../backend/specs/api/importexportGetPost.js | 565 +++----
tests/backend/specs/api/instance.js | 48 +-
tests/backend/specs/api/pad.js | 1372 +++++++++--------
tests/backend/specs/api/sessionsAndGroups.js | 492 +++---
tests/backend/specs/api/tidy.js | 96 +-
tests/backend/specs/contentcollector.js | 90 +-
tests/backend/specs/promises.js | 144 +-
tests/backend/specs/socketio.js | 502 +++---
tests/backend/specs/webaccess.js | 805 +++++-----
13 files changed, 2296 insertions(+), 2276 deletions(-)
diff --git a/tests/backend/specs/api/api.js b/tests/backend/specs/api/api.js
index e5fca6bca..a3d29fd4f 100644
--- a/tests/backend/specs/api/api.js
+++ b/tests/backend/specs/api/api.js
@@ -18,44 +18,46 @@ var apiVersion = 1;
var testPadId = makeid();
-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(__filename, function() {
+ 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('OpenAPI definition', function() {
- it('generates valid openapi definition document', function(done) {
- api
- .get('/api/openapi.json')
- .expect(function(res) {
- const { valid, errors } = validateOpenAPI(res.body, 3);
- if (!valid) {
- const prettyErrors = JSON.stringify(errors, null, 2);
- throw new Error(`Document is not valid OpenAPI. ${errors.length} validation errors:\n${prettyErrors}`);
- }
- return;
- })
- .expect(200, done);
+ describe('OpenAPI definition', function() {
+ it('generates valid openapi definition document', function(done) {
+ api
+ .get('/api/openapi.json')
+ .expect(function(res) {
+ const { valid, errors } = validateOpenAPI(res.body, 3);
+ if (!valid) {
+ const prettyErrors = JSON.stringify(errors, null, 2);
+ throw new Error(`Document is not valid OpenAPI. ${errors.length} validation errors:\n${prettyErrors}`);
+ }
+ return;
+ })
+ .expect(200, done);
+ });
});
-});
-describe('jsonp support', function() {
- it('supports jsonp calls', function(done) {
- api
- .get(endPoint('createPad') + '&jsonp=jsonp_1&padID=' + testPadId)
- .expect(function(res) {
- if (!res.text.match('jsonp_1')) throw new Error('no jsonp call seen');
- })
- .expect('Content-Type', /javascript/)
- .expect(200, done);
+ describe('jsonp support', function() {
+ it('supports jsonp calls', function(done) {
+ api
+ .get(endPoint('createPad') + '&jsonp=jsonp_1&padID=' + testPadId)
+ .expect(function(res) {
+ if (!res.text.match('jsonp_1')) throw new Error('no jsonp call seen');
+ })
+ .expect('Content-Type', /javascript/)
+ .expect(200, done);
+ });
});
});
diff --git a/tests/backend/specs/api/characterEncoding.js b/tests/backend/specs/api/characterEncoding.js
index ed192d325..494a1bbd6 100644
--- a/tests/backend/specs/api/characterEncoding.js
+++ b/tests/backend/specs/api/characterEncoding.js
@@ -14,76 +14,78 @@ const apiKey = common.apiKey;
var apiVersion = 1;
var testPadId = makeid();
-describe('Connectivity For Character Encoding', function(){
- it('can connect', function(done) {
- api.get('/api/')
- .expect('Content-Type', /json/)
- .expect(200, done)
- });
-})
-
-describe('API Versioning', function(){
- it('finds the version tag', 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 with invalid 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)
- });
-})
-
-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('setHTML', function(){
- it('Sets the HTML of a Pad attempting to weird utf8 encoded content', function(done) {
- fs.readFile('../tests/backend/specs/api/emojis.html', 'utf8', function(err, html) {
- api.post(endPoint('setHTML'))
- .send({
- "padID": testPadId,
- "html": html,
- })
- .expect(function(res){
- if(res.body.code !== 0) throw new Error("Can't set HTML properly");
- })
- .expect('Content-Type', /json/)
- .expect(200, done);
+describe(__filename, function() {
+ describe('Connectivity For Character Encoding', function() {
+ it('can connect', function(done) {
+ api.get('/api/')
+ .expect('Content-Type', /json/)
+ .expect(200, done)
});
- });
-})
+ })
-describe('getHTML', function(){
- it('get the HTML of Pad with emojis', function(done) {
- api.get(endPoint('getHTML')+"&padID="+testPadId)
- .expect(function(res){
- if (res.body.data.html.indexOf("🇼") === -1) {
- throw new Error("Unable to get the HTML");
- }
- })
- .expect('Content-Type', /json/)
- .expect(200, done)
- });
-})
+ describe('API Versioning', function() {
+ it('finds the version tag', 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 with invalid 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)
+ });
+ })
+
+ 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('setHTML', function() {
+ it('Sets the HTML of a Pad attempting to weird utf8 encoded content', function(done) {
+ fs.readFile('../tests/backend/specs/api/emojis.html', 'utf8', function(err, html) {
+ api.post(endPoint('setHTML'))
+ .send({
+ "padID": testPadId,
+ "html": html,
+ })
+ .expect(function(res){
+ if(res.body.code !== 0) throw new Error("Can't set HTML properly");
+ })
+ .expect('Content-Type', /json/)
+ .expect(200, done);
+ });
+ });
+ })
+
+ describe('getHTML', function() {
+ it('get the HTML of Pad with emojis', function(done) {
+ api.get(endPoint('getHTML')+"&padID="+testPadId)
+ .expect(function(res){
+ if (res.body.data.html.indexOf("🇼") === -1) {
+ throw new Error("Unable to get the HTML");
+ }
+ })
+ .expect('Content-Type', /json/)
+ .expect(200, done)
+ });
+ })
+});
/*
diff --git a/tests/backend/specs/api/chat.js b/tests/backend/specs/api/chat.js
index 293b4a145..a7c6c0762 100644
--- a/tests/backend/specs/api/chat.js
+++ b/tests/backend/specs/api/chat.js
@@ -11,89 +11,91 @@ var authorID = "";
var padID = makeid();
var timestamp = Date.now();
-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(__filename, function() {
+ 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)
+ });
+ })
-// BEGIN GROUP AND AUTHOR TESTS
-/////////////////////////////////////
-/////////////////////////////////////
+ // BEGIN GROUP AND AUTHOR TESTS
+ /////////////////////////////////////
+ /////////////////////////////////////
-/* Tests performed
--> createPad(padID)
- -> createAuthor([name]) -- should return an authorID
- -> appendChatMessage(padID, text, authorID, time)
- -> getChatHead(padID)
- -> getChatHistory(padID)
-*/
+ /* Tests performed
+ -> createPad(padID)
+ -> createAuthor([name]) -- should return an authorID
+ -> appendChatMessage(padID, text, authorID, time)
+ -> getChatHead(padID)
+ -> getChatHistory(padID)
+ */
-describe('createPad', function(){
- it('creates a new Pad', function(done) {
- api.get(endPoint('createPad')+"&padID="+padID)
- .expect(function(res){
- if(res.body.code !== 0) throw new Error("Unable to create new Pad");
- })
- .expect('Content-Type', /json/)
- .expect(200, done)
- });
-})
+ describe('createPad', function(){
+ it('creates a new Pad', function(done) {
+ api.get(endPoint('createPad')+"&padID="+padID)
+ .expect(function(res){
+ if(res.body.code !== 0) throw new Error("Unable to create new Pad");
+ })
+ .expect('Content-Type', /json/)
+ .expect(200, done)
+ });
+ })
-describe('createAuthor', function(){
- it('Creates an author with a name set', function(done) {
- api.get(endPoint('createAuthor'))
- .expect(function(res){
- if(res.body.code !== 0 || !res.body.data.authorID) throw new Error("Unable to create author");
- authorID = res.body.data.authorID; // we will be this author for the rest of the tests
- })
- .expect('Content-Type', /json/)
- .expect(200, done)
- });
-})
+ describe('createAuthor', function(){
+ it('Creates an author with a name set', function(done) {
+ api.get(endPoint('createAuthor'))
+ .expect(function(res){
+ if(res.body.code !== 0 || !res.body.data.authorID) throw new Error("Unable to create author");
+ authorID = res.body.data.authorID; // we will be this author for the rest of the tests
+ })
+ .expect('Content-Type', /json/)
+ .expect(200, done)
+ });
+ })
-describe('appendChatMessage', function(){
- it('Adds a chat message to the pad', function(done) {
- api.get(endPoint('appendChatMessage')+"&padID="+padID+"&text=blalblalbha&authorID="+authorID+"&time="+timestamp)
- .expect(function(res){
- if(res.body.code !== 0) throw new Error("Unable to create chat message");
- })
- .expect('Content-Type', /json/)
- .expect(200, done)
- });
-})
+ describe('appendChatMessage', function(){
+ it('Adds a chat message to the pad', function(done) {
+ api.get(endPoint('appendChatMessage')+"&padID="+padID+"&text=blalblalbha&authorID="+authorID+"&time="+timestamp)
+ .expect(function(res){
+ if(res.body.code !== 0) throw new Error("Unable to create chat message");
+ })
+ .expect('Content-Type', /json/)
+ .expect(200, done)
+ });
+ })
-describe('getChatHead', function(){
- it('Gets the head of chat', function(done) {
- api.get(endPoint('getChatHead')+"&padID="+padID)
- .expect(function(res){
- if(res.body.data.chatHead !== 0) throw new Error("Chat Head Length is wrong");
+ describe('getChatHead', function(){
+ it('Gets the head of chat', function(done) {
+ api.get(endPoint('getChatHead')+"&padID="+padID)
+ .expect(function(res){
+ if(res.body.data.chatHead !== 0) throw new Error("Chat Head Length is wrong");
- if(res.body.code !== 0) throw new Error("Unable to get chat head");
- })
- .expect('Content-Type', /json/)
- .expect(200, done)
- });
-})
+ if(res.body.code !== 0) throw new Error("Unable to get chat head");
+ })
+ .expect('Content-Type', /json/)
+ .expect(200, done)
+ });
+ })
-describe('getChatHistory', function(){
- it('Gets Chat History of a Pad', function(done) {
- api.get(endPoint('getChatHistory')+"&padID="+padID)
- .expect(function(res){
- if(res.body.data.messages.length !== 1) throw new Error("Chat History Length is wrong");
- if(res.body.code !== 0) throw new Error("Unable to get chat history");
- })
- .expect('Content-Type', /json/)
- .expect(200, done)
- });
-})
+ describe('getChatHistory', function(){
+ it('Gets Chat History of a Pad', function(done) {
+ api.get(endPoint('getChatHistory')+"&padID="+padID)
+ .expect(function(res){
+ if(res.body.data.messages.length !== 1) throw new Error("Chat History Length is wrong");
+ if(res.body.code !== 0) throw new Error("Unable to get chat history");
+ })
+ .expect('Content-Type', /json/)
+ .expect(200, done)
+ });
+ })
+});
var endPoint = function(point){
return '/api/'+apiVersion+'/'+point+'?apikey='+apiKey;
diff --git a/tests/backend/specs/api/importexport.js b/tests/backend/specs/api/importexport.js
index 67ced55db..3744dd67d 100644
--- a/tests/backend/specs/api/importexport.js
+++ b/tests/backend/specs/api/importexport.js
@@ -56,38 +56,39 @@ var testImports = {
*/
}
-Object.keys(testImports).forEach(function (testName) {
- var testPadId = makeid();
- test = testImports[testName];
- 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(__filename, function() {
+ Object.keys(testImports).forEach(function(testName) {
+ var testPadId = makeid();
+ test = testImports[testName];
+ 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('setHTML', function(){
- it('Sets the HTML', function(done) {
- api.get(endPoint('setHTML')+"&padID="+testPadId+"&html="+test.input)
- .expect(function(res){
- if(res.body.code !== 0) throw new Error("Error:"+testName)
- })
- .expect('Content-Type', /json/)
- .expect(200, done)
- });
- })
+ describe('setHTML', function() {
+ it('Sets the HTML', function(done) {
+ api.get(endPoint('setHTML') + "&padID=" + testPadId + "&html=" + test.input)
+ .expect(function(res) {
+ if(res.body.code !== 0) throw new Error("Error:" + testName)
+ })
+ .expect('Content-Type', /json/)
+ .expect(200, done)
+ });
+ })
- describe('getHTML', function(){
- it('Gets back the HTML of a Pad', function(done) {
- api.get(endPoint('getHTML')+"&padID="+testPadId)
- .expect(function(res){
- var receivedHtml = res.body.data.html;
- if (receivedHtml !== test.expectedHTML) {
- throw new Error(`HTML received from export is not the one we were expecting.
+ describe('getHTML', function() {
+ it('Gets back the HTML of a Pad', function(done) {
+ api.get(endPoint('getHTML') + "&padID=" + testPadId)
+ .expect(function(res) {
+ var receivedHtml = res.body.data.html;
+ if (receivedHtml !== test.expectedHTML) {
+ throw new Error(`HTML received from export is not the one we were expecting.
Test Name:
${testName}
@@ -99,20 +100,20 @@ Object.keys(testImports).forEach(function (testName) {
Which is a different version of the originally imported one:
${test.input}`);
- }
- })
- .expect('Content-Type', /json/)
- .expect(200, done)
- });
- })
+ }
+ })
+ .expect('Content-Type', /json/)
+ .expect(200, done)
+ });
+ })
- describe('getText', function(){
- it('Gets back the Text of a Pad', function(done) {
- api.get(endPoint('getText')+"&padID="+testPadId)
- .expect(function(res){
- var receivedText = res.body.data.text;
- if (receivedText !== test.expectedText) {
- throw new Error(`Text received from export is not the one we were expecting.
+ describe('getText', function() {
+ it('Gets back the Text of a Pad', function(done) {
+ api.get(endPoint('getText') + "&padID=" + testPadId)
+ .expect(function(res) {
+ var receivedText = res.body.data.text;
+ if (receivedText !== test.expectedText) {
+ throw new Error(`Text received from export is not the one we were expecting.
Test Name:
${testName}
@@ -124,12 +125,13 @@ Object.keys(testImports).forEach(function (testName) {
Which is a different version of the originally imported one:
${test.input}`);
- }
- })
- .expect('Content-Type', /json/)
- .expect(200, done)
- });
- })
+ }
+ })
+ .expect('Content-Type', /json/)
+ .expect(200, done)
+ });
+ })
+ });
});
diff --git a/tests/backend/specs/api/importexportGetPost.js b/tests/backend/specs/api/importexportGetPost.js
index edc51f92d..1775d2ed7 100644
--- a/tests/backend/specs/api/importexportGetPost.js
+++ b/tests/backend/specs/api/importexportGetPost.js
@@ -23,326 +23,327 @@ var apiVersion = 1;
const testPadId = makeid();
const testPadIdEnc = encodeURIComponent(testPadId);
-before(async function() { agent = await common.init(); });
+describe(__filename, function() {
+ before(async function() { agent = await common.init(); });
-describe('Connectivity', function(){
- it('can connect', async function() {
- await agent.get('/api/')
- .expect(200)
- .expect('Content-Type', /json/);
- });
-})
-
-describe('API Versioning', function(){
- it('finds the version tag', async function() {
- await agent.get('/api/')
- .expect(200)
- .expect((res) => assert(res.body.currentVersion));
- });
-})
-
-/*
-Tests
------
-
-Test.
- / Create a pad
- / Set pad contents
- / Try export pad in various formats
- / Get pad contents and ensure it matches imported contents
-
-Test.
- / Try to export a pad that doesn't exist // Expect failure
-
-Test.
- / Try to import an unsupported file to a pad that exists
-
--- TODO: Test.
- Try to import to a file and abort it half way through
-
-Test.
- Try to import to files of varying size.
-
-Example Curl command for testing import URI:
- curl -s -v --form file=@/home/jose/test.txt http://127.0.0.1:9001/p/foo/import
-*/
-
-describe('Imports and Exports', function(){
- const backups = {};
-
- beforeEach(async function() {
- // Note: This is a shallow copy.
- backups.settings = Object.assign({}, settings);
- });
-
- afterEach(async function() {
- // Note: This does not unset settings that were added.
- Object.assign(settings, backups.settings);
- });
-
- it('creates a new Pad, imports content to it, checks that content', async function() {
- await agent.get(endPoint('createPad') + `&padID=${testPadId}`)
- .expect(200)
- .expect('Content-Type', /json/)
- .expect((res) => assert.equal(res.body.code, 0));
- await agent.post(`/p/${testPadId}/import`)
- .attach('file', padText, {filename: '/test.txt', contentType: 'text/plain'})
- .expect(200);
- await agent.get(endPoint('getText') + `&padID=${testPadId}`)
- .expect(200)
- .expect((res) => assert.equal(res.body.data.text, padText.toString()));
- });
-
- it('gets read only pad Id and exports the html and text for this pad', async function(){
- let ro = await agent.get(endPoint('getReadOnlyID')+"&padID="+testPadId)
- .expect(200)
- .expect((res) => assert.ok(JSON.parse(res.text).data.readOnlyID));
- let readOnlyId = JSON.parse(ro.text).data.readOnlyID;
-
- await agent.get(`/p/${readOnlyId}/export/html`)
- .expect(200)
- .expect((res) => assert(res.text.indexOf("This is the") !== -1));
-
- await agent.get(`/p/${readOnlyId}/export/txt`)
- .expect(200)
- .expect((res) => assert(res.text.indexOf("This is the") !== -1));
- });
-
-
- describe('Import/Export tests requiring AbiWord/LibreOffice', function() {
- before(function() {
- if ((!settings.abiword || settings.abiword.indexOf('/') === -1) &&
- (!settings.soffice || settings.soffice.indexOf('/') === -1)) {
- this.skip();
- }
- });
-
- // For some reason word import does not work in testing..
- // TODO: fix support for .doc files..
- it('Tries to import .doc that uses soffice or abiword', async function() {
- await agent.post(`/p/${testPadId}/import`)
- .attach('file', wordDoc, {filename: '/test.doc', contentType: 'application/msword'})
+ describe('Connectivity', function(){
+ it('can connect', async function() {
+ await agent.get('/api/')
.expect(200)
- .expect(/FrameCall\('undefined', 'ok'\);/);
+ .expect('Content-Type', /json/);
});
+ })
- it('exports DOC', async function() {
- await agent.get(`/p/${testPadId}/export/doc`)
- .buffer(true).parse(superagent.parse['application/octet-stream'])
+ describe('API Versioning', function(){
+ it('finds the version tag', async function() {
+ await agent.get('/api/')
.expect(200)
- .expect((res) => assert(res.body.length >= 9000));
+ .expect((res) => assert(res.body.currentVersion));
});
+ })
- it('Tries to import .docx that uses soffice or abiword', async function() {
- await agent.post(`/p/${testPadId}/import`)
- .attach('file', wordXDoc, {
- filename: '/test.docx',
- contentType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
- })
- .expect(200)
- .expect(/FrameCall\('undefined', 'ok'\);/);
- });
+ /*
+ Tests
+ -----
- it('exports DOC from imported DOCX', async function() {
- await agent.get(`/p/${testPadId}/export/doc`)
- .buffer(true).parse(superagent.parse['application/octet-stream'])
- .expect(200)
- .expect((res) => assert(res.body.length >= 9100));
- });
+ Test.
+ / Create a pad
+ / Set pad contents
+ / Try export pad in various formats
+ / Get pad contents and ensure it matches imported contents
- it('Tries to import .pdf that uses soffice or abiword', async function() {
- await agent.post(`/p/${testPadId}/import`)
- .attach('file', pdfDoc, {filename: '/test.pdf', contentType: 'application/pdf'})
- .expect(200)
- .expect(/FrameCall\('undefined', 'ok'\);/);
- });
+ Test.
+ / Try to export a pad that doesn't exist // Expect failure
- it('exports PDF', async function() {
- await agent.get(`/p/${testPadId}/export/pdf`)
- .buffer(true).parse(superagent.parse['application/octet-stream'])
- .expect(200)
- .expect((res) => assert(res.body.length >= 1000));
- });
+ Test.
+ / Try to import an unsupported file to a pad that exists
- it('Tries to import .odt that uses soffice or abiword', async function() {
- await agent.post(`/p/${testPadId}/import`)
- .attach('file', odtDoc, {filename: '/test.odt', contentType: 'application/odt'})
- .expect(200)
- .expect(/FrameCall\('undefined', 'ok'\);/);
- });
+ -- TODO: Test.
+ Try to import to a file and abort it half way through
- it('exports ODT', async function() {
- await agent.get(`/p/${testPadId}/export/odt`)
- .buffer(true).parse(superagent.parse['application/octet-stream'])
- .expect(200)
- .expect((res) => assert(res.body.length >= 7000));
- });
+ Test.
+ Try to import to files of varying size.
- }); // End of AbiWord/LibreOffice tests.
+ Example Curl command for testing import URI:
+ curl -s -v --form file=@/home/jose/test.txt http://127.0.0.1:9001/p/foo/import
+ */
- it('Tries to import .etherpad', async function() {
- await agent.post(`/p/${testPadId}/import`)
- .attach('file', etherpadDoc, {
- filename: '/test.etherpad',
- contentType: 'application/etherpad',
- })
- .expect(200)
- .expect(/FrameCall\('true', 'ok'\);/);
- });
-
- it('exports Etherpad', async function() {
- await agent.get(`/p/${testPadId}/export/etherpad`)
- .buffer(true).parse(superagent.parse.text)
- .expect(200)
- .expect(/hello/);
- });
-
- it('exports HTML for this Etherpad file', async function() {
- await agent.get(`/p/${testPadId}/export/html`)
- .expect(200)
- .expect('content-type', 'text/html; charset=utf-8')
- .expect(/- hello<\/ul><\/li><\/ul>/);
- });
-
- it('Tries to import unsupported file type', async function() {
- settings.allowUnknownFileEnds = false;
- await agent.post(`/p/${testPadId}/import`)
- .attach('file', padText, {filename: '/test.xasdasdxx', contentType: 'weirdness/jobby'})
- .expect(200)
- .expect((res) => assert.doesNotMatch(res.text, /FrameCall\('undefined', 'ok'\);/));
- });
-
- describe('Import authorization checks', function() {
- let authorize;
-
- const deleteTestPad = async () => {
- if (await padManager.doesPadExist(testPadId)) {
- const pad = await padManager.getPad(testPadId);
- await pad.remove();
- }
- };
-
- const createTestPad = async (text) => {
- const pad = await padManager.getPad(testPadId);
- if (text) await pad.setText(text);
- return pad;
- };
+ describe('Imports and Exports', function(){
+ const backups = {};
beforeEach(async function() {
- await deleteTestPad();
- settings.requireAuthentication = false;
- settings.requireAuthorization = true;
- settings.users = {user: {password: 'user-password'}};
- authorize = () => true;
- backups.hooks = {};
- backups.hooks.authorize = plugins.hooks.authorize || [];
- plugins.hooks.authorize = [{hook_fn: (hookName, {req}, cb) => cb([authorize(req)])}];
+ // Note: This is a shallow copy.
+ backups.settings = Object.assign({}, settings);
});
afterEach(async function() {
- await deleteTestPad();
- Object.assign(plugins.hooks, backups.hooks);
+ // Note: This does not unset settings that were added.
+ Object.assign(settings, backups.settings);
});
- it('!authn !exist -> create', async function() {
- await agent.post(`/p/${testPadIdEnc}/import`)
- .attach('file', padText, {filename: '/test.txt', contentType: 'text/plain'})
- .expect(200);
- assert(await padManager.doesPadExist(testPadId));
- const pad = await padManager.getPad(testPadId);
- assert.equal(pad.text(), padText.toString());
+ it('creates a new Pad, imports content to it, checks that content', async function() {
+ await agent.get(endPoint('createPad') + `&padID=${testPadId}`)
+ .expect(200)
+ .expect('Content-Type', /json/)
+ .expect((res) => assert.equal(res.body.code, 0));
+ await agent.post(`/p/${testPadId}/import`)
+ .attach('file', padText, {filename: '/test.txt', contentType: 'text/plain'})
+ .expect(200);
+ await agent.get(endPoint('getText') + `&padID=${testPadId}`)
+ .expect(200)
+ .expect((res) => assert.equal(res.body.data.text, padText.toString()));
});
- it('!authn exist -> replace', async function() {
- const pad = await createTestPad('before import');
- await agent.post(`/p/${testPadIdEnc}/import`)
- .attach('file', padText, {filename: '/test.txt', contentType: 'text/plain'})
- .expect(200);
- assert(await padManager.doesPadExist(testPadId));
- assert.equal(pad.text(), padText.toString());
+ it('gets read only pad Id and exports the html and text for this pad', async function(){
+ let ro = await agent.get(endPoint('getReadOnlyID')+"&padID="+testPadId)
+ .expect(200)
+ .expect((res) => assert.ok(JSON.parse(res.text).data.readOnlyID));
+ let readOnlyId = JSON.parse(ro.text).data.readOnlyID;
+
+ await agent.get(`/p/${readOnlyId}/export/html`)
+ .expect(200)
+ .expect((res) => assert(res.text.indexOf("This is the") !== -1));
+
+ await agent.get(`/p/${readOnlyId}/export/txt`)
+ .expect(200)
+ .expect((res) => assert(res.text.indexOf("This is the") !== -1));
});
- it('authn anonymous !exist -> fail', async function() {
- settings.requireAuthentication = true;
- await agent.post(`/p/${testPadIdEnc}/import`)
- .attach('file', padText, {filename: '/test.txt', contentType: 'text/plain'})
- .expect(401);
- assert(!(await padManager.doesPadExist(testPadId)));
+
+ describe('Import/Export tests requiring AbiWord/LibreOffice', function() {
+ before(function() {
+ if ((!settings.abiword || settings.abiword.indexOf('/') === -1) &&
+ (!settings.soffice || settings.soffice.indexOf('/') === -1)) {
+ this.skip();
+ }
+ });
+
+ // For some reason word import does not work in testing..
+ // TODO: fix support for .doc files..
+ it('Tries to import .doc that uses soffice or abiword', async function() {
+ await agent.post(`/p/${testPadId}/import`)
+ .attach('file', wordDoc, {filename: '/test.doc', contentType: 'application/msword'})
+ .expect(200)
+ .expect(/FrameCall\('undefined', 'ok'\);/);
+ });
+
+ it('exports DOC', async function() {
+ await agent.get(`/p/${testPadId}/export/doc`)
+ .buffer(true).parse(superagent.parse['application/octet-stream'])
+ .expect(200)
+ .expect((res) => assert(res.body.length >= 9000));
+ });
+
+ it('Tries to import .docx that uses soffice or abiword', async function() {
+ await agent.post(`/p/${testPadId}/import`)
+ .attach('file', wordXDoc, {
+ filename: '/test.docx',
+ contentType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
+ })
+ .expect(200)
+ .expect(/FrameCall\('undefined', 'ok'\);/);
+ });
+
+ it('exports DOC from imported DOCX', async function() {
+ await agent.get(`/p/${testPadId}/export/doc`)
+ .buffer(true).parse(superagent.parse['application/octet-stream'])
+ .expect(200)
+ .expect((res) => assert(res.body.length >= 9100));
+ });
+
+ it('Tries to import .pdf that uses soffice or abiword', async function() {
+ await agent.post(`/p/${testPadId}/import`)
+ .attach('file', pdfDoc, {filename: '/test.pdf', contentType: 'application/pdf'})
+ .expect(200)
+ .expect(/FrameCall\('undefined', 'ok'\);/);
+ });
+
+ it('exports PDF', async function() {
+ await agent.get(`/p/${testPadId}/export/pdf`)
+ .buffer(true).parse(superagent.parse['application/octet-stream'])
+ .expect(200)
+ .expect((res) => assert(res.body.length >= 1000));
+ });
+
+ it('Tries to import .odt that uses soffice or abiword', async function() {
+ await agent.post(`/p/${testPadId}/import`)
+ .attach('file', odtDoc, {filename: '/test.odt', contentType: 'application/odt'})
+ .expect(200)
+ .expect(/FrameCall\('undefined', 'ok'\);/);
+ });
+
+ it('exports ODT', async function() {
+ await agent.get(`/p/${testPadId}/export/odt`)
+ .buffer(true).parse(superagent.parse['application/octet-stream'])
+ .expect(200)
+ .expect((res) => assert(res.body.length >= 7000));
+ });
+
+ }); // End of AbiWord/LibreOffice tests.
+
+ it('Tries to import .etherpad', async function() {
+ await agent.post(`/p/${testPadId}/import`)
+ .attach('file', etherpadDoc, {
+ filename: '/test.etherpad',
+ contentType: 'application/etherpad',
+ })
+ .expect(200)
+ .expect(/FrameCall\('true', 'ok'\);/);
});
- it('authn anonymous exist -> fail', async function() {
- settings.requireAuthentication = true;
- const pad = await createTestPad('before import\n');
- await agent.post(`/p/${testPadIdEnc}/import`)
- .attach('file', padText, {filename: '/test.txt', contentType: 'text/plain'})
- .expect(401);
- assert.equal(pad.text(), 'before import\n');
+ it('exports Etherpad', async function() {
+ await agent.get(`/p/${testPadId}/export/etherpad`)
+ .buffer(true).parse(superagent.parse.text)
+ .expect(200)
+ .expect(/hello/);
});
- it('authn user create !exist -> create', async function() {
- settings.requireAuthentication = true;
- await agent.post(`/p/${testPadIdEnc}/import`)
- .auth('user', 'user-password')
- .attach('file', padText, {filename: '/test.txt', contentType: 'text/plain'})
- .expect(200);
- assert(await padManager.doesPadExist(testPadId));
- const pad = await padManager.getPad(testPadId);
- assert.equal(pad.text(), padText.toString());
+ it('exports HTML for this Etherpad file', async function() {
+ await agent.get(`/p/${testPadId}/export/html`)
+ .expect(200)
+ .expect('content-type', 'text/html; charset=utf-8')
+ .expect(/
- hello<\/ul><\/li><\/ul>/);
});
- it('authn user modify !exist -> fail', async function() {
- settings.requireAuthentication = true;
- authorize = () => 'modify';
- await agent.post(`/p/${testPadIdEnc}/import`)
- .auth('user', 'user-password')
- .attach('file', padText, {filename: '/test.txt', contentType: 'text/plain'})
- .expect(403);
- assert(!(await padManager.doesPadExist(testPadId)));
+ it('Tries to import unsupported file type', async function() {
+ settings.allowUnknownFileEnds = false;
+ await agent.post(`/p/${testPadId}/import`)
+ .attach('file', padText, {filename: '/test.xasdasdxx', contentType: 'weirdness/jobby'})
+ .expect(200)
+ .expect((res) => assert.doesNotMatch(res.text, /FrameCall\('undefined', 'ok'\);/));
});
- it('authn user readonly !exist -> fail', async function() {
- settings.requireAuthentication = true;
- authorize = () => 'readOnly';
- await agent.post(`/p/${testPadIdEnc}/import`)
- .auth('user', 'user-password')
- .attach('file', padText, {filename: '/test.txt', contentType: 'text/plain'})
- .expect(403);
- assert(!(await padManager.doesPadExist(testPadId)));
- });
+ describe('Import authorization checks', function() {
+ let authorize;
- it('authn user create exist -> replace', async function() {
- settings.requireAuthentication = true;
- const pad = await createTestPad('before import\n');
- await agent.post(`/p/${testPadIdEnc}/import`)
- .auth('user', 'user-password')
- .attach('file', padText, {filename: '/test.txt', contentType: 'text/plain'})
- .expect(200);
- assert.equal(pad.text(), padText.toString());
- });
+ const deleteTestPad = async () => {
+ if (await padManager.doesPadExist(testPadId)) {
+ const pad = await padManager.getPad(testPadId);
+ await pad.remove();
+ }
+ };
- it('authn user modify exist -> replace', async function() {
- settings.requireAuthentication = true;
- authorize = () => 'modify';
- const pad = await createTestPad('before import\n');
- await agent.post(`/p/${testPadIdEnc}/import`)
- .auth('user', 'user-password')
- .attach('file', padText, {filename: '/test.txt', contentType: 'text/plain'})
- .expect(200);
- assert.equal(pad.text(), padText.toString());
- });
+ const createTestPad = async (text) => {
+ const pad = await padManager.getPad(testPadId);
+ if (text) await pad.setText(text);
+ return pad;
+ };
- it('authn user readonly exist -> fail', async function() {
- const pad = await createTestPad('before import\n');
- settings.requireAuthentication = true;
- authorize = () => 'readOnly';
- await agent.post(`/p/${testPadIdEnc}/import`)
- .auth('user', 'user-password')
- .attach('file', padText, {filename: '/test.txt', contentType: 'text/plain'})
- .expect(403);
- assert.equal(pad.text(), 'before import\n');
+ beforeEach(async function() {
+ await deleteTestPad();
+ settings.requireAuthentication = false;
+ settings.requireAuthorization = true;
+ settings.users = {user: {password: 'user-password'}};
+ authorize = () => true;
+ backups.hooks = {};
+ backups.hooks.authorize = plugins.hooks.authorize || [];
+ plugins.hooks.authorize = [{hook_fn: (hookName, {req}, cb) => cb([authorize(req)])}];
+ });
+
+ afterEach(async function() {
+ await deleteTestPad();
+ Object.assign(plugins.hooks, backups.hooks);
+ });
+
+ it('!authn !exist -> create', async function() {
+ await agent.post(`/p/${testPadIdEnc}/import`)
+ .attach('file', padText, {filename: '/test.txt', contentType: 'text/plain'})
+ .expect(200);
+ assert(await padManager.doesPadExist(testPadId));
+ const pad = await padManager.getPad(testPadId);
+ assert.equal(pad.text(), padText.toString());
+ });
+
+ it('!authn exist -> replace', async function() {
+ const pad = await createTestPad('before import');
+ await agent.post(`/p/${testPadIdEnc}/import`)
+ .attach('file', padText, {filename: '/test.txt', contentType: 'text/plain'})
+ .expect(200);
+ assert(await padManager.doesPadExist(testPadId));
+ assert.equal(pad.text(), padText.toString());
+ });
+
+ it('authn anonymous !exist -> fail', async function() {
+ settings.requireAuthentication = true;
+ await agent.post(`/p/${testPadIdEnc}/import`)
+ .attach('file', padText, {filename: '/test.txt', contentType: 'text/plain'})
+ .expect(401);
+ assert(!(await padManager.doesPadExist(testPadId)));
+ });
+
+ it('authn anonymous exist -> fail', async function() {
+ settings.requireAuthentication = true;
+ const pad = await createTestPad('before import\n');
+ await agent.post(`/p/${testPadIdEnc}/import`)
+ .attach('file', padText, {filename: '/test.txt', contentType: 'text/plain'})
+ .expect(401);
+ assert.equal(pad.text(), 'before import\n');
+ });
+
+ it('authn user create !exist -> create', async function() {
+ settings.requireAuthentication = true;
+ await agent.post(`/p/${testPadIdEnc}/import`)
+ .auth('user', 'user-password')
+ .attach('file', padText, {filename: '/test.txt', contentType: 'text/plain'})
+ .expect(200);
+ assert(await padManager.doesPadExist(testPadId));
+ const pad = await padManager.getPad(testPadId);
+ assert.equal(pad.text(), padText.toString());
+ });
+
+ it('authn user modify !exist -> fail', async function() {
+ settings.requireAuthentication = true;
+ authorize = () => 'modify';
+ await agent.post(`/p/${testPadIdEnc}/import`)
+ .auth('user', 'user-password')
+ .attach('file', padText, {filename: '/test.txt', contentType: 'text/plain'})
+ .expect(403);
+ assert(!(await padManager.doesPadExist(testPadId)));
+ });
+
+ it('authn user readonly !exist -> fail', async function() {
+ settings.requireAuthentication = true;
+ authorize = () => 'readOnly';
+ await agent.post(`/p/${testPadIdEnc}/import`)
+ .auth('user', 'user-password')
+ .attach('file', padText, {filename: '/test.txt', contentType: 'text/plain'})
+ .expect(403);
+ assert(!(await padManager.doesPadExist(testPadId)));
+ });
+
+ it('authn user create exist -> replace', async function() {
+ settings.requireAuthentication = true;
+ const pad = await createTestPad('before import\n');
+ await agent.post(`/p/${testPadIdEnc}/import`)
+ .auth('user', 'user-password')
+ .attach('file', padText, {filename: '/test.txt', contentType: 'text/plain'})
+ .expect(200);
+ assert.equal(pad.text(), padText.toString());
+ });
+
+ it('authn user modify exist -> replace', async function() {
+ settings.requireAuthentication = true;
+ authorize = () => 'modify';
+ const pad = await createTestPad('before import\n');
+ await agent.post(`/p/${testPadIdEnc}/import`)
+ .auth('user', 'user-password')
+ .attach('file', padText, {filename: '/test.txt', contentType: 'text/plain'})
+ .expect(200);
+ assert.equal(pad.text(), padText.toString());
+ });
+
+ it('authn user readonly exist -> fail', async function() {
+ const pad = await createTestPad('before import\n');
+ settings.requireAuthentication = true;
+ authorize = () => 'readOnly';
+ await agent.post(`/p/${testPadIdEnc}/import`)
+ .auth('user', 'user-password')
+ .attach('file', padText, {filename: '/test.txt', contentType: 'text/plain'})
+ .expect(403);
+ assert.equal(pad.text(), 'before import\n');
+ });
});
});
-
}); // End of tests.
diff --git a/tests/backend/specs/api/instance.js b/tests/backend/specs/api/instance.js
index c7b25e8d5..a29f8fdf7 100644
--- a/tests/backend/specs/api/instance.js
+++ b/tests/backend/specs/api/instance.js
@@ -11,34 +11,36 @@ const api = supertest('http://'+settings.ip+":"+settings.port);
const apiKey = common.apiKey;
var apiVersion = '1.2.14';
-describe('Connectivity for instance-level API tests', function() {
- it('can connect', function(done) {
- api.get('/api/')
- .expect('Content-Type', /json/)
- .expect(200, done)
+describe(__filename, function() {
+ describe('Connectivity for instance-level API tests', function() {
+ it('can connect', function(done) {
+ api.get('/api/')
+ .expect('Content-Type', /json/)
+ .expect(200, done)
+ });
});
-});
-describe('getStats', function(){
- it('Gets the stats of a running instance', function(done) {
- api.get(endPoint('getStats'))
- .expect(function(res){
- if (res.body.code !== 0) throw new Error("getStats() failed");
+ describe('getStats', function() {
+ it('Gets the stats of a running instance', function(done) {
+ api.get(endPoint('getStats'))
+ .expect(function(res) {
+ if (res.body.code !== 0) throw new Error("getStats() failed");
- if (!(('totalPads' in res.body.data) && (typeof res.body.data.totalPads === 'number'))) {
- throw new Error(`Response to getStats() does not contain field totalPads, or it's not a number: ${JSON.stringify(res.body.data)}`);
- }
+ if (!(('totalPads' in res.body.data) && (typeof res.body.data.totalPads === 'number'))) {
+ throw new Error(`Response to getStats() does not contain field totalPads, or it's not a number: ${JSON.stringify(res.body.data)}`);
+ }
- if (!(('totalSessions' in res.body.data) && (typeof res.body.data.totalSessions === 'number'))) {
- throw new Error(`Response to getStats() does not contain field totalSessions, or it's not a number: ${JSON.stringify(res.body.data)}`);
- }
+ if (!(('totalSessions' in res.body.data) && (typeof res.body.data.totalSessions === 'number'))) {
+ throw new Error(`Response to getStats() does not contain field totalSessions, or it's not a number: ${JSON.stringify(res.body.data)}`);
+ }
- if (!(('totalActivePads' in res.body.data) && (typeof res.body.data.totalActivePads === 'number'))) {
- throw new Error(`Response to getStats() does not contain field totalActivePads, or it's not a number: ${JSON.stringify(res.body.data)}`);
- }
- })
- .expect('Content-Type', /json/)
- .expect(200, done);
+ if (!(('totalActivePads' in res.body.data) && (typeof res.body.data.totalActivePads === 'number'))) {
+ throw new Error(`Response to getStats() does not contain field totalActivePads, or it's not a number: ${JSON.stringify(res.body.data)}`);
+ }
+ })
+ .expect('Content-Type', /json/)
+ .expect(200, done);
+ });
});
});
diff --git a/tests/backend/specs/api/pad.js b/tests/backend/specs/api/pad.js
index 5440856e9..3f5cbf2e8 100644
--- a/tests/backend/specs/api/pad.js
+++ b/tests/backend/specs/api/pad.js
@@ -43,575 +43,576 @@ var ulSpaceHtml = '
- one
*/
var expectedSpaceHtml = '';
-describe('Connectivity', function(){
- it('can connect', function(done) {
- api.get('/api/')
- .expect('Content-Type', /json/)
- .expect(200, done)
- });
-})
-
-describe('API Versioning', function(){
- it('finds the version tag', 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 with invalid 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 -- Should be 0
- -> 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
- -> 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
- -> appendText(padID, "hello")
- -> getText(padID) -- Should be "hello worldhello"
- -> setHTML(padID) -- Should fail on invalid HTML
- -> setHTML(padID) *3 -- Should fail on invalid HTML
- -> getHTML(padID) -- Should return HTML close to posted HTML
- -> createPad -- Tries to create pads with bad url characters
-
-*/
-
-describe('deletePad', function(){
- it('deletes a Pad', function(done) {
- api.get(endPoint('deletePad')+"&padID="+testPadId)
- .expect('Content-Type', /json/)
- .expect(200, done) // @TODO: we shouldn't expect 200 here since the pad may not exist
- });
-})
-
-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('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 the HTML");
- })
- .expect('Content-Type', /json/)
- .expect(200, done)
- });
-})
-
-describe('listAllPads', function () {
- it('list all pads', function (done) {
- api.get(endPoint('listAllPads'))
- .expect(function (res) {
- if (res.body.data.padIDs.includes(testPadId) !== true) {
- throw new Error('Unable to find pad in pad list')
- }
- })
- .expect('Content-Type', /json/)
- .expect(200, done)
+describe(__filename, function() {
+ describe('Connectivity', function() {
+ it('can connect', function(done) {
+ api.get('/api/')
+ .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('listAllPads', function () {
- it('list all pads', function (done) {
- api.get(endPoint('listAllPads'))
- .expect(function (res) {
- if (res.body.data.padIDs.includes(testPadId) !== false) {
- throw new Error('Test pad should not be in pads list')
- }
- })
- .expect('Content-Type', /json/)
- .expect(200, done)
+ describe('API Versioning', function(){
+ it('finds the version tag', 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('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")
+ describe('Permission', function(){
+ it('errors with invalid 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 -- Should be 0
+ -> 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
+ -> 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
+ -> appendText(padID, "hello")
+ -> getText(padID) -- Should be "hello worldhello"
+ -> setHTML(padID) -- Should fail on invalid HTML
+ -> setHTML(padID) *3 -- Should fail on invalid HTML
+ -> getHTML(padID) -- Should return HTML close to posted HTML
+ -> createPad -- Tries to create pads with bad url characters
+
+ */
+
+ describe('deletePad', function(){
+ it('deletes a Pad', function(done) {
+ api.get(endPoint('deletePad')+"&padID="+testPadId)
+ .expect('Content-Type', /json/)
+ .expect(200, done) // @TODO: we shouldn't expect 200 here since the pad may not exist
+ });
+ })
+
+ 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('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 the HTML");
+ })
+ .expect('Content-Type', /json/)
+ .expect(200, done)
+ });
+ })
+
+ describe('listAllPads', function () {
+ it('list all pads', function (done) {
+ api.get(endPoint('listAllPads'))
+ .expect(function (res) {
+ if (res.body.data.padIDs.includes(testPadId) !== true) {
+ throw new Error('Unable to find pad in pad list')
+ }
+ })
+ .expect('Content-Type', /json/)
+ .expect(200, done)
})
- .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('listAllPads', function () {
+ it('list all pads', function (done) {
+ api.get(endPoint('listAllPads'))
+ .expect(function (res) {
+ if (res.body.data.padIDs.includes(testPadId) !== false) {
+ throw new Error('Test pad should not be in pads list')
+ }
+ })
+ .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.post(endPoint('setText'))
+ .send({
+ "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 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 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)
+ .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)
+ });
+ })
+
+ describe('listAuthorsOfPad', function(){
+ it('Get Authors of the Pad', function(done) {
+ api.get(endPoint('listAuthorsOfPad')+"&padID="+testPadId)
+ .expect(function(res){
+ if(res.body.data.authorIDs.length !== 0) throw new Error("# of Authors of pad is not 0")
+ })
+ .expect('Content-Type', /json/)
+ .expect(200, done)
+ });
+ })
+
+ describe('getLastEdited', function(){
+ it('Get When Pad was left Edited', function(done) {
+ api.get(endPoint('getLastEdited')+"&padID="+testPadId)
+ .expect(function(res){
+ if(!res.body.data.lastEdited){
+ throw new Error("# of Authors of pad is not 0")
+ }else{
+ lastEdited = res.body.data.lastEdited;
+ }
+ })
+ .expect('Content-Type', /json/)
+ .expect(200, done)
+ });
+ })
+
+ describe('setText', function(){
+ it('creates a new Pad with text', function(done) {
+ api.post(endPoint('setText'))
+ .send({
+ "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('getLastEdited', function(){
+ it('Get When Pad was left Edited', function(done) {
+ api.get(endPoint('getLastEdited')+"&padID="+testPadId)
+ .expect(function(res){
+ if(res.body.data.lastEdited <= lastEdited){
+ throw new Error("Editing A Pad is not updating when it was last edited")
+ }
+ })
+ .expect('Content-Type', /json/)
+ .expect(200, done)
+ });
+ })
+
+ describe('padUsers', function(){
+ it('gets User Count of a Pad', function(done) {
+ api.get(endPoint('padUsers')+"&padID="+testPadId)
+ .expect(function(res){
+ if(res.body.data.padUsers.length !== 0) throw new Error("Incorrect Pad Users")
+ })
+ .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)
+ });
+ })
+
+ var originalPadId = testPadId;
+ var newPadId = makeid();
+ var copiedPadId = 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.post(endPoint('setText')+"&padID="+testPadId)
+ .field({text: text})
+ .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 !== text+"\n") throw new Error("Pad Text not set properly");
+ })
+ .expect('Content-Type', /json/)
+ .expect(200, done)
+ });
+ })
+
+ describe('setText', function(){
+ it('Sets text on a pad Id including an explicit newline', function(done) {
+ api.post(endPoint('setText')+"&padID="+testPadId)
+ .field({text: text+'\n'})
+ .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 and doesn't have an excess newline", 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 !== text+"\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){
+ 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 !== text+"\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 !== text+"\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)
+ });
+ })
+
+ describe('appendText', function(){
+ it('Append text to a pad Id', function(done) {
+ api.get(endPoint('appendText', '1.2.13')+"&padID="+testPadId+"&text=hello")
+ .expect(function(res){
+ if(res.body.code !== 0) throw new Error("Pad Append Text 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 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 !== text+"hello\n") throw new Error("Pad Text not set properly");
+ })
+ .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.post(endPoint('setText'))
- .send({
- "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 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 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)
- .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)
- });
-})
-
-describe('listAuthorsOfPad', function(){
- it('Get Authors of the Pad', function(done) {
- api.get(endPoint('listAuthorsOfPad')+"&padID="+testPadId)
- .expect(function(res){
- if(res.body.data.authorIDs.length !== 0) throw new Error("# of Authors of pad is not 0")
- })
- .expect('Content-Type', /json/)
- .expect(200, done)
- });
-})
-
-describe('getLastEdited', function(){
- it('Get When Pad was left Edited', function(done) {
- api.get(endPoint('getLastEdited')+"&padID="+testPadId)
- .expect(function(res){
- if(!res.body.data.lastEdited){
- throw new Error("# of Authors of pad is not 0")
- }else{
- lastEdited = res.body.data.lastEdited;
- }
- })
- .expect('Content-Type', /json/)
- .expect(200, done)
- });
-})
-
-describe('setText', function(){
- it('creates a new Pad with text', function(done) {
- api.post(endPoint('setText'))
- .send({
- "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('getLastEdited', function(){
- it('Get When Pad was left Edited', function(done) {
- api.get(endPoint('getLastEdited')+"&padID="+testPadId)
- .expect(function(res){
- if(res.body.data.lastEdited <= lastEdited){
- throw new Error("Editing A Pad is not updating when it was last edited")
- }
- })
- .expect('Content-Type', /json/)
- .expect(200, done)
- });
-})
-
-describe('padUsers', function(){
- it('gets User Count of a Pad', function(done) {
- api.get(endPoint('padUsers')+"&padID="+testPadId)
- .expect(function(res){
- if(res.body.data.padUsers.length !== 0) throw new Error("Incorrect Pad Users")
- })
- .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)
- });
-})
-
-var originalPadId = testPadId;
-var newPadId = makeid();
-var copiedPadId = 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.post(endPoint('setText')+"&padID="+testPadId)
- .field({text: text})
- .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 !== text+"\n") throw new Error("Pad Text not set properly");
- })
- .expect('Content-Type', /json/)
- .expect(200, done)
- });
-})
-
-describe('setText', function(){
- it('Sets text on a pad Id including an explicit newline', function(done) {
- api.post(endPoint('setText')+"&padID="+testPadId)
- .field({text: text+'\n'})
- .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 and doesn't have an excess newline", 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 !== text+"\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){
- 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 !== text+"\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 !== text+"\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)
- });
-})
-
-describe('appendText', function(){
- it('Append text to a pad Id', function(done) {
- api.get(endPoint('appendText', '1.2.13')+"&padID="+testPadId+"&text=hello")
- .expect(function(res){
- if(res.body.code !== 0) throw new Error("Pad Append 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 !== text+"hello\n") throw new Error("Pad Text not set properly");
- })
- .expect('Content-Type', /json/)
- .expect(200, done);
- });
-});
-describe('setHTML', function(){
- it('Sets the HTML of a Pad attempting to pass ugly HTML', function(done) {
- var html = "Hello HTML
";
- api.post(endPoint('setHTML'))
- .send({
- "padID": testPadId,
- "html": html,
- })
- .expect(function(res){
- if(res.body.code !== 0) throw new Error("Crappy HTML Can't be Imported[we weren't able to sanitize it']")
- })
- .expect('Content-Type', /json/)
- .expect(200, done)
- });
-})
+ describe('setHTML', function(){
+ it('Sets the HTML of a Pad attempting to pass ugly HTML', function(done) {
+ var html = "Hello HTML
";
+ api.post(endPoint('setHTML'))
+ .send({
+ "padID": testPadId,
+ "html": html,
+ })
+ .expect(function(res){
+ if(res.body.code !== 0) throw new Error("Crappy HTML Can't be Imported[we weren't able to sanitize it']")
+ })
+ .expect('Content-Type', /json/)
+ .expect(200, done)
+ });
+ })
-describe('setHTML', function(){
- it('Sets the HTML of a Pad with complex nested lists of different types', function(done) {
- api.post(endPoint('setHTML'))
- .send({
- "padID": testPadId,
- "html": ulHtml,
- })
- .expect(function(res){
- if(res.body.code !== 0) throw new Error("List HTML cant be imported")
- })
- .expect('Content-Type', /json/)
- .expect(200, done)
- });
-})
+ describe('setHTML', function(){
+ it('Sets the HTML of a Pad with complex nested lists of different types', function(done) {
+ api.post(endPoint('setHTML'))
+ .send({
+ "padID": testPadId,
+ "html": ulHtml,
+ })
+ .expect(function(res){
+ if(res.body.code !== 0) throw new Error("List HTML cant be imported")
+ })
+ .expect('Content-Type', /json/)
+ .expect(200, done)
+ });
+ })
-describe('getHTML', function(){
- it('Gets back the HTML of a Pad with complex nested lists of different types', function(done) {
- api.get(endPoint('getHTML')+"&padID="+testPadId)
- .expect(function(res){
- var receivedHtml = res.body.data.html.replace("
a paragraph
List without outer ULtrailing closing p