From 330868ff0cb1611a5b4a2e4115b01b0f3fab55ce Mon Sep 17 00:00:00 2001 From: andrew rumble Date: Fri, 2 Aug 2024 17:31:49 +0100 Subject: [PATCH] Handle Mongoose callback api removal in test helpers GitOrigin-RevId: 00b8128aed7727e7a1b6f8d2d92a5fbc3a7775fb --- .../src/helpers/DeletedSubscription.js | 25 +++++------ .../acceptance/src/helpers/Institution.js | 18 ++++---- .../web/test/acceptance/src/helpers/User.js | 42 ++++++++++--------- 3 files changed, 42 insertions(+), 43 deletions(-) diff --git a/services/web/test/acceptance/src/helpers/DeletedSubscription.js b/services/web/test/acceptance/src/helpers/DeletedSubscription.js index 6ce678f677..1e60083689 100644 --- a/services/web/test/acceptance/src/helpers/DeletedSubscription.js +++ b/services/web/test/acceptance/src/helpers/DeletedSubscription.js @@ -21,16 +21,13 @@ class DeletedSubscription { } expectRestored(callback) { - DeletedSubscriptionModel.findOne( - { 'subscription._id': this.subscription._id }, - (error, deletedSubscription) => { - if (error) { - return callback(error) - } + DeletedSubscriptionModel.findOne({ + 'subscription._id': this.subscription._id, + }) + .then(deletedSubscription => { expect(deletedSubscription).to.be.null - SubscriptionModel.findById( - this.subscription._id, - (error, subscription) => { + SubscriptionModel.findById(this.subscription._id) + .then(subscription => { expect(subscription).to.exist expect(subscription._id.toString()).to.equal( this.subscription._id.toString() @@ -38,11 +35,11 @@ class DeletedSubscription { expect(subscription.admin_id.toString()).to.equal( this.subscription.admin_id.toString() ) - callback(error) - } - ) - } - ) + callback() + }) + .catch(callback) + }) + .catch(callback) } } diff --git a/services/web/test/acceptance/src/helpers/Institution.js b/services/web/test/acceptance/src/helpers/Institution.js index 3f15193769..23951a0624 100644 --- a/services/web/test/acceptance/src/helpers/Institution.js +++ b/services/web/test/acceptance/src/helpers/Institution.js @@ -15,23 +15,21 @@ class Institution { ensureExists(callback) { const filter = { v1Id: this.v1Id } const options = { upsert: true, new: true, setDefaultsOnInsert: true } - InstitutionModel.findOneAndUpdate( - filter, - {}, - options, - (error, institution) => { + InstitutionModel.findOneAndUpdate(filter, {}, options) + .then(institution => { this._id = institution._id - callback(error) - } - ) + callback() + }) + .catch(callback) } setManagerIds(managerIds, callback) { return InstitutionModel.findOneAndUpdate( { _id: new ObjectId(this._id) }, - { managerIds }, - callback + { managerIds } ) + .then((...args) => callback(null, ...args)) + .catch(callback) } } diff --git a/services/web/test/acceptance/src/helpers/User.js b/services/web/test/acceptance/src/helpers/User.js index f4d0cd0b8d..2cedfb060a 100644 --- a/services/web/test/acceptance/src/helpers/User.js +++ b/services/web/test/acceptance/src/helpers/User.js @@ -423,16 +423,13 @@ class User { UserModel.findOneAndUpdate( filter, { $set: { hashedPassword, emails: this.emails } }, - options, - (error, user) => { - if (error != null) { - return callback(error) - } - + options + ) + .then(user => { this.setExtraAttributes(user) callback(null, this.password) - } - ) + }) + .catch(callback) } ) } @@ -443,28 +440,34 @@ class User { const value = features[key] update[`features.${key}`] = value } - UserModel.updateOne({ _id: this.id }, update, callback) + UserModel.updateOne({ _id: this.id }, update) + .then((...args) => callback(null, ...args)) + .catch(callback) } setFeaturesOverride(featuresOverride, callback) { const update = { $push: { featuresOverrides: featuresOverride } } - UserModel.updateOne({ _id: this.id }, update, callback) + UserModel.updateOne({ _id: this.id }, update) + .then((...args) => callback(null, ...args)) + .catch(callback) } setOverleafId(overleafId, callback) { - UserModel.updateOne( - { _id: this.id }, - { 'overleaf.id': overleafId }, - callback - ) + UserModel.updateOne({ _id: this.id }, { 'overleaf.id': overleafId }) + .then((...args) => callback(null, ...args)) + .catch(callback) } setEmails(emails, callback) { - UserModel.updateOne({ _id: this.id }, { emails }, callback) + UserModel.updateOne({ _id: this.id }, { emails }) + .then((...args) => callback(null, ...args)) + .catch(callback) } setSuspended(suspended, callback) { - UserModel.updateOne({ _id: this.id }, { suspended }, callback) + UserModel.updateOne({ _id: this.id }, { suspended }) + .then((...args) => callback(null, ...args)) + .catch(callback) } logout(callback) { @@ -1215,9 +1218,10 @@ class User { overleaf: { id: v1Id, }, - }, - callback + } ) + .then((...args) => callback(null, ...args)) + .catch(callback) } setCollaboratorInfo(projectId, userId, info, callback) {