Просмотр исходного кода

Handle Mongoose callback api removal in test helpers

GitOrigin-RevId: 00b8128aed7727e7a1b6f8d2d92a5fbc3a7775fb
andrew rumble 2 лет назад
Родитель
Сommit
330868ff0c

+ 11 - 14
services/web/test/acceptance/src/helpers/DeletedSubscription.js

@@ -21,16 +21,13 @@ class DeletedSubscription {
   }
   }
 
 
   expectRestored(callback) {
   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
         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).to.exist
             expect(subscription._id.toString()).to.equal(
             expect(subscription._id.toString()).to.equal(
               this.subscription._id.toString()
               this.subscription._id.toString()
@@ -38,11 +35,11 @@ class DeletedSubscription {
             expect(subscription.admin_id.toString()).to.equal(
             expect(subscription.admin_id.toString()).to.equal(
               this.subscription.admin_id.toString()
               this.subscription.admin_id.toString()
             )
             )
-            callback(error)
-          }
-        )
-      }
-    )
+            callback()
+          })
+          .catch(callback)
+      })
+      .catch(callback)
   }
   }
 }
 }
 
 

+ 8 - 10
services/web/test/acceptance/src/helpers/Institution.js

@@ -15,23 +15,21 @@ class Institution {
   ensureExists(callback) {
   ensureExists(callback) {
     const filter = { v1Id: this.v1Id }
     const filter = { v1Id: this.v1Id }
     const options = { upsert: true, new: true, setDefaultsOnInsert: true }
     const options = { upsert: true, new: true, setDefaultsOnInsert: true }
-    InstitutionModel.findOneAndUpdate(
-      filter,
-      {},
-      options,
-      (error, institution) => {
+    InstitutionModel.findOneAndUpdate(filter, {}, options)
+      .then(institution => {
         this._id = institution._id
         this._id = institution._id
-        callback(error)
-      }
-    )
+        callback()
+      })
+      .catch(callback)
   }
   }
 
 
   setManagerIds(managerIds, callback) {
   setManagerIds(managerIds, callback) {
     return InstitutionModel.findOneAndUpdate(
     return InstitutionModel.findOneAndUpdate(
       { _id: new ObjectId(this._id) },
       { _id: new ObjectId(this._id) },
-      { managerIds },
-      callback
+      { managerIds }
     )
     )
+      .then((...args) => callback(null, ...args))
+      .catch(callback)
   }
   }
 }
 }
 
 

+ 23 - 19
services/web/test/acceptance/src/helpers/User.js

@@ -423,16 +423,13 @@ class User {
         UserModel.findOneAndUpdate(
         UserModel.findOneAndUpdate(
           filter,
           filter,
           { $set: { hashedPassword, emails: this.emails } },
           { $set: { hashedPassword, emails: this.emails } },
-          options,
-          (error, user) => {
-            if (error != null) {
-              return callback(error)
-            }
-
+          options
+        )
+          .then(user => {
             this.setExtraAttributes(user)
             this.setExtraAttributes(user)
             callback(null, this.password)
             callback(null, this.password)
-          }
-        )
+          })
+          .catch(callback)
       }
       }
     )
     )
   }
   }
@@ -443,28 +440,34 @@ class User {
       const value = features[key]
       const value = features[key]
       update[`features.${key}`] = value
       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) {
   setFeaturesOverride(featuresOverride, callback) {
     const update = { $push: { featuresOverrides: featuresOverride } }
     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) {
   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) {
   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) {
   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) {
   logout(callback) {
@@ -1215,9 +1218,10 @@ class User {
         overleaf: {
         overleaf: {
           id: v1Id,
           id: v1Id,
         },
         },
-      },
-      callback
+      }
     )
     )
+      .then((...args) => callback(null, ...args))
+      .catch(callback)
   }
   }
 
 
   setCollaboratorInfo(projectId, userId, info, callback) {
   setCollaboratorInfo(projectId, userId, info, callback) {