mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-29 23:14:04 -05:00
Merge pull request #2627 from overleaf/jel-decaf-cleanup
Decaf cleanup GitOrigin-RevId: 9e0770ce6c5362ea288fc1706014aacd45608008
This commit is contained in:
parent
509c23def7
commit
403c9ae66b
4 changed files with 90 additions and 139 deletions
|
@ -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) {
|
define(['base'], function(App) {
|
||||||
const countriesList = [
|
const countriesList = [
|
||||||
{ code: 'af', name: 'Afghanistan' },
|
{ code: 'af', name: 'Afghanistan' },
|
||||||
|
@ -408,13 +394,13 @@ define(['base'], function(App) {
|
||||||
'126'
|
'126'
|
||||||
]
|
]
|
||||||
|
|
||||||
for (let domain of Array.from(commonDomains)) {
|
for (let domain of commonDomains) {
|
||||||
for (let tld of Array.from(commonTLDs)) {
|
for (let tld of commonTLDs) {
|
||||||
domainsBlackList[`${domain}.${tld}`] = true
|
domainsBlackList[`${domain}.${tld}`] = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return App.factory('UserAffiliationsDataService', function($http, $q, _) {
|
App.factory('UserAffiliationsDataService', function($http, $q, _) {
|
||||||
const getCountries = () => $q.resolve(countriesList)
|
const getCountries = () => $q.resolve(countriesList)
|
||||||
|
|
||||||
const getDefaultRoleHints = () => $q.resolve(defaultRoleHints)
|
const getDefaultRoleHints = () => $q.resolve(defaultRoleHints)
|
||||||
|
|
|
@ -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 sinon = require('sinon')
|
||||||
const assertCalledWith = sinon.assert.calledWith
|
const assertCalledWith = sinon.assert.calledWith
|
||||||
const assertNotCalled = sinon.assert.notCalled
|
const assertNotCalled = sinon.assert.notCalled
|
||||||
const chai = require('chai')
|
const chai = require('chai')
|
||||||
const should = chai.should()
|
|
||||||
const { assert } = chai
|
const { assert } = chai
|
||||||
const modulePath = '../../../../app/src/Features/User/UserEmailsController.js'
|
const modulePath = '../../../../app/src/Features/User/UserEmailsController.js'
|
||||||
const SandboxedModule = require('sandboxed-module')
|
const SandboxedModule = require('sandboxed-module')
|
||||||
const MockRequest = require('../helpers/MockRequest')
|
const MockRequest = require('../helpers/MockRequest')
|
||||||
const MockResponse = require('../helpers/MockResponse')
|
|
||||||
const Errors = require('../../../../app/src/Features/Errors/Errors')
|
const Errors = require('../../../../app/src/Features/Errors/Errors')
|
||||||
|
|
||||||
describe('UserEmailsController', function() {
|
describe('UserEmailsController', function() {
|
||||||
|
@ -52,7 +38,7 @@ describe('UserEmailsController', function() {
|
||||||
.withArgs('example.com')
|
.withArgs('example.com')
|
||||||
.resolves({ sso_enabled: false })
|
.resolves({ sso_enabled: false })
|
||||||
}
|
}
|
||||||
return (this.UserEmailsController = SandboxedModule.require(modulePath, {
|
this.UserEmailsController = SandboxedModule.require(modulePath, {
|
||||||
globals: {
|
globals: {
|
||||||
console: console
|
console: console
|
||||||
},
|
},
|
||||||
|
@ -68,12 +54,12 @@ describe('UserEmailsController', function() {
|
||||||
'../Errors/Errors': Errors,
|
'../Errors/Errors': Errors,
|
||||||
'logger-sharelatex': {
|
'logger-sharelatex': {
|
||||||
log() {
|
log() {
|
||||||
return console.log(arguments)
|
console.log(arguments)
|
||||||
},
|
},
|
||||||
err() {}
|
err() {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('List', function() {
|
describe('List', function() {
|
||||||
|
@ -83,11 +69,11 @@ describe('UserEmailsController', function() {
|
||||||
const fullEmails = [{ some: 'data' }]
|
const fullEmails = [{ some: 'data' }]
|
||||||
this.UserGetter.getUserFullEmails.callsArgWith(1, null, fullEmails)
|
this.UserGetter.getUserFullEmails.callsArgWith(1, null, fullEmails)
|
||||||
|
|
||||||
return this.UserEmailsController.list(this.req, {
|
this.UserEmailsController.list(this.req, {
|
||||||
json: response => {
|
json: response => {
|
||||||
assert.deepEqual(response, fullEmails)
|
assert.deepEqual(response, fullEmails)
|
||||||
assertCalledWith(this.UserGetter.getUserFullEmails, this.user._id)
|
assertCalledWith(this.UserGetter.getUserFullEmails, this.user._id)
|
||||||
return done()
|
done()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -106,11 +92,11 @@ describe('UserEmailsController', function() {
|
||||||
this.UserEmailsConfirmationHandler.sendConfirmationEmail = sinon
|
this.UserEmailsConfirmationHandler.sendConfirmationEmail = sinon
|
||||||
.stub()
|
.stub()
|
||||||
.yields()
|
.yields()
|
||||||
return this.UserUpdater.addEmailAddress.callsArgWith(3, null)
|
this.UserUpdater.addEmailAddress.callsArgWith(3, null)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('adds new email', function(done) {
|
it('adds new email', function(done) {
|
||||||
return this.UserEmailsController.add(this.req, {
|
this.UserEmailsController.add(this.req, {
|
||||||
sendStatus: code => {
|
sendStatus: code => {
|
||||||
code.should.equal(204)
|
code.should.equal(204)
|
||||||
assertCalledWith(this.EmailHelper.parseEmail, this.newEmail)
|
assertCalledWith(this.EmailHelper.parseEmail, this.newEmail)
|
||||||
|
@ -127,13 +113,13 @@ describe('UserEmailsController', function() {
|
||||||
affiliationOptions.department.should.equal(this.req.body.department)
|
affiliationOptions.department.should.equal(this.req.body.department)
|
||||||
affiliationOptions.role.should.equal(this.req.body.role)
|
affiliationOptions.role.should.equal(this.req.body.role)
|
||||||
|
|
||||||
return done()
|
done()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('sends an email confirmation', function(done) {
|
it('sends an email confirmation', function(done) {
|
||||||
return this.UserEmailsController.add(this.req, {
|
this.UserEmailsController.add(this.req, {
|
||||||
sendStatus: code => {
|
sendStatus: code => {
|
||||||
code.should.equal(204)
|
code.should.equal(204)
|
||||||
assertCalledWith(
|
assertCalledWith(
|
||||||
|
@ -141,18 +127,18 @@ describe('UserEmailsController', function() {
|
||||||
this.user._id,
|
this.user._id,
|
||||||
this.newEmail
|
this.newEmail
|
||||||
)
|
)
|
||||||
return done()
|
done()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('handles email parse error', function(done) {
|
it('handles email parse error', function(done) {
|
||||||
this.EmailHelper.parseEmail.returns(null)
|
this.EmailHelper.parseEmail.returns(null)
|
||||||
return this.UserEmailsController.add(this.req, {
|
this.UserEmailsController.add(this.req, {
|
||||||
sendStatus: code => {
|
sendStatus: code => {
|
||||||
code.should.equal(422)
|
code.should.equal(422)
|
||||||
assertNotCalled(this.UserUpdater.addEmailAddress)
|
assertNotCalled(this.UserUpdater.addEmailAddress)
|
||||||
return done()
|
done()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -162,13 +148,13 @@ describe('UserEmailsController', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
this.email = 'email_to_remove@bar.com'
|
this.email = 'email_to_remove@bar.com'
|
||||||
this.req.body.email = this.email
|
this.req.body.email = this.email
|
||||||
return this.EmailHelper.parseEmail.returns(this.email)
|
this.EmailHelper.parseEmail.returns(this.email)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('removes email', function(done) {
|
it('removes email', function(done) {
|
||||||
this.UserUpdater.removeEmailAddress.callsArgWith(2, null)
|
this.UserUpdater.removeEmailAddress.callsArgWith(2, null)
|
||||||
|
|
||||||
return this.UserEmailsController.remove(this.req, {
|
this.UserEmailsController.remove(this.req, {
|
||||||
sendStatus: code => {
|
sendStatus: code => {
|
||||||
code.should.equal(200)
|
code.should.equal(200)
|
||||||
assertCalledWith(this.EmailHelper.parseEmail, this.email)
|
assertCalledWith(this.EmailHelper.parseEmail, this.email)
|
||||||
|
@ -177,7 +163,7 @@ describe('UserEmailsController', function() {
|
||||||
this.user._id,
|
this.user._id,
|
||||||
this.email
|
this.email
|
||||||
)
|
)
|
||||||
return done()
|
done()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -185,11 +171,11 @@ describe('UserEmailsController', function() {
|
||||||
it('handles email parse error', function(done) {
|
it('handles email parse error', function(done) {
|
||||||
this.EmailHelper.parseEmail.returns(null)
|
this.EmailHelper.parseEmail.returns(null)
|
||||||
|
|
||||||
return this.UserEmailsController.remove(this.req, {
|
this.UserEmailsController.remove(this.req, {
|
||||||
sendStatus: code => {
|
sendStatus: code => {
|
||||||
code.should.equal(422)
|
code.should.equal(422)
|
||||||
assertNotCalled(this.UserUpdater.removeEmailAddress)
|
assertNotCalled(this.UserUpdater.removeEmailAddress)
|
||||||
return done()
|
done()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -232,7 +218,7 @@ describe('UserEmailsController', function() {
|
||||||
sendStatus: code => {
|
sendStatus: code => {
|
||||||
code.should.equal(422)
|
code.should.equal(422)
|
||||||
assertNotCalled(this.UserUpdater.setDefaultEmailAddress)
|
assertNotCalled(this.UserUpdater.setDefaultEmailAddress)
|
||||||
return done()
|
done()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -242,14 +228,14 @@ describe('UserEmailsController', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
this.email = 'email_to_endorse@bar.com'
|
this.email = 'email_to_endorse@bar.com'
|
||||||
this.req.body.email = this.email
|
this.req.body.email = this.email
|
||||||
return this.EmailHelper.parseEmail.returns(this.email)
|
this.EmailHelper.parseEmail.returns(this.email)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('endorses affiliation', function(done) {
|
it('endorses affiliation', function(done) {
|
||||||
this.req.body.role = 'Role'
|
this.req.body.role = 'Role'
|
||||||
this.req.body.department = 'Department'
|
this.req.body.department = 'Department'
|
||||||
|
|
||||||
return this.UserEmailsController.endorse(this.req, {
|
this.UserEmailsController.endorse(this.req, {
|
||||||
sendStatus: code => {
|
sendStatus: code => {
|
||||||
code.should.equal(204)
|
code.should.equal(204)
|
||||||
assertCalledWith(
|
assertCalledWith(
|
||||||
|
@ -259,7 +245,7 @@ describe('UserEmailsController', function() {
|
||||||
'Role',
|
'Role',
|
||||||
'Department'
|
'Department'
|
||||||
)
|
)
|
||||||
return done()
|
done()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -277,33 +263,33 @@ describe('UserEmailsController', function() {
|
||||||
this.res.status = sinon.stub().returns(this.res)
|
this.res.status = sinon.stub().returns(this.res)
|
||||||
this.next = sinon.stub()
|
this.next = sinon.stub()
|
||||||
this.token = 'mock-token'
|
this.token = 'mock-token'
|
||||||
return (this.req.body = { token: this.token })
|
this.req.body = { token: this.token }
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('successfully', function() {
|
describe('successfully', function() {
|
||||||
beforeEach(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() {
|
it('should confirm the email from the token', function() {
|
||||||
return this.UserEmailsConfirmationHandler.confirmEmailFromToken
|
this.UserEmailsConfirmationHandler.confirmEmailFromToken
|
||||||
.calledWith(this.token)
|
.calledWith(this.token)
|
||||||
.should.equal(true)
|
.should.equal(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should return a 200 status', function() {
|
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() {
|
describe('without a token', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
this.req.body.token = null
|
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() {
|
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
|
this.UserEmailsConfirmationHandler.confirmEmailFromToken = sinon
|
||||||
.stub()
|
.stub()
|
||||||
.yields(new Errors.NotFoundError('not found'))
|
.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() {
|
it('should return a 404 error code with a message', function() {
|
||||||
this.res.status.calledWith(404).should.equal(true)
|
this.res.status.calledWith(404).should.equal(true)
|
||||||
return this.res.json
|
this.res.json
|
||||||
.calledWith({
|
.calledWith({
|
||||||
message: this.req.i18n.translate('confirmation_token_invalid')
|
message: this.req.i18n.translate('confirmation_token_invalid')
|
||||||
})
|
})
|
||||||
|
|
|
@ -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 { ObjectId } = require('mongojs')
|
||||||
const should = require('chai').should()
|
const should = require('chai').should()
|
||||||
const SandboxedModule = require('sandboxed-module')
|
const SandboxedModule = require('sandboxed-module')
|
||||||
|
@ -47,7 +35,7 @@ describe('UserGetter', function() {
|
||||||
const settings = { apis: { v1: { url: 'v1.url', user: '', pass: '' } } }
|
const settings = { apis: { v1: { url: 'v1.url', user: '', pass: '' } } }
|
||||||
this.getUserAffiliations = sinon.stub().callsArgWith(1, null, [])
|
this.getUserAffiliations = sinon.stub().callsArgWith(1, null, [])
|
||||||
|
|
||||||
return (this.UserGetter = SandboxedModule.require(modulePath, {
|
this.UserGetter = SandboxedModule.require(modulePath, {
|
||||||
globals: {
|
globals: {
|
||||||
console: console
|
console: console
|
||||||
},
|
},
|
||||||
|
@ -68,25 +56,26 @@ describe('UserGetter', function() {
|
||||||
},
|
},
|
||||||
'../Errors/Errors': Errors
|
'../Errors/Errors': Errors
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('getUser', function() {
|
describe('getUser', function() {
|
||||||
it('should get user', function(done) {
|
it('should get user', function(done) {
|
||||||
const query = { _id: 'foo' }
|
const query = { _id: 'foo' }
|
||||||
const projection = { email: 1 }
|
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.called.should.equal(true)
|
||||||
this.findOne.calledWith(query, projection).should.equal(true)
|
this.findOne.calledWith(query, projection).should.equal(true)
|
||||||
user.should.deep.equal(this.fakeUser)
|
user.should.deep.equal(this.fakeUser)
|
||||||
return done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should not allow null query', function(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
|
error.should.exist
|
||||||
return done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -97,14 +86,15 @@ describe('UserGetter', function() {
|
||||||
.stub()
|
.stub()
|
||||||
.callsArgWith(2, null, this.fakeUser)
|
.callsArgWith(2, null, this.fakeUser)
|
||||||
const projection = { email: 1, emails: 1 }
|
const projection = { email: 1, emails: 1 }
|
||||||
return this.UserGetter.getUserFullEmails(
|
this.UserGetter.getUserFullEmails(
|
||||||
this.fakeUser._id,
|
this.fakeUser._id,
|
||||||
(error, fullEmails) => {
|
(error, fullEmails) => {
|
||||||
|
expect(error).to.not.exist
|
||||||
this.UserGetter.getUser.called.should.equal(true)
|
this.UserGetter.getUser.called.should.equal(true)
|
||||||
this.UserGetter.getUser
|
this.UserGetter.getUser
|
||||||
.calledWith(this.fakeUser._id, projection)
|
.calledWith(this.fakeUser._id, projection)
|
||||||
.should.equal(true)
|
.should.equal(true)
|
||||||
return done()
|
done()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -113,9 +103,10 @@ describe('UserGetter', function() {
|
||||||
this.UserGetter.getUser = sinon
|
this.UserGetter.getUser = sinon
|
||||||
.stub()
|
.stub()
|
||||||
.callsArgWith(2, null, this.fakeUser)
|
.callsArgWith(2, null, this.fakeUser)
|
||||||
return this.UserGetter.getUserFullEmails(
|
this.UserGetter.getUserFullEmails(
|
||||||
this.fakeUser._id,
|
this.fakeUser._id,
|
||||||
(error, fullEmails) => {
|
(error, fullEmails) => {
|
||||||
|
expect(error).to.not.exist
|
||||||
assert.deepEqual(fullEmails, [
|
assert.deepEqual(fullEmails, [
|
||||||
{
|
{
|
||||||
email: 'email1@foo.bar',
|
email: 'email1@foo.bar',
|
||||||
|
@ -128,7 +119,7 @@ describe('UserGetter', function() {
|
||||||
default: true
|
default: true
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
return done()
|
done()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -148,9 +139,10 @@ describe('UserGetter', function() {
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
this.getUserAffiliations.callsArgWith(1, null, affiliationsData)
|
this.getUserAffiliations.callsArgWith(1, null, affiliationsData)
|
||||||
return this.UserGetter.getUserFullEmails(
|
this.UserGetter.getUserFullEmails(
|
||||||
this.fakeUser._id,
|
this.fakeUser._id,
|
||||||
(error, fullEmails) => {
|
(error, fullEmails) => {
|
||||||
|
expect(error).to.not.exist
|
||||||
assert.deepEqual(fullEmails, [
|
assert.deepEqual(fullEmails, [
|
||||||
{
|
{
|
||||||
email: 'email1@foo.bar',
|
email: 'email1@foo.bar',
|
||||||
|
@ -170,7 +162,7 @@ describe('UserGetter', function() {
|
||||||
default: true
|
default: true
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
return done()
|
done()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -184,15 +176,16 @@ describe('UserGetter', function() {
|
||||||
.stub()
|
.stub()
|
||||||
.callsArgWith(2, null, this.fakeUser)
|
.callsArgWith(2, null, this.fakeUser)
|
||||||
const projection = { email: 1, emails: 1 }
|
const projection = { email: 1, emails: 1 }
|
||||||
return this.UserGetter.getUserFullEmails(
|
this.UserGetter.getUserFullEmails(
|
||||||
this.fakeUser._id,
|
this.fakeUser._id,
|
||||||
(error, fullEmails) => {
|
(error, fullEmails) => {
|
||||||
|
expect(error).to.not.exist
|
||||||
this.UserGetter.getUser.called.should.equal(true)
|
this.UserGetter.getUser.called.should.equal(true)
|
||||||
this.UserGetter.getUser
|
this.UserGetter.getUser
|
||||||
.calledWith(this.fakeUser._id, projection)
|
.calledWith(this.fakeUser._id, projection)
|
||||||
.should.equal(true)
|
.should.equal(true)
|
||||||
assert.deepEqual(fullEmails, [])
|
assert.deepEqual(fullEmails, [])
|
||||||
return done()
|
done()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -202,31 +195,30 @@ describe('UserGetter', function() {
|
||||||
it('query user by main email', function(done) {
|
it('query user by main email', function(done) {
|
||||||
const email = 'hello@world.com'
|
const email = 'hello@world.com'
|
||||||
const projection = { emails: 1 }
|
const projection = { emails: 1 }
|
||||||
return this.UserGetter.getUserByMainEmail(
|
this.UserGetter.getUserByMainEmail(email, projection, (error, user) => {
|
||||||
email,
|
expect(error).to.not.exist
|
||||||
projection,
|
|
||||||
(error, user) => {
|
|
||||||
this.findOne.called.should.equal(true)
|
this.findOne.called.should.equal(true)
|
||||||
this.findOne.calledWith({ email }, projection).should.equal(true)
|
this.findOne.calledWith({ email }, projection).should.equal(true)
|
||||||
return done()
|
done()
|
||||||
}
|
})
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('return user if found', function(done) {
|
it('return user if found', function(done) {
|
||||||
const email = 'hello@world.com'
|
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)
|
user.should.deep.equal(this.fakeUser)
|
||||||
return done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('trim email', function(done) {
|
it('trim email', function(done) {
|
||||||
const email = 'hello@world.com'
|
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.called.should.equal(true)
|
||||||
this.findOne.calledWith({ email }).should.equal(true)
|
this.findOne.calledWith({ email }).should.equal(true)
|
||||||
return done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -239,13 +231,14 @@ describe('UserGetter', function() {
|
||||||
'emails.email': email
|
'emails.email': email
|
||||||
}
|
}
|
||||||
const projection = { emails: 1 }
|
const projection = { emails: 1 }
|
||||||
return this.UserGetter.getUserByAnyEmail(
|
this.UserGetter.getUserByAnyEmail(
|
||||||
` ${email} `,
|
` ${email} `,
|
||||||
projection,
|
projection,
|
||||||
(error, user) => {
|
(error, user) => {
|
||||||
|
expect(error).to.not.exist
|
||||||
this.findOne.calledWith(expectedQuery, projection).should.equal(true)
|
this.findOne.calledWith(expectedQuery, projection).should.equal(true)
|
||||||
user.should.deep.equal(this.fakeUser)
|
user.should.deep.equal(this.fakeUser)
|
||||||
return done()
|
done()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -255,9 +248,10 @@ describe('UserGetter', function() {
|
||||||
emails: { $exists: true },
|
emails: { $exists: true },
|
||||||
'emails.email': ''
|
'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)
|
this.findOne.calledWith(expectedQuery, {}).should.equal(true)
|
||||||
return done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -265,13 +259,14 @@ describe('UserGetter', function() {
|
||||||
this.findOne.callsArgWith(2, null, null)
|
this.findOne.callsArgWith(2, null, null)
|
||||||
const email = 'hello@world.com'
|
const email = 'hello@world.com'
|
||||||
const projection = { emails: 1 }
|
const projection = { emails: 1 }
|
||||||
return this.UserGetter.getUserByAnyEmail(
|
this.UserGetter.getUserByAnyEmail(
|
||||||
` ${email} `,
|
` ${email} `,
|
||||||
projection,
|
projection,
|
||||||
(error, user) => {
|
(error, user) => {
|
||||||
|
expect(error).to.not.exist
|
||||||
this.findOne.calledTwice.should.equal(true)
|
this.findOne.calledTwice.should.equal(true)
|
||||||
this.findOne.calledWith({ email }, projection).should.equal(true)
|
this.findOne.calledWith({ email }, projection).should.equal(true)
|
||||||
return done()
|
done()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -288,13 +283,14 @@ describe('UserGetter', function() {
|
||||||
.join('')
|
.join('')
|
||||||
}
|
}
|
||||||
const projection = { emails: 1 }
|
const projection = { emails: 1 }
|
||||||
return this.UserGetter.getUsersByHostname(
|
this.UserGetter.getUsersByHostname(
|
||||||
hostname,
|
hostname,
|
||||||
projection,
|
projection,
|
||||||
(error, users) => {
|
(error, users) => {
|
||||||
|
expect(error).to.not.exist
|
||||||
this.find.calledOnce.should.equal(true)
|
this.find.calledOnce.should.equal(true)
|
||||||
this.find.calledWith(expectedQuery, projection).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 }
|
'overleaf.id': { $in: v1Ids }
|
||||||
}
|
}
|
||||||
const projection = { emails: 1 }
|
const projection = { emails: 1 }
|
||||||
return this.UserGetter.getUsersByV1Ids(
|
this.UserGetter.getUsersByV1Ids(v1Ids, projection, (error, users) => {
|
||||||
v1Ids,
|
expect(error).to.not.exist
|
||||||
projection,
|
|
||||||
(error, users) => {
|
|
||||||
this.find.calledOnce.should.equal(true)
|
this.find.calledOnce.should.equal(true)
|
||||||
this.find.calledWith(expectedQuery, projection).should.equal(true)
|
this.find.calledWith(expectedQuery, projection).should.equal(true)
|
||||||
return done()
|
done()
|
||||||
}
|
})
|
||||||
)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('ensureUniqueEmailAddress', function() {
|
describe('ensureUniqueEmailAddress', function() {
|
||||||
beforeEach(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) {
|
it('should return error if existing user is found', function(done) {
|
||||||
this.UserGetter.getUserByAnyEmail.callsArgWith(1, null, this.fakeUser)
|
this.UserGetter.getUserByAnyEmail.callsArgWith(1, null, this.fakeUser)
|
||||||
return this.UserGetter.ensureUniqueEmailAddress(this.newEmail, err => {
|
this.UserGetter.ensureUniqueEmailAddress(this.newEmail, err => {
|
||||||
should.exist(err)
|
should.exist(err)
|
||||||
expect(err).to.be.an.instanceof(Errors.EmailExistsError)
|
expect(err).to.be.an.instanceof(Errors.EmailExistsError)
|
||||||
return done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should return null if no user is found', function(done) {
|
it('should return null if no user is found', function(done) {
|
||||||
this.UserGetter.getUserByAnyEmail.callsArgWith(1)
|
this.UserGetter.getUserByAnyEmail.callsArgWith(1)
|
||||||
return this.UserGetter.ensureUniqueEmailAddress(this.newEmail, err => {
|
this.UserGetter.ensureUniqueEmailAddress(this.newEmail, err => {
|
||||||
should.not.exist(err)
|
should.not.exist(err)
|
||||||
return done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -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 sinon = require('sinon')
|
||||||
const chai = require('chai')
|
|
||||||
const should = chai.should()
|
|
||||||
const modulePath = '../../../../app/src/Features/User/UserHandler.js'
|
const modulePath = '../../../../app/src/Features/User/UserHandler.js'
|
||||||
const SandboxedModule = require('sandboxed-module')
|
const SandboxedModule = require('sandboxed-module')
|
||||||
|
|
||||||
|
@ -28,23 +14,23 @@ describe('UserHandler', function() {
|
||||||
createTeamInvitesForLegacyInvitedEmail: sinon.stub().yields()
|
createTeamInvitesForLegacyInvitedEmail: sinon.stub().yields()
|
||||||
}
|
}
|
||||||
|
|
||||||
return (this.UserHandler = SandboxedModule.require(modulePath, {
|
this.UserHandler = SandboxedModule.require(modulePath, {
|
||||||
globals: {
|
globals: {
|
||||||
console: console
|
console: console
|
||||||
},
|
},
|
||||||
requires: {
|
requires: {
|
||||||
'../Subscription/TeamInvitesHandler': this.TeamInvitesHandler
|
'../Subscription/TeamInvitesHandler': this.TeamInvitesHandler
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('populateTeamInvites', function() {
|
describe('populateTeamInvites', function() {
|
||||||
beforeEach(function(done) {
|
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() {
|
it('notifies the user about legacy team invites', function() {
|
||||||
return this.TeamInvitesHandler.createTeamInvitesForLegacyInvitedEmail
|
this.TeamInvitesHandler.createTeamInvitesForLegacyInvitedEmail
|
||||||
.calledWith(this.user.email)
|
.calledWith(this.user.email)
|
||||||
.should.eq(true)
|
.should.eq(true)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue