Update tests

GitOrigin-RevId: 9272720e0f6865c54257c43bd98d8e6003251aa2
This commit is contained in:
Andrew Rumble 2024-10-10 13:05:04 +01:00 committed by Copybot
parent 9490251251
commit 2bfb55a305
39 changed files with 868 additions and 827 deletions

View file

@ -1,14 +1,13 @@
const SandboxedModule = require('sandboxed-module') import esmock from 'esmock'
const path = require('path') import sinon from 'sinon'
const modulePath = path.join( import MockResponse from '../helpers/MockResponse.js'
__dirname, const modulePath = new URL(
'../../../../app/src/Features/Analytics/AnalyticsController' '../../../../app/src/Features/Analytics/AnalyticsController.mjs',
) import.meta.url
const sinon = require('sinon') ).pathname
const MockResponse = require('../helpers/MockResponse')
describe('AnalyticsController', function () { describe('AnalyticsController', function () {
beforeEach(function () { beforeEach(async function () {
this.SessionManager = { getLoggedInUserId: sinon.stub() } this.SessionManager = { getLoggedInUserId: sinon.stub() }
this.AnalyticsManager = { this.AnalyticsManager = {
@ -20,17 +19,17 @@ describe('AnalyticsController', function () {
hasFeature: sinon.stub().returns(true), hasFeature: sinon.stub().returns(true),
} }
this.controller = SandboxedModule.require(modulePath, { this.controller = await esmock.strict(modulePath, {
requires: { '../../../../app/src/Features/Analytics/AnalyticsManager.js':
'./AnalyticsManager': this.AnalyticsManager, this.AnalyticsManager,
'../Authentication/SessionManager': this.SessionManager, '../../../../app/src/Features/Authentication/SessionManager.js':
'../../infrastructure/Features': this.Features, this.SessionManager,
'../../infrastructure/GeoIpLookup': (this.GeoIpLookup = { '../../../../app/src/infrastructure/Features.js': this.Features,
promises: { '../../../../app/src/infrastructure/GeoIpLookup.js': (this.GeoIpLookup = {
getDetails: sinon.stub().resolves(), promises: {
}, getDetails: sinon.stub().resolves(),
}), },
}, }),
}) })
this.res = new MockResponse() this.res = new MockResponse()

View file

@ -1,17 +1,16 @@
const SandboxedModule = require('sandboxed-module') import esmock from 'esmock'
const path = require('path') import sinon from 'sinon'
const sinon = require('sinon') import MockRequest from '../helpers/MockRequest.js'
const MockRequest = require('../helpers/MockRequest') import MockResponse from '../helpers/MockResponse.js'
const MockResponse = require('../helpers/MockResponse') import { assert } from 'chai'
const { assert } = require('chai')
const MODULE_PATH = path.join( const MODULE_PATH = new URL(
__dirname, '../../../../app/src/Features/Analytics/AnalyticsUTMTrackingMiddleware',
'../../../../app/src/Features/Analytics/AnalyticsUTMTrackingMiddleware' import.meta.url
) ).pathname
describe('AnalyticsUTMTrackingMiddleware', function () { describe('AnalyticsUTMTrackingMiddleware', function () {
beforeEach(function () { beforeEach(async function () {
this.analyticsId = 'ecdb935a-52f3-4f91-aebc-7a70d2ffbb55' this.analyticsId = 'ecdb935a-52f3-4f91-aebc-7a70d2ffbb55'
this.userId = '61795fcb013504bb7b663092' this.userId = '61795fcb013504bb7b663092'
@ -25,15 +24,14 @@ describe('AnalyticsUTMTrackingMiddleware', function () {
}, },
} }
this.AnalyticsUTMTrackingMiddleware = SandboxedModule.require(MODULE_PATH, { this.AnalyticsUTMTrackingMiddleware = await esmock.strict(MODULE_PATH, {
requires: { '../../../../app/src/Features/Analytics/AnalyticsManager.js':
'./AnalyticsManager': (this.AnalyticsManager = { (this.AnalyticsManager = {
recordEventForSession: sinon.stub().resolves(), recordEventForSession: sinon.stub().resolves(),
setUserPropertyForSessionInBackground: sinon.stub(), setUserPropertyForSessionInBackground: sinon.stub(),
}), }),
'@overleaf/settings': { '@overleaf/settings': {
siteUrl: 'https://www.overleaf.com', siteUrl: 'https://www.overleaf.com',
},
}, },
}) })

View file

@ -1,16 +1,18 @@
const sinon = require('sinon') import sinon from 'sinon'
const { expect } = require('chai') import { expect } from 'chai'
const SandboxedModule = require('sandboxed-module') import esmock from 'esmock'
const { ObjectId } = require('mongodb-legacy') import mongodb from 'mongodb-legacy'
const Errors = require('../../../../app/src/Features/Errors/Errors') import Errors from '../../../../app/src/Features/Errors/Errors.js'
const MockRequest = require('../helpers/MockRequest') import MockRequest from '../helpers/MockRequest.js'
const MockResponse = require('../helpers/MockResponse') import MockResponse from '../helpers/MockResponse.js'
const ObjectId = mongodb.ObjectId
const MODULE_PATH = const MODULE_PATH =
'../../../../app/src/Features/Collaborators/CollaboratorsController.js' '../../../../app/src/Features/Collaborators/CollaboratorsController.mjs'
describe('CollaboratorsController', function () { describe('CollaboratorsController', function () {
beforeEach(function () { beforeEach(async function () {
this.res = new MockResponse() this.res = new MockResponse()
this.req = new MockRequest() this.req = new MockRequest()
@ -77,22 +79,31 @@ describe('CollaboratorsController', function () {
}, },
} }
this.CollaboratorsController = SandboxedModule.require(MODULE_PATH, { this.CollaboratorsController = await esmock.strict(MODULE_PATH, {
requires: { 'mongodb-legacy': { ObjectId },
'mongodb-legacy': { ObjectId }, '../../../../app/src/Features/Collaborators/CollaboratorsHandler.js':
'./CollaboratorsHandler': this.CollaboratorsHandler, this.CollaboratorsHandler,
'./CollaboratorsGetter': this.CollaboratorsGetter, '../../../../app/src/Features/Collaborators/CollaboratorsGetter.js':
'./OwnershipTransferHandler': this.OwnershipTransferHandler, this.CollaboratorsGetter,
'../Editor/EditorRealTimeController': this.EditorRealTimeController, '../../../../app/src/Features/Collaborators/OwnershipTransferHandler.js':
'../../Features/Errors/HttpErrorHandler': this.HttpErrorHandler, this.OwnershipTransferHandler,
'../Tags/TagsHandler': this.TagsHandler, '../../../../app/src/Features/Editor/EditorRealTimeController':
'../Authentication/SessionManager': this.SessionManager, this.EditorRealTimeController,
'../TokenAccess/TokenAccessHandler': this.TokenAccessHandler, '../../../../app/src/Features/Errors/HttpErrorHandler.js':
'../Project/ProjectAuditLogHandler': this.ProjectAuditLogHandler, this.HttpErrorHandler,
'../Project/ProjectGetter': this.ProjectGetter, '../../../../app/src/Features/Tags/TagsHandler.js': this.TagsHandler,
'../SplitTests/SplitTestHandler': this.SplitTestHandler, '../../../../app/src/Features/Authentication/SessionManager.js':
'../Subscription/LimitationsManager': this.LimitationsManager, this.SessionManager,
}, '../../../../app/src/Features/TokenAccess/TokenAccessHandler.js':
this.TokenAccessHandler,
'../../../../app/src/Features/Project/ProjectAuditLogHandler.js':
this.ProjectAuditLogHandler,
'../../../../app/src/Features/Project/ProjectGetter.js':
this.ProjectGetter,
'../../../../app/src/Features/SplitTests/SplitTestHandler.js':
this.SplitTestHandler,
'../../../../app/src/Features/Subscription/LimitationsManager.js':
this.LimitationsManager,
}) })
}) })

View file

@ -1,17 +1,19 @@
const sinon = require('sinon') import sinon from 'sinon'
const { expect } = require('chai') import { expect } from 'chai'
const SandboxedModule = require('sandboxed-module') import esmock from 'esmock'
const MockRequest = require('../helpers/MockRequest') import MockRequest from '../helpers/MockRequest.js'
const MockResponse = require('../helpers/MockResponse') import MockResponse from '../helpers/MockResponse.js'
const { ObjectId } = require('mongodb-legacy') import mongodb from 'mongodb-legacy'
const Errors = require('../../../../app/src/Features/Errors/Errors') import Errors from '../../../../app/src/Features/Errors/Errors.js'
const _ = require('lodash') import _ from 'lodash'
const ObjectId = mongodb.ObjectId
const MODULE_PATH = const MODULE_PATH =
'../../../../app/src/Features/Collaborators/CollaboratorsInviteController.js' '../../../../app/src/Features/Collaborators/CollaboratorsInviteController.mjs'
describe('CollaboratorsInviteController', function () { describe('CollaboratorsInviteController', function () {
beforeEach(function () { beforeEach(async function () {
this.projectId = 'project-id-123' this.projectId = 'project-id-123'
this.token = 'some-opaque-token' this.token = 'some-opaque-token'
this.tokenHmac = 'some-hmac-token' this.tokenHmac = 'some-hmac-token'
@ -120,24 +122,32 @@ describe('CollaboratorsInviteController', function () {
}, },
} }
this.CollaboratorsInviteController = SandboxedModule.require(MODULE_PATH, { this.CollaboratorsInviteController = await esmock.strict(MODULE_PATH, {
requires: { '../../../../app/src/Features/Project/ProjectGetter.js':
'../Project/ProjectGetter': this.ProjectGetter, this.ProjectGetter,
'../Project/ProjectAuditLogHandler': this.ProjectAuditLogHandler, '../../../../app/src/Features/Project/ProjectAuditLogHandler.js':
'../Subscription/LimitationsManager': this.LimitationsManager, this.ProjectAuditLogHandler,
'../User/UserGetter': this.UserGetter, '../../../../app/src/Features/Subscription/LimitationsManager.js':
'./CollaboratorsGetter': this.CollaboratorsGetter, this.LimitationsManager,
'./CollaboratorsInviteHandler': this.CollaboratorsInviteHandler, '../../../../app/src/Features/User/UserGetter.js': this.UserGetter,
'./CollaboratorsInviteGetter': this.CollaboratorsInviteGetter, '../../../../app/src/Features/Collaborators/CollaboratorsGetter.js':
'../Editor/EditorRealTimeController': this.EditorRealTimeController, this.CollaboratorsGetter,
'../Analytics/AnalyticsManager': this.AnalyticsManger, '../../../../app/src/Features/Collaborators/CollaboratorsInviteHandler.mjs':
'../Authentication/SessionManager': this.SessionManager, this.CollaboratorsInviteHandler,
'@overleaf/settings': this.settings, '../../../../app/src/Features/Collaborators/CollaboratorsInviteGetter.js':
'../../infrastructure/RateLimiter': this.RateLimiter, this.CollaboratorsInviteGetter,
'../Authentication/AuthenticationController': '../../../../app/src/Features/Editor/EditorRealTimeController.js':
this.AuthenticationController, this.EditorRealTimeController,
'../SplitTests/SplitTestHandler': this.SplitTestHandler, '../../../../app/src/Features/Analytics/AnalyticsManager.js':
}, this.AnalyticsManger,
'../../../../app/src/Features/Authentication/SessionManager.js':
this.SessionManager,
'@overleaf/settings': this.settings,
'../../../../app/src/infrastructure/RateLimiter': this.RateLimiter,
'../../../../app/src/Features/Authentication/AuthenticationController':
this.AuthenticationController,
'../../../../app/src/Features/SplitTests/SplitTestHandler':
this.SplitTestHandler,
}) })
this.res = new MockResponse() this.res = new MockResponse()

View file

@ -1,14 +1,16 @@
const sinon = require('sinon') import sinon from 'sinon'
const { expect } = require('chai') import { expect } from 'chai'
const SandboxedModule = require('sandboxed-module') import esmock from 'esmock'
const { ObjectId } = require('mongodb-legacy') import mongodb from 'mongodb-legacy'
const Crypto = require('crypto') import Crypto from 'crypto'
const ObjectId = mongodb.ObjectId
const MODULE_PATH = const MODULE_PATH =
'../../../../app/src/Features/Collaborators/CollaboratorsInviteHandler.js' '../../../../app/src/Features/Collaborators/CollaboratorsInviteHandler.mjs'
describe('CollaboratorsInviteHandler', function () { describe('CollaboratorsInviteHandler', function () {
beforeEach(function () { beforeEach(async function () {
this.ProjectInvite = class ProjectInvite { this.ProjectInvite = class ProjectInvite {
constructor(options) { constructor(options) {
if (options == null) { if (options == null) {
@ -72,22 +74,31 @@ describe('CollaboratorsInviteHandler', function () {
addEntryInBackground: sinon.stub(), addEntryInBackground: sinon.stub(),
} }
this.CollaboratorsInviteHandler = SandboxedModule.require(MODULE_PATH, { this.CollaboratorsInviteHandler = await esmock.strict(MODULE_PATH, {
requires: { '@overleaf/settings': this.settings,
'@overleaf/settings': this.settings, '../../../../app/src/models/ProjectInvite.js': {
'../../models/ProjectInvite': { ProjectInvite: this.ProjectInvite }, ProjectInvite: this.ProjectInvite,
'./CollaboratorsEmailHandler': this.CollaboratorsEmailHandler,
'./CollaboratorsHandler': this.CollaboratorsHandler,
'../User/UserGetter': this.UserGetter,
'../Project/ProjectGetter': this.ProjectGetter,
'../Notifications/NotificationsBuilder': this.NotificationsBuilder,
'./CollaboratorsInviteHelper': this.CollaboratorsInviteHelper,
'./CollaboratorsInviteGetter': this.CollaboratorsInviteGetter,
'../SplitTests/SplitTestHandler': this.SplitTestHandler,
'../Subscription/LimitationsManager': this.LimitationsManager,
'../Project/ProjectAuditLogHandler': this.ProjectAuditLogHandler,
crypto: this.CryptogetAssignmentForUser,
}, },
'../../../../app/src/Features/Collaborators/CollaboratorsEmailHandler.mjs':
this.CollaboratorsEmailHandler,
'../../../../app/src/Features/Collaborators/CollaboratorsHandler.js':
this.CollaboratorsHandler,
'../../../../app/src/Features/User/UserGetter.js': this.UserGetter,
'../../../../app/src/Features/Project/ProjectGetter.js':
this.ProjectGetter,
'../../../../app/src/Features/Notifications/NotificationsBuilder.js':
this.NotificationsBuilder,
'../../../../app/src/Features/Collaborators/CollaboratorsInviteHelper.js':
this.CollaboratorsInviteHelper,
'../../../../app/src/Features/Collaborators/CollaboratorsInviteGetter':
this.CollaboratorsInviteGetter,
'../../../../app/src/Features/SplitTests/SplitTestHandler.js':
this.SplitTestHandler,
'../../../../app/src/Features/Subscription/LimitationsManager.js':
this.LimitationsManager,
'../../../../app/src/Features/Project/ProjectAuditLogHandler.js':
this.ProjectAuditLogHandler,
crypto: this.CryptogetAssignmentForUser,
}) })
this.projectId = new ObjectId() this.projectId = new ObjectId()

View file

@ -1,21 +1,23 @@
const sinon = require('sinon') import sinon from 'sinon'
const { expect } = require('chai') import { expect } from 'chai'
const modulePath = '../../../../app/src/Features/Contacts/ContactController.js' import esmock from 'esmock'
const SandboxedModule = require('sandboxed-module') import MockResponse from '../helpers/MockResponse.js'
const MockResponse = require('../helpers/MockResponse') const modulePath = '../../../../app/src/Features/Contacts/ContactController.mjs'
describe('ContactController', function () { describe('ContactController', function () {
beforeEach(function () { beforeEach(async function () {
this.SessionManager = { getLoggedInUserId: sinon.stub() } this.SessionManager = { getLoggedInUserId: sinon.stub() }
this.ContactController = SandboxedModule.require(modulePath, { this.ContactController = await esmock.strict(modulePath, {
requires: { '../../../../app/src/Features/User/UserGetter': (this.UserGetter = {
'../User/UserGetter': (this.UserGetter = { promises: {} }), promises: {},
'./ContactManager': (this.ContactManager = { promises: {} }), }),
'../Authentication/SessionManager': (this.SessionManager = {}), '../../../../app/src/Features/Contacts/ContactManager':
'../../infrastructure/Modules': (this.Modules = { (this.ContactManager = { promises: {} }),
promises: { hooks: {} }, '../../../../app/src/Features/Authentication/SessionManager':
}), (this.SessionManager = {}),
}, '../../../../app/src/infrastructure/Modules': (this.Modules = {
promises: { hooks: {} },
}),
}) })
this.req = {} this.req = {}

View file

@ -9,21 +9,20 @@
* DS102: Remove unnecessary code created because of implicit returns * DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/ */
const SandboxedModule = require('sandboxed-module') import esmock from 'esmock'
const sinon = require('sinon') import sinon from 'sinon'
const { expect } = require('chai') import { expect } from 'chai'
const modulePath = require('path').join( const modulePath = new URL(
__dirname, '../../../../app/src/Features/Cooldown/CooldownMiddleware.mjs',
'../../../../app/src/Features/Cooldown/CooldownMiddleware' import.meta.url
) ).pathname
describe('CooldownMiddleware', function () { describe('CooldownMiddleware', function () {
beforeEach(function () { beforeEach(async function () {
this.CooldownManager = { isProjectOnCooldown: sinon.stub() } this.CooldownManager = { isProjectOnCooldown: sinon.stub() }
return (this.CooldownMiddleware = SandboxedModule.require(modulePath, { return (this.CooldownMiddleware = await esmock.strict(modulePath, {
requires: { '../../../../app/src/Features/Cooldown/CooldownManager.js':
'./CooldownManager': this.CooldownManager, this.CooldownManager,
},
})) }))
}) })

View file

@ -1,13 +1,13 @@
const sinon = require('sinon') import sinon from 'sinon'
const { expect } = require('chai') import { expect } from 'chai'
const SandboxedModule = require('sandboxed-module') import esmock from 'esmock'
const MockResponse = require('../helpers/MockResponse') import MockResponse from '../helpers/MockResponse.js'
const MODULE_PATH = const MODULE_PATH =
'../../../../app/src/Features/DocumentUpdater/DocumentUpdaterController.js' '../../../../app/src/Features/DocumentUpdater/DocumentUpdaterController.mjs'
describe('DocumentUpdaterController', function () { describe('DocumentUpdaterController', function () {
beforeEach(function () { beforeEach(async function () {
this.DocumentUpdaterHandler = { this.DocumentUpdaterHandler = {
promises: { promises: {
getDocument: sinon.stub(), getDocument: sinon.stub(),
@ -18,12 +18,12 @@ describe('DocumentUpdaterController', function () {
findElement: sinon.stub(), findElement: sinon.stub(),
}, },
} }
this.controller = SandboxedModule.require(MODULE_PATH, { this.controller = await esmock.strict(MODULE_PATH, {
requires: { '@overleaf/settings': this.settings,
'@overleaf/settings': this.settings, '../../../../app/src/Features/Project/ProjectLocator.js':
'../Project/ProjectLocator': this.ProjectLocator, this.ProjectLocator,
'./DocumentUpdaterHandler': this.DocumentUpdaterHandler, '../../../../app/src/Features/DocumentUpdater/DocumentUpdaterHandler.js':
}, this.DocumentUpdaterHandler,
}) })
this.projectId = '2k3j1lk3j21lk3j' this.projectId = '2k3j1lk3j21lk3j'
this.fileId = '12321kklj1lk3jk12' this.fileId = '12321kklj1lk3jk12'

View file

@ -1,14 +1,14 @@
const sinon = require('sinon') import sinon from 'sinon'
const SandboxedModule = require('sandboxed-module') import esmock from 'esmock'
const MockRequest = require('../helpers/MockRequest') import MockRequest from '../helpers/MockRequest.js'
const MockResponse = require('../helpers/MockResponse') import MockResponse from '../helpers/MockResponse.js'
const Errors = require('../../../../app/src/Features/Errors/Errors') import Errors from '../../../../app/src/Features/Errors/Errors.js'
const MODULE_PATH = const MODULE_PATH =
'../../../../app/src/Features/Documents/DocumentController.js' '../../../../app/src/Features/Documents/DocumentController.mjs'
describe('DocumentController', function () { describe('DocumentController', function () {
beforeEach(function () { beforeEach(async function () {
this.res = new MockResponse() this.res = new MockResponse()
this.req = new MockRequest() this.req = new MockRequest()
this.next = sinon.stub() this.next = sinon.stub()
@ -87,15 +87,15 @@ describe('DocumentController', function () {
}, },
} }
this.DocumentController = SandboxedModule.require(MODULE_PATH, { this.DocumentController = await esmock.strict(MODULE_PATH, {
requires: { '../../../../app/src/Features/Project/ProjectGetter': this.ProjectGetter,
'../Project/ProjectGetter': this.ProjectGetter, '../../../../app/src/Features/Project/ProjectLocator':
'../Project/ProjectLocator': this.ProjectLocator, this.ProjectLocator,
'../Project/ProjectEntityHandler': this.ProjectEntityHandler, '../../../../app/src/Features/Project/ProjectEntityHandler':
'../Project/ProjectEntityUpdateHandler': this.ProjectEntityHandler,
this.ProjectEntityUpdateHandler, '../../../../app/src/Features/Project/ProjectEntityUpdateHandler':
'../Chat/ChatApiHandler': this.ChatApiHandler, this.ProjectEntityUpdateHandler,
}, '../../../../app/src/Features/Chat/ChatApiHandler': this.ChatApiHandler,
}) })
}) })

View file

@ -1,8 +1,3 @@
/* eslint-disable
max-len,
no-return-assign,
no-unused-vars,
*/
// TODO: This file was created by bulk-decaffeinate. // TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint. // Fix any style issues and re-enable lint.
/* /*
@ -10,33 +5,29 @@
* DS102: Remove unnecessary code created because of implicit returns * DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/ */
const sinon = require('sinon') import sinon from 'sinon'
const { expect } = require('chai') import esmock from 'esmock'
import MockRequest from '../helpers/MockRequest.js'
import MockResponse from '../helpers/MockResponse.js'
const modulePath = const modulePath =
'../../../../app/src/Features/Downloads/ProjectDownloadsController.js' '../../../../app/src/Features/Downloads/ProjectDownloadsController.mjs'
const SandboxedModule = require('sandboxed-module')
const MockRequest = require('../helpers/MockRequest')
const MockResponse = require('../helpers/MockResponse')
describe('ProjectDownloadsController', function () { describe('ProjectDownloadsController', function () {
beforeEach(function () { beforeEach(async function () {
this.project_id = 'project-id-123' this.project_id = 'project-id-123'
this.req = new MockRequest() this.req = new MockRequest()
this.res = new MockResponse() this.res = new MockResponse()
this.next = sinon.stub() this.next = sinon.stub()
this.DocumentUpdaterHandler = sinon.stub() this.DocumentUpdaterHandler = sinon.stub()
return (this.ProjectDownloadsController = SandboxedModule.require( return (this.ProjectDownloadsController = await esmock.strict(modulePath, {
modulePath, '../../../../app/src/Features/Downloads/ProjectZipStreamManager.mjs':
{ (this.ProjectZipStreamManager = {}),
requires: { '../../../../app/src/Features/Project/ProjectGetter.js':
'./ProjectZipStreamManager': (this.ProjectZipStreamManager = {}), (this.ProjectGetter = {}),
'../Project/ProjectGetter': (this.ProjectGetter = {}), '@overleaf/metrics': (this.metrics = {}),
'@overleaf/metrics': (this.metrics = {}), '../../../../app/src/Features/DocumentUpdater/DocumentUpdaterHandler.js':
'../DocumentUpdater/DocumentUpdaterHandler': this.DocumentUpdaterHandler,
this.DocumentUpdaterHandler, }))
},
}
))
}) })
describe('downloadProject', function () { describe('downloadProject', function () {

View file

@ -1,9 +1,3 @@
/* eslint-disable
max-len,
no-return-assign,
no-unused-vars,
one-var,
*/
// TODO: This file was created by bulk-decaffeinate. // TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint. // Fix any style issues and re-enable lint.
/* /*
@ -14,28 +8,34 @@
* DS205: Consider reworking code to avoid use of IIFEs * DS205: Consider reworking code to avoid use of IIFEs
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/ */
const sinon = require('sinon') import sinon from 'sinon'
const { expect } = require('chai') import esmock from 'esmock'
import { EventEmitter } from 'events'
const modulePath = const modulePath =
'../../../../app/src/Features/Downloads/ProjectZipStreamManager.js' '../../../../app/src/Features/Downloads/ProjectZipStreamManager.mjs'
const SandboxedModule = require('sandboxed-module')
const { EventEmitter } = require('events')
describe('ProjectZipStreamManager', function () { describe('ProjectZipStreamManager', function () {
beforeEach(function () { beforeEach(async function () {
this.project_id = 'project-id-123' this.project_id = 'project-id-123'
this.callback = sinon.stub() this.callback = sinon.stub()
this.archive = { this.archive = {
on() {}, on() {},
append: sinon.stub(), append: sinon.stub(),
} }
return (this.ProjectZipStreamManager = SandboxedModule.require(modulePath, { this.logger = {
requires: { error: sinon.stub(),
archiver: (this.archiver = sinon.stub().returns(this.archive)), info: sinon.stub(),
'../Project/ProjectEntityHandler': (this.ProjectEntityHandler = {}), debug: sinon.stub(),
'../FileStore/FileStoreHandler': (this.FileStoreHandler = {}), }
'../Project/ProjectGetter': (this.ProjectGetter = {}), return (this.ProjectZipStreamManager = await esmock.strict(modulePath, {
}, archiver: (this.archiver = sinon.stub().returns(this.archive)),
'@overleaf/logger': this.logger,
'../../../../app/src/Features/Project/ProjectEntityHandler':
(this.ProjectEntityHandler = {}),
'../../../../app/src/Features/FileStore/FileStoreHandler':
(this.FileStoreHandler = {}),
'../../../../app/src/Features/Project/ProjectGetter':
(this.ProjectGetter = {}),
})) }))
}) })
@ -254,7 +254,7 @@ describe('ProjectZipStreamManager', function () {
.stub() .stub()
.callsArg(2) .callsArg(2)
this.archive.finalize = sinon.stub() this.archive.finalize = sinon.stub()
return this.ProjectZipStreamManager.createZipStreamForProject( this.ProjectZipStreamManager.createZipStreamForProject(
this.project_id, this.project_id,
this.callback this.callback
) )
@ -379,8 +379,7 @@ describe('ProjectZipStreamManager', function () {
.stub() .stub()
.callsArgWith(1, null, this.files) .callsArgWith(1, null, this.files)
this.FileStoreHandler.getFileStream = (projectId, fileId, ...rest) => { this.FileStoreHandler.getFileStream = (projectId, fileId, ...rest) => {
const obj = rest[0], const [, callback] = rest
callback = rest[1]
return callback(null, this.streams[fileId]) return callback(null, this.streams[fileId])
} }
sinon.spy(this.FileStoreHandler, 'getFileStream') sinon.spy(this.FileStoreHandler, 'getFileStream')

View file

@ -1,9 +1,3 @@
/* eslint-disable
max-len,
no-return-assign,
no-unused-vars,
no-useless-escape,
*/
// TODO: This file was created by bulk-decaffeinate. // TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint. // Fix any style issues and re-enable lint.
/* /*
@ -11,14 +5,13 @@
* DS102: Remove unnecessary code created because of implicit returns * DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/ */
const SandboxedModule = require('sandboxed-module') import esmock from 'esmock'
const assert = require('assert') import { expect } from 'chai'
const { expect } = require('chai') import sinon from 'sinon'
const sinon = require('sinon') const modulePath = new URL(
const modulePath = require('path').join( '../../../../app/src/Features/Exports/ExportsController.mjs',
__dirname, import.meta.url
'../../../../app/src/Features/Exports/ExportsController.js' ).pathname
)
describe('ExportsController', function () { describe('ExportsController', function () {
const projectId = '123njdskj9jlk' const projectId = '123njdskj9jlk'
@ -32,7 +25,7 @@ describe('ExportsController', function () {
const license = 'other' const license = 'other'
const showSource = true const showSource = true
beforeEach(function () { beforeEach(async function () {
this.handler = { getUserNotifications: sinon.stub().callsArgWith(1) } this.handler = { getUserNotifications: sinon.stub().callsArgWith(1) }
this.req = { this.req = {
params: { params: {
@ -61,12 +54,10 @@ describe('ExportsController', function () {
this.AuthenticationController = { this.AuthenticationController = {
getLoggedInUserId: sinon.stub().returns(this.req.session.user._id), getLoggedInUserId: sinon.stub().returns(this.req.session.user._id),
} }
return (this.controller = SandboxedModule.require(modulePath, { return (this.controller = await esmock.strict(modulePath, {
requires: { '../../../../app/src/Features/Exports/ExportsHandler.mjs': this.handler,
'./ExportsHandler': this.handler, '../../../../app/src/Features/Authentication/AuthenticationController.js':
'../Authentication/AuthenticationController': this.AuthenticationController,
this.AuthenticationController,
},
})) }))
}) })
@ -170,16 +161,16 @@ describe('ExportsController', function () {
it('should ask the handler to return the status of an export', function (done) { it('should ask the handler to return the status of an export', function (done) {
this.handler.fetchExport = sinon.stub().yields( this.handler.fetchExport = sinon.stub().yields(
null, null,
`{ \ `{
\"id\":897, \ "id":897,
\"status_summary\":\"completed\", \ "status_summary":"completed",
\"status_detail\":\"all done\", \ "status_detail":"all done",
\"partner_submission_id\":\"abc123\", \ "partner_submission_id":"abc123",
\"v2_user_email\":\"la@tex.com\", \ "v2_user_email":"la@tex.com",
\"v2_user_first_name\":\"Arthur\", \ "v2_user_first_name":"Arthur",
\"v2_user_last_name\":\"Author\", \ "v2_user_last_name":"Author",
\"title\":\"my project\", \ "title":"my project",
\"token\":\"token\" \ "token":"token"
}` }`
) )

View file

@ -1,8 +1,3 @@
/* eslint-disable
max-len,
no-return-assign,
no-unused-vars,
*/
// TODO: This file was created by bulk-decaffeinate. // TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint. // Fix any style issues and re-enable lint.
/* /*
@ -10,29 +5,31 @@
* DS102: Remove unnecessary code created because of implicit returns * DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/ */
const sinon = require('sinon') import sinon from 'sinon'
const { expect } = require('chai') import esmock from 'esmock'
const modulePath = '../../../../app/src/Features/Exports/ExportsHandler.js' import { expect } from 'chai'
const SandboxedModule = require('sandboxed-module') const modulePath = '../../../../app/src/Features/Exports/ExportsHandler.mjs'
describe('ExportsHandler', function () { describe('ExportsHandler', function () {
beforeEach(function () { beforeEach(async function () {
this.stubRequest = {} this.stubRequest = {}
this.request = { this.request = {
defaults: () => { defaults: () => {
return this.stubRequest return this.stubRequest
}, },
} }
this.ExportsHandler = SandboxedModule.require(modulePath, { this.ExportsHandler = await esmock.strict(modulePath, {
requires: { '../../../../app/src/Features/Project/ProjectGetter':
'../Project/ProjectGetter': (this.ProjectGetter = {}), (this.ProjectGetter = {}),
'../Project/ProjectHistoryHandler': (this.ProjectHistoryHandler = {}), '../../../../app/src/Features/Project/ProjectHistoryHandler':
'../Project/ProjectLocator': (this.ProjectLocator = {}), (this.ProjectHistoryHandler = {}),
'../Project/ProjectRootDocManager': (this.ProjectRootDocManager = {}), '../../../../app/src/Features/Project/ProjectLocator':
'../User/UserGetter': (this.UserGetter = {}), (this.ProjectLocator = {}),
'@overleaf/settings': (this.settings = {}), '../../../../app/src/Features/Project/ProjectRootDocManager':
request: this.request, (this.ProjectRootDocManager = {}),
}, '../../../../app/src/Features/User/UserGetter': (this.UserGetter = {}),
'@overleaf/settings': (this.settings = {}),
request: this.request,
}) })
this.project_id = 'project-id-123' this.project_id = 'project-id-123'
this.project_history_id = 987 this.project_history_id = 987

View file

@ -1,29 +1,29 @@
const { expect } = require('chai') import { expect } from 'chai'
const sinon = require('sinon') import sinon from 'sinon'
const SandboxedModule = require('sandboxed-module') import esmock from 'esmock'
const Errors = require('../../../../app/src/Features/Errors/Errors') import Errors from '../../../../app/src/Features/Errors/Errors.js'
const MockResponse = require('../helpers/MockResponse') import MockResponse from '../helpers/MockResponse.js'
const MODULE_PATH = const MODULE_PATH =
'../../../../app/src/Features/FileStore/FileStoreController.js' '../../../../app/src/Features/FileStore/FileStoreController.mjs'
const expectedFileHeaders = { const expectedFileHeaders = {
'Cache-Control': 'private, max-age=3600', 'Cache-Control': 'private, max-age=3600',
} }
describe('FileStoreController', function () { describe('FileStoreController', function () {
beforeEach(function () { beforeEach(async function () {
this.FileStoreHandler = { this.FileStoreHandler = {
getFileStream: sinon.stub(), getFileStream: sinon.stub(),
getFileSize: sinon.stub(), getFileSize: sinon.stub(),
} }
this.ProjectLocator = { findElement: sinon.stub() } this.ProjectLocator = { findElement: sinon.stub() }
this.controller = SandboxedModule.require(MODULE_PATH, { this.controller = await esmock.strict(MODULE_PATH, {
requires: { '@overleaf/settings': this.settings,
'@overleaf/settings': this.settings, '../../../../app/src/Features/Project/ProjectLocator':
'../Project/ProjectLocator': this.ProjectLocator, this.ProjectLocator,
'./FileStoreHandler': this.FileStoreHandler, '../../../../app/src/Features/FileStore/FileStoreHandler':
}, this.FileStoreHandler,
}) })
this.stream = {} this.stream = {}
this.projectId = '2k3j1lk3j21lk3j' this.projectId = '2k3j1lk3j21lk3j'

View file

@ -1,8 +1,8 @@
const { expect } = require('chai') import { expect } from 'chai'
const SandboxedModule = require('sandboxed-module') import esmock from 'esmock'
const sinon = require('sinon') import sinon from 'sinon'
const modulePath = const modulePath =
'../../../../app/src/Features/LinkedFiles/LinkedFilesController' '../../../../app/src/Features/LinkedFiles/LinkedFilesController.mjs'
describe('LinkedFilesController', function () { describe('LinkedFilesController', function () {
beforeEach(function () { beforeEach(function () {
@ -14,7 +14,7 @@ describe('LinkedFilesController', function () {
this.clock.restore() this.clock.restore()
}) })
beforeEach(function () { beforeEach(async function () {
this.userId = 'user-id' this.userId = 'user-id'
this.Agent = { this.Agent = {
promises: { promises: {
@ -42,24 +42,32 @@ describe('LinkedFilesController', function () {
this.ProjectOutputFileAgent = {} this.ProjectOutputFileAgent = {}
this.EditorController = {} this.EditorController = {}
this.ProjectLocator = {} this.ProjectLocator = {}
this.logger = {} this.logger = {
error: sinon.stub(),
}
this.settings = { enabledLinkedFileTypes: [] } this.settings = { enabledLinkedFileTypes: [] }
this.LinkedFilesController = SandboxedModule.require(modulePath, { this.LinkedFilesController = await esmock.strict(modulePath, {
requires: { '.../../../../app/src/Features/Authentication/SessionManager':
'../Authentication/SessionManager': this.SessionManager, this.SessionManager,
'../../../../app/src/Features/Analytics/AnalyticsManager': '../../../../app/src/Features/Analytics/AnalyticsManager':
this.AnalyticsManager, this.AnalyticsManager,
'./LinkedFilesHandler': this.LinkedFilesHandler, '../../../../app/src/Features/LinkedFiles/LinkedFilesHandler':
'../Editor/EditorRealTimeController': this.EditorRealTimeController, this.LinkedFilesHandler,
'../References/ReferencesHandler': this.ReferencesHandler, '../../../../app/src/Features/Editor/EditorRealTimeController':
'./UrlAgent': this.UrlAgent, this.EditorRealTimeController,
'./ProjectFileAgent': this.ProjectFileAgent, '../../../../app/src/Features/References/ReferencesHandler':
'./ProjectOutputFileAgent': this.ProjectOutputFileAgent, this.ReferencesHandler,
'../Editor/EditorController': this.EditorController, '../../../../app/src/Features/LinkedFiles/UrlAgent': this.UrlAgent,
'../Project/ProjectLocator': this.ProjectLocator, '../../../../app/src/Features/LinkedFiles/ProjectFileAgent':
'@overleaf/logger': this.logger, this.ProjectFileAgent,
'@overleaf/settings': this.settings, '../../../../app/src/Features/LinkedFiles/ProjectOutputFileAgent':
}, this.ProjectOutputFileAgent,
'../../../../app/src/Features/Editor/EditorController':
this.EditorController,
'../../../../app/src/Features/Project/ProjectLocator':
this.ProjectLocator,
'@overleaf/logger': this.logger,
'@overleaf/settings': this.settings,
}) })
this.LinkedFilesController._getAgent = sinon.stub().resolves(this.Agent) this.LinkedFilesController._getAgent = sinon.stub().resolves(this.Agent)
}) })

View file

@ -1,11 +1,11 @@
const { expect } = require('chai') import { expect } from 'chai'
const sinon = require('sinon') import sinon from 'sinon'
const modulePath = '../../../../app/src/Features/Metadata/MetaController' import esmock from 'esmock'
const SandboxedModule = require('sandboxed-module') import MockResponse from '../helpers/MockResponse.js'
const MockResponse = require('../helpers/MockResponse') const modulePath = '../../../../app/src/Features/Metadata/MetaController.mjs'
describe('MetaController', function () { describe('MetaController', function () {
beforeEach(function () { beforeEach(async function () {
this.EditorRealTimeController = { this.EditorRealTimeController = {
emitToRoom: sinon.stub(), emitToRoom: sinon.stub(),
} }
@ -17,11 +17,10 @@ describe('MetaController', function () {
}, },
} }
this.MetadataController = SandboxedModule.require(modulePath, { this.MetadataController = await esmock.strict(modulePath, {
requires: { '../../../../app/src/Features/Editor/EditorRealTimeController':
'../Editor/EditorRealTimeController': this.EditorRealTimeController, this.EditorRealTimeController,
'./MetaHandler': this.MetaHandler, '../../../../app/src/Features/Metadata/MetaHandler': this.MetaHandler,
},
}) })
}) })

View file

@ -1,10 +1,11 @@
const { expect } = require('chai') import { expect } from 'chai'
const sinon = require('sinon') import sinon from 'sinon'
const modulePath = '../../../../app/src/Features/Metadata/MetaHandler' import esmock from 'esmock'
const SandboxedModule = require('sandboxed-module')
const modulePath = '../../../../app/src/Features/Metadata/MetaHandler.mjs'
describe('MetaHandler', function () { describe('MetaHandler', function () {
beforeEach(function () { beforeEach(async function () {
this.projectId = 'someprojectid' this.projectId = 'someprojectid'
this.docId = 'somedocid' this.docId = 'somedocid'
@ -66,13 +67,13 @@ describe('MetaHandler', function () {
], ],
} }
this.MetaHandler = SandboxedModule.require(modulePath, { this.MetaHandler = await esmock.strict(modulePath, {
requires: { '../../../../app/src/Features/Project/ProjectEntityHandler':
'../Project/ProjectEntityHandler': this.ProjectEntityHandler, this.ProjectEntityHandler,
'../DocumentUpdater/DocumentUpdaterHandler': '../../../../app/src/Features/DocumentUpdater/DocumentUpdaterHandler':
this.DocumentUpdaterHandler, this.DocumentUpdaterHandler,
'./packageMapping': this.packageMapping, '../../../../app/src/Features/Metadata/packageMapping':
}, this.packageMapping,
}) })
}) })

View file

@ -1,15 +1,16 @@
const SandboxedModule = require('sandboxed-module') import esmock from 'esmock'
const sinon = require('sinon') import sinon from 'sinon'
const modulePath = require('path').join(
__dirname, const modulePath = new URL(
'../../../../app/src/Features/Notifications/NotificationsController.js' '../../../../app/src/Features/Notifications/NotificationsController.mjs',
) import.meta.url
).pathname
describe('NotificationsController', function () { describe('NotificationsController', function () {
const userId = '123nd3ijdks' const userId = '123nd3ijdks'
const notificationId = '123njdskj9jlk' const notificationId = '123njdskj9jlk'
beforeEach(function () { beforeEach(async function () {
this.handler = { this.handler = {
getUserNotifications: sinon.stub().callsArgWith(1), getUserNotifications: sinon.stub().callsArgWith(1),
markAsRead: sinon.stub().callsArgWith(2), markAsRead: sinon.stub().callsArgWith(2),
@ -30,12 +31,11 @@ describe('NotificationsController', function () {
this.AuthenticationController = { this.AuthenticationController = {
getLoggedInUserId: sinon.stub().returns(this.req.session.user._id), getLoggedInUserId: sinon.stub().returns(this.req.session.user._id),
} }
this.controller = SandboxedModule.require(modulePath, { this.controller = await esmock.strict(modulePath, {
requires: { '../../../../app/src/Features/Notifications/NotificationsHandler':
'./NotificationsHandler': this.handler, this.handler,
'../Authentication/AuthenticationController': '../../../../app/src/Features/Authentication/AuthenticationController':
this.AuthenticationController, this.AuthenticationController,
},
}) })
}) })

View file

@ -1,16 +1,15 @@
const SandboxedModule = require('sandboxed-module') import esmock from 'esmock'
const path = require('path') import sinon from 'sinon'
const sinon = require('sinon') import { expect } from 'chai'
const { expect } = require('chai') import MockResponse from '../helpers/MockResponse.js'
const MockResponse = require('../helpers/MockResponse')
const MODULE_PATH = path.join( const MODULE_PATH = new URL(
__dirname, '../../../../app/src/Features/PasswordReset/PasswordResetController.mjs',
'../../../../app/src/Features/PasswordReset/PasswordResetController' import.meta.url
) ).pathname
describe('PasswordResetController', function () { describe('PasswordResetController', function () {
beforeEach(function () { beforeEach(async function () {
this.email = 'bob@bob.com' this.email = 'bob@bob.com'
this.user_id = 'mock-user-id' this.user_id = 'mock-user-id'
this.token = 'my security token that was emailed to me' this.token = 'my security token that was emailed to me'
@ -58,27 +57,27 @@ describe('PasswordResetController', function () {
removeReconfirmFlag: sinon.stub().resolves(), removeReconfirmFlag: sinon.stub().resolves(),
}, },
} }
this.PasswordResetController = SandboxedModule.require(MODULE_PATH, { this.PasswordResetController = await esmock.strict(MODULE_PATH, {
requires: { '@overleaf/settings': this.settings,
'@overleaf/settings': this.settings, '../../../../app/src/Features/PasswordReset/PasswordResetHandler':
'./PasswordResetHandler': this.PasswordResetHandler, this.PasswordResetHandler,
'../Authentication/AuthenticationManager': { '../../../../app/src/Features/Authentication/AuthenticationManager': {
validatePassword: sinon.stub().returns(null), validatePassword: sinon.stub().returns(null),
},
'../Authentication/AuthenticationController':
(this.AuthenticationController = {
getLoggedInUserId: sinon.stub(),
finishLogin: sinon.stub(),
setAuditInfo: sinon.stub(),
}),
'../User/UserGetter': (this.UserGetter = {
promises: {
getUser: sinon.stub(),
},
}),
'../User/UserSessionsManager': this.UserSessionsManager,
'../User/UserUpdater': this.UserUpdater,
}, },
'../../../../app/src/Features/Authentication/AuthenticationController':
(this.AuthenticationController = {
getLoggedInUserId: sinon.stub(),
finishLogin: sinon.stub(),
setAuditInfo: sinon.stub(),
}),
'../../../../app/src/Features/User/UserGetter': (this.UserGetter = {
promises: {
getUser: sinon.stub(),
},
}),
'../../../../app/src/Features/User/UserSessionsManager':
this.UserSessionsManager,
'../../../../app/src/Features/User/UserUpdater': this.UserUpdater,
}) })
}) })

View file

@ -1,14 +1,13 @@
const SandboxedModule = require('sandboxed-module') import esmock from 'esmock'
const path = require('path') import sinon from 'sinon'
const sinon = require('sinon') import { expect } from 'chai'
const { expect } = require('chai') const modulePath = new URL(
const modulePath = path.join( '../../../../app/src/Features/PasswordReset/PasswordResetHandler',
__dirname, import.meta.url
'../../../../app/src/Features/PasswordReset/PasswordResetHandler' ).pathname
)
describe('PasswordResetHandler', function () { describe('PasswordResetHandler', function () {
beforeEach(function () { beforeEach(async function () {
this.settings = { siteUrl: 'https://www.overleaf.com' } this.settings = { siteUrl: 'https://www.overleaf.com' }
this.OneTimeTokenHandler = { this.OneTimeTokenHandler = {
promises: { promises: {
@ -33,24 +32,26 @@ describe('PasswordResetHandler', function () {
setUserPassword: sinon.stub().resolves(), setUserPassword: sinon.stub().resolves(),
}, },
} }
this.PasswordResetHandler = SandboxedModule.require(modulePath, { this.PasswordResetHandler = await esmock.strict(modulePath, {
requires: { '../../../../app/src/Features/User/UserAuditLogHandler':
'../User/UserAuditLogHandler': (this.UserAuditLogHandler = { (this.UserAuditLogHandler = {
promises: { promises: {
addEntry: sinon.stub().resolves(), addEntry: sinon.stub().resolves(),
}, },
}), }),
'../User/UserGetter': this.UserGetter, '../../../../app/src/Features/User/UserGetter': this.UserGetter,
'../Security/OneTimeTokenHandler': this.OneTimeTokenHandler, '../../../../app/src/Features/Security/OneTimeTokenHandler':
'../Email/EmailHandler': this.EmailHandler, this.OneTimeTokenHandler,
'../Authentication/AuthenticationManager': this.AuthenticationManager, '../../../../app/src/Features/Email/EmailHandler': this.EmailHandler,
'@overleaf/settings': this.settings, '../../../../app/src/Features/Authentication/AuthenticationManager':
'../Authorization/PermissionsManager': (this.PermissionsManager = { this.AuthenticationManager,
'@overleaf/settings': this.settings,
'../../../../app/src/Features/Authorization/PermissionsManager':
(this.PermissionsManager = {
promises: { promises: {
assertUserPermissions: sinon.stub(), assertUserPermissions: sinon.stub(),
}, },
}), }),
},
}) })
this.token = '12312321i' this.token = '12312321i'
this.user_id = 'user_id_here' this.user_id = 'user_id_here'

View file

@ -1,92 +1,80 @@
/* eslint-disable import esmock from 'esmock'
max-len,
mocha/no-identical-title, const modulePath = '../../../../app/src/Features/Project/DocLinesComparitor.mjs'
no-return-assign,
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
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const sinon = require('sinon')
const modulePath = '../../../../app/src/Features/Project/DocLinesComparitor.js'
const SandboxedModule = require('sandboxed-module')
describe('doc lines comparitor', function () { describe('doc lines comparitor', function () {
beforeEach(function () { beforeEach(async function () {
return (this.comparitor = SandboxedModule.require(modulePath, {})) this.comparitor = await esmock.strict(modulePath, {})
}) })
it('should return true when the lines are the same', function () { it('should return true when the lines are the same', function () {
const lines1 = ['hello', 'world'] const lines1 = ['hello', 'world']
const lines2 = ['hello', 'world'] const lines2 = ['hello', 'world']
const result = this.comparitor.areSame(lines1, lines2) const result = this.comparitor.areSame(lines1, lines2)
return result.should.equal(true) result.should.equal(true)
}) })
;[
it('should return false when the lines are different', function () { {
const lines1 = ['hello', 'world'] lines1: ['hello', 'world'],
const lines2 = ['diff', 'world'] lines2: ['diff', 'world'],
const result = this.comparitor.areSame(lines1, lines2) },
return result.should.equal(false) {
}) lines1: ['hello', 'world'],
lines2: ['hello', 'wrld'],
it('should return false when the lines are different', function () { },
const lines1 = ['hello', 'world'] ].forEach(({ lines1, lines2 }) => {
const lines2 = ['hello', 'wrld'] it('should return false when the lines are different', function () {
const result = this.comparitor.areSame(lines1, lines2) const result = this.comparitor.areSame(lines1, lines2)
return result.should.equal(false) result.should.equal(false)
})
}) })
it('should return true when the lines are same', function () { it('should return true when the lines are same', function () {
const lines1 = ['hello', 'world'] const lines1 = ['hello', 'world']
const lines2 = ['hello', 'world'] const lines2 = ['hello', 'world']
const result = this.comparitor.areSame(lines1, lines2) const result = this.comparitor.areSame(lines1, lines2)
return result.should.equal(true) result.should.equal(true)
}) })
it('should return false if the doc lines are different in length', function () { it('should return false if the doc lines are different in length', function () {
const lines1 = ['hello', 'world'] const lines1 = ['hello', 'world']
const lines2 = ['hello', 'world', 'please'] const lines2 = ['hello', 'world', 'please']
const result = this.comparitor.areSame(lines1, lines2) const result = this.comparitor.areSame(lines1, lines2)
return result.should.equal(false) result.should.equal(false)
}) })
it('should return false if the first array is undefined', function () { it('should return false if the first array is undefined', function () {
const lines1 = undefined const lines1 = undefined
const lines2 = ['hello', 'world'] const lines2 = ['hello', 'world']
const result = this.comparitor.areSame(lines1, lines2) const result = this.comparitor.areSame(lines1, lines2)
return result.should.equal(false) result.should.equal(false)
}) })
it('should return false if the second array is undefined', function () { it('should return false if the second array is undefined', function () {
const lines1 = ['hello'] const lines1 = ['hello']
const lines2 = undefined const lines2 = undefined
const result = this.comparitor.areSame(lines1, lines2) const result = this.comparitor.areSame(lines1, lines2)
return result.should.equal(false) result.should.equal(false)
}) })
it('should return false if the second array is not an array', function () { it('should return false if the second array is not an array', function () {
const lines1 = ['hello'] const lines1 = ['hello']
const lines2 = '' const lines2 = ''
const result = this.comparitor.areSame(lines1, lines2) const result = this.comparitor.areSame(lines1, lines2)
return result.should.equal(false) result.should.equal(false)
}) })
it('should return true when comparing equal orchard docs', function () { it('should return true when comparing equal orchard docs', function () {
const lines1 = [{ text: 'hello world' }] const lines1 = [{ text: 'hello world' }]
const lines2 = [{ text: 'hello world' }] const lines2 = [{ text: 'hello world' }]
const result = this.comparitor.areSame(lines1, lines2) const result = this.comparitor.areSame(lines1, lines2)
return result.should.equal(true) result.should.equal(true)
}) })
it('should return false when comparing different orchard docs', function () { it('should return false when comparing different orchard docs', function () {
const lines1 = [{ text: 'goodbye world' }] const lines1 = [{ text: 'goodbye world' }]
const lines2 = [{ text: 'hello world' }] const lines2 = [{ text: 'hello world' }]
const result = this.comparitor.areSame(lines1, lines2) const result = this.comparitor.areSame(lines1, lines2)
return result.should.equal(false) result.should.equal(false)
}) })
}) })

View file

@ -1,8 +1,3 @@
/* eslint-disable
max-len,
no-return-assign,
no-unused-vars,
*/
// TODO: This file was created by bulk-decaffeinate. // TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint. // Fix any style issues and re-enable lint.
/* /*
@ -10,17 +5,17 @@
* DS102: Remove unnecessary code created because of implicit returns * DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/ */
import esmock from 'esmock'
import sinon from 'sinon'
const modulePath = '../../../../app/src/Features/Project/ProjectApiController' const modulePath = '../../../../app/src/Features/Project/ProjectApiController'
const SandboxedModule = require('sandboxed-module')
const sinon = require('sinon')
describe('Project api controller', function () { describe('Project api controller', function () {
beforeEach(function () { beforeEach(async function () {
this.ProjectDetailsHandler = { getDetails: sinon.stub() } this.ProjectDetailsHandler = { getDetails: sinon.stub() }
this.controller = SandboxedModule.require(modulePath, { this.controller = await esmock.strict(modulePath, {
requires: { '../../../../app/src/Features/Project/ProjectDetailsHandler':
'./ProjectDetailsHandler': this.ProjectDetailsHandler, this.ProjectDetailsHandler,
},
}) })
this.project_id = '321l3j1kjkjl' this.project_id = '321l3j1kjkjl'
this.req = { this.req = {

View file

@ -1,17 +1,18 @@
const SandboxedModule = require('sandboxed-module') import esmock from 'esmock'
const path = require('path') import sinon from 'sinon'
const sinon = require('sinon') import { expect } from 'chai'
const { expect } = require('chai') import mongodb from 'mongodb-legacy'
const { ObjectId } = require('mongodb-legacy') import Errors from '../../../../app/src/Features/Errors/Errors.js'
const Errors = require('../../../../app/src/Features/Errors/Errors')
const MODULE_PATH = path.join( const ObjectId = mongodb.ObjectId
__dirname,
'../../../../app/src/Features/Project/ProjectListController' const MODULE_PATH = new URL(
) '../../../../app/src/Features/Project/ProjectListController',
import.meta.url
).pathname
describe('ProjectListController', function () { describe('ProjectListController', function () {
beforeEach(function () { beforeEach(async function () {
this.project_id = new ObjectId('abcdefabcdefabcdefabcdef') this.project_id = new ObjectId('abcdefabcdefabcdefabcdef')
this.user = { this.user = {
@ -150,34 +151,40 @@ describe('ProjectListController', function () {
}, },
} }
this.ProjectListController = SandboxedModule.require(MODULE_PATH, { this.ProjectListController = await esmock.strict(MODULE_PATH, {
requires: { 'mongodb-legacy': { ObjectId },
'mongodb-legacy': { ObjectId }, '@overleaf/settings': this.settings,
'@overleaf/settings': this.settings, '@overleaf/metrics': this.Metrics,
'@overleaf/metrics': this.Metrics, '../../../../app/src/Features/SplitTests/SplitTestHandler':
'../SplitTests/SplitTestHandler': this.SplitTestHandler, this.SplitTestHandler,
'../SplitTests/SplitTestSessionHandler': this.SplitTestSessionHandler, '../../../../app/src/Features/SplitTests/SplitTestSessionHandler':
'../User/UserController': this.UserController, this.SplitTestSessionHandler,
'./ProjectHelper': this.ProjectHelper, '../../../../app/src/Features/User/UserController': this.UserController,
'../Subscription/LimitationsManager': this.LimitationsManager, '../../../../app/src/Features/Project/ProjectHelper': this.ProjectHelper,
'../Tags/TagsHandler': this.TagsHandler, '../../../../app/src/Features/Subscription/LimitationsManager':
'../Notifications/NotificationsHandler': this.NotificationsHandler, this.LimitationsManager,
'../../models/User': { User: this.UserModel }, '../../../../app/src/Features/Tags/TagsHandler': this.TagsHandler,
'./ProjectGetter': this.ProjectGetter, '../../../../app/src/Features/Notifications/NotificationsHandler':
'../Authentication/SessionManager': this.SessionManager, this.NotificationsHandler,
'../../infrastructure/Features': this.Features, '../../../../app/src/models/User': { User: this.UserModel },
'../User/UserGetter': this.UserGetter, '../../../../app/src/Features/Project/ProjectGetter': this.ProjectGetter,
'../Subscription/SubscriptionViewModelBuilder': '../../../../app/src/Features/Authentication/SessionManager':
this.SubscriptionViewModelBuilder, this.SessionManager,
'../../infrastructure/Modules': this.Modules, '../../../../app/src/infrastructure/Features': this.Features,
'../Survey/SurveyHandler': this.SurveyHandler, '../../../../app/src/Features/User/UserGetter': this.UserGetter,
'../User/UserPrimaryEmailCheckHandler': '../../../../app/src/Features/Subscription/SubscriptionViewModelBuilder':
this.UserPrimaryEmailCheckHandler, this.SubscriptionViewModelBuilder,
'../Notifications/NotificationsBuilder': this.NotificationBuilder, '../../../../app/src/infrastructure/Modules': this.Modules,
'../Subscription/SubscriptionLocator': this.SubscriptionLocator, '../../../../app/src/Features/Survey/SurveyHandler': this.SurveyHandler,
'../../infrastructure/GeoIpLookup': this.GeoIpLookup, '../../../../app/src/Features/User/UserPrimaryEmailCheckHandler':
'../Tutorial/TutorialHandler': this.TutorialHandler, this.UserPrimaryEmailCheckHandler,
}, '../../../../app/src/Features/Notifications/NotificationsBuilder':
this.NotificationBuilder,
'../../../../app/src/Features/Subscription/SubscriptionLocator':
this.SubscriptionLocator,
'../../../../app/src/infrastructure/GeoIpLookup': this.GeoIpLookup,
'../../../../app/src/Features/Tutorial/TutorialHandler':
this.TutorialHandler,
}) })
this.req = { this.req = {

View file

@ -1,12 +1,12 @@
const SandboxedModule = require('sandboxed-module') import esmock from 'esmock'
const modulePath = require('path').join( const modulePath = new URL(
__dirname, '../../../../app/src/Features/Referal/ReferalConnect.mjs',
'../../../../app/src/Features/Referal/ReferalConnect.js' import.meta.url
) ).pathname
describe('Referal connect middle wear', function () { describe('Referal connect middle wear', function () {
beforeEach(function () { beforeEach(async function () {
this.connect = SandboxedModule.require(modulePath, {}) this.connect = await esmock.strict(modulePath, {})
}) })
it('should take a referal query string and put it on the session if it exists', function (done) { it('should take a referal query string and put it on the session if it exists', function (done) {

View file

@ -1,11 +0,0 @@
const SandboxedModule = require('sandboxed-module')
const modulePath = require('path').join(
__dirname,
'../../../../app/src/Features/Referal/ReferalController.js'
)
describe('Referal controller', function () {
beforeEach(function () {
this.controller = SandboxedModule.require(modulePath, {})
})
})

View file

@ -0,0 +1,11 @@
import esmock from 'esmock'
const modulePath = new URL(
'../../../../app/src/Features/Referal/ReferalController.js',
import.meta.url
).pathname
describe('Referal controller', function () {
beforeEach(async function () {
this.controller = await esmock.strict(modulePath, {})
})
})

View file

@ -1,23 +1,21 @@
const SandboxedModule = require('sandboxed-module') import esmock from 'esmock'
const { expect } = require('chai') import { expect } from 'chai'
const sinon = require('sinon') import sinon from 'sinon'
const modulePath = require('path').join( const modulePath = new URL(
__dirname, '../../../../app/src/Features/Referal/ReferalHandler.mjs',
'../../../../app/src/Features/Referal/ReferalHandler.js' import.meta.url
) ).pathname
describe('Referal handler', function () { describe('Referal handler', function () {
beforeEach(function () { beforeEach(async function () {
this.User = { this.User = {
findById: sinon.stub().returns({ findById: sinon.stub().returns({
exec: sinon.stub(), exec: sinon.stub(),
}), }),
} }
this.handler = SandboxedModule.require(modulePath, { this.handler = await esmock.strict(modulePath, {
requires: { '../../../../app/src/models/User': {
'../../models/User': { User: this.User,
User: this.User,
},
}, },
}) })
this.user_id = '12313' this.user_id = '12313'

View file

@ -1,39 +1,26 @@
/* eslint-disable import esmock from 'esmock'
max-len, import sinon from 'sinon'
no-return-assign, import MockRequest from '../helpers/MockRequest.js'
no-unused-vars, import MockResponse from '../helpers/MockResponse.js'
*/
// 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
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const SandboxedModule = require('sandboxed-module')
const sinon = require('sinon')
const { assert } = require('chai')
const modulePath = const modulePath =
'../../../../app/src/Features/References/ReferencesController' '../../../../app/src/Features/References/ReferencesController'
const MockRequest = require('../helpers/MockRequest')
const MockResponse = require('../helpers/MockResponse')
describe('ReferencesController', function () { describe('ReferencesController', function () {
beforeEach(function () { beforeEach(async function () {
this.projectId = '2222' this.projectId = '2222'
this.controller = SandboxedModule.require(modulePath, { this.controller = await esmock.strict(modulePath, {
requires: { '@overleaf/settings': (this.settings = {
'@overleaf/settings': (this.settings = { apis: { web: { url: 'http://some.url' } },
apis: { web: { url: 'http://some.url' } }, }),
}), '../../../../app/src/Features/References/ReferencesHandler':
'./ReferencesHandler': (this.ReferencesHandler = { (this.ReferencesHandler = {
index: sinon.stub(), index: sinon.stub(),
indexAll: sinon.stub(), indexAll: sinon.stub(),
}), }),
'../Editor/EditorRealTimeController': (this.EditorRealTimeController = { '../../../../app/src/Features/Editor/EditorRealTimeController':
(this.EditorRealTimeController = {
emitToRoom: sinon.stub(), emitToRoom: sinon.stub(),
}), }),
},
}) })
this.req = new MockRequest() this.req = new MockRequest()
this.req.params.Project_id = this.projectId this.req.params.Project_id = this.projectId
@ -45,10 +32,10 @@ describe('ReferencesController', function () {
this.res.json = sinon.stub() this.res.json = sinon.stub()
this.res.sendStatus = sinon.stub() this.res.sendStatus = sinon.stub()
this.next = sinon.stub() this.next = sinon.stub()
return (this.fakeResponseData = { this.fakeResponseData = {
projectId: this.projectId, projectId: this.projectId,
keys: ['one', 'two', 'three'], keys: ['one', 'two', 'three'],
}) }
}) })
describe('indexAll', function () { describe('indexAll', function () {
@ -59,36 +46,36 @@ describe('ReferencesController', function () {
null, null,
this.fakeResponseData this.fakeResponseData
) )
return (this.call = callback => { this.call = callback => {
this.controller.indexAll(this.req, this.res, this.next) this.controller.indexAll(this.req, this.res, this.next)
return callback() return callback()
}) }
}) })
it('should not produce an error', function (done) { it('should not produce an error', function (done) {
return this.call(() => { this.call(() => {
this.res.sendStatus.callCount.should.equal(0) this.res.sendStatus.callCount.should.equal(0)
this.res.sendStatus.calledWith(500).should.equal(false) this.res.sendStatus.calledWith(500).should.equal(false)
this.res.sendStatus.calledWith(400).should.equal(false) this.res.sendStatus.calledWith(400).should.equal(false)
return done() done()
}) })
}) })
it('should return data', function (done) { it('should return data', function (done) {
return this.call(() => { this.call(() => {
this.res.json.callCount.should.equal(1) this.res.json.callCount.should.equal(1)
this.res.json.calledWith(this.fakeResponseData).should.equal(true) this.res.json.calledWith(this.fakeResponseData).should.equal(true)
return done() done()
}) })
}) })
it('should call ReferencesHandler.indexAll', function (done) { it('should call ReferencesHandler.indexAll', function (done) {
return this.call(() => { this.call(() => {
this.ReferencesHandler.indexAll.callCount.should.equal(1) this.ReferencesHandler.indexAll.callCount.should.equal(1)
this.ReferencesHandler.indexAll this.ReferencesHandler.indexAll
.calledWith(this.projectId) .calledWith(this.projectId)
.should.equal(true) .should.equal(true)
return done() done()
}) })
}) })
@ -99,30 +86,30 @@ describe('ReferencesController', function () {
null, null,
this.fakeResponseData this.fakeResponseData
) )
return (this.req.body.shouldBroadcast = true) this.req.body.shouldBroadcast = true
}) })
it('should call EditorRealTimeController.emitToRoom', function (done) { it('should call EditorRealTimeController.emitToRoom', function (done) {
return this.call(() => { this.call(() => {
this.EditorRealTimeController.emitToRoom.callCount.should.equal(1) this.EditorRealTimeController.emitToRoom.callCount.should.equal(1)
return done() done()
}) })
}) })
it('should not produce an error', function (done) { it('should not produce an error', function (done) {
return this.call(() => { this.call(() => {
this.res.sendStatus.callCount.should.equal(0) this.res.sendStatus.callCount.should.equal(0)
this.res.sendStatus.calledWith(500).should.equal(false) this.res.sendStatus.calledWith(500).should.equal(false)
this.res.sendStatus.calledWith(400).should.equal(false) this.res.sendStatus.calledWith(400).should.equal(false)
return done() done()
}) })
}) })
it('should still return data', function (done) { it('should still return data', function (done) {
return this.call(() => { this.call(() => {
this.res.json.callCount.should.equal(1) this.res.json.callCount.should.equal(1)
this.res.json.calledWith(this.fakeResponseData).should.equal(true) this.res.json.calledWith(this.fakeResponseData).should.equal(true)
return done() done()
}) })
}) })
}) })
@ -134,30 +121,30 @@ describe('ReferencesController', function () {
null, null,
this.fakeResponseData this.fakeResponseData
) )
return (this.req.body.shouldBroadcast = false) this.req.body.shouldBroadcast = false
}) })
it('should not call EditorRealTimeController.emitToRoom', function (done) { it('should not call EditorRealTimeController.emitToRoom', function (done) {
return this.call(() => { this.call(() => {
this.EditorRealTimeController.emitToRoom.callCount.should.equal(0) this.EditorRealTimeController.emitToRoom.callCount.should.equal(0)
return done() done()
}) })
}) })
it('should not produce an error', function (done) { it('should not produce an error', function (done) {
return this.call(() => { this.call(() => {
this.res.sendStatus.callCount.should.equal(0) this.res.sendStatus.callCount.should.equal(0)
this.res.sendStatus.calledWith(500).should.equal(false) this.res.sendStatus.calledWith(500).should.equal(false)
this.res.sendStatus.calledWith(400).should.equal(false) this.res.sendStatus.calledWith(400).should.equal(false)
return done() done()
}) })
}) })
it('should still return data', function (done) { it('should still return data', function (done) {
return this.call(() => { this.call(() => {
this.res.json.callCount.should.equal(1) this.res.json.callCount.should.equal(1)
this.res.json.calledWith(this.fakeResponseData).should.equal(true) this.res.json.calledWith(this.fakeResponseData).should.equal(true)
return done() done()
}) })
}) })
}) })
@ -166,35 +153,35 @@ describe('ReferencesController', function () {
describe('there is no data', function () { describe('there is no data', function () {
beforeEach(function () { beforeEach(function () {
this.ReferencesHandler.indexAll.callsArgWith(1) this.ReferencesHandler.indexAll.callsArgWith(1)
return (this.call = callback => { this.call = callback => {
this.controller.indexAll(this.req, this.res, this.next) this.controller.indexAll(this.req, this.res, this.next)
return callback() callback()
}) }
}) })
it('should not call EditorRealTimeController.emitToRoom', function (done) { it('should not call EditorRealTimeController.emitToRoom', function (done) {
return this.call(() => { this.call(() => {
this.EditorRealTimeController.emitToRoom.callCount.should.equal(0) this.EditorRealTimeController.emitToRoom.callCount.should.equal(0)
return done() done()
}) })
}) })
it('should not produce an error', function (done) { it('should not produce an error', function (done) {
return this.call(() => { this.call(() => {
this.res.sendStatus.callCount.should.equal(0) this.res.sendStatus.callCount.should.equal(0)
this.res.sendStatus.calledWith(500).should.equal(false) this.res.sendStatus.calledWith(500).should.equal(false)
this.res.sendStatus.calledWith(400).should.equal(false) this.res.sendStatus.calledWith(400).should.equal(false)
return done() done()
}) })
}) })
it('should send a response with an empty keys list', function (done) { it('should send a response with an empty keys list', function (done) {
return this.call(() => { this.call(() => {
this.res.json.called.should.equal(true) this.res.json.called.should.equal(true)
this.res.json this.res.json
.calledWith({ projectId: this.projectId, keys: [] }) .calledWith({ projectId: this.projectId, keys: [] })
.should.equal(true) .should.equal(true)
return done() done()
}) })
}) })
}) })

View file

@ -1,10 +1,3 @@
/* eslint-disable
n/handle-callback-err,
max-len,
mocha/no-identical-title,
no-return-assign,
no-unused-vars,
*/
// TODO: This file was created by bulk-decaffeinate. // TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint. // Fix any style issues and re-enable lint.
/* /*
@ -12,14 +5,16 @@
* DS102: Remove unnecessary code created because of implicit returns * DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/ */
const SandboxedModule = require('sandboxed-module') import esmock from 'esmock'
const { assert, expect } = require('chai')
const sinon = require('sinon') import { expect } from 'chai'
const Errors = require('../../../../app/src/Features/Errors/Errors') import sinon from 'sinon'
const modulePath = '../../../../app/src/Features/References/ReferencesHandler' import Errors from '../../../../app/src/Features/Errors/Errors.js'
const modulePath =
'../../../../app/src/Features/References/ReferencesHandler.mjs'
describe('ReferencesHandler', function () { describe('ReferencesHandler', function () {
beforeEach(function () { beforeEach(async function () {
this.projectId = '222' this.projectId = '222'
this.fakeProject = { this.fakeProject = {
_id: this.projectId, _id: this.projectId,
@ -46,38 +41,37 @@ describe('ReferencesHandler', function () {
], ],
} }
this.docIds = ['aaa', 'ccc'] this.docIds = ['aaa', 'ccc']
this.handler = SandboxedModule.require(modulePath, { this.handler = await esmock.strict(modulePath, {
requires: { '@overleaf/settings': (this.settings = {
'@overleaf/settings': (this.settings = { apis: {
apis: { references: { url: 'http://some.url/references' },
references: { url: 'http://some.url/references' }, docstore: { url: 'http://some.url/docstore' },
docstore: { url: 'http://some.url/docstore' }, filestore: { url: 'http://some.url/filestore' },
filestore: { url: 'http://some.url/filestore' }, },
}, }),
}), request: (this.request = {
request: (this.request = { get: sinon.stub(),
get: sinon.stub(), post: sinon.stub(),
post: sinon.stub(), }),
}), '../../../../app/src/Features/Project/ProjectGetter':
'../Project/ProjectGetter': (this.ProjectGetter = { (this.ProjectGetter = {
getProject: sinon.stub().callsArgWith(2, null, this.fakeProject), getProject: sinon.stub().callsArgWith(2, null, this.fakeProject),
}), }),
'../User/UserGetter': (this.UserGetter = { '../../../../app/src/Features/User/UserGetter': (this.UserGetter = {
getUser: sinon.stub(), getUser: sinon.stub(),
}),
'../../../../app/src/Features/DocumentUpdater/DocumentUpdaterHandler':
(this.DocumentUpdaterHandler = {
flushDocToMongo: sinon.stub().callsArgWith(2, null),
}), }),
'../DocumentUpdater/DocumentUpdaterHandler': '../../../../app/src/infrastructure/Features': (this.Features = {
(this.DocumentUpdaterHandler = { hasFeature: sinon.stub().returns(true),
flushDocToMongo: sinon.stub().callsArgWith(2, null), }),
}),
'../../infrastructure/Features': (this.Features = {
hasFeature: sinon.stub().returns(true),
}),
},
}) })
return (this.fakeResponseData = { this.fakeResponseData = {
projectId: this.projectId, projectId: this.projectId,
keys: ['k1', 'k2'], keys: ['k1', 'k2'],
}) }
}) })
describe('indexAll', function () { describe('indexAll', function () {
@ -98,6 +92,7 @@ describe('ReferencesHandler', function () {
it('should call _findBibDocIds', function (done) { it('should call _findBibDocIds', function (done) {
return this.call((err, data) => { return this.call((err, data) => {
expect(err).to.be.null
this.handler._findBibDocIds.callCount.should.equal(1) this.handler._findBibDocIds.callCount.should.equal(1)
this.handler._findBibDocIds this.handler._findBibDocIds
.calledWith(this.fakeProject) .calledWith(this.fakeProject)
@ -108,6 +103,7 @@ describe('ReferencesHandler', function () {
it('should call _findBibFileIds', function (done) { it('should call _findBibFileIds', function (done) {
return this.call((err, data) => { return this.call((err, data) => {
expect(err).to.be.null
this.handler._findBibDocIds.callCount.should.equal(1) this.handler._findBibDocIds.callCount.should.equal(1)
this.handler._findBibDocIds this.handler._findBibDocIds
.calledWith(this.fakeProject) .calledWith(this.fakeProject)
@ -118,6 +114,7 @@ describe('ReferencesHandler', function () {
it('should call DocumentUpdaterHandler.flushDocToMongo', function (done) { it('should call DocumentUpdaterHandler.flushDocToMongo', function (done) {
return this.call((err, data) => { return this.call((err, data) => {
expect(err).to.be.null
this.DocumentUpdaterHandler.flushDocToMongo.callCount.should.equal(2) this.DocumentUpdaterHandler.flushDocToMongo.callCount.should.equal(2)
return done() return done()
}) })
@ -125,6 +122,7 @@ describe('ReferencesHandler', function () {
it('should make a request to references service', function (done) { it('should make a request to references service', function (done) {
return this.call((err, data) => { return this.call((err, data) => {
expect(err).to.be.null
this.request.post.callCount.should.equal(1) this.request.post.callCount.should.equal(1)
const arg = this.request.post.firstCall.args[0] const arg = this.request.post.firstCall.args[0]
expect(arg.json).to.have.all.keys('docUrls', 'fullIndex') expect(arg.json).to.have.all.keys('docUrls', 'fullIndex')
@ -143,6 +141,7 @@ describe('ReferencesHandler', function () {
it('should return data', function (done) { it('should return data', function (done) {
return this.call((err, data) => { return this.call((err, data) => {
expect(err).to.be.null
expect(data).to.not.equal(null) expect(data).to.not.equal(null)
expect(data).to.not.equal(undefined) expect(data).to.not.equal(undefined)
expect(data).to.equal(this.fakeResponseData) expect(data).to.equal(this.fakeResponseData)
@ -165,7 +164,7 @@ describe('ReferencesHandler', function () {
}) })
it('should not send request', function (done) { it('should not send request', function (done) {
return this.call((err, data) => { return this.call(() => {
this.request.post.callCount.should.equal(0) this.request.post.callCount.should.equal(0)
return done() return done()
}) })
@ -187,7 +186,7 @@ describe('ReferencesHandler', function () {
}) })
it('should not send request', function (done) { it('should not send request', function (done) {
return this.call((err, data) => { return this.call(() => {
this.request.post.callCount.should.equal(0) this.request.post.callCount.should.equal(0)
return done() return done()
}) })
@ -210,7 +209,7 @@ describe('ReferencesHandler', function () {
}) })
it('should not send request', function (done) { it('should not send request', function (done) {
return this.call((err, data) => { return this.call(() => {
this.request.post.callCount.should.equal(0) this.request.post.callCount.should.equal(0)
return done() return done()
}) })
@ -237,7 +236,7 @@ describe('ReferencesHandler', function () {
}) })
it('should not send request', function (done) { it('should not send request', function (done) {
return this.call((err, data) => { return this.call(() => {
this.request.post.callCount.should.equal(0) this.request.post.callCount.should.equal(0)
return done() return done()
}) })

View file

@ -1,10 +1,10 @@
const SandboxedModule = require('sandboxed-module') import esmock from 'esmock'
const sinon = require('sinon') import sinon from 'sinon'
const MockResponse = require('../helpers/MockResponse') import MockResponse from '../helpers/MockResponse.js'
const modulePath = require('path').join( const modulePath = new URL(
__dirname, '../../../../app/src/Features/Spelling/SpellingController.mjs',
'../../../../app/src/Features/Spelling/SpellingController.js' import.meta.url
) ).pathname
const TEN_SECONDS = 1000 * 10 const TEN_SECONDS = 1000 * 10
@ -14,7 +14,7 @@ const SPELLING_URL = 'http://spelling.service.test'
describe('SpellingController', function () { describe('SpellingController', function () {
const userId = '123nd3ijdks' const userId = '123nd3ijdks'
beforeEach(function () { beforeEach(async function () {
this.requestStreamPipe = sinon.stub() this.requestStreamPipe = sinon.stub()
this.requestStreamOn = sinon this.requestStreamOn = sinon
.stub() .stub()
@ -26,20 +26,18 @@ describe('SpellingController', function () {
this.AuthenticationController = { this.AuthenticationController = {
getLoggedInUserId: req => req.session.user._id, getLoggedInUserId: req => req.session.user._id,
} }
this.controller = SandboxedModule.require(modulePath, { this.controller = await esmock.strict(modulePath, {
requires: { '../../../../app/src/Features/Spelling/LearnedWordsManager': {},
'./LearnedWordsManager': {}, request: this.request,
request: this.request, '@overleaf/settings': {
'@overleaf/settings': { languages: [
languages: [ { name: 'English', code: 'en' },
{ name: 'English', code: 'en' }, { name: 'French', code: 'fr' },
{ name: 'French', code: 'fr' }, ],
], apis: { spelling: { host: SPELLING_HOST, url: SPELLING_URL } },
apis: { spelling: { host: SPELLING_HOST, url: SPELLING_URL } },
},
'../Authentication/AuthenticationController':
this.AuthenticationController,
}, },
'../../../../app/src/Features/Authentication/AuthenticationController':
this.AuthenticationController,
}) })
this.req = { this.req = {
url: '/spelling/check', url: '/spelling/check',

View file

@ -1,10 +1,10 @@
const SandboxedModule = require('sandboxed-module') import esmock from 'esmock'
const sinon = require('sinon') import sinon from 'sinon'
const modulePath = const modulePath =
'../../../../app/src/Features/Subscription/SubscriptionGroupController' '../../../../app/src/Features/Subscription/SubscriptionGroupController'
describe('SubscriptionGroupController', function () { describe('SubscriptionGroupController', function () {
beforeEach(function () { beforeEach(async function () {
this.user = { _id: '!@312431', email: 'user@email.com' } this.user = { _id: '!@312431', email: 'user@email.com' }
this.adminUserId = '123jlkj' this.adminUserId = '123jlkj'
this.subscriptionId = '123434325412' this.subscriptionId = '123434325412'
@ -61,14 +61,16 @@ describe('SubscriptionGroupController', function () {
}, },
} }
this.Controller = SandboxedModule.require(modulePath, { this.Controller = await esmock.strict(modulePath, {
requires: { '../../../../app/src/Features/Subscription/SubscriptionGroupHandler':
'./SubscriptionGroupHandler': this.SubscriptionGroupHandler, this.SubscriptionGroupHandler,
'./SubscriptionLocator': this.SubscriptionLocator, '../../../../app/src/Features/Subscription/SubscriptionLocator':
'../Authentication/SessionManager': this.SessionManager, this.SubscriptionLocator,
'../User/UserAuditLogHandler': this.UserAuditLogHandler, '../../../../app/src/Features/Authentication/SessionManager':
'../../infrastructure/Modules': this.Modules, this.SessionManager,
}, '../../../../app/src/Features/User/UserAuditLogHandler':
this.UserAuditLogHandler,
'../../../../app/src/infrastructure/Modules': this.Modules,
}) })
}) })

View file

@ -1,11 +1,11 @@
const SandboxedModule = require('sandboxed-module') import esmock from 'esmock'
const sinon = require('sinon') import sinon from 'sinon'
const { expect } = require('chai') import { expect } from 'chai'
const modulePath = const modulePath =
'../../../../app/src/Features/Subscription/TeamInvitesController' '../../../../app/src/Features/Subscription/TeamInvitesController'
describe('TeamInvitesController', function () { describe('TeamInvitesController', function () {
beforeEach(function () { beforeEach(async function () {
this.user = { _id: '!@312431', email: 'user@email.com' } this.user = { _id: '!@312431', email: 'user@email.com' }
this.adminUserId = '123jlkj' this.adminUserId = '123jlkj'
this.subscriptionId = '123434325412' this.subscriptionId = '123434325412'
@ -77,29 +77,33 @@ describe('TeamInvitesController', function () {
RateLimiter: class {}, RateLimiter: class {},
} }
this.Controller = SandboxedModule.require(modulePath, { this.Controller = await esmock.strict(modulePath, {
requires: { '../../../../app/src/Features/Subscription/TeamInvitesHandler':
'./TeamInvitesHandler': this.TeamInvitesHandler, this.TeamInvitesHandler,
'../Authentication/SessionManager': this.SessionManager, '../../../../app/src/Features/Authentication/SessionManager':
'./SubscriptionLocator': this.SubscriptionLocator, this.SessionManager,
'../User/UserAuditLogHandler': this.UserAuditLogHandler, '../../../../app/src/Features/Subscription/SubscriptionLocator':
'../Errors/ErrorController': this.ErrorController, this.SubscriptionLocator,
'../User/UserGetter': this.UserGetter, '../../../../app/src/Features/User/UserAuditLogHandler':
'../Email/EmailHandler': this.EmailHandler, this.UserAuditLogHandler,
'../../infrastructure/RateLimiter': this.RateLimiter, '../../../../app/src/Features/Errors/ErrorController':
'../../infrastructure/Modules': (this.Modules = { this.ErrorController,
promises: { '../../../../app/src/Features/User/UserGetter': this.UserGetter,
hooks: { '../../../../app/src/Features/Email/EmailHandler': this.EmailHandler,
fire: sinon.stub().resolves([]), '../../../../app/src/infrastructure/RateLimiter': this.RateLimiter,
}, '../../../../app/src/infrastructure/Modules': (this.Modules = {
promises: {
hooks: {
fire: sinon.stub().resolves([]),
}, },
}), },
'../SplitTests/SplitTestHandler': (this.SplitTestHandler = { }),
'../../../../app/src/Features/SplitTests/SplitTestHandler':
(this.SplitTestHandler = {
promises: { promises: {
getAssignment: sinon.stub().resolves({}), getAssignment: sinon.stub().resolves({}),
}, },
}), }),
},
}) })
}) })

View file

@ -1,16 +1,16 @@
const SandboxedModule = require('sandboxed-module') import esmock from 'esmock'
const sinon = require('sinon') import sinon from 'sinon'
const { assert } = require('chai') import { assert } from 'chai'
const modulePath = require('path').join( const modulePath = new URL(
__dirname, '../../../../app/src/Features/Tags/TagsController.mjs',
'../../../../app/src/Features/Tags/TagsController.js' import.meta.url
) ).pathname
describe('TagsController', function () { describe('TagsController', function () {
const userId = '123nd3ijdks' const userId = '123nd3ijdks'
const projectId = '123njdskj9jlk' const projectId = '123njdskj9jlk'
beforeEach(function () { beforeEach(async function () {
this.TagsHandler = { this.TagsHandler = {
promises: { promises: {
addProjectToTag: sinon.stub().resolves(), addProjectToTag: sinon.stub().resolves(),
@ -28,11 +28,10 @@ describe('TagsController', function () {
return session.user._id return session.user._id
}, },
} }
this.TagsController = SandboxedModule.require(modulePath, { this.TagsController = await esmock.strict(modulePath, {
requires: { '../../../../app/src/Features/Tags/TagsHandler': this.TagsHandler,
'./TagsHandler': this.TagsHandler, '../../../../app/src/Features/Authentication/SessionManager':
'../Authentication/SessionManager': this.SessionManager, this.SessionManager,
},
}) })
this.req = { this.req = {
params: { params: {

View file

@ -1,16 +1,18 @@
const { ObjectId } = require('mongodb-legacy') import mongodb from 'mongodb-legacy'
const { expect } = require('chai') import { expect } from 'chai'
const SandboxedModule = require('sandboxed-module') import esmock from 'esmock'
const sinon = require('sinon') import sinon from 'sinon'
const Errors = require('../../../../app/src/Features/Errors/Errors') import Errors from '../../../../app/src/Features/Errors/Errors.js'
const MockResponse = require('../helpers/MockResponse') import MockResponse from '../helpers/MockResponse.js'
const MockRequest = require('../helpers/MockRequest') import MockRequest from '../helpers/MockRequest.js'
const ObjectId = mongodb.ObjectId
const MODULE_PATH = const MODULE_PATH =
'../../../../app/src/Features/ThirdPartyDataStore/TpdsController.js' '../../../../app/src/Features/ThirdPartyDataStore/TpdsController.mjs'
describe('TpdsController', function () { describe('TpdsController', function () {
beforeEach(function () { beforeEach(async function () {
this.metadata = { this.metadata = {
projectId: new ObjectId(), projectId: new ObjectId(),
entityId: new ObjectId(), entityId: new ObjectId(),
@ -55,17 +57,23 @@ describe('TpdsController', function () {
generateUniqueName: sinon.stub().resolves('unique'), generateUniqueName: sinon.stub().resolves('unique'),
}, },
} }
this.TpdsController = SandboxedModule.require(MODULE_PATH, { this.TpdsController = await esmock.strict(MODULE_PATH, {
requires: { '../../../../app/src/Features/ThirdPartyDataStore/TpdsUpdateHandler':
'./TpdsUpdateHandler': this.TpdsUpdateHandler, this.TpdsUpdateHandler,
'./UpdateMerger': this.UpdateMerger, '../../../../app/src/Features/ThirdPartyDataStore/UpdateMerger':
'../Notifications/NotificationsBuilder': this.NotificationsBuilder, this.UpdateMerger,
'../Authentication/SessionManager': this.SessionManager, '../../../../app/src/Features/Notifications/NotificationsBuilder':
'../Errors/HttpErrorHandler': this.HttpErrorHandler, this.NotificationsBuilder,
'./TpdsQueueManager': this.TpdsQueueManager, '../../../../app/src/Features/Authentication/SessionManager':
'../Project/ProjectCreationHandler': this.ProjectCreationHandler, this.SessionManager,
'../Project/ProjectDetailsHandler': this.ProjectDetailsHandler, '../../../../app/src/Features/Errors/HttpErrorHandler':
}, this.HttpErrorHandler,
'../../../../app/src/Features/ThirdPartyDataStore/TpdsQueueManager':
this.TpdsQueueManager,
'../../../../app/src/Features/Project/ProjectCreationHandler':
this.ProjectCreationHandler,
'../../../../app/src/Features/Project/ProjectDetailsHandler':
this.ProjectDetailsHandler,
}) })
this.user_id = 'dsad29jlkjas' this.user_id = 'dsad29jlkjas'

View file

@ -1,14 +1,16 @@
const SandboxedModule = require('sandboxed-module') import esmock from 'esmock'
const sinon = require('sinon') import sinon from 'sinon'
const { expect } = require('chai') import { expect } from 'chai'
const { ObjectId } = require('mongodb-legacy') import mongodb from 'mongodb-legacy'
const Errors = require('../../../../app/src/Features/Errors/Errors') import Errors from '../../../../app/src/Features/Errors/Errors.js'
const ObjectId = mongodb.ObjectId
const MODULE_PATH = const MODULE_PATH =
'../../../../app/src/Features/ThirdPartyDataStore/TpdsUpdateHandler.js' '../../../../app/src/Features/ThirdPartyDataStore/TpdsUpdateHandler.mjs'
describe('TpdsUpdateHandler', function () { describe('TpdsUpdateHandler', function () {
beforeEach(function () { beforeEach(async function () {
this.projectName = 'My recipes' this.projectName = 'My recipes'
this.projects = { this.projects = {
active1: { _id: new ObjectId(), name: this.projectName }, active1: { _id: new ObjectId(), name: this.projectName },
@ -95,19 +97,24 @@ describe('TpdsUpdateHandler', function () {
}, },
} }
this.TpdsUpdateHandler = SandboxedModule.require(MODULE_PATH, { this.TpdsUpdateHandler = await esmock.strict(MODULE_PATH, {
requires: { '.../../../../app/src/Features/Cooldown/CooldownManager':
'../Cooldown/CooldownManager': this.CooldownManager, this.CooldownManager,
'../Uploads/FileTypeManager': this.FileTypeManager, '../../../../app/src/Features/Uploads/FileTypeManager':
'../../infrastructure/Modules': this.Modules, this.FileTypeManager,
'../Notifications/NotificationsBuilder': this.NotificationsBuilder, '../../../../app/src/infrastructure/Modules': this.Modules,
'../Project/ProjectCreationHandler': this.ProjectCreationHandler, '../../../../app/src/Features/Notifications/NotificationsBuilder':
'../Project/ProjectDeleter': this.ProjectDeleter, this.NotificationsBuilder,
'../Project/ProjectGetter': this.ProjectGetter, '../../../../app/src/Features/Project/ProjectCreationHandler':
'../Project/ProjectHelper': this.ProjectHelper, this.ProjectCreationHandler,
'../Project/ProjectRootDocManager': this.RootDocManager, '../../../../app/src/Features/Project/ProjectDeleter':
'./UpdateMerger': this.UpdateMerger, this.ProjectDeleter,
}, '../../../../app/src/Features/Project/ProjectGetter': this.ProjectGetter,
'../../../../app/src/Features/Project/ProjectHelper': this.ProjectHelper,
'../../../../app/src/Features/Project/ProjectRootDocManager':
this.RootDocManager,
'../../../../app/src/Features/ThirdPartyDataStore/UpdateMerger':
this.UpdateMerger,
}) })
}) })

View file

@ -1,16 +1,19 @@
const SandboxedModule = require('sandboxed-module') import esmock from 'esmock'
const sinon = require('sinon') import sinon from 'sinon'
const { expect } = require('chai') import { expect } from 'chai'
const { ObjectId } = require('mongodb-legacy') import mongodb from 'mongodb-legacy'
const MockRequest = require('../helpers/MockRequest') import MockRequest from '../helpers/MockRequest.js'
const MockResponse = require('../helpers/MockResponse') import MockResponse from '../helpers/MockResponse.js'
const PrivilegeLevels = require('../../../../app/src/Features/Authorization/PrivilegeLevels') import PrivilegeLevels from '../../../../app/src/Features/Authorization/PrivilegeLevels.js'
import { getSafeRedirectPath } from '../../../../app/src/Features/Helpers/UrlHelper.js'
const ObjectId = mongodb.ObjectId
const MODULE_PATH = const MODULE_PATH =
'../../../../app/src/Features/TokenAccess/TokenAccessController' '../../../../app/src/Features/TokenAccess/TokenAccessController'
describe('TokenAccessController', function () { describe('TokenAccessController', function () {
beforeEach(function () { beforeEach(async function () {
this.token = 'abc123' this.token = 'abc123'
this.user = { _id: new ObjectId() } this.user = { _id: new ObjectId() }
this.project = { this.project = {
@ -137,32 +140,54 @@ describe('TokenAccessController', function () {
}, },
} }
this.TokenAccessController = SandboxedModule.require(MODULE_PATH, { this.TokenAccessController = await esmock.strict(MODULE_PATH, {
requires: { '@overleaf/settings': this.Settings,
'@overleaf/settings': this.Settings, '../../../../app/src/Features/TokenAccess/TokenAccessHandler':
'./TokenAccessHandler': this.TokenAccessHandler, this.TokenAccessHandler,
'../Authentication/AuthenticationController': '../../../../app/src/Features/Authentication/AuthenticationController':
this.AuthenticationController, this.AuthenticationController,
'../Authentication/SessionManager': this.SessionManager, '../../../../app/src/Features/Authentication/SessionManager':
'../Authorization/AuthorizationManager': this.AuthorizationManager, this.SessionManager,
'../Authorization/AuthorizationMiddleware': '../../../../app/src/Features/Authorization/AuthorizationManager':
this.AuthorizationMiddleware, this.AuthorizationManager,
'../Project/ProjectAuditLogHandler': this.ProjectAuditLogHandler, '../../../../app/src/Features/Authorization/AuthorizationMiddleware':
'../SplitTests/SplitTestHandler': this.SplitTestHandler, this.AuthorizationMiddleware,
'../Errors/Errors': (this.Errors = { NotFoundError: sinon.stub() }), '../../../../app/src/Features/Project/ProjectAuditLogHandler':
'../Collaborators/CollaboratorsHandler': this.CollaboratorsHandler, this.ProjectAuditLogHandler,
'../Collaborators/CollaboratorsInviteHandler': '../../../../app/src/Features/SplitTests/SplitTestHandler':
this.CollaboratorsInviteHandler, this.SplitTestHandler,
'../Collaborators/CollaboratorsGetter': this.CollaboratorsGetter, '../../../../app/src/Features/Errors/Errors': (this.Errors = {
'../Editor/EditorRealTimeController': this.EditorRealTimeController, NotFoundError: sinon.stub(),
'../Project/ProjectGetter': this.ProjectGetter, }),
'../Helpers/AsyncFormHelper': (this.AsyncFormHelper = { '../../../../app/src/Features/Collaborators/CollaboratorsHandler':
this.CollaboratorsHandler,
'../../../../app/src/Features/Collaborators/CollaboratorsInviteHandler':
this.CollaboratorsInviteHandler,
'../../../../app/src/Features/Collaborators/CollaboratorsGetter':
this.CollaboratorsGetter,
'../../../../app/src/Features/Editor/EditorRealTimeController':
this.EditorRealTimeController,
'../../../../app/src/Features/Project/ProjectGetter': this.ProjectGetter,
'../../../../app/src/Features/Helpers/AsyncFormHelper':
(this.AsyncFormHelper = {
redirect: sinon.stub(), redirect: sinon.stub(),
}), }),
'../Analytics/AnalyticsManager': this.AnalyticsManager, '../../../../app/src/Features/Helpers/AdminAuthorizationHelper':
'../User/UserGetter': this.UserGetter, (this.AdminAuthorizationHelper = {
'../Subscription/LimitationsManager': this.LimitationsManager, canRedirectToAdminDomain: sinon.stub(),
}, }),
'../../../../app/src/Features/Helpers/UrlHelper': (this.UrlHelper = {
getSafeAdminDomainRedirect: sinon
.stub()
.callsFake(
path => `${this.Settings.adminUrl}${getSafeRedirectPath(path)}`
),
}),
'../../../../app/src/Features/Analytics/AnalyticsManager':
this.AnalyticsManager,
'../../../../app/src/Features/User/UserGetter': this.UserGetter,
'../../../../app/src/Features/Subscription/LimitationsManager':
this.LimitationsManager,
}) })
}) })
@ -757,6 +782,7 @@ describe('TokenAccessController', function () {
beforeEach(function () { beforeEach(function () {
this.SessionManager.getLoggedInUserId.returns(admin._id) this.SessionManager.getLoggedInUserId.returns(admin._id)
this.SessionManager.getSessionUser.returns(admin) this.SessionManager.getSessionUser.returns(admin)
this.AdminAuthorizationHelper.canRedirectToAdminDomain.returns(true)
this.req.params = { token: this.token } this.req.params = { token: this.token }
this.req.body = { confirmedByUser: true, tokenHashPrefix: '#prefix' } this.req.body = { confirmedByUser: true, tokenHashPrefix: '#prefix' }
}) })

View file

@ -1,8 +1,3 @@
/* eslint-disable
max-len,
no-return-assign,
no-unused-vars,
*/
// TODO: This file was created by bulk-decaffeinate. // TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint. // Fix any style issues and re-enable lint.
/* /*
@ -11,17 +6,20 @@
* DS206: Consider reworking classes to avoid initClass * DS206: Consider reworking classes to avoid initClass
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/ */
const sinon = require('sinon') import sinon from 'sinon'
const { expect } = require('chai')
import { expect } from 'chai'
import esmock from 'esmock'
import MockRequest from '../helpers/MockRequest.js'
import MockResponse from '../helpers/MockResponse.js'
import ArchiveErrors from '../../../../app/src/Features/Uploads/ArchiveErrors.js'
const modulePath = const modulePath =
'../../../../app/src/Features/Uploads/ProjectUploadController.js' '../../../../app/src/Features/Uploads/ProjectUploadController.mjs'
const SandboxedModule = require('sandboxed-module')
const MockRequest = require('../helpers/MockRequest')
const MockResponse = require('../helpers/MockResponse')
const ArchiveErrors = require('../../../../app/src/Features/Uploads/ArchiveErrors')
describe('ProjectUploadController', function () { describe('ProjectUploadController', function () {
beforeEach(function () { beforeEach(async function () {
let Timer let Timer
this.req = new MockRequest() this.req = new MockRequest()
this.res = new MockResponse() this.res = new MockResponse()
@ -47,19 +45,22 @@ describe('ProjectUploadController', function () {
promises: {}, promises: {},
} }
return (this.ProjectUploadController = SandboxedModule.require(modulePath, { return (this.ProjectUploadController = await esmock.strict(modulePath, {
requires: { multer: sinon.stub(),
multer: sinon.stub(), '@overleaf/settings': { path: {} },
'@overleaf/settings': { path: {} }, '../../../../app/src/Features/Uploads/ProjectUploadManager':
'./ProjectUploadManager': (this.ProjectUploadManager = {}), (this.ProjectUploadManager = {}),
'./FileSystemImportManager': (this.FileSystemImportManager = {}), '../../../../app/src/Features/Uploads/FileSystemImportManager':
'@overleaf/metrics': this.metrics, (this.FileSystemImportManager = {}),
'../Authentication/SessionManager': this.SessionManager, '@overleaf/metrics': this.metrics,
'./ArchiveErrors': ArchiveErrors, '../../../../app/src/Features/Authentication/SessionManager':
'../Project/ProjectLocator': this.ProjectLocator, this.SessionManager,
'../Editor/EditorController': this.EditorController, '../../../../app/src/Features/Uploads/ArchiveErrors': ArchiveErrors,
fs: (this.fs = {}), '../../../../app/src/Features/Project/ProjectLocator':
}, this.ProjectLocator,
'../../../../app/src/Features/Editor/EditorController':
this.EditorController,
fs: (this.fs = {}),
})) }))
}) })

View file

@ -1,17 +1,17 @@
const SandboxedModule = require('sandboxed-module') import esmock from 'esmock'
const assert = require('assert') import assert from 'assert'
const path = require('path') import sinon from 'sinon'
const sinon = require('sinon') import { expect } from 'chai'
const modulePath = path.join( import MockResponse from '../helpers/MockResponse.js'
__dirname, import MockRequest from '../helpers/MockRequest.js'
'../../../../app/src/Features/User/UserPagesController'
) const modulePath = new URL(
const { expect } = require('chai') '../../../../app/src/Features/User/UserPagesController',
const MockResponse = require('../helpers/MockResponse') import.meta.url
const MockRequest = require('../helpers/MockRequest') ).pathname
describe('UserPagesController', function () { describe('UserPagesController', function () {
beforeEach(function () { beforeEach(async function () {
this.settings = { this.settings = {
apis: { apis: {
v1: { v1: {
@ -85,24 +85,28 @@ describe('UserPagesController', function () {
}, },
}, },
} }
this.UserPagesController = SandboxedModule.require(modulePath, { this.UserPagesController = await esmock.strict(modulePath, {
requires: { '@overleaf/settings': this.settings,
'@overleaf/settings': this.settings, '../../../../app/src/Features/User/UserGetter': this.UserGetter,
'./UserGetter': this.UserGetter, '../../../../app/src/Features/User/UserSessionsManager':
'./UserSessionsManager': this.UserSessionsManager, this.UserSessionsManager,
'../Newsletter/NewsletterManager': this.NewsletterManager, '../../../../app/src/Features/Newsletter/NewsletterManager':
'../Errors/ErrorController': this.ErrorController, this.NewsletterManager,
'../Authentication/AuthenticationController': '../../../../app/src/Features/Errors/ErrorController':
this.AuthenticationController, this.ErrorController,
'../Subscription/SubscriptionLocator': this.SubscriptionLocator, '../../../../app/src/Features/Authentication/AuthenticationController':
'../../infrastructure/Features': this.Features, this.AuthenticationController,
'../../../../modules/oauth2-server/app/src/OAuthPersonalAccessTokenManager': '../../../../app/src/Features/Subscription/SubscriptionLocator':
this.PersonalAccessTokenManager, this.SubscriptionLocator,
'../Authentication/SessionManager': this.SessionManager, '../../../../app/src/infrastructure/Features': this.Features,
'../SplitTests/SplitTestHandler': this.SplitTestHandler, '../../../../modules/oauth2-server/app/src/OAuthPersonalAccessTokenManager':
'../../infrastructure/Modules': this.Modules, this.PersonalAccessTokenManager,
request: (this.request = sinon.stub()), '../../../../app/src/Features/Authentication/SessionManager':
}, this.SessionManager,
'../../../../app/src/Features/SplitTests/SplitTestHandler':
this.SplitTestHandler,
'../../../../app/src/infrastructure/Modules': this.Modules,
request: (this.request = sinon.stub()),
}) })
this.req = new MockRequest() this.req = new MockRequest()
this.req.session.user = this.user this.req.session.user = this.user

View file

@ -1,21 +1,22 @@
const sinon = require('sinon') import sinon from 'sinon'
const assertCalledWith = sinon.assert.calledWith import { expect } from 'chai'
const { expect } = require('chai') import esmock from 'esmock'
const modulePath = import MockRequest from '../helpers/MockRequest.js'
'../../../../app/src/Features/UserMembership/UserMembershipController.js' import MockResponse from '../helpers/MockResponse.js'
const SandboxedModule = require('sandboxed-module') import EntityConfigs from '../../../../app/src/Features/UserMembership/UserMembershipEntityConfigs.js'
const MockRequest = require('../helpers/MockRequest') import Errors from '../../../../app/src/Features/Errors/Errors.js'
const MockResponse = require('../helpers/MockResponse') import {
const EntityConfigs = require('../../../../app/src/Features/UserMembership/UserMembershipEntityConfigs')
const Errors = require('../../../../app/src/Features/Errors/Errors')
const {
UserIsManagerError, UserIsManagerError,
UserNotFoundError, UserNotFoundError,
UserAlreadyAddedError, UserAlreadyAddedError,
} = require('../../../../app/src/Features/UserMembership/UserMembershipErrors') } from '../../../../app/src/Features/UserMembership/UserMembershipErrors.js'
const assertCalledWith = sinon.assert.calledWith
const modulePath =
'../../../../app/src/Features/UserMembership/UserMembershipController.mjs'
describe('UserMembershipController', function () { describe('UserMembershipController', function () {
beforeEach(function () { beforeEach(async function () {
this.req = new MockRequest() this.req = new MockRequest()
this.req.params.id = 'mock-entity-id' this.req.params.id = 'mock-entity-id'
this.user = { _id: 'mock-user-id' } this.user = { _id: 'mock-user-id' }
@ -79,19 +80,20 @@ describe('UserMembershipController', function () {
}, },
getAssignment: sinon.stub().yields(null, { variant: 'default' }), getAssignment: sinon.stub().yields(null, { variant: 'default' }),
} }
this.UserMembershipController = SandboxedModule.require(modulePath, { this.UserMembershipController = await esmock.strict(modulePath, {
requires: { '../../../../app/src/Features/UserMembership/UserMembershipErrors': {
'./UserMembershipErrors': { UserIsManagerError,
UserIsManagerError, UserNotFoundError,
UserNotFoundError, UserAlreadyAddedError,
UserAlreadyAddedError,
},
'../Authentication/SessionManager': this.SessionManager,
'../SplitTests/SplitTestHandler': this.SplitTestHandler,
'./UserMembershipHandler': this.UserMembershipHandler,
'@overleaf/settings': this.Settings,
'../../models/SSOConfig': { SSOConfig: this.SSOConfig },
}, },
'../../../../app/src/Features/Authentication/SessionManager':
this.SessionManager,
'../../../../app/src/Features/SplitTests/SplitTestHandler':
this.SplitTestHandler,
'../../../../app/src/Features/UserMembership/UserMembershipHandler':
this.UserMembershipHandler,
'@overleaf/settings': this.Settings,
'../../../../app/src/models/SSOConfig': { SSOConfig: this.SSOConfig },
}) })
}) })