Merge pull request #14235 from overleaf/ii-history-project-diff

Project history diff fix

GitOrigin-RevId: 42d55425873aa610560a03609c01e55606894940
This commit is contained in:
ilkin-overleaf 2023-08-16 12:50:54 +03:00 committed by Copybot
parent 975ea16317
commit 6db48cdaa3
2 changed files with 19 additions and 23 deletions

View file

@ -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) {

View file

@ -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()
}
)