From 6db48cdaa3c221cb3087acdc8392babf1f4e333c Mon Sep 17 00:00:00 2001 From: ilkin-overleaf <100852799+ilkin-overleaf@users.noreply.github.com> Date: Wed, 16 Aug 2023 12:50:54 +0300 Subject: [PATCH] Merge pull request #14235 from overleaf/ii-history-project-diff Project history diff fix GitOrigin-RevId: 42d55425873aa610560a03609c01e55606894940 --- .../app/js/FileTreeDiffGenerator.js | 24 ++++--------------- .../test/acceptance/js/FileTreeDiffTests.js | 18 ++++++++++---- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/services/project-history/app/js/FileTreeDiffGenerator.js b/services/project-history/app/js/FileTreeDiffGenerator.js index 5937b7a70e..16696c686c 100644 --- a/services/project-history/app/js/FileTreeDiffGenerator.js +++ b/services/project-history/app/js/FileTreeDiffGenerator.js @@ -71,25 +71,11 @@ function _getInitialFiles(chunk, fromVersion) { } function _applyAddFileToDiff(diff, operation) { - const change = diff[operation.pathname] - if (change != null) { - // already exists, likely a delete so just cancel that and put the file back to unchanged - if (change.operation !== 'removed') { - const err = new Errors.InconsistentChunkError( - 'trying to add file that already exists', - { diff, operation } - ) - throw err - } - delete diff[operation.pathname].operation - return delete diff[operation.pathname].deletedAtV - } else { - return (diff[operation.pathname] = { - pathname: operation.pathname, - operation: 'added', - editable: operation.file.isEditable(), - }) - } + return (diff[operation.pathname] = { + pathname: operation.pathname, + operation: 'added', + editable: operation.file.isEditable(), + }) } function _applyEditFileToDiff(diff, operation) { diff --git a/services/project-history/test/acceptance/js/FileTreeDiffTests.js b/services/project-history/test/acceptance/js/FileTreeDiffTests.js index 0e8f897fef..2a16979349 100644 --- a/services/project-history/test/acceptance/js/FileTreeDiffTests.js +++ b/services/project-history/test/acceptance/js/FileTreeDiffTests.js @@ -409,7 +409,7 @@ describe('FileTree Diffs', function () { ) }) - it('should handle deleting the re-adding a file', function (done) { + it('should handle deleting then re-adding a file', function (done) { MockHistoryStore() .get(`/api/projects/${this.historyId}/versions/5/history`) .reply(200, { @@ -465,7 +465,8 @@ describe('FileTree Diffs', function () { diff: [ { pathname: 'one.tex', - editable: true, + operation: 'added', + editable: null, }, ], }) @@ -655,7 +656,7 @@ describe('FileTree Diffs', function () { ) }) - it('should return 422 with a chunk with an invalid add', function (done) { + it('should return 200 with a chunk with an invalid add', function (done) { MockHistoryStore() .get(`/api/projects/${this.historyId}/versions/6/history`) .reply(200, { @@ -697,7 +698,16 @@ describe('FileTree Diffs', function () { if (error != null) { throw error } - expect(statusCode).to.equal(422) + expect(diff).to.deep.equal({ + diff: [ + { + pathname: 'foo.tex', + operation: 'added', + editable: null, + }, + ], + }) + expect(statusCode).to.equal(200) return done() } )