tests: chat API: Use `assert` library
parent
5603e6b94e
commit
3146d6758b
|
@ -1,5 +1,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const assert = require('assert').strict;
|
||||||
const common = require('../../common');
|
const common = require('../../common');
|
||||||
|
|
||||||
let agent;
|
let agent;
|
||||||
|
@ -19,8 +20,7 @@ describe(__filename, function () {
|
||||||
await 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');
|
assert(res.body.currentVersion);
|
||||||
return;
|
|
||||||
})
|
})
|
||||||
.expect(200);
|
.expect(200);
|
||||||
});
|
});
|
||||||
|
@ -42,7 +42,7 @@ describe(__filename, function () {
|
||||||
it('creates a new Pad', async function () {
|
it('creates a new Pad', async function () {
|
||||||
await 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');
|
assert.equal(res.body.code, 0);
|
||||||
})
|
})
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(200);
|
.expect(200);
|
||||||
|
@ -53,9 +53,8 @@ describe(__filename, function () {
|
||||||
it('Creates an author with a name set', async function () {
|
it('Creates an author with a name set', async function () {
|
||||||
await agent.get(endPoint('createAuthor'))
|
await agent.get(endPoint('createAuthor'))
|
||||||
.expect((res) => {
|
.expect((res) => {
|
||||||
if (res.body.code !== 0 || !res.body.data.authorID) {
|
assert.equal(res.body.code, 0);
|
||||||
throw new Error('Unable to create author');
|
assert(res.body.data.authorID);
|
||||||
}
|
|
||||||
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/)
|
||||||
|
@ -68,7 +67,7 @@ describe(__filename, function () {
|
||||||
await 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');
|
assert.equal(res.body.code, 0);
|
||||||
})
|
})
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(200);
|
.expect(200);
|
||||||
|
@ -80,9 +79,8 @@ describe(__filename, function () {
|
||||||
it('Gets the head of chat', async function () {
|
it('Gets the head of chat', async function () {
|
||||||
await 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');
|
assert.equal(res.body.data.chatHead, 0);
|
||||||
|
assert.equal(res.body.code, 0);
|
||||||
if (res.body.code !== 0) throw new Error('Unable to get chat head');
|
|
||||||
})
|
})
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(200);
|
.expect(200);
|
||||||
|
@ -93,10 +91,8 @@ describe(__filename, function () {
|
||||||
it('Gets Chat History of a Pad', async function () {
|
it('Gets Chat History of a Pad', async function () {
|
||||||
await agent.get(`${endPoint('getChatHistory')}&padID=${padID}`)
|
await agent.get(`${endPoint('getChatHistory')}&padID=${padID}`)
|
||||||
.expect((res) => {
|
.expect((res) => {
|
||||||
if (res.body.data.messages.length !== 1) {
|
assert.equal(res.body.data.messages.length, 1);
|
||||||
throw new Error('Chat History Length is wrong');
|
assert.equal(res.body.code, 0);
|
||||||
}
|
|
||||||
if (res.body.code !== 0) throw new Error('Unable to get chat history');
|
|
||||||
})
|
})
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(200);
|
.expect(200);
|
||||||
|
|
Loading…
Reference in New Issue