mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-15 14:43:46 +01:00
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
This commit is contained in:
committed by
Copybot
parent
aa7510bb6a
commit
007fce2938
@@ -54,7 +54,7 @@ export async function updateMessage(
|
||||
room_id: roomId,
|
||||
})
|
||||
if (userId) {
|
||||
query.user_id = ObjectId(userId)
|
||||
query.user_id = new ObjectId(userId)
|
||||
}
|
||||
const res = await db.messages.updateOne(query, {
|
||||
$set: {
|
||||
@@ -75,13 +75,13 @@ export async function deleteMessage(roomId, messageId) {
|
||||
|
||||
function _ensureIdsAreObjectIds(query) {
|
||||
if (query.user_id && !(query.user_id instanceof ObjectId)) {
|
||||
query.user_id = ObjectId(query.user_id)
|
||||
query.user_id = new ObjectId(query.user_id)
|
||||
}
|
||||
if (query.room_id && !(query.room_id instanceof ObjectId)) {
|
||||
query.room_id = ObjectId(query.room_id)
|
||||
query.room_id = new ObjectId(query.room_id)
|
||||
}
|
||||
if (query._id && !(query._id instanceof ObjectId)) {
|
||||
query._id = ObjectId(query._id)
|
||||
query._id = new ObjectId(query._id)
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
@@ -4,9 +4,9 @@ export const GLOBAL_THREAD = 'GLOBAL'
|
||||
|
||||
export async function findOrCreateThread(projectId, threadId) {
|
||||
let query, update
|
||||
projectId = ObjectId(projectId.toString())
|
||||
projectId = new ObjectId(projectId.toString())
|
||||
if (threadId !== GLOBAL_THREAD) {
|
||||
threadId = ObjectId(threadId.toString())
|
||||
threadId = new ObjectId(threadId.toString())
|
||||
}
|
||||
|
||||
if (threadId === GLOBAL_THREAD) {
|
||||
@@ -33,14 +33,14 @@ export async function findOrCreateThread(projectId, threadId) {
|
||||
{ $set: update },
|
||||
{ upsert: true, returnDocument: 'after' }
|
||||
)
|
||||
return result.value
|
||||
return result
|
||||
}
|
||||
|
||||
export async function findAllThreadRooms(projectId) {
|
||||
return db.rooms
|
||||
.find(
|
||||
{
|
||||
project_id: ObjectId(projectId.toString()),
|
||||
project_id: new ObjectId(projectId.toString()),
|
||||
thread_id: { $exists: true },
|
||||
},
|
||||
{
|
||||
@@ -55,7 +55,7 @@ export async function findAllThreadRoomsAndGlobalThread(projectId) {
|
||||
return db.rooms
|
||||
.find(
|
||||
{
|
||||
project_id: ObjectId(projectId.toString()),
|
||||
project_id: new ObjectId(projectId.toString()),
|
||||
},
|
||||
{
|
||||
thread_id: 1,
|
||||
@@ -68,8 +68,8 @@ export async function findAllThreadRoomsAndGlobalThread(projectId) {
|
||||
export async function resolveThread(projectId, threadId, userId) {
|
||||
await db.rooms.updateOne(
|
||||
{
|
||||
project_id: ObjectId(projectId.toString()),
|
||||
thread_id: ObjectId(threadId.toString()),
|
||||
project_id: new ObjectId(projectId.toString()),
|
||||
thread_id: new ObjectId(threadId.toString()),
|
||||
},
|
||||
{
|
||||
$set: {
|
||||
@@ -85,8 +85,8 @@ export async function resolveThread(projectId, threadId, userId) {
|
||||
export async function reopenThread(projectId, threadId) {
|
||||
await db.rooms.updateOne(
|
||||
{
|
||||
project_id: ObjectId(projectId.toString()),
|
||||
thread_id: ObjectId(threadId.toString()),
|
||||
project_id: new ObjectId(projectId.toString()),
|
||||
thread_id: new ObjectId(threadId.toString()),
|
||||
},
|
||||
{
|
||||
$unset: {
|
||||
@@ -106,6 +106,6 @@ export async function deleteThread(projectId, threadId) {
|
||||
|
||||
export async function deleteAllThreadsInProject(projectId) {
|
||||
await db.rooms.deleteMany({
|
||||
project_id: ObjectId(projectId.toString()),
|
||||
project_id: new ObjectId(projectId.toString()),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
"body-parser": "^1.19.0",
|
||||
"exegesis-express": "^4.0.0",
|
||||
"express": "^4.18.2",
|
||||
"mongodb": "^4.11.0"
|
||||
"mongodb": "^6.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"acorn": "^7.1.1",
|
||||
|
||||
@@ -5,9 +5,9 @@ import * as ChatClient from './helpers/ChatClient.js'
|
||||
import * as ChatApp from './helpers/ChatApp.js'
|
||||
|
||||
describe('Deleting a message', async function () {
|
||||
const projectId = ObjectId().toString()
|
||||
const userId = ObjectId().toString()
|
||||
const threadId = ObjectId().toString()
|
||||
const projectId = new ObjectId().toString()
|
||||
const userId = new ObjectId().toString()
|
||||
const threadId = new ObjectId().toString()
|
||||
|
||||
before(async function () {
|
||||
await ChatApp.ensureRunning()
|
||||
|
||||
@@ -5,14 +5,14 @@ import * as ChatClient from './helpers/ChatClient.js'
|
||||
import * as ChatApp from './helpers/ChatApp.js'
|
||||
|
||||
describe('Deleting a thread', async function () {
|
||||
const projectId = ObjectId().toString()
|
||||
const userId = ObjectId().toString()
|
||||
const projectId = new ObjectId().toString()
|
||||
const userId = new ObjectId().toString()
|
||||
before(async function () {
|
||||
await ChatApp.ensureRunning()
|
||||
})
|
||||
|
||||
describe('with a thread that is deleted', async function () {
|
||||
const threadId = ObjectId().toString()
|
||||
const threadId = new ObjectId().toString()
|
||||
const content = 'deleted thread message'
|
||||
before(async function () {
|
||||
const { response } = await ChatClient.sendMessage(
|
||||
|
||||
@@ -8,19 +8,19 @@ const db = ChatApp.db
|
||||
|
||||
async function getMessage(messageId) {
|
||||
return await db.messages.findOne({
|
||||
_id: ObjectId(messageId),
|
||||
_id: new ObjectId(messageId),
|
||||
})
|
||||
}
|
||||
|
||||
describe('Destroying a project', async function () {
|
||||
const projectId = ObjectId().toString()
|
||||
const userId = ObjectId().toString()
|
||||
const projectId = new ObjectId().toString()
|
||||
const userId = new ObjectId().toString()
|
||||
before(async function () {
|
||||
await ChatApp.ensureRunning()
|
||||
})
|
||||
|
||||
describe('with a project that has threads and messages', async function () {
|
||||
const threadId = ObjectId().toString()
|
||||
const threadId = new ObjectId().toString()
|
||||
before(async function () {
|
||||
const { response } = await ChatClient.sendMessage(
|
||||
projectId,
|
||||
@@ -39,7 +39,7 @@ describe('Destroying a project', async function () {
|
||||
this.globalThreadMessageId = response2.body.id
|
||||
|
||||
const threadRooms = await db.rooms
|
||||
.find({ project_id: ObjectId(projectId) })
|
||||
.find({ project_id: new ObjectId(projectId) })
|
||||
.toArray()
|
||||
expect(threadRooms.length).to.equal(2)
|
||||
const threadMessage = await getMessage(this.threadMessageId)
|
||||
@@ -55,7 +55,7 @@ describe('Destroying a project', async function () {
|
||||
|
||||
it('should remove the messages and threads from the database', async function () {
|
||||
const threadRooms = await db.rooms
|
||||
.find({ project_id: ObjectId(projectId) })
|
||||
.find({ project_id: new ObjectId(projectId) })
|
||||
.toArray()
|
||||
expect(threadRooms.length).to.equal(0)
|
||||
const threadMessage = await getMessage(this.threadMessageId)
|
||||
|
||||
@@ -15,9 +15,9 @@ describe('Editing a message', async function () {
|
||||
const newContent = 'updated thread message'
|
||||
let messageId
|
||||
beforeEach(async function () {
|
||||
projectId = ObjectId().toString()
|
||||
userId = ObjectId().toString()
|
||||
threadId = ObjectId().toString()
|
||||
projectId = new ObjectId().toString()
|
||||
userId = new ObjectId().toString()
|
||||
threadId = new ObjectId().toString()
|
||||
|
||||
const { response, body: message } = await ChatClient.sendMessage(
|
||||
projectId,
|
||||
@@ -80,7 +80,7 @@ describe('Editing a message', async function () {
|
||||
projectId,
|
||||
threadId,
|
||||
messageId,
|
||||
ObjectId(),
|
||||
new ObjectId(),
|
||||
newContent
|
||||
)
|
||||
expect(response.statusCode).to.equal(404)
|
||||
|
||||
@@ -15,8 +15,8 @@ async function getCount() {
|
||||
}
|
||||
|
||||
describe('Getting messages', async function () {
|
||||
const userId1 = ObjectId().toString()
|
||||
const userId2 = ObjectId().toString()
|
||||
const userId1 = new ObjectId().toString()
|
||||
const userId2 = new ObjectId().toString()
|
||||
const content1 = 'foo bar'
|
||||
const content2 = 'hello world'
|
||||
before(async function () {
|
||||
@@ -24,7 +24,7 @@ describe('Getting messages', async function () {
|
||||
})
|
||||
|
||||
describe('globally', async function () {
|
||||
const projectId = ObjectId().toString()
|
||||
const projectId = new ObjectId().toString()
|
||||
before(async function () {
|
||||
const previousCount = await getCount()
|
||||
const { response } = await ChatClient.sendGlobalMessage(
|
||||
@@ -60,9 +60,9 @@ describe('Getting messages', async function () {
|
||||
})
|
||||
|
||||
describe('from all the threads', async function () {
|
||||
const projectId = ObjectId().toString()
|
||||
const threadId1 = ObjectId().toString()
|
||||
const threadId2 = ObjectId().toString()
|
||||
const projectId = new ObjectId().toString()
|
||||
const threadId1 = new ObjectId().toString()
|
||||
const threadId2 = new ObjectId().toString()
|
||||
|
||||
before(async function () {
|
||||
const { response } = await ChatClient.sendMessage(
|
||||
|
||||
@@ -5,14 +5,14 @@ import * as ChatClient from './helpers/ChatClient.js'
|
||||
import * as ChatApp from './helpers/ChatApp.js'
|
||||
|
||||
describe('Resolving a thread', async function () {
|
||||
const projectId = ObjectId().toString()
|
||||
const userId = ObjectId().toString()
|
||||
const projectId = new ObjectId().toString()
|
||||
const userId = new ObjectId().toString()
|
||||
before(async function () {
|
||||
await ChatApp.ensureRunning()
|
||||
})
|
||||
|
||||
describe('with a resolved thread', async function () {
|
||||
const threadId = ObjectId().toString()
|
||||
const threadId = new ObjectId().toString()
|
||||
const content = 'resolved message'
|
||||
before(async function () {
|
||||
const { response } = await ChatClient.sendMessage(
|
||||
@@ -41,7 +41,7 @@ describe('Resolving a thread', async function () {
|
||||
})
|
||||
|
||||
describe('when a thread is not resolved', async function () {
|
||||
const threadId = ObjectId().toString()
|
||||
const threadId = new ObjectId().toString()
|
||||
const content = 'open message'
|
||||
before(async function () {
|
||||
const { response } = await ChatClient.sendMessage(
|
||||
@@ -61,7 +61,7 @@ describe('Resolving a thread', async function () {
|
||||
})
|
||||
|
||||
describe('when a thread is resolved then reopened', async function () {
|
||||
const threadId = ObjectId().toString()
|
||||
const threadId = new ObjectId().toString()
|
||||
const content = 'resolved message'
|
||||
before(async function () {
|
||||
const { response } = await ChatClient.sendMessage(
|
||||
|
||||
@@ -10,8 +10,8 @@ describe('Sending a message', async function () {
|
||||
})
|
||||
|
||||
describe('globally', async function () {
|
||||
const projectId = ObjectId().toString()
|
||||
const userId = ObjectId().toString()
|
||||
const projectId = new ObjectId().toString()
|
||||
const userId = new ObjectId().toString()
|
||||
const content = 'global message'
|
||||
before(async function () {
|
||||
const { response, body } = await ChatClient.sendGlobalMessage(
|
||||
@@ -36,9 +36,9 @@ describe('Sending a message', async function () {
|
||||
})
|
||||
|
||||
describe('to a thread', async function () {
|
||||
const projectId = ObjectId().toString()
|
||||
const userId = ObjectId().toString()
|
||||
const threadId = ObjectId().toString()
|
||||
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(
|
||||
@@ -70,9 +70,9 @@ describe('Sending a message', async function () {
|
||||
})
|
||||
|
||||
describe('failure cases', async function () {
|
||||
const projectId = ObjectId().toString()
|
||||
const userId = ObjectId().toString()
|
||||
const threadId = ObjectId().toString()
|
||||
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 () {
|
||||
|
||||
Reference in New Issue
Block a user