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

[web] handle v1 outage gracefully

GitOrigin-RevId: 54f9800abf13846a39512224b898de6939be1d3a
This commit is contained in:
Andrew Rumble
2024-11-29 09:05:07 +00:00
committed by Copybot
parent 9e1ac94ebf
commit d97555a380
2 changed files with 15 additions and 14 deletions
@@ -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 () {
@@ -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