From ff4d42747a579d714b3f361ea381be400de4e658 Mon Sep 17 00:00:00 2001 From: Miguel Serrano Date: Tue, 15 Oct 2024 10:15:43 +0200 Subject: [PATCH] Merge pull request #21051 from overleaf/msm-esm-migration-history-v1 [web] Migrate `modules/history-v1` to ESM GitOrigin-RevId: db1f5485ea268a6a9f62efd3183e16920505bfda --- .../history-v1/{index.js => index.mjs} | 2 +- .../src/{HistoryTests.js => HistoryTests.mjs} | 71 +++++------- .../src/{LabelsTests.js => LabelsTests.mjs} | 50 ++++----- ...tureTests.js => ProjectStructureTests.mjs} | 22 ++-- ...ingFilesTest.js => RestoringFilesTest.mjs} | 105 ++++++++---------- 5 files changed, 108 insertions(+), 142 deletions(-) rename services/web/modules/history-v1/{index.js => index.mjs} (78%) rename services/web/modules/history-v1/test/acceptance/src/{HistoryTests.js => HistoryTests.mjs} (84%) rename services/web/modules/history-v1/test/acceptance/src/{LabelsTests.js => LabelsTests.mjs} (66%) rename services/web/modules/history-v1/test/acceptance/src/{ProjectStructureTests.js => ProjectStructureTests.mjs} (98%) rename services/web/modules/history-v1/test/acceptance/src/{RestoringFilesTest.js => RestoringFilesTest.mjs} (74%) diff --git a/services/web/modules/history-v1/index.js b/services/web/modules/history-v1/index.mjs similarity index 78% rename from services/web/modules/history-v1/index.js rename to services/web/modules/history-v1/index.mjs index 57a7963265..87dd319265 100644 --- a/services/web/modules/history-v1/index.js +++ b/services/web/modules/history-v1/index.mjs @@ -3,4 +3,4 @@ /** @type {WebModule} */ const HistoryModule = {} -module.exports = HistoryModule +export default HistoryModule diff --git a/services/web/modules/history-v1/test/acceptance/src/HistoryTests.js b/services/web/modules/history-v1/test/acceptance/src/HistoryTests.mjs similarity index 84% rename from services/web/modules/history-v1/test/acceptance/src/HistoryTests.js rename to services/web/modules/history-v1/test/acceptance/src/HistoryTests.mjs index 3682282306..88c2b1239d 100644 --- a/services/web/modules/history-v1/test/acceptance/src/HistoryTests.js +++ b/services/web/modules/history-v1/test/acceptance/src/HistoryTests.mjs @@ -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() } ) } diff --git a/services/web/modules/history-v1/test/acceptance/src/LabelsTests.js b/services/web/modules/history-v1/test/acceptance/src/LabelsTests.mjs similarity index 66% rename from services/web/modules/history-v1/test/acceptance/src/LabelsTests.js rename to services/web/modules/history-v1/test/acceptance/src/LabelsTests.mjs index ec62ff1e70..c197614cc0 100644 --- a/services/web/modules/history-v1/test/acceptance/src/LabelsTests.js +++ b/services/web/modules/history-v1/test/acceptance/src/LabelsTests.mjs @@ -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() } ) }) diff --git a/services/web/modules/history-v1/test/acceptance/src/ProjectStructureTests.js b/services/web/modules/history-v1/test/acceptance/src/ProjectStructureTests.mjs similarity index 98% rename from services/web/modules/history-v1/test/acceptance/src/ProjectStructureTests.js rename to services/web/modules/history-v1/test/acceptance/src/ProjectStructureTests.mjs index 5254c7becb..73be773da9 100644 --- a/services/web/modules/history-v1/test/acceptance/src/ProjectStructureTests.js +++ b/services/web/modules/history-v1/test/acceptance/src/ProjectStructureTests.mjs @@ -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 diff --git a/services/web/modules/history-v1/test/acceptance/src/RestoringFilesTest.js b/services/web/modules/history-v1/test/acceptance/src/RestoringFilesTest.mjs similarity index 74% rename from services/web/modules/history-v1/test/acceptance/src/RestoringFilesTest.js rename to services/web/modules/history-v1/test/acceptance/src/RestoringFilesTest.mjs index f2dbc0363d..76c699ce2b 100644 --- a/services/web/modules/history-v1/test/acceptance/src/RestoringFilesTest.js +++ b/services/web/modules/history-v1/test/acceptance/src/RestoringFilesTest.mjs @@ -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() }) }) })