2021-02-16 18:25:15 -05:00
|
|
|
'use strict';
|
|
|
|
|
2022-04-07 19:57:34 -04:00
|
|
|
const assert = require('assert').strict;
|
2020-10-08 01:37:17 -04:00
|
|
|
const common = require('../../common');
|
2015-04-01 13:52:56 +01:00
|
|
|
|
2021-02-16 18:35:50 -05:00
|
|
|
let agent;
|
2020-10-08 01:37:17 -04:00
|
|
|
const apiKey = common.apiKey;
|
2020-11-23 13:21:51 -05:00
|
|
|
let apiVersion = 1;
|
|
|
|
let authorID = '';
|
|
|
|
const padID = makeid();
|
|
|
|
const timestamp = Date.now();
|
2015-04-01 13:52:56 +01:00
|
|
|
|
2021-02-16 18:25:15 -05:00
|
|
|
const endPoint = (point) => `/api/${apiVersion}/${point}?apikey=${apiKey}`;
|
|
|
|
|
2020-11-23 13:21:51 -05:00
|
|
|
describe(__filename, function () {
|
2021-02-16 18:35:50 -05:00
|
|
|
before(async function () { agent = await common.init(); });
|
|
|
|
|
2020-11-23 13:21:51 -05:00
|
|
|
describe('API Versioning', function () {
|
2022-04-07 19:31:28 -04:00
|
|
|
it('errors if can not connect', async function () {
|
|
|
|
await agent.get('/api/')
|
2022-04-07 19:35:00 -04:00
|
|
|
.expect(200)
|
2020-11-23 13:21:51 -05:00
|
|
|
.expect((res) => {
|
2022-04-07 19:57:34 -04:00
|
|
|
assert(res.body.currentVersion);
|
2022-04-07 19:35:00 -04:00
|
|
|
apiVersion = res.body.currentVersion;
|
|
|
|
});
|
2020-10-09 18:19:46 -04:00
|
|
|
});
|
2020-11-23 13:21:51 -05:00
|
|
|
});
|
2015-04-01 13:52:56 +01:00
|
|
|
|
2020-10-09 18:19:46 -04:00
|
|
|
// BEGIN GROUP AND AUTHOR TESTS
|
2020-11-23 13:21:51 -05:00
|
|
|
// ///////////////////////////////////
|
|
|
|
// ///////////////////////////////////
|
2015-04-01 13:52:56 +01:00
|
|
|
|
2020-10-09 18:19:46 -04:00
|
|
|
/* Tests performed
|
|
|
|
-> createPad(padID)
|
|
|
|
-> createAuthor([name]) -- should return an authorID
|
|
|
|
-> appendChatMessage(padID, text, authorID, time)
|
|
|
|
-> getChatHead(padID)
|
|
|
|
-> getChatHistory(padID)
|
|
|
|
*/
|
2015-04-01 13:52:56 +01:00
|
|
|
|
2020-11-23 13:21:51 -05:00
|
|
|
describe('createPad', function () {
|
2022-04-07 19:31:28 -04:00
|
|
|
it('creates a new Pad', async function () {
|
|
|
|
await agent.get(`${endPoint('createPad')}&padID=${padID}`)
|
2022-04-07 19:35:00 -04:00
|
|
|
.expect(200)
|
|
|
|
.expect('Content-Type', /json/)
|
2020-11-23 13:21:51 -05:00
|
|
|
.expect((res) => {
|
2022-04-07 19:57:34 -04:00
|
|
|
assert.equal(res.body.code, 0);
|
2022-04-07 19:35:00 -04:00
|
|
|
});
|
2020-10-09 18:19:46 -04:00
|
|
|
});
|
2020-11-23 13:21:51 -05:00
|
|
|
});
|
2015-04-01 13:52:56 +01:00
|
|
|
|
2020-11-23 13:21:51 -05:00
|
|
|
describe('createAuthor', function () {
|
2022-04-07 19:31:28 -04:00
|
|
|
it('Creates an author with a name set', async function () {
|
|
|
|
await agent.get(endPoint('createAuthor'))
|
2022-04-07 19:35:00 -04:00
|
|
|
.expect(200)
|
|
|
|
.expect('Content-Type', /json/)
|
2020-11-23 13:21:51 -05:00
|
|
|
.expect((res) => {
|
2022-04-07 19:57:34 -04:00
|
|
|
assert.equal(res.body.code, 0);
|
|
|
|
assert(res.body.data.authorID);
|
2020-10-09 18:19:46 -04:00
|
|
|
authorID = res.body.data.authorID; // we will be this author for the rest of the tests
|
2022-04-07 19:35:00 -04:00
|
|
|
});
|
2020-10-09 18:19:46 -04:00
|
|
|
});
|
2020-11-23 13:21:51 -05:00
|
|
|
});
|
2015-04-01 13:52:56 +01:00
|
|
|
|
2020-11-23 13:21:51 -05:00
|
|
|
describe('appendChatMessage', function () {
|
2022-04-07 19:31:28 -04:00
|
|
|
it('Adds a chat message to the pad', async function () {
|
|
|
|
await agent.get(`${endPoint('appendChatMessage')}&padID=${padID}&text=blalblalbha` +
|
2021-02-16 18:35:50 -05:00
|
|
|
`&authorID=${authorID}&time=${timestamp}`)
|
2022-04-07 19:35:00 -04:00
|
|
|
.expect(200)
|
|
|
|
.expect('Content-Type', /json/)
|
2020-11-23 13:21:51 -05:00
|
|
|
.expect((res) => {
|
2022-04-07 19:57:34 -04:00
|
|
|
assert.equal(res.body.code, 0);
|
2022-04-07 19:35:00 -04:00
|
|
|
});
|
2020-10-09 18:19:46 -04:00
|
|
|
});
|
2020-11-23 13:21:51 -05:00
|
|
|
});
|
2015-04-01 13:52:56 +01:00
|
|
|
|
|
|
|
|
2020-11-23 13:21:51 -05:00
|
|
|
describe('getChatHead', function () {
|
2022-04-07 19:31:28 -04:00
|
|
|
it('Gets the head of chat', async function () {
|
|
|
|
await agent.get(`${endPoint('getChatHead')}&padID=${padID}`)
|
2022-04-07 19:35:00 -04:00
|
|
|
.expect(200)
|
|
|
|
.expect('Content-Type', /json/)
|
2020-11-23 13:21:51 -05:00
|
|
|
.expect((res) => {
|
2022-04-07 19:57:34 -04:00
|
|
|
assert.equal(res.body.code, 0);
|
2022-04-07 19:35:00 -04:00
|
|
|
assert.equal(res.body.data.chatHead, 0);
|
|
|
|
});
|
2020-10-09 18:19:46 -04:00
|
|
|
});
|
2020-11-23 13:21:51 -05:00
|
|
|
});
|
2015-04-01 13:52:56 +01:00
|
|
|
|
2020-11-23 13:21:51 -05:00
|
|
|
describe('getChatHistory', function () {
|
2022-04-07 19:31:28 -04:00
|
|
|
it('Gets Chat History of a Pad', async function () {
|
|
|
|
await agent.get(`${endPoint('getChatHistory')}&padID=${padID}`)
|
2022-04-07 19:35:00 -04:00
|
|
|
.expect(200)
|
|
|
|
.expect('Content-Type', /json/)
|
2020-11-23 13:21:51 -05:00
|
|
|
.expect((res) => {
|
2022-04-07 19:57:34 -04:00
|
|
|
assert.equal(res.body.code, 0);
|
2022-04-07 19:35:00 -04:00
|
|
|
assert.equal(res.body.data.messages.length, 1);
|
|
|
|
});
|
2020-10-09 18:19:46 -04:00
|
|
|
});
|
2020-11-23 13:21:51 -05:00
|
|
|
});
|
2020-10-09 18:19:46 -04:00
|
|
|
});
|
2015-04-01 13:52:56 +01:00
|
|
|
|
2020-11-21 13:37:57 -05:00
|
|
|
function makeid() {
|
2020-11-23 13:21:51 -05:00
|
|
|
let text = '';
|
|
|
|
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
2015-04-01 13:52:56 +01:00
|
|
|
|
2020-11-23 13:21:51 -05:00
|
|
|
for (let i = 0; i < 5; i++) {
|
2015-04-01 13:52:56 +01:00
|
|
|
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
|
|
|
}
|
|
|
|
return text;
|
|
|
|
}
|