mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-19 14:13:34 +01:00
tests: Factor out common skip checks
This commit is contained in:
parent
1c3c5b744c
commit
54c999fe83
1 changed files with 153 additions and 199 deletions
|
@ -70,227 +70,185 @@ Example Curl command for testing import URI:
|
||||||
*/
|
*/
|
||||||
|
|
||||||
describe('Imports and Exports', function(){
|
describe('Imports and Exports', function(){
|
||||||
it('creates a new Pad, imports content to it, checks that content', function(done) {
|
before(function() {
|
||||||
if(!settings.allowAnyoneToImport){
|
if (!settings.allowAnyoneToImport) {
|
||||||
console.warn("not anyone can import so not testing -- to include this test set allowAnyoneToImport to true in settings.json");
|
console.warn('not anyone can import so not testing -- ' +
|
||||||
|
'to include this test set allowAnyoneToImport to true in settings.json');
|
||||||
this.skip();
|
this.skip();
|
||||||
done();
|
|
||||||
}else{
|
|
||||||
api.get(endPoint('createPad')+"&padID="+testPadId)
|
|
||||||
.expect(function(res){
|
|
||||||
if(res.body.code !== 0) throw new Error("Unable to create new Pad");
|
|
||||||
|
|
||||||
var req = request.post(host + '/p/'+testPadId+'/import', function (err, res, body) {
|
|
||||||
if (err) {
|
|
||||||
throw new Error("Failed to import", err);
|
|
||||||
} else {
|
|
||||||
api.get(endPoint('getText')+"&padID="+testPadId)
|
|
||||||
.expect(function(res){
|
|
||||||
if(res.body.data.text !== padText.toString()){
|
|
||||||
throw new Error("text is wrong on export");
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let form = req.form();
|
|
||||||
|
|
||||||
form.append('file', padText, {
|
|
||||||
filename: '/test.txt',
|
|
||||||
contentType: 'text/plain'
|
|
||||||
});
|
|
||||||
|
|
||||||
})
|
|
||||||
.expect('Content-Type', /json/)
|
|
||||||
.expect(200, done)
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// For some reason word import does not work in testing..
|
it('creates a new Pad, imports content to it, checks that content', function(done) {
|
||||||
// TODO: fix support for .doc files..
|
api.get(endPoint('createPad') + "&padID=" + testPadId)
|
||||||
it('Tries to import .doc that uses soffice or abiword', function(done) {
|
.expect(function(res) {
|
||||||
if (!settings.allowAnyoneToImport) { this.skip(); return done(); }
|
if (res.body.code !== 0) throw new Error("Unable to create new Pad");
|
||||||
if ((!settings.abiword || settings.abiword.indexOf('/') === -1) &&
|
|
||||||
(!settings.soffice || settings.soffice.indexOf('/') === -1)) {
|
|
||||||
this.skip();
|
|
||||||
return done();
|
|
||||||
}
|
|
||||||
|
|
||||||
var req = request.post(host + '/p/'+testPadId+'/import', function (err, res, body) {
|
var req = request.post(host + '/p/' + testPadId + '/import', function(err, res, body) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw new Error("Failed to import", err);
|
throw new Error("Failed to import", err);
|
||||||
} else {
|
} else {
|
||||||
if(res.body.indexOf("FrameCall('undefined', 'ok');") === -1){
|
api.get(endPoint('getText')+"&padID="+testPadId)
|
||||||
throw new Error("Failed DOC import", testPadId);
|
.expect(function(res){
|
||||||
}else{
|
if(res.body.data.text !== padText.toString()){
|
||||||
done();
|
throw new Error("text is wrong on export");
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let form = req.form();
|
||||||
|
|
||||||
|
form.append('file', padText, {
|
||||||
|
filename: '/test.txt',
|
||||||
|
contentType: 'text/plain'
|
||||||
|
});
|
||||||
|
|
||||||
|
})
|
||||||
|
.expect('Content-Type', /json/)
|
||||||
|
.expect(200, done)
|
||||||
|
});
|
||||||
|
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let form = req.form();
|
// For some reason word import does not work in testing..
|
||||||
form.append('file', wordDoc, {
|
// TODO: fix support for .doc files..
|
||||||
filename: '/test.doc',
|
it('Tries to import .doc that uses soffice or abiword', function(done) {
|
||||||
contentType: 'application/msword'
|
var req = request.post(host + '/p/'+testPadId+'/import', function (err, res, body) {
|
||||||
});
|
if (err) {
|
||||||
});
|
throw new Error("Failed to import", err);
|
||||||
|
} else {
|
||||||
|
if(res.body.indexOf("FrameCall('undefined', 'ok');") === -1){
|
||||||
|
throw new Error("Failed DOC import", testPadId);
|
||||||
|
}else{
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
it('exports DOC', function(done) {
|
let form = req.form();
|
||||||
if (!settings.allowAnyoneToImport) { this.skip(); return done(); }
|
form.append('file', wordDoc, {
|
||||||
if ((!settings.abiword || settings.abiword.indexOf('/') === -1) &&
|
filename: '/test.doc',
|
||||||
(!settings.soffice || settings.soffice.indexOf('/') === -1)) {
|
contentType: 'application/msword'
|
||||||
this.skip();
|
});
|
||||||
return done();
|
});
|
||||||
}
|
|
||||||
try{
|
it('exports DOC', function(done) {
|
||||||
|
try{
|
||||||
|
request(host + '/p/'+testPadId+'/export/doc', function (err, res, body) {
|
||||||
|
// TODO: At some point checking that the contents is correct would be suitable
|
||||||
|
if(body.length >= 9000){
|
||||||
|
done();
|
||||||
|
}else{
|
||||||
|
throw new Error("Word Document export length is not right");
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}catch(e){
|
||||||
|
throw new Error(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Tries to import .docx that uses soffice or abiword', function(done) {
|
||||||
|
var req = request.post(host + '/p/'+testPadId+'/import', function (err, res, body) {
|
||||||
|
if (err) {
|
||||||
|
throw new Error("Failed to import", err);
|
||||||
|
} else {
|
||||||
|
if(res.body.indexOf("FrameCall('undefined', 'ok');") === -1){
|
||||||
|
throw new Error("Failed DOCX import");
|
||||||
|
}else{
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let form = req.form();
|
||||||
|
form.append('file', wordXDoc, {
|
||||||
|
filename: '/test.docx',
|
||||||
|
contentType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('exports DOC from imported DOCX', function(done) {
|
||||||
request(host + '/p/'+testPadId+'/export/doc', function (err, res, body) {
|
request(host + '/p/'+testPadId+'/export/doc', function (err, res, body) {
|
||||||
// TODO: At some point checking that the contents is correct would be suitable
|
// TODO: At some point checking that the contents is correct would be suitable
|
||||||
if(body.length >= 9000){
|
if(body.length >= 9100){
|
||||||
done();
|
done();
|
||||||
}else{
|
}else{
|
||||||
throw new Error("Word Document export length is not right");
|
throw new Error("Word Document export length is not right");
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}catch(e){
|
});
|
||||||
throw new Error(e);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
it('Tries to import .docx that uses soffice or abiword', function(done) {
|
it('Tries to import .pdf that uses soffice or abiword', function(done) {
|
||||||
if (!settings.allowAnyoneToImport) { this.skip(); return done(); }
|
var req = request.post(host + '/p/'+testPadId+'/import', function (err, res, body) {
|
||||||
if ((!settings.abiword || settings.abiword.indexOf('/') === -1) &&
|
if (err) {
|
||||||
(!settings.soffice || settings.soffice.indexOf('/') === -1)) {
|
throw new Error("Failed to import", err);
|
||||||
this.skip();
|
} else {
|
||||||
return done();
|
if(res.body.indexOf("FrameCall('undefined', 'ok');") === -1){
|
||||||
}
|
throw new Error("Failed PDF import");
|
||||||
|
}else{
|
||||||
var req = request.post(host + '/p/'+testPadId+'/import', function (err, res, body) {
|
done();
|
||||||
if (err) {
|
}
|
||||||
throw new Error("Failed to import", err);
|
|
||||||
} else {
|
|
||||||
if(res.body.indexOf("FrameCall('undefined', 'ok');") === -1){
|
|
||||||
throw new Error("Failed DOCX import");
|
|
||||||
}else{
|
|
||||||
done();
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
|
let form = req.form();
|
||||||
|
form.append('file', pdfDoc, {
|
||||||
|
filename: '/test.pdf',
|
||||||
|
contentType: 'application/pdf'
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
let form = req.form();
|
it('exports PDF', function(done) {
|
||||||
form.append('file', wordXDoc, {
|
request(host + '/p/'+testPadId+'/export/pdf', function (err, res, body) {
|
||||||
filename: '/test.docx',
|
// TODO: At some point checking that the contents is correct would be suitable
|
||||||
contentType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
|
if(body.length >= 1000){
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('exports DOC from imported DOCX', function(done) {
|
|
||||||
if (!settings.allowAnyoneToImport) { this.skip(); return done(); }
|
|
||||||
if ((!settings.abiword || settings.abiword.indexOf('/') === -1) &&
|
|
||||||
(!settings.soffice || settings.soffice.indexOf('/') === -1)) {
|
|
||||||
this.skip();
|
|
||||||
return done();
|
|
||||||
}
|
|
||||||
request(host + '/p/'+testPadId+'/export/doc', function (err, res, body) {
|
|
||||||
// TODO: At some point checking that the contents is correct would be suitable
|
|
||||||
if(body.length >= 9100){
|
|
||||||
done();
|
|
||||||
}else{
|
|
||||||
throw new Error("Word Document export length is not right");
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it('Tries to import .pdf that uses soffice or abiword', function(done) {
|
|
||||||
if (!settings.allowAnyoneToImport) { this.skip(); return done(); }
|
|
||||||
if ((!settings.abiword || settings.abiword.indexOf('/') === -1) &&
|
|
||||||
(!settings.soffice || settings.soffice.indexOf('/') === -1)) {
|
|
||||||
this.skip();
|
|
||||||
return done();
|
|
||||||
}
|
|
||||||
|
|
||||||
var req = request.post(host + '/p/'+testPadId+'/import', function (err, res, body) {
|
|
||||||
if (err) {
|
|
||||||
throw new Error("Failed to import", err);
|
|
||||||
} else {
|
|
||||||
if(res.body.indexOf("FrameCall('undefined', 'ok');") === -1){
|
|
||||||
throw new Error("Failed PDF import");
|
|
||||||
}else{
|
|
||||||
done();
|
done();
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let form = req.form();
|
|
||||||
form.append('file', pdfDoc, {
|
|
||||||
filename: '/test.pdf',
|
|
||||||
contentType: 'application/pdf'
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('exports PDF', function(done) {
|
|
||||||
if (!settings.allowAnyoneToImport) { this.skip(); return done(); }
|
|
||||||
if ((!settings.abiword || settings.abiword.indexOf('/') === -1) &&
|
|
||||||
(!settings.soffice || settings.soffice.indexOf('/') === -1)) {
|
|
||||||
this.skip();
|
|
||||||
return done();
|
|
||||||
}
|
|
||||||
request(host + '/p/'+testPadId+'/export/pdf', function (err, res, body) {
|
|
||||||
// TODO: At some point checking that the contents is correct would be suitable
|
|
||||||
if(body.length >= 1000){
|
|
||||||
done();
|
|
||||||
}else{
|
|
||||||
throw new Error("PDF Document export length is not right");
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it('Tries to import .odt that uses soffice or abiword', function(done) {
|
|
||||||
if (!settings.allowAnyoneToImport) { this.skip(); return done(); }
|
|
||||||
if ((!settings.abiword || settings.abiword.indexOf('/') === -1) &&
|
|
||||||
(!settings.soffice || settings.soffice.indexOf('/') === -1)) {
|
|
||||||
this.skip();
|
|
||||||
return done();
|
|
||||||
}
|
|
||||||
|
|
||||||
var req = request.post(host + '/p/'+testPadId+'/import', function (err, res, body) {
|
|
||||||
if (err) {
|
|
||||||
throw new Error("Failed to import", err);
|
|
||||||
} else {
|
|
||||||
if(res.body.indexOf("FrameCall('undefined', 'ok');") === -1){
|
|
||||||
throw new Error("Failed ODT import", testPadId);
|
|
||||||
}else{
|
}else{
|
||||||
done();
|
throw new Error("PDF Document export length is not right");
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
let form = req.form();
|
it('Tries to import .odt that uses soffice or abiword', function(done) {
|
||||||
form.append('file', odtDoc, {
|
var req = request.post(host + '/p/'+testPadId+'/import', function (err, res, body) {
|
||||||
filename: '/test.odt',
|
if (err) {
|
||||||
contentType: 'application/odt'
|
throw new Error("Failed to import", err);
|
||||||
});
|
} else {
|
||||||
});
|
if(res.body.indexOf("FrameCall('undefined', 'ok');") === -1){
|
||||||
|
throw new Error("Failed ODT import", testPadId);
|
||||||
|
}else{
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
it('exports ODT', function(done) {
|
let form = req.form();
|
||||||
if (!settings.allowAnyoneToImport) { this.skip(); return done(); }
|
form.append('file', odtDoc, {
|
||||||
if ((!settings.abiword || settings.abiword.indexOf('/') === -1) &&
|
filename: '/test.odt',
|
||||||
(!settings.soffice || settings.soffice.indexOf('/') === -1)) {
|
contentType: 'application/odt'
|
||||||
this.skip();
|
});
|
||||||
return done();
|
});
|
||||||
}
|
|
||||||
request(host + '/p/'+testPadId+'/export/odt', function (err, res, body) {
|
it('exports ODT', function(done) {
|
||||||
// TODO: At some point checking that the contents is correct would be suitable
|
request(host + '/p/'+testPadId+'/export/odt', function (err, res, body) {
|
||||||
if(body.length >= 7000){
|
// TODO: At some point checking that the contents is correct would be suitable
|
||||||
done();
|
if(body.length >= 7000){
|
||||||
}else{
|
done();
|
||||||
throw new Error("ODT Document export length is not right");
|
}else{
|
||||||
}
|
throw new Error("ODT Document export length is not right");
|
||||||
})
|
}
|
||||||
})
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
}); // End of AbiWord/LibreOffice tests.
|
||||||
|
|
||||||
it('Tries to import .etherpad', function(done) {
|
it('Tries to import .etherpad', function(done) {
|
||||||
if (!settings.allowAnyoneToImport) { this.skip(); return done(); }
|
|
||||||
|
|
||||||
var req = request.post(host + '/p/'+testPadId+'/import', function (err, res, body) {
|
var req = request.post(host + '/p/'+testPadId+'/import', function (err, res, body) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw new Error("Failed to import", err);
|
throw new Error("Failed to import", err);
|
||||||
|
@ -311,7 +269,6 @@ describe('Imports and Exports', function(){
|
||||||
});
|
});
|
||||||
|
|
||||||
it('exports Etherpad', function(done) {
|
it('exports Etherpad', function(done) {
|
||||||
if (!settings.allowAnyoneToImport) { this.skip(); return done(); }
|
|
||||||
request(host + '/p/'+testPadId+'/export/etherpad', function (err, res, body) {
|
request(host + '/p/'+testPadId+'/export/etherpad', function (err, res, body) {
|
||||||
// TODO: At some point checking that the contents is correct would be suitable
|
// TODO: At some point checking that the contents is correct would be suitable
|
||||||
if(body.indexOf("hello") !== -1){
|
if(body.indexOf("hello") !== -1){
|
||||||
|
@ -321,10 +278,9 @@ describe('Imports and Exports', function(){
|
||||||
throw new Error("Etherpad Document does not include hello");
|
throw new Error("Etherpad Document does not include hello");
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
});
|
||||||
|
|
||||||
it('exports HTML for this Etherpad file', function(done) {
|
it('exports HTML for this Etherpad file', function(done) {
|
||||||
if (!settings.allowAnyoneToImport) { this.skip(); return done(); }
|
|
||||||
request(host + '/p/'+testPadId+'/export/html', function (err, res, body) {
|
request(host + '/p/'+testPadId+'/export/html', function (err, res, body) {
|
||||||
|
|
||||||
// broken pre fix export -- <ul class="bullet"></li><ul class="bullet"></ul></li></ul>
|
// broken pre fix export -- <ul class="bullet"></li><ul class="bullet"></ul></li></ul>
|
||||||
|
@ -337,10 +293,9 @@ describe('Imports and Exports', function(){
|
||||||
throw new Error("Exported HTML nested list items is not right", body);
|
throw new Error("Exported HTML nested list items is not right", body);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
});
|
||||||
|
|
||||||
it('tries to import Plain Text to a pad that does not exist', function(done) {
|
it('tries to import Plain Text to a pad that does not exist', function(done) {
|
||||||
if (!settings.allowAnyoneToImport) { this.skip(); return done(); }
|
|
||||||
var req = request.post(host + '/p/'+testPadId+testPadId+testPadId+'/import', function (err, res, body) {
|
var req = request.post(host + '/p/'+testPadId+testPadId+testPadId+'/import', function (err, res, body) {
|
||||||
if (res.statusCode === 200) {
|
if (res.statusCode === 200) {
|
||||||
throw new Error("Was able to import to a pad that doesn't exist");
|
throw new Error("Was able to import to a pad that doesn't exist");
|
||||||
|
@ -363,7 +318,6 @@ describe('Imports and Exports', function(){
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Tries to import unsupported file type', function(done) {
|
it('Tries to import unsupported file type', function(done) {
|
||||||
if (!settings.allowAnyoneToImport) { this.skip(); return done(); }
|
|
||||||
if(settings.allowUnknownFileEnds === true){
|
if(settings.allowUnknownFileEnds === true){
|
||||||
console.log("allowing unknown file ends so skipping this test");
|
console.log("allowing unknown file ends so skipping this test");
|
||||||
this.skip();
|
this.skip();
|
||||||
|
|
Loading…
Reference in a new issue