2022-12-13 12:37:49 +00:00
|
|
|
|
import { ObjectId } from '../../../app/js/mongodb.js'
|
|
|
|
|
import { expect } from 'chai'
|
2016-12-14 17:38:14 +00:00
|
|
|
|
|
2022-12-13 12:37:49 +00:00
|
|
|
|
import * as ChatClient from './helpers/ChatClient.js'
|
|
|
|
|
import * as ChatApp from './helpers/ChatApp.js'
|
2016-12-14 17:38:14 +00:00
|
|
|
|
|
2022-01-10 09:29:32 +00:00
|
|
|
|
describe('Sending a message', async function () {
|
|
|
|
|
before(async function () {
|
|
|
|
|
await ChatApp.ensureRunning()
|
2020-02-11 09:08:37 +00:00
|
|
|
|
})
|
2016-12-16 16:52:50 +00:00
|
|
|
|
|
2022-01-10 09:29:32 +00:00
|
|
|
|
describe('globally', async function () {
|
2022-01-10 09:50:25 +00:00
|
|
|
|
const projectId = ObjectId().toString()
|
|
|
|
|
const userId = ObjectId().toString()
|
|
|
|
|
const content = 'global message'
|
2022-01-10 09:29:32 +00:00
|
|
|
|
before(async function () {
|
|
|
|
|
const { response, body } = await ChatClient.sendGlobalMessage(
|
2022-01-10 09:50:25 +00:00
|
|
|
|
projectId,
|
|
|
|
|
userId,
|
|
|
|
|
content
|
2018-12-20 19:14:11 +00:00
|
|
|
|
)
|
2022-01-10 09:29:32 +00:00
|
|
|
|
expect(response.statusCode).to.equal(201)
|
2022-01-10 09:50:25 +00:00
|
|
|
|
expect(body.content).to.equal(content)
|
|
|
|
|
expect(body.user_id).to.equal(userId)
|
|
|
|
|
expect(body.room_id).to.equal(projectId)
|
2018-12-20 19:14:11 +00:00
|
|
|
|
})
|
2016-12-16 16:52:50 +00:00
|
|
|
|
|
2022-01-10 09:29:32 +00:00
|
|
|
|
it('should then list the message in the project messages', async function () {
|
|
|
|
|
const { response, body: messages } = await ChatClient.getGlobalMessages(
|
2022-01-10 09:50:25 +00:00
|
|
|
|
projectId
|
2018-12-20 19:14:11 +00:00
|
|
|
|
)
|
2022-01-10 09:29:32 +00:00
|
|
|
|
expect(response.statusCode).to.equal(200)
|
|
|
|
|
expect(messages.length).to.equal(1)
|
2022-01-10 09:50:25 +00:00
|
|
|
|
expect(messages[0].content).to.equal(content)
|
2018-12-20 19:14:11 +00:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2022-01-10 09:29:32 +00:00
|
|
|
|
describe('to a thread', async function () {
|
2022-01-10 09:50:25 +00:00
|
|
|
|
const projectId = ObjectId().toString()
|
|
|
|
|
const userId = ObjectId().toString()
|
|
|
|
|
const threadId = ObjectId().toString()
|
|
|
|
|
const content = 'thread message'
|
2022-01-10 09:29:32 +00:00
|
|
|
|
before(async function () {
|
|
|
|
|
const { response, body } = await ChatClient.sendMessage(
|
2022-01-10 09:50:25 +00:00
|
|
|
|
projectId,
|
|
|
|
|
threadId,
|
|
|
|
|
userId,
|
|
|
|
|
content
|
2018-12-20 19:14:11 +00:00
|
|
|
|
)
|
2022-01-10 09:29:32 +00:00
|
|
|
|
expect(response.statusCode).to.equal(201)
|
2022-01-10 09:50:25 +00:00
|
|
|
|
expect(body.content).to.equal(content)
|
|
|
|
|
expect(body.user_id).to.equal(userId)
|
|
|
|
|
expect(body.room_id).to.equal(projectId)
|
2018-12-20 19:14:11 +00:00
|
|
|
|
})
|
|
|
|
|
|
2022-01-10 09:29:32 +00:00
|
|
|
|
it('should then list the message in the threads', async function () {
|
2022-01-10 09:50:25 +00:00
|
|
|
|
const { response, body: threads } = await ChatClient.getThreads(projectId)
|
2022-01-10 09:29:32 +00:00
|
|
|
|
expect(response.statusCode).to.equal(200)
|
2022-01-10 09:50:25 +00:00
|
|
|
|
expect(threads[threadId].messages.length).to.equal(1)
|
|
|
|
|
expect(threads[threadId].messages[0].content).to.equal(content)
|
2018-12-20 19:14:11 +00:00
|
|
|
|
})
|
|
|
|
|
|
2022-01-10 09:29:32 +00:00
|
|
|
|
it('should not appear in the global messages', async function () {
|
|
|
|
|
const { response, body: messages } = await ChatClient.getGlobalMessages(
|
2022-01-10 09:50:25 +00:00
|
|
|
|
projectId
|
2018-12-20 19:14:11 +00:00
|
|
|
|
)
|
2022-01-10 09:29:32 +00:00
|
|
|
|
expect(response.statusCode).to.equal(200)
|
|
|
|
|
expect(messages.length).to.equal(0)
|
2018-12-20 19:14:11 +00:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2022-01-10 09:29:32 +00:00
|
|
|
|
describe('failure cases', async function () {
|
2022-01-10 09:50:25 +00:00
|
|
|
|
const projectId = ObjectId().toString()
|
|
|
|
|
const userId = ObjectId().toString()
|
|
|
|
|
const threadId = ObjectId().toString()
|
2018-12-20 19:14:11 +00:00
|
|
|
|
|
2022-01-10 09:50:25 +00:00
|
|
|
|
describe('with a malformed userId', async function () {
|
2022-01-10 09:29:32 +00:00
|
|
|
|
it('should return a graceful error', async function () {
|
|
|
|
|
const { response, body } = await ChatClient.sendMessage(
|
2022-01-10 09:50:25 +00:00
|
|
|
|
projectId,
|
|
|
|
|
threadId,
|
2018-12-20 19:14:11 +00:00
|
|
|
|
'malformed-user',
|
2022-01-10 09:29:32 +00:00
|
|
|
|
'content'
|
2018-12-20 19:14:11 +00:00
|
|
|
|
)
|
2022-01-10 09:29:32 +00:00
|
|
|
|
expect(response.statusCode).to.equal(400)
|
|
|
|
|
expect(body).to.equal('Invalid userId')
|
2020-02-11 09:08:37 +00:00
|
|
|
|
})
|
|
|
|
|
})
|
2018-12-20 19:14:11 +00:00
|
|
|
|
|
2022-01-10 09:50:25 +00:00
|
|
|
|
describe('with a malformed projectId', async function () {
|
2022-01-10 09:29:32 +00:00
|
|
|
|
it('should return a graceful error', async function () {
|
|
|
|
|
const { response, body } = await ChatClient.sendMessage(
|
2018-12-20 19:14:11 +00:00
|
|
|
|
'malformed-project',
|
2022-01-10 09:50:25 +00:00
|
|
|
|
threadId,
|
|
|
|
|
userId,
|
2022-01-10 09:29:32 +00:00
|
|
|
|
'content'
|
2018-12-20 19:14:11 +00:00
|
|
|
|
)
|
2022-01-10 09:29:32 +00:00
|
|
|
|
expect(response.statusCode).to.equal(400)
|
|
|
|
|
expect(body).to.equal('Invalid projectId')
|
2020-02-11 09:08:37 +00:00
|
|
|
|
})
|
|
|
|
|
})
|
2018-12-20 19:14:11 +00:00
|
|
|
|
|
2022-01-10 09:50:25 +00:00
|
|
|
|
describe('with a malformed threadId', async function () {
|
2022-01-10 09:29:32 +00:00
|
|
|
|
it('should return a graceful error', async function () {
|
|
|
|
|
const { response, body } = await ChatClient.sendMessage(
|
2022-01-10 09:50:25 +00:00
|
|
|
|
projectId,
|
2018-12-20 19:14:11 +00:00
|
|
|
|
'malformed-thread-id',
|
2022-01-10 09:50:25 +00:00
|
|
|
|
userId,
|
2022-01-10 09:29:32 +00:00
|
|
|
|
'content'
|
2018-12-20 19:14:11 +00:00
|
|
|
|
)
|
2022-01-10 09:29:32 +00:00
|
|
|
|
expect(response.statusCode).to.equal(400)
|
|
|
|
|
expect(body).to.equal('Invalid threadId')
|
2020-02-11 09:08:37 +00:00
|
|
|
|
})
|
|
|
|
|
})
|
2018-12-20 19:14:11 +00:00
|
|
|
|
|
2022-01-10 09:29:32 +00:00
|
|
|
|
describe('with no content', async function () {
|
|
|
|
|
it('should return a graceful error', async function () {
|
|
|
|
|
const { response, body } = await ChatClient.sendMessage(
|
2022-01-10 09:50:25 +00:00
|
|
|
|
projectId,
|
|
|
|
|
threadId,
|
|
|
|
|
userId,
|
2022-01-10 09:29:32 +00:00
|
|
|
|
null
|
2018-12-20 19:14:11 +00:00
|
|
|
|
)
|
2022-01-10 09:29:32 +00:00
|
|
|
|
expect(response.statusCode).to.equal(400)
|
2023-01-04 15:07:58 +00:00
|
|
|
|
// Exegesis is responding with validation errors. I can´t find a way to choose the validation error yet.
|
|
|
|
|
// expect(body).to.equal('No content provided')
|
|
|
|
|
expect(body.message).to.equal('Validation errors')
|
2020-02-11 09:08:37 +00:00
|
|
|
|
})
|
|
|
|
|
})
|
2018-12-20 19:14:11 +00:00
|
|
|
|
|
2022-01-10 09:29:32 +00:00
|
|
|
|
describe('with very long content', async function () {
|
|
|
|
|
it('should return a graceful error', async function () {
|
2020-08-19 11:59:33 +00:00
|
|
|
|
const content = '-'.repeat(10 * 1024 + 1)
|
2022-01-10 09:29:32 +00:00
|
|
|
|
const { response, body } = await ChatClient.sendMessage(
|
2022-01-10 09:50:25 +00:00
|
|
|
|
projectId,
|
|
|
|
|
threadId,
|
|
|
|
|
userId,
|
2022-01-10 09:29:32 +00:00
|
|
|
|
content
|
2018-12-20 19:14:11 +00:00
|
|
|
|
)
|
2022-01-10 09:29:32 +00:00
|
|
|
|
expect(response.statusCode).to.equal(400)
|
|
|
|
|
expect(body).to.equal('Content too long (> 10240 bytes)')
|
2020-02-11 09:08:37 +00:00
|
|
|
|
})
|
|
|
|
|
})
|
2018-12-20 19:14:11 +00:00
|
|
|
|
})
|
|
|
|
|
})
|