Files
overleaf-cep/services/docstore/test/acceptance/js/GettingAllDocsTests.js
T
Jakob Ackermann 4e80d65efc [ranges-tracker] add legacy orderedRejections field in tracked-changes (#36565)
* [docstore] use more realistic test stubs for ranges

* [monorepo] define ranges schemas in @overleaf/ranges-tracker

* [ranges-tracker] add legacy orderedRejections field in tracked-changes

* [monorepo] resolve @overleaf/ranges-tracker subpath imports in typescript

* [real-time] validate comment thread ids and tracked change id seeds

* [ranges-tracker] require ObjectId ids and tracked change metadata in ranges

* [monorepo] require ObjectId tracked change ids on the accept routes

* [web] use ObjectId comment thread ids in the DocumentController tests

GitOrigin-RevId: 58b20dec311d85b917ef63f9efbe745a265a2de6
2026-09-17 12:01:19 +00:00

183 lines
4.9 KiB
JavaScript

import mongodb from 'mongodb-legacy'
import async from 'async'
import DocstoreApp from './helpers/DocstoreApp.js'
import { callbackify } from 'node:util'
import DocstoreClient from './helpers/DocstoreClient.js'
const { ObjectId } = mongodb
describe('Getting all docs', function () {
beforeEach(function (done) {
this.project_id = new ObjectId()
this.threadId1 = new ObjectId().toString()
this.threadId2 = new ObjectId().toString()
this.docs = [
{
_id: new ObjectId(),
lines: ['one', 'two', 'three'],
ranges: {
comments: [
{
id: new ObjectId().toString(),
op: {
c: 'c',
p: 0,
t: this.threadId1,
},
},
],
changes: [
{
id: new ObjectId().toString(),
op: { d: 'd', p: 1 },
metadata: {
user_id: 'user-id-1',
ts: new Date().toJSON(),
},
},
],
},
rev: 2,
},
{
_id: new ObjectId(),
lines: ['aaa', 'bbb', 'ccc'],
ranges: {
changes: [
{
id: new ObjectId().toString(),
op: { i: 'd', p: 1 },
metadata: {
user_id: 'user-id-2',
ts: new Date().toJSON(),
},
},
],
},
rev: 4,
},
{
_id: new ObjectId(),
lines: ['111', '222', '333'],
ranges: {
comments: [
{
id: new ObjectId().toString(),
op: { c: 'c', p: 1, t: this.threadId2 },
},
],
changes: [
{
id: new ObjectId().toString(),
op: { d: 'x', p: 1 },
metadata: {
user_id: 'anonymous-user',
ts: new Date().toJSON(),
},
},
],
},
rev: 6,
},
]
this.fixedRanges = this.docs.map(doc => {
if (!doc.ranges?.comments?.length) return doc.ranges
return {
...doc.ranges,
comments: [
{ ...doc.ranges.comments[0], id: doc.ranges.comments[0].op.t },
],
}
})
this.deleted_doc = {
_id: new ObjectId(),
lines: ['deleted'],
ranges: {
comments: [
{
id: new ObjectId().toString(),
op: { c: 'c', p: 1, t: new ObjectId().toString() },
},
],
changes: [
{
id: new ObjectId().toString(),
op: { d: 'd', p: 0 },
metadata: {
user_id: 'user-id-3',
ts: new Date().toJSON(),
},
},
],
},
rev: 8,
}
const version = 42
const jobs = this.docs.map(doc =>
(
doc => callback =>
callbackify(DocstoreClient.createDoc)(
this.project_id,
doc._id,
doc.lines,
version,
doc.ranges,
callback
)
)(doc)
)
jobs.push(cb =>
callbackify(DocstoreClient.createDoc)(
this.project_id,
this.deleted_doc._id,
this.deleted_doc.lines,
version,
this.deleted_doc.ranges,
err => {
if (err) return done(err)
callbackify(DocstoreClient.deleteDoc)(
this.project_id,
this.deleted_doc._id,
cb
)
}
)
)
jobs.unshift(cb => callbackify(DocstoreApp.ensureRunning)(cb))
async.series(jobs, done)
})
it('getAllDocs should return all the (non-deleted) docs', async function () {
const docs = await DocstoreClient.getAllDocs(this.project_id)
docs.length.should.equal(this.docs.length)
for (let i = 0; i < docs.length; i++) {
const doc = docs[i]
doc.lines.should.deep.equal(this.docs[i].lines)
}
})
it('getAllRanges should return all the (non-deleted) doc ranges', async function () {
const docs = await DocstoreClient.getAllRanges(this.project_id)
docs.length.should.equal(this.docs.length)
for (let i = 0; i < docs.length; i++) {
const doc = docs[i]
doc.ranges.should.deep.equal(this.fixedRanges[i])
}
})
it('getTrackedChangesUserIds should return all the user ids from (non-deleted) ranges', async function () {
const userIds = await DocstoreClient.getTrackedChangesUserIds(
this.project_id
)
userIds.should.deep.equal(['user-id-1', 'user-id-2'])
})
it('getCommentThreadIds should return all the thread ids from (non-deleted) ranges', async function () {
const threadIds = await DocstoreClient.getCommentThreadIds(this.project_id)
threadIds.should.deep.equal({
[this.docs[0]._id.toString()]: [this.threadId1],
[this.docs[2]._id.toString()]: [this.threadId2],
})
})
})