mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Update tests
GitOrigin-RevId: 9272720e0f6865c54257c43bd98d8e6003251aa2
This commit is contained in:
parent
9490251251
commit
2bfb55a305
39 changed files with 868 additions and 827 deletions
|
@ -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,
|
||||||
|
'../../../../app/src/infrastructure/GeoIpLookup.js': (this.GeoIpLookup = {
|
||||||
promises: {
|
promises: {
|
||||||
getDetails: sinon.stub().resolves(),
|
getDetails: sinon.stub().resolves(),
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
this.res = new MockResponse()
|
this.res = new MockResponse()
|
|
@ -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,16 +24,15 @@ 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',
|
||||||
},
|
},
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
this.middleware = this.AnalyticsUTMTrackingMiddleware.recordUTMTags()
|
this.middleware = this.AnalyticsUTMTrackingMiddleware.recordUTMTags()
|
|
@ -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 },
|
||||||
'./CollaboratorsHandler': this.CollaboratorsHandler,
|
'../../../../app/src/Features/Collaborators/CollaboratorsHandler.js':
|
||||||
'./CollaboratorsGetter': this.CollaboratorsGetter,
|
this.CollaboratorsHandler,
|
||||||
'./OwnershipTransferHandler': this.OwnershipTransferHandler,
|
'../../../../app/src/Features/Collaborators/CollaboratorsGetter.js':
|
||||||
'../Editor/EditorRealTimeController': this.EditorRealTimeController,
|
this.CollaboratorsGetter,
|
||||||
'../../Features/Errors/HttpErrorHandler': this.HttpErrorHandler,
|
'../../../../app/src/Features/Collaborators/OwnershipTransferHandler.js':
|
||||||
'../Tags/TagsHandler': this.TagsHandler,
|
this.OwnershipTransferHandler,
|
||||||
'../Authentication/SessionManager': this.SessionManager,
|
'../../../../app/src/Features/Editor/EditorRealTimeController':
|
||||||
'../TokenAccess/TokenAccessHandler': this.TokenAccessHandler,
|
this.EditorRealTimeController,
|
||||||
'../Project/ProjectAuditLogHandler': this.ProjectAuditLogHandler,
|
'../../../../app/src/Features/Errors/HttpErrorHandler.js':
|
||||||
'../Project/ProjectGetter': this.ProjectGetter,
|
this.HttpErrorHandler,
|
||||||
'../SplitTests/SplitTestHandler': this.SplitTestHandler,
|
'../../../../app/src/Features/Tags/TagsHandler.js': this.TagsHandler,
|
||||||
'../Subscription/LimitationsManager': this.LimitationsManager,
|
'../../../../app/src/Features/Authentication/SessionManager.js':
|
||||||
},
|
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,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -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,
|
||||||
|
'../../../../app/src/Features/Collaborators/CollaboratorsInviteGetter.js':
|
||||||
|
this.CollaboratorsInviteGetter,
|
||||||
|
'../../../../app/src/Features/Editor/EditorRealTimeController.js':
|
||||||
|
this.EditorRealTimeController,
|
||||||
|
'../../../../app/src/Features/Analytics/AnalyticsManager.js':
|
||||||
|
this.AnalyticsManger,
|
||||||
|
'../../../../app/src/Features/Authentication/SessionManager.js':
|
||||||
|
this.SessionManager,
|
||||||
'@overleaf/settings': this.settings,
|
'@overleaf/settings': this.settings,
|
||||||
'../../infrastructure/RateLimiter': this.RateLimiter,
|
'../../../../app/src/infrastructure/RateLimiter': this.RateLimiter,
|
||||||
'../Authentication/AuthenticationController':
|
'../../../../app/src/Features/Authentication/AuthenticationController':
|
||||||
this.AuthenticationController,
|
this.AuthenticationController,
|
||||||
'../SplitTests/SplitTestHandler': this.SplitTestHandler,
|
'../../../../app/src/Features/SplitTests/SplitTestHandler':
|
||||||
},
|
this.SplitTestHandler,
|
||||||
})
|
})
|
||||||
|
|
||||||
this.res = new MockResponse()
|
this.res = new MockResponse()
|
|
@ -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,
|
||||||
'../../models/ProjectInvite': { ProjectInvite: this.ProjectInvite },
|
'../../../../app/src/models/ProjectInvite.js': {
|
||||||
'./CollaboratorsEmailHandler': this.CollaboratorsEmailHandler,
|
ProjectInvite: this.ProjectInvite,
|
||||||
'./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()
|
|
@ -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: {} }),
|
||||||
|
'../../../../app/src/Features/Authentication/SessionManager':
|
||||||
|
(this.SessionManager = {}),
|
||||||
|
'../../../../app/src/infrastructure/Modules': (this.Modules = {
|
||||||
promises: { hooks: {} },
|
promises: { hooks: {} },
|
||||||
}),
|
}),
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
this.req = {}
|
this.req = {}
|
|
@ -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,
|
||||||
},
|
|
||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
|
|
|
@ -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,
|
||||||
'../Project/ProjectLocator': this.ProjectLocator,
|
'../../../../app/src/Features/Project/ProjectLocator.js':
|
||||||
'./DocumentUpdaterHandler': this.DocumentUpdaterHandler,
|
this.ProjectLocator,
|
||||||
},
|
'../../../../app/src/Features/DocumentUpdater/DocumentUpdaterHandler.js':
|
||||||
|
this.DocumentUpdaterHandler,
|
||||||
})
|
})
|
||||||
this.projectId = '2k3j1lk3j21lk3j'
|
this.projectId = '2k3j1lk3j21lk3j'
|
||||||
this.fileId = '12321kklj1lk3jk12'
|
this.fileId = '12321kklj1lk3jk12'
|
|
@ -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,
|
||||||
|
'../../../../app/src/Features/Project/ProjectEntityUpdateHandler':
|
||||||
this.ProjectEntityUpdateHandler,
|
this.ProjectEntityUpdateHandler,
|
||||||
'../Chat/ChatApiHandler': this.ChatApiHandler,
|
'../../../../app/src/Features/Chat/ChatApiHandler': this.ChatApiHandler,
|
||||||
},
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -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 = {}),
|
||||||
'../DocumentUpdater/DocumentUpdaterHandler':
|
'../../../../app/src/Features/DocumentUpdater/DocumentUpdaterHandler.js':
|
||||||
this.DocumentUpdaterHandler,
|
this.DocumentUpdaterHandler,
|
||||||
},
|
}))
|
||||||
}
|
|
||||||
))
|
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('downloadProject', function () {
|
describe('downloadProject', function () {
|
|
@ -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(),
|
||||||
|
info: sinon.stub(),
|
||||||
|
debug: sinon.stub(),
|
||||||
|
}
|
||||||
|
return (this.ProjectZipStreamManager = await esmock.strict(modulePath, {
|
||||||
archiver: (this.archiver = sinon.stub().returns(this.archive)),
|
archiver: (this.archiver = sinon.stub().returns(this.archive)),
|
||||||
'../Project/ProjectEntityHandler': (this.ProjectEntityHandler = {}),
|
'@overleaf/logger': this.logger,
|
||||||
'../FileStore/FileStoreHandler': (this.FileStoreHandler = {}),
|
'../../../../app/src/Features/Project/ProjectEntityHandler':
|
||||||
'../Project/ProjectGetter': (this.ProjectGetter = {}),
|
(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')
|
|
@ -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"
|
||||||
}`
|
}`
|
||||||
)
|
)
|
||||||
|
|
|
@ -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 = {}),
|
||||||
|
'../../../../app/src/Features/Project/ProjectRootDocManager':
|
||||||
|
(this.ProjectRootDocManager = {}),
|
||||||
|
'../../../../app/src/Features/User/UserGetter': (this.UserGetter = {}),
|
||||||
'@overleaf/settings': (this.settings = {}),
|
'@overleaf/settings': (this.settings = {}),
|
||||||
request: this.request,
|
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
|
|
@ -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,
|
||||||
'../Project/ProjectLocator': this.ProjectLocator,
|
'../../../../app/src/Features/Project/ProjectLocator':
|
||||||
'./FileStoreHandler': this.FileStoreHandler,
|
this.ProjectLocator,
|
||||||
},
|
'../../../../app/src/Features/FileStore/FileStoreHandler':
|
||||||
|
this.FileStoreHandler,
|
||||||
})
|
})
|
||||||
this.stream = {}
|
this.stream = {}
|
||||||
this.projectId = '2k3j1lk3j21lk3j'
|
this.projectId = '2k3j1lk3j21lk3j'
|
|
@ -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':
|
||||||
|
this.ProjectFileAgent,
|
||||||
|
'../../../../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/logger': this.logger,
|
||||||
'@overleaf/settings': this.settings,
|
'@overleaf/settings': this.settings,
|
||||||
},
|
|
||||||
})
|
})
|
||||||
this.LinkedFilesController._getAgent = sinon.stub().resolves(this.Agent)
|
this.LinkedFilesController._getAgent = sinon.stub().resolves(this.Agent)
|
||||||
})
|
})
|
|
@ -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,
|
||||||
},
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -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,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -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,
|
||||||
},
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -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,
|
||||||
'./PasswordResetHandler': this.PasswordResetHandler,
|
'../../../../app/src/Features/PasswordReset/PasswordResetHandler':
|
||||||
'../Authentication/AuthenticationManager': {
|
this.PasswordResetHandler,
|
||||||
|
'../../../../app/src/Features/Authentication/AuthenticationManager': {
|
||||||
validatePassword: sinon.stub().returns(null),
|
validatePassword: sinon.stub().returns(null),
|
||||||
},
|
},
|
||||||
'../Authentication/AuthenticationController':
|
'../../../../app/src/Features/Authentication/AuthenticationController':
|
||||||
(this.AuthenticationController = {
|
(this.AuthenticationController = {
|
||||||
getLoggedInUserId: sinon.stub(),
|
getLoggedInUserId: sinon.stub(),
|
||||||
finishLogin: sinon.stub(),
|
finishLogin: sinon.stub(),
|
||||||
setAuditInfo: sinon.stub(),
|
setAuditInfo: sinon.stub(),
|
||||||
}),
|
}),
|
||||||
'../User/UserGetter': (this.UserGetter = {
|
'../../../../app/src/Features/User/UserGetter': (this.UserGetter = {
|
||||||
promises: {
|
promises: {
|
||||||
getUser: sinon.stub(),
|
getUser: sinon.stub(),
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
'../User/UserSessionsManager': this.UserSessionsManager,
|
'../../../../app/src/Features/User/UserSessionsManager':
|
||||||
'../User/UserUpdater': this.UserUpdater,
|
this.UserSessionsManager,
|
||||||
},
|
'../../../../app/src/Features/User/UserUpdater': this.UserUpdater,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -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,
|
||||||
|
'../../../../app/src/Features/Authentication/AuthenticationManager':
|
||||||
|
this.AuthenticationManager,
|
||||||
'@overleaf/settings': this.settings,
|
'@overleaf/settings': this.settings,
|
||||||
'../Authorization/PermissionsManager': (this.PermissionsManager = {
|
'../../../../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'
|
|
@ -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)
|
||||||
})
|
})
|
||||||
|
;[
|
||||||
|
{
|
||||||
|
lines1: ['hello', 'world'],
|
||||||
|
lines2: ['diff', 'world'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
lines1: ['hello', 'world'],
|
||||||
|
lines2: ['hello', 'wrld'],
|
||||||
|
},
|
||||||
|
].forEach(({ lines1, lines2 }) => {
|
||||||
it('should return false when the lines are different', function () {
|
it('should return false when the lines are different', function () {
|
||||||
const lines1 = ['hello', 'world']
|
|
||||||
const lines2 = ['diff', '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 when the lines are different', function () {
|
|
||||||
const lines1 = ['hello', 'world']
|
|
||||||
const lines2 = ['hello', 'wrld']
|
|
||||||
const result = this.comparitor.areSame(lines1, lines2)
|
|
||||||
return 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)
|
||||||
})
|
})
|
||||||
})
|
})
|
|
@ -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 = {
|
|
@ -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,
|
||||||
'../SplitTests/SplitTestHandler': this.SplitTestHandler,
|
'../../../../app/src/Features/SplitTests/SplitTestHandler':
|
||||||
'../SplitTests/SplitTestSessionHandler': this.SplitTestSessionHandler,
|
this.SplitTestHandler,
|
||||||
'../User/UserController': this.UserController,
|
'../../../../app/src/Features/SplitTests/SplitTestSessionHandler':
|
||||||
'./ProjectHelper': this.ProjectHelper,
|
this.SplitTestSessionHandler,
|
||||||
'../Subscription/LimitationsManager': this.LimitationsManager,
|
'../../../../app/src/Features/User/UserController': this.UserController,
|
||||||
'../Tags/TagsHandler': this.TagsHandler,
|
'../../../../app/src/Features/Project/ProjectHelper': this.ProjectHelper,
|
||||||
'../Notifications/NotificationsHandler': this.NotificationsHandler,
|
'../../../../app/src/Features/Subscription/LimitationsManager':
|
||||||
'../../models/User': { User: this.UserModel },
|
this.LimitationsManager,
|
||||||
'./ProjectGetter': this.ProjectGetter,
|
'../../../../app/src/Features/Tags/TagsHandler': this.TagsHandler,
|
||||||
'../Authentication/SessionManager': this.SessionManager,
|
'../../../../app/src/Features/Notifications/NotificationsHandler':
|
||||||
'../../infrastructure/Features': this.Features,
|
this.NotificationsHandler,
|
||||||
'../User/UserGetter': this.UserGetter,
|
'../../../../app/src/models/User': { User: this.UserModel },
|
||||||
'../Subscription/SubscriptionViewModelBuilder':
|
'../../../../app/src/Features/Project/ProjectGetter': this.ProjectGetter,
|
||||||
|
'../../../../app/src/Features/Authentication/SessionManager':
|
||||||
|
this.SessionManager,
|
||||||
|
'../../../../app/src/infrastructure/Features': this.Features,
|
||||||
|
'../../../../app/src/Features/User/UserGetter': this.UserGetter,
|
||||||
|
'../../../../app/src/Features/Subscription/SubscriptionViewModelBuilder':
|
||||||
this.SubscriptionViewModelBuilder,
|
this.SubscriptionViewModelBuilder,
|
||||||
'../../infrastructure/Modules': this.Modules,
|
'../../../../app/src/infrastructure/Modules': this.Modules,
|
||||||
'../Survey/SurveyHandler': this.SurveyHandler,
|
'../../../../app/src/Features/Survey/SurveyHandler': this.SurveyHandler,
|
||||||
'../User/UserPrimaryEmailCheckHandler':
|
'../../../../app/src/Features/User/UserPrimaryEmailCheckHandler':
|
||||||
this.UserPrimaryEmailCheckHandler,
|
this.UserPrimaryEmailCheckHandler,
|
||||||
'../Notifications/NotificationsBuilder': this.NotificationBuilder,
|
'../../../../app/src/Features/Notifications/NotificationsBuilder':
|
||||||
'../Subscription/SubscriptionLocator': this.SubscriptionLocator,
|
this.NotificationBuilder,
|
||||||
'../../infrastructure/GeoIpLookup': this.GeoIpLookup,
|
'../../../../app/src/Features/Subscription/SubscriptionLocator':
|
||||||
'../Tutorial/TutorialHandler': this.TutorialHandler,
|
this.SubscriptionLocator,
|
||||||
},
|
'../../../../app/src/infrastructure/GeoIpLookup': this.GeoIpLookup,
|
||||||
|
'../../../../app/src/Features/Tutorial/TutorialHandler':
|
||||||
|
this.TutorialHandler,
|
||||||
})
|
})
|
||||||
|
|
||||||
this.req = {
|
this.req = {
|
|
@ -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) {
|
|
@ -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, {})
|
|
||||||
})
|
|
||||||
})
|
|
|
@ -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, {})
|
||||||
|
})
|
||||||
|
})
|
|
@ -1,24 +1,22 @@
|
||||||
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'
|
||||||
})
|
})
|
|
@ -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' } },
|
||||||
}),
|
}),
|
||||||
'./ReferencesHandler': (this.ReferencesHandler = {
|
'../../../../app/src/Features/References/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()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
|
@ -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,8 +41,7 @@ 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' },
|
||||||
|
@ -59,25 +53,25 @@ describe('ReferencesHandler', function () {
|
||||||
get: sinon.stub(),
|
get: sinon.stub(),
|
||||||
post: sinon.stub(),
|
post: sinon.stub(),
|
||||||
}),
|
}),
|
||||||
'../Project/ProjectGetter': (this.ProjectGetter = {
|
'../../../../app/src/Features/Project/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(),
|
||||||
}),
|
}),
|
||||||
'../DocumentUpdater/DocumentUpdaterHandler':
|
'../../../../app/src/Features/DocumentUpdater/DocumentUpdaterHandler':
|
||||||
(this.DocumentUpdaterHandler = {
|
(this.DocumentUpdaterHandler = {
|
||||||
flushDocToMongo: sinon.stub().callsArgWith(2, null),
|
flushDocToMongo: sinon.stub().callsArgWith(2, null),
|
||||||
}),
|
}),
|
||||||
'../../infrastructure/Features': (this.Features = {
|
'../../../../app/src/infrastructure/Features': (this.Features = {
|
||||||
hasFeature: sinon.stub().returns(true),
|
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()
|
||||||
})
|
})
|
|
@ -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,9 +26,8 @@ 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: [
|
||||||
|
@ -37,9 +36,8 @@ describe('SpellingController', function () {
|
||||||
],
|
],
|
||||||
apis: { spelling: { host: SPELLING_HOST, url: SPELLING_URL } },
|
apis: { spelling: { host: SPELLING_HOST, url: SPELLING_URL } },
|
||||||
},
|
},
|
||||||
'../Authentication/AuthenticationController':
|
'../../../../app/src/Features/Authentication/AuthenticationController':
|
||||||
this.AuthenticationController,
|
this.AuthenticationController,
|
||||||
},
|
|
||||||
})
|
})
|
||||||
this.req = {
|
this.req = {
|
||||||
url: '/spelling/check',
|
url: '/spelling/check',
|
|
@ -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,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -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,
|
||||||
|
'../../../../app/src/Features/User/UserGetter': this.UserGetter,
|
||||||
|
'../../../../app/src/Features/Email/EmailHandler': this.EmailHandler,
|
||||||
|
'../../../../app/src/infrastructure/RateLimiter': this.RateLimiter,
|
||||||
|
'../../../../app/src/infrastructure/Modules': (this.Modules = {
|
||||||
promises: {
|
promises: {
|
||||||
hooks: {
|
hooks: {
|
||||||
fire: sinon.stub().resolves([]),
|
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({}),
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
},
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -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: {
|
|
@ -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'
|
|
@ -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,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -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,
|
||||||
'./TokenAccessHandler': this.TokenAccessHandler,
|
'../../../../app/src/Features/TokenAccess/TokenAccessHandler':
|
||||||
'../Authentication/AuthenticationController':
|
this.TokenAccessHandler,
|
||||||
|
'../../../../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.AuthorizationManager,
|
||||||
|
'../../../../app/src/Features/Authorization/AuthorizationMiddleware':
|
||||||
this.AuthorizationMiddleware,
|
this.AuthorizationMiddleware,
|
||||||
'../Project/ProjectAuditLogHandler': this.ProjectAuditLogHandler,
|
'../../../../app/src/Features/Project/ProjectAuditLogHandler':
|
||||||
'../SplitTests/SplitTestHandler': this.SplitTestHandler,
|
this.ProjectAuditLogHandler,
|
||||||
'../Errors/Errors': (this.Errors = { NotFoundError: sinon.stub() }),
|
'../../../../app/src/Features/SplitTests/SplitTestHandler':
|
||||||
'../Collaborators/CollaboratorsHandler': this.CollaboratorsHandler,
|
this.SplitTestHandler,
|
||||||
'../Collaborators/CollaboratorsInviteHandler':
|
'../../../../app/src/Features/Errors/Errors': (this.Errors = {
|
||||||
|
NotFoundError: sinon.stub(),
|
||||||
|
}),
|
||||||
|
'../../../../app/src/Features/Collaborators/CollaboratorsHandler':
|
||||||
|
this.CollaboratorsHandler,
|
||||||
|
'../../../../app/src/Features/Collaborators/CollaboratorsInviteHandler':
|
||||||
this.CollaboratorsInviteHandler,
|
this.CollaboratorsInviteHandler,
|
||||||
'../Collaborators/CollaboratorsGetter': this.CollaboratorsGetter,
|
'../../../../app/src/Features/Collaborators/CollaboratorsGetter':
|
||||||
'../Editor/EditorRealTimeController': this.EditorRealTimeController,
|
this.CollaboratorsGetter,
|
||||||
'../Project/ProjectGetter': this.ProjectGetter,
|
'../../../../app/src/Features/Editor/EditorRealTimeController':
|
||||||
'../Helpers/AsyncFormHelper': (this.AsyncFormHelper = {
|
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' }
|
||||||
})
|
})
|
|
@ -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: {} },
|
||||||
'./ProjectUploadManager': (this.ProjectUploadManager = {}),
|
'../../../../app/src/Features/Uploads/ProjectUploadManager':
|
||||||
'./FileSystemImportManager': (this.FileSystemImportManager = {}),
|
(this.ProjectUploadManager = {}),
|
||||||
|
'../../../../app/src/Features/Uploads/FileSystemImportManager':
|
||||||
|
(this.FileSystemImportManager = {}),
|
||||||
'@overleaf/metrics': this.metrics,
|
'@overleaf/metrics': this.metrics,
|
||||||
'../Authentication/SessionManager': this.SessionManager,
|
'../../../../app/src/Features/Authentication/SessionManager':
|
||||||
'./ArchiveErrors': ArchiveErrors,
|
this.SessionManager,
|
||||||
'../Project/ProjectLocator': this.ProjectLocator,
|
'../../../../app/src/Features/Uploads/ArchiveErrors': ArchiveErrors,
|
||||||
'../Editor/EditorController': this.EditorController,
|
'../../../../app/src/Features/Project/ProjectLocator':
|
||||||
|
this.ProjectLocator,
|
||||||
|
'../../../../app/src/Features/Editor/EditorController':
|
||||||
|
this.EditorController,
|
||||||
fs: (this.fs = {}),
|
fs: (this.fs = {}),
|
||||||
},
|
|
||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
|
|
|
@ -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,
|
||||||
'./UserGetter': this.UserGetter,
|
'../../../../app/src/Features/User/UserGetter': this.UserGetter,
|
||||||
'./UserSessionsManager': this.UserSessionsManager,
|
'../../../../app/src/Features/User/UserSessionsManager':
|
||||||
'../Newsletter/NewsletterManager': this.NewsletterManager,
|
this.UserSessionsManager,
|
||||||
'../Errors/ErrorController': this.ErrorController,
|
'../../../../app/src/Features/Newsletter/NewsletterManager':
|
||||||
'../Authentication/AuthenticationController':
|
this.NewsletterManager,
|
||||||
|
'../../../../app/src/Features/Errors/ErrorController':
|
||||||
|
this.ErrorController,
|
||||||
|
'../../../../app/src/Features/Authentication/AuthenticationController':
|
||||||
this.AuthenticationController,
|
this.AuthenticationController,
|
||||||
'../Subscription/SubscriptionLocator': this.SubscriptionLocator,
|
'../../../../app/src/Features/Subscription/SubscriptionLocator':
|
||||||
'../../infrastructure/Features': this.Features,
|
this.SubscriptionLocator,
|
||||||
|
'../../../../app/src/infrastructure/Features': this.Features,
|
||||||
'../../../../modules/oauth2-server/app/src/OAuthPersonalAccessTokenManager':
|
'../../../../modules/oauth2-server/app/src/OAuthPersonalAccessTokenManager':
|
||||||
this.PersonalAccessTokenManager,
|
this.PersonalAccessTokenManager,
|
||||||
'../Authentication/SessionManager': this.SessionManager,
|
'../../../../app/src/Features/Authentication/SessionManager':
|
||||||
'../SplitTests/SplitTestHandler': this.SplitTestHandler,
|
this.SessionManager,
|
||||||
'../../infrastructure/Modules': this.Modules,
|
'../../../../app/src/Features/SplitTests/SplitTestHandler':
|
||||||
|
this.SplitTestHandler,
|
||||||
|
'../../../../app/src/infrastructure/Modules': this.Modules,
|
||||||
request: (this.request = sinon.stub()),
|
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
|
|
@ -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,
|
'../../../../app/src/Features/Authentication/SessionManager':
|
||||||
'../SplitTests/SplitTestHandler': this.SplitTestHandler,
|
this.SessionManager,
|
||||||
'./UserMembershipHandler': this.UserMembershipHandler,
|
'../../../../app/src/Features/SplitTests/SplitTestHandler':
|
||||||
|
this.SplitTestHandler,
|
||||||
|
'../../../../app/src/Features/UserMembership/UserMembershipHandler':
|
||||||
|
this.UserMembershipHandler,
|
||||||
'@overleaf/settings': this.Settings,
|
'@overleaf/settings': this.Settings,
|
||||||
'../../models/SSOConfig': { SSOConfig: this.SSOConfig },
|
'../../../../app/src/models/SSOConfig': { SSOConfig: this.SSOConfig },
|
||||||
},
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue