From 2687dc3b09c998c38d1a39e492c04eb2652b9c2f Mon Sep 17 00:00:00 2001 From: Andrew Rumble Date: Thu, 28 Nov 2024 13:57:03 +0000 Subject: [PATCH] Merge pull request #22003 from overleaf/ar-handle-v1-outage-gracefully [web] handle v1 outage gracefully GitOrigin-RevId: 54f9800abf13846a39512224b898de6939be1d3a --- .../src/UserMembershipAuthorizationTests.mjs | 6 ++--- .../{Institution.js => Institution.mjs} | 23 ++++++++++--------- 2 files changed, 15 insertions(+), 14 deletions(-) rename services/web/test/acceptance/src/helpers/{Institution.js => Institution.mjs} (59%) diff --git a/services/web/test/acceptance/src/UserMembershipAuthorizationTests.mjs b/services/web/test/acceptance/src/UserMembershipAuthorizationTests.mjs index 5b9428dea4..3622b570e6 100644 --- a/services/web/test/acceptance/src/UserMembershipAuthorizationTests.mjs +++ b/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 () { diff --git a/services/web/test/acceptance/src/helpers/Institution.js b/services/web/test/acceptance/src/helpers/Institution.mjs similarity index 59% rename from services/web/test/acceptance/src/helpers/Institution.js rename to services/web/test/acceptance/src/helpers/Institution.mjs index 23951a0624..eb2bd0b274 100644 --- a/services/web/test/acceptance/src/helpers/Institution.js +++ b/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