2020-08-19 08:00:01 -04:00
|
|
|
const { ObjectId } = require('../../../app/js/mongodb')
|
2018-12-20 14:14:11 -05:00
|
|
|
const { expect } = require('chai')
|
2017-01-24 09:44:32 -05:00
|
|
|
|
2018-12-20 14:14:11 -05:00
|
|
|
const ChatClient = require('./helpers/ChatClient')
|
|
|
|
const ChatApp = require('./helpers/ChatApp')
|
2017-01-24 09:44:32 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
describe('Deleting a message', function () {
|
|
|
|
before(function (done) {
|
2018-12-20 14:14:11 -05:00
|
|
|
this.project_id = ObjectId().toString()
|
|
|
|
this.user_id = ObjectId().toString()
|
|
|
|
this.thread_id = ObjectId().toString()
|
2022-01-07 05:41:23 -05:00
|
|
|
ChatApp.ensureRunning(done)
|
2018-12-20 14:14:11 -05:00
|
|
|
})
|
2017-01-24 09:44:32 -05:00
|
|
|
|
2022-01-07 05:41:23 -05:00
|
|
|
describe('in a thread', function () {
|
2020-08-10 12:01:11 -04:00
|
|
|
before(function (done) {
|
2022-01-07 05:41:23 -05:00
|
|
|
ChatClient.sendMessage(
|
2018-12-20 14:14:11 -05:00
|
|
|
this.project_id,
|
|
|
|
this.thread_id,
|
|
|
|
this.user_id,
|
|
|
|
'first message',
|
|
|
|
(error, response, message) => {
|
|
|
|
this.message = message
|
|
|
|
expect(error).to.be.null
|
|
|
|
expect(response.statusCode).to.equal(201)
|
2022-01-07 05:41:23 -05:00
|
|
|
ChatClient.sendMessage(
|
2018-12-20 14:14:11 -05:00
|
|
|
this.project_id,
|
|
|
|
this.thread_id,
|
|
|
|
this.user_id,
|
|
|
|
'deleted message',
|
|
|
|
(error, response, message1) => {
|
|
|
|
this.message = message1
|
|
|
|
expect(error).to.be.null
|
|
|
|
expect(response.statusCode).to.equal(201)
|
2022-01-07 05:41:23 -05:00
|
|
|
ChatClient.deleteMessage(
|
2018-12-20 14:14:11 -05:00
|
|
|
this.project_id,
|
|
|
|
this.thread_id,
|
|
|
|
this.message.id,
|
|
|
|
(error, response, body) => {
|
|
|
|
expect(error).to.be.null
|
|
|
|
expect(response.statusCode).to.equal(204)
|
2022-01-07 05:41:23 -05:00
|
|
|
done()
|
2018-12-20 14:14:11 -05:00
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2022-01-07 05:41:23 -05:00
|
|
|
it('should then remove the message from the threads', 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].messages.length).to.equal(1)
|
|
|
|
done()
|
|
|
|
})
|
2018-12-20 14:14:11 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|