Merge pull request #21051 from overleaf/msm-esm-migration-history-v1

[web] Migrate `modules/history-v1` to ESM

GitOrigin-RevId: db1f5485ea268a6a9f62efd3183e16920505bfda
This commit is contained in:
Miguel Serrano 2024-10-15 10:15:43 +02:00 committed by Copybot
parent 3f0cf84318
commit cc0ce638b7
5 changed files with 108 additions and 142 deletions

View file

@ -3,4 +3,4 @@
/** @type {WebModule} */
const HistoryModule = {}
module.exports = HistoryModule
export default HistoryModule

View file

@ -1,24 +1,9 @@
/* eslint-disable
max-len,
no-unused-vars,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const { expect } = require('chai')
const _ = require('lodash')
import { expect } from 'chai'
const {
db,
ObjectId,
} = require('../../../../../app/src/infrastructure/mongodb')
const User = require('../../../../../test/acceptance/src/helpers/User')
const MockV1HistoryApiClass = require('../../../../../test/acceptance/src/mocks/MockV1HistoryApi')
import _ from 'lodash'
import { db, ObjectId } from '../../../../../app/src/infrastructure/mongodb.js'
import User from '../../../../../test/acceptance/src/helpers/User.js'
import MockV1HistoryApiClass from '../../../../../test/acceptance/src/mocks/MockV1HistoryApi.js'
let MockV1HistoryApi
@ -29,18 +14,18 @@ before(function () {
describe('History', function () {
beforeEach(function (done) {
this.owner = new User()
return this.owner.login(done)
this.owner.login(done)
})
describe('zip download of version', function () {
it('should stream the zip file of a version', function (done) {
return this.owner.createProject('example-project', (error, projectId) => {
this.owner.createProject('example-project', (error, projectId) => {
this.project_id = projectId
if (error != null) {
if (error) {
return done(error)
}
this.v1_history_id = 42
return db.projects.updateOne(
db.projects.updateOne(
{
_id: new ObjectId(this.project_id),
},
@ -50,13 +35,13 @@ describe('History', function () {
},
},
error => {
if (error != null) {
if (error) {
return done(error)
}
return this.owner.request(
this.owner.request(
`/project/${this.project_id}/version/42/zip`,
(error, response, body) => {
if (error != null) {
if (error) {
return done(error)
}
expect(response.statusCode).to.equal(200)
@ -69,7 +54,7 @@ describe('History', function () {
expect(body).to.equal(
`Mock zip for ${this.v1_history_id} at version 42`
)
return done()
done()
}
)
}
@ -195,12 +180,12 @@ describe('History', function () {
})
it('should return 402 for non-v2-history project', function (done) {
return this.owner.createProject('non-v2-project', (error, projectId) => {
this.owner.createProject('non-v2-project', (error, projectId) => {
this.project_id = projectId
if (error != null) {
if (error) {
return done(error)
}
return db.projects.updateOne(
db.projects.updateOne(
{
_id: new ObjectId(this.project_id),
},
@ -210,17 +195,17 @@ describe('History', function () {
},
},
error => {
if (error != null) {
if (error) {
return done(error)
}
return this.owner.request(
this.owner.request(
`/project/${this.project_id}/version/42/zip`,
(error, response, body) => {
if (error != null) {
if (error) {
return done(error)
}
expect(response.statusCode).to.equal(402)
return done()
done()
}
)
}
@ -234,7 +219,7 @@ describe('History', function () {
_.remove(
MockV1HistoryApi.app._router.stack,
appRoute =>
(appRoute.route != null ? appRoute.route.path : undefined) ===
appRoute.route?.path ===
'/api/projects/:project_id/version/:version/zip'
)
MockV1HistoryApi.app.post(
@ -258,7 +243,7 @@ describe('History', function () {
}
this.project_id = projectId
this.v1_history_id = 42
return db.projects.updateOne(
db.projects.updateOne(
{
_id: new ObjectId(this.project_id),
},
@ -274,11 +259,11 @@ describe('History', function () {
this.owner.request(
`/project/${this.project_id}/version/42/zip`,
(error, response, body) => {
if (error != null) {
if (error) {
return done(error)
}
expect(response.statusCode).to.equal(404)
return done()
done()
}
)
}
@ -292,7 +277,7 @@ describe('History', function () {
_.remove(
MockV1HistoryApi.app._router.stack,
appRoute =>
(appRoute.route != null ? appRoute.route.path : undefined) ===
appRoute.route?.path ===
'/api/projects/:project_id/version/:version/zip'
)
MockV1HistoryApi.app.get(
@ -322,7 +307,7 @@ describe('History', function () {
}
this.project_id = projectId
this.v1_history_id = 42
return db.projects.updateOne(
db.projects.updateOne(
{
_id: new ObjectId(this.project_id),
},
@ -338,11 +323,11 @@ describe('History', function () {
this.owner.request(
`/project/${this.project_id}/version/42/zip`,
(error, response, body) => {
if (error != null) {
if (error) {
return done(error)
}
expect(response.statusCode).to.equal(500)
return done()
done()
}
)
}

View file

@ -1,21 +1,9 @@
/* eslint-disable
max-len,
no-unused-vars,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const _ = require('lodash')
const { expect } = require('chai')
const { ObjectId } = require('mongodb-legacy')
import { expect } from 'chai'
import mongodb from 'mongodb-legacy'
import User from '../../../../../test/acceptance/src/helpers/User.js'
import MockProjectHistoryApiClass from '../../../../../test/acceptance/src/mocks/MockProjectHistoryApi.js'
const User = require('../../../../../test/acceptance/src/helpers/User')
const MockProjectHistoryApiClass = require('../../../../../test/acceptance/src/mocks/MockProjectHistoryApi')
const { ObjectId } = mongodb
let MockProjectHistoryApi
@ -26,19 +14,19 @@ before(function () {
describe('Labels', function () {
beforeEach(function (done) {
this.owner = new User()
return this.owner.login(error => {
if (error != null) {
this.owner.login(error => {
if (error) {
throw error
}
return this.owner.createProject(
this.owner.createProject(
'example-project',
{ template: 'example' },
(error, projectId) => {
this.project_id = projectId
if (error != null) {
if (error) {
throw error
}
return done()
done()
}
)
})
@ -54,19 +42,19 @@ describe('Labels', function () {
version,
})
return this.owner.request(
this.owner.request(
{
method: 'GET',
url: `/project/${this.project_id}/labels`,
json: true,
},
(error, response, body) => {
if (error != null) {
if (error) {
throw error
}
expect(response.statusCode).to.equal(200)
expect(body).to.deep.equal([{ id: labelId, comment, version }])
return done()
done()
}
)
})
@ -75,14 +63,14 @@ describe('Labels', function () {
const comment = 'a label comment'
const version = 3
return this.owner.request(
this.owner.request(
{
method: 'POST',
url: `/project/${this.project_id}/labels`,
json: { comment, version },
},
(error, response, body) => {
if (error != null) {
if (error) {
throw error
}
expect(response.statusCode).to.equal(200)
@ -90,7 +78,7 @@ describe('Labels', function () {
expect(MockProjectHistoryApi.getLabels(this.project_id)).to.deep.equal([
{ id: labelId, comment, version },
])
return done()
done()
}
)
})
@ -105,21 +93,21 @@ describe('Labels', function () {
version,
})
return this.owner.request(
this.owner.request(
{
method: 'DELETE',
url: `/project/${this.project_id}/labels/${labelId}`,
json: true,
},
(error, response, body) => {
if (error != null) {
if (error) {
throw error
}
expect(response.statusCode).to.equal(204)
expect(MockProjectHistoryApi.getLabels(this.project_id)).to.deep.equal(
[]
)
return done()
done()
}
)
})

View file

@ -1,15 +1,17 @@
const { expect } = require('chai')
const { ObjectId } = require('mongodb-legacy')
const Path = require('path')
const fs = require('fs')
const Settings = require('@overleaf/settings')
const _ = require('lodash')
import { expect } from 'chai'
import mongodb from 'mongodb-legacy'
import Path from 'node:path'
import { fileURLToPath } from 'node:url'
import fs from 'node:fs'
import Settings from '@overleaf/settings'
import _ from 'lodash'
import ProjectGetter from '../../../../../app/src/Features/Project/ProjectGetter.js'
import User from '../../../../../test/acceptance/src/helpers/User.js'
import MockDocUpdaterApiClass from '../../../../../test/acceptance/src/mocks/MockDocUpdaterApi.js'
const ProjectGetter = require('../../../../../app/src/Features/Project/ProjectGetter')
const User = require('../../../../../test/acceptance/src/helpers/User')
const MockDocUpdaterApiClass = require('../../../../../test/acceptance/src/mocks/MockDocUpdaterApi')
const { ObjectId } = mongodb
const __dirname = fileURLToPath(new URL('.', import.meta.url))
const FILES_PATH = Path.join(__dirname, '../../../../../test/acceptance/files')
let MockDocUpdaterApi

View file

@ -1,27 +1,18 @@
/* eslint-disable
max-len,
no-unused-vars,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const { expect } = require('chai')
const _ = require('lodash')
const fs = require('fs')
const Path = require('path')
import { expect } from 'chai'
const User = require('../../../../../test/acceptance/src/helpers/User')
const MockProjectHistoryApiClass = require('../../../../../test/acceptance/src/mocks/MockProjectHistoryApi')
const MockDocstoreApiClass = require('../../../../../test/acceptance/src/mocks/MockDocstoreApi')
const MockFilestoreApiClass = require('../../../../../test/acceptance/src/mocks/MockFilestoreApi')
import _ from 'lodash'
import fs from 'node:fs'
import { fileURLToPath } from 'node:url'
import Path from 'node:path'
import User from '../../../../../test/acceptance/src/helpers/User.js'
import MockProjectHistoryApiClass from '../../../../../test/acceptance/src/mocks/MockProjectHistoryApi.js'
import MockDocstoreApiClass from '../../../../../test/acceptance/src/mocks/MockDocstoreApi.js'
import MockFilestoreApiClass from '../../../../../test/acceptance/src/mocks/MockFilestoreApi.js'
let MockProjectHistoryApi, MockDocstoreApi, MockFilestoreApi
const __dirname = fileURLToPath(new URL('.', import.meta.url))
before(function () {
MockProjectHistoryApi = MockProjectHistoryApiClass.instance()
MockDocstoreApi = MockDocstoreApiClass.instance()
@ -31,19 +22,19 @@ before(function () {
describe('RestoringFiles', function () {
beforeEach(function (done) {
this.owner = new User()
return this.owner.login(error => {
if (error != null) {
this.owner.login(error => {
if (error) {
throw error
}
return this.owner.createProject(
this.owner.createProject(
'example-project',
{ template: 'example' },
(error, projectId) => {
this.project_id = projectId
if (error != null) {
if (error) {
throw error
}
return done()
done()
}
)
})
@ -58,7 +49,7 @@ describe('RestoringFiles', function () {
'foo.tex',
'hello world, this is foo.tex!'
)
return this.owner.request(
this.owner.request(
{
method: 'POST',
url: `/project/${this.project_id}/restore_file`,
@ -68,18 +59,18 @@ describe('RestoringFiles', function () {
},
},
(error, response, body) => {
if (error != null) {
if (error) {
throw error
}
expect(response.statusCode).to.equal(200)
return done()
done()
}
)
})
it('should have created a doc', function (done) {
return this.owner.getProject(this.project_id, (error, project) => {
if (error != null) {
this.owner.getProject(this.project_id, (error, project) => {
if (error) {
throw error
}
let doc = _.find(
@ -88,7 +79,7 @@ describe('RestoringFiles', function () {
)
doc = MockDocstoreApi.docs[this.project_id][doc._id]
expect(doc.lines).to.deep.equal(['hello world, this is foo.tex!'])
return done()
done()
})
})
})
@ -108,7 +99,7 @@ describe('RestoringFiles', function () {
'image.png',
this.pngData
)
return this.owner.request(
this.owner.request(
{
method: 'POST',
url: `/project/${this.project_id}/restore_file`,
@ -118,18 +109,18 @@ describe('RestoringFiles', function () {
},
},
(error, response, body) => {
if (error != null) {
if (error) {
throw error
}
expect(response.statusCode).to.equal(200)
return done()
done()
}
)
})
it('should have created a file', function (done) {
return this.owner.getProject(this.project_id, (error, project) => {
if (error != null) {
this.owner.getProject(this.project_id, (error, project) => {
if (error) {
throw error
}
let file = _.find(
@ -138,7 +129,7 @@ describe('RestoringFiles', function () {
)
file = MockFilestoreApi.files[this.project_id][file._id]
expect(file.content).to.equal(this.pngData)
return done()
done()
})
})
})
@ -151,7 +142,7 @@ describe('RestoringFiles', function () {
'foldername/foo2.tex',
'hello world, this is foo-2.tex!'
)
return this.owner.request.post(
this.owner.request.post(
{
uri: `project/${this.project_id}/folder`,
json: {
@ -159,11 +150,11 @@ describe('RestoringFiles', function () {
},
},
(error, response, body) => {
if (error != null) {
if (error) {
throw error
}
expect(response.statusCode).to.equal(200)
return this.owner.request(
this.owner.request(
{
method: 'POST',
url: `/project/${this.project_id}/restore_file`,
@ -173,11 +164,11 @@ describe('RestoringFiles', function () {
},
},
(error, response, body) => {
if (error != null) {
if (error) {
throw error
}
expect(response.statusCode).to.equal(200)
return done()
done()
}
)
}
@ -185,8 +176,8 @@ describe('RestoringFiles', function () {
})
it('should have created the doc in the named folder', function (done) {
return this.owner.getProject(this.project_id, (error, project) => {
if (error != null) {
this.owner.getProject(this.project_id, (error, project) => {
if (error) {
throw error
}
const folder = _.find(
@ -196,7 +187,7 @@ describe('RestoringFiles', function () {
let doc = _.find(folder.docs, doc => doc.name === 'foo2.tex')
doc = MockDocstoreApi.docs[this.project_id][doc._id]
expect(doc.lines).to.deep.equal(['hello world, this is foo-2.tex!'])
return done()
done()
})
})
})
@ -209,7 +200,7 @@ describe('RestoringFiles', function () {
'nothere/foo3.tex',
'hello world, this is foo-3.tex!'
)
return this.owner.request(
this.owner.request(
{
method: 'POST',
url: `/project/${this.project_id}/restore_file`,
@ -219,18 +210,18 @@ describe('RestoringFiles', function () {
},
},
(error, response, body) => {
if (error != null) {
if (error) {
throw error
}
expect(response.statusCode).to.equal(200)
return done()
done()
}
)
})
it('should have created the folder and restored the doc to it', function (done) {
return this.owner.getProject(this.project_id, (error, project) => {
if (error != null) {
this.owner.getProject(this.project_id, (error, project) => {
if (error) {
throw error
}
const folder = _.find(
@ -241,7 +232,7 @@ describe('RestoringFiles', function () {
let doc = _.find(folder.docs, doc => doc.name === 'foo3.tex')
doc = MockDocstoreApi.docs[this.project_id][doc._id]
expect(doc.lines).to.deep.equal(['hello world, this is foo-3.tex!'])
return done()
done()
})
})
})
@ -254,7 +245,7 @@ describe('RestoringFiles', function () {
'main.tex',
'hello world, this is main.tex!'
)
return this.owner.request(
this.owner.request(
{
method: 'POST',
url: `/project/${this.project_id}/restore_file`,
@ -264,18 +255,18 @@ describe('RestoringFiles', function () {
},
},
(error, response, body) => {
if (error != null) {
if (error) {
throw error
}
expect(response.statusCode).to.equal(200)
return done()
done()
}
)
})
it('should have created the doc in the root folder', function (done) {
return this.owner.getProject(this.project_id, (error, project) => {
if (error != null) {
this.owner.getProject(this.project_id, (error, project) => {
if (error) {
throw error
}
let doc = _.find(project.rootFolder[0].docs, doc =>
@ -284,7 +275,7 @@ describe('RestoringFiles', function () {
expect(doc).to.exist
doc = MockDocstoreApi.docs[this.project_id][doc._id]
expect(doc.lines).to.deep.equal(['hello world, this is main.tex!'])
return done()
done()
})
})
})