mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-12 13:13:45 +01:00
[chat] gracefully handle projects without threads/messages when cloning (#36101)
GitOrigin-RevId: 0623a4b801f469b7d55412f2be8aac782cb6ab19
This commit is contained in:
@@ -114,6 +114,7 @@ function _ensureIdsAreObjectIds(query) {
|
||||
|
||||
export async function duplicateRoomToOtherRoom(sourceRoomId, targetRoomId) {
|
||||
const sourceMessages = await findAllMessagesInRooms([sourceRoomId])
|
||||
if (sourceMessages.length === 0) return
|
||||
const targetMessages = sourceMessages.map(comment => {
|
||||
return _ensureIdsAreObjectIds({
|
||||
room_id: targetRoomId,
|
||||
|
||||
@@ -16,6 +16,7 @@ export async function cloneThreads(sourceProjectId, targetProjectId) {
|
||||
.find({ project_id: sourceProjectId, thread_id: { $exists: true } })
|
||||
.toArray()
|
||||
const mapping = []
|
||||
if (rooms.length === 0) return mapping
|
||||
await db.rooms.insertMany(
|
||||
rooms.map(room => {
|
||||
const from = room._id
|
||||
|
||||
@@ -122,6 +122,32 @@ describe('Cloning comment threads', async function () {
|
||||
expectValidationErrorRaw(response, 404, 'projectId')
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a thread whose room has no messages', async function () {
|
||||
before(async function () {
|
||||
this.emptyThreadId = new ObjectId().toString()
|
||||
const { response: deleteResponse } = await ChatClient.deleteMessage(
|
||||
projectId,
|
||||
this.emptyThreadId,
|
||||
new ObjectId().toString()
|
||||
)
|
||||
expect(deleteResponse.statusCode).to.equal(204)
|
||||
|
||||
const {
|
||||
response: { body: result, statusCode },
|
||||
} = await ChatClient.duplicateCommentThreads(projectId, [
|
||||
this.emptyThreadId,
|
||||
])
|
||||
this.result = result
|
||||
expect(statusCode).to.equal(200)
|
||||
})
|
||||
|
||||
it('should duplicate the thread', function () {
|
||||
expect(this.result.newThreads[this.emptyThreadId]).to.have.property(
|
||||
'duplicateId'
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('Cloning comment threads to another project', async function () {
|
||||
@@ -189,4 +215,21 @@ describe('Cloning comment threads to another project', async function () {
|
||||
expectValidationErrorRaw(response, 400, 'targetProjectId')
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a source project that has no comment threads', function () {
|
||||
it('should clone no threads into the target project', async function () {
|
||||
const emptySourceProjectId = new ObjectId().toString()
|
||||
const freshTargetProjectId = new ObjectId().toString()
|
||||
const { response } = await ChatClient.cloneCommentThreads(
|
||||
emptySourceProjectId,
|
||||
freshTargetProjectId
|
||||
)
|
||||
expect(response.statusCode).to.equal(204)
|
||||
|
||||
const { response: getResponse, body: threads } =
|
||||
await ChatClient.getThreads(freshTargetProjectId)
|
||||
expect(getResponse.statusCode).to.equal(200)
|
||||
expect(threads).to.deep.equal({})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user