Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix append revision test #5851

Merged
merged 2 commits into from
Jul 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 35 additions & 50 deletions src/tests/backend/specs/api/chat.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const common = require('../../common');
const assert = require('assert').strict;

let agent;
const apiKey = common.apiKey;
Expand All @@ -15,14 +16,14 @@ describe(__filename, function () {
before(async function () { agent = await common.init(); });

describe('API Versioning', function () {
it('errors if can not connect', function (done) {
agent.get('/api/')
it('errors if can not connect', async function () {
await agent.get('/api/')
.expect((res) => {
apiVersion = res.body.currentVersion;
if (!res.body.currentVersion) throw new Error('No version set in API');
return;
})
.expect(200, done);
.expect(200);
});
});

Expand All @@ -38,86 +39,70 @@ describe(__filename, function () {
-> getChatHistory(padID)
*/

describe('createPad', function () {
it('creates a new Pad', function (done) {
agent.get(`${endPoint('createPad')}&padID=${padID}`)
describe('Chat functionality', function () {
it('creates a new Pad', async function () {
await agent.get(`${endPoint('createPad')}&padID=${padID}`)
.expect((res) => {
if (res.body.code !== 0) throw new Error('Unable to create new Pad');
})
.expect('Content-Type', /json/)
.expect(200, done);
.expect(200);
});
});


describe('createPad with empty text', () => {
it('creates a new Pad with empty text', function (done) {
agent.get(`${endPoint('createPad')}&padID=${padID}&text=`)
it('Creates an author with a name set', async function () {
await agent.get(endPoint('createAuthor'))
.expect((res) => {
if (res.body.code !== 0) throw new Error('Unable to create new Pad');
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);
agent.get(`${endPoint('deletePad')}&padID=${padID}`)
.expect((res) => {
if (res.body.code !== 0) throw new Error('Unable to delete empty Pad');
})
.expect('Content-Type', /json/)
.expect(200, done);
});
});

describe('createAuthor', function () {
it('Creates an author with a name set', function (done) {
agent.get(endPoint('createAuthor'))
it('Gets the head of chat before the first chat msg', async function () {
await agent.get(`${endPoint('getChatHead')}&padID=${padID}`)
.expect((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
if (res.body.data.chatHead !== -1) 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);
.expect(200);
});
});

describe('appendChatMessage', function () {
it('Adds a chat message to the pad', function (done) {
agent.get(`${endPoint('appendChatMessage')}&padID=${padID}&text=blalblalbha` +
it('Adds a chat message to the pad', async function () {
await agent.get(`${endPoint('appendChatMessage')}&padID=${padID}&text=blalblalbha` +
`&authorID=${authorID}&time=${timestamp}`)
.expect((res) => {
if (res.body.code !== 0) throw new Error('Unable to create chat message');
})
.expect('Content-Type', /json/)
.expect(200, done);
.expect(200);
});
});


describe('getChatHead', function () {
it('Gets the head of chat', function (done) {
agent.get(`${endPoint('getChatHead')}&padID=${padID}`)
it('Gets the head of chat', async function () {
await agent.get(`${endPoint('getChatHead')}&padID=${padID}`)
.expect((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);
.expect(200);
});
});

describe('getChatHistory', function () {
it('Gets Chat History of a Pad', function (done) {
agent.get(`${endPoint('getChatHistory')}&padID=${padID}`)
.expect((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');
})
it('Gets Chat History of a Pad', async function () {
await agent.get(`${endPoint('getChatHistory')}&padID=${padID}`)
.expect('Content-Type', /json/)
.expect(200, done);
.expect(200)
.expect((res) => {
assert.equal(res.body.code, 0, 'Unable to get chat history');
assert.equal(res.body.data.messages.length, 1, 'Chat History Length is wrong');
assert.equal(res.body.data.messages[0].text, 'blalblalbha', 'Chat text does not match');
assert.equal(res.body.data.messages[0].userId, authorID, 'Message author does not match');
assert.equal(res.body.data.messages[0].time, timestamp.toString(), 'Message time does not match');
});
});
});
});
Expand Down
12 changes: 6 additions & 6 deletions src/tests/backend/specs/api/instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ describe(__filename, function () {
before(async function () { agent = await common.init(); });

describe('Connectivity for instance-level API tests', function () {
it('can connect', function (done) {
agent.get('/api/')
it('can connect', async function () {
await agent.get('/api/')
.expect('Content-Type', /json/)
.expect(200, done);
.expect(200);
});
});

describe('getStats', function () {
it('Gets the stats of a running instance', function (done) {
agent.get(endPoint('getStats'))
it('Gets the stats of a running instance', async function () {
await agent.get(endPoint('getStats'))
.expect((res) => {
if (res.body.code !== 0) throw new Error('getStats() failed');

Expand All @@ -48,7 +48,7 @@ describe(__filename, function () {
}
})
.expect('Content-Type', /json/)
.expect(200, done);
.expect(200);
});
});
});
26 changes: 26 additions & 0 deletions src/tests/backend/specs/api/pad.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ let apiVersion = 1;
const testPadId = makeid();
const newPadId = makeid();
const copiedPadId = makeid();
const anotherPadId = makeid();
let lastEdited = '';
const text = generateLongText();

Expand Down Expand Up @@ -502,6 +503,31 @@ describe(__filename, function () {
.expect('Content-Type', /json/);
assert.equal(res.body.data.revisions, revCount);
});

it('creates a new Pad with empty text', async function () {
await agent.get(`${endPoint('createPad')}&padID=${anotherPadId}&text=`)
.expect('Content-Type', /json/)
.expect(200)
.expect((res) => {
assert.equal(res.body.code, 0, 'Unable to create new Pad');
});
await agent.get(`${endPoint('getText')}&padID=${anotherPadId}`)
.expect('Content-Type', /json/)
.expect(200)
.expect((res) => {
assert.equal(res.body.code, 0, 'Unable to get pad text');
assert.equal(res.body.data.text, '\n', 'Pad text is not empty');
});
});

it('deletes with empty text', async function () {
await agent.get(`${endPoint('deletePad')}&padID=${anotherPadId}`)
.expect('Content-Type', /json/)
.expect(200)
.expect((res) => {
assert.equal(res.body.code, 0, 'Unable to delete empty Pad');
});
});
});

describe('copyPadWithoutHistory', function () {
Expand Down
Loading