tests: chat API: Move test setup to before()

This commit is contained in:
Richard Hansen 2022-04-07 19:42:06 -04:00
parent 92d70e5ead
commit 7b7b085a1c

View file

@ -13,40 +13,31 @@ const timestamp = Date.now();
const endPoint = (point) => `/api/${apiVersion}/${point}?apikey=${apiKey}`; const endPoint = (point) => `/api/${apiVersion}/${point}?apikey=${apiKey}`;
describe(__filename, function () { describe(__filename, function () {
before(async function () { agent = await common.init(); }); before(async function () {
agent = await common.init();
describe('API Versioning', function () { await agent.get('/api/')
it('errors if can not connect', async function () { .expect(200)
await agent.get('/api/') .expect((res) => {
.expect(200) assert(res.body.currentVersion);
.expect((res) => { apiVersion = res.body.currentVersion;
assert(res.body.currentVersion); });
apiVersion = res.body.currentVersion; await agent.get(`${endPoint('createPad')}&padID=${padID}`)
}); .expect(200)
}); .expect('Content-Type', /json/)
.expect((res) => {
assert.equal(res.body.code, 0);
});
await agent.get(endPoint('createAuthor'))
.expect(200)
.expect('Content-Type', /json/)
.expect((res) => {
assert.equal(res.body.code, 0);
assert(res.body.data.authorID);
authorID = res.body.data.authorID; // we will be this author for the rest of the tests
});
}); });
describe('message sequence', function () { describe('message sequence', function () {
it('createPad', async function () {
await agent.get(`${endPoint('createPad')}&padID=${padID}`)
.expect(200)
.expect('Content-Type', /json/)
.expect((res) => {
assert.equal(res.body.code, 0);
});
});
it('createAuthor', async function () {
await agent.get(endPoint('createAuthor'))
.expect(200)
.expect('Content-Type', /json/)
.expect((res) => {
assert.equal(res.body.code, 0);
assert(res.body.data.authorID);
authorID = res.body.data.authorID; // we will be this author for the rest of the tests
});
});
it('appendChatMessage', async function () { it('appendChatMessage', async 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}`)