diff --git a/services/web/app/src/Features/Collaborators/CollaboratorsHandler.js b/services/web/app/src/Features/Collaborators/CollaboratorsHandler.js index 8bce297920..d8e4484248 100644 --- a/services/web/app/src/Features/Collaborators/CollaboratorsHandler.js +++ b/services/web/app/src/Features/Collaborators/CollaboratorsHandler.js @@ -41,7 +41,7 @@ async function removeUserFromProject(projectId, userId) { archived = archived.filter(id => id.toString() !== userId.toString()) - await Project.update( + await Project.updateOne( { _id: projectId }, { $set: { archived: archived }, @@ -55,7 +55,7 @@ async function removeUserFromProject(projectId, userId) { } ) } else { - await Project.update( + await Project.updateOne( { _id: projectId }, { $pull: { @@ -126,7 +126,7 @@ async function addUserIdToProject( ContactManager.addContact(addingUserId, userId) } - await Project.update({ _id: projectId }, { $addToSet: level }).exec() + await Project.updateOne({ _id: projectId }, { $addToSet: level }).exec() // Flush to TPDS in background to add files to collaborator's Dropbox TpdsProjectFlusher.promises.flushProjectToTpds(projectId).catch(err => { @@ -152,40 +152,35 @@ async function transferProjects(fromUserId, toUserId) { const projectIds = projects.map(p => p._id) logger.log({ projectIds, fromUserId, toUserId }, 'transferring projects') - await Project.update( + await Project.updateMany( { owner_ref: fromUserId }, - { $set: { owner_ref: toUserId } }, - { multi: true } + { $set: { owner_ref: toUserId } } ).exec() - await Project.update( + await Project.updateMany( { collaberator_refs: fromUserId }, { $addToSet: { collaberator_refs: toUserId } - }, - { multi: true } + } ).exec() - await Project.update( + await Project.updateMany( { collaberator_refs: fromUserId }, { $pull: { collaberator_refs: fromUserId } - }, - { multi: true } + } ).exec() - await Project.update( + await Project.updateMany( { readOnly_refs: fromUserId }, { $addToSet: { readOnly_refs: toUserId } - }, - { multi: true } + } ).exec() - await Project.update( + await Project.updateMany( { readOnly_refs: fromUserId }, { $pull: { readOnly_refs: fromUserId } - }, - { multi: true } + } ).exec() // Flush in background, no need to block on this diff --git a/services/web/app/src/Features/Collaborators/CollaboratorsInviteHandler.js b/services/web/app/src/Features/Collaborators/CollaboratorsInviteHandler.js index 3728d68c5d..7e9bdb41dc 100644 --- a/services/web/app/src/Features/Collaborators/CollaboratorsInviteHandler.js +++ b/services/web/app/src/Features/Collaborators/CollaboratorsInviteHandler.js @@ -51,7 +51,7 @@ const CollaboratorsInviteHandler = { callback = function(err, count) {} } logger.log({ projectId }, 'counting invites for project') - return ProjectInvite.count({ projectId }, function(err, count) { + return ProjectInvite.countDocuments({ projectId }, function(err, count) { if (err != null) { OError.tag(err, 'error getting invites from mongo', { projectId @@ -212,7 +212,7 @@ const CollaboratorsInviteHandler = { callback = function(err) {} } logger.log({ projectId, inviteId }, 'removing invite') - return ProjectInvite.remove({ projectId, _id: inviteId }, function(err) { + return ProjectInvite.deleteOne({ projectId, _id: inviteId }, function(err) { if (err != null) { OError.tag(err, 'error removing invite', { projectId, @@ -333,7 +333,7 @@ const CollaboratorsInviteHandler = { } // Remove invite logger.log({ projectId, inviteId }, 'removing invite') - return ProjectInvite.remove({ _id: inviteId }, function(err) { + return ProjectInvite.deleteOne({ _id: inviteId }, function(err) { if (err != null) { OError.tag(err, 'error removing invite', { projectId, diff --git a/services/web/app/src/Features/Collaborators/OwnershipTransferHandler.js b/services/web/app/src/Features/Collaborators/OwnershipTransferHandler.js index 8221cc428a..fc93f01fab 100644 --- a/services/web/app/src/Features/Collaborators/OwnershipTransferHandler.js +++ b/services/web/app/src/Features/Collaborators/OwnershipTransferHandler.js @@ -83,7 +83,7 @@ async function _transferOwnership(projectId, previousOwnerId, newOwnerId) { projectId, newOwnerId ) - await Project.update( + await Project.updateOne( { _id: projectId }, { $set: { owner_ref: newOwnerId } } ).exec() diff --git a/services/web/app/src/Features/Project/ProjectCollabratecDetailsHandler.js b/services/web/app/src/Features/Project/ProjectCollabratecDetailsHandler.js index 7366bd589c..f1813b169d 100644 --- a/services/web/app/src/Features/Project/ProjectCollabratecDetailsHandler.js +++ b/services/web/app/src/Features/Project/ProjectCollabratecDetailsHandler.js @@ -96,7 +96,7 @@ module.exports = ProjectCollabratecDetailsHandler = { } } } - return Project.update(query, update, callback) + return Project.updateOne(query, update, callback) }, setCollabratecUsers(project_id, collabratec_users, callback) { @@ -122,7 +122,7 @@ module.exports = ProjectCollabratecDetailsHandler = { } } const update = { $set: { collabratecUsers: collabratec_users } } - return Project.update({ _id: project_id }, update, callback) + return Project.updateOne({ _id: project_id }, update, callback) }, unlinkCollabratecUserProject(project_id, user_id, callback) { @@ -144,7 +144,7 @@ module.exports = ProjectCollabratecDetailsHandler = { } } } - return Project.update(query, update, callback) + return Project.updateOne(query, update, callback) }, updateCollabratecUserIds(old_user_id, new_user_id, callback) { @@ -160,7 +160,6 @@ module.exports = ProjectCollabratecDetailsHandler = { } const query = { 'collabratecUsers.user_id': old_user_id } const update = { $set: { 'collabratecUsers.$.user_id': new_user_id } } - const options = { multi: true } - return Project.update(query, update, options, callback) + return Project.updateMany(query, update, callback) } } diff --git a/services/web/app/src/Features/Project/ProjectDeleter.js b/services/web/app/src/Features/Project/ProjectDeleter.js index ebe69a9042..ac352317a4 100644 --- a/services/web/app/src/Features/Project/ProjectDeleter.js +++ b/services/web/app/src/Features/Project/ProjectDeleter.js @@ -57,7 +57,7 @@ async function markAsDeletedByExternalSource(projectId) { { project_id: projectId }, 'marking project as deleted by external data source' ) - await Project.update( + await Project.updateOne( { _id: projectId }, { deletedByExternalDataSource: true } ).exec() @@ -68,7 +68,7 @@ async function markAsDeletedByExternalSource(projectId) { } async function unmarkAsDeletedByExternalSource(projectId) { - await Project.update( + await Project.updateOne( { _id: projectId }, { deletedByExternalDataSource: false } ).exec() @@ -101,7 +101,7 @@ async function expireDeletedProjectsAfterDuration() { } async function restoreProject(projectId) { - await Project.update( + await Project.updateOne( { _id: projectId }, { $unset: { archived: true } } ).exec() @@ -119,7 +119,7 @@ async function archiveProject(projectId, userId) { 'ARCHIVE' ) - await Project.update( + await Project.updateOne( { _id: projectId }, { $set: { archived: archived }, $pull: { trashed: ObjectId(userId) } } ) @@ -142,7 +142,10 @@ async function unarchiveProject(projectId, userId) { 'UNARCHIVE' ) - await Project.update({ _id: projectId }, { $set: { archived: archived } }) + await Project.updateOne( + { _id: projectId }, + { $set: { archived: archived } } + ) } catch (err) { logger.warn({ err }, 'problem unarchiving project') throw err @@ -162,7 +165,7 @@ async function trashProject(projectId, userId) { 'UNARCHIVE' ) - await Project.update( + await Project.updateOne( { _id: projectId }, { $addToSet: { trashed: ObjectId(userId) }, @@ -182,7 +185,7 @@ async function untrashProject(projectId, userId) { throw new Errors.NotFoundError('project not found') } - await Project.update( + await Project.updateOne( { _id: projectId }, { $pull: { trashed: ObjectId(userId) } } ) @@ -227,7 +230,7 @@ async function deleteProject(projectId, options = {}) { key => (deleterData[key] === undefined ? delete deleterData[key] : '') ) - await DeletedProject.update( + await DeletedProject.updateOne( { 'deleterData.deletedProjectId': projectId }, { project, deleterData }, { upsert: true } @@ -251,7 +254,7 @@ async function deleteProject(projectId, options = {}) { }) } - await Project.remove({ _id: projectId }).exec() + await Project.deleteOne({ _id: projectId }).exec() } catch (err) { logger.warn({ err }, 'problem deleting project') throw err @@ -316,7 +319,7 @@ async function expireDeletedProject(projectId) { await HistoryManager.promises.deleteProject(deletedProject.project._id) await FilestoreHandler.promises.deleteProject(deletedProject.project._id) - await DeletedProject.update( + await DeletedProject.updateOne( { _id: deletedProject._id }, diff --git a/services/web/app/src/Features/Project/ProjectDetailsHandler.js b/services/web/app/src/Features/Project/ProjectDetailsHandler.js index c0f43fdbc7..09d8f39e52 100644 --- a/services/web/app/src/Features/Project/ProjectDetailsHandler.js +++ b/services/web/app/src/Features/Project/ProjectDetailsHandler.js @@ -90,7 +90,7 @@ async function setProjectDescription(projectId, description) { 'setting project description' ) try { - await Project.update(conditions, update).exec() + await Project.updateOne(conditions, update).exec() } catch (err) { logger.warn({ err }, 'something went wrong setting project description') throw err @@ -111,7 +111,7 @@ async function renameProject(projectId, newName) { return } const oldProjectName = project.name - await Project.update({ _id: projectId }, { name: newName }).exec() + await Project.updateOne({ _id: projectId }, { name: newName }).exec() await TpdsUpdateSender.promises.moveEntity({ project_id: projectId, project_name: oldProjectName, @@ -197,7 +197,7 @@ async function setPublicAccessLevel(projectId, newAccessLevel) { newAccessLevel ) ) { - await Project.update( + await Project.updateOne( { _id: projectId }, { publicAccesLevel: newAccessLevel } ).exec() @@ -216,7 +216,7 @@ async function ensureTokensArePresent(projectId) { return project.tokens } await _generateTokens(project) - await Project.update( + await Project.updateOne( { _id: projectId }, { $set: { tokens: project.tokens } } ).exec() @@ -224,7 +224,7 @@ async function ensureTokensArePresent(projectId) { } async function clearTokens(projectId) { - await Project.update( + await Project.updateOne( { _id: projectId }, { $unset: { tokens: 1 }, $set: { publicAccesLevel: 'private' } } ).exec() diff --git a/services/web/app/src/Features/Project/ProjectEntityUpdateHandler.js b/services/web/app/src/Features/Project/ProjectEntityUpdateHandler.js index e1c02fd09e..0d21a757cc 100644 --- a/services/web/app/src/Features/Project/ProjectEntityUpdateHandler.js +++ b/services/web/app/src/Features/Project/ProjectEntityUpdateHandler.js @@ -182,7 +182,7 @@ const ProjectEntityUpdateHandler = { return callback(err) } if (ProjectEntityUpdateHandler.isPathValidForRootDoc(docPath)) { - Project.update( + Project.updateOne( { _id: projectId }, { rootDoc_id: newRootDocID }, {}, @@ -201,7 +201,7 @@ const ProjectEntityUpdateHandler = { unsetRootDoc(projectId, callback) { logger.log({ projectId }, 'removing root doc') - Project.update( + Project.updateOne( { _id: projectId }, { $unset: { rootDoc_id: true } }, {}, diff --git a/services/web/app/src/Features/Project/ProjectHistoryHandler.js b/services/web/app/src/Features/Project/ProjectHistoryHandler.js index 734e3026ee..74529f8098 100644 --- a/services/web/app/src/Features/Project/ProjectHistoryHandler.js +++ b/services/web/app/src/Features/Project/ProjectHistoryHandler.js @@ -31,7 +31,7 @@ const ProjectHistoryHandler = { return callback(new Error('invalid history id')) } // use $exists:false to prevent overwriting any existing history id, atomically - return Project.update( + return Project.updateOne( { _id: project_id, 'overleaf.history.id': { $exists: false } }, { 'overleaf.history.id': history_id }, function(err, result) { @@ -72,7 +72,7 @@ const ProjectHistoryHandler = { if (callback == null) { callback = function(err, result) {} } - return Project.update( + return Project.updateOne( { _id: project_id, 'overleaf.history.id': { $exists: true } }, { 'overleaf.history.display': true, @@ -95,7 +95,7 @@ const ProjectHistoryHandler = { if (callback == null) { callback = function(err, result) {} } - return Project.update( + return Project.updateOne( { _id: project_id, 'overleaf.history.upgradedAt': { $exists: true } }, { 'overleaf.history.display': false, diff --git a/services/web/app/src/Features/Project/ProjectOptionsHandler.js b/services/web/app/src/Features/Project/ProjectOptionsHandler.js index e03f65ec7e..1a9852621e 100644 --- a/services/web/app/src/Features/Project/ProjectOptionsHandler.js +++ b/services/web/app/src/Features/Project/ProjectOptionsHandler.js @@ -15,7 +15,7 @@ const ProjectOptionsHandler = { } const conditions = { _id: projectId } const update = { compiler } - Project.update(conditions, update, {}, callback) + Project.updateOne(conditions, update, {}, callback) }, setImageName(projectId, imageName, callback) { @@ -31,7 +31,7 @@ const ProjectOptionsHandler = { } const conditions = { _id: projectId } const update = { imageName: settings.imageRoot + '/' + imageName } - Project.update(conditions, update, {}, callback) + Project.updateOne(conditions, update, {}, callback) }, setSpellCheckLanguage(projectId, languageCode, callback) { @@ -46,7 +46,7 @@ const ProjectOptionsHandler = { } const conditions = { _id: projectId } const update = { spellCheckLanguage: languageCode } - Project.update(conditions, update, {}, callback) + Project.updateOne(conditions, update, {}, callback) }, setBrandVariationId(projectId, brandVariationId, callback) { @@ -55,13 +55,13 @@ const ProjectOptionsHandler = { } const conditions = { _id: projectId } const update = { brandVariationId } - Project.update(conditions, update, {}, callback) + Project.updateOne(conditions, update, {}, callback) }, unsetBrandVariationId(projectId, callback) { const conditions = { _id: projectId } const update = { $unset: { brandVariationId: 1 } } - Project.update(conditions, update, {}, callback) + Project.updateOne(conditions, update, {}, callback) } } diff --git a/services/web/app/src/Features/Project/ProjectUpdateHandler.js b/services/web/app/src/Features/Project/ProjectUpdateHandler.js index facf7bfa04..f98fd62eeb 100644 --- a/services/web/app/src/Features/Project/ProjectUpdateHandler.js +++ b/services/web/app/src/Features/Project/ProjectUpdateHandler.js @@ -32,13 +32,13 @@ module.exports = { lastUpdated: lastUpdatedAt || new Date().getTime(), lastUpdatedBy } - return Project.update(conditions, update, {}, callback) + return Project.updateOne(conditions, update, {}, callback) }, markAsOpened(project_id, callback) { const conditions = { _id: project_id } const update = { lastOpened: Date.now() } - return Project.update(conditions, update, {}, function(err) { + return Project.updateOne(conditions, update, {}, function(err) { if (callback != null) { return callback() } @@ -48,7 +48,7 @@ module.exports = { markAsInactive(project_id, callback) { const conditions = { _id: project_id } const update = { active: false } - return Project.update(conditions, update, {}, function(err) { + return Project.updateOne(conditions, update, {}, function(err) { if (callback != null) { return callback() } @@ -58,7 +58,7 @@ module.exports = { markAsActive(project_id, callback) { const conditions = { _id: project_id } const update = { active: true } - return Project.update(conditions, update, {}, function(err) { + return Project.updateOne(conditions, update, {}, function(err) { if (callback != null) { return callback() } diff --git a/services/web/app/src/Features/Referal/ReferalAllocator.js b/services/web/app/src/Features/Referal/ReferalAllocator.js index aee65d9e6c..a6707a29d7 100644 --- a/services/web/app/src/Features/Referal/ReferalAllocator.js +++ b/services/web/app/src/Features/Referal/ReferalAllocator.js @@ -21,7 +21,7 @@ module.exports = { } if (referalSource === 'bonus') { - User.update( + User.updateOne( query, { $push: { diff --git a/services/web/app/src/Features/Subscription/SubscriptionGroupHandler.js b/services/web/app/src/Features/Subscription/SubscriptionGroupHandler.js index 490ce7e6c5..aa50bc1155 100644 --- a/services/web/app/src/Features/Subscription/SubscriptionGroupHandler.js +++ b/services/web/app/src/Features/Subscription/SubscriptionGroupHandler.js @@ -38,7 +38,7 @@ const SubscriptionGroupHandler = { }, replaceUserReferencesInGroups(oldId, newId, callback) { - return Subscription.update( + return Subscription.updateOne( { admin_id: oldId }, { admin_id: newId }, function(error) { @@ -118,22 +118,12 @@ var replaceInArray = function(model, property, oldValue, newValue, callback) { const setOldValue = {} setOldValue[property] = oldValue - return model.update( - query, - { $addToSet: setNewValue }, - { multi: true }, - function(error) { - if (error != null) { - return callback(error) - } - return model.update( - query, - { $pull: setOldValue }, - { multi: true }, - callback - ) + model.updateMany(query, { $addToSet: setNewValue }, function(error) { + if (error) { + return callback(error) } - ) + model.updateMany(query, { $pull: setOldValue }, callback) + }) } function __guard__(value, transform) { diff --git a/services/web/app/src/Features/Subscription/SubscriptionUpdater.js b/services/web/app/src/Features/Subscription/SubscriptionUpdater.js index adef207bfd..b2465471f7 100644 --- a/services/web/app/src/Features/Subscription/SubscriptionUpdater.js +++ b/services/web/app/src/Features/Subscription/SubscriptionUpdater.js @@ -37,7 +37,7 @@ const SubscriptionUpdater = { } else { update.$set.manager_ids = [ObjectId(adminId)] } - Subscription.update(query, update, callback) + Subscription.updateOne(query, update, callback) }, syncSubscription(recurlySubscription, adminUserId, requesterData, callback) { @@ -99,7 +99,7 @@ const SubscriptionUpdater = { const searchOps = { _id: subscriptionId } const insertOperation = { $addToSet: { member_ids: { $each: memberIds } } } - Subscription.findAndModify(searchOps, insertOperation, callback) + Subscription.updateOne(searchOps, insertOperation, callback) }, removeUserFromGroups(filter, userId, callback) { @@ -168,7 +168,7 @@ const SubscriptionUpdater = { ), cb => // 2. remove subscription - Subscription.remove({ _id: subscription._id }, cb), + Subscription.deleteOne({ _id: subscription._id }, cb), cb => // 3. refresh users features SubscriptionUpdater._refreshUsersFeatures(subscription, cb) diff --git a/services/web/app/src/Features/Subscription/TeamInvitesHandler.js b/services/web/app/src/Features/Subscription/TeamInvitesHandler.js index 39ff21417a..ad26b23d37 100644 --- a/services/web/app/src/Features/Subscription/TeamInvitesHandler.js +++ b/services/web/app/src/Features/Subscription/TeamInvitesHandler.js @@ -209,7 +209,7 @@ var removeInviteFromTeam = function(subscriptionId, email, callback) { async.series( [ - cb => Subscription.update(searchConditions, removeInvite, cb), + cb => Subscription.updateOne(searchConditions, removeInvite, cb), cb => removeLegacyInvite(subscriptionId, email, cb) ], callback @@ -217,7 +217,7 @@ var removeInviteFromTeam = function(subscriptionId, email, callback) { } var removeLegacyInvite = (subscriptionId, email, callback) => - Subscription.update( + Subscription.updateOne( { _id: new ObjectId(subscriptionId.toString()) }, diff --git a/services/web/app/src/Features/Subscription/UserFeaturesUpdater.js b/services/web/app/src/Features/Subscription/UserFeaturesUpdater.js index eca73eb792..70f3861876 100644 --- a/services/web/app/src/Features/Subscription/UserFeaturesUpdater.js +++ b/services/web/app/src/Features/Subscription/UserFeaturesUpdater.js @@ -8,7 +8,7 @@ module.exports = { const value = features[key] update[`features.${key}`] = value } - User.update(conditions, update, (err, result) => + User.updateOne(conditions, update, (err, result) => callback(err, features, (result ? result.nModified : 0) === 1) ) }, @@ -16,7 +16,7 @@ module.exports = { overrideFeatures(userId, features, callback) { const conditions = { _id: userId } const update = { features } - User.update(conditions, update, (err, result) => + User.updateOne(conditions, update, (err, result) => callback(err, (result ? result.nModified : 0) === 1) ) } diff --git a/services/web/app/src/Features/SystemMessages/SystemMessageManager.js b/services/web/app/src/Features/SystemMessages/SystemMessageManager.js index 68153a94cb..6ecbb2b638 100644 --- a/services/web/app/src/Features/SystemMessages/SystemMessageManager.js +++ b/services/web/app/src/Features/SystemMessages/SystemMessageManager.js @@ -31,7 +31,7 @@ module.exports = SystemMessageManager = { if (callback == null) { callback = function(error) {} } - return SystemMessage.remove({}, callback) + return SystemMessage.deleteMany({}, callback) }, createMessage(content, callback) { diff --git a/services/web/app/src/Features/Tags/TagsHandler.js b/services/web/app/src/Features/Tags/TagsHandler.js index e05e8f8309..cee8e9401b 100644 --- a/services/web/app/src/Features/Tags/TagsHandler.js +++ b/services/web/app/src/Features/Tags/TagsHandler.js @@ -22,7 +22,7 @@ function renameTag(userId, tagId, name, callback) { if (!callback) { callback = function() {} } - Tag.update( + Tag.updateOne( { _id: tagId, user_id: userId @@ -40,7 +40,7 @@ function deleteTag(userId, tagId, callback) { if (!callback) { callback = function() {} } - Tag.remove( + Tag.deleteOne( { _id: tagId, user_id: userId @@ -56,7 +56,7 @@ function updateTagUserIds(oldUserId, newUserId, callback) { } const searchOps = { user_id: oldUserId } const updateOperation = { $set: { user_id: newUserId } } - Tag.update(searchOps, updateOperation, { multi: true }, callback) + Tag.updateMany(searchOps, updateOperation, callback) } function removeProjectFromTag(userId, tagId, projectId, callback) { @@ -68,7 +68,7 @@ function removeProjectFromTag(userId, tagId, projectId, callback) { user_id: userId } const deleteOperation = { $pull: { project_ids: projectId } } - Tag.update(searchOps, deleteOperation, callback) + Tag.updateOne(searchOps, deleteOperation, callback) } function addProjectToTag(userId, tagId, projectId, callback) { @@ -92,13 +92,13 @@ function addProjectToTagName(userId, name, projectId, callback) { user_id: userId } const insertOperation = { $addToSet: { project_ids: projectId } } - Tag.update(searchOps, insertOperation, { upsert: true }, callback) + Tag.updateOne(searchOps, insertOperation, { upsert: true }, callback) } function removeProjectFromAllTags(userId, projectId, callback) { const searchOps = { user_id: userId } const deleteOperation = { $pull: { project_ids: projectId } } - Tag.update(searchOps, deleteOperation, { multi: true }, callback) + Tag.updateMany(searchOps, deleteOperation, callback) } const TagsHandler = { diff --git a/services/web/app/src/Features/Templates/TemplatesManager.js b/services/web/app/src/Features/Templates/TemplatesManager.js index ff4c5b3190..a102b91d9c 100644 --- a/services/web/app/src/Features/Templates/TemplatesManager.js +++ b/services/web/app/src/Features/Templates/TemplatesManager.js @@ -112,7 +112,7 @@ const TemplatesManager = { fromV1TemplateId: templateId, fromV1TemplateVersionId: templateVersionId } - return Project.update( + return Project.updateOne( { _id: project._id }, update, {}, diff --git a/services/web/app/src/Features/TokenAccess/TokenAccessHandler.js b/services/web/app/src/Features/TokenAccess/TokenAccessHandler.js index 5336a96c2f..49b68e86b5 100644 --- a/services/web/app/src/Features/TokenAccess/TokenAccessHandler.js +++ b/services/web/app/src/Features/TokenAccess/TokenAccessHandler.js @@ -164,7 +164,7 @@ const TokenAccessHandler = { addReadOnlyUserToProject(userId, projectId, callback) { userId = ObjectId(userId.toString()) projectId = ObjectId(projectId.toString()) - Project.update( + Project.updateOne( { _id: projectId }, @@ -178,7 +178,7 @@ const TokenAccessHandler = { addReadAndWriteUserToProject(userId, projectId, callback) { userId = ObjectId(userId.toString()) projectId = ObjectId(projectId.toString()) - Project.update( + Project.updateOne( { _id: projectId }, diff --git a/services/web/app/src/Features/User/SAMLIdentityManager.js b/services/web/app/src/Features/User/SAMLIdentityManager.js index d8c729cec8..215e38db02 100644 --- a/services/web/app/src/Features/User/SAMLIdentityManager.js +++ b/services/web/app/src/Features/User/SAMLIdentityManager.js @@ -258,7 +258,7 @@ async function unlinkAccounts( } } // update v2 user - await User.update(query, update).exec() + await User.updateOne(query, update).exec() // update v1 affiliations record await InstitutionsAPI.promises.removeEntitlement(userId, institutionEmail) // send email @@ -283,7 +283,7 @@ async function updateEntitlement( } } // update v2 user - await User.update(query, update).exec() + await User.updateOne(query, update).exec() // update v1 affiliations record if (hasEntitlement) { await InstitutionsAPI.promises.addEntitlement(userId, institutionEmail) diff --git a/services/web/app/src/Features/User/UserDeleter.js b/services/web/app/src/Features/User/UserDeleter.js index ce748be3af..97fc77d572 100644 --- a/services/web/app/src/Features/User/UserDeleter.js +++ b/services/web/app/src/Features/User/UserDeleter.js @@ -101,7 +101,7 @@ async function ensureCanDeleteUser(user) { } async function _createDeletedUser(user, options) { - await DeletedUser.update( + await DeletedUser.updateOne( { 'deleterData.deletedUserId': user._id }, { user: user, diff --git a/services/web/app/src/Features/User/UserRegistrationHandler.js b/services/web/app/src/Features/User/UserRegistrationHandler.js index 84578e1faa..36b69ade7a 100644 --- a/services/web/app/src/Features/User/UserRegistrationHandler.js +++ b/services/web/app/src/Features/User/UserRegistrationHandler.js @@ -64,7 +64,7 @@ const UserRegistrationHandler = { async.series( [ cb => - User.update( + User.updateOne( { _id: user._id }, { $set: { holdingAccount: false } }, cb diff --git a/services/web/app/src/Features/UserMembership/UserMembershipHandler.js b/services/web/app/src/Features/UserMembership/UserMembershipHandler.js index 0049121f3c..c612f05af8 100644 --- a/services/web/app/src/Features/UserMembership/UserMembershipHandler.js +++ b/services/web/app/src/Features/UserMembership/UserMembershipHandler.js @@ -114,7 +114,7 @@ var addUserToEntity = function(entity, attribute, user, callback) { } const fieldUpdate = {} fieldUpdate[attribute] = user._id - return entity.update({ $addToSet: fieldUpdate }, callback) + return entity.updateOne({ $addToSet: fieldUpdate }, callback) } var removeUserFromEntity = function(entity, attribute, userId, callback) { @@ -123,7 +123,7 @@ var removeUserFromEntity = function(entity, attribute, userId, callback) { } const fieldUpdate = {} fieldUpdate[attribute] = userId - return entity.update({ $pull: fieldUpdate }, callback) + return entity.updateOne({ $pull: fieldUpdate }, callback) } var buildEntityQuery = function(entityId, entityConfig, loggedInUser) { diff --git a/services/web/app/src/infrastructure/Mongoose.js b/services/web/app/src/infrastructure/Mongoose.js index e91521ef29..6f7c3e393a 100644 --- a/services/web/app/src/infrastructure/Mongoose.js +++ b/services/web/app/src/infrastructure/Mongoose.js @@ -18,7 +18,9 @@ const connectionPromise = mongoose.connect( { poolSize: POOL_SIZE, config: { autoIndex: false }, - useMongoClient: true, + useUnifiedTopology: Settings.mongo.options.useUnifiedTopology, + useNewUrlParser: true, + useFindAndModify: false, socketTimeoutMS: Settings.mongo.socketTimeoutMS, appname: 'web' } @@ -44,7 +46,7 @@ mongoose.connection.on('disconnected', () => if (process.env.MONGOOSE_DEBUG) { mongoose.set('debug', (collectionName, method, query, doc) => - logger.debug('mongoose debug', { collectionName, method, query, doc }) + logger.debug({ collectionName, method, query, doc }, 'mongoose debug') ) } @@ -55,8 +57,8 @@ mongoose.plugin(schema => { mongoose.Promise = global.Promise async function getNativeDb() { - const connection = await connectionPromise - return connection.db + const mongooseInstance = await connectionPromise + return mongooseInstance.connection.db } mongoose.getNativeDb = getNativeDb diff --git a/services/web/app/src/models/Subscription.js b/services/web/app/src/models/Subscription.js index 757f3178c7..ac5604fb92 100644 --- a/services/web/app/src/models/Subscription.js +++ b/services/web/app/src/models/Subscription.js @@ -10,7 +10,15 @@ const SubscriptionSchema = new Schema({ ref: 'User', index: { unique: true, dropDups: true } }, - manager_ids: { type: [ObjectId], ref: 'User', required: true }, + manager_ids: { + type: [ObjectId], + ref: 'User', + required: true, + validate: function(managers) { + // require at least one manager + return !!managers.length + } + }, member_ids: [{ type: ObjectId, ref: 'User' }], invited_emails: [String], teamInvites: [TeamInviteSchema], @@ -32,11 +40,6 @@ const SubscriptionSchema = new Schema({ } }) -SubscriptionSchema.statics.findAndModify = function(query, update, callback) { - const self = this - return this.update(query, update, () => self.findOne(query, callback)) -} - // Subscriptions have no v1 data to fetch SubscriptionSchema.method('fetchV1Data', function(callback) { callback(null, this) diff --git a/services/web/modules/launchpad/app/src/LaunchpadController.js b/services/web/modules/launchpad/app/src/LaunchpadController.js index e7c7f9e06f..91d4795401 100644 --- a/services/web/modules/launchpad/app/src/LaunchpadController.js +++ b/services/web/modules/launchpad/app/src/LaunchpadController.js @@ -168,7 +168,7 @@ module.exports = LaunchpadController = { return next(err) } - return User.update( + return User.updateOne( { _id: user._id }, { $set: { isAdmin: true }, @@ -225,7 +225,7 @@ module.exports = LaunchpadController = { } logger.log({ user_id: user._id }, 'making user an admin') - User.update( + User.updateOne( { _id: user._id }, { $set: { diff --git a/services/web/modules/launchpad/test/unit/src/LaunchpadControllerTests.js b/services/web/modules/launchpad/test/unit/src/LaunchpadControllerTests.js index 0a21b2b733..13fa280579 100644 --- a/services/web/modules/launchpad/test/unit/src/LaunchpadControllerTests.js +++ b/services/web/modules/launchpad/test/unit/src/LaunchpadControllerTests.js @@ -337,7 +337,7 @@ describe('LaunchpadController', function() { this.UserRegistrationHandler.registerNewUser = sinon .stub() .callsArgWith(1, null, this.user) - this.User.update = sinon.stub().callsArgWith(2, null) + this.User.updateOne = sinon.stub().callsArgWith(2, null) this.AuthenticationController.setRedirectInSession = sinon.stub() this.res.json = sinon.stub() this.next = sinon.stub() @@ -365,8 +365,8 @@ describe('LaunchpadController', function() { }) it('should have updated the user to make them an admin', function() { - this.User.update.callCount.should.equal(1) - return this.User.update + this.User.updateOne.callCount.should.equal(1) + return this.User.updateOne .calledWithMatch( { _id: this.user._id }, { @@ -401,7 +401,7 @@ describe('LaunchpadController', function() { email: this.email } this.UserRegistrationHandler.registerNewUser = sinon.stub() - this.User.update = sinon.stub() + this.User.updateOne = sinon.stub() this.AuthenticationController.setRedirectInSession = sinon.stub() this.res.sendStatus = sinon.stub() this.next = sinon.stub() @@ -440,7 +440,7 @@ describe('LaunchpadController', function() { email: this.email } this.UserRegistrationHandler.registerNewUser = sinon.stub() - this.User.update = sinon.stub() + this.User.updateOne = sinon.stub() this.AuthenticationController.setRedirectInSession = sinon.stub() this.res.sendStatus = sinon.stub() this.next = sinon.stub() @@ -479,7 +479,7 @@ describe('LaunchpadController', function() { email: this.email } this.UserRegistrationHandler.registerNewUser = sinon.stub() - this.User.update = sinon.stub() + this.User.updateOne = sinon.stub() this.AuthenticationController.setRedirectInSession = sinon.stub() this.res.sendStatus = sinon.stub() this.next = sinon.stub() @@ -514,7 +514,7 @@ describe('LaunchpadController', function() { email: this.email } this.UserRegistrationHandler.registerNewUser = sinon.stub() - this.User.update = sinon.stub() + this.User.updateOne = sinon.stub() this.AuthenticationController.setRedirectInSession = sinon.stub() this.res.sendStatus = sinon.stub() this.next = sinon.stub() @@ -555,7 +555,7 @@ describe('LaunchpadController', function() { this.UserRegistrationHandler.registerNewUser = sinon .stub() .callsArgWith(1, new Error('woops')) - this.User.update = sinon.stub() + this.User.updateOne = sinon.stub() this.AuthenticationController.setRedirectInSession = sinon.stub() this.res.json = sinon.stub() this.next = sinon.stub() @@ -583,7 +583,7 @@ describe('LaunchpadController', function() { }) it('should not call update', function() { - return this.User.update.callCount.should.equal(0) + return this.User.updateOne.callCount.should.equal(0) }) }) @@ -601,7 +601,7 @@ describe('LaunchpadController', function() { this.UserRegistrationHandler.registerNewUser = sinon .stub() .callsArgWith(1, null, this.user) - this.User.update = sinon.stub().callsArgWith(2, new Error('woops')) + this.User.updateOne = sinon.stub().callsArgWith(2, new Error('woops')) this.AuthenticationController.setRedirectInSession = sinon.stub() this.res.json = sinon.stub() this.next = sinon.stub() @@ -645,7 +645,7 @@ describe('LaunchpadController', function() { this.UserRegistrationHandler.registerNewUser = sinon .stub() .callsArgWith(1, null, this.user) - this.User.update = sinon.stub().callsArgWith(2, null) + this.User.updateOne = sinon.stub().callsArgWith(2, null) this.AuthenticationController.setRedirectInSession = sinon.stub() this.UserGetter.getUser = sinon .stub() @@ -676,7 +676,7 @@ describe('LaunchpadController', function() { }) it('should have updated the user to make them an admin', function() { - return this.User.update + return this.User.updateOne .calledWith( { _id: this.user._id }, { @@ -725,7 +725,7 @@ describe('LaunchpadController', function() { this.UserRegistrationHandler.registerNewUser = sinon .stub() .callsArgWith(1, null, this.user) - this.User.update = sinon.stub().callsArgWith(2, null) + this.User.updateOne = sinon.stub().callsArgWith(2, null) this.AuthenticationController.setRedirectInSession = sinon.stub() this.res.json = sinon.stub() this.next = sinon.stub() @@ -758,8 +758,8 @@ describe('LaunchpadController', function() { }) it('should have updated the user to make them an admin', function() { - this.User.update.callCount.should.equal(1) - return this.User.update + this.User.updateOne.callCount.should.equal(1) + return this.User.updateOne .calledWith( { _id: this.user._id }, { @@ -790,7 +790,7 @@ describe('LaunchpadController', function() { email: this.email } this.UserRegistrationHandler.registerNewUser = sinon.stub() - this.User.update = sinon.stub() + this.User.updateOne = sinon.stub() this.AuthenticationController.setRedirectInSession = sinon.stub() this.res.sendStatus = sinon.stub() this.next = sinon.stub() @@ -825,7 +825,7 @@ describe('LaunchpadController', function() { email: this.email } this.UserRegistrationHandler.registerNewUser = sinon.stub() - this.User.update = sinon.stub() + this.User.updateOne = sinon.stub() this.AuthenticationController.setRedirectInSession = sinon.stub() this.res.sendStatus = sinon.stub() this.next = sinon.stub() @@ -862,7 +862,7 @@ describe('LaunchpadController', function() { email: this.email } this.UserRegistrationHandler.registerNewUser = sinon.stub() - this.User.update = sinon.stub() + this.User.updateOne = sinon.stub() this.AuthenticationController.setRedirectInSession = sinon.stub() this.res.sendStatus = sinon.stub() this.next = sinon.stub() @@ -895,7 +895,7 @@ describe('LaunchpadController', function() { email: this.email } this.UserRegistrationHandler.registerNewUser = sinon.stub() - this.User.update = sinon.stub() + this.User.updateOne = sinon.stub() this.AuthenticationController.setRedirectInSession = sinon.stub() this.res.sendStatus = sinon.stub() this.next = sinon.stub() @@ -934,7 +934,7 @@ describe('LaunchpadController', function() { this.UserRegistrationHandler.registerNewUser = sinon .stub() .callsArgWith(1, new Error('woops')) - this.User.update = sinon.stub() + this.User.updateOne = sinon.stub() this.AuthenticationController.setRedirectInSession = sinon.stub() this.res.json = sinon.stub() this.next = sinon.stub() @@ -967,7 +967,7 @@ describe('LaunchpadController', function() { }) it('should not call update', function() { - return this.User.update.callCount.should.equal(0) + return this.User.updateOne.callCount.should.equal(0) }) }) @@ -983,7 +983,7 @@ describe('LaunchpadController', function() { this.UserRegistrationHandler.registerNewUser = sinon .stub() .callsArgWith(1, null, this.user) - this.User.update = sinon.stub().callsArgWith(2, new Error('woops')) + this.User.updateOne = sinon.stub().callsArgWith(2, new Error('woops')) this.AuthenticationController.setRedirectInSession = sinon.stub() this.res.json = sinon.stub() this.next = sinon.stub() diff --git a/services/web/package-lock.json b/services/web/package-lock.json index 2c59ec4154..a42b4454b7 100644 --- a/services/web/package-lock.json +++ b/services/web/package-lock.json @@ -12188,9 +12188,9 @@ } }, "bson": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/bson/-/bson-1.0.4.tgz", - "integrity": "sha512-0Ib4Zy4vANsueMULLnoYfaVNK0xOFZ+ZQ3IpQbZRMjf1fXh5ASVtjnETbyAgkKet0PYnZibw6drFX1D20sg9lw==" + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/bson/-/bson-1.1.5.tgz", + "integrity": "sha512-kDuEzldR21lHciPQAIulLs1LZlCXdLziXI6Mb/TDkwXhb//UORJNPXgcRs2CuO4H0DcMkpfT3/ySsP3unoZjBg==" }, "buffer": { "version": "4.9.1", @@ -12249,11 +12249,6 @@ "integrity": "sha512-4/rOEg86jivtPTeOUUT61jJO1Ya1TrR/OkqCSZDyq84WJh3LuuiphBYJN+fm5xufIk4XAFcEwte/8WzC8If/1g==", "dev": true }, - "buffer-shims": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/buffer-shims/-/buffer-shims-1.0.0.tgz", - "integrity": "sha512-Zy8ZXMyxIT6RMTeY7OP/bDndfj6bwCan7SS98CEndS6deHwWPpseeHlwarNcBim+etXnF9HBc1non5JgDaJU1g==" - }, "buffer-xor": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/buffer-xor/-/buffer-xor-1.0.3.tgz", @@ -14569,7 +14564,7 @@ "d64": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/d64/-/d64-1.0.0.tgz", - "integrity": "sha1-QAKofoUMv8n52XBrYPymE6MzbpA=" + "integrity": "sha512-5eNy3WZziVYnrogqgXhcdEmqcDB2IHurTqLcrgssJsfkMVCUoUaZpK6cJjxxvLV2dUm5SuJMNcYfVGoin9UIRw==" }, "damerau-levenshtein": { "version": "1.0.6", @@ -19618,11 +19613,6 @@ "parse-passwd": "^1.0.0" } }, - "hooks-fixed": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/hooks-fixed/-/hooks-fixed-2.0.2.tgz", - "integrity": "sha512-YurCM4gQSetcrhwEtpQHhQ4M7Zo7poNGqY4kQGeBS6eZtOcT3tnNs01ThFa0jYBByAiYt1MjMjP/YApG0EnAvQ==" - }, "hosted-git-info": { "version": "2.8.8", "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.8.tgz", @@ -20842,7 +20832,7 @@ "is-subset": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/is-subset/-/is-subset-0.1.1.tgz", - "integrity": "sha1-ilkRfZMt4d4A8kX83TnOQ/HpOaY=", + "integrity": "sha512-6Ybun0IkarhmEqxXCNw/C0bna6Zb/TkfUX9UbwJtK6ObwAVCxmAP308WWTHviM/zAqXk05cdhYsUsZeGQh99iw==", "dev": true }, "is-svg": { @@ -21750,9 +21740,9 @@ } }, "kareem": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/kareem/-/kareem-1.5.0.tgz", - "integrity": "sha512-DFYc05y1WSs6Ar++MHYRYu7/5r5356WDaKk8tQ8m6rlXD3VLpyG6Np81U78/wWJ4b5hjFXS7HkJNYrs85VypQA==" + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/kareem/-/kareem-2.3.1.tgz", + "integrity": "sha512-l3hLhffs9zqoDe8zjmb/mAN4B8VT3L56EUvKNqLFVs9YlFA+zx7ke1DO8STAdDyYNkeSo1nKmjuvQeI12So8Xw==" }, "karma": { "version": "5.0.4", @@ -22245,7 +22235,7 @@ "keycode": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/keycode/-/keycode-2.2.0.tgz", - "integrity": "sha1-PQr1bce4uOXLqNCpfxByBO7CKwQ=" + "integrity": "sha512-ps3I9jAdNtRpJrbBvQjpzyFbss/skHqzS+eu4RxKLaEAtFqkjZaB6TZMSivPbLxf4K7VI4SjR0P5mRCX5+Q25A==" }, "killable": { "version": "1.0.1", @@ -22732,12 +22722,12 @@ "lodash.at": { "version": "4.6.0", "resolved": "https://registry.npmjs.org/lodash.at/-/lodash.at-4.6.0.tgz", - "integrity": "sha1-k83OZk8KGZTqM9181A4jr9EbD/g=" + "integrity": "sha512-GOTh0SEp+Yosnlpjic+8cl2WM9MykorogkGA9xyIFkkObQ3H3kNZqZ+ohuq4K3FrSVo7hMcZBMataJemrxC3BA==" }, "lodash.camelcase": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz", - "integrity": "sha1-soqmKIorn8ZRA1x3EfZathkDMaY=" + "integrity": "sha512-TwuEnCnxbc3rAvhf/LbG7tJUDzhqXyFnv3dtzLOPgCG/hODL7WFnsbwktkD7yUV0RrreP/l1PALq/YSg6VvjlA==" }, "lodash.defaults": { "version": "4.2.0", @@ -22757,7 +22747,7 @@ "lodash.frompairs": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/lodash.frompairs/-/lodash.frompairs-4.0.1.tgz", - "integrity": "sha1-vE5SB/onV8E25XNhTpZkUGsrG9I=" + "integrity": "sha512-dvqe2I+cO5MzXCMhUnfYFa9MD+/760yx2aTAN1lqEcEkf896TxgrX373igVdqSJj6tQd0jnSLE1UMuKufqqxFw==" }, "lodash.get": { "version": "4.4.2", @@ -22767,7 +22757,7 @@ "lodash.has": { "version": "4.5.2", "resolved": "https://registry.npmjs.org/lodash.has/-/lodash.has-4.5.2.tgz", - "integrity": "sha1-0Z9NwQlQWMzL4rDN9O4P5Ko3yGI=" + "integrity": "sha512-rnYUdIo6xRCJnQmbVFEwcxF144erlD+M3YcJUVesflU9paQaE8p+fJDcIQrlMYbxoANFL+AB9hZrzSBBk5PL+g==" }, "lodash.includes": { "version": "4.3.0", @@ -22782,7 +22772,7 @@ "lodash.isequal": { "version": "4.5.0", "resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz", - "integrity": "sha1-QVxEePK8wwEgwizhDtMib30+GOA=", + "integrity": "sha512-pDo3lu8Jhfjqls6GkMgpahsF9kCyayhgykjyLMNFTKWrpVdAQtYyB4muAMWozBB4ig/dtWAmsMxLEI8wuz+DYQ==", "dev": true }, "lodash.isinteger": { @@ -22835,7 +22825,7 @@ "lodash.sortby": { "version": "4.7.0", "resolved": "https://registry.npmjs.org/lodash.sortby/-/lodash.sortby-4.7.0.tgz", - "integrity": "sha1-7dFMgk4sycHgsKG0K7UhBRakJDg=", + "integrity": "sha512-HDWXG8isMntAyRF5vZ7xKuEvOhT4AhlRt/3czTSjvGUxjYCBVRQY48ViDHyfYz9VIoBkW4TMGQNapx+l3RUwdA==", "dev": true }, "lodash.unescape": { @@ -23859,7 +23849,7 @@ }, "mkdirp": { "version": "0.5.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", "integrity": "sha512-SknJC52obPfGQPnjIkXbmA6+5H15E+fR+E4iR2oQ3zzCLbd7/ONua69R/Gw7AgkTLsRG+r5fzksYwWe1AgTyWA==", "requires": { "minimist": "0.0.8" @@ -23868,7 +23858,7 @@ "minimist": { "version": "0.0.8", "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", - "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=" + "integrity": "sha512-miQKw5Hv4NS1Psg2517mV4e4dYNaO3++hjAvLOAzKqZ61rH8NS1SK+vbfBWZ5PY/Me/bEWhUwqMghEW5Fb9T7Q==" } } }, @@ -24115,86 +24105,40 @@ } }, "mongoose": { - "version": "4.13.19", - "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-4.13.19.tgz", - "integrity": "sha512-O41XmkbAZtLK6Uw4cqjI30s0sP8oZeG+aWweOIyE2VYHMQiYDWhVkBMtsv+Kv8chDizaBhO5oErTHexLQKzU+w==", + "version": "5.10.9", + "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-5.10.9.tgz", + "integrity": "sha512-7dkr1d6Uyk87hELzoc6B7Zo7kkPTx8rKummk51Y0je2V2Ttsw0KFPwTp1G8JIbBta7Wpw8j15PJi0d33Ode2nw==", "requires": { - "async": "2.6.0", - "bson": "~1.0.4", - "hooks-fixed": "2.0.2", - "kareem": "1.5.0", - "lodash.get": "4.4.2", - "mongodb": "2.2.34", - "mpath": "0.5.1", - "mpromise": "0.5.5", - "mquery": "2.3.3", - "ms": "2.0.0", - "muri": "1.3.0", - "regexp-clone": "0.0.1", + "bson": "^1.1.4", + "kareem": "2.3.1", + "mongodb": "3.6.2", + "mongoose-legacy-pluralize": "1.0.2", + "mpath": "0.7.0", + "mquery": "3.2.2", + "ms": "2.1.2", + "regexp-clone": "1.0.0", + "safe-buffer": "5.2.1", + "sift": "7.0.1", "sliced": "1.0.1" }, "dependencies": { - "async": { - "version": "2.6.0", - "resolved": "https://registry.npmjs.org/async/-/async-2.6.0.tgz", - "integrity": "sha512-xAfGg1/NTLBBKlHFmnd7PlmUW9KhVQIUuSrYem9xzFUZy13ScvtyGGejaae9iAVRiRq9+Cx7DPFaAAhCpyxyPw==", - "requires": { - "lodash": "^4.14.0" - } + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, - "es6-promise": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-3.2.1.tgz", - "integrity": "sha1-7FYjOGgDKQkgcXDDlEjiREndH8Q=" - }, - "isarray": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", - "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" - }, - "mongodb": { - "version": "2.2.34", - "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-2.2.34.tgz", - "integrity": "sha1-o09Zu+thdUrsQy3nLD/iFSakTBo=", - "requires": { - "es6-promise": "3.2.1", - "mongodb-core": "2.1.18", - "readable-stream": "2.2.7" - } - }, - "mongodb-core": { - "version": "2.1.18", - "resolved": "https://registry.npmjs.org/mongodb-core/-/mongodb-core-2.1.18.tgz", - "integrity": "sha1-TEYTm986HwMt7ZHbSfOO7AFlkFA=", - "requires": { - "bson": "~1.0.4", - "require_optional": "~1.0.0" - } - }, - "readable-stream": { - "version": "2.2.7", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.2.7.tgz", - "integrity": "sha1-BwV6y+JGeyIELTb5jFrVBwVOlbE=", - "requires": { - "buffer-shims": "~1.0.0", - "core-util-is": "~1.0.0", - "inherits": "~2.0.1", - "isarray": "~1.0.0", - "process-nextick-args": "~1.0.6", - "string_decoder": "~1.0.0", - "util-deprecate": "~1.0.1" - } - }, - "string_decoder": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", - "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==", - "requires": { - "safe-buffer": "~5.1.0" - } + "safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==" } } }, + "mongoose-legacy-pluralize": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/mongoose-legacy-pluralize/-/mongoose-legacy-pluralize-1.0.2.tgz", + "integrity": "sha512-Yo/7qQU4/EyIS8YDFSeenIvXxZN+ld7YdV9LqFVQJzTLye8unujAWPZ4NWKfFA+RNjh+wvTWKY9Z3E5XM6ZZiQ==" + }, "morgan": { "version": "1.10.0", "resolved": "https://registry.npmjs.org/morgan/-/morgan-1.10.0.tgz", @@ -24248,43 +24192,39 @@ } }, "mpath": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/mpath/-/mpath-0.5.1.tgz", - "integrity": "sha512-H8OVQ+QEz82sch4wbODFOz+3YQ61FYz/z3eJ5pIdbMEaUzDqA268Wd+Vt4Paw9TJfvDgVKaayC0gBzMIw2jhsg==" - }, - "mpromise": { - "version": "0.5.5", - "resolved": "https://registry.npmjs.org/mpromise/-/mpromise-0.5.5.tgz", - "integrity": "sha512-b/IJDqWlRXIW3ZouxIkUYLZFrr4qK/oUEgfVAywuvm77nTdDmY6y57lHxA8kfLnOSM+SbAUN/VvU1RxsGBLkQw==" + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/mpath/-/mpath-0.7.0.tgz", + "integrity": "sha512-Aiq04hILxhz1L+f7sjGyn7IxYzWm1zLNNXcfhDtx04kZ2Gk7uvFdgZ8ts1cWa/6d0TQmag2yR8zSGZUmp0tFNg==" }, "mquery": { - "version": "2.3.3", - "resolved": "https://registry.npmjs.org/mquery/-/mquery-2.3.3.tgz", - "integrity": "sha512-NC8L14kn+qxJbbJ1gbcEMDxF0sC3sv+1cbRReXXwVvowcwY1y9KoVZFq0ebwARibsadu8lx8nWGvm3V0Pf0ZWQ==", + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/mquery/-/mquery-3.2.2.tgz", + "integrity": "sha512-XB52992COp0KP230I3qloVUbkLUxJIu328HBP2t2EsxSFtf4W1HPSOBWOXf1bqxK4Xbb66lfMJ+Bpfd9/yZE1Q==", "requires": { - "bluebird": "3.5.0", - "debug": "2.6.9", - "regexp-clone": "0.0.1", - "sliced": "0.0.5" + "bluebird": "3.5.1", + "debug": "3.1.0", + "regexp-clone": "^1.0.0", + "safe-buffer": "5.1.2", + "sliced": "1.0.1" }, "dependencies": { "bluebird": { - "version": "3.5.0", - "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.0.tgz", - "integrity": "sha512-3LE8m8bqjGdoxfvf71yhFNrUcwy3NLy00SAo+b6MfJ8l+Bc2DzQ7mUHwX6pjK2AxfgV+YfsjCeVW3T5HLQTBsQ==" + "version": "3.5.1", + "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.1.tgz", + "integrity": "sha512-MKiLiV+I1AA596t9w1sQJ8jkiSr5+ZKi0WKrYGUn6d1Fx+Ij4tIj+m2WMQSGczs5jZVxV339chE8iwk6F64wjA==" }, "debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", + "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", "requires": { "ms": "2.0.0" } }, - "sliced": { - "version": "0.0.5", - "resolved": "https://registry.npmjs.org/sliced/-/sliced-0.0.5.tgz", - "integrity": "sha512-9bYT917D6H3+q8GlQBJmLVz3bc4OeVGfZ2BB12wvLnluTGfG6/8UdOUbKJDW1EEx9SZMDbjnatkau5/XcUeyOw==" + "safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" } } }, @@ -24331,11 +24271,6 @@ "integrity": "sha512-cnAsSVxIDsYt0v7HmC0hWZFwwXSh+E6PgCrREDuN/EsjgLwA5XRmlMHhSiDPrt6HxY1gTivEa/Zh7GtODoLevQ==", "dev": true }, - "muri": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/muri/-/muri-1.3.0.tgz", - "integrity": "sha512-FiaFwKl864onHFFUV/a2szAl7X0fxVlSKNdhTf+BM8i8goEgYut8u5P9MqQqIYwvaMxjzVESsoEm/2kfkFH1rg==" - }, "mute-stream": { "version": "0.0.7", "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.7.tgz", @@ -24345,7 +24280,7 @@ "mv": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/mv/-/mv-2.1.1.tgz", - "integrity": "sha1-rmzg1vbV4KT32JN5jQPB6pVZtqI=", + "integrity": "sha512-at/ZndSy3xEGJ8i0ygALh8ru9qy7gWW1cmkaqBN29JmMlIvM//MEO9y1sk/avxuwnPcfhkejkLsuPxH81BrkSg==", "optional": true, "requires": { "mkdirp": "~0.5.1", @@ -24356,7 +24291,7 @@ "glob": { "version": "6.0.4", "resolved": "https://registry.npmjs.org/glob/-/glob-6.0.4.tgz", - "integrity": "sha1-DwiGD2oVUSey+t1PnOJLGqtuTSI=", + "integrity": "sha512-MKZeRNyYZAVVVG1oZeLaWie1uweH40m9AZwIwxyPbTSX4hHrVYSzLg0Ro5Z5R7XKkIX+Cc6oD1rqeDJnwsB8/A==", "optional": true, "requires": { "inflight": "^1.0.4", @@ -24369,7 +24304,7 @@ "rimraf": { "version": "2.4.5", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.4.5.tgz", - "integrity": "sha1-7nEM5dk6j9uFb7Xqj/Di11k0sto=", + "integrity": "sha512-J5xnxTyqaiw06JjMftq7L9ouA448dw/E7dKghkP9WpKNuwmARNNg+Gk8/u5ryb9N/Yo2+z3MCwuqFK/+qPOPfQ==", "optional": true, "requires": { "glob": "^6.0.1" @@ -24428,7 +24363,7 @@ "ncp": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ncp/-/ncp-2.0.0.tgz", - "integrity": "sha1-GVoh1sRuNh0vsSgbo4uR6d9727M=", + "integrity": "sha512-zIdGUrPRFTUELUvr3Gmc7KZ2Sw/h1PiVM0Af/oHB6zgnV1ikqSfRk+TOufi79aHYCW3NiOXmr1BP5nWbzojLaA==", "optional": true }, "needle": { @@ -26152,7 +26087,7 @@ "os-homedir": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz", - "integrity": "sha512-B5JU3cabzk8c67mRRd3ECmROafjYMXbuzlwtqdM8IbS8ktlTix8aFGb2bAGKrSRIlnfKwovGUUr72JUPyOb6kQ==" + "integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M=" }, "os-locale": { "version": "2.1.0", @@ -27855,11 +27790,6 @@ "resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz", "integrity": "sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==" }, - "process-nextick-args": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz", - "integrity": "sha512-yN0WQmuCX63LP/TMvAg31nvT6m4vDqJEiiv2CAZqWOGNWutc9DfDk1NPYYmKUFmaVM2UwDowH4u5AHWYP/jxKw==" - }, "progress": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.0.tgz", @@ -29772,7 +29702,7 @@ "react-prop-types": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/react-prop-types/-/react-prop-types-0.4.0.tgz", - "integrity": "sha1-+ZsL+0AGkpya8gUefBQUpcdbk9A=", + "integrity": "sha512-IyjsJhDX9JkoOV9wlmLaS7z+oxYoIWhfzDcFy7inwoAKTu+VcVNrVpPmLeioJ94y6GeDRsnwarG1py5qofFQMg==", "requires": { "warning": "^3.0.0" } @@ -30428,9 +30358,9 @@ } }, "regexp-clone": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/regexp-clone/-/regexp-clone-0.0.1.tgz", - "integrity": "sha512-tfYXF0HXEYh3AtgdjqNLQ8+tmZSAKIS7KtOjmB1laJgfbsi+Lf2RVNwLZVOE3U27yBXikzQuIXglLlakvb8Thw==" + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/regexp-clone/-/regexp-clone-1.0.0.tgz", + "integrity": "sha512-TuAasHQNamyyJ2hb97IuBEif4qBHGjPHBS64sZwytpLEqtBQ1gPJTnOaQ6qmpET16cK14kkjbazl6+p0RRv0yw==" }, "regexp.prototype.flags": { "version": "1.3.0", @@ -32398,6 +32328,11 @@ } } }, + "sift": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/sift/-/sift-7.0.1.tgz", + "integrity": "sha512-oqD7PMJ+uO6jV9EQCl0LrRw1OwsiPsiFQR5AR30heR+4Dl7jBBbDLnNvWiak20tzZlSE1H7RB30SX/1j/YYT7g==" + }, "signal-exit": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", @@ -33902,7 +33837,7 @@ "stubs": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/stubs/-/stubs-3.0.0.tgz", - "integrity": "sha1-6NK6H6nJBXAwPAMLaQD31fiavls=" + "integrity": "sha512-PdHt7hHUJKxvTCgbKX9C1V/ftOcjJQgz8BZwNfV5c4B6dcGqlpelTbJ999jBGZ2jYiPAwcX5dP6oBwVlBlUbxw==" }, "style-loader": { "version": "1.2.1", @@ -34882,7 +34817,7 @@ "to-no-case": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/to-no-case/-/to-no-case-1.0.2.tgz", - "integrity": "sha1-xyKQcWTvaxeBMsjmmTAhLRtKoWo=" + "integrity": "sha512-Z3g735FxuZY8rodxV4gH7LxClE4H0hTIyHNIHdk+vpQxjLm0cwnKXq/OFVZ76SOQmto7txVcwSCwkU5kqp+FKg==" }, "to-object-path": { "version": "0.3.0", @@ -34967,7 +34902,7 @@ "to-snake-case": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/to-snake-case/-/to-snake-case-1.0.0.tgz", - "integrity": "sha1-znRpE4l5RgGah+Yu366upMYIq4w=", + "integrity": "sha512-joRpzBAk1Bhi2eGEYBjukEWHOe/IvclOkiJl3DtA91jV6NwQ3MwXA4FHYeqk8BNp/D8bmi9tcNbRu/SozP0jbQ==", "requires": { "to-space-case": "^1.0.0" } @@ -34975,7 +34910,7 @@ "to-space-case": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/to-space-case/-/to-space-case-1.0.0.tgz", - "integrity": "sha1-sFLar7Gysp3HcM6gFj5ewOvJ/Bc=", + "integrity": "sha512-rLdvwXZ39VOn1IxGL3V6ZstoTbwLRckQmn/U8ZDLuWwIXNpuZDhQ3AiRUlhTbOXFVE9C+dR51wM0CBDhk31VcA==", "requires": { "to-no-case": "^1.0.0" } @@ -36190,7 +36125,7 @@ "warning": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/warning/-/warning-3.0.0.tgz", - "integrity": "sha1-MuU3fLVy3kqwR1O9+IIcAe1gW3w=", + "integrity": "sha512-jMBt6pUrKn5I+OGgtQ4YZLdhIeJmObddh6CsibPxyQ5yPZm1XExSyzC1LCNX7BzhxWgiHmizBWJTHJIjMjTQYQ==", "requires": { "loose-envify": "^1.0.0" } diff --git a/services/web/package.json b/services/web/package.json index 1e08f9cdfa..49164dc1c7 100644 --- a/services/web/package.json +++ b/services/web/package.json @@ -97,7 +97,7 @@ "mocha": "^6.2.2", "moment": "^2.24.0", "mongodb": "^3.6.0", - "mongoose": "^4.13.19", + "mongoose": "^5.10.7", "multer": "git+https://github.com/overleaf/multer.git", "nocache": "^2.1.0", "nodemailer": "2.1.0", diff --git a/services/web/test/acceptance/src/FeatureUpdaterTests.js b/services/web/test/acceptance/src/FeatureUpdaterTests.js index 105d59bf48..58588c3253 100644 --- a/services/web/test/acceptance/src/FeatureUpdaterTests.js +++ b/services/web/test/acceptance/src/FeatureUpdaterTests.js @@ -121,7 +121,7 @@ describe('FeatureUpdater.refreshFeatures', function() { describe('when the user has bonus features', function() { beforeEach(function() { - return User.update( + return User.updateOne( { _id: this.user._id }, @@ -193,7 +193,7 @@ describe('FeatureUpdater.refreshFeatures', function() { describe('when the user is due bonus features and has extra features that no longer apply', function() { beforeEach(function() { - return User.update( + return User.updateOne( { _id: this.user._id }, @@ -224,7 +224,7 @@ describe('FeatureUpdater.refreshFeatures', function() { describe('when the user has a v1 plan', function() { beforeEach(function() { MockV1Api.setUser(42, { plan_name: 'free' }) - return User.update( + return User.updateOne( { _id: this.user._id }, @@ -251,7 +251,7 @@ describe('FeatureUpdater.refreshFeatures', function() { describe('when the user has a v1 plan and bonus features', function() { beforeEach(function() { MockV1Api.setUser(42, { plan_name: 'free' }) - return User.update( + return User.updateOne( { _id: this.user._id }, @@ -327,7 +327,7 @@ describe('FeatureUpdater.refreshFeatures', function() { describe('when the notifyV1Flag is passed', function() { beforeEach(function() { - return User.update( + return User.updateOne( { _id: this.user._id }, @@ -344,7 +344,7 @@ describe('FeatureUpdater.refreshFeatures', function() { beforeEach(function() { const futureDate = new Date() futureDate.setDate(futureDate.getDate() + 1) - return User.update( + return User.updateOne( { _id: this.user._id }, diff --git a/services/web/test/acceptance/src/ModelTests.js b/services/web/test/acceptance/src/ModelTests.js index f625182da7..25ca8a4790 100644 --- a/services/web/test/acceptance/src/ModelTests.js +++ b/services/web/test/acceptance/src/ModelTests.js @@ -18,7 +18,7 @@ describe('mongoose', function() { it('does not allow the creation of multiple users with the same email', async function() { await expect(User.create({ email: email })).to.be.fulfilled await expect(User.create({ email: email })).to.be.rejected - await expect(User.count({ email: email })).to.eventually.equal(1) + await expect(User.countDocuments({ email: email })).to.eventually.equal(1) }) }) diff --git a/services/web/test/acceptance/src/ProjectCRUDTests.js b/services/web/test/acceptance/src/ProjectCRUDTests.js index 69845ccd98..38f4efc093 100644 --- a/services/web/test/acceptance/src/ProjectCRUDTests.js +++ b/services/web/test/acceptance/src/ProjectCRUDTests.js @@ -53,7 +53,7 @@ describe('Project CRUD', function() { describe('with an array archived state', function() { it('should mark the project as not archived for the user', async function() { - await Project.update( + await Project.updateOne( { _id: this.projectId }, { $set: { archived: [ObjectId(this.user._id)] } } ).exec() @@ -72,7 +72,7 @@ describe('Project CRUD', function() { describe('with a legacy boolean state', function() { it('should mark the project as not archived for the user', async function() { - await Project.update( + await Project.updateOne( { _id: this.projectId }, { $set: { archived: true } } ).exec() @@ -92,7 +92,7 @@ describe('Project CRUD', function() { describe('when untrashing a project', function() { it('should mark the project as untrashed for the user', async function() { - await Project.update( + await Project.updateOne( { _id: this.projectId }, { trashed: [ObjectId(this.user._id)] } ).exec() @@ -107,7 +107,7 @@ describe('Project CRUD', function() { }) it('does nothing if the user has already untrashed the project', async function() { - await Project.update( + await Project.updateOne( { _id: this.projectId }, { trashed: [ObjectId(this.user._id)] } ).exec() diff --git a/services/web/test/acceptance/src/ProjectStructureTests.js b/services/web/test/acceptance/src/ProjectStructureTests.js index 10d5a63c1b..fff37acc9a 100644 --- a/services/web/test/acceptance/src/ProjectStructureTests.js +++ b/services/web/test/acceptance/src/ProjectStructureTests.js @@ -1107,7 +1107,7 @@ describe('ProjectStructureChanges', function() { describe('when rootDoc_id matches doc being deleted', function() { beforeEach(function(done) { - Project.update( + Project.updateOne( { _id: this.exampleProjectId }, { $set: { rootDoc_id: this.exampleDocId } }, done @@ -1139,7 +1139,7 @@ describe('ProjectStructureChanges', function() { describe('when rootDoc_id does not match doc being deleted', function() { beforeEach(function(done) { this.exampleRootDocId = new ObjectId() - Project.update( + Project.updateOne( { _id: this.exampleProjectId }, { $set: { rootDoc_id: this.exampleRootDocId } }, done diff --git a/services/web/test/acceptance/src/SubscriptionDashboardTests.js b/services/web/test/acceptance/src/SubscriptionDashboardTests.js index d019cb17bb..54706a22cd 100644 --- a/services/web/test/acceptance/src/SubscriptionDashboardTests.js +++ b/services/web/test/acceptance/src/SubscriptionDashboardTests.js @@ -103,7 +103,7 @@ describe('Subscriptions', function() { MockRecurlyApi.mockSubscriptions = [] MockRecurlyApi.coupons = {} MockRecurlyApi.redemptions = {} - Subscription.remove( + Subscription.deleteOne( { admin_id: this.user._id }, @@ -207,7 +207,7 @@ describe('Subscriptions', function() { }) after(function(done) { - Subscription.remove( + Subscription.deleteOne( { admin_id: this.user._id }, @@ -277,7 +277,7 @@ describe('Subscriptions', function() { }) after(function(done) { - Subscription.remove( + Subscription.deleteOne( { admin_id: this.owner1._id }, @@ -285,7 +285,7 @@ describe('Subscriptions', function() { if (error != null) { return done(error) } - return Subscription.remove( + return Subscription.deleteOne( { admin_id: this.owner2._id }, @@ -349,7 +349,7 @@ describe('Subscriptions', function() { }) after(function(done) { - Subscription.remove( + Subscription.deleteOne( { admin_id: this.owner1._id }, @@ -406,7 +406,7 @@ describe('Subscriptions', function() { }) after(function(done) { - Institution.remove( + Institution.deleteOne( { v1Id: this.v1Id }, diff --git a/services/web/test/acceptance/src/helpers/User.js b/services/web/test/acceptance/src/helpers/User.js index 8e5d42df48..e2d6c427b8 100644 --- a/services/web/test/acceptance/src/helpers/User.js +++ b/services/web/test/acceptance/src/helpers/User.js @@ -135,16 +135,20 @@ class User { const value = features[key] update[`features.${key}`] = value } - UserModel.update({ _id: this.id }, update, callback) + UserModel.updateOne({ _id: this.id }, update, callback) } setFeaturesOverride(featuresOverride, callback) { const update = { $push: { featuresOverrides: featuresOverride } } - UserModel.update({ _id: this.id }, update, callback) + UserModel.updateOne({ _id: this.id }, update, callback) } setOverleafId(overleafId, callback) { - UserModel.update({ _id: this.id }, { 'overleaf.id': overleafId }, callback) + UserModel.updateOne( + { _id: this.id }, + { 'overleaf.id': overleafId }, + callback + ) } logout(callback) { @@ -622,7 +626,7 @@ class User { } setV1Id(v1Id, callback) { - UserModel.update( + UserModel.updateOne( { _id: this._id }, diff --git a/services/web/test/unit/src/Collaborators/CollaboratorsHandlerTests.js b/services/web/test/unit/src/Collaborators/CollaboratorsHandlerTests.js index 96665b745b..5f3161f25e 100644 --- a/services/web/test/unit/src/Collaborators/CollaboratorsHandlerTests.js +++ b/services/web/test/unit/src/Collaborators/CollaboratorsHandlerTests.js @@ -99,7 +99,7 @@ describe('CollaboratorsHandler', function() { }) it('should remove the user from mongo', async function() { - this.ProjectMock.expects('update') + this.ProjectMock.expects('updateOne') .withArgs( { _id: this.project._id @@ -138,7 +138,7 @@ describe('CollaboratorsHandler', function() { }) it('should remove the user from mongo', async function() { - this.ProjectMock.expects('update') + this.ProjectMock.expects('updateOne') .withArgs( { _id: this.oldArchivedProject._id @@ -175,7 +175,7 @@ describe('CollaboratorsHandler', function() { }) it('should remove the user from mongo', async function() { - this.ProjectMock.expects('update') + this.ProjectMock.expects('updateOne') .withArgs( { _id: this.archivedProject._id @@ -203,7 +203,7 @@ describe('CollaboratorsHandler', function() { describe('addUserIdToProject', function() { describe('as readOnly', function() { beforeEach(async function() { - this.ProjectMock.expects('update') + this.ProjectMock.expects('updateOne') .withArgs( { _id: this.project._id @@ -238,7 +238,7 @@ describe('CollaboratorsHandler', function() { describe('as readAndWrite', function() { beforeEach(async function() { - this.ProjectMock.expects('update') + this.ProjectMock.expects('updateOne') .withArgs( { _id: this.project._id @@ -289,7 +289,7 @@ describe('CollaboratorsHandler', function() { this.userId, 'readAndWrite' ) - // Project.update() should not be called. If it is, it will fail because + // Project.updateOne() should not be called. If it is, it will fail because // the mock is not set up. }) }) @@ -348,7 +348,7 @@ describe('CollaboratorsHandler', function() { .chain('exec') .resolves({ _id: projectId }) - this.ProjectMock.expects('update') + this.ProjectMock.expects('updateOne') .withArgs( { _id: projectId @@ -394,51 +394,46 @@ describe('CollaboratorsHandler', function() { }) .chain('exec') .resolves(this.projects) - this.ProjectMock.expects('update') + this.ProjectMock.expects('updateMany') .withArgs( { owner_ref: this.fromUserId }, - { $set: { owner_ref: this.toUserId } }, - { multi: true } + { $set: { owner_ref: this.toUserId } } ) .chain('exec') .resolves() - this.ProjectMock.expects('update') + this.ProjectMock.expects('updateMany') .withArgs( { collaberator_refs: this.fromUserId }, { $addToSet: { collaberator_refs: this.toUserId } - }, - { multi: true } + } ) .chain('exec') .resolves() - this.ProjectMock.expects('update') + this.ProjectMock.expects('updateMany') .withArgs( { collaberator_refs: this.fromUserId }, { $pull: { collaberator_refs: this.fromUserId } - }, - { multi: true } + } ) .chain('exec') .resolves() - this.ProjectMock.expects('update') + this.ProjectMock.expects('updateMany') .withArgs( { readOnly_refs: this.fromUserId }, { $addToSet: { readOnly_refs: this.toUserId } - }, - { multi: true } + } ) .chain('exec') .resolves() - this.ProjectMock.expects('update') + this.ProjectMock.expects('updateMany') .withArgs( { readOnly_refs: this.fromUserId }, { $pull: { readOnly_refs: this.fromUserId } - }, - { multi: true } + } ) .chain('exec') .resolves() diff --git a/services/web/test/unit/src/Collaborators/CollaboratorsInviteHandlerTests.js b/services/web/test/unit/src/Collaborators/CollaboratorsInviteHandlerTests.js index b7a6e3bf92..a9feeaa883 100644 --- a/services/web/test/unit/src/Collaborators/CollaboratorsInviteHandlerTests.js +++ b/services/web/test/unit/src/Collaborators/CollaboratorsInviteHandlerTests.js @@ -34,8 +34,8 @@ describe('CollaboratorsInviteHandler', function() { this.prototype.save = sinon.stub() this.findOne = sinon.stub() this.find = sinon.stub() - this.remove = sinon.stub() - this.count = sinon.stub() + this.deleteOne = sinon.stub() + this.countDocuments = sinon.stub() } constructor(options) { if (options == null) { @@ -105,7 +105,7 @@ describe('CollaboratorsInviteHandler', function() { describe('getInviteCount', function() { beforeEach(function() { - this.ProjectInvite.count.callsArgWith(1, null, 2) + this.ProjectInvite.countDocuments.callsArgWith(1, null, 2) return (this.call = callback => { return this.CollaboratorsInviteHandler.getInviteCount( this.projectId, @@ -129,9 +129,12 @@ describe('CollaboratorsInviteHandler', function() { }) }) - describe('when model.count produces an error', function() { + describe('when model.countDocuments produces an error', function() { beforeEach(function() { - return this.ProjectInvite.count.callsArgWith(1, new Error('woops')) + return this.ProjectInvite.countDocuments.callsArgWith( + 1, + new Error('woops') + ) }) it('should produce an error', function(done) { @@ -391,7 +394,7 @@ describe('CollaboratorsInviteHandler', function() { describe('revokeInvite', function() { beforeEach(function() { - this.ProjectInvite.remove.callsArgWith(1, null) + this.ProjectInvite.deleteOne.callsArgWith(1, null) this.CollaboratorsInviteHandler._tryCancelInviteNotification = sinon .stub() .callsArgWith(1, null) @@ -415,10 +418,10 @@ describe('CollaboratorsInviteHandler', function() { }) }) - it('should call ProjectInvite.remove', function(done) { + it('should call ProjectInvite.deleteOne', function(done) { return this.call(err => { - this.ProjectInvite.remove.callCount.should.equal(1) - this.ProjectInvite.remove + this.ProjectInvite.deleteOne.callCount.should.equal(1) + this.ProjectInvite.deleteOne .calledWith({ projectId: this.projectId, _id: this.inviteId }) .should.equal(true) return done() @@ -440,7 +443,7 @@ describe('CollaboratorsInviteHandler', function() { describe('when remove produces an error', function() { beforeEach(function() { - return this.ProjectInvite.remove.callsArgWith(1, new Error('woops')) + return this.ProjectInvite.deleteOne.callsArgWith(1, new Error('woops')) }) it('should produce an error', function(done) { @@ -641,7 +644,7 @@ describe('CollaboratorsInviteHandler', function() { this.CollaboratorsInviteHandler._tryCancelInviteNotification = sinon .stub() .callsArgWith(1, null) - this.ProjectInvite.remove.callsArgWith(1, null) + this.ProjectInvite.deleteOne.callsArgWith(1, null) return (this.call = callback => { return this.CollaboratorsInviteHandler.acceptInvite( this.projectId, @@ -692,10 +695,10 @@ describe('CollaboratorsInviteHandler', function() { }) }) - it('should have called ProjectInvite.remove', function(done) { + it('should have called ProjectInvite.deleteOne', function(done) { return this.call(err => { - this.ProjectInvite.remove.callCount.should.equal(1) - this.ProjectInvite.remove + this.ProjectInvite.deleteOne.callCount.should.equal(1) + this.ProjectInvite.deleteOne .calledWith({ _id: this.inviteId }) .should.equal(true) return done() @@ -763,9 +766,9 @@ describe('CollaboratorsInviteHandler', function() { }) }) - it('should not have called ProjectInvite.remove', function(done) { + it('should not have called ProjectInvite.deleteOne', function(done) { return this.call(err => { - this.ProjectInvite.remove.callCount.should.equal(0) + this.ProjectInvite.deleteOne.callCount.should.equal(0) return done() }) }) @@ -800,9 +803,9 @@ describe('CollaboratorsInviteHandler', function() { }) }) - it('should not have called ProjectInvite.remove', function(done) { + it('should not have called ProjectInvite.deleteOne', function(done) { return this.call(err => { - this.ProjectInvite.remove.callCount.should.equal(0) + this.ProjectInvite.deleteOne.callCount.should.equal(0) return done() }) }) @@ -848,17 +851,17 @@ describe('CollaboratorsInviteHandler', function() { }) }) - it('should not have called ProjectInvite.remove', function(done) { + it('should not have called ProjectInvite.deleteOne', function(done) { return this.call(err => { - this.ProjectInvite.remove.callCount.should.equal(0) + this.ProjectInvite.deleteOne.callCount.should.equal(0) return done() }) }) }) - describe('when ProjectInvite.remove produces an error', function() { + describe('when ProjectInvite.deleteOne produces an error', function() { beforeEach(function() { - return this.ProjectInvite.remove.callsArgWith(1, new Error('woops')) + return this.ProjectInvite.deleteOne.callsArgWith(1, new Error('woops')) }) it('should produce an error', function(done) { @@ -893,9 +896,9 @@ describe('CollaboratorsInviteHandler', function() { }) }) - it('should have called ProjectInvite.remove', function(done) { + it('should have called ProjectInvite.deleteOne', function(done) { return this.call(err => { - this.ProjectInvite.remove.callCount.should.equal(1) + this.ProjectInvite.deleteOne.callCount.should.equal(1) return done() }) }) diff --git a/services/web/test/unit/src/Collaborators/OwnershipTransferHandlerTests.js b/services/web/test/unit/src/Collaborators/OwnershipTransferHandlerTests.js index 5cdb540de2..11bfe108ae 100644 --- a/services/web/test/unit/src/Collaborators/OwnershipTransferHandlerTests.js +++ b/services/web/test/unit/src/Collaborators/OwnershipTransferHandlerTests.js @@ -24,7 +24,7 @@ describe('OwnershipTransferHandler', function() { } } this.ProjectModel = { - update: sinon.stub().returns({ + updateOne: sinon.stub().returns({ exec: sinon.stub().resolves() }) } @@ -129,7 +129,7 @@ describe('OwnershipTransferHandler', function() { this.project._id, this.collaborator._id ) - expect(this.ProjectModel.update).to.have.been.calledWith( + expect(this.ProjectModel.updateOne).to.have.been.calledWith( { _id: this.project._id }, sinon.match({ $set: { owner_ref: this.collaborator._id } }) ) @@ -140,7 +140,7 @@ describe('OwnershipTransferHandler', function() { this.project._id, this.user._id ) - expect(this.ProjectModel.update).not.to.have.been.called + expect(this.ProjectModel.updateOne).not.to.have.been.called }) it("should remove the user from the project's collaborators", async function() { diff --git a/services/web/test/unit/src/Project/ProjectCollabratecDetailsTest.js b/services/web/test/unit/src/Project/ProjectCollabratecDetailsTest.js index 9e0a9980c4..62d9e2b104 100644 --- a/services/web/test/unit/src/Project/ProjectCollabratecDetailsTest.js +++ b/services/web/test/unit/src/Project/ProjectCollabratecDetailsTest.js @@ -49,7 +49,7 @@ describe('ProjectCollabratecDetailsHandler', function() { describe('initializeCollabratecProject', function() { describe('when update succeeds', function() { beforeEach(function() { - this.ProjectModel.update = sinon.stub().yields() + this.ProjectModel.updateOne = sinon.stub().yields() return this.ProjectCollabratecDetailsHandler.initializeCollabratecProject( this.projectId, this.userId, @@ -71,7 +71,7 @@ describe('ProjectCollabratecDetailsHandler', function() { ] } } - return expect(this.ProjectModel.update).to.have.been.calledWith( + return expect(this.ProjectModel.updateOne).to.have.been.calledWith( { _id: this.projectId }, update, this.callback @@ -81,7 +81,7 @@ describe('ProjectCollabratecDetailsHandler', function() { describe('when update has error', function() { beforeEach(function() { - this.ProjectModel.update = sinon.stub().yields('error') + this.ProjectModel.updateOne = sinon.stub().yields('error') return this.ProjectCollabratecDetailsHandler.initializeCollabratecProject( this.projectId, this.userId, @@ -98,7 +98,7 @@ describe('ProjectCollabratecDetailsHandler', function() { describe('with invalid args', function() { beforeEach(function() { - this.ProjectModel.update = sinon.stub() + this.ProjectModel.updateOne = sinon.stub() return this.ProjectCollabratecDetailsHandler.initializeCollabratecProject( 'bad-project-id', 'bad-user-id', @@ -109,7 +109,7 @@ describe('ProjectCollabratecDetailsHandler', function() { }) it('should not update', function() { - return expect(this.ProjectModel.update).not.to.have.been.called + return expect(this.ProjectModel.updateOne).not.to.have.been.called }) it('should callback with error', function() { @@ -206,7 +206,7 @@ describe('ProjectCollabratecDetailsHandler', function() { describe('linkCollabratecUserProject', function() { describe('when update succeeds', function() { beforeEach(function() { - this.ProjectModel.update = sinon.stub().yields() + this.ProjectModel.updateOne = sinon.stub().yields() return this.ProjectCollabratecDetailsHandler.linkCollabratecUserProject( this.projectId, this.userId, @@ -235,7 +235,7 @@ describe('ProjectCollabratecDetailsHandler', function() { } } } - return expect(this.ProjectModel.update).to.have.been.calledWith( + return expect(this.ProjectModel.updateOne).to.have.been.calledWith( query, update, this.callback @@ -245,7 +245,7 @@ describe('ProjectCollabratecDetailsHandler', function() { describe('when update has error', function() { beforeEach(function() { - this.ProjectModel.update = sinon.stub().yields('error') + this.ProjectModel.updateOne = sinon.stub().yields('error') return this.ProjectCollabratecDetailsHandler.linkCollabratecUserProject( this.projectId, this.userId, @@ -261,7 +261,7 @@ describe('ProjectCollabratecDetailsHandler', function() { describe('with invalid args', function() { beforeEach(function() { - this.ProjectModel.update = sinon.stub() + this.ProjectModel.updateOne = sinon.stub() return this.ProjectCollabratecDetailsHandler.linkCollabratecUserProject( 'bad-project-id', 'bad-user-id', @@ -271,7 +271,7 @@ describe('ProjectCollabratecDetailsHandler', function() { }) it('should not update', function() { - return expect(this.ProjectModel.update).not.to.have.been.called + return expect(this.ProjectModel.updateOne).not.to.have.been.called }) it('should callback with error', function() { @@ -298,7 +298,7 @@ describe('ProjectCollabratecDetailsHandler', function() { describe('when update succeeds', function() { beforeEach(function() { - this.ProjectModel.update = sinon.stub().yields() + this.ProjectModel.updateOne = sinon.stub().yields() return this.ProjectCollabratecDetailsHandler.setCollabratecUsers( this.projectId, this.collabratecUsers, @@ -312,7 +312,7 @@ describe('ProjectCollabratecDetailsHandler', function() { collabratecUsers: this.collabratecUsers } } - return expect(this.ProjectModel.update).to.have.been.calledWith( + return expect(this.ProjectModel.updateOne).to.have.been.calledWith( { _id: this.projectId }, update, this.callback @@ -322,7 +322,7 @@ describe('ProjectCollabratecDetailsHandler', function() { describe('when update has error', function() { beforeEach(function() { - this.ProjectModel.update = sinon.stub().yields('error') + this.ProjectModel.updateOne = sinon.stub().yields('error') return this.ProjectCollabratecDetailsHandler.setCollabratecUsers( this.projectId, this.collabratecUsers, @@ -337,7 +337,7 @@ describe('ProjectCollabratecDetailsHandler', function() { describe('with invalid project_id', function() { beforeEach(function() { - this.ProjectModel.update = sinon.stub() + this.ProjectModel.updateOne = sinon.stub() return this.ProjectCollabratecDetailsHandler.setCollabratecUsers( 'bad-project-id', this.collabratecUsers, @@ -346,7 +346,7 @@ describe('ProjectCollabratecDetailsHandler', function() { }) it('should not update', function() { - return expect(this.ProjectModel.update).not.to.have.been.called + return expect(this.ProjectModel.updateOne).not.to.have.been.called }) it('should callback with error', function() { @@ -357,7 +357,7 @@ describe('ProjectCollabratecDetailsHandler', function() { describe('with invalid user_id', function() { beforeEach(function() { this.collabratecUsers[1].user_id = 'bad-user-id' - this.ProjectModel.update = sinon.stub() + this.ProjectModel.updateOne = sinon.stub() return this.ProjectCollabratecDetailsHandler.setCollabratecUsers( this.projectId, this.collabratecUsers, @@ -366,7 +366,7 @@ describe('ProjectCollabratecDetailsHandler', function() { }) it('should not update', function() { - return expect(this.ProjectModel.update).not.to.have.been.called + return expect(this.ProjectModel.updateOne).not.to.have.been.called }) it('should callback with error', function() { @@ -378,7 +378,7 @@ describe('ProjectCollabratecDetailsHandler', function() { describe('unlinkCollabratecUserProject', function() { describe('when update succeeds', function() { beforeEach(function() { - this.ProjectModel.update = sinon.stub().yields() + this.ProjectModel.updateOne = sinon.stub().yields() return this.ProjectCollabratecDetailsHandler.unlinkCollabratecUserProject( this.projectId, this.userId, @@ -395,7 +395,7 @@ describe('ProjectCollabratecDetailsHandler', function() { } } } - return expect(this.ProjectModel.update).to.have.been.calledWith( + return expect(this.ProjectModel.updateOne).to.have.been.calledWith( query, update, this.callback @@ -405,7 +405,7 @@ describe('ProjectCollabratecDetailsHandler', function() { describe('when update has error', function() { beforeEach(function() { - this.ProjectModel.update = sinon.stub().yields('error') + this.ProjectModel.updateOne = sinon.stub().yields('error') return this.ProjectCollabratecDetailsHandler.unlinkCollabratecUserProject( this.projectId, this.userId, @@ -420,7 +420,7 @@ describe('ProjectCollabratecDetailsHandler', function() { describe('with invalid args', function() { beforeEach(function() { - this.ProjectModel.update = sinon.stub() + this.ProjectModel.updateOne = sinon.stub() return this.ProjectCollabratecDetailsHandler.unlinkCollabratecUserProject( 'bad-project-id', 'bad-user-id', @@ -429,7 +429,7 @@ describe('ProjectCollabratecDetailsHandler', function() { }) it('should not update', function() { - return expect(this.ProjectModel.update).not.to.have.been.called + return expect(this.ProjectModel.updateOne).not.to.have.been.called }) it('should callback with error', function() { @@ -441,7 +441,7 @@ describe('ProjectCollabratecDetailsHandler', function() { describe('updateCollabratecUserIds', function() { describe('when update succeeds', function() { beforeEach(function() { - this.ProjectModel.update = sinon.stub().yields() + this.ProjectModel.updateMany = sinon.stub().yields() return this.ProjectCollabratecDetailsHandler.updateCollabratecUserIds( this.userId, this.userId2, @@ -450,10 +450,9 @@ describe('ProjectCollabratecDetailsHandler', function() { }) it('should update project model', function() { - return expect(this.ProjectModel.update).to.have.been.calledWith( + return expect(this.ProjectModel.updateMany).to.have.been.calledWith( { 'collabratecUsers.user_id': this.userId }, { $set: { 'collabratecUsers.$.user_id': this.userId2 } }, - { multi: true }, this.callback ) }) @@ -461,7 +460,7 @@ describe('ProjectCollabratecDetailsHandler', function() { describe('when update has error', function() { beforeEach(function() { - this.ProjectModel.update = sinon.stub().yields('error') + this.ProjectModel.updateMany = sinon.stub().yields('error') return this.ProjectCollabratecDetailsHandler.updateCollabratecUserIds( this.userId, this.userId2, @@ -476,7 +475,7 @@ describe('ProjectCollabratecDetailsHandler', function() { describe('with invalid old_user_id', function() { beforeEach(function() { - this.ProjectModel.update = sinon.stub() + this.ProjectModel.updateOne = sinon.stub() return this.ProjectCollabratecDetailsHandler.updateCollabratecUserIds( 'bad-user-id', this.userId2, @@ -485,7 +484,7 @@ describe('ProjectCollabratecDetailsHandler', function() { }) it('should not update', function() { - return expect(this.ProjectModel.update).not.to.have.been.called + return expect(this.ProjectModel.updateOne).not.to.have.been.called }) it('should callback with error', function() { @@ -495,7 +494,7 @@ describe('ProjectCollabratecDetailsHandler', function() { describe('with invalid new_user_id', function() { beforeEach(function() { - this.ProjectModel.update = sinon.stub() + this.ProjectModel.updateOne = sinon.stub() return this.ProjectCollabratecDetailsHandler.updateCollabratecUserIds( this.userId, 'bad-user-id', @@ -504,7 +503,7 @@ describe('ProjectCollabratecDetailsHandler', function() { }) it('should not update', function() { - return expect(this.ProjectModel.update).not.to.have.been.called + return expect(this.ProjectModel.updateOne).not.to.have.been.called }) it('should callback with error', function() { diff --git a/services/web/test/unit/src/Project/ProjectDeleterTests.js b/services/web/test/unit/src/Project/ProjectDeleterTests.js index 35e2f20d52..b383788b6b 100644 --- a/services/web/test/unit/src/Project/ProjectDeleterTests.js +++ b/services/web/test/unit/src/Project/ProjectDeleterTests.js @@ -162,7 +162,7 @@ describe('ProjectDeleter', function() { describe('mark as deleted by external source', function() { beforeEach(function() { - this.ProjectMock.expects('update') + this.ProjectMock.expects('updateOne') .withArgs( { _id: this.project._id }, { deletedByExternalDataSource: true } @@ -191,7 +191,7 @@ describe('ProjectDeleter', function() { describe('unmarkAsDeletedByExternalSource', function() { beforeEach(async function() { - this.ProjectMock.expects('update') + this.ProjectMock.expects('updateOne') .withArgs( { _id: this.project._id }, { deletedByExternalDataSource: false } @@ -220,11 +220,11 @@ describe('ProjectDeleter', function() { .withArgs({ _id: project._id }) .chain('exec') .resolves(project) - this.ProjectMock.expects('remove') + this.ProjectMock.expects('deleteOne') .withArgs({ _id: project._id }) .chain('exec') .resolves() - this.DeletedProjectMock.expects('update') + this.DeletedProjectMock.expects('updateOne') .withArgs( { 'deleterData.deletedProjectId': project._id }, { @@ -284,10 +284,10 @@ describe('ProjectDeleter', function() { this.deleterData.deleterIpAddress = this.ip this.deleterData.deleterId = this.user._id - this.ProjectMock.expects('remove') + this.ProjectMock.expects('deleteOne') .chain('exec') .resolves() - this.DeletedProjectMock.expects('update') + this.DeletedProjectMock.expects('updateOne') .withArgs( { 'deleterData.deletedProjectId': this.project._id }, { @@ -306,10 +306,10 @@ describe('ProjectDeleter', function() { }) it('should flushProjectToMongoAndDelete in doc updater', async function() { - this.ProjectMock.expects('remove') + this.ProjectMock.expects('deleteOne') .chain('exec') .resolves() - this.DeletedProjectMock.expects('update').resolves() + this.DeletedProjectMock.expects('updateOne').resolves() await this.ProjectDeleter.promises.deleteProject(this.project._id, { deleterUser: this.user, @@ -321,10 +321,10 @@ describe('ProjectDeleter', function() { }) it('should removeProjectFromAllTags', async function() { - this.ProjectMock.expects('remove') + this.ProjectMock.expects('deleteOne') .chain('exec') .resolves() - this.DeletedProjectMock.expects('update').resolves() + this.DeletedProjectMock.expects('updateOne').resolves() await this.ProjectDeleter.promises.deleteProject(this.project._id) sinon.assert.calledWith( @@ -340,11 +340,11 @@ describe('ProjectDeleter', function() { }) it('should remove the project from Mongo', async function() { - this.ProjectMock.expects('remove') + this.ProjectMock.expects('deleteOne') .withArgs({ _id: this.project._id }) .chain('exec') .resolves() - this.DeletedProjectMock.expects('update').resolves() + this.DeletedProjectMock.expects('updateOne').resolves() await this.ProjectDeleter.promises.deleteProject(this.project._id) this.ProjectMock.verify() @@ -372,7 +372,7 @@ describe('ProjectDeleter', function() { }) .chain('exec') .resolves(deletedProject) - this.DeletedProjectMock.expects('update') + this.DeletedProjectMock.expects('updateOne') .withArgs( { _id: deletedProject._id @@ -398,7 +398,7 @@ describe('ProjectDeleter', function() { describe('expireDeletedProject', function() { beforeEach(async function() { - this.DeletedProjectMock.expects('update') + this.DeletedProjectMock.expects('updateOne') .withArgs( { _id: this.deletedProjects[0]._id @@ -458,7 +458,7 @@ describe('ProjectDeleter', function() { .chain('exec') .resolves(this.project) - this.ProjectMock.expects('update') + this.ProjectMock.expects('updateOne') .withArgs( { _id: this.project._id }, { @@ -500,7 +500,7 @@ describe('ProjectDeleter', function() { .chain('exec') .resolves(this.project) - this.ProjectMock.expects('update') + this.ProjectMock.expects('updateOne') .withArgs({ _id: this.project._id }, { $set: { archived: archived } }) .resolves() }) @@ -536,7 +536,7 @@ describe('ProjectDeleter', function() { .chain('exec') .resolves(this.project) - this.ProjectMock.expects('update') + this.ProjectMock.expects('updateOne') .withArgs( { _id: this.project._id }, { @@ -575,7 +575,7 @@ describe('ProjectDeleter', function() { .chain('exec') .resolves(this.project) - this.ProjectMock.expects('update') + this.ProjectMock.expects('updateOne') .withArgs( { _id: this.project._id }, { $pull: { trashed: ObjectId(this.user._id) } } @@ -594,7 +594,7 @@ describe('ProjectDeleter', function() { describe('restoreProject', function() { beforeEach(function() { - this.ProjectMock.expects('update') + this.ProjectMock.expects('updateOne') .withArgs( { _id: this.project._id diff --git a/services/web/test/unit/src/Project/ProjectDetailsHandlerTests.js b/services/web/test/unit/src/Project/ProjectDetailsHandlerTests.js index 8755b7d98e..1f7c49eae9 100644 --- a/services/web/test/unit/src/Project/ProjectDetailsHandlerTests.js +++ b/services/web/test/unit/src/Project/ProjectDetailsHandlerTests.js @@ -43,7 +43,7 @@ describe('ProjectDetailsHandler', function() { exec: sinon.stub().resolves() } this.ProjectModel = { - update: sinon.stub().returns(this.ProjectModelUpdateQuery) + updateOne: sinon.stub().returns(this.ProjectModelUpdateQuery) } this.UserGetter = { promises: { @@ -156,7 +156,7 @@ describe('ProjectDetailsHandler', function() { this.project._id, this.description ) - expect(this.ProjectModel.update).to.have.been.calledWith( + expect(this.ProjectModel.updateOne).to.have.been.calledWith( { _id: this.project._id }, { description: this.description } ) @@ -170,7 +170,7 @@ describe('ProjectDetailsHandler', function() { it('should update the project with the new name', async function() { await this.handler.promises.renameProject(this.project._id, this.newName) - expect(this.ProjectModel.update).to.have.been.calledWith( + expect(this.ProjectModel.updateOne).to.have.been.calledWith( { _id: this.project._id }, { name: this.newName } ) @@ -191,7 +191,7 @@ describe('ProjectDetailsHandler', function() { await expect(this.handler.promises.renameProject(this.project._id)).to.be .rejected expect(this.TpdsUpdateSender.promises.moveEntity).not.to.have.been.called - expect(this.ProjectModel.update).not.to.have.been.called + expect(this.ProjectModel.updateOne).not.to.have.been.called }) }) @@ -401,7 +401,7 @@ describe('ProjectDetailsHandler', function() { this.project._id, this.accessLevel ) - expect(this.ProjectModel.update).to.have.been.calledWith( + expect(this.ProjectModel.updateOne).to.have.been.calledWith( { _id: this.project._id }, { publicAccesLevel: this.accessLevel } ) @@ -459,7 +459,7 @@ describe('ProjectDetailsHandler', function() { it('should not update the project with new tokens', async function() { await this.handler.promises.ensureTokensArePresent(this.project._id) - expect(this.ProjectModel.update).not.to.have.been.called + expect(this.ProjectModel.updateOne).not.to.have.been.called }) it('should produce the tokens without error', async function() { @@ -503,8 +503,8 @@ describe('ProjectDetailsHandler', function() { .to.have.been.calledOnce expect(this.ProjectTokenGenerator.readAndWriteToken).to.have.been .calledOnce - expect(this.ProjectModel.update).to.have.been.calledOnce - expect(this.ProjectModel.update).to.have.been.calledWith( + expect(this.ProjectModel.updateOne).to.have.been.calledOnce + expect(this.ProjectModel.updateOne).to.have.been.calledWith( { _id: this.project._id }, { $set: { @@ -534,7 +534,7 @@ describe('ProjectDetailsHandler', function() { describe('clearTokens', function() { it('clears the tokens from the project', async function() { await this.handler.promises.clearTokens(this.project._id) - expect(this.ProjectModel.update).to.have.been.calledWith( + expect(this.ProjectModel.updateOne).to.have.been.calledWith( { _id: this.project._id }, { $unset: { tokens: 1 }, $set: { publicAccesLevel: 'private' } } ) diff --git a/services/web/test/unit/src/Project/ProjectEntityUpdateHandlerTests.js b/services/web/test/unit/src/Project/ProjectEntityUpdateHandlerTests.js index cbea945337..e8e307cc49 100644 --- a/services/web/test/unit/src/Project/ProjectEntityUpdateHandlerTests.js +++ b/services/web/test/unit/src/Project/ProjectEntityUpdateHandlerTests.js @@ -96,7 +96,7 @@ describe('ProjectEntityUpdateHandler', function() { ) } this.ProjectModel = { - update: sinon.stub() + updateOne: sinon.stub() } this.ProjectGetter = { getProject: sinon.stub(), @@ -385,7 +385,7 @@ describe('ProjectEntityUpdateHandler', function() { this.rootDocId = 'root-doc-id-123123' }) - it('should call Project.update when the doc exists and has a valid extension', function() { + it('should call Project.updateOne when the doc exists and has a valid extension', function() { this.ProjectEntityHandler.getDocPathByProjectIdAndDocId.yields( null, `/main.tex` @@ -396,12 +396,12 @@ describe('ProjectEntityUpdateHandler', function() { this.rootDocId, () => {} ) - this.ProjectModel.update + this.ProjectModel.updateOne .calledWith({ _id: projectId }, { rootDoc_id: this.rootDocId }) .should.equal(true) }) - it("should not call Project.update when the doc doesn't exist", function() { + it("should not call Project.updateOne when the doc doesn't exist", function() { this.ProjectEntityHandler.getDocPathByProjectIdAndDocId.yields( Errors.NotFoundError ) @@ -411,7 +411,7 @@ describe('ProjectEntityUpdateHandler', function() { this.rootDocId, () => {} ) - this.ProjectModel.update + this.ProjectModel.updateOne .calledWith({ _id: projectId }, { rootDoc_id: this.rootDocId }) .should.equal(false) }) @@ -434,9 +434,9 @@ describe('ProjectEntityUpdateHandler', function() { }) describe('unsetRootDoc', function() { - it('should call Project.update', function() { + it('should call Project.updateOne', function() { this.ProjectEntityUpdateHandler.unsetRootDoc(projectId) - this.ProjectModel.update + this.ProjectModel.updateOne .calledWith({ _id: projectId }, { $unset: { rootDoc_id: true } }) .should.equal(true) }) diff --git a/services/web/test/unit/src/Project/ProjectHistoryHandlerTests.js b/services/web/test/unit/src/Project/ProjectHistoryHandlerTests.js index fd999c933b..ff1a4e88e6 100644 --- a/services/web/test/unit/src/Project/ProjectHistoryHandlerTests.js +++ b/services/web/test/unit/src/Project/ProjectHistoryHandlerTests.js @@ -83,7 +83,9 @@ describe('ProjectHistoryHandler', function() { .stub() .withArgs(project_id) .callsArgWith(1, null, this.project) - this.ProjectModel.update = sinon.stub().callsArgWith(2, null, { n: 1 }) + this.ProjectModel.updateOne = sinon + .stub() + .callsArgWith(2, null, { n: 1 }) return this.ProjectHistoryHandler.ensureHistoryExistsForProject( project_id, this.callback @@ -101,7 +103,7 @@ describe('ProjectHistoryHandler', function() { }) it('should set the new history id on the project', function() { - return this.ProjectModel.update + return this.ProjectModel.updateOne .calledWith( { _id: project_id, 'overleaf.history.id': { $exists: false } }, { 'overleaf.history.id': this.newHistoryId } @@ -133,7 +135,7 @@ describe('ProjectHistoryHandler', function() { .stub() .withArgs(project_id) .callsArgWith(1, null, this.project) - this.ProjectModel.update = sinon.stub() + this.ProjectModel.updateOne = sinon.stub() return this.ProjectHistoryHandler.ensureHistoryExistsForProject( project_id, this.callback @@ -151,7 +153,7 @@ describe('ProjectHistoryHandler', function() { }) it('should not set the new history id on the project', function() { - return this.ProjectModel.update.called.should.equal(false) + return this.ProjectModel.updateOne.called.should.equal(false) }) it('should not resync the project history', function() { diff --git a/services/web/test/unit/src/Project/ProjectOptionsHandlerTests.js b/services/web/test/unit/src/Project/ProjectOptionsHandlerTests.js index 0fd06b695f..943bcf45b6 100644 --- a/services/web/test/unit/src/Project/ProjectOptionsHandlerTests.js +++ b/services/web/test/unit/src/Project/ProjectOptionsHandlerTests.js @@ -29,7 +29,7 @@ describe('ProjectOptionsHandler', function() { this.projectModel = Project = class Project { constructor(options) {} } - this.projectModel.update = sinon.stub().yields() + this.projectModel.updateOne = sinon.stub().yields() this.handler = SandboxedModule.require(modulePath, { globals: { @@ -59,7 +59,7 @@ describe('ProjectOptionsHandler', function() { describe('Setting the compiler', function() { it('should perform and update on mongo', function(done) { this.handler.setCompiler(project_id, 'xeLaTeX', err => { - const args = this.projectModel.update.args[0] + const args = this.projectModel.updateOne.args[0] args[0]._id.should.equal(project_id) args[1].compiler.should.equal('xelatex') done() @@ -68,7 +68,7 @@ describe('ProjectOptionsHandler', function() { it('should not perform and update on mongo if it is not a recognised compiler', function(done) { this.handler.setCompiler(project_id, 'something', err => { - this.projectModel.update.called.should.equal(false) + this.projectModel.updateOne.called.should.equal(false) done() }) }) @@ -77,7 +77,7 @@ describe('ProjectOptionsHandler', function() { it('should callback with null', function(done) { this.handler.setCompiler(project_id, null, err => { expect(err).to.be.undefined - this.projectModel.update.callCount.should.equal(0) + this.projectModel.updateOne.callCount.should.equal(0) done() }) }) @@ -85,7 +85,7 @@ describe('ProjectOptionsHandler', function() { describe('when mongo update error occurs', function() { beforeEach(function() { - this.projectModel.update = sinon.stub().yields('error') + this.projectModel.updateOne = sinon.stub().yields('error') }) it('should callback with error', function(done) { @@ -100,7 +100,7 @@ describe('ProjectOptionsHandler', function() { describe('Setting the imageName', function() { it('should perform and update on mongo', function(done) { this.handler.setImageName(project_id, 'texlive-1234.5', err => { - const args = this.projectModel.update.args[0] + const args = this.projectModel.updateOne.args[0] args[0]._id.should.equal(project_id) args[1].imageName.should.equal('docker-repo/subdir/texlive-1234.5') done() @@ -109,7 +109,7 @@ describe('ProjectOptionsHandler', function() { it('should not perform and update on mongo if it is not a reconised compiler', function(done) { this.handler.setImageName(project_id, 'something', err => { - this.projectModel.update.called.should.equal(false) + this.projectModel.updateOne.called.should.equal(false) done() }) }) @@ -118,7 +118,7 @@ describe('ProjectOptionsHandler', function() { it('should callback with null', function(done) { this.handler.setImageName(project_id, null, err => { expect(err).to.be.undefined - this.projectModel.update.callCount.should.equal(0) + this.projectModel.updateOne.callCount.should.equal(0) done() }) }) @@ -126,7 +126,7 @@ describe('ProjectOptionsHandler', function() { describe('when mongo update error occurs', function() { beforeEach(function() { - this.projectModel.update = sinon.stub().yields('error') + this.projectModel.updateOne = sinon.stub().yields('error') }) it('should callback with error', function(done) { @@ -141,7 +141,7 @@ describe('ProjectOptionsHandler', function() { describe('setting the spellCheckLanguage', function() { it('should perform and update on mongo', function(done) { this.handler.setSpellCheckLanguage(project_id, 'fr', err => { - const args = this.projectModel.update.args[0] + const args = this.projectModel.updateOne.args[0] args[0]._id.should.equal(project_id) args[1].spellCheckLanguage.should.equal('fr') done() @@ -150,21 +150,21 @@ describe('ProjectOptionsHandler', function() { it('should not perform and update on mongo if it is not a reconised compiler', function(done) { this.handler.setSpellCheckLanguage(project_id, 'no a lang', err => { - this.projectModel.update.called.should.equal(false) + this.projectModel.updateOne.called.should.equal(false) done() }) }) it('should perform and update on mongo if the language is blank (means turn it off)', function(done) { this.handler.setSpellCheckLanguage(project_id, '', err => { - this.projectModel.update.called.should.equal(true) + this.projectModel.updateOne.called.should.equal(true) done() }) }) describe('when mongo update error occurs', function() { beforeEach(function() { - this.projectModel.update = sinon.stub().yields('error') + this.projectModel.updateOne = sinon.stub().yields('error') }) it('should callback with error', function(done) { @@ -179,7 +179,7 @@ describe('ProjectOptionsHandler', function() { describe('setting the brandVariationId', function() { it('should perform and update on mongo', function(done) { this.handler.setBrandVariationId(project_id, '123', err => { - const args = this.projectModel.update.args[0] + const args = this.projectModel.updateOne.args[0] args[0]._id.should.equal(project_id) args[1].brandVariationId.should.equal('123') done() @@ -188,21 +188,21 @@ describe('ProjectOptionsHandler', function() { it('should not perform and update on mongo if there is no brand variation', function(done) { this.handler.setBrandVariationId(project_id, null, err => { - this.projectModel.update.called.should.equal(false) + this.projectModel.updateOne.called.should.equal(false) done() }) }) it('should not perform and update on mongo if brand variation is an empty string', function(done) { this.handler.setBrandVariationId(project_id, '', err => { - this.projectModel.update.called.should.equal(false) + this.projectModel.updateOne.called.should.equal(false) done() }) }) describe('when mongo update error occurs', function() { beforeEach(function() { - this.projectModel.update = sinon.stub().yields('error') + this.projectModel.updateOne = sinon.stub().yields('error') }) it('should callback with error', function(done) { @@ -217,7 +217,7 @@ describe('ProjectOptionsHandler', function() { describe('unsetting the brandVariationId', function() { it('should perform and update on mongo', function(done) { this.handler.unsetBrandVariationId(project_id, err => { - const args = this.projectModel.update.args[0] + const args = this.projectModel.updateOne.args[0] args[0]._id.should.equal(project_id) expect(args[1]).to.deep.equal({ $unset: { brandVariationId: 1 } }) done() @@ -226,7 +226,7 @@ describe('ProjectOptionsHandler', function() { describe('when mongo update error occurs', function() { beforeEach(function() { - this.projectModel.update = sinon.stub().yields('error') + this.projectModel.updateOne = sinon.stub().yields('error') }) it('should callback with error', function(done) { diff --git a/services/web/test/unit/src/Project/ProjectUpdateHandlerTests.js b/services/web/test/unit/src/Project/ProjectUpdateHandlerTests.js index d9a653238f..2c4ad29427 100644 --- a/services/web/test/unit/src/Project/ProjectUpdateHandlerTests.js +++ b/services/web/test/unit/src/Project/ProjectUpdateHandlerTests.js @@ -27,7 +27,7 @@ describe('ProjectUpdateHandler', function() { beforeEach(function() { let Project this.ProjectModel = Project = class Project {} - this.ProjectModel.update = sinon.stub().callsArg(3) + this.ProjectModel.updateOne = sinon.stub().callsArg(3) return (this.handler = SandboxedModule.require(modulePath, { globals: { console: console @@ -53,7 +53,7 @@ describe('ProjectUpdateHandler', function() { this.lastUpdatedBy, err => { sinon.assert.calledWith( - this.ProjectModel.update, + this.ProjectModel.updateOne, { _id: this.project_id, lastUpdated: { $lt: this.lastUpdatedAt } @@ -71,7 +71,7 @@ describe('ProjectUpdateHandler', function() { it('should set smart fallbacks', function(done) { return this.handler.markAsUpdated(this.project_id, null, null, err => { sinon.assert.calledWithMatch( - this.ProjectModel.update, + this.ProjectModel.updateOne, { _id: this.project_id, lastUpdated: { $lt: this.fakeTime } @@ -90,7 +90,7 @@ describe('ProjectUpdateHandler', function() { it('should send an update to mongo', function(done) { const project_id = 'project_id' return this.handler.markAsOpened(project_id, err => { - const args = this.ProjectModel.update.args[0] + const args = this.ProjectModel.updateOne.args[0] args[0]._id.should.equal(project_id) const date = args[1].lastOpened + '' const now = Date.now() + '' @@ -104,7 +104,7 @@ describe('ProjectUpdateHandler', function() { it('should send an update to mongo', function(done) { const project_id = 'project_id' return this.handler.markAsInactive(project_id, err => { - const args = this.ProjectModel.update.args[0] + const args = this.ProjectModel.updateOne.args[0] args[0]._id.should.equal(project_id) args[1].active.should.equal(false) return done() @@ -116,7 +116,7 @@ describe('ProjectUpdateHandler', function() { it('should send an update to mongo', function(done) { const project_id = 'project_id' return this.handler.markAsActive(project_id, err => { - const args = this.ProjectModel.update.args[0] + const args = this.ProjectModel.updateOne.args[0] args[0]._id.should.equal(project_id) args[1].active.should.equal(true) return done() diff --git a/services/web/test/unit/src/Referal/ReferalAllocatorTests.js b/services/web/test/unit/src/Referal/ReferalAllocatorTests.js index 2578fcf64c..9b9acfe032 100644 --- a/services/web/test/unit/src/Referal/ReferalAllocatorTests.js +++ b/services/web/test/unit/src/Referal/ReferalAllocatorTests.js @@ -30,7 +30,7 @@ describe('ReferalAllocator', function() { this.user_id = 'user-id-123' this.new_user_id = 'new-user-id-123' this.FeaturesUpdater.refreshFeatures = sinon.stub().yields() - this.User.update = sinon.stub().callsArgWith(3, null) + this.User.updateOne = sinon.stub().callsArgWith(3, null) this.User.findOne = sinon .stub() .callsArgWith(2, null, { _id: this.user_id }) @@ -50,7 +50,7 @@ describe('ReferalAllocator', function() { }) it('should update the referring user with the refered users id', function() { - this.User.update + this.User.updateOne .calledWith( { referal_id: this.referal_id @@ -105,7 +105,7 @@ describe('ReferalAllocator', function() { }) it('should not update the referring user with the refered users id', function() { - this.User.update.called.should.equal(false) + this.User.updateOne.called.should.equal(false) }) it('should not assign the user a bonus', function() { @@ -130,7 +130,7 @@ describe('ReferalAllocator', function() { }) it('should not update the referring user with the refered users id', function() { - this.User.update.called.should.equal(false) + this.User.updateOne.called.should.equal(false) }) it('find the referring users id', function() { diff --git a/services/web/test/unit/src/Subscription/SubscriptionGroupHandlerTests.js b/services/web/test/unit/src/Subscription/SubscriptionGroupHandlerTests.js index 53c6abba3a..85bef08983 100644 --- a/services/web/test/unit/src/Subscription/SubscriptionGroupHandlerTests.js +++ b/services/web/test/unit/src/Subscription/SubscriptionGroupHandlerTests.js @@ -68,7 +68,8 @@ describe('SubscriptionGroupHandler', function() { this.EmailHandler = { sendEmail: sinon.stub() } this.Subscription = { - update: sinon.stub().yields(), + updateOne: sinon.stub().yields(), + updateMany: sinon.stub().yields(), findOne: sinon.stub().yields() } @@ -143,38 +144,36 @@ describe('SubscriptionGroupHandler', function() { }) it('replaces the admin_id', function() { - return this.Subscription.update + return this.Subscription.updateOne .calledWith({ admin_id: this.oldId }, { admin_id: this.newId }) .should.equal(true) }) it('replaces the manager_ids', function() { - this.Subscription.update + this.Subscription.updateMany .calledWith( { manager_ids: 'ba5eba11' }, - { $addToSet: { manager_ids: '5ca1ab1e' } }, - { multi: true } + { $addToSet: { manager_ids: '5ca1ab1e' } } ) .should.equal(true) - return this.Subscription.update + return this.Subscription.updateMany .calledWith( { manager_ids: 'ba5eba11' }, - { $pull: { manager_ids: 'ba5eba11' } }, - { multi: true } + { $pull: { manager_ids: 'ba5eba11' } } ) .should.equal(true) }) it('replaces the member ids', function() { - this.Subscription.update + this.Subscription.updateMany .calledWith( { member_ids: this.oldId }, { $addToSet: { member_ids: this.newId } } ) .should.equal(true) - return this.Subscription.update + return this.Subscription.updateMany .calledWith( { member_ids: this.oldId }, { $pull: { member_ids: this.oldId } } diff --git a/services/web/test/unit/src/Subscription/SubscriptionUpdaterTests.js b/services/web/test/unit/src/Subscription/SubscriptionUpdaterTests.js index 035dd95700..f512038bf0 100644 --- a/services/web/test/unit/src/Subscription/SubscriptionUpdaterTests.js +++ b/services/web/test/unit/src/Subscription/SubscriptionUpdaterTests.js @@ -40,9 +40,6 @@ describe('SubscriptionUpdater', function() { this.updateStub = sinon.stub().callsArgWith(2, null) this.updateManyStub = sinon.stub().callsArgWith(2, null) - this.findAndModifyStub = sinon - .stub() - .callsArgWith(2, null, this.subscription) this.findOneAndUpdateStub = sinon .stub() .callsArgWith(2, null, this.subscription) @@ -56,10 +53,9 @@ describe('SubscriptionUpdater', function() { return subscription } } - this.SubscriptionModel.remove = sinon.stub().yields() - this.SubscriptionModel.update = this.updateStub + this.SubscriptionModel.deleteOne = sinon.stub().yields() + this.SubscriptionModel.updateOne = this.updateStub this.SubscriptionModel.updateMany = this.updateManyStub - this.SubscriptionModel.findAndModify = this.findAndModifyStub this.SubscriptionModel.findOneAndUpdate = this.findOneAndUpdateStub this.SubscriptionLocator = { @@ -138,8 +134,8 @@ describe('SubscriptionUpdater', function() { $set: { admin_id: ObjectId(this.otherUserId) }, $addToSet: { manager_ids: ObjectId(this.otherUserId) } } - this.SubscriptionModel.update.should.have.been.calledOnce - this.SubscriptionModel.update.should.have.been.calledWith( + this.SubscriptionModel.updateOne.should.have.been.calledOnce + this.SubscriptionModel.updateOne.should.have.been.calledWith( query, update ) @@ -166,8 +162,8 @@ describe('SubscriptionUpdater', function() { manager_ids: [ObjectId(this.otherUserId)] } } - this.SubscriptionModel.update.should.have.been.calledOnce - this.SubscriptionModel.update.should.have.been.calledWith( + this.SubscriptionModel.updateOne.should.have.been.calledOnce + this.SubscriptionModel.updateOne.should.have.been.calledWith( query, update ) @@ -402,7 +398,7 @@ describe('SubscriptionUpdater', function() { const insertOperation = { $addToSet: { member_ids: { $each: [this.otherUserId] } } } - this.findAndModifyStub + this.updateStub .calledWith(searchOps, insertOperation) .should.equal(true) done() @@ -489,7 +485,7 @@ describe('SubscriptionUpdater', function() { }) it('should remove the subscription', function() { - this.SubscriptionModel.remove + this.SubscriptionModel.deleteOne .calledWith({ _id: this.subscription._id }) .should.equal(true) }) diff --git a/services/web/test/unit/src/Subscription/TeamInvitesHandlerTests.js b/services/web/test/unit/src/Subscription/TeamInvitesHandlerTests.js index 925a4c1699..c6f0187f92 100644 --- a/services/web/test/unit/src/Subscription/TeamInvitesHandlerTests.js +++ b/services/web/test/unit/src/Subscription/TeamInvitesHandlerTests.js @@ -54,7 +54,7 @@ describe('TeamInvitesHandler', function() { this.Subscription = { findOne: sinon.stub().yields(), - update: sinon.stub().yields() + updateOne: sinon.stub().yields() } this.EmailHandler = { @@ -201,7 +201,7 @@ describe('TeamInvitesHandler', function() { this.subscription, 'John.Snow@example.com', (err, invite) => { - this.Subscription.update + this.Subscription.updateOne .calledWith( { _id: new ObjectId('55153a8014829a865bbf700d') }, { $pull: { invited_emails: 'john.snow@example.com' } } @@ -293,7 +293,7 @@ describe('TeamInvitesHandler', function() { it('removes the invite from the subscription', function(done) { this.TeamInvitesHandler.acceptInvite('dddddddd', this.user.id, () => { - this.Subscription.update + this.Subscription.updateOne .calledWith( { _id: new ObjectId('55153a8014829a865bbf700d') }, { $pull: { teamInvites: { email: 'john.snow@example.com' } } } @@ -311,14 +311,14 @@ describe('TeamInvitesHandler', function() { this.subscription, 'jorah@example.com', () => { - this.Subscription.update + this.Subscription.updateOne .calledWith( { _id: new ObjectId('55153a8014829a865bbf700d') }, { $pull: { teamInvites: { email: 'jorah@example.com' } } } ) .should.eq(true) - this.Subscription.update + this.Subscription.updateOne .calledWith( { _id: new ObjectId('55153a8014829a865bbf700d') }, { $pull: { invited_emails: 'jorah@example.com' } } diff --git a/services/web/test/unit/src/Subscription/UserFeaturesUpdaterTests.js b/services/web/test/unit/src/Subscription/UserFeaturesUpdaterTests.js index c4137e21b3..dd08a92ea9 100644 --- a/services/web/test/unit/src/Subscription/UserFeaturesUpdaterTests.js +++ b/services/web/test/unit/src/Subscription/UserFeaturesUpdaterTests.js @@ -21,7 +21,7 @@ const { assert } = require('chai') describe('UserFeaturesUpdater', function() { beforeEach(function() { - this.User = { update: sinon.stub().callsArgWith(2) } + this.User = { updateOne: sinon.stub().callsArgWith(2) } return (this.UserFeaturesUpdater = SandboxedModule.require(modulePath, { globals: { console: console @@ -49,7 +49,7 @@ describe('UserFeaturesUpdater', function() { 'features.versioning': true, 'features.collaborators': 10 } - this.User.update + this.User.updateOne .calledWith({ _id: user_id }, update) .should.equal(true) features.should.deep.equal(this.features) diff --git a/services/web/test/unit/src/SystemMessages/SystemMessageManagerTests.js b/services/web/test/unit/src/SystemMessages/SystemMessageManagerTests.js index 2155f49df6..e06edc2c87 100644 --- a/services/web/test/unit/src/SystemMessages/SystemMessageManagerTests.js +++ b/services/web/test/unit/src/SystemMessages/SystemMessageManagerTests.js @@ -53,12 +53,12 @@ describe('SystemMessageManager', function() { describe('clearMessages', function() { beforeEach(function() { - this.SystemMessage.remove = sinon.stub().callsArg(1) + this.SystemMessage.deleteMany = sinon.stub().callsArg(1) return this.SystemMessageManager.clearMessages(this.callback) }) it('should remove the messages from the database', function() { - return this.SystemMessage.remove.calledWith({}).should.equal(true) + return this.SystemMessage.deleteMany.calledWith({}).should.equal(true) }) it('should return the callback', function() { diff --git a/services/web/test/unit/src/Tags/TagsHandlerTests.js b/services/web/test/unit/src/Tags/TagsHandlerTests.js index 61bebebfb3..2584c8c6b1 100644 --- a/services/web/test/unit/src/Tags/TagsHandlerTests.js +++ b/services/web/test/unit/src/Tags/TagsHandlerTests.js @@ -124,7 +124,7 @@ describe('TagsHandler', function() { describe('addProjectToTagName', function() { it('should call update in mongo', function(done) { - this.TagMock.expects('update') + this.TagMock.expects('updateOne') .once() .withArgs( { name: this.tag.name, user_id: this.tag.userId }, @@ -148,12 +148,11 @@ describe('TagsHandler', function() { describe('updateTagUserIds', function() { it('should call update in mongo', function(done) { this.newUserId = ObjectId().toString() - this.TagMock.expects('update') + this.TagMock.expects('updateMany') .once() .withArgs( { user_id: this.userId }, - { $set: { user_id: this.newUserId } }, - { multi: true } + { $set: { user_id: this.newUserId } } ) .yields() this.TagsHandler.updateTagUserIds(this.userId, this.newUserId, err => { @@ -167,7 +166,7 @@ describe('TagsHandler', function() { describe('removeProjectFromTag', function() { describe('with a valid tag_id', function() { it('should call update in mongo', function(done) { - this.TagMock.expects('update') + this.TagMock.expects('updateOne') .once() .withArgs( { @@ -195,7 +194,7 @@ describe('TagsHandler', function() { describe('removeProjectFromAllTags', function() { it('should pull the project id from the tag', function(done) { - this.TagMock.expects('update') + this.TagMock.expects('updateMany') .once() .withArgs( { @@ -221,7 +220,7 @@ describe('TagsHandler', function() { describe('deleteTag', function() { describe('with a valid tag_id', function() { it('should call remove in mongo', function(done) { - this.TagMock.expects('remove') + this.TagMock.expects('deleteOne') .once() .withArgs({ _id: this.tagId, user_id: this.userId }) .yields() @@ -238,7 +237,7 @@ describe('TagsHandler', function() { describe('with a valid tag_id', function() { it('should call remove in mongo', function(done) { this.newName = 'new name' - this.TagMock.expects('update') + this.TagMock.expects('updateOne') .once() .withArgs( { _id: this.tagId, user_id: this.userId }, diff --git a/services/web/test/unit/src/Templates/TemplatesManagerTests.js b/services/web/test/unit/src/Templates/TemplatesManagerTests.js index 57053eaf47..2373d2398c 100644 --- a/services/web/test/unit/src/Templates/TemplatesManagerTests.js +++ b/services/web/test/unit/src/Templates/TemplatesManagerTests.js @@ -62,7 +62,7 @@ describe('TemplatesManager', function() { getProjectDescription: sinon.stub(), fixProjectName: sinon.stub().returns(this.templateName) } - this.Project = { update: sinon.stub().callsArgWith(3, null) } + this.Project = { updateOne: sinon.stub().callsArgWith(3, null) } this.FileWriter = { ensureDumpFolderExists: sinon.stub().callsArg(0) } this.TemplatesManager = SandboxedModule.require(modulePath, { globals: { @@ -174,7 +174,7 @@ describe('TemplatesManager', function() { }) it('should update project', function() { - return this.Project.update.should.have.been.calledWithMatch( + return this.Project.updateOne.should.have.been.calledWithMatch( { _id: this.project_id }, { fromV1TemplateId: this.templateId, diff --git a/services/web/test/unit/src/TokenAccess/TokenAccessHandlerTests.js b/services/web/test/unit/src/TokenAccess/TokenAccessHandlerTests.js index d17ed0e0ad..ae6a8840ea 100644 --- a/services/web/test/unit/src/TokenAccess/TokenAccessHandlerTests.js +++ b/services/web/test/unit/src/TokenAccess/TokenAccessHandlerTests.js @@ -123,22 +123,22 @@ describe('TokenAccessHandler', function() { describe('addReadOnlyUserToProject', function() { beforeEach(function() { - return (this.Project.update = sinon.stub().callsArgWith(2, null)) + return (this.Project.updateOne = sinon.stub().callsArgWith(2, null)) }) - it('should call Project.update', function(done) { + it('should call Project.updateOne', function(done) { return this.TokenAccessHandler.addReadOnlyUserToProject( this.userId, this.projectId, err => { - expect(this.Project.update.callCount).to.equal(1) + expect(this.Project.updateOne.callCount).to.equal(1) expect( - this.Project.update.calledWith({ + this.Project.updateOne.calledWith({ _id: this.projectId }) ).to.equal(true) expect( - this.Project.update.lastCall.args[1]['$addToSet'] + this.Project.updateOne.lastCall.args[1].$addToSet ).to.have.keys('tokenAccessReadOnly_refs') return done() } @@ -156,9 +156,9 @@ describe('TokenAccessHandler', function() { ) }) - describe('when Project.update produces an error', function() { + describe('when Project.updateOne produces an error', function() { beforeEach(function() { - return (this.Project.update = sinon + return (this.Project.updateOne = sinon .stub() .callsArgWith(2, new Error('woops'))) }) @@ -178,22 +178,22 @@ describe('TokenAccessHandler', function() { describe('addReadAndWriteUserToProject', function() { beforeEach(function() { - return (this.Project.update = sinon.stub().callsArgWith(2, null)) + return (this.Project.updateOne = sinon.stub().callsArgWith(2, null)) }) - it('should call Project.update', function(done) { + it('should call Project.updateOne', function(done) { return this.TokenAccessHandler.addReadAndWriteUserToProject( this.userId, this.projectId, err => { - expect(this.Project.update.callCount).to.equal(1) + expect(this.Project.updateOne.callCount).to.equal(1) expect( - this.Project.update.calledWith({ + this.Project.updateOne.calledWith({ _id: this.projectId }) ).to.equal(true) expect( - this.Project.update.lastCall.args[1]['$addToSet'] + this.Project.updateOne.lastCall.args[1].$addToSet ).to.have.keys('tokenAccessReadAndWrite_refs') return done() } @@ -211,9 +211,9 @@ describe('TokenAccessHandler', function() { ) }) - describe('when Project.update produces an error', function() { + describe('when Project.updateOne produces an error', function() { beforeEach(function() { - return (this.Project.update = sinon + return (this.Project.updateOne = sinon .stub() .callsArgWith(2, new Error('woops'))) }) diff --git a/services/web/test/unit/src/User/SAMLIdentityManagerTests.js b/services/web/test/unit/src/User/SAMLIdentityManagerTests.js index ce3757f04e..aa13f2d789 100644 --- a/services/web/test/unit/src/User/SAMLIdentityManagerTests.js +++ b/services/web/test/unit/src/User/SAMLIdentityManagerTests.js @@ -78,7 +78,7 @@ describe('SAMLIdentityManager', function() { findOne: sinon.stub().returns({ exec: sinon.stub().resolves() }), - update: sinon.stub().returns({ + updateOne: sinon.stub().returns({ exec: sinon.stub().resolves() }) }) @@ -226,7 +226,7 @@ describe('SAMLIdentityManager', function() { expect(error).to.exist expect(error).to.equal(anError) expect(this.EmailHandler.sendEmail).to.not.have.been.called - expect(this.User.update).to.not.have.been.called + expect(this.User.updateOne).to.not.have.been.called } }) }) @@ -275,7 +275,7 @@ describe('SAMLIdentityManager', function() { ipAddress: '0:0:0:0' }, () => { - expect(this.User.update).to.have.been.called + expect(this.User.updateOne).to.have.been.called expect(this.EmailHandler.sendEmail).to.have.been.calledOnce const emailArgs = this.EmailHandler.sendEmail.lastCall.args expect(emailArgs[0]).to.equal('securityAlert') @@ -332,7 +332,7 @@ describe('SAMLIdentityManager', function() { } } } - expect(this.User.update).to.have.been.calledOnce.and.calledWithMatch( + expect(this.User.updateOne).to.have.been.calledOnce.and.calledWithMatch( query, update ) @@ -346,7 +346,7 @@ describe('SAMLIdentityManager', function() { 'Overleaf University', this.auditLog ) - expect(this.User.update).to.have.been.called + expect(this.User.updateOne).to.have.been.called expect(this.EmailHandler.sendEmail).to.have.been.calledOnce const emailArgs = this.EmailHandler.sendEmail.lastCall.args expect(emailArgs[0]).to.equal('securityAlert') @@ -376,7 +376,7 @@ describe('SAMLIdentityManager', function() { expect(error).to.exist expect(error).to.equal(anError) expect(this.EmailHandler.sendEmail).to.not.have.been.called - expect(this.User.update).to.not.have.been.called + expect(this.User.updateOne).to.not.have.been.called } }) }) diff --git a/services/web/test/unit/src/User/UserDeleterTests.js b/services/web/test/unit/src/User/UserDeleterTests.js index fbaa3c38a2..69eca4b2e2 100644 --- a/services/web/test/unit/src/User/UserDeleterTests.js +++ b/services/web/test/unit/src/User/UserDeleterTests.js @@ -147,7 +147,7 @@ describe('UserDeleter', function() { describe('when no options are passed', function() { beforeEach(function() { - this.DeletedUserMock.expects('update') + this.DeletedUserMock.expects('updateOne') .withArgs( { 'deleterData.deletedUserId': this.userId }, this.deletedUser, @@ -274,7 +274,7 @@ describe('UserDeleter', function() { this.deletedUser.deleterData.deleterIpAddress = this.ipAddress this.deletedUser.deleterData.deleterId = this.deleterId - this.DeletedUserMock.expects('update') + this.DeletedUserMock.expects('updateOne') .withArgs( { 'deleterData.deletedUserId': this.userId }, this.deletedUser, diff --git a/services/web/test/unit/src/User/UserRegistrationHandlerTests.js b/services/web/test/unit/src/User/UserRegistrationHandlerTests.js index 8765beb5ea..5e28c05cad 100644 --- a/services/web/test/unit/src/User/UserRegistrationHandlerTests.js +++ b/services/web/test/unit/src/User/UserRegistrationHandlerTests.js @@ -26,7 +26,7 @@ const EmailHelper = require('../../../../app/src/Features/Helpers/EmailHelper') describe('UserRegistrationHandler', function() { beforeEach(function() { this.user = { _id: (this.user_id = '31j2lk21kjl') } - this.User = { update: sinon.stub().callsArgWith(2) } + this.User = { updateOne: sinon.stub().callsArgWith(2) } this.UserGetter = { getUserByAnyEmail: sinon.stub() } this.UserCreator = { createNewUser: sinon.stub().callsArgWith(2, null, this.user) @@ -129,7 +129,7 @@ describe('UserRegistrationHandler', function() { it('should set holding account to false', function(done) { return this.handler.registerNewUser(this.passingRequest, err => { - const update = this.User.update.args[0] + const update = this.User.updateOne.args[0] assert.deepEqual(update[0], { _id: this.user._id }) assert.deepEqual(update[1], { $set: { holdingAccount: false } }) return done() diff --git a/services/web/test/unit/src/UserMembership/UserMembershipHandlerTests.js b/services/web/test/unit/src/UserMembership/UserMembershipHandlerTests.js index 3cc8b19558..0f2787f116 100644 --- a/services/web/test/unit/src/UserMembership/UserMembershipHandlerTests.js +++ b/services/web/test/unit/src/UserMembership/UserMembershipHandlerTests.js @@ -43,13 +43,13 @@ describe('UserMembershipHandler', function() { _id: 'mock-institution-id', v1Id: 123, managerIds: [ObjectId(), ObjectId(), ObjectId()], - update: sinon.stub().yields(null) + updateOne: sinon.stub().yields(null) } this.publisher = { _id: 'mock-publisher-id', slug: 'slug', managerIds: [ObjectId(), ObjectId()], - update: sinon.stub().yields(null) + updateOne: sinon.stub().yields(null) } this.UserMembershipViewModel = { @@ -228,7 +228,7 @@ describe('UserMembershipHandler', function() { EntityConfigs.institution, this.email, (error, user) => { - assertCalledWith(this.institution.update, { + assertCalledWith(this.institution.updateOne, { $addToSet: { managerIds: this.newUser._id } }) return done() @@ -258,8 +258,8 @@ describe('UserMembershipHandler', function() { EntityConfigs.institution, this.newUser._id, (error, user) => { - const { lastCall } = this.institution.update - assertCalledWith(this.institution.update, { + const { lastCall } = this.institution.updateOne + assertCalledWith(this.institution.updateOne, { $pull: { managerIds: this.newUser._id } }) return done()