|
@@ -4,182 +4,143 @@ const { expect } = require('chai')
|
|
|
const ChatClient = require('./helpers/ChatClient')
|
|
const ChatClient = require('./helpers/ChatClient')
|
|
|
const ChatApp = require('./helpers/ChatApp')
|
|
const ChatApp = require('./helpers/ChatApp')
|
|
|
|
|
|
|
|
-describe('Sending a message', function () {
|
|
|
|
|
- before(function (done) {
|
|
|
|
|
- ChatApp.ensureRunning(done)
|
|
|
|
|
|
|
+describe('Sending a message', async function () {
|
|
|
|
|
+ before(async function () {
|
|
|
|
|
+ await ChatApp.ensureRunning()
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- describe('globally', function () {
|
|
|
|
|
- before(function (done) {
|
|
|
|
|
|
|
+ describe('globally', async function () {
|
|
|
|
|
+ before(async function () {
|
|
|
this.project_id = ObjectId().toString()
|
|
this.project_id = ObjectId().toString()
|
|
|
this.user_id = ObjectId().toString()
|
|
this.user_id = ObjectId().toString()
|
|
|
this.content = 'global message'
|
|
this.content = 'global message'
|
|
|
- ChatClient.sendGlobalMessage(
|
|
|
|
|
|
|
+ const { response, body } = await ChatClient.sendGlobalMessage(
|
|
|
this.project_id,
|
|
this.project_id,
|
|
|
this.user_id,
|
|
this.user_id,
|
|
|
- this.content,
|
|
|
|
|
- (error, response, body) => {
|
|
|
|
|
- expect(error).to.be.null
|
|
|
|
|
- expect(response.statusCode).to.equal(201)
|
|
|
|
|
- expect(body.content).to.equal(this.content)
|
|
|
|
|
- expect(body.user_id).to.equal(this.user_id)
|
|
|
|
|
- expect(body.room_id).to.equal(this.project_id)
|
|
|
|
|
- done()
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ this.content
|
|
|
)
|
|
)
|
|
|
|
|
+ expect(response.statusCode).to.equal(201)
|
|
|
|
|
+ expect(body.content).to.equal(this.content)
|
|
|
|
|
+ expect(body.user_id).to.equal(this.user_id)
|
|
|
|
|
+ expect(body.room_id).to.equal(this.project_id)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- it('should then list the message in the project messages', function (done) {
|
|
|
|
|
- ChatClient.getGlobalMessages(
|
|
|
|
|
- this.project_id,
|
|
|
|
|
- (error, response, messages) => {
|
|
|
|
|
- expect(error).to.be.null
|
|
|
|
|
- expect(response.statusCode).to.equal(200)
|
|
|
|
|
- expect(messages.length).to.equal(1)
|
|
|
|
|
- expect(messages[0].content).to.equal(this.content)
|
|
|
|
|
- done()
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ it('should then list the message in the project messages', async function () {
|
|
|
|
|
+ const { response, body: messages } = await ChatClient.getGlobalMessages(
|
|
|
|
|
+ this.project_id
|
|
|
)
|
|
)
|
|
|
|
|
+ expect(response.statusCode).to.equal(200)
|
|
|
|
|
+ expect(messages.length).to.equal(1)
|
|
|
|
|
+ expect(messages[0].content).to.equal(this.content)
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- describe('to a thread', function () {
|
|
|
|
|
- before(function (done) {
|
|
|
|
|
|
|
+ describe('to a thread', async function () {
|
|
|
|
|
+ before(async function () {
|
|
|
this.project_id = ObjectId().toString()
|
|
this.project_id = ObjectId().toString()
|
|
|
this.user_id = ObjectId().toString()
|
|
this.user_id = ObjectId().toString()
|
|
|
this.thread_id = ObjectId().toString()
|
|
this.thread_id = ObjectId().toString()
|
|
|
this.content = 'thread message'
|
|
this.content = 'thread message'
|
|
|
- ChatClient.sendMessage(
|
|
|
|
|
|
|
+ const { response, body } = await ChatClient.sendMessage(
|
|
|
this.project_id,
|
|
this.project_id,
|
|
|
this.thread_id,
|
|
this.thread_id,
|
|
|
this.user_id,
|
|
this.user_id,
|
|
|
- this.content,
|
|
|
|
|
- (error, response, body) => {
|
|
|
|
|
- expect(error).to.be.null
|
|
|
|
|
- expect(response.statusCode).to.equal(201)
|
|
|
|
|
- expect(body.content).to.equal(this.content)
|
|
|
|
|
- expect(body.user_id).to.equal(this.user_id)
|
|
|
|
|
- expect(body.room_id).to.equal(this.project_id)
|
|
|
|
|
- done()
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ this.content
|
|
|
)
|
|
)
|
|
|
|
|
+ expect(response.statusCode).to.equal(201)
|
|
|
|
|
+ expect(body.content).to.equal(this.content)
|
|
|
|
|
+ expect(body.user_id).to.equal(this.user_id)
|
|
|
|
|
+ expect(body.room_id).to.equal(this.project_id)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- it('should then list the message in 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)
|
|
|
|
|
- expect(threads[this.thread_id].messages[0].content).to.equal(
|
|
|
|
|
- this.content
|
|
|
|
|
- )
|
|
|
|
|
- done()
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ it('should then list the message in the threads', async function () {
|
|
|
|
|
+ const { response, body: threads } = await ChatClient.getThreads(
|
|
|
|
|
+ this.project_id
|
|
|
|
|
+ )
|
|
|
|
|
+ expect(response.statusCode).to.equal(200)
|
|
|
|
|
+ expect(threads[this.thread_id].messages.length).to.equal(1)
|
|
|
|
|
+ expect(threads[this.thread_id].messages[0].content).to.equal(this.content)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- it('should not appear in the global messages', function (done) {
|
|
|
|
|
- ChatClient.getGlobalMessages(
|
|
|
|
|
- this.project_id,
|
|
|
|
|
- (error, response, messages) => {
|
|
|
|
|
- expect(error).to.be.null
|
|
|
|
|
- expect(response.statusCode).to.equal(200)
|
|
|
|
|
- expect(messages.length).to.equal(0)
|
|
|
|
|
- done()
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ it('should not appear in the global messages', async function () {
|
|
|
|
|
+ const { response, body: messages } = await ChatClient.getGlobalMessages(
|
|
|
|
|
+ this.project_id
|
|
|
)
|
|
)
|
|
|
|
|
+ expect(response.statusCode).to.equal(200)
|
|
|
|
|
+ expect(messages.length).to.equal(0)
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- describe('failure cases', function () {
|
|
|
|
|
- before(function () {
|
|
|
|
|
|
|
+ describe('failure cases', async function () {
|
|
|
|
|
+ before(async function () {
|
|
|
this.project_id = ObjectId().toString()
|
|
this.project_id = ObjectId().toString()
|
|
|
this.user_id = ObjectId().toString()
|
|
this.user_id = ObjectId().toString()
|
|
|
this.thread_id = ObjectId().toString()
|
|
this.thread_id = ObjectId().toString()
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- describe('with a malformed user_id', function () {
|
|
|
|
|
- it('should return a graceful error', function (done) {
|
|
|
|
|
- ChatClient.sendMessage(
|
|
|
|
|
|
|
+ describe('with a malformed user_id', async function () {
|
|
|
|
|
+ it('should return a graceful error', async function () {
|
|
|
|
|
+ const { response, body } = await ChatClient.sendMessage(
|
|
|
this.project_id,
|
|
this.project_id,
|
|
|
this.thread_id,
|
|
this.thread_id,
|
|
|
'malformed-user',
|
|
'malformed-user',
|
|
|
- 'content',
|
|
|
|
|
- (error, response, body) => {
|
|
|
|
|
- if (error) return done(error)
|
|
|
|
|
- expect(response.statusCode).to.equal(400)
|
|
|
|
|
- expect(body).to.equal('Invalid userId')
|
|
|
|
|
- done()
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ 'content'
|
|
|
)
|
|
)
|
|
|
|
|
+ expect(response.statusCode).to.equal(400)
|
|
|
|
|
+ expect(body).to.equal('Invalid userId')
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- describe('with a malformed project_id', function () {
|
|
|
|
|
- it('should return a graceful error', function (done) {
|
|
|
|
|
- ChatClient.sendMessage(
|
|
|
|
|
|
|
+ describe('with a malformed project_id', async function () {
|
|
|
|
|
+ it('should return a graceful error', async function () {
|
|
|
|
|
+ const { response, body } = await ChatClient.sendMessage(
|
|
|
'malformed-project',
|
|
'malformed-project',
|
|
|
this.thread_id,
|
|
this.thread_id,
|
|
|
this.user_id,
|
|
this.user_id,
|
|
|
- 'content',
|
|
|
|
|
- (error, response, body) => {
|
|
|
|
|
- if (error) return done(error)
|
|
|
|
|
- expect(response.statusCode).to.equal(400)
|
|
|
|
|
- expect(body).to.equal('Invalid projectId')
|
|
|
|
|
- done()
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ 'content'
|
|
|
)
|
|
)
|
|
|
|
|
+ expect(response.statusCode).to.equal(400)
|
|
|
|
|
+ expect(body).to.equal('Invalid projectId')
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- describe('with a malformed thread_id', function () {
|
|
|
|
|
- it('should return a graceful error', function (done) {
|
|
|
|
|
- ChatClient.sendMessage(
|
|
|
|
|
|
|
+ describe('with a malformed thread_id', async function () {
|
|
|
|
|
+ it('should return a graceful error', async function () {
|
|
|
|
|
+ const { response, body } = await ChatClient.sendMessage(
|
|
|
this.project_id,
|
|
this.project_id,
|
|
|
'malformed-thread-id',
|
|
'malformed-thread-id',
|
|
|
this.user_id,
|
|
this.user_id,
|
|
|
- 'content',
|
|
|
|
|
- (error, response, body) => {
|
|
|
|
|
- if (error) return done(error)
|
|
|
|
|
- expect(response.statusCode).to.equal(400)
|
|
|
|
|
- expect(body).to.equal('Invalid threadId')
|
|
|
|
|
- done()
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ 'content'
|
|
|
)
|
|
)
|
|
|
|
|
+ expect(response.statusCode).to.equal(400)
|
|
|
|
|
+ expect(body).to.equal('Invalid threadId')
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- describe('with no content', function () {
|
|
|
|
|
- it('should return a graceful error', function (done) {
|
|
|
|
|
- ChatClient.sendMessage(
|
|
|
|
|
|
|
+ describe('with no content', async function () {
|
|
|
|
|
+ it('should return a graceful error', async function () {
|
|
|
|
|
+ const { response, body } = await ChatClient.sendMessage(
|
|
|
this.project_id,
|
|
this.project_id,
|
|
|
this.thread_id,
|
|
this.thread_id,
|
|
|
this.user_id,
|
|
this.user_id,
|
|
|
- null,
|
|
|
|
|
- (error, response, body) => {
|
|
|
|
|
- if (error) return done(error)
|
|
|
|
|
- expect(response.statusCode).to.equal(400)
|
|
|
|
|
- expect(body).to.equal('No content provided')
|
|
|
|
|
- done()
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ null
|
|
|
)
|
|
)
|
|
|
|
|
+ expect(response.statusCode).to.equal(400)
|
|
|
|
|
+ expect(body).to.equal('No content provided')
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- describe('with very long content', function () {
|
|
|
|
|
- it('should return a graceful error', function (done) {
|
|
|
|
|
|
|
+ describe('with very long content', async function () {
|
|
|
|
|
+ it('should return a graceful error', async function () {
|
|
|
const content = '-'.repeat(10 * 1024 + 1)
|
|
const content = '-'.repeat(10 * 1024 + 1)
|
|
|
- ChatClient.sendMessage(
|
|
|
|
|
|
|
+ const { response, body } = await ChatClient.sendMessage(
|
|
|
this.project_id,
|
|
this.project_id,
|
|
|
this.thread_id,
|
|
this.thread_id,
|
|
|
this.user_id,
|
|
this.user_id,
|
|
|
- content,
|
|
|
|
|
- (error, response, body) => {
|
|
|
|
|
- if (error) return done(error)
|
|
|
|
|
- expect(response.statusCode).to.equal(400)
|
|
|
|
|
- expect(body).to.equal('Content too long (> 10240 bytes)')
|
|
|
|
|
- done()
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ content
|
|
|
)
|
|
)
|
|
|
|
|
+ expect(response.statusCode).to.equal(400)
|
|
|
|
|
+ expect(body).to.equal('Content too long (> 10240 bytes)')
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|