overleaf/services/chat/test/acceptance/js/SendingAMessageTests.js
Christopher Hoskin b3b02941c7 Merge pull request #15261 from overleaf/csh-issue-11625-mongo-ug-5-chat
Upgrade mongodb module for chat from 4.11.0 to 6.1.0

GitOrigin-RevId: d4ce72b093fd09638a575a14f8945c8cb9ec7f3d
2023-10-18 08:04:27 +00:00

145 lines
4.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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