Merge pull request #17368 from overleaf/em-handle-metadata

Handle tracked changes in project-history

GitOrigin-RevId: 9c790a4dcd874f0d68173fc65cb6823a4da55cc6
This commit is contained in:
Eric Mc Sween
2024-03-27 09:04:19 +00:00
committed by Copybot
parent 1ad2be35b5
commit 3ab54b5b14
10 changed files with 1189 additions and 108 deletions
@@ -344,7 +344,7 @@ describe('UpdateManager', function () {
appliedOps: this.appliedOps,
})
this.RedisManager.promises.updateDocument.resolves()
this.UpdateManager.promises._addMetadataToHistoryUpdates = sinon.stub()
this.UpdateManager.promises._adjustHistoryUpdatesMetadata = sinon.stub()
})
describe('normally', function () {
@@ -395,7 +395,7 @@ describe('UpdateManager', function () {
})
it('should add metadata to the ops', function () {
this.UpdateManager.promises._addMetadataToHistoryUpdates.should.have.been.calledWith(
this.UpdateManager.promises._adjustHistoryUpdatesMetadata.should.have.been.calledWith(
this.historyUpdates,
this.pathname,
this.projectHistoryId,
@@ -523,10 +523,10 @@ describe('UpdateManager', function () {
})
})
describe('_addMetadataToHistoryUpdates', function () {
it('should add projectHistoryId, pathname and doc_length metadata to the ops', function () {
const lines = ['some', 'test', 'data']
const historyUpdates = [
describe('_adjustHistoryUpdatesMetadata', function () {
beforeEach(function () {
this.lines = ['some', 'test', 'data']
this.historyUpdates = [
{
v: 42,
op: [
@@ -552,21 +552,81 @@ describe('UpdateManager', function () {
},
{ v: 49, op: [{ i: 'penguin', p: 18 }] },
]
const ranges = {
this.ranges = {
changes: [
{ op: { d: 'bingbong', p: 12 } },
{ op: { i: 'test', p: 5 } },
],
}
this.UpdateManager._addMetadataToHistoryUpdates(
historyUpdates,
})
it('should add projectHistoryId, pathname and doc_length metadata to the ops', function () {
this.UpdateManager._adjustHistoryUpdatesMetadata(
this.historyUpdates,
this.pathname,
this.projectHistoryId,
lines,
ranges,
this.lines,
this.ranges,
false
)
this.historyUpdates.should.deep.equal([
{
projectHistoryId: this.projectHistoryId,
v: 42,
op: [
{ i: 'bing', p: 12, trackedDeleteRejection: true },
{ i: 'foo', p: 4 },
{ i: 'bar', p: 6 },
],
meta: {
pathname: this.pathname,
doc_length: 14,
},
},
{
projectHistoryId: this.projectHistoryId,
v: 45,
op: [
{ d: 'qux', p: 4 },
{ i: 'bazbaz', p: 14 },
{ d: 'bong', p: 28, u: true },
],
meta: {
pathname: this.pathname,
doc_length: 24, // 14 + 'bing' + 'foo' + 'bar'
},
},
{
projectHistoryId: this.projectHistoryId,
v: 47,
op: [{ d: 'so', p: 0 }],
meta: {
pathname: this.pathname,
doc_length: 23, // 24 - 'qux' + 'bazbaz' - 'bong'
},
},
{
projectHistoryId: this.projectHistoryId,
v: 49,
op: [{ i: 'penguin', p: 18 }],
meta: {
pathname: this.pathname,
doc_length: 21, // 23 - 'so'
},
},
])
})
it('should add additional metadata when ranges support is enabled', function () {
this.UpdateManager._adjustHistoryUpdatesMetadata(
this.historyUpdates,
this.pathname,
this.projectHistoryId,
this.lines,
this.ranges,
true
)
historyUpdates.should.deep.equal([
this.historyUpdates.should.deep.equal([
{
projectHistoryId: this.projectHistoryId,
v: 42,