Merge pull request #21394 from overleaf/msm-esm-user-activation

[web] Migrate `modules/user-activate` to ESM

GitOrigin-RevId: e5ab3e9c53ea2d3f4ddfbc2200a889b8bb0db83c
This commit is contained in:
Miguel Serrano 2024-10-28 12:39:16 +01:00 committed by Copybot
parent 27c2e8b938
commit b290510faf
4 changed files with 30 additions and 28 deletions

View file

@ -1,9 +1,12 @@
const Path = require('path') import Path from 'node:path'
const UserGetter = require('../../../../app/src/Features/User/UserGetter') import { fileURLToPath } from 'node:url'
const UserRegistrationHandler = require('../../../../app/src/Features/User/UserRegistrationHandler') import UserGetter from '../../../../app/src/Features/User/UserGetter.js'
const ErrorController = require('../../../../app/src/Features/Errors/ErrorController') import UserRegistrationHandler from '../../../../app/src/Features/User/UserRegistrationHandler.js'
import ErrorController from '../../../../app/src/Features/Errors/ErrorController.js'
module.exports = { const __dirname = Path.dirname(fileURLToPath(import.meta.url))
export default {
registerNewUser(req, res, next) { registerNewUser(req, res, next) {
res.render(Path.resolve(__dirname, '../views/user/register')) res.render(Path.resolve(__dirname, '../views/user/register'))
}, },

View file

@ -1,9 +1,9 @@
const logger = require('@overleaf/logger') import logger from '@overleaf/logger'
const UserActivateController = require('./UserActivateController') import UserActivateController from './UserActivateController.mjs'
const AuthenticationController = require('../../../../app/src/Features/Authentication/AuthenticationController') import AuthenticationController from '../../../../app/src/Features/Authentication/AuthenticationController.js'
const AuthorizationMiddleware = require('../../../../app/src/Features/Authorization/AuthorizationMiddleware') import AuthorizationMiddleware from '../../../../app/src/Features/Authorization/AuthorizationMiddleware.js'
module.exports = { export default {
apply(webRouter) { apply(webRouter) {
logger.debug({}, 'Init UserActivate router') logger.debug({}, 'Init UserActivate router')

View file

@ -1,4 +1,4 @@
const UserActivateRouter = require('./app/src/UserActivateRouter') import UserActivateRouter from './app/src/UserActivateRouter.mjs'
/** /**
* @import { WebModule } from "../../types/web-module" * @import { WebModule } from "../../types/web-module"
@ -9,4 +9,4 @@ const UserActivateModule = {
router: UserActivateRouter, router: UserActivateRouter,
} }
module.exports = UserActivateModule export default UserActivateModule

View file

@ -1,15 +1,16 @@
const Path = require('path') import Path from 'node:path'
const SandboxedModule = require('sandboxed-module') import { fileURLToPath } from 'node:url'
const sinon = require('sinon') import { strict as esmock } from 'esmock'
import sinon from 'sinon'
const __dirname = Path.dirname(fileURLToPath(import.meta.url))
const MODULE_PATH = '../../../app/src/UserActivateController.mjs'
const MODULE_PATH = Path.join(
__dirname,
'../../../app/src/UserActivateController.js'
)
const VIEW_PATH = Path.join(__dirname, '../../../app/views/user/activate') const VIEW_PATH = Path.join(__dirname, '../../../app/views/user/activate')
describe('UserActivateController', function () { describe('UserActivateController', function () {
beforeEach(function () { beforeEach(async function () {
this.user = { this.user = {
_id: (this.user_id = 'kwjewkl'), _id: (this.user_id = 'kwjewkl'),
features: {}, features: {},
@ -19,14 +20,12 @@ describe('UserActivateController', function () {
this.UserGetter = { getUser: sinon.stub() } this.UserGetter = { getUser: sinon.stub() }
this.UserRegistrationHandler = {} this.UserRegistrationHandler = {}
this.ErrorController = { notFound: sinon.stub() } this.ErrorController = { notFound: sinon.stub() }
this.UserActivateController = SandboxedModule.require(MODULE_PATH, { this.UserActivateController = await esmock(MODULE_PATH, {
requires: { '../../../../../app/src/Features/User/UserGetter.js': this.UserGetter,
'../../../../app/src/Features/User/UserGetter': this.UserGetter, '../../../../../app/src/Features/User/UserRegistrationHandler.js':
'../../../../app/src/Features/User/UserRegistrationHandler':
this.UserRegistrationHandler, this.UserRegistrationHandler,
'../../../../app/src/Features/Errors/ErrorController': '../../../../../app/src/Features/Errors/ErrorController.js':
this.ErrorController, this.ErrorController,
},
}) })
this.req = { this.req = {
body: {}, body: {},