mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-26 18:51:50 +02:00
[web] Promisify ensureAffiliationMiddleware and refactor InstitutionHubsController (#22242 feedback) (#22261)
* Promisify `ensureAffiliationMiddleware` * In `ensureAffiliationMiddleware`, throw when UserNotFoundError * Unnest object `_InstitutionHubsController` * Format fix GitOrigin-RevId: 5b3c6c24724520353540b8d8dd05005b6fa749ff
This commit is contained in:
@@ -202,7 +202,7 @@ async function ensureAffiliationMiddleware(req, res, next) {
|
||||
try {
|
||||
user = await UserGetter.promises.getUser(userId)
|
||||
} catch (error) {
|
||||
return new Errors.UserNotFoundError({ info: { userId } })
|
||||
throw new Errors.UserNotFoundError({ info: { userId } })
|
||||
}
|
||||
// if the user does not have permission to add an affiliation, we skip this middleware
|
||||
try {
|
||||
|
||||
@@ -1106,5 +1106,22 @@ describe('UserController', function () {
|
||||
expect(this.next).to.be.calledWith(sinon.match.instanceOf(Error))
|
||||
})
|
||||
})
|
||||
|
||||
describe('when user is not found', function () {
|
||||
beforeEach(async function () {
|
||||
this.UserGetter.promises.getUser.rejects(new Error('not found'))
|
||||
this.Features.hasFeature.withArgs('affiliations').returns(true)
|
||||
this.req.query.ensureAffiliation = true
|
||||
await this.UserController.ensureAffiliationMiddleware(
|
||||
this.req,
|
||||
this.res,
|
||||
this.next
|
||||
)
|
||||
})
|
||||
|
||||
it('should return the error', function () {
|
||||
expect(this.next).to.be.calledWith(sinon.match.instanceOf(Error))
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user