mirror of
https://github.com/overleaf/overleaf.git
synced 2024-09-16 02:52:31 -04:00
Return the Promise from an expressified async function (#19359)
* Return the Promise from an expressified async function GitOrigin-RevId: ca4c221a92de888e210e995faad97d0ea241e93f
This commit is contained in:
parent
bcef7ea125
commit
136214f37a
3 changed files with 37 additions and 71 deletions
|
@ -234,7 +234,7 @@ function callbackifyMultiResult(fn, resultNames) {
|
||||||
*/
|
*/
|
||||||
function expressify(fn) {
|
function expressify(fn) {
|
||||||
return (req, res, next) => {
|
return (req, res, next) => {
|
||||||
fn(req, res, next).catch(next)
|
return fn(req, res, next).catch(next)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,6 +68,8 @@ describe('LaunchpadController', function () {
|
||||||
return key
|
return key
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.next = sinon.stub()
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('launchpadPage', function () {
|
describe('launchpadPage', function () {
|
||||||
|
@ -89,10 +91,8 @@ describe('LaunchpadController', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('when there are no admins', function () {
|
describe('when there are no admins', function () {
|
||||||
beforeEach(function (done) {
|
beforeEach(function () {
|
||||||
this._atLeastOneAdminExists.resolves(false)
|
this._atLeastOneAdminExists.resolves(false)
|
||||||
this.res.callback = done
|
|
||||||
this.next = sinon.stub().callsFake(() => done())
|
|
||||||
return this.LaunchpadController.launchpadPage(
|
return this.LaunchpadController.launchpadPage(
|
||||||
this.req,
|
this.req,
|
||||||
this.res,
|
this.res,
|
||||||
|
@ -116,10 +116,8 @@ describe('LaunchpadController', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('when there is at least one admin', function () {
|
describe('when there is at least one admin', function () {
|
||||||
beforeEach(function (done) {
|
beforeEach(function () {
|
||||||
this._atLeastOneAdminExists.resolves(true)
|
this._atLeastOneAdminExists.resolves(true)
|
||||||
this.res.callback = done
|
|
||||||
this.next = sinon.stub().callsFake(() => done())
|
|
||||||
return this.LaunchpadController.launchpadPage(
|
return this.LaunchpadController.launchpadPage(
|
||||||
this.req,
|
this.req,
|
||||||
this.res,
|
this.res,
|
||||||
|
@ -151,12 +149,10 @@ describe('LaunchpadController', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('when the user is an admin', function () {
|
describe('when the user is an admin', function () {
|
||||||
beforeEach(function (done) {
|
beforeEach(function () {
|
||||||
this.UserGetter.promises.getUser = sinon
|
this.UserGetter.promises.getUser = sinon
|
||||||
.stub()
|
.stub()
|
||||||
.resolves({ isAdmin: true })
|
.resolves({ isAdmin: true })
|
||||||
this.res.callback = done
|
|
||||||
this.next = sinon.stub().callsFake(() => done())
|
|
||||||
return this.LaunchpadController.launchpadPage(
|
return this.LaunchpadController.launchpadPage(
|
||||||
this.req,
|
this.req,
|
||||||
this.res,
|
this.res,
|
||||||
|
@ -170,7 +166,7 @@ describe('LaunchpadController', function () {
|
||||||
'../../../app/views/launchpad'
|
'../../../app/views/launchpad'
|
||||||
)
|
)
|
||||||
this.res.render.callCount.should.equal(1)
|
this.res.render.callCount.should.equal(1)
|
||||||
return this.res.render
|
this.res.render
|
||||||
.calledWith(viewPath, {
|
.calledWith(viewPath, {
|
||||||
wsUrl: undefined,
|
wsUrl: undefined,
|
||||||
adminUserExists: true,
|
adminUserExists: true,
|
||||||
|
@ -181,12 +177,10 @@ describe('LaunchpadController', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('when the user is not an admin', function () {
|
describe('when the user is not an admin', function () {
|
||||||
beforeEach(function (done) {
|
beforeEach(function () {
|
||||||
this.UserGetter.promises.getUser = sinon
|
this.UserGetter.promises.getUser = sinon
|
||||||
.stub()
|
.stub()
|
||||||
.resolves({ isAdmin: false })
|
.resolves({ isAdmin: false })
|
||||||
this.res.callback = done
|
|
||||||
this.next = sinon.stub().callsFake(() => done())
|
|
||||||
return this.LaunchpadController.launchpadPage(
|
return this.LaunchpadController.launchpadPage(
|
||||||
this.req,
|
this.req,
|
||||||
this.res,
|
this.res,
|
||||||
|
@ -244,15 +238,15 @@ describe('LaunchpadController', function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
this.EmailHandler.promises.sendEmail = sinon.stub().resolves()
|
this.EmailHandler.promises.sendEmail = sinon.stub().resolves()
|
||||||
this.req.body.email = 'someone@example.com'
|
this.req.body.email = 'someone@example.com'
|
||||||
return (this.next = sinon.stub())
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should produce a 200 response', function (done) {
|
it('should produce a 200 response', async function () {
|
||||||
this.res.callback = () => {
|
await this.LaunchpadController.sendTestEmail(
|
||||||
|
this.req,
|
||||||
|
this.res,
|
||||||
|
this.next
|
||||||
|
)
|
||||||
this.res.json.calledWith({ message: 'email_sent' }).should.equal(true)
|
this.res.json.calledWith({ message: 'email_sent' }).should.equal(true)
|
||||||
done()
|
|
||||||
}
|
|
||||||
this.LaunchpadController.sendTestEmail(this.req, this.res, this.next)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should not call next with an error', function () {
|
it('should not call next with an error', function () {
|
||||||
|
@ -260,8 +254,12 @@ describe('LaunchpadController', function () {
|
||||||
return this.next.callCount.should.equal(0)
|
return this.next.callCount.should.equal(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should have called sendEmail', function () {
|
it('should have called sendEmail', async function () {
|
||||||
this.LaunchpadController.sendTestEmail(this.req, this.res, this.next)
|
await this.LaunchpadController.sendTestEmail(
|
||||||
|
this.req,
|
||||||
|
this.res,
|
||||||
|
this.next
|
||||||
|
)
|
||||||
this.EmailHandler.promises.sendEmail.callCount.should.equal(1)
|
this.EmailHandler.promises.sendEmail.callCount.should.equal(1)
|
||||||
return this.EmailHandler.promises.sendEmail
|
return this.EmailHandler.promises.sendEmail
|
||||||
.calledWith('testEmail')
|
.calledWith('testEmail')
|
||||||
|
@ -315,7 +313,7 @@ describe('LaunchpadController', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('when all goes well', function () {
|
describe('when all goes well', function () {
|
||||||
beforeEach(function (done) {
|
beforeEach(function () {
|
||||||
this._atLeastOneAdminExists.resolves(false)
|
this._atLeastOneAdminExists.resolves(false)
|
||||||
this.email = 'someone@example.com'
|
this.email = 'someone@example.com'
|
||||||
this.password = 'a_really_bad_password'
|
this.password = 'a_really_bad_password'
|
||||||
|
@ -334,8 +332,6 @@ describe('LaunchpadController', function () {
|
||||||
this.AuthenticationController.setRedirectInSession = sinon.stub()
|
this.AuthenticationController.setRedirectInSession = sinon.stub()
|
||||||
this.AuthenticationManager.validateEmail = sinon.stub().returns(null)
|
this.AuthenticationManager.validateEmail = sinon.stub().returns(null)
|
||||||
this.AuthenticationManager.validatePassword = sinon.stub().returns(null)
|
this.AuthenticationManager.validatePassword = sinon.stub().returns(null)
|
||||||
this.next = sinon.stub().callsFake(() => done())
|
|
||||||
this.res.callback = done
|
|
||||||
return this.LaunchpadController.registerAdmin(
|
return this.LaunchpadController.registerAdmin(
|
||||||
this.req,
|
this.req,
|
||||||
this.res,
|
this.res,
|
||||||
|
@ -391,7 +387,6 @@ describe('LaunchpadController', function () {
|
||||||
this.UserRegistrationHandler.promises.registerNewUser = sinon.stub()
|
this.UserRegistrationHandler.promises.registerNewUser = sinon.stub()
|
||||||
this.User.updateOne = sinon.stub().returns({ exec: sinon.stub() })
|
this.User.updateOne = sinon.stub().returns({ exec: sinon.stub() })
|
||||||
this.AuthenticationController.setRedirectInSession = sinon.stub()
|
this.AuthenticationController.setRedirectInSession = sinon.stub()
|
||||||
this.next = sinon.stub()
|
|
||||||
return this.LaunchpadController.registerAdmin(
|
return this.LaunchpadController.registerAdmin(
|
||||||
this.req,
|
this.req,
|
||||||
this.res,
|
this.res,
|
||||||
|
@ -429,7 +424,6 @@ describe('LaunchpadController', function () {
|
||||||
this.UserRegistrationHandler.promises.registerNewUser = sinon.stub()
|
this.UserRegistrationHandler.promises.registerNewUser = sinon.stub()
|
||||||
this.User.updateOne = sinon.stub().returns({ exec: sinon.stub() })
|
this.User.updateOne = sinon.stub().returns({ exec: sinon.stub() })
|
||||||
this.AuthenticationController.setRedirectInSession = sinon.stub()
|
this.AuthenticationController.setRedirectInSession = sinon.stub()
|
||||||
this.next = sinon.stub()
|
|
||||||
return this.LaunchpadController.registerAdmin(
|
return this.LaunchpadController.registerAdmin(
|
||||||
this.req,
|
this.req,
|
||||||
this.res,
|
this.res,
|
||||||
|
@ -454,7 +448,7 @@ describe('LaunchpadController', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('when an invalid email is supplied', function () {
|
describe('when an invalid email is supplied', function () {
|
||||||
beforeEach(function (done) {
|
beforeEach(function () {
|
||||||
this._atLeastOneAdminExists.resolves(false)
|
this._atLeastOneAdminExists.resolves(false)
|
||||||
this.email = 'someone@example.com'
|
this.email = 'someone@example.com'
|
||||||
this.password = 'invalid password'
|
this.password = 'invalid password'
|
||||||
|
@ -471,8 +465,6 @@ describe('LaunchpadController', function () {
|
||||||
.stub()
|
.stub()
|
||||||
.returns(new Error('bad email'))
|
.returns(new Error('bad email'))
|
||||||
this.AuthenticationManager.validatePassword = sinon.stub().returns(null)
|
this.AuthenticationManager.validatePassword = sinon.stub().returns(null)
|
||||||
this.res.callback = done
|
|
||||||
this.next = sinon.stub().callsFake(() => done())
|
|
||||||
return this.LaunchpadController.registerAdmin(
|
return this.LaunchpadController.registerAdmin(
|
||||||
this.req,
|
this.req,
|
||||||
this.res,
|
this.res,
|
||||||
|
@ -496,7 +488,7 @@ describe('LaunchpadController', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('when an invalid password is supplied', function () {
|
describe('when an invalid password is supplied', function () {
|
||||||
beforeEach(function (done) {
|
beforeEach(function () {
|
||||||
this._atLeastOneAdminExists.resolves(false)
|
this._atLeastOneAdminExists.resolves(false)
|
||||||
this.email = 'someone@example.com'
|
this.email = 'someone@example.com'
|
||||||
this.password = 'invalid password'
|
this.password = 'invalid password'
|
||||||
|
@ -513,8 +505,6 @@ describe('LaunchpadController', function () {
|
||||||
this.AuthenticationManager.validatePassword = sinon
|
this.AuthenticationManager.validatePassword = sinon
|
||||||
.stub()
|
.stub()
|
||||||
.returns(new Error('bad password'))
|
.returns(new Error('bad password'))
|
||||||
this.res.callback = done
|
|
||||||
this.next = sinon.stub().callsFake(() => done())
|
|
||||||
return this.LaunchpadController.registerAdmin(
|
return this.LaunchpadController.registerAdmin(
|
||||||
this.req,
|
this.req,
|
||||||
this.res,
|
this.res,
|
||||||
|
@ -538,7 +528,7 @@ describe('LaunchpadController', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('when there are already existing admins', function () {
|
describe('when there are already existing admins', function () {
|
||||||
beforeEach(function (done) {
|
beforeEach(function () {
|
||||||
this._atLeastOneAdminExists.resolves(true)
|
this._atLeastOneAdminExists.resolves(true)
|
||||||
this.email = 'someone@example.com'
|
this.email = 'someone@example.com'
|
||||||
this.password = 'a_really_bad_password'
|
this.password = 'a_really_bad_password'
|
||||||
|
@ -553,8 +543,6 @@ describe('LaunchpadController', function () {
|
||||||
this.AuthenticationController.setRedirectInSession = sinon.stub()
|
this.AuthenticationController.setRedirectInSession = sinon.stub()
|
||||||
this.AuthenticationManager.validateEmail = sinon.stub().returns(null)
|
this.AuthenticationManager.validateEmail = sinon.stub().returns(null)
|
||||||
this.AuthenticationManager.validatePassword = sinon.stub().returns(null)
|
this.AuthenticationManager.validatePassword = sinon.stub().returns(null)
|
||||||
this.res.callback = done
|
|
||||||
this.next = sinon.stub().callsFake(() => done())
|
|
||||||
return this.LaunchpadController.registerAdmin(
|
return this.LaunchpadController.registerAdmin(
|
||||||
this.req,
|
this.req,
|
||||||
this.res,
|
this.res,
|
||||||
|
@ -575,7 +563,7 @@ describe('LaunchpadController', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('when checking admins produces an error', function () {
|
describe('when checking admins produces an error', function () {
|
||||||
beforeEach(function (done) {
|
beforeEach(function () {
|
||||||
this._atLeastOneAdminExists.rejects(new Error('woops'))
|
this._atLeastOneAdminExists.rejects(new Error('woops'))
|
||||||
this.email = 'someone@example.com'
|
this.email = 'someone@example.com'
|
||||||
this.password = 'a_really_bad_password'
|
this.password = 'a_really_bad_password'
|
||||||
|
@ -588,8 +576,6 @@ describe('LaunchpadController', function () {
|
||||||
this.UserRegistrationHandler.promises.registerNewUser = sinon.stub()
|
this.UserRegistrationHandler.promises.registerNewUser = sinon.stub()
|
||||||
this.User.updateOne = sinon.stub().returns({ exec: sinon.stub() })
|
this.User.updateOne = sinon.stub().returns({ exec: sinon.stub() })
|
||||||
this.AuthenticationController.setRedirectInSession = sinon.stub()
|
this.AuthenticationController.setRedirectInSession = sinon.stub()
|
||||||
this.res.callback = done
|
|
||||||
this.next = sinon.stub().callsFake(() => done())
|
|
||||||
return this.LaunchpadController.registerAdmin(
|
return this.LaunchpadController.registerAdmin(
|
||||||
this.req,
|
this.req,
|
||||||
this.res,
|
this.res,
|
||||||
|
@ -614,7 +600,7 @@ describe('LaunchpadController', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('when registerNewUser produces an error', function () {
|
describe('when registerNewUser produces an error', function () {
|
||||||
beforeEach(function (done) {
|
beforeEach(function () {
|
||||||
this._atLeastOneAdminExists.resolves(false)
|
this._atLeastOneAdminExists.resolves(false)
|
||||||
this.email = 'someone@example.com'
|
this.email = 'someone@example.com'
|
||||||
this.password = 'a_really_bad_password'
|
this.password = 'a_really_bad_password'
|
||||||
|
@ -631,8 +617,6 @@ describe('LaunchpadController', function () {
|
||||||
this.AuthenticationController.setRedirectInSession = sinon.stub()
|
this.AuthenticationController.setRedirectInSession = sinon.stub()
|
||||||
this.AuthenticationManager.validateEmail = sinon.stub().returns(null)
|
this.AuthenticationManager.validateEmail = sinon.stub().returns(null)
|
||||||
this.AuthenticationManager.validatePassword = sinon.stub().returns(null)
|
this.AuthenticationManager.validatePassword = sinon.stub().returns(null)
|
||||||
this.res.callback = done
|
|
||||||
this.next = sinon.stub().callsFake(() => done())
|
|
||||||
return this.LaunchpadController.registerAdmin(
|
return this.LaunchpadController.registerAdmin(
|
||||||
this.req,
|
this.req,
|
||||||
this.res,
|
this.res,
|
||||||
|
@ -664,7 +648,7 @@ describe('LaunchpadController', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('when user update produces an error', function () {
|
describe('when user update produces an error', function () {
|
||||||
beforeEach(function (done) {
|
beforeEach(function () {
|
||||||
this._atLeastOneAdminExists.resolves(false)
|
this._atLeastOneAdminExists.resolves(false)
|
||||||
this.email = 'someone@example.com'
|
this.email = 'someone@example.com'
|
||||||
this.password = 'a_really_bad_password'
|
this.password = 'a_really_bad_password'
|
||||||
|
@ -683,8 +667,6 @@ describe('LaunchpadController', function () {
|
||||||
this.AuthenticationController.setRedirectInSession = sinon.stub()
|
this.AuthenticationController.setRedirectInSession = sinon.stub()
|
||||||
this.AuthenticationManager.validateEmail = sinon.stub().returns(null)
|
this.AuthenticationManager.validateEmail = sinon.stub().returns(null)
|
||||||
this.AuthenticationManager.validatePassword = sinon.stub().returns(null)
|
this.AuthenticationManager.validatePassword = sinon.stub().returns(null)
|
||||||
this.res.callback = done
|
|
||||||
this.next = sinon.stub().callsFake(() => done())
|
|
||||||
return this.LaunchpadController.registerAdmin(
|
return this.LaunchpadController.registerAdmin(
|
||||||
this.req,
|
this.req,
|
||||||
this.res,
|
this.res,
|
||||||
|
@ -712,7 +694,7 @@ describe('LaunchpadController', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('when overleaf', function () {
|
describe('when overleaf', function () {
|
||||||
beforeEach(function (done) {
|
beforeEach(function () {
|
||||||
this.Settings.overleaf = { one: 1 }
|
this.Settings.overleaf = { one: 1 }
|
||||||
this.Settings.createV1AccountOnLogin = true
|
this.Settings.createV1AccountOnLogin = true
|
||||||
this._atLeastOneAdminExists.resolves(false)
|
this._atLeastOneAdminExists.resolves(false)
|
||||||
|
@ -736,8 +718,6 @@ describe('LaunchpadController', function () {
|
||||||
this.UserGetter.promises.getUser = sinon
|
this.UserGetter.promises.getUser = sinon
|
||||||
.stub()
|
.stub()
|
||||||
.resolves({ _id: '1234' })
|
.resolves({ _id: '1234' })
|
||||||
this.next = sinon.stub().callsFake(() => done())
|
|
||||||
this.res.callback = done
|
|
||||||
return this.LaunchpadController.registerAdmin(
|
return this.LaunchpadController.registerAdmin(
|
||||||
this.req,
|
this.req,
|
||||||
this.res,
|
this.res,
|
||||||
|
@ -793,7 +773,7 @@ describe('LaunchpadController', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('when all goes well', function () {
|
describe('when all goes well', function () {
|
||||||
beforeEach(function (done) {
|
beforeEach(function () {
|
||||||
this._atLeastOneAdminExists.resolves(false)
|
this._atLeastOneAdminExists.resolves(false)
|
||||||
this.email = 'someone@example.com'
|
this.email = 'someone@example.com'
|
||||||
this.req.body.email = this.email
|
this.req.body.email = this.email
|
||||||
|
@ -808,8 +788,6 @@ describe('LaunchpadController', function () {
|
||||||
.stub()
|
.stub()
|
||||||
.returns({ exec: sinon.stub().resolves() })
|
.returns({ exec: sinon.stub().resolves() })
|
||||||
this.AuthenticationController.setRedirectInSession = sinon.stub()
|
this.AuthenticationController.setRedirectInSession = sinon.stub()
|
||||||
this.res.callback = done
|
|
||||||
this.next = sinon.stub().callsFake(() => done())
|
|
||||||
return this.LaunchpadController.registerExternalAuthAdmin('ldap')(
|
return this.LaunchpadController.registerExternalAuthAdmin('ldap')(
|
||||||
this.req,
|
this.req,
|
||||||
this.res,
|
this.res,
|
||||||
|
@ -875,7 +853,6 @@ describe('LaunchpadController', function () {
|
||||||
this.UserRegistrationHandler.promises.registerNewUser = sinon.stub()
|
this.UserRegistrationHandler.promises.registerNewUser = sinon.stub()
|
||||||
this.User.updateOne = sinon.stub().returns({ exec: sinon.stub() })
|
this.User.updateOne = sinon.stub().returns({ exec: sinon.stub() })
|
||||||
this.AuthenticationController.setRedirectInSession = sinon.stub()
|
this.AuthenticationController.setRedirectInSession = sinon.stub()
|
||||||
this.next = sinon.stub()
|
|
||||||
return this.LaunchpadController.registerExternalAuthAdmin(
|
return this.LaunchpadController.registerExternalAuthAdmin(
|
||||||
'NOTAVALIDAUTHMETHOD'
|
'NOTAVALIDAUTHMETHOD'
|
||||||
)(this.req, this.res, this.next)
|
)(this.req, this.res, this.next)
|
||||||
|
@ -909,7 +886,6 @@ describe('LaunchpadController', function () {
|
||||||
this.UserRegistrationHandler.promises.registerNewUser = sinon.stub()
|
this.UserRegistrationHandler.promises.registerNewUser = sinon.stub()
|
||||||
this.User.updateOne = sinon.stub().returns({ exec: sinon.stub() })
|
this.User.updateOne = sinon.stub().returns({ exec: sinon.stub() })
|
||||||
this.AuthenticationController.setRedirectInSession = sinon.stub()
|
this.AuthenticationController.setRedirectInSession = sinon.stub()
|
||||||
this.next = sinon.stub()
|
|
||||||
return this.LaunchpadController.registerExternalAuthAdmin('ldap')(
|
return this.LaunchpadController.registerExternalAuthAdmin('ldap')(
|
||||||
this.req,
|
this.req,
|
||||||
this.res,
|
this.res,
|
||||||
|
@ -934,7 +910,7 @@ describe('LaunchpadController', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('when there are already existing admins', function () {
|
describe('when there are already existing admins', function () {
|
||||||
beforeEach(function (done) {
|
beforeEach(function () {
|
||||||
this._atLeastOneAdminExists.resolves(true)
|
this._atLeastOneAdminExists.resolves(true)
|
||||||
this.email = 'someone@example.com'
|
this.email = 'someone@example.com'
|
||||||
this.req.body.email = this.email
|
this.req.body.email = this.email
|
||||||
|
@ -945,8 +921,6 @@ describe('LaunchpadController', function () {
|
||||||
this.UserRegistrationHandler.promises.registerNewUser = sinon.stub()
|
this.UserRegistrationHandler.promises.registerNewUser = sinon.stub()
|
||||||
this.User.updateOne = sinon.stub().returns({ exec: sinon.stub() })
|
this.User.updateOne = sinon.stub().returns({ exec: sinon.stub() })
|
||||||
this.AuthenticationController.setRedirectInSession = sinon.stub()
|
this.AuthenticationController.setRedirectInSession = sinon.stub()
|
||||||
this.res.callback = done
|
|
||||||
this.next = sinon.stub().callsFake(() => done())
|
|
||||||
return this.LaunchpadController.registerExternalAuthAdmin('ldap')(
|
return this.LaunchpadController.registerExternalAuthAdmin('ldap')(
|
||||||
this.req,
|
this.req,
|
||||||
this.res,
|
this.res,
|
||||||
|
@ -967,7 +941,7 @@ describe('LaunchpadController', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('when checking admins produces an error', function () {
|
describe('when checking admins produces an error', function () {
|
||||||
beforeEach(function (done) {
|
beforeEach(function () {
|
||||||
this._atLeastOneAdminExists.rejects(new Error('woops'))
|
this._atLeastOneAdminExists.rejects(new Error('woops'))
|
||||||
this.email = 'someone@example.com'
|
this.email = 'someone@example.com'
|
||||||
this.req.body.email = this.email
|
this.req.body.email = this.email
|
||||||
|
@ -978,8 +952,6 @@ describe('LaunchpadController', function () {
|
||||||
this.UserRegistrationHandler.promises.registerNewUser = sinon.stub()
|
this.UserRegistrationHandler.promises.registerNewUser = sinon.stub()
|
||||||
this.User.updateOne = sinon.stub().returns({ exec: sinon.stub() })
|
this.User.updateOne = sinon.stub().returns({ exec: sinon.stub() })
|
||||||
this.AuthenticationController.setRedirectInSession = sinon.stub()
|
this.AuthenticationController.setRedirectInSession = sinon.stub()
|
||||||
this.res.callback = done
|
|
||||||
this.next = sinon.stub().callsFake(() => done())
|
|
||||||
return this.LaunchpadController.registerExternalAuthAdmin('ldap')(
|
return this.LaunchpadController.registerExternalAuthAdmin('ldap')(
|
||||||
this.req,
|
this.req,
|
||||||
this.res,
|
this.res,
|
||||||
|
@ -1004,7 +976,7 @@ describe('LaunchpadController', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('when registerNewUser produces an error', function () {
|
describe('when registerNewUser produces an error', function () {
|
||||||
beforeEach(function (done) {
|
beforeEach(function () {
|
||||||
this._atLeastOneAdminExists.resolves(false)
|
this._atLeastOneAdminExists.resolves(false)
|
||||||
this.email = 'someone@example.com'
|
this.email = 'someone@example.com'
|
||||||
this.req.body.email = this.email
|
this.req.body.email = this.email
|
||||||
|
@ -1017,8 +989,6 @@ describe('LaunchpadController', function () {
|
||||||
.rejects(new Error('woops'))
|
.rejects(new Error('woops'))
|
||||||
this.User.updateOne = sinon.stub().returns({ exec: sinon.stub() })
|
this.User.updateOne = sinon.stub().returns({ exec: sinon.stub() })
|
||||||
this.AuthenticationController.setRedirectInSession = sinon.stub()
|
this.AuthenticationController.setRedirectInSession = sinon.stub()
|
||||||
this.res.callback = done
|
|
||||||
this.next = sinon.stub().callsFake(() => done())
|
|
||||||
return this.LaunchpadController.registerExternalAuthAdmin('ldap')(
|
return this.LaunchpadController.registerExternalAuthAdmin('ldap')(
|
||||||
this.req,
|
this.req,
|
||||||
this.res,
|
this.res,
|
||||||
|
@ -1055,7 +1025,7 @@ describe('LaunchpadController', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('when user update produces an error', function () {
|
describe('when user update produces an error', function () {
|
||||||
beforeEach(function (done) {
|
beforeEach(function () {
|
||||||
this._atLeastOneAdminExists.resolves(false)
|
this._atLeastOneAdminExists.resolves(false)
|
||||||
this.email = 'someone@example.com'
|
this.email = 'someone@example.com'
|
||||||
this.req.body.email = this.email
|
this.req.body.email = this.email
|
||||||
|
@ -1070,8 +1040,6 @@ describe('LaunchpadController', function () {
|
||||||
exec: sinon.stub().rejects(new Error('woops')),
|
exec: sinon.stub().rejects(new Error('woops')),
|
||||||
})
|
})
|
||||||
this.AuthenticationController.setRedirectInSession = sinon.stub()
|
this.AuthenticationController.setRedirectInSession = sinon.stub()
|
||||||
this.res.callback = done
|
|
||||||
this.next = sinon.stub().callsFake(() => done())
|
|
||||||
return this.LaunchpadController.registerExternalAuthAdmin('ldap')(
|
return this.LaunchpadController.registerExternalAuthAdmin('ldap')(
|
||||||
this.req,
|
this.req,
|
||||||
this.res,
|
this.res,
|
||||||
|
|
|
@ -42,13 +42,12 @@ describe('TemplatesController', function () {
|
||||||
|
|
||||||
describe('createProjectFromV1Template', function () {
|
describe('createProjectFromV1Template', function () {
|
||||||
describe('on success', function () {
|
describe('on success', function () {
|
||||||
beforeEach(function (done) {
|
beforeEach(function () {
|
||||||
this.project = { _id: 'project-id' }
|
this.project = { _id: 'project-id' }
|
||||||
this.TemplatesManager.promises.createProjectFromV1Template.resolves(
|
this.TemplatesManager.promises.createProjectFromV1Template.resolves(
|
||||||
this.project
|
this.project
|
||||||
)
|
)
|
||||||
this.res.redirect.callsFake(() => done())
|
return this.TemplatesController.createProjectFromV1Template(
|
||||||
this.TemplatesController.createProjectFromV1Template(
|
|
||||||
this.req,
|
this.req,
|
||||||
this.res,
|
this.res,
|
||||||
this.next
|
this.next
|
||||||
|
@ -79,11 +78,10 @@ describe('TemplatesController', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('on error', function () {
|
describe('on error', function () {
|
||||||
beforeEach(function (done) {
|
beforeEach(function () {
|
||||||
this.TemplatesManager.promises.createProjectFromV1Template.rejects(
|
this.TemplatesManager.promises.createProjectFromV1Template.rejects(
|
||||||
'error'
|
'error'
|
||||||
)
|
)
|
||||||
this.next.callsFake(() => done())
|
|
||||||
return this.TemplatesController.createProjectFromV1Template(
|
return this.TemplatesController.createProjectFromV1Template(
|
||||||
this.req,
|
this.req,
|
||||||
this.res,
|
this.res,
|
||||||
|
|
Loading…
Reference in a new issue