2020-05-06 06:11:36 -04:00
|
|
|
const sinon = require('sinon')
|
2024-04-03 10:08:16 -04:00
|
|
|
const { expect } = require('chai')
|
2020-05-06 06:11:36 -04:00
|
|
|
const modulePath = '../../../../app/js/ProjectHistoryRedisManager.js'
|
|
|
|
const SandboxedModule = require('sandboxed-module')
|
|
|
|
const tk = require('timekeeper')
|
|
|
|
|
|
|
|
describe('ProjectHistoryRedisManager', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.project_id = 'project-id-123'
|
|
|
|
this.projectHistoryId = 'history-id-123'
|
|
|
|
this.user_id = 'user-id-123'
|
|
|
|
this.rclient = {}
|
2022-08-25 08:01:39 -04:00
|
|
|
this.source = 'editor'
|
2020-05-06 06:11:36 -04:00
|
|
|
tk.freeze(new Date())
|
2021-11-25 04:25:28 -05:00
|
|
|
|
|
|
|
this.Limits = {
|
|
|
|
docIsTooLarge: sinon.stub().returns(false),
|
|
|
|
}
|
|
|
|
|
2022-08-25 08:01:39 -04:00
|
|
|
this.ProjectHistoryRedisManager = SandboxedModule.require(modulePath, {
|
|
|
|
requires: {
|
|
|
|
'@overleaf/settings': (this.settings = {
|
|
|
|
max_doc_length: 123,
|
|
|
|
redis: {
|
|
|
|
project_history: {
|
|
|
|
key_schema: {
|
|
|
|
projectHistoryOps({ project_id: projectId }) {
|
|
|
|
return `ProjectHistory:Ops:${projectId}`
|
|
|
|
},
|
|
|
|
projectHistoryFirstOpTimestamp({ project_id: projectId }) {
|
|
|
|
return `ProjectHistory:FirstOpTimestamp:${projectId}`
|
2021-07-13 07:04:42 -04:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-05-06 06:11:36 -04:00
|
|
|
},
|
2022-08-25 08:01:39 -04:00
|
|
|
}),
|
|
|
|
'@overleaf/redis-wrapper': {
|
|
|
|
createClient: () => this.rclient,
|
2021-07-13 07:04:42 -04:00
|
|
|
},
|
2022-08-25 08:01:39 -04:00
|
|
|
'./Metrics': (this.metrics = { summary: sinon.stub() }),
|
|
|
|
'./Limits': this.Limits,
|
|
|
|
},
|
|
|
|
})
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
afterEach(function () {
|
2022-08-25 08:01:39 -04:00
|
|
|
tk.reset()
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('queueOps', function () {
|
2024-04-03 10:08:16 -04:00
|
|
|
beforeEach(async function () {
|
2020-05-06 06:11:36 -04:00
|
|
|
this.ops = ['mock-op-1', 'mock-op-2']
|
2024-04-03 10:08:16 -04:00
|
|
|
this.multi = { exec: sinon.stub().resolves([1]) }
|
2020-05-06 06:11:36 -04:00
|
|
|
this.multi.rpush = sinon.stub()
|
|
|
|
this.multi.setnx = sinon.stub()
|
|
|
|
this.rclient.multi = () => this.multi
|
2024-04-03 10:08:16 -04:00
|
|
|
await this.ProjectHistoryRedisManager.promises.queueOps(
|
2020-05-06 06:11:36 -04:00
|
|
|
this.project_id,
|
2024-04-03 10:08:16 -04:00
|
|
|
...this.ops
|
2020-05-06 06:11:36 -04:00
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should queue an update', function () {
|
2022-08-25 08:01:39 -04:00
|
|
|
this.multi.rpush
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWithExactly(
|
|
|
|
`ProjectHistory:Ops:${this.project_id}`,
|
|
|
|
this.ops[0],
|
|
|
|
this.ops[1]
|
|
|
|
)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2022-08-25 08:01:39 -04:00
|
|
|
it('should set the queue timestamp if not present', function () {
|
|
|
|
this.multi.setnx
|
2020-05-06 06:11:36 -04:00
|
|
|
.calledWithExactly(
|
|
|
|
`ProjectHistory:FirstOpTimestamp:${this.project_id}`,
|
|
|
|
Date.now()
|
|
|
|
)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('queueRenameEntity', function () {
|
2024-04-03 10:08:16 -04:00
|
|
|
beforeEach(async function () {
|
2020-05-06 06:11:36 -04:00
|
|
|
this.file_id = 1234
|
|
|
|
|
|
|
|
this.rawUpdate = {
|
|
|
|
pathname: (this.pathname = '/old'),
|
|
|
|
newPathname: (this.newPathname = '/new'),
|
2021-07-13 07:04:42 -04:00
|
|
|
version: (this.version = 2),
|
2020-05-06 06:11:36 -04:00
|
|
|
}
|
|
|
|
|
2024-04-03 10:08:16 -04:00
|
|
|
this.ProjectHistoryRedisManager.promises.queueOps = sinon
|
|
|
|
.stub()
|
|
|
|
.resolves()
|
|
|
|
await this.ProjectHistoryRedisManager.promises.queueRenameEntity(
|
2020-05-06 06:11:36 -04:00
|
|
|
this.project_id,
|
|
|
|
this.projectHistoryId,
|
|
|
|
'file',
|
|
|
|
this.file_id,
|
|
|
|
this.user_id,
|
|
|
|
this.rawUpdate,
|
2024-04-03 10:08:16 -04:00
|
|
|
this.source
|
2020-05-06 06:11:36 -04:00
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2022-08-25 08:01:39 -04:00
|
|
|
it('should queue an update', function () {
|
2020-05-06 06:11:36 -04:00
|
|
|
const update = {
|
|
|
|
pathname: this.pathname,
|
|
|
|
new_pathname: this.newPathname,
|
|
|
|
meta: {
|
|
|
|
user_id: this.user_id,
|
2021-07-13 07:04:42 -04:00
|
|
|
ts: new Date(),
|
2022-08-25 08:01:39 -04:00
|
|
|
source: this.source,
|
2020-05-06 06:11:36 -04:00
|
|
|
},
|
|
|
|
version: this.version,
|
|
|
|
projectHistoryId: this.projectHistoryId,
|
2021-07-13 07:04:42 -04:00
|
|
|
file: this.file_id,
|
2020-05-06 06:11:36 -04:00
|
|
|
}
|
|
|
|
|
2024-04-03 10:08:16 -04:00
|
|
|
this.ProjectHistoryRedisManager.promises.queueOps
|
|
|
|
.calledWithExactly(this.project_id, JSON.stringify(update))
|
2020-05-06 06:11:36 -04:00
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-08-25 08:01:39 -04:00
|
|
|
describe('queueAddEntity', function () {
|
2024-05-28 09:17:55 -04:00
|
|
|
beforeEach(function () {
|
2020-05-06 06:11:36 -04:00
|
|
|
this.doc_id = 1234
|
|
|
|
|
|
|
|
this.rawUpdate = {
|
|
|
|
pathname: (this.pathname = '/old'),
|
|
|
|
docLines: (this.docLines = 'a\nb'),
|
|
|
|
version: (this.version = 2),
|
|
|
|
}
|
|
|
|
|
2024-04-03 10:08:16 -04:00
|
|
|
this.ProjectHistoryRedisManager.promises.queueOps = sinon
|
|
|
|
.stub()
|
|
|
|
.resolves()
|
2024-05-28 09:17:55 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should queue an update', async function () {
|
|
|
|
this.rawUpdate.url = this.url = 'filestore.example.com'
|
2024-04-03 10:08:16 -04:00
|
|
|
await this.ProjectHistoryRedisManager.promises.queueAddEntity(
|
2020-05-06 06:11:36 -04:00
|
|
|
this.project_id,
|
|
|
|
this.projectHistoryId,
|
|
|
|
'doc',
|
|
|
|
this.doc_id,
|
|
|
|
this.user_id,
|
|
|
|
this.rawUpdate,
|
2024-04-03 10:08:16 -04:00
|
|
|
this.source
|
2020-05-06 06:11:36 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
const update = {
|
|
|
|
pathname: this.pathname,
|
|
|
|
docLines: this.docLines,
|
|
|
|
url: this.url,
|
|
|
|
meta: {
|
|
|
|
user_id: this.user_id,
|
2021-07-13 07:04:42 -04:00
|
|
|
ts: new Date(),
|
2022-08-25 08:01:39 -04:00
|
|
|
source: this.source,
|
2020-05-06 06:11:36 -04:00
|
|
|
},
|
|
|
|
version: this.version,
|
|
|
|
projectHistoryId: this.projectHistoryId,
|
2021-07-13 07:04:42 -04:00
|
|
|
doc: this.doc_id,
|
2020-05-06 06:11:36 -04:00
|
|
|
}
|
|
|
|
|
2024-04-03 10:08:16 -04:00
|
|
|
this.ProjectHistoryRedisManager.promises.queueOps
|
|
|
|
.calledWithExactly(this.project_id, JSON.stringify(update))
|
2020-05-06 06:11:36 -04:00
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2024-08-05 04:52:23 -04:00
|
|
|
it('should queue an update with file metadata', async function () {
|
|
|
|
const metadata = {
|
|
|
|
importedAt: '2024-07-30T09:14:45.928Z',
|
|
|
|
provider: 'references-provider',
|
|
|
|
}
|
|
|
|
const projectId = 'project-id'
|
|
|
|
const fileId = 'file-id'
|
|
|
|
const url = `http://filestore/project/${projectId}/file/${fileId}`
|
|
|
|
await this.ProjectHistoryRedisManager.promises.queueAddEntity(
|
|
|
|
projectId,
|
|
|
|
this.projectHistoryId,
|
|
|
|
'file',
|
|
|
|
fileId,
|
|
|
|
this.user_id,
|
|
|
|
{
|
|
|
|
pathname: 'foo.png',
|
|
|
|
url,
|
|
|
|
version: 42,
|
2024-08-05 04:52:40 -04:00
|
|
|
hash: '1337',
|
2024-08-05 04:52:23 -04:00
|
|
|
metadata,
|
|
|
|
},
|
|
|
|
this.source
|
|
|
|
)
|
|
|
|
|
|
|
|
const update = {
|
|
|
|
pathname: 'foo.png',
|
|
|
|
docLines: undefined,
|
|
|
|
url,
|
|
|
|
meta: {
|
|
|
|
user_id: this.user_id,
|
|
|
|
ts: new Date(),
|
|
|
|
source: this.source,
|
|
|
|
},
|
|
|
|
version: 42,
|
2024-08-05 04:52:40 -04:00
|
|
|
hash: '1337',
|
2024-08-05 04:52:23 -04:00
|
|
|
metadata,
|
|
|
|
projectHistoryId: this.projectHistoryId,
|
|
|
|
file: fileId,
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(
|
|
|
|
this.ProjectHistoryRedisManager.promises.queueOps.args[0][1]
|
|
|
|
).to.equal(JSON.stringify(update))
|
|
|
|
this.ProjectHistoryRedisManager.promises.queueOps.should.have.been.calledWithExactly(
|
|
|
|
projectId,
|
|
|
|
JSON.stringify(update)
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2024-05-28 09:17:55 -04:00
|
|
|
it('should forward history compatible ranges if history ranges support is enabled', async function () {
|
|
|
|
this.rawUpdate.historyRangesSupport = true
|
|
|
|
this.docLines = 'the quick fox jumps over the lazy dog'
|
|
|
|
|
|
|
|
const ranges = {
|
|
|
|
changes: [
|
|
|
|
{
|
|
|
|
op: { p: 4, i: 'quick' },
|
|
|
|
metadata: { ts: '2024-01-01T00:00:00.000Z', user_id: 'user-1' },
|
|
|
|
},
|
|
|
|
{
|
|
|
|
op: { p: 9, d: ' brown' },
|
|
|
|
metadata: { ts: '2024-02-01T00:00:00.000Z', user_id: 'user-1' },
|
|
|
|
},
|
|
|
|
{
|
|
|
|
op: { p: 14, i: 'jumps' },
|
|
|
|
metadata: { ts: '2024-02-01T00:00:00.000Z', user_id: 'user-1' },
|
|
|
|
},
|
|
|
|
],
|
|
|
|
comments: [
|
|
|
|
{
|
|
|
|
op: { p: 29, c: 'lazy', t: 'comment-1' },
|
|
|
|
metadata: { resolved: false },
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}
|
|
|
|
this.rawUpdate.ranges = ranges
|
|
|
|
this.rawUpdate.docLines = this.docLines
|
|
|
|
|
|
|
|
await this.ProjectHistoryRedisManager.promises.queueAddEntity(
|
|
|
|
this.project_id,
|
|
|
|
this.projectHistoryId,
|
|
|
|
'doc',
|
|
|
|
this.doc_id,
|
|
|
|
this.user_id,
|
|
|
|
this.rawUpdate,
|
|
|
|
this.source
|
|
|
|
)
|
|
|
|
|
|
|
|
const historyCompatibleRanges = {
|
|
|
|
comments: [
|
|
|
|
{
|
|
|
|
op: { p: 29, c: 'lazy', t: 'comment-1', hpos: 35 },
|
|
|
|
metadata: { resolved: false },
|
|
|
|
},
|
|
|
|
],
|
|
|
|
changes: [
|
|
|
|
{
|
|
|
|
op: { p: 4, i: 'quick' },
|
|
|
|
metadata: { ts: '2024-01-01T00:00:00.000Z', user_id: 'user-1' },
|
|
|
|
},
|
|
|
|
{
|
|
|
|
op: { p: 9, d: ' brown' },
|
|
|
|
metadata: { ts: '2024-02-01T00:00:00.000Z', user_id: 'user-1' },
|
|
|
|
},
|
|
|
|
{
|
|
|
|
op: { p: 14, i: 'jumps', hpos: 20 },
|
|
|
|
metadata: { ts: '2024-02-01T00:00:00.000Z', user_id: 'user-1' },
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
const update = {
|
|
|
|
pathname: this.pathname,
|
|
|
|
docLines: 'the quick brown fox jumps over the lazy dog',
|
|
|
|
meta: {
|
|
|
|
user_id: this.user_id,
|
|
|
|
ts: new Date(),
|
|
|
|
source: this.source,
|
|
|
|
},
|
|
|
|
version: this.version,
|
|
|
|
projectHistoryId: this.projectHistoryId,
|
|
|
|
ranges: historyCompatibleRanges,
|
|
|
|
doc: this.doc_id,
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(
|
|
|
|
this.ProjectHistoryRedisManager.promises.queueOps
|
|
|
|
).to.have.been.calledWithExactly(this.project_id, JSON.stringify(update))
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should not forward ranges if history ranges support is disabled', async function () {
|
|
|
|
this.rawUpdate.historyRangesSupport = false
|
|
|
|
|
|
|
|
const ranges = {
|
|
|
|
changes: [
|
|
|
|
{
|
|
|
|
op: { p: 0, i: 'foo' },
|
|
|
|
metadata: { ts: '2024-01-01T00:00:00.000Z', user_id: 'user-1' },
|
|
|
|
},
|
|
|
|
{
|
|
|
|
op: { p: 7, d: ' baz' },
|
|
|
|
metadata: { ts: '2024-02-01T00:00:00.000Z', user_id: 'user-1' },
|
|
|
|
},
|
|
|
|
],
|
|
|
|
comments: [
|
|
|
|
{
|
|
|
|
op: { p: 4, c: 'bar', t: 'comment-1' },
|
|
|
|
metadata: { resolved: false },
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}
|
|
|
|
this.rawUpdate.ranges = ranges
|
|
|
|
|
|
|
|
await this.ProjectHistoryRedisManager.promises.queueAddEntity(
|
|
|
|
this.project_id,
|
|
|
|
this.projectHistoryId,
|
|
|
|
'doc',
|
|
|
|
this.doc_id,
|
|
|
|
this.user_id,
|
|
|
|
this.rawUpdate,
|
|
|
|
this.source
|
|
|
|
)
|
|
|
|
|
|
|
|
const update = {
|
|
|
|
pathname: this.pathname,
|
|
|
|
docLines: this.docLines,
|
|
|
|
meta: {
|
|
|
|
user_id: this.user_id,
|
|
|
|
ts: new Date(),
|
|
|
|
source: this.source,
|
|
|
|
},
|
|
|
|
version: this.version,
|
|
|
|
projectHistoryId: this.projectHistoryId,
|
|
|
|
doc: this.doc_id,
|
|
|
|
}
|
|
|
|
|
|
|
|
this.ProjectHistoryRedisManager.promises.queueOps
|
|
|
|
.calledWithExactly(this.project_id, JSON.stringify(update))
|
|
|
|
.should.equal(true)
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
|
2024-05-28 09:17:55 -04:00
|
|
|
it('should not forward ranges if history ranges support is undefined', async function () {
|
|
|
|
this.rawUpdate.historyRangesSupport = false
|
|
|
|
|
|
|
|
const ranges = {
|
|
|
|
changes: [
|
|
|
|
{
|
|
|
|
op: { p: 0, i: 'foo' },
|
|
|
|
metadata: { ts: '2024-01-01T00:00:00.000Z', user_id: 'user-1' },
|
|
|
|
},
|
|
|
|
{
|
|
|
|
op: { p: 7, d: ' baz' },
|
|
|
|
metadata: { ts: '2024-02-01T00:00:00.000Z', user_id: 'user-1' },
|
|
|
|
},
|
|
|
|
],
|
|
|
|
comments: [
|
|
|
|
{
|
|
|
|
op: { p: 4, c: 'bar', t: 'comment-1' },
|
|
|
|
metadata: { resolved: false },
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}
|
|
|
|
this.rawUpdate.ranges = ranges
|
|
|
|
|
|
|
|
await this.ProjectHistoryRedisManager.promises.queueAddEntity(
|
|
|
|
this.project_id,
|
|
|
|
this.projectHistoryId,
|
|
|
|
'doc',
|
|
|
|
this.doc_id,
|
|
|
|
this.user_id,
|
|
|
|
this.rawUpdate,
|
|
|
|
this.source
|
|
|
|
)
|
|
|
|
|
|
|
|
const update = {
|
|
|
|
pathname: this.pathname,
|
|
|
|
docLines: this.docLines,
|
|
|
|
meta: {
|
|
|
|
user_id: this.user_id,
|
|
|
|
ts: new Date(),
|
|
|
|
source: this.source,
|
|
|
|
},
|
|
|
|
version: this.version,
|
|
|
|
projectHistoryId: this.projectHistoryId,
|
|
|
|
doc: this.doc_id,
|
|
|
|
}
|
|
|
|
|
|
|
|
this.ProjectHistoryRedisManager.promises.queueOps
|
|
|
|
.calledWithExactly(this.project_id, JSON.stringify(update))
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('queueResyncProjectStructure', function () {
|
|
|
|
it('should queue an update', function () {})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('queueResyncDocContent', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.doc_id = 1234
|
|
|
|
this.lines = ['one', 'two']
|
|
|
|
this.ranges = {
|
|
|
|
changes: [{ op: { i: 'ne', p: 1 } }, { op: { d: 'deleted', p: 3 } }],
|
|
|
|
}
|
|
|
|
this.resolvedCommentIds = ['comment-1']
|
|
|
|
this.version = 2
|
|
|
|
this.pathname = '/path'
|
|
|
|
|
|
|
|
this.ProjectHistoryRedisManager.promises.queueOps = sinon
|
|
|
|
.stub()
|
|
|
|
.resolves()
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('with a good doc', function () {
|
|
|
|
beforeEach(async function () {
|
|
|
|
this.update = {
|
|
|
|
resyncDocContent: {
|
|
|
|
content: 'one\ntwo',
|
|
|
|
version: this.version,
|
|
|
|
},
|
|
|
|
projectHistoryId: this.projectHistoryId,
|
|
|
|
path: this.pathname,
|
|
|
|
doc: this.doc_id,
|
|
|
|
meta: { ts: new Date() },
|
2024-04-08 11:07:41 -04:00
|
|
|
}
|
2021-11-25 04:25:28 -05:00
|
|
|
|
2024-05-28 09:17:55 -04:00
|
|
|
await this.ProjectHistoryRedisManager.promises.queueResyncDocContent(
|
|
|
|
this.project_id,
|
|
|
|
this.projectHistoryId,
|
|
|
|
this.doc_id,
|
|
|
|
this.lines,
|
|
|
|
this.ranges,
|
|
|
|
this.resolvedCommentIds,
|
|
|
|
this.version,
|
|
|
|
this.pathname,
|
|
|
|
false
|
|
|
|
)
|
2021-11-25 04:25:28 -05:00
|
|
|
})
|
|
|
|
|
2024-05-28 09:17:55 -04:00
|
|
|
it('should check if the doc is too large', function () {
|
|
|
|
this.Limits.docIsTooLarge
|
|
|
|
.calledWith(
|
|
|
|
JSON.stringify(this.update).length,
|
|
|
|
this.lines,
|
|
|
|
this.settings.max_doc_length
|
|
|
|
)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should queue an update', function () {
|
|
|
|
this.ProjectHistoryRedisManager.promises.queueOps
|
|
|
|
.calledWithExactly(this.project_id, JSON.stringify(this.update))
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
2024-04-08 11:07:41 -04:00
|
|
|
|
2024-05-28 09:17:55 -04:00
|
|
|
describe('with a doc that is too large', function () {
|
|
|
|
beforeEach(async function () {
|
|
|
|
this.Limits.docIsTooLarge.returns(true)
|
|
|
|
await expect(
|
|
|
|
this.ProjectHistoryRedisManager.promises.queueResyncDocContent(
|
2021-11-25 04:25:28 -05:00
|
|
|
this.project_id,
|
|
|
|
this.projectHistoryId,
|
|
|
|
this.doc_id,
|
|
|
|
this.lines,
|
2024-04-08 11:07:41 -04:00
|
|
|
this.ranges,
|
2024-05-28 07:24:06 -04:00
|
|
|
this.resolvedCommentIds,
|
2021-11-25 04:25:28 -05:00
|
|
|
this.version,
|
2024-04-08 11:07:41 -04:00
|
|
|
this.pathname,
|
|
|
|
false
|
2021-11-25 04:25:28 -05:00
|
|
|
)
|
2024-05-28 09:17:55 -04:00
|
|
|
).to.be.rejected
|
2021-11-25 04:25:28 -05:00
|
|
|
})
|
|
|
|
|
2024-05-28 09:17:55 -04:00
|
|
|
it('should not queue an update if the doc is too large', function () {
|
|
|
|
this.ProjectHistoryRedisManager.promises.queueOps.called.should.equal(
|
|
|
|
false
|
|
|
|
)
|
2021-11-25 04:25:28 -05:00
|
|
|
})
|
2024-05-28 09:17:55 -04:00
|
|
|
})
|
2024-04-08 11:07:41 -04:00
|
|
|
|
2024-05-28 09:17:55 -04:00
|
|
|
describe('when history ranges support is enabled', function () {
|
|
|
|
beforeEach(async function () {
|
|
|
|
this.update = {
|
|
|
|
resyncDocContent: {
|
|
|
|
content: 'onedeleted\ntwo',
|
|
|
|
version: this.version,
|
|
|
|
ranges: this.ranges,
|
|
|
|
resolvedCommentIds: this.resolvedCommentIds,
|
|
|
|
},
|
|
|
|
projectHistoryId: this.projectHistoryId,
|
|
|
|
path: this.pathname,
|
|
|
|
doc: this.doc_id,
|
|
|
|
meta: { ts: new Date() },
|
|
|
|
}
|
2024-04-08 11:07:41 -04:00
|
|
|
|
2024-05-28 09:17:55 -04:00
|
|
|
await this.ProjectHistoryRedisManager.promises.queueResyncDocContent(
|
|
|
|
this.project_id,
|
|
|
|
this.projectHistoryId,
|
|
|
|
this.doc_id,
|
|
|
|
this.lines,
|
|
|
|
this.ranges,
|
|
|
|
this.resolvedCommentIds,
|
|
|
|
this.version,
|
|
|
|
this.pathname,
|
|
|
|
true
|
|
|
|
)
|
|
|
|
})
|
2024-04-08 11:07:41 -04:00
|
|
|
|
2024-05-28 09:17:55 -04:00
|
|
|
it('should include tracked deletes in the update', function () {
|
|
|
|
this.ProjectHistoryRedisManager.promises.queueOps.should.have.been.calledWithExactly(
|
|
|
|
this.project_id,
|
|
|
|
JSON.stringify(this.update)
|
|
|
|
)
|
|
|
|
})
|
2024-04-08 11:07:41 -04:00
|
|
|
|
2024-05-28 09:17:55 -04:00
|
|
|
it('should check the doc length without tracked deletes', function () {
|
|
|
|
this.Limits.docIsTooLarge.should.have.been.calledWith(
|
|
|
|
JSON.stringify(this.update).length,
|
|
|
|
this.lines,
|
|
|
|
this.settings.max_doc_length
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should queue an update', function () {
|
|
|
|
this.ProjectHistoryRedisManager.promises.queueOps
|
|
|
|
.calledWithExactly(this.project_id, JSON.stringify(this.update))
|
|
|
|
.should.equal(true)
|
2024-04-08 11:07:41 -04:00
|
|
|
})
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|