From c371732e6e5b3aa0e2d491cbf92a88cf2a254451 Mon Sep 17 00:00:00 2001 From: Mathias Jakobsen Date: Mon, 18 Dec 2023 10:54:01 +0000 Subject: [PATCH] Merge pull request #16186 from overleaf/mj-mongo-object-id [web] Use constructor for ObjectId GitOrigin-RevId: 9eb8b377ea599605b72af237d1ab12f4d8287162 --- services/web/.eslintrc | 20 ++++++ .../Authentication/AuthenticationManager.js | 2 +- .../Collaborators/CollaboratorsController.js | 6 +- .../Collaborators/CollaboratorsGetter.js | 4 +- .../web/app/src/Features/Helpers/Mongo.js | 6 +- .../Institutions/InstitutionsManager.js | 8 +-- .../Project/FolderStructureBuilder.js | 2 +- .../ProjectCollabratecDetailsHandler.js | 20 +++--- .../src/Features/Project/ProjectController.js | 4 +- .../src/Features/Project/ProjectDeleter.js | 8 +-- .../Features/Project/ProjectEntityHandler.js | 6 +- .../ProjectEntityMongoUpdateHandler.js | 2 +- .../app/src/Features/Project/ProjectHelper.js | 6 +- .../Subscription/RecurlyEventHandler.js | 4 +- .../Subscription/SubscriptionUpdater.js | 8 +-- .../ThirdPartyDataStore/TpdsUpdateSender.js | 2 +- .../TokenAccess/TokenAccessHandler.js | 8 +-- .../src/Features/User/SAMLIdentityManager.js | 2 +- .../src/Features/User/UserInfoController.js | 2 +- .../UserMembership/UserMembershipHandler.js | 2 +- services/web/app/src/models/Project.js | 5 +- .../test/acceptance/src/HistoryTests.js | 10 +-- .../scripts/change-compile-timeout.js | 2 +- .../scripts/check-mongodb.js | 2 +- services/web/scripts/add_feature_override.js | 2 +- .../web/scripts/back_fill_dummy_doc_meta.js | 2 +- services/web/scripts/count_project_size.js | 2 +- .../delete-orphaned-docs.js | 8 +-- .../web/scripts/delete_dangling_file_refs.js | 2 +- .../scripts/delete_orphaned_chat_threads.js | 2 +- .../delete_orphaned_docs_online_check.js | 4 +- .../delete_orphaned_project_archives.js | 4 +- services/web/scripts/delete_subscriptions.js | 4 +- .../web/scripts/fix_malformed_filetree.js | 6 +- services/web/scripts/fix_oversized_docs.js | 4 +- services/web/scripts/force_doc_flush.js | 2 +- services/web/scripts/helpers/batchedUpdate.js | 6 +- services/web/scripts/invalidate_tokens.js | 2 +- .../merge_group_subscription_members.js | 4 +- services/web/scripts/migrate_audit_logs.js | 4 +- services/web/scripts/oauth/register_client.js | 2 +- .../web/scripts/recover_docs_from_redis.js | 4 +- services/web/scripts/set_tex_live_image.js | 4 +- services/web/scripts/stress_test.js | 2 +- .../acceptance/src/AuthenticationTests.js | 8 +-- .../src/BackFillDeletedFilesTests.js | 18 ++--- .../src/BackFillDocNameForDeletedDocsTests.js | 10 +-- .../acceptance/src/BackFillDocRevTests.js | 6 +- .../acceptance/src/ConvertArchivedState.js | 6 +- .../web/test/acceptance/src/DeletionTests.js | 8 ++- .../web/test/acceptance/src/DocUpdateTests.js | 2 +- .../web/test/acceptance/src/MongoHelper.js | 6 +- .../test/acceptance/src/ProjectCRUDTests.js | 6 +- .../acceptance/src/helpers/Institution.js | 2 +- .../test/acceptance/src/helpers/Publisher.js | 2 +- .../src/helpers/RecurlySubscription.js | 2 +- .../acceptance/src/helpers/Subscription.js | 6 +- .../web/test/acceptance/src/helpers/User.js | 20 +++--- .../test/acceptance/src/helpers/UserHelper.js | 2 +- .../acceptance/src/mocks/MockDocstoreApi.js | 2 +- .../src/Analytics/AnalyticsManagerTests.js | 10 +-- .../AuthenticationControllerTests.js | 2 +- .../AuthenticationManagerTests.js | 4 +- .../src/Authentication/SessionManagerTests.js | 2 +- .../CollaboratorsControllerTests.js | 4 +- .../Collaborators/CollaboratorsGetterTests.js | 20 +++--- .../CollaboratorsHandlerTests.js | 22 +++---- .../CollaboratorsInviteControllerTests.js | 8 +-- .../CollaboratorsInviteHandlerTests.js | 26 ++++---- .../OwnershipTransferHandlerTests.js | 13 ++-- .../unit/src/History/HistoryManagerTests.js | 2 +- .../Institutions/InstitutionsManagerTests.js | 54 ++++++++++----- .../Project/FolderStructureBuilderTests.js | 13 ++-- .../Project/ProjectCollabratecDetailsTest.js | 10 +-- .../src/Project/ProjectControllerTests.js | 6 +- .../unit/src/Project/ProjectDeleterTests.js | 16 ++--- .../src/Project/ProjectDetailsHandlerTests.js | 6 +- .../ProjectEntityMongoUpdateHandlerTests.js | 42 ++++++------ .../ProjectEntityUpdateHandlerTests.js | 8 +-- .../unit/src/Project/ProjectHelperTests.js | 66 ++++++++++--------- .../src/Project/ProjectListControllerTests.js | 4 +- .../src/SplitTests/SplitTestHandlerTests.js | 6 +- .../src/Subscription/GroupSSOHandlerTests.js | 2 +- .../Subscription/SubscriptionUpdaterTests.js | 18 ++--- .../test/unit/src/Tags/TagsHandlerTests.js | 8 +-- .../TpdsControllerTests.js | 18 ++--- .../TpdsProjectFlusherTests.js | 4 +- .../TpdsUpdateHandlerTests.js | 8 +-- .../TpdsUpdateSenderTests.js | 6 +- .../ThirdPartyDataStore/UpdateMergerTests.js | 6 +- .../TokenAccess/TokenAccessControllerTests.js | 4 +- .../TokenAccess/TokenAccessHandlerTests.js | 6 +- .../unit/src/User/SAMLIdentityManagerTests.js | 2 +- .../unit/src/User/UserAuditLogHandlerTests.js | 4 +- .../test/unit/src/User/UserDeleterTests.js | 4 +- .../unit/src/User/UserInfoControllerTests.js | 14 ++-- .../test/unit/src/User/UserUpdaterTests.js | 6 +- .../UserMembershipHandlerTests.js | 14 ++-- .../UserMembershipViewModelTests.js | 4 +- .../UserMembershipsHandlerTests.js | 2 +- 100 files changed, 423 insertions(+), 368 deletions(-) diff --git a/services/web/.eslintrc b/services/web/.eslintrc index 73bcc8de0b..e897b06892 100644 --- a/services/web/.eslintrc +++ b/services/web/.eslintrc @@ -102,6 +102,26 @@ ] } }, + { + // Backend + backend tests specific rules + "files": ["**/app/src/**/*.js", "app.js", "**/test/**/*.*", "**/scripts/*.*"], + "rules": { + // do not allow node-fetch in backend code + "no-restricted-syntax": [ + "error", + // Require `new` when constructing ObjectId (For mongo + mongoose upgrade) + { + "selector": "CallExpression[callee.name='ObjectId'], CallExpression[callee.property.name='ObjectId']", + "message": "Construct ObjectId with `new ObjectId()` instead of `ObjectId()`" + }, + // Require `new` when mapping a list of ids to a list of ObjectId (For mongo + mongoose upgrade) + { + "selector": "CallExpression[callee.property.name='map'] Identifier[name='ObjectId']:first-child, CallExpression[callee.property.name='map'] MemberExpression[property.name='ObjectId']:first-child", + "message": "Don't map ObjectId directly. Use `id => new ObjectId(id)` instead" + } + ] + } + }, { // Cypress specific rules "files": ["cypress/**/*.{js,jsx,ts,tsx}", "**/test/frontend/**/*.spec.{js,jsx,ts,tsx}"], diff --git a/services/web/app/src/Features/Authentication/AuthenticationManager.js b/services/web/app/src/Features/Authentication/AuthenticationManager.js index 2fa0552f91..fdde74037e 100644 --- a/services/web/app/src/Features/Authentication/AuthenticationManager.js +++ b/services/web/app/src/Features/Authentication/AuthenticationManager.js @@ -369,7 +369,7 @@ const AuthenticationManager = { return callback(error) } db.users.updateOne( - { _id: ObjectId(user._id.toString()) }, + { _id: new ObjectId(user._id.toString()) }, { $set: { hashedPassword: hash, diff --git a/services/web/app/src/Features/Collaborators/CollaboratorsController.js b/services/web/app/src/Features/Collaborators/CollaboratorsController.js index a86f4fface..d2959ecd28 100644 --- a/services/web/app/src/Features/Collaborators/CollaboratorsController.js +++ b/services/web/app/src/Features/Collaborators/CollaboratorsController.js @@ -105,7 +105,7 @@ async function transferOwnership(req, res, next) { toUserId, { allowTransferToNonCollaborators: hasAdminAccess(sessionUser), - sessionUserId: ObjectId(sessionUser._id), + sessionUserId: new ObjectId(sessionUser._id), } ) res.sendStatus(204) @@ -143,8 +143,8 @@ async function getShareTokens(req, res) { let tokens if (userId) { tokens = await CollaboratorsGetter.promises.getPublicShareTokens( - ObjectId(userId), - ObjectId(projectId) + new ObjectId(userId), + new ObjectId(projectId) ) } else { // anonymous access, the token is already available in the session diff --git a/services/web/app/src/Features/Collaborators/CollaboratorsGetter.js b/services/web/app/src/Features/Collaborators/CollaboratorsGetter.js index 06a84d1102..3dfcadd225 100644 --- a/services/web/app/src/Features/Collaborators/CollaboratorsGetter.js +++ b/services/web/app/src/Features/Collaborators/CollaboratorsGetter.js @@ -209,8 +209,8 @@ async function getAllInvitedMembers(projectId) { } async function userIsTokenMember(userId, projectId) { - userId = ObjectId(userId.toString()) - projectId = ObjectId(projectId.toString()) + userId = new ObjectId(userId.toString()) + projectId = new ObjectId(projectId.toString()) const project = await Project.findOne( { _id: projectId, diff --git a/services/web/app/src/Features/Helpers/Mongo.js b/services/web/app/src/Features/Helpers/Mongo.js index fd5bd1da38..f2121ac009 100644 --- a/services/web/app/src/Features/Helpers/Mongo.js +++ b/services/web/app/src/Features/Helpers/Mongo.js @@ -4,11 +4,11 @@ const { ObjectId: MongooseObjectId } = require('mongoose').mongo function _getObjectIdInstance(id) { if (typeof id === 'string') { - return ObjectId(id) + return new ObjectId(id) } else if (id instanceof ObjectId) { return id } else if (id instanceof MongooseObjectId) { - return ObjectId(id.toString()) + return new ObjectId(id.toString()) } else { throw new OError('unexpected object id', { id }) } @@ -25,7 +25,7 @@ function normalizeQuery(query) { ) { return { _id: _getObjectIdInstance(query) } } else if (typeof query._id === 'string') { - query._id = ObjectId(query._id) + query._id = new ObjectId(query._id) return query } else { return query diff --git a/services/web/app/src/Features/Institutions/InstitutionsManager.js b/services/web/app/src/Features/Institutions/InstitutionsManager.js index 4e543123bb..a410314e54 100644 --- a/services/web/app/src/Features/Institutions/InstitutionsManager.js +++ b/services/web/app/src/Features/Institutions/InstitutionsManager.js @@ -244,8 +244,8 @@ const InstitutionsManager = { if (error) { return callback(error) } - const userIds = affiliations.map(affiliation => - ObjectId(affiliation.user_id) + const userIds = affiliations.map( + affiliation => new ObjectId(affiliation.user_id) ) Subscription.find({ admin_id: userIds }) .populate('admin_id', 'email') @@ -294,12 +294,12 @@ const fetchInstitutionAndAffiliations = (institutionId, callback) => ) function refreshFeatures(affiliation, callback) { - const userId = ObjectId(affiliation.user_id) + const userId = new ObjectId(affiliation.user_id) FeaturesUpdater.refreshFeatures(userId, 'refresh-institution-users', callback) } function refreshFeaturesAndNotify(affiliation, callback) { - const userId = ObjectId(affiliation.user_id) + const userId = new ObjectId(affiliation.user_id) async.waterfall( [ cb => diff --git a/services/web/app/src/Features/Project/FolderStructureBuilder.js b/services/web/app/src/Features/Project/FolderStructureBuilder.js index c53e4f652b..ddf6f4bb48 100644 --- a/services/web/app/src/Features/Project/FolderStructureBuilder.js +++ b/services/web/app/src/Features/Project/FolderStructureBuilder.js @@ -63,7 +63,7 @@ class FolderStructureBuilder { createFolder(name) { return { - _id: ObjectId(), + _id: new ObjectId(), name, folders: [], docs: [], diff --git a/services/web/app/src/Features/Project/ProjectCollabratecDetailsHandler.js b/services/web/app/src/Features/Project/ProjectCollabratecDetailsHandler.js index 2b92d606ab..7c52ed74f5 100644 --- a/services/web/app/src/Features/Project/ProjectCollabratecDetailsHandler.js +++ b/services/web/app/src/Features/Project/ProjectCollabratecDetailsHandler.js @@ -43,8 +43,8 @@ module.exports = ProjectCollabratecDetailsHandler = { callback = function () {} } try { - projectId = ObjectId(projectId) - userId = ObjectId(userId) + projectId = new ObjectId(projectId) + userId = new ObjectId(userId) } catch (error) { const err = error return callback(err) @@ -75,8 +75,8 @@ module.exports = ProjectCollabratecDetailsHandler = { callback = function () {} } try { - projectId = ObjectId(projectId) - userId = ObjectId(userId) + projectId = new ObjectId(projectId) + userId = new ObjectId(userId) } catch (error) { const err = error return callback(err) @@ -109,7 +109,7 @@ module.exports = ProjectCollabratecDetailsHandler = { callback = function () {} } try { - projectId = ObjectId(projectId) + projectId = new ObjectId(projectId) } catch (error) { err = error return callback(err) @@ -119,7 +119,7 @@ module.exports = ProjectCollabratecDetailsHandler = { } for (const collabratecUser of Array.from(collabratecUsers)) { try { - collabratecUser.user_id = ObjectId(collabratecUser.user_id) + collabratecUser.user_id = new ObjectId(collabratecUser.user_id) } catch (error1) { err = error1 return callback(err) @@ -134,8 +134,8 @@ module.exports = ProjectCollabratecDetailsHandler = { callback = function () {} } try { - projectId = ObjectId(projectId) - userId = ObjectId(userId) + projectId = new ObjectId(projectId) + userId = new ObjectId(userId) } catch (error) { const err = error return callback(err) @@ -156,8 +156,8 @@ module.exports = ProjectCollabratecDetailsHandler = { callback = function () {} } try { - oldUserId = ObjectId(oldUserId) - newUserId = ObjectId(newUserId) + oldUserId = new ObjectId(oldUserId) + newUserId = new ObjectId(newUserId) } catch (error) { const err = error return callback(err) diff --git a/services/web/app/src/Features/Project/ProjectController.js b/services/web/app/src/Features/Project/ProjectController.js index 49b12c98cd..fd80b48f01 100644 --- a/services/web/app/src/Features/Project/ProjectController.js +++ b/services/web/app/src/Features/Project/ProjectController.js @@ -435,7 +435,7 @@ const ProjectController = { cb(null, defaultSettingsForAnonymousUser(userId)) } else { User.updateOne( - { _id: ObjectId(userId) }, + { _id: new ObjectId(userId) }, { $set: { lastActive: new Date() } }, {}, () => {} @@ -753,7 +753,7 @@ const ProjectController = { } else if ( Settings.wsUrlV2 && Settings.wsUrlV2Percentage > 0 && - (ObjectId(projectId).getTimestamp() / 1000) % 100 < + (new ObjectId(projectId).getTimestamp() / 1000) % 100 < Settings.wsUrlV2Percentage ) { wsUrl = Settings.wsUrlV2 diff --git a/services/web/app/src/Features/Project/ProjectDeleter.js b/services/web/app/src/Features/Project/ProjectDeleter.js index 35fcf2e25a..f159e2bb76 100644 --- a/services/web/app/src/Features/Project/ProjectDeleter.js +++ b/services/web/app/src/Features/Project/ProjectDeleter.js @@ -128,7 +128,7 @@ async function archiveProject(projectId, userId) { await Project.updateOne( { _id: projectId }, - { $set: { archived }, $pull: { trashed: ObjectId(userId) } } + { $set: { archived }, $pull: { trashed: new ObjectId(userId) } } ) } catch (err) { logger.warn({ err }, 'problem archiving project') @@ -172,7 +172,7 @@ async function trashProject(projectId, userId) { await Project.updateOne( { _id: projectId }, { - $addToSet: { trashed: ObjectId(userId) }, + $addToSet: { trashed: new ObjectId(userId) }, $set: { archived }, } ) @@ -191,7 +191,7 @@ async function untrashProject(projectId, userId) { await Project.updateOne( { _id: projectId }, - { $pull: { trashed: ObjectId(userId) } } + { $pull: { trashed: new ObjectId(userId) } } ) } catch (err) { logger.warn({ err }, 'problem untrashing project') @@ -280,7 +280,7 @@ async function deleteProject(projectId, options = {}) { } async function undeleteProject(projectId, options = {}) { - projectId = ObjectId(projectId) + projectId = new ObjectId(projectId) const deletedProject = await DeletedProject.findOne({ 'deleterData.deletedProjectId': projectId, }).exec() diff --git a/services/web/app/src/Features/Project/ProjectEntityHandler.js b/services/web/app/src/Features/Project/ProjectEntityHandler.js index bc87e8dc4c..8cc9b33c7d 100644 --- a/services/web/app/src/Features/Project/ProjectEntityHandler.js +++ b/services/web/app/src/Features/Project/ProjectEntityHandler.js @@ -148,8 +148,8 @@ const ProjectEntityHandler = { }, /** - * @param {ObjectID | string} projectId - * @param {ObjectID | string} docId + * @param {ObjectId | string} projectId + * @param {ObjectId | string} docId * @param {Function} callback */ getDocPathByProjectIdAndDocId(projectId, docId, callback) { @@ -176,7 +176,7 @@ const ProjectEntityHandler = { /** * @param {Project} project - * @param {ObjectID | string} docId + * @param {ObjectId | string} docId * @param {Function} callback */ getDocPathFromProjectByDocId(project, docId, callback) { diff --git a/services/web/app/src/Features/Project/ProjectEntityMongoUpdateHandler.js b/services/web/app/src/Features/Project/ProjectEntityMongoUpdateHandler.js index 1a5ace6fb4..dfbbfa5d96 100644 --- a/services/web/app/src/Features/Project/ProjectEntityMongoUpdateHandler.js +++ b/services/web/app/src/Features/Project/ProjectEntityMongoUpdateHandler.js @@ -568,7 +568,7 @@ async function _putElement(project, folderId, element, type) { throw new Errors.InvalidNameError('blocked element name') } _checkValidElementName(folder, element.name) - element._id = ObjectId(element._id.toString()) + element._id = new ObjectId(element._id.toString()) const mongoPath = `${path.mongo}.${pathSegment}` const newProject = await Project.findOneAndUpdate( { _id: project._id, [path.mongo]: { $exists: true } }, diff --git a/services/web/app/src/Features/Project/ProjectHelper.js b/services/web/app/src/Features/Project/ProjectHelper.js index 2d1ac2ef35..e7c0232b6b 100644 --- a/services/web/app/src/Features/Project/ProjectHelper.js +++ b/services/web/app/src/Features/Project/ProjectHelper.js @@ -37,7 +37,7 @@ function compilerFromV1Engine(engine) { * @returns {boolean} */ function isArchived(project, userId) { - userId = ObjectId(userId) + userId = new ObjectId(userId) return (project.archived || []).some(id => id.equals(userId)) } @@ -48,7 +48,7 @@ function isArchived(project, userId) { * @returns {boolean} */ function isTrashed(project, userId) { - userId = ObjectId(userId) + userId = new ObjectId(userId) return (project.trashed || []).some(id => id.equals(userId)) } @@ -75,7 +75,7 @@ function _allCollaborators(project) { function calculateArchivedArray(project, userId, action) { let archived = project.archived - userId = ObjectId(userId) + userId = new ObjectId(userId) if (archived === true) { archived = _allCollaborators(project) diff --git a/services/web/app/src/Features/Subscription/RecurlyEventHandler.js b/services/web/app/src/Features/Subscription/RecurlyEventHandler.js index aed2671dac..9aa4851b1d 100644 --- a/services/web/app/src/Features/Subscription/RecurlyEventHandler.js +++ b/services/web/app/src/Features/Subscription/RecurlyEventHandler.js @@ -1,12 +1,12 @@ const AnalyticsManager = require('../Analytics/AnalyticsManager') const SubscriptionEmailHandler = require('./SubscriptionEmailHandler') -const { ObjectID } = require('mongodb') +const { ObjectId } = require('mongodb') const INVOICE_SUBSCRIPTION_LIMIT = 10 async function sendRecurlyAnalyticsEvent(event, eventData) { const userId = _getUserId(eventData) - if (!ObjectID.isValid(userId)) { + if (!ObjectId.isValid(userId)) { return } diff --git a/services/web/app/src/Features/Subscription/SubscriptionUpdater.js b/services/web/app/src/Features/Subscription/SubscriptionUpdater.js index 0b7284e5ba..7fee0f1a58 100644 --- a/services/web/app/src/Features/Subscription/SubscriptionUpdater.js +++ b/services/web/app/src/Features/Subscription/SubscriptionUpdater.js @@ -27,16 +27,16 @@ const UserAuditLogHandler = require('../User/UserAuditLogHandler') */ async function updateAdmin(subscription, adminId) { const query = { - _id: ObjectId(subscription._id), + _id: new ObjectId(subscription._id), customAccount: true, } const update = { - $set: { admin_id: ObjectId(adminId) }, + $set: { admin_id: new ObjectId(adminId) }, } if (subscription.groupPlan) { - update.$addToSet = { manager_ids: ObjectId(adminId) } + update.$addToSet = { manager_ids: new ObjectId(adminId) } } else { - update.$set.manager_ids = [ObjectId(adminId)] + update.$set.manager_ids = [new ObjectId(adminId)] } await Subscription.updateOne(query, update).exec() } diff --git a/services/web/app/src/Features/ThirdPartyDataStore/TpdsUpdateSender.js b/services/web/app/src/Features/ThirdPartyDataStore/TpdsUpdateSender.js index 6713d5cfd2..4339260308 100644 --- a/services/web/app/src/Features/ThirdPartyDataStore/TpdsUpdateSender.js +++ b/services/web/app/src/Features/ThirdPartyDataStore/TpdsUpdateSender.js @@ -224,7 +224,7 @@ async function getProjectUsersIds(projectId) { // filter invited users to only return those with dropbox linked const dropboxUsers = await UserGetter.getUsers( { - _id: { $in: userIds.map(id => ObjectId(id)) }, + _id: { $in: userIds.map(id => new ObjectId(id)) }, 'dropbox.access_token.uid': { $ne: null }, }, { diff --git a/services/web/app/src/Features/TokenAccess/TokenAccessHandler.js b/services/web/app/src/Features/TokenAccess/TokenAccessHandler.js index 081ea24ef3..9855ae02c2 100644 --- a/services/web/app/src/Features/TokenAccess/TokenAccessHandler.js +++ b/services/web/app/src/Features/TokenAccess/TokenAccessHandler.js @@ -168,8 +168,8 @@ const TokenAccessHandler = { }, addReadOnlyUserToProject(userId, projectId, callback) { - userId = ObjectId(userId.toString()) - projectId = ObjectId(projectId.toString()) + userId = new ObjectId(userId.toString()) + projectId = new ObjectId(projectId.toString()) Analytics.recordEventForUser(userId, 'project-joined', { mode: 'read-only', }) @@ -185,8 +185,8 @@ const TokenAccessHandler = { }, addReadAndWriteUserToProject(userId, projectId, callback) { - userId = ObjectId(userId.toString()) - projectId = ObjectId(projectId.toString()) + userId = new ObjectId(userId.toString()) + projectId = new ObjectId(projectId.toString()) Analytics.recordEventForUser(userId, 'project-joined', { mode: 'read-write', }) diff --git a/services/web/app/src/Features/User/SAMLIdentityManager.js b/services/web/app/src/Features/User/SAMLIdentityManager.js index 38bc2d41f6..5bfb4a8ddd 100644 --- a/services/web/app/src/Features/User/SAMLIdentityManager.js +++ b/services/web/app/src/Features/User/SAMLIdentityManager.js @@ -24,7 +24,7 @@ async function _addAuditLogEntry(operation, userId, auditLog, extraInfo) { async function _ensureCanAddIdentifier(userId, institutionEmail, providerId) { const userWithProvider = await UserGetter.promises.getUser( - { _id: ObjectId(userId), 'samlIdentifiers.providerId': providerId }, + { _id: new ObjectId(userId), 'samlIdentifiers.providerId': providerId }, { _id: 1 } ) diff --git a/services/web/app/src/Features/User/UserInfoController.js b/services/web/app/src/Features/User/UserInfoController.js index 43f0c923e8..a821733a91 100644 --- a/services/web/app/src/Features/User/UserInfoController.js +++ b/services/web/app/src/Features/User/UserInfoController.js @@ -33,7 +33,7 @@ function getPersonalInfo(req, res, next) { if (/^\d+$/.test(userId)) { query = { 'overleaf.id': parseInt(userId, 10) } } else if (/^[a-f0-9]{24}$/.test(userId)) { - query = { _id: ObjectId(userId) } + query = { _id: new ObjectId(userId) } } else { return res.sendStatus(400) } diff --git a/services/web/app/src/Features/UserMembership/UserMembershipHandler.js b/services/web/app/src/Features/UserMembership/UserMembershipHandler.js index 1bcd497ba2..7404b4d6f8 100644 --- a/services/web/app/src/Features/UserMembership/UserMembershipHandler.js +++ b/services/web/app/src/Features/UserMembership/UserMembershipHandler.js @@ -143,7 +143,7 @@ function removeUserFromEntity(entity, attribute, userId, callback) { function buildEntityQuery(entityId, entityConfig, loggedInUser) { if (ObjectId.isValid(entityId.toString())) { - entityId = ObjectId(entityId) + entityId = new ObjectId(entityId) } const query = Object.assign({}, entityConfig.baseQuery) query[entityConfig.fields.primaryKey] = entityId diff --git a/services/web/app/src/models/Project.js b/services/web/app/src/models/Project.js index 14e2f9d9f1..e78ed556f4 100644 --- a/services/web/app/src/models/Project.js +++ b/services/web/app/src/models/Project.js @@ -3,7 +3,7 @@ const _ = require('underscore') const { FolderSchema } = require('./Folder') const Errors = require('../Features/Errors/Errors') -const concreteObjectId = mongoose.Types.ObjectId +const ConcreteObjectId = mongoose.Types.ObjectId const { Schema } = mongoose const { ObjectId } = Schema @@ -119,7 +119,8 @@ ProjectSchema.statics.getProject = function (projectOrId, fields, callback) { callback(null, projectOrId) } else { try { - concreteObjectId(projectOrId.toString()) + // eslint-disable-next-line no-new + new ConcreteObjectId(projectOrId.toString()) } catch (e) { return callback(new Errors.NotFoundError(e.message)) } diff --git a/services/web/modules/history-v1/test/acceptance/src/HistoryTests.js b/services/web/modules/history-v1/test/acceptance/src/HistoryTests.js index bb3639011b..3682282306 100644 --- a/services/web/modules/history-v1/test/acceptance/src/HistoryTests.js +++ b/services/web/modules/history-v1/test/acceptance/src/HistoryTests.js @@ -42,7 +42,7 @@ describe('History', function () { this.v1_history_id = 42 return db.projects.updateOne( { - _id: ObjectId(this.project_id), + _id: new ObjectId(this.project_id), }, { $set: { @@ -90,7 +90,7 @@ describe('History', function () { } this.v1_history_id = 42 db.projects.updateOne( - { _id: ObjectId(this.project_id) }, + { _id: new ObjectId(this.project_id) }, { $set: { 'overleaf.history.id': this.v1_history_id, @@ -202,7 +202,7 @@ describe('History', function () { } return db.projects.updateOne( { - _id: ObjectId(this.project_id), + _id: new ObjectId(this.project_id), }, { $unset: { @@ -260,7 +260,7 @@ describe('History', function () { this.v1_history_id = 42 return db.projects.updateOne( { - _id: ObjectId(this.project_id), + _id: new ObjectId(this.project_id), }, { $set: { @@ -324,7 +324,7 @@ describe('History', function () { this.v1_history_id = 42 return db.projects.updateOne( { - _id: ObjectId(this.project_id), + _id: new ObjectId(this.project_id), }, { $set: { diff --git a/services/web/modules/server-ce-scripts/scripts/change-compile-timeout.js b/services/web/modules/server-ce-scripts/scripts/change-compile-timeout.js index 072ce9b608..ca99e6233f 100644 --- a/services/web/modules/server-ce-scripts/scripts/change-compile-timeout.js +++ b/services/web/modules/server-ce-scripts/scripts/change-compile-timeout.js @@ -34,7 +34,7 @@ async function main() { } await db.users.updateOne( - { _id: ObjectId(userId) }, + { _id: new ObjectId(userId) }, { $set: { 'features.compileTimeout': compileTimeout } } ) } diff --git a/services/web/modules/server-ce-scripts/scripts/check-mongodb.js b/services/web/modules/server-ce-scripts/scripts/check-mongodb.js index 38dcc8ca7f..112e66e8a2 100644 --- a/services/web/modules/server-ce-scripts/scripts/check-mongodb.js +++ b/services/web/modules/server-ce-scripts/scripts/check-mongodb.js @@ -22,7 +22,7 @@ async function testTransactions() { const session = mongoClient.startSession() try { await session.withTransaction(async () => { - await db.users.findOne({ _id: ObjectId() }, { session }) + await db.users.findOne({ _id: new ObjectId() }, { session }) }) } finally { await session.endSession() diff --git a/services/web/scripts/add_feature_override.js b/services/web/scripts/add_feature_override.js index a2fb9d5c95..e53fbe3e6a 100644 --- a/services/web/scripts/add_feature_override.js +++ b/services/web/scripts/add_feature_override.js @@ -168,7 +168,7 @@ async function processUsers(userIds) { const limit = pLimit(CONCURRENCY) const results = await Promise.allSettled( - userIds.map(userId => limit(() => _handleUser(ObjectId(userId)))) + userIds.map(userId => limit(() => _handleUser(new ObjectId(userId)))) ) results.forEach((result, idx) => { if (result.status !== 'fulfilled') { diff --git a/services/web/scripts/back_fill_dummy_doc_meta.js b/services/web/scripts/back_fill_dummy_doc_meta.js index 30a4aa011c..9aad52107c 100644 --- a/services/web/scripts/back_fill_dummy_doc_meta.js +++ b/services/web/scripts/back_fill_dummy_doc_meta.js @@ -29,7 +29,7 @@ async function main(options) { _.defaults(options, { dryRun: process.env.DRY_RUN === 'true', cacheSize: parseInt(process.env.CACHE_SIZE, 10) || 100, - firstProjectId: ObjectId(process.env.FIRST_PROJECT_ID), + firstProjectId: new ObjectId(process.env.FIRST_PROJECT_ID), incrementByS: parseInt(process.env.INCREMENT_BY_S, 10) || ONE_WEEK_IN_S, batchSize: parseInt(process.env.BATCH_SIZE, 10) || 1000, stopAtS: parseInt(process.env.STOP_AT_S, 10) || NOW_IN_S, diff --git a/services/web/scripts/count_project_size.js b/services/web/scripts/count_project_size.js index e956fc04bb..a0bca153f3 100644 --- a/services/web/scripts/count_project_size.js +++ b/services/web/scripts/count_project_size.js @@ -100,7 +100,7 @@ async function countDocsSizes(docs) { for (const docId of ids) { const result = await db.docs.aggregate([ { - $match: { _id: ObjectId(docId) }, + $match: { _id: new ObjectId(docId) }, }, { $project: { diff --git a/services/web/scripts/delete-orphaned-docs/delete-orphaned-docs.js b/services/web/scripts/delete-orphaned-docs/delete-orphaned-docs.js index faf4a0089c..967761672a 100644 --- a/services/web/scripts/delete-orphaned-docs/delete-orphaned-docs.js +++ b/services/web/scripts/delete-orphaned-docs/delete-orphaned-docs.js @@ -48,8 +48,8 @@ rl.on('line', async line => { projectId = projectId.replace(/^ObjectId\(/, '').replace(/\)$/, '') try { - docId = ObjectId(docId).toString() - projectId = ObjectId(projectId).toString() + docId = new ObjectId(docId).toString() + projectId = new ObjectId(projectId).toString() } catch (err) { console.error(`Invalid id: ${docId}, ${projectId}`) return @@ -114,14 +114,14 @@ async function projectIdExists(projectId) { async function findProject(projectId) { return db.projects.findOne( - { _id: ObjectId(projectId) }, + { _id: new ObjectId(projectId) }, { projection: { _id: 1 } } ) } async function findDeletedProject(projectId) { return db.deletedProjects.findOne( - { 'project._id': ObjectId(projectId) }, + { 'project._id': new ObjectId(projectId) }, { projection: { _id: 1 } } ) } diff --git a/services/web/scripts/delete_dangling_file_refs.js b/services/web/scripts/delete_dangling_file_refs.js index 521add216c..ffad97a8b5 100644 --- a/services/web/scripts/delete_dangling_file_refs.js +++ b/services/web/scripts/delete_dangling_file_refs.js @@ -43,7 +43,7 @@ async function main() { } async function getProjects() { - const projectIds = OPTIONS.projectIds.map(id => ObjectId(id)) + const projectIds = OPTIONS.projectIds.map(id => new ObjectId(id)) const projects = await db.projects .find( { _id: { $in: projectIds } }, diff --git a/services/web/scripts/delete_orphaned_chat_threads.js b/services/web/scripts/delete_orphaned_chat_threads.js index 7a2dce6ebc..d68417faf0 100644 --- a/services/web/scripts/delete_orphaned_chat_threads.js +++ b/services/web/scripts/delete_orphaned_chat_threads.js @@ -38,7 +38,7 @@ async function processBatch(rooms) { } const projectIds = Array.from( new Set(rooms.map(room => room.project_id.toString())) - ).map(ObjectId) + ).map(id => new ObjectId(id)) console.log( `Checking projects (${projectIds.length})`, JSON.stringify(projectIds) diff --git a/services/web/scripts/delete_orphaned_docs_online_check.js b/services/web/scripts/delete_orphaned_docs_online_check.js index 49dd750a89..c0a7789d51 100644 --- a/services/web/scripts/delete_orphaned_docs_online_check.js +++ b/services/web/scripts/delete_orphaned_docs_online_check.js @@ -20,7 +20,7 @@ if (!process.env.BATCH_LAST_ID) { console.error('Set BATCH_LAST_ID and re-run.') process.exit(1) } -const BATCH_LAST_ID = ObjectId(process.env.BATCH_LAST_ID) +const BATCH_LAST_ID = new ObjectId(process.env.BATCH_LAST_ID) const INCREMENT_BY_S = parseInt(process.env.INCREMENT_BY_S, 10) || ONE_WEEK_IN_S const BATCH_SIZE = parseInt(process.env.BATCH_SIZE, 10) || 1000 const READ_CONCURRENCY_SECONDARY = @@ -66,7 +66,7 @@ async function main() { if (docs.length) { const projectIds = Array.from( new Set(docs.map(doc => doc.project_id.toString())) - ).map(ObjectId) + ).map(id => new ObjectId(id)) console.log('Checking projects', JSON.stringify(projectIds)) const { nProjectsWithOrphanedDocs, nDeletedDocs } = await processBatch( projectIds diff --git a/services/web/scripts/delete_orphaned_project_archives.js b/services/web/scripts/delete_orphaned_project_archives.js index 24edce4388..7781574214 100644 --- a/services/web/scripts/delete_orphaned_project_archives.js +++ b/services/web/scripts/delete_orphaned_project_archives.js @@ -59,8 +59,8 @@ async function processBatch(entries) { prefixes.push(prefix) projectIdToPrefix.set(projectId, prefixes) } - const projectIds = Array.from(projectIdToPrefix.keys()).map(id => - ObjectId(id) + const projectIds = Array.from(projectIdToPrefix.keys()).map( + id => new ObjectId(id) ) const projectsWithOrphanedArchive = await getHardDeletedProjectIds({ projectIds, diff --git a/services/web/scripts/delete_subscriptions.js b/services/web/scripts/delete_subscriptions.js index 9705c63cd0..93f5842130 100644 --- a/services/web/scripts/delete_subscriptions.js +++ b/services/web/scripts/delete_subscriptions.js @@ -8,7 +8,7 @@ const { ObjectId } = require('mongodb') const run = async () => { for (const id of ids) { console.log('id', id) - const subscription = await Subscription.findOne({ _id: ObjectId(id) }) + const subscription = await Subscription.findOne({ _id: new ObjectId(id) }) await SubscriptionUpdater.promises.deleteSubscription( subscription, deleterData @@ -33,7 +33,7 @@ const setup = () => { process.exit(1) } - deleterData = { id: ObjectId(deleterId) } + deleterData = { id: new ObjectId(deleterId) } } setup() diff --git a/services/web/scripts/fix_malformed_filetree.js b/services/web/scripts/fix_malformed_filetree.js index 9c7e34f93a..c4c5d15966 100644 --- a/services/web/scripts/fix_malformed_filetree.js +++ b/services/web/scripts/fix_malformed_filetree.js @@ -45,7 +45,7 @@ function parseArgs() { process.exit(1) } const [projectId, mongoPath] = args - return { projectId: ObjectId(projectId), mongoPath } + return { projectId: new ObjectId(projectId), mongoPath } } function isRootFolder(path) { @@ -86,7 +86,7 @@ async function fixRootFolder(projectId) { $set: { rootFolder: [ { - _id: ObjectId(), + _id: new ObjectId(), name: 'rootFolder', folders: [], docs: [], @@ -127,7 +127,7 @@ async function fixArray(projectId, path) { async function fixFolderId(projectId, path) { const result = await db.projects.updateOne( { _id: projectId, [path]: { $exists: false } }, - { $set: { [path]: ObjectId() } } + { $set: { [path]: new ObjectId() } } ) return result.modifiedCount } diff --git a/services/web/scripts/fix_oversized_docs.js b/services/web/scripts/fix_oversized_docs.js index 3c7a69e302..c3aada1b64 100644 --- a/services/web/scripts/fix_oversized_docs.js +++ b/services/web/scripts/fix_oversized_docs.js @@ -75,8 +75,8 @@ async function processDoc(projectId, docId) { if (opts.commit) { const fileRef = await sendDocToFilestore(projectId, doc) await ProjectEntityMongoUpdateHandler.promises.replaceDocWithFile( - ObjectId(projectId), - ObjectId(docId), + new ObjectId(projectId), + new ObjectId(docId), fileRef ) await deleteDocFromMongo(projectId, doc) diff --git a/services/web/scripts/force_doc_flush.js b/services/web/scripts/force_doc_flush.js index 7727f622ff..ed39265758 100644 --- a/services/web/scripts/force_doc_flush.js +++ b/services/web/scripts/force_doc_flush.js @@ -28,7 +28,7 @@ async function main() { if (!DRY_RUN) { console.log(`updating doc ${DOC_ID} in mongo for project ${PROJECT_ID}`) const result = await db.docs.updateOne( - { _id: ObjectId(DOC_ID), project_id: ObjectId(PROJECT_ID) }, + { _id: new ObjectId(DOC_ID), project_id: new ObjectId(PROJECT_ID) }, { $set: { lines, version, ranges }, $inc: { rev: 1 }, // maintain same behaviour as Docstore upsertIntoDocCollection diff --git a/services/web/scripts/helpers/batchedUpdate.js b/services/web/scripts/helpers/batchedUpdate.js index e86e0f8115..129a28c327 100644 --- a/services/web/scripts/helpers/batchedUpdate.js +++ b/services/web/scripts/helpers/batchedUpdate.js @@ -22,9 +22,9 @@ function refreshGlobalOptionsForBatchedUpdate(options = {}) { BATCH_SIZE = parseInt(options.BATCH_SIZE, 10) || 1000 VERBOSE_LOGGING = options.VERBOSE_LOGGING === 'true' if (options.BATCH_LAST_ID) { - BATCH_RANGE_START = ObjectId(options.BATCH_LAST_ID) + BATCH_RANGE_START = new ObjectId(options.BATCH_LAST_ID) } else if (options.BATCH_RANGE_START) { - BATCH_RANGE_START = ObjectId(options.BATCH_RANGE_START) + BATCH_RANGE_START = new ObjectId(options.BATCH_RANGE_START) } else { if (BATCH_DESCENDING) { BATCH_RANGE_START = ID_EDGE_FUTURE @@ -35,7 +35,7 @@ function refreshGlobalOptionsForBatchedUpdate(options = {}) { BATCH_MAX_TIME_SPAN_IN_MS = parseInt(options.BATCH_MAX_TIME_SPAN_IN_MS, 10) || ONE_MONTH_IN_MS if (options.BATCH_RANGE_END) { - BATCH_RANGE_END = ObjectId(options.BATCH_RANGE_END) + BATCH_RANGE_END = new ObjectId(options.BATCH_RANGE_END) } else { if (BATCH_DESCENDING) { BATCH_RANGE_END = ID_EDGE_PAST diff --git a/services/web/scripts/invalidate_tokens.js b/services/web/scripts/invalidate_tokens.js index 588e0fff6a..59b9d5a34e 100644 --- a/services/web/scripts/invalidate_tokens.js +++ b/services/web/scripts/invalidate_tokens.js @@ -3,7 +3,7 @@ const minimist = require('minimist') const argv = minimist(process.argv.slice(2)) const commit = argv.commit !== undefined const projectIds = argv._.map(x => { - return ObjectId(x) + return new ObjectId(x) }) if (!commit) { diff --git a/services/web/scripts/merge_group_subscription_members.js b/services/web/scripts/merge_group_subscription_members.js index 4c640fc027..a212d3b69a 100644 --- a/services/web/scripts/merge_group_subscription_members.js +++ b/services/web/scripts/merge_group_subscription_members.js @@ -44,8 +44,8 @@ async function main() { await waitForDb() - const targetSubscription = await getSubscription(ObjectId(target)) - const sourceSubscription = await getSubscription(ObjectId(source)) + const targetSubscription = await getSubscription(new ObjectId(target)) + const sourceSubscription = await getSubscription(new ObjectId(source)) if (!targetSubscription) { throw new Error('couldnt find target (to) subscription') diff --git a/services/web/scripts/migrate_audit_logs.js b/services/web/scripts/migrate_audit_logs.js index 62ff8b9d3f..d78bafa6cf 100644 --- a/services/web/scripts/migrate_audit_logs.js +++ b/services/web/scripts/migrate_audit_logs.js @@ -25,7 +25,7 @@ async function main(options) { if (options.projectId) { console.log('migrating projectId=' + options.projectId) const project = await db.projects.findOne( - { _id: ObjectId(options.projectId) }, + { _id: new ObjectId(options.projectId) }, { _id: 1, auditLog: 1 } ) if (!project || !project.auditLog) { @@ -36,7 +36,7 @@ async function main(options) { } else if (options.userId) { console.log('migrating userId=' + options.userId) const user = await db.users.findOne( - { _id: ObjectId(options.userId) }, + { _id: new ObjectId(options.userId) }, { _id: 1, auditLog: 1 } ) if (!user || !user.auditLog) { diff --git a/services/web/scripts/oauth/register_client.js b/services/web/scripts/oauth/register_client.js index d5687d03f7..cf21a2ef68 100644 --- a/services/web/scripts/oauth/register_client.js +++ b/services/web/scripts/oauth/register_client.js @@ -61,7 +61,7 @@ async function upsertApplication(opts) { defaults.redirectUris = [] } if (opts.mongoId != null) { - defaults._id = ObjectId(opts.mongoId) + defaults._id = new ObjectId(opts.mongoId) } await db.oauthApplications.updateOne( diff --git a/services/web/scripts/recover_docs_from_redis.js b/services/web/scripts/recover_docs_from_redis.js index 28614c6529..77bcf9ab11 100644 --- a/services/web/scripts/recover_docs_from_redis.js +++ b/services/web/scripts/recover_docs_from_redis.js @@ -53,7 +53,7 @@ async function main() { async function processDoc(docId) { // check if the doc is in mongo.. if so ignore it - const docCount = await db.docs.find({ _id: ObjectId(docId) }).count() + const docCount = await db.docs.find({ _id: new ObjectId(docId) }).count() if (docCount > 0) { logger.debug({ docId }, 'doc is present in mongo - no recovery needed') return @@ -70,7 +70,7 @@ async function processDoc(docId) { return } // check that the project is in mongo, if not delete the doc - const project = await db.projects.findOne({ _id: ObjectId(projectId) }) + const project = await db.projects.findOne({ _id: new ObjectId(projectId) }) if (!project) { logger.warn( { docId }, diff --git a/services/web/scripts/set_tex_live_image.js b/services/web/scripts/set_tex_live_image.js index a9a35e0b04..e51dbee6f4 100644 --- a/services/web/scripts/set_tex_live_image.js +++ b/services/web/scripts/set_tex_live_image.js @@ -39,7 +39,7 @@ function parseProjectIds(projectIds) { for (const projectId of projectIds) { let oid try { - oid = ObjectId(projectId) + oid = new ObjectId(projectId) } catch (err) { console.error(`Invalid project id: ${projectId}`) process.exit(1) @@ -51,7 +51,7 @@ function parseProjectIds(projectIds) { async function updateImage(image, projectIds) { const res = await Project.updateMany( - { _id: { $in: projectIds.map(ObjectId) } }, + { _id: { $in: projectIds.map(id => new ObjectId(id)) } }, { $set: { imageName: `quay.io/sharelatex/${image}` } } ).exec() console.log(`Found ${res.matchedCount} out of ${projectIds.length} projects`) diff --git a/services/web/scripts/stress_test.js b/services/web/scripts/stress_test.js index 5caad0a097..840635418c 100644 --- a/services/web/scripts/stress_test.js +++ b/services/web/scripts/stress_test.js @@ -363,7 +363,7 @@ async function uploadFile(projectId) { async function upload(abortSignal, deleteFile = true) { const size = userSize.get() const buffer = Buffer.alloc(size, crypto.randomUUID()) - const fileId = ObjectId() + const fileId = new ObjectId() const url = `${settings.apis.filestore.url}/project/${projectId}/file/${fileId}` const md5 = computeMD5Hash(buffer) const response = await fetch(url, { diff --git a/services/web/test/acceptance/src/AuthenticationTests.js b/services/web/test/acceptance/src/AuthenticationTests.js index 22a38bbc20..cd79fb2614 100644 --- a/services/web/test/acceptance/src/AuthenticationTests.js +++ b/services/web/test/acceptance/src/AuthenticationTests.js @@ -63,8 +63,8 @@ describe('Authentication', function () { const auditLogEntry = auditLog[0] expect(auditLogEntry).to.exist expect(auditLogEntry.timestamp).to.exist - expect(auditLogEntry.initiatorId).to.deep.equal(ObjectId(user.id)) - expect(auditLogEntry.userId).to.deep.equal(ObjectId(user.id)) + expect(auditLogEntry.initiatorId).to.deep.equal(new ObjectId(user.id)) + expect(auditLogEntry.userId).to.deep.equal(new ObjectId(user.id)) expect(auditLogEntry.operation).to.equal('login') expect(auditLogEntry.info).to.deep.equal({ method: 'Password login', @@ -96,8 +96,8 @@ describe('Authentication', function () { const auditLogEntry = auditLog.pop() expect(auditLogEntry).to.exist expect(auditLogEntry.timestamp).to.exist - expect(auditLogEntry.initiatorId).to.deep.equal(ObjectId(user.id)) - expect(auditLogEntry.userId).to.deep.equal(ObjectId(user.id)) + expect(auditLogEntry.initiatorId).to.deep.equal(new ObjectId(user.id)) + expect(auditLogEntry.userId).to.deep.equal(new ObjectId(user.id)) expect(auditLogEntry.operation).to.equal('failed-password-match') expect(auditLogEntry.info).to.deep.equal({ method: 'Password login', diff --git a/services/web/test/acceptance/src/BackFillDeletedFilesTests.js b/services/web/test/acceptance/src/BackFillDeletedFilesTests.js index 42ef45de86..aba9b8ed99 100644 --- a/services/web/test/acceptance/src/BackFillDeletedFilesTests.js +++ b/services/web/test/acceptance/src/BackFillDeletedFilesTests.js @@ -27,20 +27,20 @@ describe('BackFillDeletedFiles', function () { user = new User() await user.login() - projectId1 = ObjectId(await user.createProject('project1')) - projectId2 = ObjectId(await user.createProject('project2')) - projectId3 = ObjectId(await user.createProject('project3')) - projectId4 = ObjectId(await user.createProject('project4')) - projectId5 = ObjectId(await user.createProject('project5')) + projectId1 = new ObjectId(await user.createProject('project1')) + projectId2 = new ObjectId(await user.createProject('project2')) + projectId3 = new ObjectId(await user.createProject('project3')) + projectId4 = new ObjectId(await user.createProject('project4')) + projectId5 = new ObjectId(await user.createProject('project5')) }) let fileId1, fileId2, fileId3, fileId4 beforeEach('create files', function () { // take a short cut and just allocate file ids - fileId1 = ObjectId() - fileId2 = ObjectId() - fileId3 = ObjectId() - fileId4 = ObjectId() + fileId1 = new ObjectId() + fileId2 = new ObjectId() + fileId3 = new ObjectId() + fileId4 = new ObjectId() }) const otherFileDetails = { name: 'universe.jpg', diff --git a/services/web/test/acceptance/src/BackFillDocNameForDeletedDocsTests.js b/services/web/test/acceptance/src/BackFillDocNameForDeletedDocsTests.js index 73fa267e6e..99e8e63a60 100644 --- a/services/web/test/acceptance/src/BackFillDocNameForDeletedDocsTests.js +++ b/services/web/test/acceptance/src/BackFillDocNameForDeletedDocsTests.js @@ -19,17 +19,17 @@ describe('BackFillDocNameForDeletedDocs', function () { user = new User() await user.login() - projectId1 = ObjectId(await user.createProject('project1')) - projectId2 = ObjectId(await user.createProject('project2')) + projectId1 = new ObjectId(await user.createProject('project1')) + projectId2 = new ObjectId(await user.createProject('project2')) }) beforeEach('create docs', async function () { - docId1 = ObjectId( + docId1 = new ObjectId( await user.createDocInProject(projectId1, null, 'doc1.tex') ) - docId2 = ObjectId( + docId2 = new ObjectId( await user.createDocInProject(projectId1, null, 'doc2.tex') ) - docId3 = ObjectId( + docId3 = new ObjectId( await user.createDocInProject(projectId2, null, 'doc3.tex') ) }) diff --git a/services/web/test/acceptance/src/BackFillDocRevTests.js b/services/web/test/acceptance/src/BackFillDocRevTests.js index dac784a67e..a551f21fa3 100644 --- a/services/web/test/acceptance/src/BackFillDocRevTests.js +++ b/services/web/test/acceptance/src/BackFillDocRevTests.js @@ -5,9 +5,9 @@ const logger = require('@overleaf/logger/logging-manager') const { expect } = require('chai') describe('BackFillDocRevTests', function () { - const docId1 = ObjectId() - const docId2 = ObjectId() - const docId3 = ObjectId() + const docId1 = new ObjectId() + const docId2 = new ObjectId() + const docId3 = new ObjectId() beforeEach('insert docs', async function () { await db.docs.insertMany([ diff --git a/services/web/test/acceptance/src/ConvertArchivedState.js b/services/web/test/acceptance/src/ConvertArchivedState.js index 12b79349ac..79b662c6a8 100644 --- a/services/web/test/acceptance/src/ConvertArchivedState.js +++ b/services/web/test/acceptance/src/ConvertArchivedState.js @@ -52,9 +52,9 @@ describe('ConvertArchivedState', function () { }) projectThree = await userOne.getProject(projectThreeId) projectThree.archived = [ - ObjectId(userOne._id), - ObjectId(userTwo._id), - ObjectId(userFour._id), + new ObjectId(userOne._id), + new ObjectId(userTwo._id), + new ObjectId(userFour._id), ] projectThree.collaberator_refs.push(userTwo._id) projectThree.tokenAccessReadOnly_refs.push(userFour._id) diff --git a/services/web/test/acceptance/src/DeletionTests.js b/services/web/test/acceptance/src/DeletionTests.js index cf97dddd96..5ba61467a9 100644 --- a/services/web/test/acceptance/src/DeletionTests.js +++ b/services/web/test/acceptance/src/DeletionTests.js @@ -432,7 +432,7 @@ describe('Deleting a project', function () { it('Should remove the project data from mongo', function (done) { db.deletedProjects.findOne( - { 'deleterData.deletedProjectId': ObjectId(this.projectId) }, + { 'deleterData.deletedProjectId': new ObjectId(this.projectId) }, (error, deletedProject) => { expect(error).not.to.exist expect(deletedProject).to.exist @@ -454,7 +454,11 @@ describe('Deleting a project', function () { expect(res.statusCode).to.equal(200) db.deletedProjects.findOne( - { 'deleterData.deletedProjectId': ObjectId(this.projectId) }, + { + 'deleterData.deletedProjectId': new ObjectId( + this.projectId + ), + }, (error, deletedProject) => { expect(error).not.to.exist expect(deletedProject).to.exist diff --git a/services/web/test/acceptance/src/DocUpdateTests.js b/services/web/test/acceptance/src/DocUpdateTests.js index 6e388a7d57..a3841209b6 100644 --- a/services/web/test/acceptance/src/DocUpdateTests.js +++ b/services/web/test/acceptance/src/DocUpdateTests.js @@ -135,7 +135,7 @@ describe('DocUpdate', function () { describe('unknown doc', function () { beforeEach(function () { - writeOptions.docId = ObjectId() + writeOptions.docId = new ObjectId() }) shouldBlockChanges() diff --git a/services/web/test/acceptance/src/MongoHelper.js b/services/web/test/acceptance/src/MongoHelper.js index a8cbd07b8f..f9ce1665dd 100644 --- a/services/web/test/acceptance/src/MongoHelper.js +++ b/services/web/test/acceptance/src/MongoHelper.js @@ -37,7 +37,7 @@ describe('MongoTests', function () { expect(query).to.exist expect(query._id).to.be.instanceof(NativeObjectId) - expect(query._id).to.deep.equal(NativeObjectId(userIdAsString)) + expect(query._id).to.deep.equal(new NativeObjectId(userIdAsString)) const user = await db.users.findOne(query) expect(user).to.exist @@ -79,7 +79,9 @@ describe('MongoTests', function () { describe('with an ObjectId from the native driver', function () { let user beforeEach(async function getUser() { - user = await db.users.findOne({ _id: NativeObjectId(userIdAsString) }) + user = await db.users.findOne({ + _id: new NativeObjectId(userIdAsString), + }) expect(user).to.exist expect(user._id).to.exist expect(user.email).to.equal(userEmail) diff --git a/services/web/test/acceptance/src/ProjectCRUDTests.js b/services/web/test/acceptance/src/ProjectCRUDTests.js index b07b4542f7..f6b24f71c5 100644 --- a/services/web/test/acceptance/src/ProjectCRUDTests.js +++ b/services/web/test/acceptance/src/ProjectCRUDTests.js @@ -78,7 +78,7 @@ describe('Project CRUD', function () { it('should mark the project as not archived for the user', async function () { await Project.updateOne( { _id: this.projectId }, - { $set: { archived: [ObjectId(this.user._id)] } } + { $set: { archived: [new ObjectId(this.user._id)] } } ).exec() const { response } = await this.user.doRequest( @@ -117,7 +117,7 @@ describe('Project CRUD', function () { it('should mark the project as untrashed for the user', async function () { await Project.updateOne( { _id: this.projectId }, - { trashed: [ObjectId(this.user._id)] } + { trashed: [new ObjectId(this.user._id)] } ).exec() const { response } = await this.user.doRequest( 'DELETE', @@ -132,7 +132,7 @@ describe('Project CRUD', function () { it('does nothing if the user has already untrashed the project', async function () { await Project.updateOne( { _id: this.projectId }, - { trashed: [ObjectId(this.user._id)] } + { trashed: [new ObjectId(this.user._id)] } ).exec() // Mark as untrashed the first time await this.user.doRequest('DELETE', `/project/${this.projectId}/trash`) diff --git a/services/web/test/acceptance/src/helpers/Institution.js b/services/web/test/acceptance/src/helpers/Institution.js index 1a388471e5..18ae896f0b 100644 --- a/services/web/test/acceptance/src/helpers/Institution.js +++ b/services/web/test/acceptance/src/helpers/Institution.js @@ -28,7 +28,7 @@ class Institution { setManagerIds(managerIds, callback) { return InstitutionModel.findOneAndUpdate( - { _id: ObjectId(this._id) }, + { _id: new ObjectId(this._id) }, { managerIds }, callback ) diff --git a/services/web/test/acceptance/src/helpers/Publisher.js b/services/web/test/acceptance/src/helpers/Publisher.js index a5815e913b..baf83b041b 100644 --- a/services/web/test/acceptance/src/helpers/Publisher.js +++ b/services/web/test/acceptance/src/helpers/Publisher.js @@ -22,7 +22,7 @@ class Publisher { setManagerIds(managerIds, callback) { return PublisherModel.findOneAndUpdate( - { _id: ObjectId(this._id) }, + { _id: new ObjectId(this._id) }, { managerIds }, callback ) diff --git a/services/web/test/acceptance/src/helpers/RecurlySubscription.js b/services/web/test/acceptance/src/helpers/RecurlySubscription.js index 346aa66156..99aa208273 100644 --- a/services/web/test/acceptance/src/helpers/RecurlySubscription.js +++ b/services/web/test/acceptance/src/helpers/RecurlySubscription.js @@ -12,7 +12,7 @@ before(function () { class RecurlySubscription { constructor(options = {}) { - options.recurlySubscription_id = ObjectId().toString() + options.recurlySubscription_id = new ObjectId().toString() this.subscription = new Subscription(options) this.uuid = options.recurlySubscription_id diff --git a/services/web/test/acceptance/src/helpers/Subscription.js b/services/web/test/acceptance/src/helpers/Subscription.js index 38ff8fa599..b31290c52c 100644 --- a/services/web/test/acceptance/src/helpers/Subscription.js +++ b/services/web/test/acceptance/src/helpers/Subscription.js @@ -12,7 +12,7 @@ const Modules = require('../../../../app/src/infrastructure/Modules') class Subscription { constructor(options = {}) { - this.admin_id = options.adminId || ObjectId() + this.admin_id = options.adminId || new ObjectId() this.overleaf = options.overleaf || {} this.groupPlan = options.groupPlan this.manager_ids = options.managerIds || [this.admin_id] @@ -48,7 +48,7 @@ class Subscription { } get(callback) { - db.subscriptions.findOne({ _id: ObjectId(this._id) }, callback) + db.subscriptions.findOne({ _id: new ObjectId(this._id) }, callback) } getWithGroupPolicy(callback) { @@ -57,7 +57,7 @@ class Subscription { setManagerIds(managerIds, callback) { return SubscriptionModel.findOneAndUpdate( - { _id: ObjectId(this._id) }, + { _id: new ObjectId(this._id) }, { manager_ids: managerIds }, callback ) diff --git a/services/web/test/acceptance/src/helpers/User.js b/services/web/test/acceptance/src/helpers/User.js index 92cb834d07..451c183d15 100644 --- a/services/web/test/acceptance/src/helpers/User.js +++ b/services/web/test/acceptance/src/helpers/User.js @@ -44,7 +44,7 @@ class User { } get(callback) { - db.users.findOne({ _id: ObjectId(this._id) }, callback) + db.users.findOne({ _id: new ObjectId(this._id) }, callback) } getAuditLog(callback) { @@ -53,7 +53,7 @@ class User { if (!user) return callback(new Error('User not found')) db.userAuditLogEntries - .find({ userId: ObjectId(this._id) }) + .find({ userId: new ObjectId(this._id) }) .toArray((error, auditLog) => { if (error) return callback(error) callback(null, auditLog || []) @@ -74,7 +74,7 @@ class User { } mongoUpdate(updateOp, callback) { - db.users.updateOne({ _id: ObjectId(this._id) }, updateOp, callback) + db.users.updateOne({ _id: new ObjectId(this._id) }, updateOp, callback) } register(callback) { @@ -347,7 +347,7 @@ class User { getFeatures(callback) { db.users.findOne( - { _id: ObjectId(this.id) }, + { _id: new ObjectId(this.id) }, { projection: { features: 1 } }, (error, user) => callback(error, user && user.features) ) @@ -362,11 +362,11 @@ class User { return callback() } const userId = user._id - db.projects.deleteMany({ owner_ref: ObjectId(userId) }, err => { + db.projects.deleteMany({ owner_ref: new ObjectId(userId) }, err => { if (err != null) { callback(err) } - db.users.deleteOne({ _id: ObjectId(userId) }, callback) + db.users.deleteOne({ _id: new ObjectId(userId) }, callback) }) }) } @@ -401,7 +401,7 @@ class User { } getProject(projectId, callback) { - db.projects.findOne({ _id: ObjectId(projectId.toString()) }, callback) + db.projects.findOne({ _id: new ObjectId(projectId.toString()) }, callback) } saveProject(project, callback) { @@ -498,7 +498,7 @@ class User { } deleteProjects(callback) { - db.projects.deleteMany({ owner_ref: ObjectId(this.id) }, callback) + db.projects.deleteMany({ owner_ref: new ObjectId(this.id) }, callback) } openProject(projectId, callback) { @@ -721,14 +721,14 @@ class User { } else if (privileges === 'readOnly') { updateOp = { $addToSet: { readOnly_refs: user._id } } } - db.projects.updateOne({ _id: ObjectId(projectId) }, updateOp, callback) + db.projects.updateOne({ _id: new ObjectId(projectId) }, updateOp, callback) } makePublic(projectId, level, callback) { // A fudge, to get around the fact that `readOnly` and `readAndWrite` are now disallowed // via the API, but we still need to test the behaviour of projects with these values set. db.projects.updateOne( - { _id: ObjectId(projectId) }, + { _id: new ObjectId(projectId) }, // NOTE: Yes, there is a typo in the db schema. { $set: { publicAccesLevel: level } }, callback diff --git a/services/web/test/acceptance/src/helpers/UserHelper.js b/services/web/test/acceptance/src/helpers/UserHelper.js index 9536beea8b..c630ce6b8b 100644 --- a/services/web/test/acceptance/src/helpers/UserHelper.js +++ b/services/web/test/acceptance/src/helpers/UserHelper.js @@ -238,7 +238,7 @@ class UserHelper { static async updateUser(userId, update) { // TODO(das7pad): revert back to args pass-through after mongo upgrades const user = await UserUpdater.promises.updateUser( - { _id: ObjectId(userId) }, + { _id: new ObjectId(userId) }, update ) diff --git a/services/web/test/acceptance/src/mocks/MockDocstoreApi.js b/services/web/test/acceptance/src/mocks/MockDocstoreApi.js index a79f7a006b..da479ca30a 100644 --- a/services/web/test/acceptance/src/mocks/MockDocstoreApi.js +++ b/services/web/test/acceptance/src/mocks/MockDocstoreApi.js @@ -91,7 +91,7 @@ class MockDocstoreApi extends AbstractMockApi { this.app.post('/project/:projectId/destroy', async (req, res) => { const { projectId } = req.params delete this.docs[projectId] - await db.docs.deleteMany({ project_id: ObjectId(projectId) }) + await db.docs.deleteMany({ project_id: new ObjectId(projectId) }) res.sendStatus(204) }) } diff --git a/services/web/test/unit/src/Analytics/AnalyticsManagerTests.js b/services/web/test/unit/src/Analytics/AnalyticsManagerTests.js index a907477ae8..d91bb3d5bf 100644 --- a/services/web/test/unit/src/Analytics/AnalyticsManagerTests.js +++ b/services/web/test/unit/src/Analytics/AnalyticsManagerTests.js @@ -4,7 +4,7 @@ const sinon = require('sinon') const MockRequest = require('../helpers/MockRequest') const MockResponse = require('../helpers/MockResponse') const { assert } = require('chai') -const { ObjectID } = require('mongodb') +const { ObjectId } = require('mongodb') const MODULE_PATH = path.join( __dirname, @@ -85,7 +85,7 @@ describe('AnalyticsManager', function () { it('analyticsId is missing', function () { this.AnalyticsManager.identifyUser( - new ObjectID(this.fakeUserId), + new ObjectId(this.fakeUserId), undefined ) sinon.assert.notCalled(this.Queues.createScheduledJob) @@ -93,7 +93,7 @@ describe('AnalyticsManager', function () { it('analyticsId is not a valid UUID', function () { this.AnalyticsManager.identifyUser( - new ObjectID(this.fakeUserId), + new ObjectId(this.fakeUserId), this.fakeUserId ) sinon.assert.notCalled(this.Queues.createScheduledJob) @@ -101,8 +101,8 @@ describe('AnalyticsManager', function () { it('userId and analyticsId are the same Mongo ID', function () { this.AnalyticsManager.identifyUser( - new ObjectID(this.fakeUserId), - new ObjectID(this.fakeUserId) + new ObjectId(this.fakeUserId), + new ObjectId(this.fakeUserId) ) sinon.assert.notCalled(this.Queues.createScheduledJob) }) diff --git a/services/web/test/unit/src/Authentication/AuthenticationControllerTests.js b/services/web/test/unit/src/Authentication/AuthenticationControllerTests.js index cc0b08cbf5..0332e52ef1 100644 --- a/services/web/test/unit/src/Authentication/AuthenticationControllerTests.js +++ b/services/web/test/unit/src/Authentication/AuthenticationControllerTests.js @@ -17,7 +17,7 @@ describe('AuthenticationController', function () { 'valid-test-user': Math.random().toString(16).slice(2), } this.user = { - _id: ObjectId(), + _id: new ObjectId(), email: (this.email = 'USER@example.com'), first_name: 'bob', last_name: 'brown', diff --git a/services/web/test/unit/src/Authentication/AuthenticationManagerTests.js b/services/web/test/unit/src/Authentication/AuthenticationManagerTests.js index 52041d8795..3dfbd82630 100644 --- a/services/web/test/unit/src/Authentication/AuthenticationManagerTests.js +++ b/services/web/test/unit/src/Authentication/AuthenticationManagerTests.js @@ -747,7 +747,7 @@ describe('AuthenticationManager', function () { describe('setUserPassword', function () { beforeEach(function () { - this.user_id = ObjectId() + this.user_id = new ObjectId() this.password = 'bananagram' this.hashedPassword = 'asdkjfa;osiuvandf' this.salt = 'saltaasdfasdfasdf' @@ -955,7 +955,7 @@ describe('AuthenticationManager', function () { it("should update the user's password in the database", function () { const { args } = this.db.users.updateOne.lastCall expect(args[0]).to.deep.equal({ - _id: ObjectId(this.user_id.toString()), + _id: new ObjectId(this.user_id.toString()), }) expect(args[1]).to.deep.equal({ $set: { diff --git a/services/web/test/unit/src/Authentication/SessionManagerTests.js b/services/web/test/unit/src/Authentication/SessionManagerTests.js index 44926c59ce..08ede266f1 100644 --- a/services/web/test/unit/src/Authentication/SessionManagerTests.js +++ b/services/web/test/unit/src/Authentication/SessionManagerTests.js @@ -13,7 +13,7 @@ describe('SessionManager', function () { requires: {}, }) this.user = { - _id: ObjectId(), + _id: new ObjectId(), email: (this.email = 'USER@example.com'), first_name: 'bob', last_name: 'brown', diff --git a/services/web/test/unit/src/Collaborators/CollaboratorsControllerTests.js b/services/web/test/unit/src/Collaborators/CollaboratorsControllerTests.js index 0f50b76c84..25d8594255 100644 --- a/services/web/test/unit/src/Collaborators/CollaboratorsControllerTests.js +++ b/services/web/test/unit/src/Collaborators/CollaboratorsControllerTests.js @@ -14,8 +14,8 @@ describe('CollaboratorsController', function () { this.res = new MockResponse() this.req = new MockRequest() - this.user = { _id: ObjectId() } - this.projectId = ObjectId() + this.user = { _id: new ObjectId() } + this.projectId = new ObjectId() this.callback = sinon.stub() this.CollaboratorsHandler = { diff --git a/services/web/test/unit/src/Collaborators/CollaboratorsGetterTests.js b/services/web/test/unit/src/Collaborators/CollaboratorsGetterTests.js index 318888dcdd..0df201915e 100644 --- a/services/web/test/unit/src/Collaborators/CollaboratorsGetterTests.js +++ b/services/web/test/unit/src/Collaborators/CollaboratorsGetterTests.js @@ -14,16 +14,16 @@ const MODULE_PATH = Path.join( describe('CollaboratorsGetter', function () { beforeEach(function () { this.userId = 'mock-user-id' - this.ownerRef = ObjectId() - this.readOnlyRef1 = ObjectId() - this.readOnlyRef2 = ObjectId() - this.readWriteRef1 = ObjectId() - this.readWriteRef2 = ObjectId() - this.readOnlyTokenRef = ObjectId() - this.readWriteTokenRef = ObjectId() - this.nonMemberRef = ObjectId() + this.ownerRef = new ObjectId() + this.readOnlyRef1 = new ObjectId() + this.readOnlyRef2 = new ObjectId() + this.readWriteRef1 = new ObjectId() + this.readWriteRef2 = new ObjectId() + this.readOnlyTokenRef = new ObjectId() + this.readWriteTokenRef = new ObjectId() + this.nonMemberRef = new ObjectId() this.project = { - _id: ObjectId(), + _id: new ObjectId(), owner_ref: [this.ownerRef], readOnly_refs: [this.readOnlyRef1, this.readOnlyRef2], collaberator_refs: [this.readWriteRef1, this.readWriteRef2], @@ -366,7 +366,7 @@ describe('CollaboratorsGetter', function () { }) describe('getPublicShareTokens', function () { - const userMock = ObjectId() + const userMock = new ObjectId() it('should return null when the project is not found', async function () { this.ProjectMock.expects('findOne').chain('exec').resolves(undefined) diff --git a/services/web/test/unit/src/Collaborators/CollaboratorsHandlerTests.js b/services/web/test/unit/src/Collaborators/CollaboratorsHandlerTests.js index 2e6791dfc6..3812915a90 100644 --- a/services/web/test/unit/src/Collaborators/CollaboratorsHandlerTests.js +++ b/services/web/test/unit/src/Collaborators/CollaboratorsHandlerTests.js @@ -16,21 +16,21 @@ const sleep = promisify(setTimeout) describe('CollaboratorsHandler', function () { beforeEach(function () { - this.userId = ObjectId() - this.addingUserId = ObjectId() + this.userId = new ObjectId() + this.addingUserId = new ObjectId() this.project = { - _id: ObjectId(), + _id: new ObjectId(), owner_ref: this.addingUserId, name: 'Foo', } this.archivedProject = { - _id: ObjectId(), - archived: [ObjectId(this.userId)], + _id: new ObjectId(), + archived: [new ObjectId(this.userId)], } this.oldArchivedProject = { - _id: ObjectId(), + _id: new ObjectId(), archived: true, } @@ -124,7 +124,7 @@ describe('CollaboratorsHandler', function () { describe('an archived project, archived with a boolean value', function () { beforeEach(function () { - const archived = [ObjectId(this.userId)] + const archived = [new ObjectId(this.userId)] this.ProjectHelper.calculateArchivedArray.returns(archived) this.ProjectMock.expects('findOne') @@ -394,14 +394,14 @@ describe('CollaboratorsHandler', function () { describe('transferProjects', function () { beforeEach(function () { - this.fromUserId = ObjectId() - this.toUserId = ObjectId() + this.fromUserId = new ObjectId() + this.toUserId = new ObjectId() this.projects = [ { - _id: ObjectId(), + _id: new ObjectId(), }, { - _id: ObjectId(), + _id: new ObjectId(), }, ] this.ProjectMock.expects('find') diff --git a/services/web/test/unit/src/Collaborators/CollaboratorsInviteControllerTests.js b/services/web/test/unit/src/Collaborators/CollaboratorsInviteControllerTests.js index 450005befe..1ba43146a5 100644 --- a/services/web/test/unit/src/Collaborators/CollaboratorsInviteControllerTests.js +++ b/services/web/test/unit/src/Collaborators/CollaboratorsInviteControllerTests.js @@ -20,7 +20,7 @@ describe('CollaboratorsInviteController', function () { email: 'current-user@example.com', } this.invite = { - _id: ObjectId(), + _id: new ObjectId(), token: this.token, sendingUserId: this.currentUser._id, projectId: this.projectId, @@ -116,8 +116,8 @@ describe('CollaboratorsInviteController', function () { describe('getAllInvites', function () { beforeEach(function () { this.fakeInvites = [ - { _id: ObjectId(), one: 1 }, - { _id: ObjectId(), two: 2 }, + { _id: new ObjectId(), one: 1 }, + { _id: new ObjectId(), two: 2 }, ] this.req.params = { Project_id: this.projectId } }) @@ -1295,7 +1295,7 @@ describe('CollaboratorsInviteController', function () { describe('when user account is present', function () { beforeEach(function () { - this.user = { _id: ObjectId().toString() } + this.user = { _id: new ObjectId().toString() } this.UserGetter.promises.getUserByAnyEmail.resolves(this.user) }) diff --git a/services/web/test/unit/src/Collaborators/CollaboratorsInviteHandlerTests.js b/services/web/test/unit/src/Collaborators/CollaboratorsInviteHandlerTests.js index a244129d1a..f337f9cc79 100644 --- a/services/web/test/unit/src/Collaborators/CollaboratorsInviteHandlerTests.js +++ b/services/web/test/unit/src/Collaborators/CollaboratorsInviteHandlerTests.js @@ -14,7 +14,7 @@ describe('CollaboratorsInviteHandler', function () { if (options == null) { options = {} } - this._id = ObjectId() + this._id = new ObjectId() for (const k in options) { const v = options[k] this[k] = v @@ -55,19 +55,19 @@ describe('CollaboratorsInviteHandler', function () { }, }) - this.projectId = ObjectId() - this.sendingUserId = ObjectId() + this.projectId = new ObjectId() + this.sendingUserId = new ObjectId() this.sendingUser = { _id: this.sendingUserId, name: 'Bob', } this.email = 'user@example.com' - this.userId = ObjectId() + this.userId = new ObjectId() this.user = { _id: this.userId, email: 'someone@example.com', } - this.inviteId = ObjectId() + this.inviteId = new ObjectId() this.token = 'hnhteaosuhtaeosuahs' this.privileges = 'readAndWrite' this.fakeInvite = { @@ -114,8 +114,8 @@ describe('CollaboratorsInviteHandler', function () { describe('getAllInvites', function () { beforeEach(function () { this.fakeInvites = [ - { _id: ObjectId(), one: 1 }, - { _id: ObjectId(), two: 2 }, + { _id: new ObjectId(), one: 1 }, + { _id: new ObjectId(), two: 2 }, ] this.ProjectInvite.find.returns({ exec: sinon.stub().resolves(this.fakeInvites), @@ -607,8 +607,8 @@ describe('CollaboratorsInviteHandler', function () { describe('_tryCancelInviteNotification', function () { beforeEach(function () { - this.inviteId = ObjectId() - this.currentUser = { _id: ObjectId() } + this.inviteId = new ObjectId() + this.currentUser = { _id: new ObjectId() } this.notification = { read: sinon.stub().resolves() } this.NotificationsBuilder.promises.projectInvite = sinon .stub() @@ -644,18 +644,18 @@ describe('CollaboratorsInviteHandler', function () { describe('_trySendInviteNotification', function () { beforeEach(function () { this.invite = { - _id: ObjectId(), + _id: new ObjectId(), token: 'some_token', - sendingUserId: ObjectId(), + sendingUserId: new ObjectId(), projectId: this.project_id, targetEmail: 'user@example.com', createdAt: new Date(), } this.sendingUser = { - _id: ObjectId(), + _id: new ObjectId(), first_name: 'jim', } - this.existingUser = { _id: ObjectId() } + this.existingUser = { _id: new ObjectId() } this.UserGetter.promises.getUserByAnyEmail = sinon .stub() .resolves(this.existingUser) diff --git a/services/web/test/unit/src/Collaborators/OwnershipTransferHandlerTests.js b/services/web/test/unit/src/Collaborators/OwnershipTransferHandlerTests.js index e2ff635c07..934496a42e 100644 --- a/services/web/test/unit/src/Collaborators/OwnershipTransferHandlerTests.js +++ b/services/web/test/unit/src/Collaborators/OwnershipTransferHandlerTests.js @@ -10,10 +10,13 @@ const MODULE_PATH = describe('OwnershipTransferHandler', function () { beforeEach(function () { - this.user = { _id: ObjectId(), email: 'owner@example.com' } - this.collaborator = { _id: ObjectId(), email: 'collaborator@example.com' } + this.user = { _id: new ObjectId(), email: 'owner@example.com' } + this.collaborator = { + _id: new ObjectId(), + email: 'collaborator@example.com', + } this.project = { - _id: ObjectId(), + _id: new ObjectId(), name: 'project', owner_ref: this.user._id, collaberator_refs: [this.collaborator._id], @@ -205,7 +208,7 @@ describe('OwnershipTransferHandler', function () { }) it('should track the change in BigQuery', async function () { - const sessionUserId = ObjectId() + const sessionUserId = new ObjectId() await this.handler.promises.transferOwnership( this.project._id, this.collaborator._id, @@ -222,7 +225,7 @@ describe('OwnershipTransferHandler', function () { }) it('should write an entry in the audit log', async function () { - const sessionUserId = ObjectId() + const sessionUserId = new ObjectId() await this.handler.promises.transferOwnership( this.project._id, this.collaborator._id, diff --git a/services/web/test/unit/src/History/HistoryManagerTests.js b/services/web/test/unit/src/History/HistoryManagerTests.js index a27220d78f..955bbf72da 100644 --- a/services/web/test/unit/src/History/HistoryManagerTests.js +++ b/services/web/test/unit/src/History/HistoryManagerTests.js @@ -8,7 +8,7 @@ const MODULE_PATH = '../../../../app/src/Features/History/HistoryManager' describe('HistoryManager', function () { beforeEach(function () { this.user_id = 'user-id-123' - this.historyId = ObjectId().toString() + this.historyId = new ObjectId().toString() this.AuthenticationController = { getLoggedInUserId: sinon.stub().returns(this.user_id), } diff --git a/services/web/test/unit/src/Institutions/InstitutionsManagerTests.js b/services/web/test/unit/src/Institutions/InstitutionsManagerTests.js index 46e34e4fe2..9b597676d6 100644 --- a/services/web/test/unit/src/Institutions/InstitutionsManagerTests.js +++ b/services/web/test/unit/src/Institutions/InstitutionsManagerTests.js @@ -2,6 +2,7 @@ const SandboxedModule = require('sandboxed-module') const path = require('path') const sinon = require('sinon') const { expect } = require('chai') +const { ObjectId } = require('mongodb') const modulePath = path.join( __dirname, '../../../../app/src/Features/Institutions/InstitutionsManager' @@ -16,19 +17,23 @@ describe('InstitutionsManager', function () { this.getConfirmedInstitutionAffiliations = sinon.stub() this.addAffiliation = sinon.stub().callsArgWith(3, null) this.refreshFeatures = sinon.stub().yields() + const lapsedUser = { + _id: '657300a08a14461b3d1aac3e', + features: {}, + } this.users = [ - { _id: 'lapsed', features: {} }, - { _id: '1a', features: {} }, - { _id: '2b', features: {} }, - { _id: '3c', features: {} }, + lapsedUser, + { _id: '657300a08a14461b3d1aac3f', features: {} }, + { _id: '657300a08a14461b3d1aac40', features: {} }, + { _id: '657300a08a14461b3d1aac41', features: {} }, ] this.ssoUsers = [ { - _id: '1a', + _id: '657300a08a14461b3d1aac3f', samlIdentifiers: [{ providerId: this.institutionId.toString() }], }, { - _id: '2b', + _id: '657300a08a14461b3d1aac40', samlIdentifiers: [ { providerId: this.institutionId.toString(), @@ -37,7 +42,7 @@ describe('InstitutionsManager', function () { ], }, { - _id: 'lapsed', + _id: '657300a08a14461b3d1aac3e', samlIdentifiers: [{ providerId: this.institutionId.toString() }], hasEntitlement: true, }, @@ -83,12 +88,15 @@ describe('InstitutionsManager', function () { }), }, } - this.Mongo = { ObjectId: sinon.stub().returnsArg(0) } + + this.Mongo = { + ObjectId, + } this.v1Counts = { user_ids: this.users.map(user => user._id), current_users_count: 3, - lapsed_user_ids: ['lapsed'], + lapsed_user_ids: [lapsedUser._id], entitled_via_sso: 1, // 2 entitled, but 1 lapsed with_confirmed_email: 2, // 1 non entitled SSO + 1 email user } @@ -151,8 +159,8 @@ describe('InstitutionsManager', function () { beforeEach(function () { this.user1Id = '123abc123abc123abc123abc' this.user2Id = '456def456def456def456def' - this.user3Id = 'trial123abc' - this.user4Id = 'group123abc' + this.user3Id = '789abd789abd789abd789abd' + this.user4Id = '321cba321cba321cba321cba' this.affiliations = [ { user_id: this.user1Id }, { user_id: this.user2Id }, @@ -164,10 +172,18 @@ describe('InstitutionsManager', function () { this.user3 = { _id: this.user3Id } this.user4 = { _id: this.user4Id } - this.UserGetter.getUser.withArgs(this.user1Id).yields(null, this.user1) - this.UserGetter.getUser.withArgs(this.user2Id).yields(null, this.user2) - this.UserGetter.getUser.withArgs(this.user3Id).yields(null, this.user3) - this.UserGetter.getUser.withArgs(this.user4Id).yields(null, this.user4) + this.UserGetter.getUser + .withArgs(new ObjectId(this.user1Id)) + .yields(null, this.user1) + this.UserGetter.getUser + .withArgs(new ObjectId(this.user2Id)) + .yields(null, this.user2) + this.UserGetter.getUser + .withArgs(new ObjectId(this.user3Id)) + .yields(null, this.user3) + this.UserGetter.getUser + .withArgs(new ObjectId(this.user4Id)) + .yields(null, this.user4) this.SubscriptionLocator.getUsersSubscription .withArgs(this.user2) @@ -188,7 +204,9 @@ describe('InstitutionsManager', function () { groupPlan: true, }) - this.refreshFeatures.withArgs(this.user1Id).yields(null, {}, true) + this.refreshFeatures + .withArgs(new ObjectId(this.user1Id)) + .yields(null, {}, true) this.getInstitutionAffiliations.yields(null, this.affiliations) this.getConfirmedInstitutionAffiliations.yields(null, this.affiliations) }) @@ -370,7 +388,7 @@ describe('InstitutionsManager', function () { beforeEach(function () { this.host = 'mit.edu'.split('').reverse().join('') this.stubbedUser1 = { - _id: '3131231', + _id: '6573014d8a14461b3d1aac3f', name: 'bob', email: 'hello@world.com', emails: [ @@ -393,7 +411,7 @@ describe('InstitutionsManager', function () { }, ] this.stubbedUser2 = { - _id: '3131232', + _id: '6573014d8a14461b3d1aac40', name: 'test', email: 'hello2@world.com', emails: [{ email: 'subb2@mit.edu', reversedHostname: this.host }], diff --git a/services/web/test/unit/src/Project/FolderStructureBuilderTests.js b/services/web/test/unit/src/Project/FolderStructureBuilderTests.js index 3febe37ebd..324ce7b2d1 100644 --- a/services/web/test/unit/src/Project/FolderStructureBuilderTests.js +++ b/services/web/test/unit/src/Project/FolderStructureBuilderTests.js @@ -1,17 +1,22 @@ const { expect } = require('chai') -const sinon = require('sinon') const SandboxedModule = require('sandboxed-module') +const { ObjectId } = require('mongodb') const MODULE_PATH = '../../../../app/src/Features/Project/FolderStructureBuilder' -const MOCK_OBJECT_ID = 'MOCK_OBJECT_ID' +const MOCK_OBJECT_ID = new ObjectId('657306930a1cf28031c358da') describe('FolderStructureBuilder', function () { beforeEach(function () { - this.ObjectId = sinon.stub().returns(MOCK_OBJECT_ID) this.FolderStructureBuilder = SandboxedModule.require(MODULE_PATH, { requires: { - mongodb: { ObjectId: this.ObjectId }, + mongodb: { + ObjectId: class { + constructor() { + return MOCK_OBJECT_ID + } + }, + }, }, }) }) diff --git a/services/web/test/unit/src/Project/ProjectCollabratecDetailsTest.js b/services/web/test/unit/src/Project/ProjectCollabratecDetailsTest.js index 800bb0f81e..c2502032cf 100644 --- a/services/web/test/unit/src/Project/ProjectCollabratecDetailsTest.js +++ b/services/web/test/unit/src/Project/ProjectCollabratecDetailsTest.js @@ -25,9 +25,9 @@ const modulePath = Path.join( describe('ProjectCollabratecDetailsHandler', function () { beforeEach(function () { - this.projectId = ObjectId('5bea8747c7bba6012fcaceb3') - this.userId = ObjectId('5be316a9c7f6aa03802ea8fb') - this.userId2 = ObjectId('5c1794b3f0e89b1d1c577eca') + this.projectId = new ObjectId('5bea8747c7bba6012fcaceb3') + this.userId = new ObjectId('5be316a9c7f6aa03802ea8fb') + this.userId2 = new ObjectId('5c1794b3f0e89b1d1c577eca') this.ProjectModel = {} this.ProjectCollabratecDetailsHandler = SandboxedModule.require( modulePath, @@ -132,10 +132,10 @@ describe('ProjectCollabratecDetailsHandler', function () { it('should call find with project and user id', function () { return expect(this.ProjectModel.findOne).to.have.been.calledWithMatch( { - _id: ObjectId(this.projectId), + _id: new ObjectId(this.projectId), collabratecUsers: { $elemMatch: { - user_id: ObjectId(this.userId), + user_id: new ObjectId(this.userId), }, }, } diff --git a/services/web/test/unit/src/Project/ProjectControllerTests.js b/services/web/test/unit/src/Project/ProjectControllerTests.js index fe179b2cfb..99f3ac61b9 100644 --- a/services/web/test/unit/src/Project/ProjectControllerTests.js +++ b/services/web/test/unit/src/Project/ProjectControllerTests.js @@ -11,10 +11,10 @@ const MODULE_PATH = path.join( describe('ProjectController', function () { beforeEach(function () { - this.project_id = ObjectId('abcdefabcdefabcdefabcdef') + this.project_id = new ObjectId('abcdefabcdefabcdefabcdef') this.user = { - _id: ObjectId('123456123456123456123456'), + _id: new ObjectId('123456123456123456123456'), email: 'test@overleaf.com', first_name: 'bjkdsjfk', features: {}, @@ -590,7 +590,7 @@ describe('ProjectController', function () { this.res.render = (pageName, opts) => { expect(this.UserModel.updateOne).to.have.been.calledOnce expect(this.UserModel.updateOne.args[0][0]).to.deep.equal({ - _id: ObjectId(this.user._id), + _id: new ObjectId(this.user._id), }) expect(this.UserModel.updateOne.args[0][1].$set.lastActive).to.exist done() diff --git a/services/web/test/unit/src/Project/ProjectDeleterTests.js b/services/web/test/unit/src/Project/ProjectDeleterTests.js index a2af8f5acf..f551f8bed4 100644 --- a/services/web/test/unit/src/Project/ProjectDeleterTests.js +++ b/services/web/test/unit/src/Project/ProjectDeleterTests.js @@ -567,7 +567,7 @@ describe('ProjectDeleter', function () { describe('archiveProject', function () { beforeEach(function () { - const archived = [ObjectId(this.user._id)] + const archived = [new ObjectId(this.user._id)] this.ProjectHelper.calculateArchivedArray.returns(archived) this.ProjectMock.expects('findOne') @@ -580,7 +580,7 @@ describe('ProjectDeleter', function () { { _id: this.project._id }, { $set: { archived }, - $pull: { trashed: ObjectId(this.user._id) }, + $pull: { trashed: new ObjectId(this.user._id) }, } ) .resolves() @@ -609,7 +609,7 @@ describe('ProjectDeleter', function () { describe('unarchiveProject', function () { beforeEach(function () { - const archived = [ObjectId(this.user._id)] + const archived = [new ObjectId(this.user._id)] this.ProjectHelper.calculateArchivedArray.returns(archived) this.ProjectMock.expects('findOne') @@ -645,7 +645,7 @@ describe('ProjectDeleter', function () { describe('trashProject', function () { beforeEach(function () { - const archived = [ObjectId(this.user._id)] + const archived = [new ObjectId(this.user._id)] this.ProjectHelper.calculateArchivedArray.returns(archived) this.ProjectMock.expects('findOne') @@ -657,7 +657,7 @@ describe('ProjectDeleter', function () { .withArgs( { _id: this.project._id }, { - $addToSet: { trashed: ObjectId(this.user._id) }, + $addToSet: { trashed: new ObjectId(this.user._id) }, $set: { archived }, } ) @@ -695,7 +695,7 @@ describe('ProjectDeleter', function () { this.ProjectMock.expects('updateOne') .withArgs( { _id: this.project._id }, - { $pull: { trashed: ObjectId(this.user._id) } } + { $pull: { trashed: new ObjectId(this.user._id) } } ) .resolves() }) @@ -731,8 +731,8 @@ describe('ProjectDeleter', function () { describe('undeleteProject', function () { beforeEach(function () { - this.unknownProjectId = ObjectId() - this.purgedProjectId = ObjectId() + this.unknownProjectId = new ObjectId() + this.purgedProjectId = new ObjectId() this.deletedProject = { _id: 'deleted', diff --git a/services/web/test/unit/src/Project/ProjectDetailsHandlerTests.js b/services/web/test/unit/src/Project/ProjectDetailsHandlerTests.js index 235fec66cb..c0efd48942 100644 --- a/services/web/test/unit/src/Project/ProjectDetailsHandlerTests.js +++ b/services/web/test/unit/src/Project/ProjectDetailsHandlerTests.js @@ -10,16 +10,16 @@ const MODULE_PATH = '../../../../app/src/Features/Project/ProjectDetailsHandler' describe('ProjectDetailsHandler', function () { beforeEach(function () { this.user = { - _id: ObjectId(), + _id: new ObjectId(), email: 'user@example.com', features: 'mock-features', } this.collaborator = { - _id: ObjectId(), + _id: new ObjectId(), email: 'collaborator@example.com', } this.project = { - _id: ObjectId(), + _id: new ObjectId(), name: 'project', description: 'this is a great project', something: 'should not exist', diff --git a/services/web/test/unit/src/Project/ProjectEntityMongoUpdateHandlerTests.js b/services/web/test/unit/src/Project/ProjectEntityMongoUpdateHandlerTests.js index b4f1afc9a6..8645c6f9fe 100644 --- a/services/web/test/unit/src/Project/ProjectEntityMongoUpdateHandlerTests.js +++ b/services/web/test/unit/src/Project/ProjectEntityMongoUpdateHandlerTests.js @@ -13,7 +13,7 @@ const MODULE_PATH = describe('ProjectEntityMongoUpdateHandler', function () { beforeEach(function () { this.doc = { - _id: ObjectId(), + _id: new ObjectId(), name: 'test-doc.txt', lines: ['hello', 'world'], rev: 1234, @@ -23,7 +23,7 @@ describe('ProjectEntityMongoUpdateHandler', function () { fileSystem: '/test-doc.txt', } this.file = { - _id: ObjectId(), + _id: new ObjectId(), name: 'something.jpg', linkedFileData: { provider: 'url' }, hash: 'some-hash', @@ -32,18 +32,18 @@ describe('ProjectEntityMongoUpdateHandler', function () { fileSystem: '/something.png', mongo: 'rootFolder.0.fileRefs.0', } - this.subfolder = { _id: ObjectId(), name: 'test-subfolder' } + this.subfolder = { _id: new ObjectId(), name: 'test-subfolder' } this.subfolderPath = { fileSystem: '/test-folder/test-subfolder', mongo: 'rootFolder.0.folders.0.folders.0', } - this.notSubfolder = { _id: ObjectId(), name: 'test-folder-2' } + this.notSubfolder = { _id: new ObjectId(), name: 'test-folder-2' } this.notSubfolderPath = { fileSystem: '/test-folder-2/test-subfolder', mongo: 'rootFolder.0.folders.0.folders.0', } this.folder = { - _id: ObjectId(), + _id: new ObjectId(), name: 'test-folder', folders: [this.subfolder], } @@ -52,7 +52,7 @@ describe('ProjectEntityMongoUpdateHandler', function () { mongo: 'rootFolder.0.folders.0', } this.rootFolder = { - _id: ObjectId(), + _id: new ObjectId(), folders: [this.folder], docs: [this.doc], fileRefs: [this.file], @@ -62,7 +62,7 @@ describe('ProjectEntityMongoUpdateHandler', function () { mongo: 'rootFolder.0', } this.project = { - _id: ObjectId(), + _id: new ObjectId(), name: 'project name', rootFolder: [this.rootFolder], } @@ -221,7 +221,7 @@ describe('ProjectEntityMongoUpdateHandler', function () { describe('addDoc', function () { beforeEach(async function () { - const doc = { _id: ObjectId(), name: 'other.txt' } + const doc = { _id: new ObjectId(), name: 'other.txt' } this.ProjectMock.expects('findOneAndUpdate') .withArgs( { @@ -261,7 +261,7 @@ describe('ProjectEntityMongoUpdateHandler', function () { describe('addFile', function () { beforeEach(function () { - this.newFile = { _id: ObjectId(), name: 'picture.jpg' } + this.newFile = { _id: new ObjectId(), name: 'picture.jpg' } this.ProjectMock.expects('findOneAndUpdate') .withArgs( { @@ -329,7 +329,7 @@ describe('ProjectEntityMongoUpdateHandler', function () { beforeEach(async function () { const folderName = 'New folder' this.FolderModel.withArgs({ name: folderName }).returns({ - _id: ObjectId(), + _id: new ObjectId(), name: folderName, }) this.ProjectMock.expects('findOneAndUpdate') @@ -364,7 +364,7 @@ describe('ProjectEntityMongoUpdateHandler', function () { describe('replaceFileWithNew', function () { beforeEach(async function () { const newFile = { - _id: ObjectId(), + _id: new ObjectId(), name: 'some-other-file.png', linkedFileData: { some: 'data' }, hash: 'some-hash', @@ -460,7 +460,7 @@ describe('ProjectEntityMongoUpdateHandler', function () { describe('when the path is a new folder at the top level', function () { beforeEach(async function () { - this.newFolder = { _id: ObjectId(), name: 'new-folder' } + this.newFolder = { _id: new ObjectId(), name: 'new-folder' } this.FolderModel.returns(this.newFolder) this.exactCaseMatch = false this.ProjectMock.expects('findOneAndUpdate') @@ -504,7 +504,7 @@ describe('ProjectEntityMongoUpdateHandler', function () { describe('adding a subfolder', function () { beforeEach(async function () { - this.newFolder = { _id: ObjectId(), name: 'new-folder' } + this.newFolder = { _id: new ObjectId(), name: 'new-folder' } this.FolderModel.returns(this.newFolder) this.ProjectMock.expects('findOneAndUpdate') .withArgs( @@ -548,12 +548,12 @@ describe('ProjectEntityMongoUpdateHandler', function () { describe('when mutliple folders are missing', async function () { beforeEach(function () { - this.folder1 = { _id: ObjectId(), name: 'folder1' } + this.folder1 = { _id: new ObjectId(), name: 'folder1' } this.folder1Path = { fileSystem: '/test-folder/folder1', mongo: 'rootFolder.0.folders.0.folders.0', } - this.folder2 = { _id: ObjectId(), name: 'folder2' } + this.folder2 = { _id: new ObjectId(), name: 'folder2' } this.folder2Path = { fileSystem: '/test-folder/folder1/folder2', mongo: 'rootFolder.0.folders.0.folders.0.folders.0', @@ -865,7 +865,7 @@ describe('ProjectEntityMongoUpdateHandler', function () { describe('updating the project', function () { describe('when the parent folder is given', function () { beforeEach(function () { - this.newFile = { _id: ObjectId(), name: 'new file.png' } + this.newFile = { _id: new ObjectId(), name: 'new file.png' } this.ProjectMock.expects('findOneAndUpdate') .withArgs( { @@ -927,7 +927,7 @@ describe('ProjectEntityMongoUpdateHandler', function () { }) it('should error if element name contains invalid characters', async function () { - const file = { _id: ObjectId(), name: 'something*bad' } + const file = { _id: new ObjectId(), name: 'something*bad' } await expect( this.subject.promises._putElement( this.project, @@ -940,7 +940,7 @@ describe('ProjectEntityMongoUpdateHandler', function () { it('should error if element name is too long', async function () { const file = { - _id: ObjectId(), + _id: new ObjectId(), name: 'long-'.repeat(1000) + 'something', } await expect( @@ -955,7 +955,7 @@ describe('ProjectEntityMongoUpdateHandler', function () { it('should error if the folder name is too long', async function () { const file = { - _id: ObjectId(), + _id: new ObjectId(), name: 'something', } this.ProjectLocator.promises.findElement @@ -980,7 +980,7 @@ describe('ProjectEntityMongoUpdateHandler', function () { ;['file', 'doc', 'folder'].forEach(entityType => { it(`should error if a ${entityType} already exists with the same name`, async function () { const file = { - _id: ObjectId(), + _id: new ObjectId(), name: this[entityType].name, } await expect( @@ -998,7 +998,7 @@ describe('ProjectEntityMongoUpdateHandler', function () { describe('when the parent folder is not given', function () { it('should default to root folder insert', async function () { - this.newFile = { _id: ObjectId(), name: 'new file.png' } + this.newFile = { _id: new ObjectId(), name: 'new file.png' } this.ProjectMock.expects('findOneAndUpdate') .withArgs( { _id: this.project._id, 'rootFolder.0': { $exists: true } }, diff --git a/services/web/test/unit/src/Project/ProjectEntityUpdateHandlerTests.js b/services/web/test/unit/src/Project/ProjectEntityUpdateHandlerTests.js index 178a900d75..1cc3765557 100644 --- a/services/web/test/unit/src/Project/ProjectEntityUpdateHandlerTests.js +++ b/services/web/test/unit/src/Project/ProjectEntityUpdateHandlerTests.js @@ -182,7 +182,7 @@ describe('ProjectEntityUpdateHandler', function () { this.ranges = { mock: 'ranges' } this.lastUpdatedAt = new Date().getTime() this.lastUpdatedBy = 'fake-last-updater-id' - this.parentFolder = { _id: ObjectId() } + this.parentFolder = { _id: new ObjectId() } this.DocstoreManager.isDocDeleted.yields(null, false) this.ProjectGetter.getProject.yields(null, this.project) this.ProjectLocator.findElement.yields( @@ -1011,7 +1011,7 @@ describe('ProjectEntityUpdateHandler', function () { describe('updating an existing file', function () { beforeEach(function () { this.existingFile = { _id: fileId, name: this.fileName, rev: 1 } - this.newFile = { _id: ObjectId(), name: this.fileName, rev: 3 } + this.newFile = { _id: new ObjectId(), name: this.fileName, rev: 3 } this.folder = { _id: folderId, fileRefs: [this.existingFile], docs: [] } this.ProjectLocator.findElement.yields(null, this.folder) this.newProject = 'new-project-stub' @@ -2634,7 +2634,7 @@ describe('ProjectEntityUpdateHandler', function () { describe('_cleanUpDoc', function () { beforeEach(function () { this.doc = { - _id: ObjectId(), + _id: new ObjectId(), name: 'test.tex', } this.path = '/path/to/doc' @@ -2679,7 +2679,7 @@ describe('ProjectEntityUpdateHandler', function () { describe('when the doc is not the root doc', function () { beforeEach(function () { - this.project.rootDoc_id = ObjectId() + this.project.rootDoc_id = new ObjectId() this.ProjectEntityUpdateHandler._cleanUpDoc( this.project, this.doc, diff --git a/services/web/test/unit/src/Project/ProjectHelperTests.js b/services/web/test/unit/src/Project/ProjectHelperTests.js index 671e079cd6..e08c7865e7 100644 --- a/services/web/test/unit/src/Project/ProjectHelperTests.js +++ b/services/web/test/unit/src/Project/ProjectHelperTests.js @@ -47,8 +47,8 @@ describe('ProjectHelper', function () { describe('project.archived being an array', function () { it('returns true if user id is found', function () { this.project.archived = [ - ObjectId('588f3ddae8ebc1bac07c9fa4'), - ObjectId('5c41deb2b4ca500153340809'), + new ObjectId('588f3ddae8ebc1bac07c9fa4'), + new ObjectId('5c41deb2b4ca500153340809'), ] expect( this.ProjectHelper.isArchived(this.project, this.user._id) @@ -76,8 +76,8 @@ describe('ProjectHelper', function () { describe('isTrashed', function () { it('returns true if user id is found', function () { this.project.trashed = [ - ObjectId('588f3ddae8ebc1bac07c9fa4'), - ObjectId('5c41deb2b4ca500153340809'), + new ObjectId('588f3ddae8ebc1bac07c9fa4'), + new ObjectId('5c41deb2b4ca500153340809'), ] expect( this.ProjectHelper.isTrashed(this.project, this.user._id) @@ -107,17 +107,17 @@ describe('ProjectHelper', function () { const project = { archived: [] } const result = this.ProjectHelper.calculateArchivedArray( project, - ObjectId('5c922599cdb09e014aa7d499'), + new ObjectId('5c922599cdb09e014aa7d499'), 'ARCHIVE' ) - expect(result).to.deep.equal([ObjectId('5c922599cdb09e014aa7d499')]) + expect(result).to.deep.equal([new ObjectId('5c922599cdb09e014aa7d499')]) }) it('returns an array without the current user id when unarchiving', function () { - const project = { archived: [ObjectId('5c922599cdb09e014aa7d499')] } + const project = { archived: [new ObjectId('5c922599cdb09e014aa7d499')] } const result = this.ProjectHelper.calculateArchivedArray( project, - ObjectId('5c922599cdb09e014aa7d499'), + new ObjectId('5c922599cdb09e014aa7d499'), 'UNARCHIVE' ) expect(result).to.deep.equal([]) @@ -130,11 +130,13 @@ describe('ProjectHelper', function () { archived: true, owner_ref: this.user._id, collaberator_refs: [ - ObjectId('4f2cfb341eb5855a5b000f8b'), - ObjectId('5c45f3bd425ead01488675aa'), + new ObjectId('4f2cfb341eb5855a5b000f8b'), + new ObjectId('5c45f3bd425ead01488675aa'), + ], + readOnly_refs: [new ObjectId('5c92243fcdb09e014aa7d487')], + tokenAccessReadAndWrite_refs: [ + new ObjectId('5c922599cdb09e014aa7d499'), ], - readOnly_refs: [ObjectId('5c92243fcdb09e014aa7d487')], - tokenAccessReadAndWrite_refs: [ObjectId('5c922599cdb09e014aa7d499')], tokenAccessReadOnly_refs: [], } @@ -145,10 +147,10 @@ describe('ProjectHelper', function () { ) expect(result).to.deep.equal([ this.user._id, - ObjectId('4f2cfb341eb5855a5b000f8b'), - ObjectId('5c45f3bd425ead01488675aa'), - ObjectId('5c92243fcdb09e014aa7d487'), - ObjectId('5c922599cdb09e014aa7d499'), + new ObjectId('4f2cfb341eb5855a5b000f8b'), + new ObjectId('5c45f3bd425ead01488675aa'), + new ObjectId('5c92243fcdb09e014aa7d487'), + new ObjectId('5c922599cdb09e014aa7d499'), ]) }) @@ -157,12 +159,14 @@ describe('ProjectHelper', function () { archived: true, owner_ref: this.user._id, collaberator_refs: [ - ObjectId('4f2cfb341eb5855a5b000f8b'), - ObjectId('5c45f3bd425ead01488675aa'), - ObjectId('5c922599cdb09e014aa7d499'), + new ObjectId('4f2cfb341eb5855a5b000f8b'), + new ObjectId('5c45f3bd425ead01488675aa'), + new ObjectId('5c922599cdb09e014aa7d499'), + ], + readOnly_refs: [new ObjectId('5c92243fcdb09e014aa7d487')], + tokenAccessReadAndWrite_refs: [ + new ObjectId('5c922599cdb09e014aa7d499'), ], - readOnly_refs: [ObjectId('5c92243fcdb09e014aa7d487')], - tokenAccessReadAndWrite_refs: [ObjectId('5c922599cdb09e014aa7d499')], tokenAccessReadOnly_refs: [], } @@ -172,10 +176,10 @@ describe('ProjectHelper', function () { 'UNARCHIVE' ) expect(result).to.deep.equal([ - ObjectId('4f2cfb341eb5855a5b000f8b'), - ObjectId('5c45f3bd425ead01488675aa'), - ObjectId('5c922599cdb09e014aa7d499'), - ObjectId('5c92243fcdb09e014aa7d487'), + new ObjectId('4f2cfb341eb5855a5b000f8b'), + new ObjectId('5c45f3bd425ead01488675aa'), + new ObjectId('5c922599cdb09e014aa7d499'), + new ObjectId('5c92243fcdb09e014aa7d487'), ]) }) }) @@ -185,17 +189,17 @@ describe('ProjectHelper', function () { const project = { archived: false } const result = this.ProjectHelper.calculateArchivedArray( project, - ObjectId('5c922599cdb09e014aa7d499'), + new ObjectId('5c922599cdb09e014aa7d499'), 'ARCHIVE' ) - expect(result).to.deep.equal([ObjectId('5c922599cdb09e014aa7d499')]) + expect(result).to.deep.equal([new ObjectId('5c922599cdb09e014aa7d499')]) }) it('returns an empty array when unarchiving', function () { const project = { archived: false } const result = this.ProjectHelper.calculateArchivedArray( project, - ObjectId('5c922599cdb09e014aa7d499'), + new ObjectId('5c922599cdb09e014aa7d499'), 'UNARCHIVE' ) expect(result).to.deep.equal([]) @@ -207,17 +211,17 @@ describe('ProjectHelper', function () { const project = { archived: undefined } const result = this.ProjectHelper.calculateArchivedArray( project, - ObjectId('5c922599cdb09e014aa7d499'), + new ObjectId('5c922599cdb09e014aa7d499'), 'ARCHIVE' ) - expect(result).to.deep.equal([ObjectId('5c922599cdb09e014aa7d499')]) + expect(result).to.deep.equal([new ObjectId('5c922599cdb09e014aa7d499')]) }) it('returns an empty array when unarchiving', function () { const project = { archived: undefined } const result = this.ProjectHelper.calculateArchivedArray( project, - ObjectId('5c922599cdb09e014aa7d499'), + new ObjectId('5c922599cdb09e014aa7d499'), 'UNARCHIVE' ) expect(result).to.deep.equal([]) diff --git a/services/web/test/unit/src/Project/ProjectListControllerTests.js b/services/web/test/unit/src/Project/ProjectListControllerTests.js index e5dcf0905e..22b04e1497 100644 --- a/services/web/test/unit/src/Project/ProjectListControllerTests.js +++ b/services/web/test/unit/src/Project/ProjectListControllerTests.js @@ -12,10 +12,10 @@ const MODULE_PATH = path.join( describe('ProjectListController', function () { beforeEach(function () { - this.project_id = ObjectId('abcdefabcdefabcdefabcdef') + this.project_id = new ObjectId('abcdefabcdefabcdefabcdef') this.user = { - _id: ObjectId('123456123456123456123456'), + _id: new ObjectId('123456123456123456123456'), email: 'test@overleaf.com', first_name: 'bjkdsjfk', features: {}, diff --git a/services/web/test/unit/src/SplitTests/SplitTestHandlerTests.js b/services/web/test/unit/src/SplitTests/SplitTestHandlerTests.js index bf30d289a1..7b147f8597 100644 --- a/services/web/test/unit/src/SplitTests/SplitTestHandlerTests.js +++ b/services/web/test/unit/src/SplitTests/SplitTestHandlerTests.js @@ -79,7 +79,7 @@ describe('SplitTestHandler', function () { describe('with an existing user', function () { beforeEach(async function () { this.user = { - _id: ObjectId(), + _id: new ObjectId(), splitTests: { 'active-test': [ { @@ -149,7 +149,7 @@ describe('SplitTestHandler', function () { describe('with an non-existent user', function () { beforeEach(async function () { - const unknownUserId = ObjectId() + const unknownUserId = new ObjectId() this.assignments = await this.SplitTestHandler.promises.getActiveAssignmentsForUser( unknownUserId @@ -163,7 +163,7 @@ describe('SplitTestHandler', function () { describe('with a user without assignments', function () { beforeEach(async function () { - this.user = { _id: ObjectId() } + this.user = { _id: new ObjectId() } this.UserGetter.promises.getUser .withArgs(this.user._id) .resolves(this.user) diff --git a/services/web/test/unit/src/Subscription/GroupSSOHandlerTests.js b/services/web/test/unit/src/Subscription/GroupSSOHandlerTests.js index bc84a7914b..efab09a9ca 100644 --- a/services/web/test/unit/src/Subscription/GroupSSOHandlerTests.js +++ b/services/web/test/unit/src/Subscription/GroupSSOHandlerTests.js @@ -11,7 +11,7 @@ describe('GroupSSOHandler', function () { beforeEach(function () { this.user = { _id: new ObjectId(), enrollment: { sso: [] } } this.subscription = { - _id: ObjectId().toString(), + _id: new ObjectId().toString(), admin_id: new ObjectId(), member_ids: [this.user._id], } diff --git a/services/web/test/unit/src/Subscription/SubscriptionUpdaterTests.js b/services/web/test/unit/src/Subscription/SubscriptionUpdaterTests.js index b606c7462e..f2abc445af 100644 --- a/services/web/test/unit/src/Subscription/SubscriptionUpdaterTests.js +++ b/services/web/test/unit/src/Subscription/SubscriptionUpdaterTests.js @@ -181,12 +181,12 @@ describe('SubscriptionUpdater', function () { this.otherUserId ) const query = { - _id: ObjectId(this.subscription._id), + _id: new ObjectId(this.subscription._id), customAccount: true, } const update = { - $set: { admin_id: ObjectId(this.otherUserId) }, - $addToSet: { manager_ids: ObjectId(this.otherUserId) }, + $set: { admin_id: new ObjectId(this.otherUserId) }, + $addToSet: { manager_ids: new ObjectId(this.otherUserId) }, } this.SubscriptionModel.updateOne.should.have.been.calledOnce this.SubscriptionModel.updateOne.should.have.been.calledWith( @@ -201,13 +201,13 @@ describe('SubscriptionUpdater', function () { this.otherUserId ) const query = { - _id: ObjectId(this.subscription._id), + _id: new ObjectId(this.subscription._id), customAccount: true, } const update = { $set: { - admin_id: ObjectId(this.otherUserId), - manager_ids: [ObjectId(this.otherUserId)], + admin_id: new ObjectId(this.otherUserId), + manager_ids: [new ObjectId(this.otherUserId)], }, } this.SubscriptionModel.updateOne.should.have.been.calledOnce @@ -710,10 +710,10 @@ describe('SubscriptionUpdater', function () { describe('deleteSubscription', function () { beforeEach(async function () { this.subscription = { - _id: ObjectId().toString(), + _id: new ObjectId().toString(), mock: 'subscription', - admin_id: ObjectId(), - member_ids: [ObjectId(), ObjectId(), ObjectId()], + admin_id: new ObjectId(), + member_ids: [new ObjectId(), new ObjectId(), new ObjectId()], } await this.SubscriptionUpdater.promises.deleteSubscription( this.subscription, diff --git a/services/web/test/unit/src/Tags/TagsHandlerTests.js b/services/web/test/unit/src/Tags/TagsHandlerTests.js index b68bed71ae..aa9e4bb363 100644 --- a/services/web/test/unit/src/Tags/TagsHandlerTests.js +++ b/services/web/test/unit/src/Tags/TagsHandlerTests.js @@ -10,13 +10,13 @@ const modulePath = require('path').join( describe('TagsHandler', function () { beforeEach(function () { - this.userId = ObjectId().toString() + this.userId = new ObjectId().toString() this.callback = sinon.stub() this.tag = { user_id: this.userId, name: 'some name', color: '#3399CC' } - this.tagId = ObjectId().toString() - this.projectId = ObjectId().toString() - this.projectIds = [ObjectId().toString(), ObjectId().toString()] + this.tagId = new ObjectId().toString() + this.projectId = new ObjectId().toString() + this.projectIds = [new ObjectId().toString(), new ObjectId().toString()] this.mongodb = { ObjectId } this.TagMock = sinon.mock(Tag) diff --git a/services/web/test/unit/src/ThirdPartyDataStore/TpdsControllerTests.js b/services/web/test/unit/src/ThirdPartyDataStore/TpdsControllerTests.js index 1f9919fa7b..076cde6f37 100644 --- a/services/web/test/unit/src/ThirdPartyDataStore/TpdsControllerTests.js +++ b/services/web/test/unit/src/ThirdPartyDataStore/TpdsControllerTests.js @@ -12,9 +12,9 @@ const MODULE_PATH = describe('TpdsController', function () { beforeEach(function () { this.metadata = { - projectId: ObjectId(), - entityId: ObjectId(), - folderId: ObjectId(), + projectId: new ObjectId(), + entityId: new ObjectId(), + folderId: new ObjectId(), entityType: 'doc', rev: 2, } @@ -46,7 +46,7 @@ describe('TpdsController', function () { conflict: sinon.stub(), } - this.newProject = { _id: ObjectId() } + this.newProject = { _id: new ObjectId() } this.ProjectCreationHandler = { promises: { createBlankProject: sinon.stub().resolves(this.newProject) }, } @@ -291,10 +291,10 @@ describe('TpdsController', function () { it("creates a folder if it doesn't exist", function (done) { const metadata = { - folderId: ObjectId(), - projectId: ObjectId(), + folderId: new ObjectId(), + projectId: new ObjectId(), path: '/def/ghi.txt', - parentFolderId: ObjectId(), + parentFolderId: new ObjectId(), } this.TpdsUpdateHandler.promises.createFolder.resolves(metadata) this.res.json.callsFake(body => { @@ -311,8 +311,8 @@ describe('TpdsController', function () { it('supports top level folders', function (done) { const metadata = { - folderId: ObjectId(), - projectId: ObjectId(), + folderId: new ObjectId(), + projectId: new ObjectId(), path: '/', parentFolderId: null, } diff --git a/services/web/test/unit/src/ThirdPartyDataStore/TpdsProjectFlusherTests.js b/services/web/test/unit/src/ThirdPartyDataStore/TpdsProjectFlusherTests.js index 6f01521b40..dd9e24d080 100644 --- a/services/web/test/unit/src/ThirdPartyDataStore/TpdsProjectFlusherTests.js +++ b/services/web/test/unit/src/ThirdPartyDataStore/TpdsProjectFlusherTests.js @@ -9,8 +9,8 @@ const MODULE_PATH = describe('TpdsProjectFlusher', function () { beforeEach(function () { - this.project = { _id: ObjectId() } - this.folder = { _id: ObjectId() } + this.project = { _id: new ObjectId() } + this.folder = { _id: new ObjectId() } this.docs = { '/doc/one': { _id: 'mock-doc-1', diff --git a/services/web/test/unit/src/ThirdPartyDataStore/TpdsUpdateHandlerTests.js b/services/web/test/unit/src/ThirdPartyDataStore/TpdsUpdateHandlerTests.js index 75b3ef5398..8527e8c1ab 100644 --- a/services/web/test/unit/src/ThirdPartyDataStore/TpdsUpdateHandlerTests.js +++ b/services/web/test/unit/src/ThirdPartyDataStore/TpdsUpdateHandlerTests.js @@ -38,8 +38,8 @@ describe('TpdsUpdateHandler', function () { this.update = {} this.folderPath = '/some/folder' this.folder = { - _id: ObjectId(), - parentFolder_id: ObjectId(), + _id: new ObjectId(), + parentFolder_id: new ObjectId(), } this.CooldownManager = { @@ -125,7 +125,7 @@ describe('TpdsUpdateHandler', function () { describe('byId', function () { describe('with no matching project', function () { beforeEach(function () { - this.projectId = ObjectId().toString() + this.projectId = new ObjectId().toString() }) receiveUpdateById() expectProjectNotCreated() @@ -222,7 +222,7 @@ describe('TpdsUpdateHandler', function () { describe('byId', function () { describe('with no matching project', function () { beforeEach(function () { - this.projectId = ObjectId().toString() + this.projectId = new ObjectId().toString() }) receiveFileDeleteById() expectDeleteNotProcessed() diff --git a/services/web/test/unit/src/ThirdPartyDataStore/TpdsUpdateSenderTests.js b/services/web/test/unit/src/ThirdPartyDataStore/TpdsUpdateSenderTests.js index c4e98e8144..ed195fd9bf 100644 --- a/services/web/test/unit/src/ThirdPartyDataStore/TpdsUpdateSenderTests.js +++ b/services/web/test/unit/src/ThirdPartyDataStore/TpdsUpdateSenderTests.js @@ -10,9 +10,9 @@ const modulePath = path.join( ) const projectId = 'project_id_here' -const userId = ObjectId() -const readOnlyRef = ObjectId() -const collaberatorRef = ObjectId() +const userId = new ObjectId() +const readOnlyRef = new ObjectId() +const collaberatorRef = new ObjectId() const projectName = 'project_name_here' const thirdPartyDataStoreApiUrl = 'http://third-party-json-store.herokuapp.com' diff --git a/services/web/test/unit/src/ThirdPartyDataStore/UpdateMergerTests.js b/services/web/test/unit/src/ThirdPartyDataStore/UpdateMergerTests.js index 5e92a04b11..3591775dad 100644 --- a/services/web/test/unit/src/ThirdPartyDataStore/UpdateMergerTests.js +++ b/services/web/test/unit/src/ThirdPartyDataStore/UpdateMergerTests.js @@ -48,17 +48,17 @@ describe('UpdateMerger :', function () { } this.doc = { - _id: ObjectId(), + _id: new ObjectId(), rev: 2, } this.file = { - _id: ObjectId(), + _id: new ObjectId(), rev: 6, } this.folder = { - _id: ObjectId(), + _id: new ObjectId(), } this.EditorController = { diff --git a/services/web/test/unit/src/TokenAccess/TokenAccessControllerTests.js b/services/web/test/unit/src/TokenAccess/TokenAccessControllerTests.js index 830a17b73f..fd0b9758e9 100644 --- a/services/web/test/unit/src/TokenAccess/TokenAccessControllerTests.js +++ b/services/web/test/unit/src/TokenAccess/TokenAccessControllerTests.js @@ -12,9 +12,9 @@ const MODULE_PATH = describe('TokenAccessController', function () { beforeEach(function () { this.token = 'abc123' - this.user = { _id: ObjectId() } + this.user = { _id: new ObjectId() } this.project = { - _id: ObjectId(), + _id: new ObjectId(), tokenAccessReadAndWrite_refs: [], tokenAccessReadOnly_refs: [], } diff --git a/services/web/test/unit/src/TokenAccess/TokenAccessHandlerTests.js b/services/web/test/unit/src/TokenAccess/TokenAccessHandlerTests.js index 94ce66ee3f..fa25351d0c 100644 --- a/services/web/test/unit/src/TokenAccess/TokenAccessHandlerTests.js +++ b/services/web/test/unit/src/TokenAccess/TokenAccessHandlerTests.js @@ -11,13 +11,13 @@ const { ObjectId } = require('mongodb') describe('TokenAccessHandler', function () { beforeEach(function () { this.token = 'abcdefabcdef' - this.projectId = ObjectId() + this.projectId = new ObjectId() this.project = { _id: this.projectId, publicAccesLevel: 'tokenBased', - owner_ref: ObjectId(), + owner_ref: new ObjectId(), } - this.userId = ObjectId() + this.userId = new ObjectId() this.req = {} this.TokenAccessHandler = SandboxedModule.require(modulePath, { requires: { diff --git a/services/web/test/unit/src/User/SAMLIdentityManagerTests.js b/services/web/test/unit/src/User/SAMLIdentityManagerTests.js index e6e1f1baaa..8b00392901 100644 --- a/services/web/test/unit/src/User/SAMLIdentityManagerTests.js +++ b/services/web/test/unit/src/User/SAMLIdentityManagerTests.js @@ -370,7 +370,7 @@ describe('SAMLIdentityManager', function () { expect( this.UserGetter.promises.getUser ).to.have.been.calledWithMatch({ - _id: ObjectId('6005c75b12cbcaf771f4a105'), + _id: new ObjectId('6005c75b12cbcaf771f4a105'), 'samlIdentifiers.providerId': '123456', }) expect(error).to.be.instanceof(Errors.SAMLAlreadyLinkedError) diff --git a/services/web/test/unit/src/User/UserAuditLogHandlerTests.js b/services/web/test/unit/src/User/UserAuditLogHandlerTests.js index 86bd07d141..9c92e148ce 100644 --- a/services/web/test/unit/src/User/UserAuditLogHandlerTests.js +++ b/services/web/test/unit/src/User/UserAuditLogHandlerTests.js @@ -8,8 +8,8 @@ const MODULE_PATH = '../../../../app/src/Features/User/UserAuditLogHandler' describe('UserAuditLogHandler', function () { beforeEach(function () { - this.userId = ObjectId() - this.initiatorId = ObjectId() + this.userId = new ObjectId() + this.initiatorId = new ObjectId() this.action = { operation: 'clear-sessions', initiatorId: this.initiatorId, diff --git a/services/web/test/unit/src/User/UserDeleterTests.js b/services/web/test/unit/src/User/UserDeleterTests.js index 5f96dc36f9..1682031ea8 100644 --- a/services/web/test/unit/src/User/UserDeleterTests.js +++ b/services/web/test/unit/src/User/UserDeleterTests.js @@ -14,7 +14,7 @@ describe('UserDeleter', function () { beforeEach(function () { tk.freeze(Date.now()) - this.userId = ObjectId() + this.userId = new ObjectId() this.UserMock = sinon.mock(User) this.DeletedUserMock = sinon.mock(DeletedUser) @@ -289,7 +289,7 @@ describe('UserDeleter', function () { describe('when a user and IP address are specified', function () { beforeEach(function () { this.ipAddress = '1.2.3.4' - this.deleterId = ObjectId() + this.deleterId = new ObjectId() this.deletedUser.deleterData.deleterIpAddress = this.ipAddress this.deletedUser.deleterData.deleterId = this.deleterId diff --git a/services/web/test/unit/src/User/UserInfoControllerTests.js b/services/web/test/unit/src/User/UserInfoControllerTests.js index 6f48fb8731..48040a516b 100644 --- a/services/web/test/unit/src/User/UserInfoControllerTests.js +++ b/services/web/test/unit/src/User/UserInfoControllerTests.js @@ -32,8 +32,8 @@ describe('UserInfoController', function () { describe('getPersonalInfo', function () { describe('when the user exists with sharelatex id', function () { beforeEach(function () { - this.user_id = ObjectId().toString() - this.user = { _id: ObjectId(this.user_id) } + this.user_id = new ObjectId().toString() + this.user = { _id: new ObjectId(this.user_id) } this.req.params = { user_id: this.user_id } this.UserGetter.getUser = sinon.stub().callsArgWith(2, null, this.user) this.UserInfoController.sendFormattedPersonalInfo = sinon.stub() @@ -43,7 +43,7 @@ describe('UserInfoController', function () { it('should look up the user in the database', function () { this.UserGetter.getUser .calledWith( - { _id: ObjectId(this.user_id) }, + { _id: new ObjectId(this.user_id) }, { _id: true, first_name: true, last_name: true, email: true } ) .should.equal(true) @@ -54,7 +54,7 @@ describe('UserInfoController', function () { beforeEach(function () { this.user_id = 12345 this.user = { - _id: ObjectId(), + _id: new ObjectId(), overleaf: { id: this.user_id, }, @@ -76,7 +76,7 @@ describe('UserInfoController', function () { describe('when the user does not exist', function () { beforeEach(function () { - this.user_id = ObjectId().toString() + this.user_id = new ObjectId().toString() this.req.params = { user_id: this.user_id } this.UserGetter.getUser = sinon.stub().callsArgWith(2, null, null) this.UserInfoController.getPersonalInfo(this.req, this.res, this.next) @@ -104,7 +104,7 @@ describe('UserInfoController', function () { describe('sendFormattedPersonalInfo', function () { beforeEach(function () { this.user = { - _id: ObjectId(), + _id: new ObjectId(), first_name: 'Douglas', last_name: 'Adams', email: 'doug@sharelatex.com', @@ -126,7 +126,7 @@ describe('UserInfoController', function () { describe('formatPersonalInfo', function () { it('should return the correctly formatted data', function () { this.user = { - _id: ObjectId(), + _id: new ObjectId(), first_name: 'Douglas', last_name: 'Adams', email: 'doug@sharelatex.com', diff --git a/services/web/test/unit/src/User/UserUpdaterTests.js b/services/web/test/unit/src/User/UserUpdaterTests.js index 641b0251b8..7aed708c39 100644 --- a/services/web/test/unit/src/User/UserUpdaterTests.js +++ b/services/web/test/unit/src/User/UserUpdaterTests.js @@ -18,7 +18,7 @@ describe('UserUpdater', function () { tk.freeze(Date.now()) this.user = { - _id: ObjectId(), + _id: new ObjectId(), name: 'bob', email: 'hello@world.com', emails: [{ email: 'hello@world.com' }], @@ -31,9 +31,7 @@ describe('UserUpdater', function () { } this.mongodb = { db: this.db, - ObjectId(id) { - return id - }, + ObjectId, } this.UserGetter = { diff --git a/services/web/test/unit/src/UserMembership/UserMembershipHandlerTests.js b/services/web/test/unit/src/UserMembership/UserMembershipHandlerTests.js index b5d445873e..6ea0b14a98 100644 --- a/services/web/test/unit/src/UserMembership/UserMembershipHandlerTests.js +++ b/services/web/test/unit/src/UserMembership/UserMembershipHandlerTests.js @@ -27,15 +27,15 @@ const { describe('UserMembershipHandler', function () { beforeEach(function () { - this.user = { _id: ObjectId() } - this.newUser = { _id: ObjectId(), email: 'new-user-email@foo.bar' } - this.fakeEntityId = ObjectId() + this.user = { _id: new ObjectId() } + this.newUser = { _id: new ObjectId(), email: 'new-user-email@foo.bar' } + this.fakeEntityId = new ObjectId() this.subscription = { _id: 'mock-subscription-id', groupPlan: true, membersLimit: 10, - member_ids: [ObjectId(), ObjectId()], - manager_ids: [ObjectId()], + member_ids: [new ObjectId(), new ObjectId()], + manager_ids: [new ObjectId()], invited_emails: ['mock-email-1@foo.com'], teamInvites: [{ email: 'mock-email-1@bar.com' }], update: sinon.stub().yields(null), @@ -43,13 +43,13 @@ describe('UserMembershipHandler', function () { this.institution = { _id: 'mock-institution-id', v1Id: 123, - managerIds: [ObjectId(), ObjectId(), ObjectId()], + managerIds: [new ObjectId(), new ObjectId(), new ObjectId()], updateOne: sinon.stub().yields(null), } this.publisher = { _id: 'mock-publisher-id', slug: 'slug', - managerIds: [ObjectId(), ObjectId()], + managerIds: [new ObjectId(), new ObjectId()], updateOne: sinon.stub().yields(null), } diff --git a/services/web/test/unit/src/UserMembership/UserMembershipViewModelTests.js b/services/web/test/unit/src/UserMembership/UserMembershipViewModelTests.js index 7ea0c35855..bf1500ec44 100644 --- a/services/web/test/unit/src/UserMembership/UserMembershipViewModelTests.js +++ b/services/web/test/unit/src/UserMembership/UserMembershipViewModelTests.js @@ -109,7 +109,7 @@ describe('UserMembershipViewModel', function () { it('build user id', function (done) { this.UserGetter.getUser.yields(null, this.user) return this.UserMembershipViewModel.buildAsync( - ObjectId(), + new ObjectId(), (error, viewModel) => { expect(error).not.to.exist assertNotCalled(this.UserMembershipViewModel.build) @@ -127,7 +127,7 @@ describe('UserMembershipViewModel', function () { it('build user id with error', function (done) { this.UserGetter.getUser.yields(new Error('nope')) - const userId = ObjectId() + const userId = new ObjectId() return this.UserMembershipViewModel.buildAsync( userId, (error, viewModel) => { diff --git a/services/web/test/unit/src/UserMembership/UserMembershipsHandlerTests.js b/services/web/test/unit/src/UserMembership/UserMembershipsHandlerTests.js index 90ef4db584..f0c11c7044 100644 --- a/services/web/test/unit/src/UserMembership/UserMembershipsHandlerTests.js +++ b/services/web/test/unit/src/UserMembership/UserMembershipsHandlerTests.js @@ -19,7 +19,7 @@ const SandboxedModule = require('sandboxed-module') describe('UserMembershipsHandler', function () { beforeEach(function () { - this.user = { _id: ObjectId() } + this.user = { _id: new ObjectId() } this.Institution = { updateMany: sinon.stub().yields(null) } this.Subscription = { updateMany: sinon.stub().yields(null) }