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

Merge pull request #22003 from overleaf/ar-handle-v1-outage-gracefully

[web] handle v1 outage gracefully

GitOrigin-RevId: 54f9800abf13846a39512224b898de6939be1d3a
Andrew Rumble 1 год назад
Родитель
Сommit
d97555a380

+ 3 - 3
services/web/test/acceptance/src/UserMembershipAuthorizationTests.mjs

@@ -1,7 +1,7 @@
 import { expect } from 'chai'
 import async from 'async'
 import User from './helpers/User.js'
-import Institution from './helpers/Institution.js'
+import Institution from './helpers/Institution.mjs'
 import Subscription from './helpers/Subscription.js'
 import Publisher from './helpers/Publisher.js'
 
@@ -55,9 +55,9 @@ describe('UserMembershipAuthorization', function () {
   })
 
   describe('institution', function () {
-    beforeEach(function (done) {
+    beforeEach(async function () {
       this.institution = new Institution()
-      async.series([this.institution.ensureExists.bind(this.institution)], done)
+      await this.institution.ensureExists(this.institution)
     })
 
     describe('users management', function () {

+ 12 - 11
services/web/test/acceptance/src/helpers/Institution.js → services/web/test/acceptance/src/helpers/Institution.mjs

@@ -1,6 +1,7 @@
-const { ObjectId } = require('mongodb-legacy')
-const InstitutionModel =
-  require('../../../../app/src/models/Institution').Institution
+import mongodb from 'mongodb-legacy'
+import { Institution as InstitutionModel } from '../../../../app/src/models/Institution.js'
+
+const { ObjectId } = mongodb
 
 let count = parseInt(Math.random() * 999999)
 
@@ -12,15 +13,15 @@ class Institution {
     count += 1
   }
 
-  ensureExists(callback) {
+  async ensureExists() {
     const filter = { v1Id: this.v1Id }
     const options = { upsert: true, new: true, setDefaultsOnInsert: true }
-    InstitutionModel.findOneAndUpdate(filter, {}, options)
-      .then(institution => {
-        this._id = institution._id
-        callback()
-      })
-      .catch(callback)
+    const institution = await InstitutionModel.findOneAndUpdate(
+      filter,
+      {},
+      options
+    )
+    this._id = institution._id
   }
 
   setManagerIds(managerIds, callback) {
@@ -33,4 +34,4 @@ class Institution {
   }
 }
 
-module.exports = Institution
+export default Institution