Merge pull request #2627 from overleaf/jel-decaf-cleanup

Decaf cleanup

GitOrigin-RevId: 9e0770ce6c5362ea288fc1706014aacd45608008
This commit is contained in:
Eric Mc Sween 2020-02-27 07:45:53 -05:00 committed by Copybot
parent 509c23def7
commit 403c9ae66b
4 changed files with 90 additions and 139 deletions

View file

@ -1,17 +1,3 @@
/* eslint-disable
max-len,
no-return-assign,
no-undef,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS101: Remove unnecessary use of Array.from
* DS102: Remove unnecessary code created because of implicit returns
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
define(['base'], function(App) {
const countriesList = [
{ code: 'af', name: 'Afghanistan' },
@ -408,13 +394,13 @@ define(['base'], function(App) {
'126'
]
for (let domain of Array.from(commonDomains)) {
for (let tld of Array.from(commonTLDs)) {
for (let domain of commonDomains) {
for (let tld of commonTLDs) {
domainsBlackList[`${domain}.${tld}`] = true
}
}
return App.factory('UserAffiliationsDataService', function($http, $q, _) {
App.factory('UserAffiliationsDataService', function($http, $q, _) {
const getCountries = () => $q.resolve(countriesList)
const getDefaultRoleHints = () => $q.resolve(defaultRoleHints)

View file

@ -1,25 +1,11 @@
/* eslint-disable
max-len,
no-return-assign,
no-unused-vars,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const sinon = require('sinon')
const assertCalledWith = sinon.assert.calledWith
const assertNotCalled = sinon.assert.notCalled
const chai = require('chai')
const should = chai.should()
const { assert } = chai
const modulePath = '../../../../app/src/Features/User/UserEmailsController.js'
const SandboxedModule = require('sandboxed-module')
const MockRequest = require('../helpers/MockRequest')
const MockResponse = require('../helpers/MockResponse')
const Errors = require('../../../../app/src/Features/Errors/Errors')
describe('UserEmailsController', function() {
@ -52,7 +38,7 @@ describe('UserEmailsController', function() {
.withArgs('example.com')
.resolves({ sso_enabled: false })
}
return (this.UserEmailsController = SandboxedModule.require(modulePath, {
this.UserEmailsController = SandboxedModule.require(modulePath, {
globals: {
console: console
},
@ -68,12 +54,12 @@ describe('UserEmailsController', function() {
'../Errors/Errors': Errors,
'logger-sharelatex': {
log() {
return console.log(arguments)
console.log(arguments)
},
err() {}
}
}
}))
})
})
describe('List', function() {
@ -83,11 +69,11 @@ describe('UserEmailsController', function() {
const fullEmails = [{ some: 'data' }]
this.UserGetter.getUserFullEmails.callsArgWith(1, null, fullEmails)
return this.UserEmailsController.list(this.req, {
this.UserEmailsController.list(this.req, {
json: response => {
assert.deepEqual(response, fullEmails)
assertCalledWith(this.UserGetter.getUserFullEmails, this.user._id)
return done()
done()
}
})
})
@ -106,11 +92,11 @@ describe('UserEmailsController', function() {
this.UserEmailsConfirmationHandler.sendConfirmationEmail = sinon
.stub()
.yields()
return this.UserUpdater.addEmailAddress.callsArgWith(3, null)
this.UserUpdater.addEmailAddress.callsArgWith(3, null)
})
it('adds new email', function(done) {
return this.UserEmailsController.add(this.req, {
this.UserEmailsController.add(this.req, {
sendStatus: code => {
code.should.equal(204)
assertCalledWith(this.EmailHelper.parseEmail, this.newEmail)
@ -127,13 +113,13 @@ describe('UserEmailsController', function() {
affiliationOptions.department.should.equal(this.req.body.department)
affiliationOptions.role.should.equal(this.req.body.role)
return done()
done()
}
})
})
it('sends an email confirmation', function(done) {
return this.UserEmailsController.add(this.req, {
this.UserEmailsController.add(this.req, {
sendStatus: code => {
code.should.equal(204)
assertCalledWith(
@ -141,18 +127,18 @@ describe('UserEmailsController', function() {
this.user._id,
this.newEmail
)
return done()
done()
}
})
})
it('handles email parse error', function(done) {
this.EmailHelper.parseEmail.returns(null)
return this.UserEmailsController.add(this.req, {
this.UserEmailsController.add(this.req, {
sendStatus: code => {
code.should.equal(422)
assertNotCalled(this.UserUpdater.addEmailAddress)
return done()
done()
}
})
})
@ -162,13 +148,13 @@ describe('UserEmailsController', function() {
beforeEach(function() {
this.email = 'email_to_remove@bar.com'
this.req.body.email = this.email
return this.EmailHelper.parseEmail.returns(this.email)
this.EmailHelper.parseEmail.returns(this.email)
})
it('removes email', function(done) {
this.UserUpdater.removeEmailAddress.callsArgWith(2, null)
return this.UserEmailsController.remove(this.req, {
this.UserEmailsController.remove(this.req, {
sendStatus: code => {
code.should.equal(200)
assertCalledWith(this.EmailHelper.parseEmail, this.email)
@ -177,7 +163,7 @@ describe('UserEmailsController', function() {
this.user._id,
this.email
)
return done()
done()
}
})
})
@ -185,11 +171,11 @@ describe('UserEmailsController', function() {
it('handles email parse error', function(done) {
this.EmailHelper.parseEmail.returns(null)
return this.UserEmailsController.remove(this.req, {
this.UserEmailsController.remove(this.req, {
sendStatus: code => {
code.should.equal(422)
assertNotCalled(this.UserUpdater.removeEmailAddress)
return done()
done()
}
})
})
@ -232,7 +218,7 @@ describe('UserEmailsController', function() {
sendStatus: code => {
code.should.equal(422)
assertNotCalled(this.UserUpdater.setDefaultEmailAddress)
return done()
done()
}
})
})
@ -242,14 +228,14 @@ describe('UserEmailsController', function() {
beforeEach(function() {
this.email = 'email_to_endorse@bar.com'
this.req.body.email = this.email
return this.EmailHelper.parseEmail.returns(this.email)
this.EmailHelper.parseEmail.returns(this.email)
})
it('endorses affiliation', function(done) {
this.req.body.role = 'Role'
this.req.body.department = 'Department'
return this.UserEmailsController.endorse(this.req, {
this.UserEmailsController.endorse(this.req, {
sendStatus: code => {
code.should.equal(204)
assertCalledWith(
@ -259,7 +245,7 @@ describe('UserEmailsController', function() {
'Role',
'Department'
)
return done()
done()
}
})
})
@ -277,33 +263,33 @@ describe('UserEmailsController', function() {
this.res.status = sinon.stub().returns(this.res)
this.next = sinon.stub()
this.token = 'mock-token'
return (this.req.body = { token: this.token })
this.req.body = { token: this.token }
})
describe('successfully', function() {
beforeEach(function() {
return this.UserEmailsController.confirm(this.req, this.res, this.next)
this.UserEmailsController.confirm(this.req, this.res, this.next)
})
it('should confirm the email from the token', function() {
return this.UserEmailsConfirmationHandler.confirmEmailFromToken
this.UserEmailsConfirmationHandler.confirmEmailFromToken
.calledWith(this.token)
.should.equal(true)
})
it('should return a 200 status', function() {
return this.res.sendStatus.calledWith(200).should.equal(true)
this.res.sendStatus.calledWith(200).should.equal(true)
})
})
describe('without a token', function() {
beforeEach(function() {
this.req.body.token = null
return this.UserEmailsController.confirm(this.req, this.res, this.next)
this.UserEmailsController.confirm(this.req, this.res, this.next)
})
it('should return a 422 status', function() {
return this.res.status.calledWith(422).should.equal(true)
this.res.status.calledWith(422).should.equal(true)
})
})
@ -312,12 +298,12 @@ describe('UserEmailsController', function() {
this.UserEmailsConfirmationHandler.confirmEmailFromToken = sinon
.stub()
.yields(new Errors.NotFoundError('not found'))
return this.UserEmailsController.confirm(this.req, this.res, this.next)
this.UserEmailsController.confirm(this.req, this.res, this.next)
})
it('should return a 404 error code with a message', function() {
this.res.status.calledWith(404).should.equal(true)
return this.res.json
this.res.json
.calledWith({
message: this.req.i18n.translate('confirmation_token_invalid')
})

View file

@ -1,15 +1,3 @@
/* eslint-disable
handle-callback-err,
max-len,
no-return-assign,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const { ObjectId } = require('mongojs')
const should = require('chai').should()
const SandboxedModule = require('sandboxed-module')
@ -47,7 +35,7 @@ describe('UserGetter', function() {
const settings = { apis: { v1: { url: 'v1.url', user: '', pass: '' } } }
this.getUserAffiliations = sinon.stub().callsArgWith(1, null, [])
return (this.UserGetter = SandboxedModule.require(modulePath, {
this.UserGetter = SandboxedModule.require(modulePath, {
globals: {
console: console
},
@ -68,25 +56,26 @@ describe('UserGetter', function() {
},
'../Errors/Errors': Errors
}
}))
})
})
describe('getUser', function() {
it('should get user', function(done) {
const query = { _id: 'foo' }
const projection = { email: 1 }
return this.UserGetter.getUser(query, projection, (error, user) => {
this.UserGetter.getUser(query, projection, (error, user) => {
expect(error).to.not.exist
this.findOne.called.should.equal(true)
this.findOne.calledWith(query, projection).should.equal(true)
user.should.deep.equal(this.fakeUser)
return done()
done()
})
})
it('should not allow null query', function(done) {
return this.UserGetter.getUser(null, {}, (error, user) => {
this.UserGetter.getUser(null, {}, (error, user) => {
error.should.exist
return done()
done()
})
})
})
@ -97,14 +86,15 @@ describe('UserGetter', function() {
.stub()
.callsArgWith(2, null, this.fakeUser)
const projection = { email: 1, emails: 1 }
return this.UserGetter.getUserFullEmails(
this.UserGetter.getUserFullEmails(
this.fakeUser._id,
(error, fullEmails) => {
expect(error).to.not.exist
this.UserGetter.getUser.called.should.equal(true)
this.UserGetter.getUser
.calledWith(this.fakeUser._id, projection)
.should.equal(true)
return done()
done()
}
)
})
@ -113,9 +103,10 @@ describe('UserGetter', function() {
this.UserGetter.getUser = sinon
.stub()
.callsArgWith(2, null, this.fakeUser)
return this.UserGetter.getUserFullEmails(
this.UserGetter.getUserFullEmails(
this.fakeUser._id,
(error, fullEmails) => {
expect(error).to.not.exist
assert.deepEqual(fullEmails, [
{
email: 'email1@foo.bar',
@ -128,7 +119,7 @@ describe('UserGetter', function() {
default: true
}
])
return done()
done()
}
)
})
@ -148,9 +139,10 @@ describe('UserGetter', function() {
}
]
this.getUserAffiliations.callsArgWith(1, null, affiliationsData)
return this.UserGetter.getUserFullEmails(
this.UserGetter.getUserFullEmails(
this.fakeUser._id,
(error, fullEmails) => {
expect(error).to.not.exist
assert.deepEqual(fullEmails, [
{
email: 'email1@foo.bar',
@ -170,7 +162,7 @@ describe('UserGetter', function() {
default: true
}
])
return done()
done()
}
)
})
@ -184,15 +176,16 @@ describe('UserGetter', function() {
.stub()
.callsArgWith(2, null, this.fakeUser)
const projection = { email: 1, emails: 1 }
return this.UserGetter.getUserFullEmails(
this.UserGetter.getUserFullEmails(
this.fakeUser._id,
(error, fullEmails) => {
expect(error).to.not.exist
this.UserGetter.getUser.called.should.equal(true)
this.UserGetter.getUser
.calledWith(this.fakeUser._id, projection)
.should.equal(true)
assert.deepEqual(fullEmails, [])
return done()
done()
}
)
})
@ -202,31 +195,30 @@ describe('UserGetter', function() {
it('query user by main email', function(done) {
const email = 'hello@world.com'
const projection = { emails: 1 }
return this.UserGetter.getUserByMainEmail(
email,
projection,
(error, user) => {
this.findOne.called.should.equal(true)
this.findOne.calledWith({ email }, projection).should.equal(true)
return done()
}
)
this.UserGetter.getUserByMainEmail(email, projection, (error, user) => {
expect(error).to.not.exist
this.findOne.called.should.equal(true)
this.findOne.calledWith({ email }, projection).should.equal(true)
done()
})
})
it('return user if found', function(done) {
const email = 'hello@world.com'
return this.UserGetter.getUserByMainEmail(email, (error, user) => {
this.UserGetter.getUserByMainEmail(email, (error, user) => {
expect(error).to.not.exist
user.should.deep.equal(this.fakeUser)
return done()
done()
})
})
it('trim email', function(done) {
const email = 'hello@world.com'
return this.UserGetter.getUserByMainEmail(` ${email} `, (error, user) => {
this.UserGetter.getUserByMainEmail(` ${email} `, (error, user) => {
expect(error).to.not.exist
this.findOne.called.should.equal(true)
this.findOne.calledWith({ email }).should.equal(true)
return done()
done()
})
})
})
@ -239,13 +231,14 @@ describe('UserGetter', function() {
'emails.email': email
}
const projection = { emails: 1 }
return this.UserGetter.getUserByAnyEmail(
this.UserGetter.getUserByAnyEmail(
` ${email} `,
projection,
(error, user) => {
expect(error).to.not.exist
this.findOne.calledWith(expectedQuery, projection).should.equal(true)
user.should.deep.equal(this.fakeUser)
return done()
done()
}
)
})
@ -255,9 +248,10 @@ describe('UserGetter', function() {
emails: { $exists: true },
'emails.email': ''
}
return this.UserGetter.getUserByAnyEmail('', {}, (error, user) => {
this.UserGetter.getUserByAnyEmail('', {}, (error, user) => {
expect(error).to.not.exist
this.findOne.calledWith(expectedQuery, {}).should.equal(true)
return done()
done()
})
})
@ -265,13 +259,14 @@ describe('UserGetter', function() {
this.findOne.callsArgWith(2, null, null)
const email = 'hello@world.com'
const projection = { emails: 1 }
return this.UserGetter.getUserByAnyEmail(
this.UserGetter.getUserByAnyEmail(
` ${email} `,
projection,
(error, user) => {
expect(error).to.not.exist
this.findOne.calledTwice.should.equal(true)
this.findOne.calledWith({ email }, projection).should.equal(true)
return done()
done()
}
)
})
@ -288,13 +283,14 @@ describe('UserGetter', function() {
.join('')
}
const projection = { emails: 1 }
return this.UserGetter.getUsersByHostname(
this.UserGetter.getUsersByHostname(
hostname,
projection,
(error, users) => {
expect(error).to.not.exist
this.find.calledOnce.should.equal(true)
this.find.calledWith(expectedQuery, projection).should.equal(true)
return done()
done()
}
)
})
@ -307,37 +303,34 @@ describe('UserGetter', function() {
'overleaf.id': { $in: v1Ids }
}
const projection = { emails: 1 }
return this.UserGetter.getUsersByV1Ids(
v1Ids,
projection,
(error, users) => {
this.find.calledOnce.should.equal(true)
this.find.calledWith(expectedQuery, projection).should.equal(true)
return done()
}
)
this.UserGetter.getUsersByV1Ids(v1Ids, projection, (error, users) => {
expect(error).to.not.exist
this.find.calledOnce.should.equal(true)
this.find.calledWith(expectedQuery, projection).should.equal(true)
done()
})
})
})
describe('ensureUniqueEmailAddress', function() {
beforeEach(function() {
return (this.UserGetter.getUserByAnyEmail = sinon.stub())
this.UserGetter.getUserByAnyEmail = sinon.stub()
})
it('should return error if existing user is found', function(done) {
this.UserGetter.getUserByAnyEmail.callsArgWith(1, null, this.fakeUser)
return this.UserGetter.ensureUniqueEmailAddress(this.newEmail, err => {
this.UserGetter.ensureUniqueEmailAddress(this.newEmail, err => {
should.exist(err)
expect(err).to.be.an.instanceof(Errors.EmailExistsError)
return done()
done()
})
})
it('should return null if no user is found', function(done) {
this.UserGetter.getUserByAnyEmail.callsArgWith(1)
return this.UserGetter.ensureUniqueEmailAddress(this.newEmail, err => {
this.UserGetter.ensureUniqueEmailAddress(this.newEmail, err => {
should.not.exist(err)
return done()
done()
})
})
})

View file

@ -1,18 +1,4 @@
/* eslint-disable
max-len,
no-return-assign,
no-unused-vars,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const sinon = require('sinon')
const chai = require('chai')
const should = chai.should()
const modulePath = '../../../../app/src/Features/User/UserHandler.js'
const SandboxedModule = require('sandboxed-module')
@ -28,23 +14,23 @@ describe('UserHandler', function() {
createTeamInvitesForLegacyInvitedEmail: sinon.stub().yields()
}
return (this.UserHandler = SandboxedModule.require(modulePath, {
this.UserHandler = SandboxedModule.require(modulePath, {
globals: {
console: console
},
requires: {
'../Subscription/TeamInvitesHandler': this.TeamInvitesHandler
}
}))
})
})
describe('populateTeamInvites', function() {
beforeEach(function(done) {
return this.UserHandler.populateTeamInvites(this.user, done)
this.UserHandler.populateTeamInvites(this.user, done)
})
it('notifies the user about legacy team invites', function() {
return this.TeamInvitesHandler.createTeamInvitesForLegacyInvitedEmail
this.TeamInvitesHandler.createTeamInvitesForLegacyInvitedEmail
.calledWith(this.user.email)
.should.eq(true)
})