mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-12 13:13:45 +01:00
* [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
130 lines
4.1 KiB
JavaScript
130 lines
4.1 KiB
JavaScript
const { expect } = require('chai')
|
|
const { ranges } = require('../../schemas')
|
|
|
|
const metadata = Object.freeze({
|
|
user_id: '65a4f2c3b1e4d5a6f7089123',
|
|
ts: '2026-08-14T10:47:58.000Z',
|
|
})
|
|
const threadId = '65a4f2c3b1e4d5a6f7089124'
|
|
// an 18 character RangesTracker id seed plus its 6 character increment
|
|
const changeId = '65a4f2c3b1e4d5a6f7' + '000001'
|
|
|
|
describe('schemas', function () {
|
|
describe('ranges', function () {
|
|
it('accepts a legacy fixedRemoveChange flag on an insert op', function () {
|
|
const result = ranges.safeParse({
|
|
changes: [
|
|
{ op: { i: 'foo', p: 0, fixedRemoveChange: true }, metadata },
|
|
],
|
|
})
|
|
expect(result.success).to.equal(true)
|
|
})
|
|
|
|
it('accepts a legacy fixedRemoveChange flag on a delete op', function () {
|
|
const result = ranges.safeParse({
|
|
changes: [
|
|
{ op: { d: 'foo', p: 0, fixedRemoveChange: true }, metadata },
|
|
],
|
|
})
|
|
expect(result.success).to.equal(true)
|
|
})
|
|
|
|
it('accepts a legacy orderedRejections flag on an insert op', function () {
|
|
const result = ranges.safeParse({
|
|
changes: [
|
|
{ op: { i: 'foo', p: 0, orderedRejections: true }, metadata },
|
|
],
|
|
})
|
|
expect(result.success).to.equal(true)
|
|
})
|
|
|
|
it('accepts a legacy orderedRejections flag on a delete op', function () {
|
|
const result = ranges.safeParse({
|
|
changes: [
|
|
{ op: { d: 'foo', p: 0, orderedRejections: true }, metadata },
|
|
],
|
|
})
|
|
expect(result.success).to.equal(true)
|
|
})
|
|
|
|
it('rejects an unrecognized key on an insert op', function () {
|
|
const result = ranges.safeParse({
|
|
changes: [{ op: { i: 'foo', p: 0, somethingElse: true }, metadata }],
|
|
})
|
|
expect(result.success).to.equal(false)
|
|
})
|
|
|
|
it('rejects a tracked change without metadata', function () {
|
|
const result = ranges.safeParse({
|
|
changes: [{ op: { i: 'foo', p: 0 } }],
|
|
})
|
|
expect(result.success).to.equal(false)
|
|
})
|
|
|
|
it('rejects a tracked change without a user_id', function () {
|
|
const result = ranges.safeParse({
|
|
changes: [{ op: { i: 'foo', p: 0 }, metadata: { ts: metadata.ts } }],
|
|
})
|
|
expect(result.success).to.equal(false)
|
|
})
|
|
|
|
it('accepts a tracked change with a RangesTracker id', function () {
|
|
const result = ranges.safeParse({
|
|
changes: [{ id: changeId, op: { i: 'foo', p: 0 }, metadata }],
|
|
})
|
|
expect(result.success).to.equal(true)
|
|
})
|
|
|
|
it('rejects a tracked change with a non-ObjectId id', function () {
|
|
const result = ranges.safeParse({
|
|
changes: [{ id: 'tc_1000001', op: { i: 'foo', p: 0 }, metadata }],
|
|
})
|
|
expect(result.success).to.equal(false)
|
|
})
|
|
|
|
it('rejects a tracked change without a ts', function () {
|
|
const result = ranges.safeParse({
|
|
changes: [
|
|
{ op: { i: 'foo', p: 0 }, metadata: { user_id: metadata.user_id } },
|
|
],
|
|
})
|
|
expect(result.success).to.equal(false)
|
|
})
|
|
|
|
it('accepts a comment op with an ObjectId thread id', function () {
|
|
const result = ranges.safeParse({
|
|
comments: [{ op: { c: 'foo', p: 0, t: threadId } }],
|
|
})
|
|
expect(result.success).to.equal(true)
|
|
})
|
|
|
|
it('rejects a comment op with a non-ObjectId thread id', function () {
|
|
const result = ranges.safeParse({
|
|
comments: [{ op: { c: 'foo', p: 0, t: 'thread-id-1' } }],
|
|
})
|
|
expect(result.success).to.equal(false)
|
|
})
|
|
|
|
it('rejects a comment op without a thread id', function () {
|
|
const result = ranges.safeParse({
|
|
comments: [{ op: { c: 'foo', p: 0 } }],
|
|
})
|
|
expect(result.success).to.equal(false)
|
|
})
|
|
|
|
it('accepts a comment with an ObjectId id', function () {
|
|
const result = ranges.safeParse({
|
|
comments: [{ id: threadId, op: { c: 'foo', p: 0, t: threadId } }],
|
|
})
|
|
expect(result.success).to.equal(true)
|
|
})
|
|
|
|
it('rejects a comment with a non-ObjectId id', function () {
|
|
const result = ranges.safeParse({
|
|
comments: [{ id: 'thread-id-1', op: { c: 'foo', p: 0, t: threadId } }],
|
|
})
|
|
expect(result.success).to.equal(false)
|
|
})
|
|
})
|
|
})
|