asyncify tests

GitOrigin-RevId: 62f875bb121a599fab830a3244959596796cd6e1
This commit is contained in:
Tim Alby
2022-01-14 09:03:08 +00:00
committed by Copybot
parent 67ce7c3c75
commit 795ed56034
8 changed files with 385 additions and 502 deletions
@@ -4,122 +4,96 @@ const { expect } = require('chai')
const ChatClient = require('./helpers/ChatClient')
const ChatApp = require('./helpers/ChatApp')
describe('Resolving a thread', function () {
before(function (done) {
describe('Resolving a thread', async function () {
before(async function () {
this.project_id = ObjectId().toString()
this.user_id = ObjectId().toString()
ChatApp.ensureRunning(done)
await ChatApp.ensureRunning()
})
describe('with a resolved thread', function () {
before(function (done) {
describe('with a resolved thread', async function () {
before(async function () {
this.thread_id = ObjectId().toString()
this.content = 'resolved message'
ChatClient.sendMessage(
const { response } = await ChatClient.sendMessage(
this.project_id,
this.thread_id,
this.user_id,
this.content,
(error, response, body) => {
expect(error).to.be.null
expect(response.statusCode).to.equal(201)
ChatClient.resolveThread(
this.project_id,
this.thread_id,
this.user_id,
(error, response, body) => {
expect(error).to.be.null
expect(response.statusCode).to.equal(204)
done()
}
)
}
this.content
)
expect(response.statusCode).to.equal(201)
const { response: response2 } = await ChatClient.resolveThread(
this.project_id,
this.thread_id,
this.user_id
)
expect(response2.statusCode).to.equal(204)
})
it('should then list the thread as resolved', function (done) {
ChatClient.getThreads(this.project_id, (error, response, threads) => {
expect(error).to.be.null
expect(response.statusCode).to.equal(200)
expect(threads[this.thread_id].resolved).to.equal(true)
expect(threads[this.thread_id].resolved_by_user_id).to.equal(
this.user_id
)
const resolvedAt = new Date(threads[this.thread_id].resolved_at)
expect(new Date() - resolvedAt).to.be.below(1000)
done()
})
it('should then list the thread as resolved', async function () {
const { response, body: threads } = await ChatClient.getThreads(
this.project_id
)
expect(response.statusCode).to.equal(200)
expect(threads[this.thread_id].resolved).to.equal(true)
expect(threads[this.thread_id].resolved_by_user_id).to.equal(this.user_id)
const resolvedAt = new Date(threads[this.thread_id].resolved_at)
expect(new Date() - resolvedAt).to.be.below(1000)
})
})
describe('when a thread is not resolved', function () {
before(function (done) {
describe('when a thread is not resolved', async function () {
before(async function () {
this.thread_id = ObjectId().toString()
this.content = 'open message'
ChatClient.sendMessage(
const { response } = await ChatClient.sendMessage(
this.project_id,
this.thread_id,
this.user_id,
this.content,
(error, response, body) => {
expect(error).to.be.null
expect(response.statusCode).to.equal(201)
done()
}
this.content
)
expect(response.statusCode).to.equal(201)
})
it('should not list the thread as resolved', function (done) {
ChatClient.getThreads(this.project_id, (error, response, threads) => {
expect(error).to.be.null
expect(response.statusCode).to.equal(200)
expect(threads[this.thread_id].resolved).to.be.undefined
done()
})
it('should not list the thread as resolved', async function () {
const { response, body: threads } = await ChatClient.getThreads(
this.project_id
)
expect(response.statusCode).to.equal(200)
expect(threads[this.thread_id].resolved).to.be.undefined
})
})
describe('when a thread is resolved then reopened', function () {
before(function (done) {
describe('when a thread is resolved then reopened', async function () {
before(async function () {
this.thread_id = ObjectId().toString()
this.content = 'resolved message'
ChatClient.sendMessage(
const { response } = await ChatClient.sendMessage(
this.project_id,
this.thread_id,
this.user_id,
this.content,
(error, response, body) => {
expect(error).to.be.null
expect(response.statusCode).to.equal(201)
ChatClient.resolveThread(
this.project_id,
this.thread_id,
this.user_id,
(error, response, body) => {
expect(error).to.be.null
expect(response.statusCode).to.equal(204)
ChatClient.reopenThread(
this.project_id,
this.thread_id,
(error, response, body) => {
expect(error).to.be.null
expect(response.statusCode).to.equal(204)
done()
}
)
}
)
}
this.content
)
expect(response.statusCode).to.equal(201)
const { response: response2 } = await ChatClient.resolveThread(
this.project_id,
this.thread_id,
this.user_id
)
expect(response2.statusCode).to.equal(204)
const { response: response3 } = await ChatClient.reopenThread(
this.project_id,
this.thread_id
)
expect(response3.statusCode).to.equal(204)
})
it('should not list the thread as resolved', function (done) {
ChatClient.getThreads(this.project_id, (error, response, threads) => {
expect(error).to.be.null
expect(response.statusCode).to.equal(200)
expect(threads[this.thread_id].resolved).to.be.undefined
done()
})
it('should not list the thread as resolved', async function () {
const { response, body: threads } = await ChatClient.getThreads(
this.project_id
)
expect(response.statusCode).to.equal(200)
expect(threads[this.thread_id].resolved).to.be.undefined
})
})
})