Explorar o código

Merge pull request #19263 from overleaf/mj-doc-updater-missing-ranges

[doc-updater] Allow resyncs on docs without ranges property

GitOrigin-RevId: b393e463036990ae18bb18aa93ed24c833a619ea
Eric Mc Sween %!s(int64=2) %!d(string=hai) anos
pai
achega
adf21125b7

+ 1 - 1
services/document-updater/app/js/DocumentManager.js

@@ -431,7 +431,7 @@ const DocumentManager = {
       projectHistoryId,
       projectHistoryId,
       docId,
       docId,
       lines,
       lines,
-      ranges,
+      ranges ?? {},
       resolvedCommentIds,
       resolvedCommentIds,
       version,
       version,
       // use the path from the resyncProjectStructure update
       // use the path from the resyncProjectStructure update

+ 43 - 0
services/document-updater/test/unit/js/DocumentManager/DocumentManagerTests.js

@@ -1085,5 +1085,48 @@ describe('DocumentManager', function () {
           .should.equal(true)
           .should.equal(true)
       })
       })
     })
     })
+
+    describe('when a doc has no ranges in docstore', function () {
+      beforeEach(async function () {
+        this.pathnameFromProjectStructureUpdate = '/foo/bar.tex'
+        this.RedisManager.promises.getDoc.resolves({})
+        this.PersistenceManager.promises.getDoc.resolves({
+          lines: this.lines,
+          version: this.version,
+          ranges: undefined,
+          resolvedCommentIds: [],
+          pathname: this.pathname,
+          projectHistoryId: this.projectHistoryId,
+          historyRangesSupport: this.historyRangesSupport,
+        })
+        await this.DocumentManager.promises.resyncDocContents(
+          this.project_id,
+          this.doc_id,
+          this.pathnameFromProjectStructureUpdate
+        )
+      })
+
+      it('gets the doc contents from web', function () {
+        this.PersistenceManager.promises.getDoc
+          .calledWith(this.project_id, this.doc_id, { peek: true })
+          .should.equal(true)
+      })
+
+      it('queues a resync doc content update with an empty ranges object', function () {
+        this.ProjectHistoryRedisManager.promises.queueResyncDocContent
+          .calledWith(
+            this.project_id,
+            this.projectHistoryId,
+            this.doc_id,
+            this.lines,
+            {},
+            [],
+            this.version,
+            this.pathnameFromProjectStructureUpdate,
+            this.historyRangesSupport
+          )
+          .should.equal(true)
+      })
+    })
   })
   })
 })
 })