lint and timeouts for pad.js

This commit is contained in:
John McLear 2021-01-27 20:45:31 +00:00
parent e5d80a0696
commit 3d69773cd2

View file

@ -1,3 +1,5 @@
'use strict';
/* /*
* ACHTUNG: there is a copied & modified version of this file in * ACHTUNG: there is a copied & modified version of this file in
* <basedir>/tests/container/specs/api/pad.js * <basedir>/tests/container/specs/api/pad.js
@ -46,6 +48,7 @@ const expectedSpaceHtml = '<!doctype html><html><body><ul class="bullet"><li>one
describe(__filename, function () { describe(__filename, function () {
describe('Connectivity', function () { describe('Connectivity', function () {
it('can connect', function (done) { it('can connect', function (done) {
this.timeout(200);
api.get('/api/') api.get('/api/')
.expect('Content-Type', /json/) .expect('Content-Type', /json/)
.expect(200, done); .expect(200, done);
@ -54,6 +57,7 @@ describe(__filename, function () {
describe('API Versioning', function () { describe('API Versioning', function () {
it('finds the version tag', function (done) { it('finds the version tag', function (done) {
this.timeout(150);
api.get('/api/') api.get('/api/')
.expect((res) => { .expect((res) => {
apiVersion = res.body.currentVersion; apiVersion = res.body.currentVersion;
@ -66,6 +70,7 @@ describe(__filename, function () {
describe('Permission', function () { describe('Permission', function () {
it('errors with invalid APIKey', function (done) { it('errors with invalid APIKey', function (done) {
this.timeout(150);
// This is broken because Etherpad doesn't handle HTTP codes properly see #2343 // 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 // If your APIKey is password you deserve to fail all tests anyway
const permErrorURL = `/api/${apiVersion}/createPad?apikey=password&padID=test`; const permErrorURL = `/api/${apiVersion}/createPad?apikey=password&padID=test`;
@ -118,6 +123,7 @@ describe(__filename, function () {
describe('deletePad', function () { describe('deletePad', function () {
it('deletes a Pad', function (done) { it('deletes a Pad', function (done) {
this.timeout(100);
api.get(`${endPoint('deletePad')}&padID=${testPadId}`) api.get(`${endPoint('deletePad')}&padID=${testPadId}`)
.expect('Content-Type', /json/) .expect('Content-Type', /json/)
.expect(200, done); // @TODO: we shouldn't expect 200 here since the pad may not exist .expect(200, done); // @TODO: we shouldn't expect 200 here since the pad may not exist
@ -126,6 +132,7 @@ describe(__filename, function () {
describe('createPad', function () { describe('createPad', function () {
it('creates a new Pad', function (done) { it('creates a new Pad', function (done) {
this.timeout(100);
api.get(`${endPoint('createPad')}&padID=${testPadId}`) api.get(`${endPoint('createPad')}&padID=${testPadId}`)
.expect((res) => { .expect((res) => {
if (res.body.code !== 0) throw new Error('Unable to create new Pad'); if (res.body.code !== 0) throw new Error('Unable to create new Pad');
@ -137,6 +144,7 @@ describe(__filename, function () {
describe('getRevisionsCount', function () { describe('getRevisionsCount', function () {
it('gets revision count of Pad', function (done) { it('gets revision count of Pad', function (done) {
this.timeout(100);
api.get(`${endPoint('getRevisionsCount')}&padID=${testPadId}`) api.get(`${endPoint('getRevisionsCount')}&padID=${testPadId}`)
.expect((res) => { .expect((res) => {
if (res.body.code !== 0) throw new Error('Unable to get Revision Count'); if (res.body.code !== 0) throw new Error('Unable to get Revision Count');
@ -149,6 +157,7 @@ describe(__filename, function () {
describe('getSavedRevisionsCount', function () { describe('getSavedRevisionsCount', function () {
it('gets saved revisions count of Pad', function (done) { it('gets saved revisions count of Pad', function (done) {
this.timeout(100);
api.get(`${endPoint('getSavedRevisionsCount')}&padID=${testPadId}`) api.get(`${endPoint('getSavedRevisionsCount')}&padID=${testPadId}`)
.expect((res) => { .expect((res) => {
if (res.body.code !== 0) throw new Error('Unable to get Saved Revisions Count'); if (res.body.code !== 0) throw new Error('Unable to get Saved Revisions Count');
@ -161,6 +170,7 @@ describe(__filename, function () {
describe('listSavedRevisions', function () { describe('listSavedRevisions', function () {
it('gets saved revision list of Pad', function (done) { it('gets saved revision list of Pad', function (done) {
this.timeout(100);
api.get(`${endPoint('listSavedRevisions')}&padID=${testPadId}`) api.get(`${endPoint('listSavedRevisions')}&padID=${testPadId}`)
.expect((res) => { .expect((res) => {
if (res.body.code !== 0) throw new Error('Unable to get Saved Revisions List'); if (res.body.code !== 0) throw new Error('Unable to get Saved Revisions List');
@ -173,6 +183,7 @@ describe(__filename, function () {
describe('getHTML', function () { describe('getHTML', function () {
it('get the HTML of Pad', function (done) { it('get the HTML of Pad', function (done) {
this.timeout(100);
api.get(`${endPoint('getHTML')}&padID=${testPadId}`) api.get(`${endPoint('getHTML')}&padID=${testPadId}`)
.expect((res) => { .expect((res) => {
if (res.body.data.html.length <= 1) throw new Error('Unable to get the HTML'); if (res.body.data.html.length <= 1) throw new Error('Unable to get the HTML');
@ -184,6 +195,7 @@ describe(__filename, function () {
describe('listAllPads', function () { describe('listAllPads', function () {
it('list all pads', function (done) { it('list all pads', function (done) {
this.timeout(100);
api.get(endPoint('listAllPads')) api.get(endPoint('listAllPads'))
.expect((res) => { .expect((res) => {
if (res.body.data.padIDs.includes(testPadId) !== true) { if (res.body.data.padIDs.includes(testPadId) !== true) {
@ -197,6 +209,7 @@ describe(__filename, function () {
describe('deletePad', function () { describe('deletePad', function () {
it('deletes a Pad', function (done) { it('deletes a Pad', function (done) {
this.timeout(100);
api.get(`${endPoint('deletePad')}&padID=${testPadId}`) api.get(`${endPoint('deletePad')}&padID=${testPadId}`)
.expect((res) => { .expect((res) => {
if (res.body.code !== 0) throw new Error('Pad Deletion failed'); if (res.body.code !== 0) throw new Error('Pad Deletion failed');
@ -208,6 +221,7 @@ describe(__filename, function () {
describe('listAllPads', function () { describe('listAllPads', function () {
it('list all pads', function (done) { it('list all pads', function (done) {
this.timeout(100);
api.get(endPoint('listAllPads')) api.get(endPoint('listAllPads'))
.expect((res) => { .expect((res) => {
if (res.body.data.padIDs.includes(testPadId) !== false) { if (res.body.data.padIDs.includes(testPadId) !== false) {
@ -221,6 +235,7 @@ describe(__filename, function () {
describe('getHTML', function () { describe('getHTML', function () {
it('get the HTML of a Pad -- Should return a failure', function (done) { it('get the HTML of a Pad -- Should return a failure', function (done) {
this.timeout(100);
api.get(`${endPoint('getHTML')}&padID=${testPadId}`) api.get(`${endPoint('getHTML')}&padID=${testPadId}`)
.expect((res) => { .expect((res) => {
if (res.body.code !== 1) throw new Error('Pad deletion failed'); if (res.body.code !== 1) throw new Error('Pad deletion failed');
@ -232,6 +247,7 @@ describe(__filename, function () {
describe('createPad', function () { describe('createPad', function () {
it('creates a new Pad with text', function (done) { it('creates a new Pad with text', function (done) {
this.timeout(100);
api.get(`${endPoint('createPad')}&padID=${testPadId}&text=testText`) api.get(`${endPoint('createPad')}&padID=${testPadId}&text=testText`)
.expect((res) => { .expect((res) => {
if (res.body.code !== 0) throw new Error('Pad Creation failed'); if (res.body.code !== 0) throw new Error('Pad Creation failed');
@ -243,6 +259,7 @@ describe(__filename, function () {
describe('getText', function () { describe('getText', function () {
it('gets the Pad text and expect it to be testText with \n which is a line break', function (done) { it('gets the Pad text and expect it to be testText with \n which is a line break', function (done) {
this.timeout(100);
api.get(`${endPoint('getText')}&padID=${testPadId}`) api.get(`${endPoint('getText')}&padID=${testPadId}`)
.expect((res) => { .expect((res) => {
if (res.body.data.text !== 'testText\n') throw new Error('Pad Creation with text'); if (res.body.data.text !== 'testText\n') throw new Error('Pad Creation with text');
@ -254,6 +271,7 @@ describe(__filename, function () {
describe('setText', function () { describe('setText', function () {
it('creates a new Pad with text', function (done) { it('creates a new Pad with text', function (done) {
this.timeout(200);
api.post(endPoint('setText')) api.post(endPoint('setText'))
.send({ .send({
padID: testPadId, padID: testPadId,
@ -269,6 +287,7 @@ describe(__filename, function () {
describe('getText', function () { describe('getText', function () {
it('gets the Pad text', function (done) { it('gets the Pad text', function (done) {
this.timeout(100);
api.get(`${endPoint('getText')}&padID=${testPadId}`) api.get(`${endPoint('getText')}&padID=${testPadId}`)
.expect((res) => { .expect((res) => {
if (res.body.data.text !== 'testTextTwo\n') throw new Error('Setting Text'); if (res.body.data.text !== 'testTextTwo\n') throw new Error('Setting Text');
@ -280,6 +299,7 @@ describe(__filename, function () {
describe('getRevisionsCount', function () { describe('getRevisionsCount', function () {
it('gets Revision Count of a Pad', function (done) { it('gets Revision Count of a Pad', function (done) {
this.timeout(100);
api.get(`${endPoint('getRevisionsCount')}&padID=${testPadId}`) api.get(`${endPoint('getRevisionsCount')}&padID=${testPadId}`)
.expect((res) => { .expect((res) => {
if (res.body.data.revisions !== 1) throw new Error('Unable to get text revision count'); if (res.body.data.revisions !== 1) throw new Error('Unable to get text revision count');
@ -291,6 +311,7 @@ describe(__filename, function () {
describe('saveRevision', function () { describe('saveRevision', function () {
it('saves Revision', function (done) { it('saves Revision', function (done) {
this.timeout(100);
api.get(`${endPoint('saveRevision')}&padID=${testPadId}`) api.get(`${endPoint('saveRevision')}&padID=${testPadId}`)
.expect((res) => { .expect((res) => {
if (res.body.code !== 0) throw new Error('Unable to save Revision'); if (res.body.code !== 0) throw new Error('Unable to save Revision');
@ -302,6 +323,7 @@ describe(__filename, function () {
describe('getSavedRevisionsCount', function () { describe('getSavedRevisionsCount', function () {
it('gets saved revisions count of Pad', function (done) { it('gets saved revisions count of Pad', function (done) {
this.timeout(100);
api.get(`${endPoint('getSavedRevisionsCount')}&padID=${testPadId}`) api.get(`${endPoint('getSavedRevisionsCount')}&padID=${testPadId}`)
.expect((res) => { .expect((res) => {
if (res.body.code !== 0) throw new Error('Unable to get Saved Revisions Count'); if (res.body.code !== 0) throw new Error('Unable to get Saved Revisions Count');
@ -314,6 +336,7 @@ describe(__filename, function () {
describe('listSavedRevisions', function () { describe('listSavedRevisions', function () {
it('gets saved revision list of Pad', function (done) { it('gets saved revision list of Pad', function (done) {
this.timeout(100);
api.get(`${endPoint('listSavedRevisions')}&padID=${testPadId}`) api.get(`${endPoint('listSavedRevisions')}&padID=${testPadId}`)
.expect((res) => { .expect((res) => {
if (res.body.code !== 0) throw new Error('Unable to get Saved Revisions List'); if (res.body.code !== 0) throw new Error('Unable to get Saved Revisions List');
@ -325,6 +348,7 @@ describe(__filename, function () {
}); });
describe('padUsersCount', function () { describe('padUsersCount', function () {
it('gets User Count of a Pad', function (done) { it('gets User Count of a Pad', function (done) {
this.timeout(100);
api.get(`${endPoint('padUsersCount')}&padID=${testPadId}`) api.get(`${endPoint('padUsersCount')}&padID=${testPadId}`)
.expect((res) => { .expect((res) => {
if (res.body.data.padUsersCount !== 0) throw new Error('Incorrect Pad User count'); if (res.body.data.padUsersCount !== 0) throw new Error('Incorrect Pad User count');
@ -336,6 +360,7 @@ describe(__filename, function () {
describe('getReadOnlyID', function () { describe('getReadOnlyID', function () {
it('Gets the Read Only ID of a Pad', function (done) { it('Gets the Read Only ID of a Pad', function (done) {
this.timeout(100);
api.get(`${endPoint('getReadOnlyID')}&padID=${testPadId}`) api.get(`${endPoint('getReadOnlyID')}&padID=${testPadId}`)
.expect((res) => { .expect((res) => {
if (!res.body.data.readOnlyID) throw new Error('No Read Only ID for Pad'); if (!res.body.data.readOnlyID) throw new Error('No Read Only ID for Pad');
@ -347,6 +372,7 @@ describe(__filename, function () {
describe('listAuthorsOfPad', function () { describe('listAuthorsOfPad', function () {
it('Get Authors of the Pad', function (done) { it('Get Authors of the Pad', function (done) {
this.timeout(100);
api.get(`${endPoint('listAuthorsOfPad')}&padID=${testPadId}`) api.get(`${endPoint('listAuthorsOfPad')}&padID=${testPadId}`)
.expect((res) => { .expect((res) => {
if (res.body.data.authorIDs.length !== 0) throw new Error('# of Authors of pad is not 0'); if (res.body.data.authorIDs.length !== 0) throw new Error('# of Authors of pad is not 0');
@ -358,6 +384,7 @@ describe(__filename, function () {
describe('getLastEdited', function () { describe('getLastEdited', function () {
it('Get When Pad was left Edited', function (done) { it('Get When Pad was left Edited', function (done) {
this.timeout(100);
api.get(`${endPoint('getLastEdited')}&padID=${testPadId}`) api.get(`${endPoint('getLastEdited')}&padID=${testPadId}`)
.expect((res) => { .expect((res) => {
if (!res.body.data.lastEdited) { if (!res.body.data.lastEdited) {
@ -373,6 +400,7 @@ describe(__filename, function () {
describe('setText', function () { describe('setText', function () {
it('creates a new Pad with text', function (done) { it('creates a new Pad with text', function (done) {
this.timeout(200);
api.post(endPoint('setText')) api.post(endPoint('setText'))
.send({ .send({
padID: testPadId, padID: testPadId,
@ -388,6 +416,7 @@ describe(__filename, function () {
describe('getLastEdited', function () { describe('getLastEdited', function () {
it('Get When Pad was left Edited', function (done) { it('Get When Pad was left Edited', function (done) {
this.timeout(100);
api.get(`${endPoint('getLastEdited')}&padID=${testPadId}`) api.get(`${endPoint('getLastEdited')}&padID=${testPadId}`)
.expect((res) => { .expect((res) => {
if (res.body.data.lastEdited <= lastEdited) { if (res.body.data.lastEdited <= lastEdited) {
@ -401,6 +430,7 @@ describe(__filename, function () {
describe('padUsers', function () { describe('padUsers', function () {
it('gets User Count of a Pad', function (done) { it('gets User Count of a Pad', function (done) {
this.timeout(100);
api.get(`${endPoint('padUsers')}&padID=${testPadId}`) api.get(`${endPoint('padUsers')}&padID=${testPadId}`)
.expect((res) => { .expect((res) => {
if (res.body.data.padUsers.length !== 0) throw new Error('Incorrect Pad Users'); if (res.body.data.padUsers.length !== 0) throw new Error('Incorrect Pad Users');
@ -412,6 +442,7 @@ describe(__filename, function () {
describe('deletePad', function () { describe('deletePad', function () {
it('deletes a Pad', function (done) { it('deletes a Pad', function (done) {
this.timeout(100);
api.get(`${endPoint('deletePad')}&padID=${testPadId}`) api.get(`${endPoint('deletePad')}&padID=${testPadId}`)
.expect((res) => { .expect((res) => {
if (res.body.code !== 0) throw new Error('Pad Deletion failed'); if (res.body.code !== 0) throw new Error('Pad Deletion failed');
@ -427,6 +458,7 @@ describe(__filename, function () {
describe('createPad', function () { describe('createPad', function () {
it('creates a new Pad with text', function (done) { it('creates a new Pad with text', function (done) {
this.timeout(200);
api.get(`${endPoint('createPad')}&padID=${testPadId}`) api.get(`${endPoint('createPad')}&padID=${testPadId}`)
.expect((res) => { .expect((res) => {
if (res.body.code !== 0) throw new Error('Pad Creation failed'); if (res.body.code !== 0) throw new Error('Pad Creation failed');
@ -437,6 +469,7 @@ describe(__filename, function () {
}); });
describe('setText', function () { describe('setText', function () {
this.timeout(200);
it('Sets text on a pad Id', function (done) { it('Sets text on a pad Id', function (done) {
api.post(`${endPoint('setText')}&padID=${testPadId}`) api.post(`${endPoint('setText')}&padID=${testPadId}`)
.field({text}) .field({text})
@ -450,6 +483,7 @@ describe(__filename, function () {
describe('getText', function () { describe('getText', function () {
it('Gets text on a pad Id', function (done) { it('Gets text on a pad Id', function (done) {
this.timeout(100);
api.get(`${endPoint('getText')}&padID=${testPadId}`) api.get(`${endPoint('getText')}&padID=${testPadId}`)
.expect((res) => { .expect((res) => {
if (res.body.code !== 0) throw new Error('Pad Get Text failed'); if (res.body.code !== 0) throw new Error('Pad Get Text failed');
@ -462,6 +496,7 @@ describe(__filename, function () {
describe('setText', function () { describe('setText', function () {
it('Sets text on a pad Id including an explicit newline', function (done) { it('Sets text on a pad Id including an explicit newline', function (done) {
this.timeout(200);
api.post(`${endPoint('setText')}&padID=${testPadId}`) api.post(`${endPoint('setText')}&padID=${testPadId}`)
.field({text: `${text}\n`}) .field({text: `${text}\n`})
.expect((res) => { .expect((res) => {
@ -474,6 +509,7 @@ describe(__filename, function () {
describe('getText', function () { describe('getText', function () {
it("Gets text on a pad Id and doesn't have an excess newline", function (done) { it("Gets text on a pad Id and doesn't have an excess newline", function (done) {
this.timeout(100);
api.get(`${endPoint('getText')}&padID=${testPadId}`) api.get(`${endPoint('getText')}&padID=${testPadId}`)
.expect((res) => { .expect((res) => {
if (res.body.code !== 0) throw new Error('Pad Get Text failed'); if (res.body.code !== 0) throw new Error('Pad Get Text failed');
@ -486,6 +522,7 @@ describe(__filename, function () {
describe('getLastEdited', function () { describe('getLastEdited', function () {
it('Gets when pad was last edited', function (done) { it('Gets when pad was last edited', function (done) {
this.timeout(100);
api.get(`${endPoint('getLastEdited')}&padID=${testPadId}`) api.get(`${endPoint('getLastEdited')}&padID=${testPadId}`)
.expect((res) => { .expect((res) => {
if (res.body.lastEdited === 0) throw new Error('Get Last Edited Failed'); if (res.body.lastEdited === 0) throw new Error('Get Last Edited Failed');
@ -497,6 +534,7 @@ describe(__filename, function () {
describe('movePad', function () { describe('movePad', function () {
it('Move a Pad to a different Pad ID', function (done) { it('Move a Pad to a different Pad ID', function (done) {
this.timeout(200);
api.get(`${endPoint('movePad')}&sourceID=${testPadId}&destinationID=${newPadId}&force=true`) api.get(`${endPoint('movePad')}&sourceID=${testPadId}&destinationID=${newPadId}&force=true`)
.expect((res) => { .expect((res) => {
if (res.body.code !== 0) throw new Error('Moving Pad Failed'); if (res.body.code !== 0) throw new Error('Moving Pad Failed');
@ -508,6 +546,7 @@ describe(__filename, function () {
describe('getText', function () { describe('getText', function () {
it('Gets text on a pad Id', function (done) { it('Gets text on a pad Id', function (done) {
this.timeout(100);
api.get(`${endPoint('getText')}&padID=${newPadId}`) api.get(`${endPoint('getText')}&padID=${newPadId}`)
.expect((res) => { .expect((res) => {
if (res.body.data.text !== `${text}\n`) throw new Error('Pad Get Text failed'); if (res.body.data.text !== `${text}\n`) throw new Error('Pad Get Text failed');
@ -519,6 +558,7 @@ describe(__filename, function () {
describe('movePad', function () { describe('movePad', function () {
it('Move a Pad to a different Pad ID', function (done) { it('Move a Pad to a different Pad ID', function (done) {
this.timeout(200);
api.get(`${endPoint('movePad')}&sourceID=${newPadId}&destinationID=${testPadId}&force=false`) api.get(`${endPoint('movePad')}&sourceID=${newPadId}&destinationID=${testPadId}&force=false`)
.expect((res) => { .expect((res) => {
if (res.body.code !== 0) throw new Error('Moving Pad Failed'); if (res.body.code !== 0) throw new Error('Moving Pad Failed');
@ -530,6 +570,7 @@ describe(__filename, function () {
describe('getText', function () { describe('getText', function () {
it('Gets text on a pad Id', function (done) { it('Gets text on a pad Id', function (done) {
this.timeout(100);
api.get(`${endPoint('getText')}&padID=${testPadId}`) api.get(`${endPoint('getText')}&padID=${testPadId}`)
.expect((res) => { .expect((res) => {
if (res.body.data.text !== `${text}\n`) throw new Error('Pad Get Text failed'); if (res.body.data.text !== `${text}\n`) throw new Error('Pad Get Text failed');
@ -541,6 +582,7 @@ describe(__filename, function () {
describe('getLastEdited', function () { describe('getLastEdited', function () {
it('Gets when pad was last edited', function (done) { it('Gets when pad was last edited', function (done) {
this.timeout(100);
api.get(`${endPoint('getLastEdited')}&padID=${testPadId}`) api.get(`${endPoint('getLastEdited')}&padID=${testPadId}`)
.expect((res) => { .expect((res) => {
if (res.body.lastEdited === 0) throw new Error('Get Last Edited Failed'); if (res.body.lastEdited === 0) throw new Error('Get Last Edited Failed');
@ -552,6 +594,7 @@ describe(__filename, function () {
describe('appendText', function () { describe('appendText', function () {
it('Append text to a pad Id', function (done) { it('Append text to a pad Id', function (done) {
this.timeout(100);
api.get(`${endPoint('appendText', '1.2.13')}&padID=${testPadId}&text=hello`) api.get(`${endPoint('appendText', '1.2.13')}&padID=${testPadId}&text=hello`)
.expect((res) => { .expect((res) => {
if (res.body.code !== 0) throw new Error('Pad Append Text failed'); if (res.body.code !== 0) throw new Error('Pad Append Text failed');
@ -563,6 +606,7 @@ describe(__filename, function () {
describe('getText', function () { describe('getText', function () {
it('Gets text on a pad Id', function (done) { it('Gets text on a pad Id', function (done) {
this.timeout(100);
api.get(`${endPoint('getText')}&padID=${testPadId}`) api.get(`${endPoint('getText')}&padID=${testPadId}`)
.expect((res) => { .expect((res) => {
if (res.body.code !== 0) throw new Error('Pad Get Text failed'); if (res.body.code !== 0) throw new Error('Pad Get Text failed');
@ -576,6 +620,7 @@ describe(__filename, function () {
describe('setHTML', function () { describe('setHTML', function () {
it('Sets the HTML of a Pad attempting to pass ugly HTML', function (done) { it('Sets the HTML of a Pad attempting to pass ugly HTML', function (done) {
this.timeout(100);
const html = '<div><b>Hello HTML</title></head></div>'; const html = '<div><b>Hello HTML</title></head></div>';
api.post(endPoint('setHTML')) api.post(endPoint('setHTML'))
.send({ .send({
@ -592,6 +637,7 @@ describe(__filename, function () {
describe('setHTML', function () { describe('setHTML', function () {
it('Sets the HTML of a Pad with complex nested lists of different types', function (done) { it('Sets the HTML of a Pad with complex nested lists of different types', function (done) {
this.timeout(100);
api.post(endPoint('setHTML')) api.post(endPoint('setHTML'))
.send({ .send({
padID: testPadId, padID: testPadId,
@ -607,6 +653,7 @@ describe(__filename, function () {
describe('getHTML', function () { describe('getHTML', function () {
it('Gets back the HTML of a Pad with complex nested lists of different types', function (done) { it('Gets back the HTML of a Pad with complex nested lists of different types', function (done) {
this.timeout(100);
api.get(`${endPoint('getHTML')}&padID=${testPadId}`) api.get(`${endPoint('getHTML')}&padID=${testPadId}`)
.expect((res) => { .expect((res) => {
const receivedHtml = res.body.data.html.replace('<br></body>', '</body>').toLowerCase(); const receivedHtml = res.body.data.html.replace('<br></body>', '</body>').toLowerCase();
@ -630,6 +677,7 @@ describe(__filename, function () {
describe('setHTML', function () { describe('setHTML', function () {
it('Sets the HTML of a Pad with white space between list items', function (done) { it('Sets the HTML of a Pad with white space between list items', function (done) {
this.timeout(100);
api.get(`${endPoint('setHTML')}&padID=${testPadId}&html=${ulSpaceHtml}`) api.get(`${endPoint('setHTML')}&padID=${testPadId}&html=${ulSpaceHtml}`)
.expect((res) => { .expect((res) => {
if (res.body.code !== 0) throw new Error('List HTML cant be imported'); if (res.body.code !== 0) throw new Error('List HTML cant be imported');
@ -641,6 +689,7 @@ describe(__filename, function () {
describe('getHTML', function () { describe('getHTML', function () {
it('Gets back the HTML of a Pad with complex nested lists of different types', function (done) { it('Gets back the HTML of a Pad with complex nested lists of different types', function (done) {
this.timeout(100);
api.get(`${endPoint('getHTML')}&padID=${testPadId}`) api.get(`${endPoint('getHTML')}&padID=${testPadId}`)
.expect((res) => { .expect((res) => {
const receivedHtml = res.body.data.html.replace('<br></body>', '</body>').toLowerCase(); const receivedHtml = res.body.data.html.replace('<br></body>', '</body>').toLowerCase();
@ -663,6 +712,7 @@ describe(__filename, function () {
describe('createPad', function () { describe('createPad', function () {
it('errors if pad can be created', function (done) { it('errors if pad can be created', function (done) {
this.timeout(200);
const badUrlChars = ['/', '%23', '%3F', '%26']; const badUrlChars = ['/', '%23', '%3F', '%26'];
async.map( async.map(
badUrlChars, badUrlChars,
@ -680,6 +730,7 @@ describe(__filename, function () {
describe('copyPad', function () { describe('copyPad', function () {
it('copies the content of a existent pad', function (done) { it('copies the content of a existent pad', function (done) {
this.timeout(200);
api.get(`${endPoint('copyPad')}&sourceID=${testPadId}&destinationID=${copiedPadId}&force=true`) api.get(`${endPoint('copyPad')}&sourceID=${testPadId}&destinationID=${copiedPadId}&force=true`)
.expect((res) => { .expect((res) => {
if (res.body.code !== 0) throw new Error('Copy Pad Failed'); if (res.body.code !== 0) throw new Error('Copy Pad Failed');
@ -702,6 +753,7 @@ describe(__filename, function () {
}); });
it('returns a successful response', function (done) { it('returns a successful response', function (done) {
this.timeout(200);
api.get(`${endPoint('copyPadWithoutHistory')}&sourceID=${sourcePadId}&destinationID=${newPad}&force=false`) api.get(`${endPoint('copyPadWithoutHistory')}&sourceID=${sourcePadId}&destinationID=${newPad}&force=false`)
.expect((res) => { .expect((res) => {
if (res.body.code !== 0) throw new Error('Copy Pad Without History Failed'); if (res.body.code !== 0) throw new Error('Copy Pad Without History Failed');
@ -712,6 +764,7 @@ describe(__filename, function () {
// this test validates if the source pad's text and attributes are kept // this test validates if the source pad's text and attributes are kept
it('creates a new pad with the same content as the source pad', function (done) { it('creates a new pad with the same content as the source pad', function (done) {
this.timeout(200);
api.get(`${endPoint('copyPadWithoutHistory')}&sourceID=${sourcePadId}&destinationID=${newPad}&force=false`) api.get(`${endPoint('copyPadWithoutHistory')}&sourceID=${sourcePadId}&destinationID=${newPad}&force=false`)
.expect((res) => { .expect((res) => {
if (res.body.code !== 0) throw new Error('Copy Pad Without History Failed'); if (res.body.code !== 0) throw new Error('Copy Pad Without History Failed');
@ -741,6 +794,7 @@ describe(__filename, function () {
const padId = makeid(); const padId = makeid();
const padWithNonExistentGroup = `notExistentGroup$${padId}`; const padWithNonExistentGroup = `notExistentGroup$${padId}`;
it('throws an error', function (done) { it('throws an error', function (done) {
this.timeout(200);
api.get(`${endPoint('copyPadWithoutHistory')}&sourceID=${sourcePadId}&destinationID=${padWithNonExistentGroup}&force=true`) api.get(`${endPoint('copyPadWithoutHistory')}&sourceID=${sourcePadId}&destinationID=${padWithNonExistentGroup}&force=true`)
.expect((res) => { .expect((res) => {
// code 1, it means an error has happened // code 1, it means an error has happened
@ -759,6 +813,7 @@ describe(__filename, function () {
context('and force is false', function () { context('and force is false', function () {
it('throws an error', function (done) { it('throws an error', function (done) {
this.timeout(200);
api.get(`${endPoint('copyPadWithoutHistory')}&sourceID=${sourcePadId}&destinationID=${padIdExistent}&force=false`) api.get(`${endPoint('copyPadWithoutHistory')}&sourceID=${sourcePadId}&destinationID=${padIdExistent}&force=false`)
.expect((res) => { .expect((res) => {
// code 1, it means an error has happened // code 1, it means an error has happened
@ -770,6 +825,7 @@ describe(__filename, function () {
context('and force is true', function () { context('and force is true', function () {
it('returns a successful response', function (done) { it('returns a successful response', function (done) {
this.timeout(200);
api.get(`${endPoint('copyPadWithoutHistory')}&sourceID=${sourcePadId}&destinationID=${padIdExistent}&force=true`) api.get(`${endPoint('copyPadWithoutHistory')}&sourceID=${sourcePadId}&destinationID=${padIdExistent}&force=true`)
.expect((res) => { .expect((res) => {
// code 1, it means an error has happened // code 1, it means an error has happened
@ -787,7 +843,7 @@ describe(__filename, function () {
*/ */
var createNewPadWithHtml = function (padId, html, cb) { const createNewPadWithHtml = function (padId, html, cb) {
api.get(`${endPoint('createPad')}&padID=${padId}`) api.get(`${endPoint('createPad')}&padID=${padId}`)
.end(() => { .end(() => {
api.post(endPoint('setHTML')) api.post(endPoint('setHTML'))
@ -799,7 +855,7 @@ var createNewPadWithHtml = function (padId, html, cb) {
}); });
}; };
var endPoint = function (point, version) { const endPoint = function (point, version) {
version = version || apiVersion; version = version || apiVersion;
return `/api/${version}/${point}?apikey=${apiKey}`; return `/api/${version}/${point}?apikey=${apiKey}`;
}; };
@ -829,13 +885,13 @@ Array.prototype.equals = function (array) {
// if the other array is a falsy value, return // if the other array is a falsy value, return
if (!array) return false; if (!array) return false;
// compare lengths - can save a lot of time // compare lengths - can save a lot of time
if (this.length != array.length) return false; if (this.length !== array.length) return false;
for (let i = 0, l = this.length; i < l; i++) { for (let i = 0, l = this.length; i < l; i++) {
// Check if we have nested arrays // Check if we have nested arrays
if (this[i] instanceof Array && array[i] instanceof Array) { if (this[i] instanceof Array && array[i] instanceof Array) {
// recurse into the nested arrays // recurse into the nested arrays
if (!this[i].equals(array[i])) return false; if (!this[i].equals(array[i])) return false;
} else if (this[i] != array[i]) { } else if (this[i] !== array[i]) {
// Warning - two different object instances will never be equal: {x:20} != {x:20} // Warning - two different object instances will never be equal: {x:20} != {x:20}
return false; return false;
} }