Merge pull request #3495 from overleaf/ae-prettier-2
Upgrade Prettier to v2 GitOrigin-RevId: 85aa3fa1acb6332c4f58c46165a43d1a51471f33
This commit is contained in:
@@ -41,7 +41,7 @@ module.exports = LaunchpadController = {
|
||||
// * how does all this work with ldap and saml?
|
||||
const sessionUser = AuthenticationController.getSessionUser(req)
|
||||
const authMethod = LaunchpadController._getAuthMethod()
|
||||
return LaunchpadController._atLeastOneAdminExists(function(
|
||||
return LaunchpadController._atLeastOneAdminExists(function (
|
||||
err,
|
||||
adminUserExists
|
||||
) {
|
||||
@@ -59,35 +59,36 @@ module.exports = LaunchpadController = {
|
||||
return res.redirect('/login')
|
||||
}
|
||||
} else {
|
||||
return UserGetter.getUser(sessionUser._id, { isAdmin: 1 }, function(
|
||||
err,
|
||||
user
|
||||
) {
|
||||
if (err != null) {
|
||||
return next(err)
|
||||
return UserGetter.getUser(
|
||||
sessionUser._id,
|
||||
{ isAdmin: 1 },
|
||||
function (err, user) {
|
||||
if (err != null) {
|
||||
return next(err)
|
||||
}
|
||||
if (user && user.isAdmin) {
|
||||
return res.render(Path.resolve(__dirname, '../views/launchpad'), {
|
||||
wsUrl: Settings.wsUrl,
|
||||
adminUserExists,
|
||||
authMethod
|
||||
})
|
||||
} else {
|
||||
return res.redirect('/restricted')
|
||||
}
|
||||
}
|
||||
if (user && user.isAdmin) {
|
||||
return res.render(Path.resolve(__dirname, '../views/launchpad'), {
|
||||
wsUrl: Settings.wsUrl,
|
||||
adminUserExists,
|
||||
authMethod
|
||||
})
|
||||
} else {
|
||||
return res.redirect('/restricted')
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
_atLeastOneAdminExists(callback) {
|
||||
if (callback == null) {
|
||||
callback = function(err, exists) {}
|
||||
callback = function (err, exists) {}
|
||||
}
|
||||
return UserGetter.getUser(
|
||||
{ isAdmin: true },
|
||||
{ _id: 1, isAdmin: 1 },
|
||||
function(err, user) {
|
||||
function (err, user) {
|
||||
if (err != null) {
|
||||
return callback(err)
|
||||
}
|
||||
@@ -104,7 +105,7 @@ module.exports = LaunchpadController = {
|
||||
}
|
||||
logger.log({ email }, 'sending test email')
|
||||
const emailOptions = { to: email }
|
||||
return EmailHandler.sendEmail('testEmail', emailOptions, function(err) {
|
||||
return EmailHandler.sendEmail('testEmail', emailOptions, function (err) {
|
||||
if (err != null) {
|
||||
OError.tag(err, 'error sending test email', {
|
||||
email
|
||||
@@ -117,7 +118,7 @@ module.exports = LaunchpadController = {
|
||||
},
|
||||
|
||||
registerExternalAuthAdmin(authMethod) {
|
||||
return function(req, res, next) {
|
||||
return function (req, res, next) {
|
||||
if (LaunchpadController._getAuthMethod() !== authMethod) {
|
||||
logger.log(
|
||||
{ authMethod },
|
||||
@@ -132,7 +133,7 @@ module.exports = LaunchpadController = {
|
||||
}
|
||||
|
||||
logger.log({ email }, 'attempted register first admin user')
|
||||
return LaunchpadController._atLeastOneAdminExists(function(err, exists) {
|
||||
return LaunchpadController._atLeastOneAdminExists(function (err, exists) {
|
||||
if (err != null) {
|
||||
return next(err)
|
||||
}
|
||||
@@ -156,42 +157,42 @@ module.exports = LaunchpadController = {
|
||||
'creating admin account for specified external-auth user'
|
||||
)
|
||||
|
||||
return UserRegistrationHandler.registerNewUser(body, function(
|
||||
err,
|
||||
user
|
||||
) {
|
||||
if (err != null) {
|
||||
OError.tag(err, 'error with registerNewUser', {
|
||||
email,
|
||||
authMethod
|
||||
})
|
||||
return next(err)
|
||||
}
|
||||
|
||||
return User.updateOne(
|
||||
{ _id: user._id },
|
||||
{
|
||||
$set: { isAdmin: true },
|
||||
emails: [{ email }]
|
||||
},
|
||||
function(err) {
|
||||
if (err != null) {
|
||||
OError.tag(err, 'error setting user to admin', {
|
||||
user_id: user._id
|
||||
})
|
||||
return next(err)
|
||||
}
|
||||
|
||||
AuthenticationController.setRedirectInSession(req, '/launchpad')
|
||||
logger.log(
|
||||
{ email, user_id: user._id, authMethod },
|
||||
'created first admin account'
|
||||
)
|
||||
|
||||
return res.json({ redir: '/launchpad', email })
|
||||
return UserRegistrationHandler.registerNewUser(
|
||||
body,
|
||||
function (err, user) {
|
||||
if (err != null) {
|
||||
OError.tag(err, 'error with registerNewUser', {
|
||||
email,
|
||||
authMethod
|
||||
})
|
||||
return next(err)
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
return User.updateOne(
|
||||
{ _id: user._id },
|
||||
{
|
||||
$set: { isAdmin: true },
|
||||
emails: [{ email }]
|
||||
},
|
||||
function (err) {
|
||||
if (err != null) {
|
||||
OError.tag(err, 'error setting user to admin', {
|
||||
user_id: user._id
|
||||
})
|
||||
return next(err)
|
||||
}
|
||||
|
||||
AuthenticationController.setRedirectInSession(req, '/launchpad')
|
||||
logger.log(
|
||||
{ email, user_id: user._id, authMethod },
|
||||
'created first admin account'
|
||||
)
|
||||
|
||||
return res.json({ redir: '/launchpad', email })
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
},
|
||||
@@ -205,7 +206,7 @@ module.exports = LaunchpadController = {
|
||||
}
|
||||
|
||||
logger.log({ email }, 'attempted register first admin user')
|
||||
return LaunchpadController._atLeastOneAdminExists(function(err, exists) {
|
||||
return LaunchpadController._atLeastOneAdminExists(function (err, exists) {
|
||||
if (err != null) {
|
||||
return next(err)
|
||||
}
|
||||
@@ -219,44 +220,47 @@ module.exports = LaunchpadController = {
|
||||
}
|
||||
|
||||
const body = { email, password }
|
||||
return UserRegistrationHandler.registerNewUser(body, function(err, user) {
|
||||
if (err != null) {
|
||||
return next(err)
|
||||
}
|
||||
|
||||
logger.log({ user_id: user._id }, 'making user an admin')
|
||||
User.updateOne(
|
||||
{ _id: user._id },
|
||||
{
|
||||
$set: {
|
||||
isAdmin: true,
|
||||
emails: [{ email }]
|
||||
}
|
||||
},
|
||||
function(err) {
|
||||
if (err != null) {
|
||||
OError.tag(err, 'error setting user to admin', {
|
||||
user_id: user._id
|
||||
})
|
||||
return next(err)
|
||||
}
|
||||
|
||||
AuthenticationController.setRedirectInSession(req, '/launchpad')
|
||||
logger.log(
|
||||
{ email, user_id: user._id },
|
||||
'created first admin account'
|
||||
)
|
||||
return res.json({
|
||||
redir: '',
|
||||
id: user._id.toString(),
|
||||
first_name: user.first_name,
|
||||
last_name: user.last_name,
|
||||
email: user.email,
|
||||
created: Date.now()
|
||||
})
|
||||
return UserRegistrationHandler.registerNewUser(
|
||||
body,
|
||||
function (err, user) {
|
||||
if (err != null) {
|
||||
return next(err)
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
logger.log({ user_id: user._id }, 'making user an admin')
|
||||
User.updateOne(
|
||||
{ _id: user._id },
|
||||
{
|
||||
$set: {
|
||||
isAdmin: true,
|
||||
emails: [{ email }]
|
||||
}
|
||||
},
|
||||
function (err) {
|
||||
if (err != null) {
|
||||
OError.tag(err, 'error setting user to admin', {
|
||||
user_id: user._id
|
||||
})
|
||||
return next(err)
|
||||
}
|
||||
|
||||
AuthenticationController.setRedirectInSession(req, '/launchpad')
|
||||
logger.log(
|
||||
{ email, user_id: user._id },
|
||||
'created first admin account'
|
||||
)
|
||||
return res.json({
|
||||
redir: '',
|
||||
id: user._id.toString(),
|
||||
first_name: user.first_name,
|
||||
last_name: user.last_name,
|
||||
email: user.email,
|
||||
created: Date.now()
|
||||
})
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
+134
-135
@@ -14,145 +14,144 @@
|
||||
*/
|
||||
import App from '../../../../../../frontend/js/base'
|
||||
|
||||
export default App.controller('LaunchpadController', function(
|
||||
$scope,
|
||||
$http,
|
||||
$timeout
|
||||
) {
|
||||
$scope.adminUserExists = window.data.adminUserExists
|
||||
$scope.ideJsPath = window.data.ideJsPath
|
||||
$scope.authMethod = window.data.authMethod
|
||||
export default App.controller(
|
||||
'LaunchpadController',
|
||||
function ($scope, $http, $timeout) {
|
||||
$scope.adminUserExists = window.data.adminUserExists
|
||||
$scope.ideJsPath = window.data.ideJsPath
|
||||
$scope.authMethod = window.data.authMethod
|
||||
|
||||
$scope.createAdminSuccess = null
|
||||
$scope.createAdminError = null
|
||||
$scope.createAdminSuccess = null
|
||||
$scope.createAdminError = null
|
||||
|
||||
$scope.statusChecks = {
|
||||
ideJs: { status: 'inflight', error: null },
|
||||
websocket: { status: 'inflight', error: null },
|
||||
healthCheck: { status: 'inflight', error: null }
|
||||
}
|
||||
$scope.statusChecks = {
|
||||
ideJs: { status: 'inflight', error: null },
|
||||
websocket: { status: 'inflight', error: null },
|
||||
healthCheck: { status: 'inflight', error: null }
|
||||
}
|
||||
|
||||
$scope.testEmail = {
|
||||
emailAddress: '',
|
||||
inflight: false,
|
||||
status: null // | 'ok' | 'success'
|
||||
}
|
||||
$scope.testEmail = {
|
||||
emailAddress: '',
|
||||
inflight: false,
|
||||
status: null // | 'ok' | 'success'
|
||||
}
|
||||
|
||||
$scope.shouldShowAdminForm = () => !$scope.adminUserExists
|
||||
$scope.shouldShowAdminForm = () => !$scope.adminUserExists
|
||||
|
||||
$scope.onCreateAdminSuccess = function(response) {
|
||||
const { status } = response
|
||||
if (status >= 200 && status < 300) {
|
||||
return ($scope.createAdminSuccess = true)
|
||||
$scope.onCreateAdminSuccess = function (response) {
|
||||
const { status } = response
|
||||
if (status >= 200 && status < 300) {
|
||||
return ($scope.createAdminSuccess = true)
|
||||
}
|
||||
}
|
||||
|
||||
$scope.onCreateAdminError = () => ($scope.createAdminError = true)
|
||||
|
||||
$scope.sendTestEmail = function () {
|
||||
$scope.testEmail.inflight = true
|
||||
$scope.testEmail.status = null
|
||||
return $http
|
||||
.post('/launchpad/send_test_email', {
|
||||
email: $scope.testEmail.emailAddress,
|
||||
_csrf: window.csrfToken
|
||||
})
|
||||
.then(function (response) {
|
||||
const { status } = response
|
||||
$scope.testEmail.inflight = false
|
||||
if (status >= 200 && status < 300) {
|
||||
return ($scope.testEmail.status = 'ok')
|
||||
}
|
||||
})
|
||||
.catch(function () {
|
||||
$scope.testEmail.inflight = false
|
||||
return ($scope.testEmail.status = 'error')
|
||||
})
|
||||
}
|
||||
|
||||
$scope.tryFetchIdeJs = function () {
|
||||
$scope.statusChecks.ideJs.status = 'inflight'
|
||||
return $timeout(
|
||||
() =>
|
||||
$http
|
||||
.get($scope.ideJsPath)
|
||||
.then(function (response) {
|
||||
const { status } = response
|
||||
if (status >= 200 && status < 300) {
|
||||
return ($scope.statusChecks.ideJs.status = 'ok')
|
||||
}
|
||||
})
|
||||
.catch(function (response) {
|
||||
const { status } = response
|
||||
$scope.statusChecks.ideJs.status = 'error'
|
||||
return ($scope.statusChecks.ideJs.error = new Error(
|
||||
`Http status: ${status}`
|
||||
))
|
||||
}),
|
||||
|
||||
1000
|
||||
)
|
||||
}
|
||||
|
||||
$scope.tryOpenWebSocket = function () {
|
||||
$scope.statusChecks.websocket.status = 'inflight'
|
||||
return $timeout(function () {
|
||||
if (typeof io === 'undefined' || io === null) {
|
||||
$scope.statusChecks.websocket.status = 'error'
|
||||
$scope.statusChecks.websocket.error = 'socket.io not loaded'
|
||||
return
|
||||
}
|
||||
const socket = io.connect(null, {
|
||||
reconnect: false,
|
||||
'connect timeout': 30 * 1000,
|
||||
'force new connection': true
|
||||
})
|
||||
|
||||
socket.on('connectionAccepted', function () {
|
||||
$scope.statusChecks.websocket.status = 'ok'
|
||||
return $scope.$apply(function () {})
|
||||
})
|
||||
|
||||
socket.on('connectionRejected', function (err) {
|
||||
$scope.statusChecks.websocket.status = 'error'
|
||||
$scope.statusChecks.websocket.error = err
|
||||
return $scope.$apply(function () {})
|
||||
})
|
||||
|
||||
return socket.on('connect_failed', function (err) {
|
||||
$scope.statusChecks.websocket.status = 'error'
|
||||
$scope.statusChecks.websocket.error = err
|
||||
return $scope.$apply(function () {})
|
||||
})
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
$scope.tryHealthCheck = function () {
|
||||
$scope.statusChecks.healthCheck.status = 'inflight'
|
||||
return $http
|
||||
.get('/health_check')
|
||||
.then(function (response) {
|
||||
const { status } = response
|
||||
if (status >= 200 && status < 300) {
|
||||
return ($scope.statusChecks.healthCheck.status = 'ok')
|
||||
}
|
||||
})
|
||||
.catch(function (response) {
|
||||
const { status } = response
|
||||
$scope.statusChecks.healthCheck.status = 'error'
|
||||
return ($scope.statusChecks.healthCheck.error = new Error(
|
||||
`Http status: ${status}`
|
||||
))
|
||||
})
|
||||
}
|
||||
|
||||
$scope.runStatusChecks = function () {
|
||||
$timeout(() => $scope.tryFetchIdeJs(), 1000)
|
||||
return $timeout(() => $scope.tryOpenWebSocket(), 2000)
|
||||
}
|
||||
|
||||
// kick off the status checks on load
|
||||
if ($scope.adminUserExists) {
|
||||
return $scope.runStatusChecks()
|
||||
}
|
||||
}
|
||||
|
||||
$scope.onCreateAdminError = () => ($scope.createAdminError = true)
|
||||
|
||||
$scope.sendTestEmail = function() {
|
||||
$scope.testEmail.inflight = true
|
||||
$scope.testEmail.status = null
|
||||
return $http
|
||||
.post('/launchpad/send_test_email', {
|
||||
email: $scope.testEmail.emailAddress,
|
||||
_csrf: window.csrfToken
|
||||
})
|
||||
.then(function(response) {
|
||||
const { status } = response
|
||||
$scope.testEmail.inflight = false
|
||||
if (status >= 200 && status < 300) {
|
||||
return ($scope.testEmail.status = 'ok')
|
||||
}
|
||||
})
|
||||
.catch(function() {
|
||||
$scope.testEmail.inflight = false
|
||||
return ($scope.testEmail.status = 'error')
|
||||
})
|
||||
}
|
||||
|
||||
$scope.tryFetchIdeJs = function() {
|
||||
$scope.statusChecks.ideJs.status = 'inflight'
|
||||
return $timeout(
|
||||
() =>
|
||||
$http
|
||||
.get($scope.ideJsPath)
|
||||
.then(function(response) {
|
||||
const { status } = response
|
||||
if (status >= 200 && status < 300) {
|
||||
return ($scope.statusChecks.ideJs.status = 'ok')
|
||||
}
|
||||
})
|
||||
.catch(function(response) {
|
||||
const { status } = response
|
||||
$scope.statusChecks.ideJs.status = 'error'
|
||||
return ($scope.statusChecks.ideJs.error = new Error(
|
||||
`Http status: ${status}`
|
||||
))
|
||||
}),
|
||||
|
||||
1000
|
||||
)
|
||||
}
|
||||
|
||||
$scope.tryOpenWebSocket = function() {
|
||||
$scope.statusChecks.websocket.status = 'inflight'
|
||||
return $timeout(function() {
|
||||
if (typeof io === 'undefined' || io === null) {
|
||||
$scope.statusChecks.websocket.status = 'error'
|
||||
$scope.statusChecks.websocket.error = 'socket.io not loaded'
|
||||
return
|
||||
}
|
||||
const socket = io.connect(null, {
|
||||
reconnect: false,
|
||||
'connect timeout': 30 * 1000,
|
||||
'force new connection': true
|
||||
})
|
||||
|
||||
socket.on('connectionAccepted', function() {
|
||||
$scope.statusChecks.websocket.status = 'ok'
|
||||
return $scope.$apply(function() {})
|
||||
})
|
||||
|
||||
socket.on('connectionRejected', function(err) {
|
||||
$scope.statusChecks.websocket.status = 'error'
|
||||
$scope.statusChecks.websocket.error = err
|
||||
return $scope.$apply(function() {})
|
||||
})
|
||||
|
||||
return socket.on('connect_failed', function(err) {
|
||||
$scope.statusChecks.websocket.status = 'error'
|
||||
$scope.statusChecks.websocket.error = err
|
||||
return $scope.$apply(function() {})
|
||||
})
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
$scope.tryHealthCheck = function() {
|
||||
$scope.statusChecks.healthCheck.status = 'inflight'
|
||||
return $http
|
||||
.get('/health_check')
|
||||
.then(function(response) {
|
||||
const { status } = response
|
||||
if (status >= 200 && status < 300) {
|
||||
return ($scope.statusChecks.healthCheck.status = 'ok')
|
||||
}
|
||||
})
|
||||
.catch(function(response) {
|
||||
const { status } = response
|
||||
$scope.statusChecks.healthCheck.status = 'error'
|
||||
return ($scope.statusChecks.healthCheck.error = new Error(
|
||||
`Http status: ${status}`
|
||||
))
|
||||
})
|
||||
}
|
||||
|
||||
$scope.runStatusChecks = function() {
|
||||
$timeout(() => $scope.tryFetchIdeJs(), 1000)
|
||||
return $timeout(() => $scope.tryOpenWebSocket(), 2000)
|
||||
}
|
||||
|
||||
// kick off the status checks on load
|
||||
if ($scope.adminUserExists) {
|
||||
return $scope.runStatusChecks()
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
@@ -19,8 +19,8 @@ const modulePath = require('path').join(
|
||||
'../../../app/src/LaunchpadController.js'
|
||||
)
|
||||
|
||||
describe('LaunchpadController', function() {
|
||||
beforeEach(function() {
|
||||
describe('LaunchpadController', function () {
|
||||
beforeEach(function () {
|
||||
this.user = {
|
||||
_id: '323123',
|
||||
first_name: 'fn',
|
||||
@@ -59,8 +59,8 @@ describe('LaunchpadController', function() {
|
||||
return (this.next = sinon.stub())
|
||||
})
|
||||
|
||||
describe('launchpadPage', function() {
|
||||
beforeEach(function() {
|
||||
describe('launchpadPage', function () {
|
||||
beforeEach(function () {
|
||||
this._atLeastOneAdminExists = sinon.stub(
|
||||
this.LaunchpadController,
|
||||
'_atLeastOneAdminExists'
|
||||
@@ -68,20 +68,20 @@ describe('LaunchpadController', function() {
|
||||
return (this.AuthenticationController.setRedirectInSession = sinon.stub())
|
||||
})
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
return this._atLeastOneAdminExists.restore()
|
||||
})
|
||||
|
||||
describe('when the user is not logged in', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the user is not logged in', function () {
|
||||
beforeEach(function () {
|
||||
this.AuthenticationController.getSessionUser = sinon
|
||||
.stub()
|
||||
.returns(null)
|
||||
return (this.res.render = sinon.stub())
|
||||
})
|
||||
|
||||
describe('when there are no admins', function() {
|
||||
beforeEach(function() {
|
||||
describe('when there are no admins', function () {
|
||||
beforeEach(function () {
|
||||
this._atLeastOneAdminExists.callsArgWith(0, null, false)
|
||||
return this.LaunchpadController.launchpadPage(
|
||||
this.req,
|
||||
@@ -90,7 +90,7 @@ describe('LaunchpadController', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should render the launchpad page', function() {
|
||||
it('should render the launchpad page', function () {
|
||||
const viewPath = require('path').join(
|
||||
__dirname,
|
||||
'../../../app/views/launchpad'
|
||||
@@ -105,8 +105,8 @@ describe('LaunchpadController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when there is at least one admin', function() {
|
||||
beforeEach(function() {
|
||||
describe('when there is at least one admin', function () {
|
||||
beforeEach(function () {
|
||||
this._atLeastOneAdminExists.callsArgWith(0, null, true)
|
||||
return this.LaunchpadController.launchpadPage(
|
||||
this.req,
|
||||
@@ -115,21 +115,21 @@ describe('LaunchpadController', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should redirect to login page', function() {
|
||||
it('should redirect to login page', function () {
|
||||
this.AuthenticationController.setRedirectInSession.callCount.should.equal(
|
||||
1
|
||||
)
|
||||
this.res.redirect.calledWith('/login').should.equal(true)
|
||||
})
|
||||
|
||||
it('should not render the launchpad page', function() {
|
||||
it('should not render the launchpad page', function () {
|
||||
return this.res.render.callCount.should.equal(0)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the user is logged in', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the user is logged in', function () {
|
||||
beforeEach(function () {
|
||||
this.user = {
|
||||
_id: 'abcd',
|
||||
email: 'abcd@example.com'
|
||||
@@ -142,8 +142,8 @@ describe('LaunchpadController', function() {
|
||||
return (this.res.redirect = sinon.stub())
|
||||
})
|
||||
|
||||
describe('when the user is an admin', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the user is an admin', function () {
|
||||
beforeEach(function () {
|
||||
this.UserGetter.getUser = sinon
|
||||
.stub()
|
||||
.callsArgWith(2, null, { isAdmin: true })
|
||||
@@ -154,7 +154,7 @@ describe('LaunchpadController', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should render the launchpad page', function() {
|
||||
it('should render the launchpad page', function () {
|
||||
const viewPath = require('path').join(
|
||||
__dirname,
|
||||
'../../../app/views/launchpad'
|
||||
@@ -170,8 +170,8 @@ describe('LaunchpadController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the user is not an admin', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the user is not an admin', function () {
|
||||
beforeEach(function () {
|
||||
this.UserGetter.getUser = sinon
|
||||
.stub()
|
||||
.callsArgWith(2, null, { isAdmin: false })
|
||||
@@ -182,7 +182,7 @@ describe('LaunchpadController', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should redirect to restricted page', function() {
|
||||
it('should redirect to restricted page', function () {
|
||||
this.res.redirect.callCount.should.equal(1)
|
||||
return this.res.redirect.calledWith('/restricted').should.equal(true)
|
||||
})
|
||||
@@ -190,15 +190,15 @@ describe('LaunchpadController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('_atLeastOneAdminExists', function() {
|
||||
describe('when there are no admins', function() {
|
||||
beforeEach(function() {
|
||||
describe('_atLeastOneAdminExists', function () {
|
||||
describe('when there are no admins', function () {
|
||||
beforeEach(function () {
|
||||
return (this.UserGetter.getUser = sinon
|
||||
.stub()
|
||||
.callsArgWith(2, null, null))
|
||||
})
|
||||
|
||||
it('should callback with false', function(done) {
|
||||
it('should callback with false', function (done) {
|
||||
return this.LaunchpadController._atLeastOneAdminExists(
|
||||
(err, exists) => {
|
||||
expect(err).to.equal(null)
|
||||
@@ -209,14 +209,14 @@ describe('LaunchpadController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when there are some admins', function() {
|
||||
beforeEach(function() {
|
||||
describe('when there are some admins', function () {
|
||||
beforeEach(function () {
|
||||
return (this.UserGetter.getUser = sinon
|
||||
.stub()
|
||||
.callsArgWith(2, null, { _id: 'abcd' }))
|
||||
})
|
||||
|
||||
it('should callback with true', function(done) {
|
||||
it('should callback with true', function (done) {
|
||||
return this.LaunchpadController._atLeastOneAdminExists(
|
||||
(err, exists) => {
|
||||
expect(err).to.equal(null)
|
||||
@@ -227,14 +227,14 @@ describe('LaunchpadController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when getUser produces an error', function() {
|
||||
beforeEach(function() {
|
||||
describe('when getUser produces an error', function () {
|
||||
beforeEach(function () {
|
||||
return (this.UserGetter.getUser = sinon
|
||||
.stub()
|
||||
.callsArgWith(2, new Error('woops')))
|
||||
})
|
||||
|
||||
it('should produce an error', function(done) {
|
||||
it('should produce an error', function (done) {
|
||||
return this.LaunchpadController._atLeastOneAdminExists(
|
||||
(err, exists) => {
|
||||
expect(err).to.not.equal(null)
|
||||
@@ -247,26 +247,26 @@ describe('LaunchpadController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('sendTestEmail', function() {
|
||||
beforeEach(function() {
|
||||
describe('sendTestEmail', function () {
|
||||
beforeEach(function () {
|
||||
this.EmailHandler.sendEmail = sinon.stub().callsArgWith(2, null)
|
||||
this.req.body.email = 'someone@example.com'
|
||||
this.res.sendStatus = sinon.stub()
|
||||
return (this.next = sinon.stub())
|
||||
})
|
||||
|
||||
it('should produce a 201 response', function() {
|
||||
it('should produce a 201 response', function () {
|
||||
this.LaunchpadController.sendTestEmail(this.req, this.res, this.next)
|
||||
this.res.sendStatus.callCount.should.equal(1)
|
||||
return this.res.sendStatus.calledWith(201).should.equal(true)
|
||||
})
|
||||
|
||||
it('should not call next with an error', function() {
|
||||
it('should not call next with an error', function () {
|
||||
this.LaunchpadController.sendTestEmail(this.req, this.res, this.next)
|
||||
return this.next.callCount.should.equal(0)
|
||||
})
|
||||
|
||||
it('should have called sendEmail', function() {
|
||||
it('should have called sendEmail', function () {
|
||||
this.LaunchpadController.sendTestEmail(this.req, this.res, this.next)
|
||||
this.EmailHandler.sendEmail.callCount.should.equal(1)
|
||||
return this.EmailHandler.sendEmail
|
||||
@@ -274,26 +274,26 @@ describe('LaunchpadController', function() {
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
describe('when sendEmail produces an error', function() {
|
||||
beforeEach(function() {
|
||||
describe('when sendEmail produces an error', function () {
|
||||
beforeEach(function () {
|
||||
return (this.EmailHandler.sendEmail = sinon
|
||||
.stub()
|
||||
.callsArgWith(2, new Error('woops')))
|
||||
})
|
||||
|
||||
it('should call next with an error', function() {
|
||||
it('should call next with an error', function () {
|
||||
this.LaunchpadController.sendTestEmail(this.req, this.res, this.next)
|
||||
this.next.callCount.should.equal(1)
|
||||
return expect(this.next.lastCall.args[0]).to.be.instanceof(Error)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when no email address is supplied', function() {
|
||||
beforeEach(function() {
|
||||
describe('when no email address is supplied', function () {
|
||||
beforeEach(function () {
|
||||
return (this.req.body.email = undefined)
|
||||
})
|
||||
|
||||
it('should produce a 400 response', function() {
|
||||
it('should produce a 400 response', function () {
|
||||
this.LaunchpadController.sendTestEmail(this.req, this.res, this.next)
|
||||
this.res.sendStatus.callCount.should.equal(1)
|
||||
return this.res.sendStatus.calledWith(400).should.equal(true)
|
||||
@@ -301,20 +301,20 @@ describe('LaunchpadController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('registerAdmin', function() {
|
||||
beforeEach(function() {
|
||||
describe('registerAdmin', function () {
|
||||
beforeEach(function () {
|
||||
return (this._atLeastOneAdminExists = sinon.stub(
|
||||
this.LaunchpadController,
|
||||
'_atLeastOneAdminExists'
|
||||
))
|
||||
})
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
return this._atLeastOneAdminExists.restore()
|
||||
})
|
||||
|
||||
describe('when all goes well', function() {
|
||||
beforeEach(function() {
|
||||
describe('when all goes well', function () {
|
||||
beforeEach(function () {
|
||||
this._atLeastOneAdminExists.callsArgWith(0, null, false)
|
||||
this.email = 'someone@example.com'
|
||||
this.password = 'a_really_bad_password'
|
||||
@@ -338,23 +338,23 @@ describe('LaunchpadController', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should send back a json response', function() {
|
||||
it('should send back a json response', function () {
|
||||
this.res.json.callCount.should.equal(1)
|
||||
return expect(this.res.json.lastCall.args[0].email).to.equal(this.email)
|
||||
})
|
||||
|
||||
it('should have checked for existing admins', function() {
|
||||
it('should have checked for existing admins', function () {
|
||||
return this._atLeastOneAdminExists.callCount.should.equal(1)
|
||||
})
|
||||
|
||||
it('should have called registerNewUser', function() {
|
||||
it('should have called registerNewUser', function () {
|
||||
this.UserRegistrationHandler.registerNewUser.callCount.should.equal(1)
|
||||
return this.UserRegistrationHandler.registerNewUser
|
||||
.calledWith({ email: this.email, password: this.password })
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should have updated the user to make them an admin', function() {
|
||||
it('should have updated the user to make them an admin', function () {
|
||||
this.User.updateOne.callCount.should.equal(1)
|
||||
return this.User.updateOne
|
||||
.calledWithMatch(
|
||||
@@ -369,7 +369,7 @@ describe('LaunchpadController', function() {
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should have set a redirect in session', function() {
|
||||
it('should have set a redirect in session', function () {
|
||||
this.AuthenticationController.setRedirectInSession.callCount.should.equal(
|
||||
1
|
||||
)
|
||||
@@ -379,8 +379,8 @@ describe('LaunchpadController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when no email is supplied', function() {
|
||||
beforeEach(function() {
|
||||
describe('when no email is supplied', function () {
|
||||
beforeEach(function () {
|
||||
this._atLeastOneAdminExists.callsArgWith(0, null, false)
|
||||
this.email = undefined
|
||||
this.password = 'a_really_bad_password'
|
||||
@@ -402,24 +402,24 @@ describe('LaunchpadController', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should send a 400 response', function() {
|
||||
it('should send a 400 response', function () {
|
||||
this.res.sendStatus.callCount.should.equal(1)
|
||||
return this.res.sendStatus.calledWith(400).should.equal(true)
|
||||
})
|
||||
|
||||
it('should not check for existing admins', function() {
|
||||
it('should not check for existing admins', function () {
|
||||
return this._atLeastOneAdminExists.callCount.should.equal(0)
|
||||
})
|
||||
|
||||
it('should not call registerNewUser', function() {
|
||||
it('should not call registerNewUser', function () {
|
||||
return this.UserRegistrationHandler.registerNewUser.callCount.should.equal(
|
||||
0
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when no password is supplied', function() {
|
||||
beforeEach(function() {
|
||||
describe('when no password is supplied', function () {
|
||||
beforeEach(function () {
|
||||
this._atLeastOneAdminExists.callsArgWith(0, null, false)
|
||||
this.email = 'someone@example.com'
|
||||
this.password = undefined
|
||||
@@ -441,24 +441,24 @@ describe('LaunchpadController', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should send a 400 response', function() {
|
||||
it('should send a 400 response', function () {
|
||||
this.res.sendStatus.callCount.should.equal(1)
|
||||
return this.res.sendStatus.calledWith(400).should.equal(true)
|
||||
})
|
||||
|
||||
it('should not check for existing admins', function() {
|
||||
it('should not check for existing admins', function () {
|
||||
return this._atLeastOneAdminExists.callCount.should.equal(0)
|
||||
})
|
||||
|
||||
it('should not call registerNewUser', function() {
|
||||
it('should not call registerNewUser', function () {
|
||||
return this.UserRegistrationHandler.registerNewUser.callCount.should.equal(
|
||||
0
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when there are already existing admins', function() {
|
||||
beforeEach(function() {
|
||||
describe('when there are already existing admins', function () {
|
||||
beforeEach(function () {
|
||||
this._atLeastOneAdminExists.callsArgWith(0, null, true)
|
||||
this.email = 'someone@example.com'
|
||||
this.password = 'a_really_bad_password'
|
||||
@@ -480,20 +480,20 @@ describe('LaunchpadController', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should send a 403 response', function() {
|
||||
it('should send a 403 response', function () {
|
||||
this.res.sendStatus.callCount.should.equal(1)
|
||||
return this.res.sendStatus.calledWith(403).should.equal(true)
|
||||
})
|
||||
|
||||
it('should not call registerNewUser', function() {
|
||||
it('should not call registerNewUser', function () {
|
||||
return this.UserRegistrationHandler.registerNewUser.callCount.should.equal(
|
||||
0
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when checking admins produces an error', function() {
|
||||
beforeEach(function() {
|
||||
describe('when checking admins produces an error', function () {
|
||||
beforeEach(function () {
|
||||
this._atLeastOneAdminExists.callsArgWith(0, new Error('woops'))
|
||||
this.email = 'someone@example.com'
|
||||
this.password = 'a_really_bad_password'
|
||||
@@ -515,24 +515,24 @@ describe('LaunchpadController', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should call next with an error', function() {
|
||||
it('should call next with an error', function () {
|
||||
this.next.callCount.should.equal(1)
|
||||
return expect(this.next.lastCall.args[0]).to.be.instanceof(Error)
|
||||
})
|
||||
|
||||
it('should have checked for existing admins', function() {
|
||||
it('should have checked for existing admins', function () {
|
||||
return this._atLeastOneAdminExists.callCount.should.equal(1)
|
||||
})
|
||||
|
||||
it('should not call registerNewUser', function() {
|
||||
it('should not call registerNewUser', function () {
|
||||
return this.UserRegistrationHandler.registerNewUser.callCount.should.equal(
|
||||
0
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when registerNewUser produces an error', function() {
|
||||
beforeEach(function() {
|
||||
describe('when registerNewUser produces an error', function () {
|
||||
beforeEach(function () {
|
||||
this._atLeastOneAdminExists.callsArgWith(0, null, false)
|
||||
this.email = 'someone@example.com'
|
||||
this.password = 'a_really_bad_password'
|
||||
@@ -556,29 +556,29 @@ describe('LaunchpadController', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should call next with an error', function() {
|
||||
it('should call next with an error', function () {
|
||||
this.next.callCount.should.equal(1)
|
||||
return expect(this.next.lastCall.args[0]).to.be.instanceof(Error)
|
||||
})
|
||||
|
||||
it('should have checked for existing admins', function() {
|
||||
it('should have checked for existing admins', function () {
|
||||
return this._atLeastOneAdminExists.callCount.should.equal(1)
|
||||
})
|
||||
|
||||
it('should have called registerNewUser', function() {
|
||||
it('should have called registerNewUser', function () {
|
||||
this.UserRegistrationHandler.registerNewUser.callCount.should.equal(1)
|
||||
return this.UserRegistrationHandler.registerNewUser
|
||||
.calledWith({ email: this.email, password: this.password })
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should not call update', function() {
|
||||
it('should not call update', function () {
|
||||
return this.User.updateOne.callCount.should.equal(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when user update produces an error', function() {
|
||||
beforeEach(function() {
|
||||
describe('when user update produces an error', function () {
|
||||
beforeEach(function () {
|
||||
this._atLeastOneAdminExists.callsArgWith(0, null, false)
|
||||
this.email = 'someone@example.com'
|
||||
this.password = 'a_really_bad_password'
|
||||
@@ -602,16 +602,16 @@ describe('LaunchpadController', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should call next with an error', function() {
|
||||
it('should call next with an error', function () {
|
||||
this.next.callCount.should.equal(1)
|
||||
return expect(this.next.lastCall.args[0]).to.be.instanceof(Error)
|
||||
})
|
||||
|
||||
it('should have checked for existing admins', function() {
|
||||
it('should have checked for existing admins', function () {
|
||||
return this._atLeastOneAdminExists.callCount.should.equal(1)
|
||||
})
|
||||
|
||||
it('should have called registerNewUser', function() {
|
||||
it('should have called registerNewUser', function () {
|
||||
this.UserRegistrationHandler.registerNewUser.callCount.should.equal(1)
|
||||
return this.UserRegistrationHandler.registerNewUser
|
||||
.calledWith({ email: this.email, password: this.password })
|
||||
@@ -619,8 +619,8 @@ describe('LaunchpadController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when overleaf', function() {
|
||||
beforeEach(function() {
|
||||
describe('when overleaf', function () {
|
||||
beforeEach(function () {
|
||||
this.Settings.overleaf = { one: 1 }
|
||||
this.Settings.createV1AccountOnLogin = true
|
||||
this._atLeastOneAdminExists.callsArgWith(0, null, false)
|
||||
@@ -649,23 +649,23 @@ describe('LaunchpadController', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should send back a json response', function() {
|
||||
it('should send back a json response', function () {
|
||||
this.res.json.callCount.should.equal(1)
|
||||
return expect(this.res.json.lastCall.args[0].email).to.equal(this.email)
|
||||
})
|
||||
|
||||
it('should have checked for existing admins', function() {
|
||||
it('should have checked for existing admins', function () {
|
||||
return this._atLeastOneAdminExists.callCount.should.equal(1)
|
||||
})
|
||||
|
||||
it('should have called registerNewUser', function() {
|
||||
it('should have called registerNewUser', function () {
|
||||
this.UserRegistrationHandler.registerNewUser.callCount.should.equal(1)
|
||||
return this.UserRegistrationHandler.registerNewUser
|
||||
.calledWith({ email: this.email, password: this.password })
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should have updated the user to make them an admin', function() {
|
||||
it('should have updated the user to make them an admin', function () {
|
||||
return this.User.updateOne
|
||||
.calledWith(
|
||||
{ _id: this.user._id },
|
||||
@@ -679,7 +679,7 @@ describe('LaunchpadController', function() {
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should have set a redirect in session', function() {
|
||||
it('should have set a redirect in session', function () {
|
||||
this.AuthenticationController.setRedirectInSession.callCount.should.equal(
|
||||
1
|
||||
)
|
||||
@@ -690,8 +690,8 @@ describe('LaunchpadController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('registerExternalAuthAdmin', function() {
|
||||
beforeEach(function() {
|
||||
describe('registerExternalAuthAdmin', function () {
|
||||
beforeEach(function () {
|
||||
this.Settings.ldap = { one: 1 }
|
||||
return (this._atLeastOneAdminExists = sinon.stub(
|
||||
this.LaunchpadController,
|
||||
@@ -699,12 +699,12 @@ describe('LaunchpadController', function() {
|
||||
))
|
||||
})
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
return this._atLeastOneAdminExists.restore()
|
||||
})
|
||||
|
||||
describe('when all goes well', function() {
|
||||
beforeEach(function() {
|
||||
describe('when all goes well', function () {
|
||||
beforeEach(function () {
|
||||
this._atLeastOneAdminExists.callsArgWith(0, null, false)
|
||||
this.email = 'someone@example.com'
|
||||
this.req.body.email = this.email
|
||||
@@ -726,16 +726,16 @@ describe('LaunchpadController', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should send back a json response', function() {
|
||||
it('should send back a json response', function () {
|
||||
this.res.json.callCount.should.equal(1)
|
||||
return expect(this.res.json.lastCall.args[0].email).to.equal(this.email)
|
||||
})
|
||||
|
||||
it('should have checked for existing admins', function() {
|
||||
it('should have checked for existing admins', function () {
|
||||
return this._atLeastOneAdminExists.callCount.should.equal(1)
|
||||
})
|
||||
|
||||
it('should have called registerNewUser', function() {
|
||||
it('should have called registerNewUser', function () {
|
||||
this.UserRegistrationHandler.registerNewUser.callCount.should.equal(1)
|
||||
return this.UserRegistrationHandler.registerNewUser
|
||||
.calledWith({
|
||||
@@ -747,7 +747,7 @@ describe('LaunchpadController', function() {
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should have updated the user to make them an admin', function() {
|
||||
it('should have updated the user to make them an admin', function () {
|
||||
this.User.updateOne.callCount.should.equal(1)
|
||||
return this.User.updateOne
|
||||
.calledWith(
|
||||
@@ -760,7 +760,7 @@ describe('LaunchpadController', function() {
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should have set a redirect in session', function() {
|
||||
it('should have set a redirect in session', function () {
|
||||
this.AuthenticationController.setRedirectInSession.callCount.should.equal(
|
||||
1
|
||||
)
|
||||
@@ -770,8 +770,8 @@ describe('LaunchpadController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the authMethod is invalid', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the authMethod is invalid', function () {
|
||||
beforeEach(function () {
|
||||
this._atLeastOneAdminExists.callsArgWith(0, null, false)
|
||||
this.email = undefined
|
||||
this.req.body.email = this.email
|
||||
@@ -789,24 +789,24 @@ describe('LaunchpadController', function() {
|
||||
)(this.req, this.res, this.next)
|
||||
})
|
||||
|
||||
it('should send a 403 response', function() {
|
||||
it('should send a 403 response', function () {
|
||||
this.res.sendStatus.callCount.should.equal(1)
|
||||
return this.res.sendStatus.calledWith(403).should.equal(true)
|
||||
})
|
||||
|
||||
it('should not check for existing admins', function() {
|
||||
it('should not check for existing admins', function () {
|
||||
return this._atLeastOneAdminExists.callCount.should.equal(0)
|
||||
})
|
||||
|
||||
it('should not call registerNewUser', function() {
|
||||
it('should not call registerNewUser', function () {
|
||||
return this.UserRegistrationHandler.registerNewUser.callCount.should.equal(
|
||||
0
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when no email is supplied', function() {
|
||||
beforeEach(function() {
|
||||
describe('when no email is supplied', function () {
|
||||
beforeEach(function () {
|
||||
this._atLeastOneAdminExists.callsArgWith(0, null, false)
|
||||
this.email = undefined
|
||||
this.req.body.email = this.email
|
||||
@@ -826,24 +826,24 @@ describe('LaunchpadController', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should send a 400 response', function() {
|
||||
it('should send a 400 response', function () {
|
||||
this.res.sendStatus.callCount.should.equal(1)
|
||||
return this.res.sendStatus.calledWith(400).should.equal(true)
|
||||
})
|
||||
|
||||
it('should not check for existing admins', function() {
|
||||
it('should not check for existing admins', function () {
|
||||
return this._atLeastOneAdminExists.callCount.should.equal(0)
|
||||
})
|
||||
|
||||
it('should not call registerNewUser', function() {
|
||||
it('should not call registerNewUser', function () {
|
||||
return this.UserRegistrationHandler.registerNewUser.callCount.should.equal(
|
||||
0
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when there are already existing admins', function() {
|
||||
beforeEach(function() {
|
||||
describe('when there are already existing admins', function () {
|
||||
beforeEach(function () {
|
||||
this._atLeastOneAdminExists.callsArgWith(0, null, true)
|
||||
this.email = 'someone@example.com'
|
||||
this.req.body.email = this.email
|
||||
@@ -863,20 +863,20 @@ describe('LaunchpadController', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should send a 403 response', function() {
|
||||
it('should send a 403 response', function () {
|
||||
this.res.sendStatus.callCount.should.equal(1)
|
||||
return this.res.sendStatus.calledWith(403).should.equal(true)
|
||||
})
|
||||
|
||||
it('should not call registerNewUser', function() {
|
||||
it('should not call registerNewUser', function () {
|
||||
return this.UserRegistrationHandler.registerNewUser.callCount.should.equal(
|
||||
0
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when checking admins produces an error', function() {
|
||||
beforeEach(function() {
|
||||
describe('when checking admins produces an error', function () {
|
||||
beforeEach(function () {
|
||||
this._atLeastOneAdminExists.callsArgWith(0, new Error('woops'))
|
||||
this.email = 'someone@example.com'
|
||||
this.req.body.email = this.email
|
||||
@@ -896,24 +896,24 @@ describe('LaunchpadController', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should call next with an error', function() {
|
||||
it('should call next with an error', function () {
|
||||
this.next.callCount.should.equal(1)
|
||||
return expect(this.next.lastCall.args[0]).to.be.instanceof(Error)
|
||||
})
|
||||
|
||||
it('should have checked for existing admins', function() {
|
||||
it('should have checked for existing admins', function () {
|
||||
return this._atLeastOneAdminExists.callCount.should.equal(1)
|
||||
})
|
||||
|
||||
it('should not call registerNewUser', function() {
|
||||
it('should not call registerNewUser', function () {
|
||||
return this.UserRegistrationHandler.registerNewUser.callCount.should.equal(
|
||||
0
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when registerNewUser produces an error', function() {
|
||||
beforeEach(function() {
|
||||
describe('when registerNewUser produces an error', function () {
|
||||
beforeEach(function () {
|
||||
this._atLeastOneAdminExists.callsArgWith(0, null, false)
|
||||
this.email = 'someone@example.com'
|
||||
this.req.body.email = this.email
|
||||
@@ -935,16 +935,16 @@ describe('LaunchpadController', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should call next with an error', function() {
|
||||
it('should call next with an error', function () {
|
||||
this.next.callCount.should.equal(1)
|
||||
return expect(this.next.lastCall.args[0]).to.be.instanceof(Error)
|
||||
})
|
||||
|
||||
it('should have checked for existing admins', function() {
|
||||
it('should have checked for existing admins', function () {
|
||||
return this._atLeastOneAdminExists.callCount.should.equal(1)
|
||||
})
|
||||
|
||||
it('should have called registerNewUser', function() {
|
||||
it('should have called registerNewUser', function () {
|
||||
this.UserRegistrationHandler.registerNewUser.callCount.should.equal(1)
|
||||
return this.UserRegistrationHandler.registerNewUser
|
||||
.calledWith({
|
||||
@@ -956,13 +956,13 @@ describe('LaunchpadController', function() {
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should not call update', function() {
|
||||
it('should not call update', function () {
|
||||
return this.User.updateOne.callCount.should.equal(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when user update produces an error', function() {
|
||||
beforeEach(function() {
|
||||
describe('when user update produces an error', function () {
|
||||
beforeEach(function () {
|
||||
this._atLeastOneAdminExists.callsArgWith(0, null, false)
|
||||
this.email = 'someone@example.com'
|
||||
this.req.body.email = this.email
|
||||
@@ -984,16 +984,16 @@ describe('LaunchpadController', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should call next with an error', function() {
|
||||
it('should call next with an error', function () {
|
||||
this.next.callCount.should.equal(1)
|
||||
return expect(this.next.lastCall.args[0]).to.be.instanceof(Error)
|
||||
})
|
||||
|
||||
it('should have checked for existing admins', function() {
|
||||
it('should have checked for existing admins', function () {
|
||||
return this._atLeastOneAdminExists.callCount.should.equal(1)
|
||||
})
|
||||
|
||||
it('should have called registerNewUser', function() {
|
||||
it('should have called registerNewUser', function () {
|
||||
this.UserRegistrationHandler.registerNewUser.callCount.should.equal(1)
|
||||
return this.UserRegistrationHandler.registerNewUser
|
||||
.calledWith({
|
||||
|
||||
@@ -18,7 +18,7 @@ if (fs.existsSync(MODULES_PATH)) {
|
||||
}, entryPoints)
|
||||
}
|
||||
|
||||
module.exports = function() {
|
||||
module.exports = function () {
|
||||
return {
|
||||
code: entryPoints.map(entryPoint => `import '${entryPoint}'`).join('\n')
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ if (fs.existsSync(MODULES_PATH)) {
|
||||
}, entryPoints)
|
||||
}
|
||||
|
||||
module.exports = function() {
|
||||
module.exports = function () {
|
||||
return {
|
||||
code: entryPoints.map(entryPoint => `import '${entryPoint}'`).join('\n')
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ const MODULE_PATH = Path.join(
|
||||
)
|
||||
const VIEW_PATH = Path.join(__dirname, '../../../app/views/user/activate')
|
||||
|
||||
describe('UserActivateController', function() {
|
||||
beforeEach(function() {
|
||||
describe('UserActivateController', function () {
|
||||
beforeEach(function () {
|
||||
this.user = {
|
||||
_id: (this.user_id = 'kwjewkl'),
|
||||
features: {},
|
||||
@@ -34,38 +34,38 @@ describe('UserActivateController', function() {
|
||||
this.res = {}
|
||||
})
|
||||
|
||||
describe('activateAccountPage', function() {
|
||||
beforeEach(function() {
|
||||
describe('activateAccountPage', function () {
|
||||
beforeEach(function () {
|
||||
this.UserGetter.getUser = sinon.stub().callsArgWith(2, null, this.user)
|
||||
this.req.query.user_id = this.user_id
|
||||
this.req.query.token = this.token = 'mock-token-123'
|
||||
})
|
||||
|
||||
it('should 404 without a user_id', function(done) {
|
||||
it('should 404 without a user_id', function (done) {
|
||||
delete this.req.query.user_id
|
||||
this.ErrorController.notFound = () => done()
|
||||
this.UserActivateController.activateAccountPage(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should 404 without a token', function(done) {
|
||||
it('should 404 without a token', function (done) {
|
||||
delete this.req.query.token
|
||||
this.ErrorController.notFound = () => done()
|
||||
this.UserActivateController.activateAccountPage(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should 404 without a valid user_id', function(done) {
|
||||
it('should 404 without a valid user_id', function (done) {
|
||||
this.UserGetter.getUser = sinon.stub().callsArgWith(2, null, null)
|
||||
this.ErrorController.notFound = () => done()
|
||||
this.UserActivateController.activateAccountPage(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should 403 for complex user_id', function(done) {
|
||||
it('should 403 for complex user_id', function (done) {
|
||||
this.ErrorController.forbidden = () => done()
|
||||
this.req.query.user_id = { first_name: 'X' }
|
||||
this.UserActivateController.activateAccountPage(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should redirect activated users to login', function(done) {
|
||||
it('should redirect activated users to login', function (done) {
|
||||
this.user.loginCount = 1
|
||||
this.res.redirect = url => {
|
||||
this.UserGetter.getUser.calledWith(this.user_id).should.equal(true)
|
||||
@@ -75,7 +75,7 @@ describe('UserActivateController', function() {
|
||||
this.UserActivateController.activateAccountPage(this.req, this.res)
|
||||
})
|
||||
|
||||
it('render the activation page if the user has not logged in before', function(done) {
|
||||
it('render the activation page if the user has not logged in before', function (done) {
|
||||
this.user.loginCount = 0
|
||||
this.res.render = (page, opts) => {
|
||||
page.should.equal(VIEW_PATH)
|
||||
|
||||
Reference in New Issue
Block a user