tests: chat API: Promisify

This commit is contained in:
Richard Hansen 2022-04-07 19:31:28 -04:00
parent 33c46cb002
commit 5603e6b94e

View file

@ -15,14 +15,14 @@ describe(__filename, function () {
before(async function () { agent = await common.init(); }); before(async function () { agent = await common.init(); });
describe('API Versioning', function () { describe('API Versioning', function () {
it('errors if can not connect', function (done) { it('errors if can not connect', async function () {
agent.get('/api/') await agent.get('/api/')
.expect((res) => { .expect((res) => {
apiVersion = res.body.currentVersion; apiVersion = res.body.currentVersion;
if (!res.body.currentVersion) throw new Error('No version set in API'); if (!res.body.currentVersion) throw new Error('No version set in API');
return; return;
}) })
.expect(200, done); .expect(200);
}); });
}); });
@ -39,19 +39,19 @@ describe(__filename, function () {
*/ */
describe('createPad', function () { describe('createPad', function () {
it('creates a new Pad', function (done) { it('creates a new Pad', async function () {
agent.get(`${endPoint('createPad')}&padID=${padID}`) await agent.get(`${endPoint('createPad')}&padID=${padID}`)
.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');
}) })
.expect('Content-Type', /json/) .expect('Content-Type', /json/)
.expect(200, done); .expect(200);
}); });
}); });
describe('createAuthor', function () { describe('createAuthor', function () {
it('Creates an author with a name set', function (done) { it('Creates an author with a name set', async function () {
agent.get(endPoint('createAuthor')) await agent.get(endPoint('createAuthor'))
.expect((res) => { .expect((res) => {
if (res.body.code !== 0 || !res.body.data.authorID) { if (res.body.code !== 0 || !res.body.data.authorID) {
throw new Error('Unable to create author'); throw new Error('Unable to create author');
@ -59,39 +59,39 @@ describe(__filename, function () {
authorID = res.body.data.authorID; // we will be this author for the rest of the tests authorID = res.body.data.authorID; // we will be this author for the rest of the tests
}) })
.expect('Content-Type', /json/) .expect('Content-Type', /json/)
.expect(200, done); .expect(200);
}); });
}); });
describe('appendChatMessage', function () { describe('appendChatMessage', function () {
it('Adds a chat message to the pad', function (done) { it('Adds a chat message to the pad', async function () {
agent.get(`${endPoint('appendChatMessage')}&padID=${padID}&text=blalblalbha` + await agent.get(`${endPoint('appendChatMessage')}&padID=${padID}&text=blalblalbha` +
`&authorID=${authorID}&time=${timestamp}`) `&authorID=${authorID}&time=${timestamp}`)
.expect((res) => { .expect((res) => {
if (res.body.code !== 0) throw new Error('Unable to create chat message'); if (res.body.code !== 0) throw new Error('Unable to create chat message');
}) })
.expect('Content-Type', /json/) .expect('Content-Type', /json/)
.expect(200, done); .expect(200);
}); });
}); });
describe('getChatHead', function () { describe('getChatHead', function () {
it('Gets the head of chat', function (done) { it('Gets the head of chat', async function () {
agent.get(`${endPoint('getChatHead')}&padID=${padID}`) await agent.get(`${endPoint('getChatHead')}&padID=${padID}`)
.expect((res) => { .expect((res) => {
if (res.body.data.chatHead !== 0) throw new Error('Chat Head Length is wrong'); 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'); if (res.body.code !== 0) throw new Error('Unable to get chat head');
}) })
.expect('Content-Type', /json/) .expect('Content-Type', /json/)
.expect(200, done); .expect(200);
}); });
}); });
describe('getChatHistory', function () { describe('getChatHistory', function () {
it('Gets Chat History of a Pad', function (done) { it('Gets Chat History of a Pad', async function () {
agent.get(`${endPoint('getChatHistory')}&padID=${padID}`) await agent.get(`${endPoint('getChatHistory')}&padID=${padID}`)
.expect((res) => { .expect((res) => {
if (res.body.data.messages.length !== 1) { if (res.body.data.messages.length !== 1) {
throw new Error('Chat History Length is wrong'); throw new Error('Chat History Length is wrong');
@ -99,7 +99,7 @@ describe(__filename, function () {
if (res.body.code !== 0) throw new Error('Unable to get chat history'); if (res.body.code !== 0) throw new Error('Unable to get chat history');
}) })
.expect('Content-Type', /json/) .expect('Content-Type', /json/)
.expect(200, done); .expect(200);
}); });
}); });
}); });