From d62e2d99c89a44e0e321bd08ecd408e206eb8f40 Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Tue, 11 Oct 2022 12:33:01 +0100 Subject: [PATCH] Merge pull request #9926 from overleaf/jpa-fallback-lines [docstore] getAllDocs: ensure returned docs have a lines field GitOrigin-RevId: 8b1eb7ef7e68e50501442cc6700b3d5cb8d4361f --- services/docstore/app/js/HttpController.js | 9 ++++- .../test/unit/js/HttpControllerTests.js | 39 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/services/docstore/app/js/HttpController.js b/services/docstore/app/js/HttpController.js index 60c55341dd..59137aeb0b 100644 --- a/services/docstore/app/js/HttpController.js +++ b/services/docstore/app/js/HttpController.js @@ -79,7 +79,14 @@ function getAllDocs(req, res, next) { if (error) { return next(error) } - res.json(_buildDocsArrayView(projectId, docs)) + const docViews = _buildDocsArrayView(projectId, docs) + for (const docView of docViews) { + if (!docView.lines) { + logger.warn({ projectId, docId: docView._id }, 'missing doc lines') + docView.lines = [] + } + } + res.json(docViews) } ) } diff --git a/services/docstore/test/unit/js/HttpControllerTests.js b/services/docstore/test/unit/js/HttpControllerTests.js index c3e68b717a..53cc121c1c 100644 --- a/services/docstore/test/unit/js/HttpControllerTests.js +++ b/services/docstore/test/unit/js/HttpControllerTests.js @@ -198,6 +198,45 @@ describe('HttpController', function () { }) }) + describe('with null lines', function () { + beforeEach(function () { + this.req.params = { project_id: this.projectId } + this.docs = [ + { + _id: ObjectId(), + lines: null, + rev: 2, + }, + { + _id: ObjectId(), + lines: ['mock', 'lines', 'two'], + rev: 4, + }, + ] + this.DocManager.getAllNonDeletedDocs = sinon + .stub() + .callsArgWith(2, null, this.docs) + this.HttpController.getAllDocs(this.req, this.res, this.next) + }) + + it('should return the doc with fallback lines', function () { + this.res.json + .calledWith([ + { + _id: this.docs[0]._id.toString(), + lines: [], + rev: this.docs[0].rev, + }, + { + _id: this.docs[1]._id.toString(), + lines: this.docs[1].lines, + rev: this.docs[1].rev, + }, + ]) + .should.equal(true) + }) + }) + describe('with a null doc', function () { beforeEach(function () { this.req.params = { project_id: this.projectId }