mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-01 05:11:34 +02:00
Migrate Features to ES modules
GitOrigin-RevId: 4e9d3176b4b5a5504afc102e569a27d7788864a3
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
const path = require('path')
|
||||
const sinon = require('sinon')
|
||||
const { expect } = require('chai')
|
||||
const MockResponse = require('../helpers/MockResponse')
|
||||
import esmock from 'esmock'
|
||||
import path from 'node:path'
|
||||
import sinon from 'sinon'
|
||||
import { expect } from 'chai'
|
||||
import MockResponse from '../helpers/MockResponse.js'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
const __dirname = fileURLToPath(new URL('.', import.meta.url))
|
||||
|
||||
const modulePath = path.join(
|
||||
__dirname,
|
||||
@@ -10,7 +13,7 @@ const modulePath = path.join(
|
||||
)
|
||||
|
||||
describe('BetaProgramController', function () {
|
||||
beforeEach(function () {
|
||||
beforeEach(async function () {
|
||||
this.user = {
|
||||
_id: (this.user_id = 'a_simple_id'),
|
||||
email: 'user@example.com',
|
||||
@@ -28,28 +31,28 @@ describe('BetaProgramController', function () {
|
||||
sessionMaintenance: sinon.stub(),
|
||||
},
|
||||
}
|
||||
this.BetaProgramController = SandboxedModule.require(modulePath, {
|
||||
requires: {
|
||||
'../SplitTests/SplitTestSessionHandler': this.SplitTestSessionHandler,
|
||||
'./BetaProgramHandler': (this.BetaProgramHandler = {
|
||||
this.BetaProgramController = await esmock.strict(modulePath, {
|
||||
'../../../../app/src/Features/SplitTests/SplitTestSessionHandler':
|
||||
this.SplitTestSessionHandler,
|
||||
'../../../../app/src/Features/BetaProgram/BetaProgramHandler':
|
||||
(this.BetaProgramHandler = {
|
||||
promises: {
|
||||
optIn: sinon.stub().resolves(),
|
||||
optOut: sinon.stub().resolves(),
|
||||
},
|
||||
}),
|
||||
'../User/UserGetter': (this.UserGetter = {
|
||||
promises: {
|
||||
getUser: sinon.stub().resolves(),
|
||||
},
|
||||
'../../../../app/src/Features/User/UserGetter': (this.UserGetter = {
|
||||
promises: {
|
||||
getUser: sinon.stub().resolves(),
|
||||
},
|
||||
}),
|
||||
'@overleaf/settings': (this.settings = {
|
||||
languages: {},
|
||||
}),
|
||||
'../../../../app/src/Features/Authentication/AuthenticationController':
|
||||
(this.AuthenticationController = {
|
||||
getLoggedInUserId: sinon.stub().returns(this.user._id),
|
||||
}),
|
||||
'@overleaf/settings': (this.settings = {
|
||||
languages: {},
|
||||
}),
|
||||
'../Authentication/AuthenticationController':
|
||||
(this.AuthenticationController = {
|
||||
getLoggedInUserId: sinon.stub().returns(this.user._id),
|
||||
}),
|
||||
},
|
||||
})
|
||||
this.res = new MockResponse()
|
||||
this.next = sinon.stub()
|
||||
@@ -1,14 +1,19 @@
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
const path = require('path')
|
||||
import esmock from 'esmock'
|
||||
import path from 'node:path'
|
||||
|
||||
import sinon from 'sinon'
|
||||
import { expect } from 'chai'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
const __dirname = fileURLToPath(new URL('.', import.meta.url))
|
||||
|
||||
const modulePath = path.join(
|
||||
__dirname,
|
||||
'../../../../app/src/Features/BetaProgram/BetaProgramHandler'
|
||||
)
|
||||
const sinon = require('sinon')
|
||||
const { expect } = require('chai')
|
||||
|
||||
describe('BetaProgramHandler', function () {
|
||||
beforeEach(function () {
|
||||
beforeEach(async function () {
|
||||
this.user_id = 'some_id'
|
||||
this.user = {
|
||||
_id: this.user_id,
|
||||
@@ -17,20 +22,19 @@ describe('BetaProgramHandler', function () {
|
||||
betaProgram: false,
|
||||
save: sinon.stub().callsArgWith(0, null),
|
||||
}
|
||||
this.handler = SandboxedModule.require(modulePath, {
|
||||
requires: {
|
||||
'@overleaf/metrics': {
|
||||
inc: sinon.stub(),
|
||||
this.handler = await esmock.strict(modulePath, {
|
||||
'@overleaf/metrics': {
|
||||
inc: sinon.stub(),
|
||||
},
|
||||
'../../../../app/src/Features/User/UserUpdater': (this.UserUpdater = {
|
||||
promises: {
|
||||
updateUser: sinon.stub().resolves(),
|
||||
},
|
||||
'../User/UserUpdater': (this.UserUpdater = {
|
||||
promises: {
|
||||
updateUser: sinon.stub().resolves(),
|
||||
},
|
||||
}),
|
||||
'../Analytics/AnalyticsManager': (this.AnalyticsManager = {
|
||||
}),
|
||||
'../../../../app/src/Features/Analytics/AnalyticsManager':
|
||||
(this.AnalyticsManager = {
|
||||
setUserPropertyForUserInBackground: sinon.stub(),
|
||||
}),
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user