mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-06 07:39:02 +02:00
Merge pull request #3495 from overleaf/ae-prettier-2
Upgrade Prettier to v2 GitOrigin-RevId: 85aa3fa1acb6332c4f58c46165a43d1a51471f33
This commit is contained in:
@@ -5,10 +5,10 @@ const SandboxedModule = require('sandboxed-module')
|
||||
const Errors = require('../../../../app/src/Features/Errors/Errors')
|
||||
const modulePath = '../../../../app/src/Features/User/SAMLIdentityManager.js'
|
||||
|
||||
describe('SAMLIdentityManager', function() {
|
||||
describe('SAMLIdentityManager', function () {
|
||||
const linkedEmail = 'another@example.com'
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
this.userId = '6005c75b12cbcaf771f4a105'
|
||||
this.user = {
|
||||
_id: this.userId,
|
||||
@@ -97,8 +97,8 @@ describe('SAMLIdentityManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('getUser', function() {
|
||||
it('should throw an error if missing provider ID and/or external user ID', async function() {
|
||||
describe('getUser', function () {
|
||||
it('should throw an error if missing provider ID and/or external user ID', async function () {
|
||||
let error
|
||||
try {
|
||||
await this.SAMLIdentityManager.getUser(null, null)
|
||||
@@ -110,15 +110,15 @@ describe('SAMLIdentityManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('linkAccounts', function() {
|
||||
describe('errors', function() {
|
||||
beforeEach(function() {
|
||||
describe('linkAccounts', function () {
|
||||
describe('errors', function () {
|
||||
beforeEach(function () {
|
||||
// first call is to get userWithProvider; should be falsy
|
||||
this.UserGetter.promises.getUser.onFirstCall().resolves()
|
||||
this.UserGetter.promises.getUser.onSecondCall().resolves(this.user)
|
||||
})
|
||||
|
||||
it('should throw an error if missing data', async function() {
|
||||
it('should throw an error if missing data', async function () {
|
||||
let error
|
||||
try {
|
||||
await this.SAMLIdentityManager.linkAccounts(
|
||||
@@ -135,14 +135,14 @@ describe('SAMLIdentityManager', function() {
|
||||
}
|
||||
})
|
||||
|
||||
describe('when email is already associated with another Overleaf account', function() {
|
||||
beforeEach(function() {
|
||||
describe('when email is already associated with another Overleaf account', function () {
|
||||
beforeEach(function () {
|
||||
this.UserGetter.promises.getUserByAnyEmail.resolves(
|
||||
this.userEmailExists
|
||||
)
|
||||
})
|
||||
|
||||
it('should throw an EmailExistsError error', async function() {
|
||||
it('should throw an EmailExistsError error', async function () {
|
||||
let error
|
||||
try {
|
||||
await this.SAMLIdentityManager.linkAccounts(
|
||||
@@ -166,8 +166,8 @@ describe('SAMLIdentityManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when email is not affiliated', function() {
|
||||
beforeEach(function() {
|
||||
describe('when email is not affiliated', function () {
|
||||
beforeEach(function () {
|
||||
this.UserGetter.promises.getUserByAnyEmail.resolves(this.user)
|
||||
this.UserGetter.promises.getUserFullEmails.resolves([
|
||||
{
|
||||
@@ -176,7 +176,7 @@ describe('SAMLIdentityManager', function() {
|
||||
])
|
||||
})
|
||||
|
||||
it('should throw SAMLEmailNotAffiliatedError', async function() {
|
||||
it('should throw SAMLEmailNotAffiliatedError', async function () {
|
||||
let error
|
||||
try {
|
||||
await this.SAMLIdentityManager.linkAccounts(
|
||||
@@ -200,8 +200,8 @@ describe('SAMLIdentityManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when email is affiliated with another institution', function() {
|
||||
beforeEach(function() {
|
||||
describe('when email is affiliated with another institution', function () {
|
||||
beforeEach(function () {
|
||||
this.UserGetter.promises.getUserByAnyEmail.resolves(this.user)
|
||||
this.UserGetter.promises.getUserFullEmails.resolves([
|
||||
{
|
||||
@@ -211,7 +211,7 @@ describe('SAMLIdentityManager', function() {
|
||||
])
|
||||
})
|
||||
|
||||
it('should throw SAMLEmailAffiliatedWithAnotherInstitutionError', async function() {
|
||||
it('should throw SAMLEmailAffiliatedWithAnotherInstitutionError', async function () {
|
||||
let error
|
||||
try {
|
||||
await this.SAMLIdentityManager.linkAccounts(
|
||||
@@ -237,14 +237,14 @@ describe('SAMLIdentityManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when institution identifier is already associated with another Overleaf account', function() {
|
||||
beforeEach(function() {
|
||||
describe('when institution identifier is already associated with another Overleaf account', function () {
|
||||
beforeEach(function () {
|
||||
this.UserGetter.promises.getUserByAnyEmail.resolves(
|
||||
this.userAlreadyLinked
|
||||
)
|
||||
})
|
||||
|
||||
it('should throw an SAMLIdentityExistsError error', async function() {
|
||||
it('should throw an SAMLIdentityExistsError error', async function () {
|
||||
let error
|
||||
try {
|
||||
await this.SAMLIdentityManager.linkAccounts(
|
||||
@@ -268,13 +268,13 @@ describe('SAMLIdentityManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when institution provider is already associated with the user', function() {
|
||||
beforeEach(function() {
|
||||
describe('when institution provider is already associated with the user', function () {
|
||||
beforeEach(function () {
|
||||
// first call is to get userWithProvider; resolves with any user
|
||||
this.UserGetter.promises.getUser.onFirstCall().resolves(this.user)
|
||||
})
|
||||
|
||||
it('should throw an SAMLAlreadyLinkedError error', async function() {
|
||||
it('should throw an SAMLAlreadyLinkedError error', async function () {
|
||||
let error
|
||||
try {
|
||||
await this.SAMLIdentityManager.linkAccounts(
|
||||
@@ -304,7 +304,7 @@ describe('SAMLIdentityManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should pass back errors via UserAuditLogHandler', async function() {
|
||||
it('should pass back errors via UserAuditLogHandler', async function () {
|
||||
let error
|
||||
const anError = new Error('oops')
|
||||
this.UserAuditLogHandler.promises.addEntry.rejects(anError)
|
||||
@@ -332,14 +332,14 @@ describe('SAMLIdentityManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('success', function() {
|
||||
beforeEach(function() {
|
||||
describe('success', function () {
|
||||
beforeEach(function () {
|
||||
// first call is to get userWithProvider; should be falsy
|
||||
this.UserGetter.promises.getUser.onFirstCall().resolves()
|
||||
this.UserGetter.promises.getUser.onSecondCall().resolves(this.user)
|
||||
})
|
||||
|
||||
it('should update the user audit log', function() {
|
||||
it('should update the user audit log', function () {
|
||||
const auditLog = {
|
||||
intiatorId: '6005c75b12cbcaf771f4a105',
|
||||
ip: '0:0:0:0'
|
||||
@@ -370,7 +370,7 @@ describe('SAMLIdentityManager', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should send an email notification', function() {
|
||||
it('should send an email notification', function () {
|
||||
this.SAMLIdentityManager.linkAccounts(
|
||||
this.user._id,
|
||||
'externalUserId',
|
||||
@@ -397,8 +397,8 @@ describe('SAMLIdentityManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('unlinkAccounts', function() {
|
||||
it('should update the audit log', async function() {
|
||||
describe('unlinkAccounts', function () {
|
||||
it('should update the audit log', async function () {
|
||||
await this.SAMLIdentityManager.unlinkAccounts(
|
||||
this.user._id,
|
||||
linkedEmail,
|
||||
@@ -421,7 +421,7 @@ describe('SAMLIdentityManager', function() {
|
||||
}
|
||||
)
|
||||
})
|
||||
it('should remove the identifier', async function() {
|
||||
it('should remove the identifier', async function () {
|
||||
await this.SAMLIdentityManager.unlinkAccounts(
|
||||
this.user._id,
|
||||
linkedEmail,
|
||||
@@ -445,7 +445,7 @@ describe('SAMLIdentityManager', function() {
|
||||
update
|
||||
)
|
||||
})
|
||||
it('should send an email notification', async function() {
|
||||
it('should send an email notification', async function () {
|
||||
await this.SAMLIdentityManager.unlinkAccounts(
|
||||
this.user._id,
|
||||
linkedEmail,
|
||||
@@ -464,8 +464,8 @@ describe('SAMLIdentityManager', function() {
|
||||
expect(emailArgs[1].message[0]).to.contain(linkedEmail)
|
||||
})
|
||||
|
||||
describe('errors', function() {
|
||||
it('should pass back errors via UserAuditLogHandler', async function() {
|
||||
describe('errors', function () {
|
||||
it('should pass back errors via UserAuditLogHandler', async function () {
|
||||
let error
|
||||
const anError = new Error('oops')
|
||||
this.UserAuditLogHandler.promises.addEntry.rejects(anError)
|
||||
@@ -490,43 +490,43 @@ describe('SAMLIdentityManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('entitlementAttributeMatches', function() {
|
||||
it('should return true when entitlement matches on string', function() {
|
||||
describe('entitlementAttributeMatches', function () {
|
||||
it('should return true when entitlement matches on string', function () {
|
||||
this.SAMLIdentityManager.entitlementAttributeMatches(
|
||||
'foo bar',
|
||||
'bar'
|
||||
).should.equal(true)
|
||||
})
|
||||
|
||||
it('should return false when entitlement does not match on string', function() {
|
||||
it('should return false when entitlement does not match on string', function () {
|
||||
this.SAMLIdentityManager.entitlementAttributeMatches(
|
||||
'foo bar',
|
||||
'bam'
|
||||
).should.equal(false)
|
||||
})
|
||||
|
||||
it('should return false on an invalid matcher', function() {
|
||||
it('should return false on an invalid matcher', function () {
|
||||
this.SAMLIdentityManager.entitlementAttributeMatches(
|
||||
'foo bar',
|
||||
'('
|
||||
).should.equal(false)
|
||||
})
|
||||
|
||||
it('should log error on an invalid matcher', function() {
|
||||
it('should log error on an invalid matcher', function () {
|
||||
this.SAMLIdentityManager.entitlementAttributeMatches('foo bar', '(')
|
||||
this.logger.error.firstCall.args[0].err.message.should.equal(
|
||||
'Invalid regular expression: /(/: Unterminated group'
|
||||
)
|
||||
})
|
||||
|
||||
it('should return true when entitlement matches on array', function() {
|
||||
it('should return true when entitlement matches on array', function () {
|
||||
this.SAMLIdentityManager.entitlementAttributeMatches(
|
||||
['foo', 'bar'],
|
||||
'bar'
|
||||
).should.equal(true)
|
||||
})
|
||||
|
||||
it('should return false when entitlement does not match array', function() {
|
||||
it('should return false when entitlement does not match array', function () {
|
||||
this.SAMLIdentityManager.entitlementAttributeMatches(
|
||||
['foo', 'bar'],
|
||||
'bam'
|
||||
@@ -534,19 +534,19 @@ describe('SAMLIdentityManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('redundantSubscription', function() {
|
||||
describe('redundantSubscription', function () {
|
||||
const userId = '1bv'
|
||||
const providerId = 123
|
||||
const providerName = 'University Name'
|
||||
describe('with a personal subscription', function() {
|
||||
beforeEach(function() {
|
||||
describe('with a personal subscription', function () {
|
||||
beforeEach(function () {
|
||||
this.SubscriptionLocator.promises.getUserIndividualSubscription.resolves(
|
||||
{
|
||||
planCode: 'professional'
|
||||
}
|
||||
)
|
||||
})
|
||||
it('should create redundant personal subscription notification ', async function() {
|
||||
it('should create redundant personal subscription notification ', async function () {
|
||||
try {
|
||||
await this.SAMLIdentityManager.redundantSubscription(
|
||||
userId,
|
||||
@@ -560,8 +560,8 @@ describe('SAMLIdentityManager', function() {
|
||||
.to.have.been.calledOnce
|
||||
})
|
||||
})
|
||||
describe('without a personal subscription', function() {
|
||||
it('should create redundant personal subscription notification ', async function() {
|
||||
describe('without a personal subscription', function () {
|
||||
it('should create redundant personal subscription notification ', async function () {
|
||||
try {
|
||||
await this.SAMLIdentityManager.redundantSubscription(
|
||||
userId,
|
||||
|
||||
@@ -4,8 +4,8 @@ const SandboxedModule = require('sandboxed-module')
|
||||
const modulePath =
|
||||
'../../../../app/src/Features/User/ThirdPartyIdentityManager.js'
|
||||
|
||||
describe('ThirdPartyIdentityManager', function() {
|
||||
beforeEach(function() {
|
||||
describe('ThirdPartyIdentityManager', function () {
|
||||
beforeEach(function () {
|
||||
this.userId = 'a1b2c3'
|
||||
this.user = {
|
||||
_id: this.userId,
|
||||
@@ -41,8 +41,8 @@ describe('ThirdPartyIdentityManager', function() {
|
||||
}
|
||||
})
|
||||
})
|
||||
describe('getUser', function() {
|
||||
it('should an error when missing providerId or externalUserId', function(done) {
|
||||
describe('getUser', function () {
|
||||
it('should an error when missing providerId or externalUserId', function (done) {
|
||||
this.ThirdPartyIdentityManager.getUser(
|
||||
undefined,
|
||||
undefined,
|
||||
@@ -57,12 +57,12 @@ describe('ThirdPartyIdentityManager', function() {
|
||||
}
|
||||
)
|
||||
})
|
||||
describe('when user linked', function() {
|
||||
beforeEach(function() {
|
||||
describe('when user linked', function () {
|
||||
beforeEach(function () {
|
||||
this.User.findOne.yields(undefined, this.user)
|
||||
})
|
||||
|
||||
it('should return the user', async function() {
|
||||
it('should return the user', async function () {
|
||||
this.User.findOne.returns(undefined, this.user)
|
||||
const user = await this.ThirdPartyIdentityManager.promises.getUser(
|
||||
'google',
|
||||
@@ -71,7 +71,7 @@ describe('ThirdPartyIdentityManager', function() {
|
||||
expect(user).to.deep.equal(this.user)
|
||||
})
|
||||
})
|
||||
it('should return ThirdPartyUserNotFoundError when no user linked', function(done) {
|
||||
it('should return ThirdPartyUserNotFoundError when no user linked', function (done) {
|
||||
this.ThirdPartyIdentityManager.getUser(
|
||||
'google',
|
||||
'an-id-not-linked',
|
||||
@@ -83,8 +83,8 @@ describe('ThirdPartyIdentityManager', function() {
|
||||
)
|
||||
})
|
||||
})
|
||||
describe('link', function() {
|
||||
it('should send email alert', async function() {
|
||||
describe('link', function () {
|
||||
it('should send email alert', async function () {
|
||||
await this.ThirdPartyIdentityManager.promises.link(
|
||||
this.userId,
|
||||
'google',
|
||||
@@ -99,7 +99,7 @@ describe('ThirdPartyIdentityManager', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should update user audit log', async function() {
|
||||
it('should update user audit log', async function () {
|
||||
await this.ThirdPartyIdentityManager.promises.link(
|
||||
this.userId,
|
||||
'google',
|
||||
@@ -117,9 +117,9 @@ describe('ThirdPartyIdentityManager', function() {
|
||||
}
|
||||
)
|
||||
})
|
||||
describe('errors', function() {
|
||||
describe('errors', function () {
|
||||
const anError = new Error('oops')
|
||||
it('should not unlink if the UserAuditLogHandler throws an error', function(done) {
|
||||
it('should not unlink if the UserAuditLogHandler throws an error', function (done) {
|
||||
this.UserAuditLogHandler.addEntry.yields(anError)
|
||||
this.ThirdPartyIdentityManager.link(
|
||||
this.userId,
|
||||
@@ -135,11 +135,11 @@ describe('ThirdPartyIdentityManager', function() {
|
||||
}
|
||||
)
|
||||
})
|
||||
describe('EmailHandler', function() {
|
||||
beforeEach(function() {
|
||||
describe('EmailHandler', function () {
|
||||
beforeEach(function () {
|
||||
this.EmailHandler.sendEmail.yields(anError)
|
||||
})
|
||||
it('should log but not return the error', function(done) {
|
||||
it('should log but not return the error', function (done) {
|
||||
this.ThirdPartyIdentityManager.link(
|
||||
this.userId,
|
||||
'google',
|
||||
@@ -162,8 +162,8 @@ describe('ThirdPartyIdentityManager', function() {
|
||||
})
|
||||
})
|
||||
})
|
||||
describe('unlink', function() {
|
||||
it('should send email alert', async function() {
|
||||
describe('unlink', function () {
|
||||
it('should send email alert', async function () {
|
||||
await this.ThirdPartyIdentityManager.promises.unlink(
|
||||
this.userId,
|
||||
'orcid',
|
||||
@@ -175,7 +175,7 @@ describe('ThirdPartyIdentityManager', function() {
|
||||
'an Orcid account was unlinked from'
|
||||
)
|
||||
})
|
||||
it('should update user audit log', async function() {
|
||||
it('should update user audit log', async function () {
|
||||
await this.ThirdPartyIdentityManager.promises.unlink(
|
||||
this.userId,
|
||||
'orcid',
|
||||
@@ -191,9 +191,9 @@ describe('ThirdPartyIdentityManager', function() {
|
||||
}
|
||||
)
|
||||
})
|
||||
describe('errors', function() {
|
||||
describe('errors', function () {
|
||||
const anError = new Error('oops')
|
||||
it('should not unlink if the UserAuditLogHandler throws an error', function(done) {
|
||||
it('should not unlink if the UserAuditLogHandler throws an error', function (done) {
|
||||
this.UserAuditLogHandler.addEntry.yields(anError)
|
||||
this.ThirdPartyIdentityManager.unlink(
|
||||
this.userId,
|
||||
@@ -208,11 +208,11 @@ describe('ThirdPartyIdentityManager', function() {
|
||||
)
|
||||
expect(this.User.findOneAndUpdate).to.not.have.been.called
|
||||
})
|
||||
describe('EmailHandler', function() {
|
||||
beforeEach(function() {
|
||||
describe('EmailHandler', function () {
|
||||
beforeEach(function () {
|
||||
this.EmailHandler.sendEmail.yields(anError)
|
||||
})
|
||||
it('should log but not return the error', function(done) {
|
||||
it('should log but not return the error', function (done) {
|
||||
this.ThirdPartyIdentityManager.unlink(
|
||||
this.userId,
|
||||
'google',
|
||||
|
||||
@@ -6,8 +6,8 @@ const { User } = require('../helpers/models/User')
|
||||
|
||||
const MODULE_PATH = '../../../../app/src/Features/User/UserAuditLogHandler'
|
||||
|
||||
describe('UserAuditLogHandler', function() {
|
||||
beforeEach(function() {
|
||||
describe('UserAuditLogHandler', function () {
|
||||
beforeEach(function () {
|
||||
this.userId = ObjectId()
|
||||
this.initiatorId = ObjectId()
|
||||
this.action = {
|
||||
@@ -31,18 +31,18 @@ describe('UserAuditLogHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
this.UserMock.restore()
|
||||
})
|
||||
|
||||
describe('addEntry', function() {
|
||||
describe('success', function() {
|
||||
beforeEach(function() {
|
||||
describe('addEntry', function () {
|
||||
describe('success', function () {
|
||||
beforeEach(function () {
|
||||
this.dbUpdate = this.UserMock.expects('updateOne')
|
||||
.chain('exec')
|
||||
.resolves({ nModified: 1 })
|
||||
})
|
||||
it('writes a log', async function() {
|
||||
it('writes a log', async function () {
|
||||
await this.UserAuditLogHandler.promises.addEntry(
|
||||
this.userId,
|
||||
this.action.operation,
|
||||
@@ -53,7 +53,7 @@ describe('UserAuditLogHandler', function() {
|
||||
this.UserMock.verify()
|
||||
})
|
||||
|
||||
it('updates the log for password reset operation witout a initiatorId', async function() {
|
||||
it('updates the log for password reset operation witout a initiatorId', async function () {
|
||||
await expect(
|
||||
this.UserAuditLogHandler.promises.addEntry(
|
||||
this.userId,
|
||||
@@ -67,15 +67,15 @@ describe('UserAuditLogHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('errors', function() {
|
||||
describe('when the user does not exist', function() {
|
||||
beforeEach(function() {
|
||||
describe('errors', function () {
|
||||
describe('when the user does not exist', function () {
|
||||
beforeEach(function () {
|
||||
this.UserMock.expects('updateOne')
|
||||
.chain('exec')
|
||||
.resolves({ nModified: 0 })
|
||||
})
|
||||
|
||||
it('throws an error', async function() {
|
||||
it('throws an error', async function () {
|
||||
await expect(
|
||||
this.UserAuditLogHandler.promises.addEntry(
|
||||
this.userId,
|
||||
@@ -88,8 +88,8 @@ describe('UserAuditLogHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('missing parameters', function() {
|
||||
it('throws an error when no operation', async function() {
|
||||
describe('missing parameters', function () {
|
||||
it('throws an error when no operation', async function () {
|
||||
await expect(
|
||||
this.UserAuditLogHandler.promises.addEntry(
|
||||
this.userId,
|
||||
@@ -101,7 +101,7 @@ describe('UserAuditLogHandler', function() {
|
||||
).to.be.rejected
|
||||
})
|
||||
|
||||
it('throws an error when no IP', async function() {
|
||||
it('throws an error when no IP', async function () {
|
||||
await expect(
|
||||
this.UserAuditLogHandler.promises.addEntry(
|
||||
this.userId,
|
||||
@@ -113,7 +113,7 @@ describe('UserAuditLogHandler', function() {
|
||||
).to.be.rejected
|
||||
})
|
||||
|
||||
it('throws an error when no initiatorId and not a password reset operation', async function() {
|
||||
it('throws an error when no initiatorId and not a password reset operation', async function () {
|
||||
await expect(
|
||||
this.UserAuditLogHandler.promises.addEntry(
|
||||
this.userId,
|
||||
|
||||
@@ -5,8 +5,8 @@ const SandboxedModule = require('sandboxed-module')
|
||||
const OError = require('@overleaf/o-error')
|
||||
const Errors = require('../../../../app/src/Features/Errors/Errors')
|
||||
|
||||
describe('UserController', function() {
|
||||
beforeEach(function() {
|
||||
describe('UserController', function () {
|
||||
beforeEach(function () {
|
||||
this.user_id = '323123'
|
||||
|
||||
this.user = {
|
||||
@@ -137,8 +137,8 @@ describe('UserController', function() {
|
||||
this.callback = sinon.stub()
|
||||
})
|
||||
|
||||
describe('tryDeleteUser', function() {
|
||||
beforeEach(function() {
|
||||
describe('tryDeleteUser', function () {
|
||||
beforeEach(function () {
|
||||
this.req.body.password = 'wat'
|
||||
this.req.logout = sinon.stub()
|
||||
this.req.session.destroy = sinon.stub().callsArgWith(0, null)
|
||||
@@ -150,7 +150,7 @@ describe('UserController', function() {
|
||||
.callsArgWith(2, null, this.user)
|
||||
})
|
||||
|
||||
it('should send 200', function(done) {
|
||||
it('should send 200', function (done) {
|
||||
this.res.sendStatus = code => {
|
||||
code.should.equal(200)
|
||||
done()
|
||||
@@ -158,7 +158,7 @@ describe('UserController', function() {
|
||||
this.UserController.tryDeleteUser(this.req, this.res, this.next)
|
||||
})
|
||||
|
||||
it('should try to authenticate user', function(done) {
|
||||
it('should try to authenticate user', function (done) {
|
||||
this.res.sendStatus = code => {
|
||||
this.AuthenticationManager.authenticate.callCount.should.equal(1)
|
||||
this.AuthenticationManager.authenticate
|
||||
@@ -169,7 +169,7 @@ describe('UserController', function() {
|
||||
this.UserController.tryDeleteUser(this.req, this.res, this.next)
|
||||
})
|
||||
|
||||
it('should delete the user', function(done) {
|
||||
it('should delete the user', function (done) {
|
||||
this.res.sendStatus = code => {
|
||||
this.UserDeleter.deleteUser.callCount.should.equal(1)
|
||||
this.UserDeleter.deleteUser.calledWith(this.user._id).should.equal(true)
|
||||
@@ -178,12 +178,12 @@ describe('UserController', function() {
|
||||
this.UserController.tryDeleteUser(this.req, this.res, this.next)
|
||||
})
|
||||
|
||||
describe('when no password is supplied', function() {
|
||||
beforeEach(function() {
|
||||
describe('when no password is supplied', function () {
|
||||
beforeEach(function () {
|
||||
this.req.body.password = ''
|
||||
})
|
||||
|
||||
it('should return 403', function(done) {
|
||||
it('should return 403', function (done) {
|
||||
this.res.sendStatus = code => {
|
||||
code.should.equal(403)
|
||||
done()
|
||||
@@ -192,14 +192,14 @@ describe('UserController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when authenticate produces an error', function() {
|
||||
beforeEach(function() {
|
||||
describe('when authenticate produces an error', function () {
|
||||
beforeEach(function () {
|
||||
this.AuthenticationManager.authenticate = sinon
|
||||
.stub()
|
||||
.callsArgWith(2, new Error('woops'))
|
||||
})
|
||||
|
||||
it('should call next with an error', function(done) {
|
||||
it('should call next with an error', function (done) {
|
||||
this.next = err => {
|
||||
expect(err).to.not.equal(null)
|
||||
expect(err).to.be.instanceof(Error)
|
||||
@@ -209,14 +209,14 @@ describe('UserController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when authenticate does not produce a user', function() {
|
||||
beforeEach(function() {
|
||||
describe('when authenticate does not produce a user', function () {
|
||||
beforeEach(function () {
|
||||
this.AuthenticationManager.authenticate = sinon
|
||||
.stub()
|
||||
.callsArgWith(2, null, null)
|
||||
})
|
||||
|
||||
it('should return 403', function(done) {
|
||||
it('should return 403', function (done) {
|
||||
this.res.sendStatus = code => {
|
||||
code.should.equal(403)
|
||||
done()
|
||||
@@ -225,12 +225,12 @@ describe('UserController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when deleteUser produces an error', function() {
|
||||
beforeEach(function() {
|
||||
describe('when deleteUser produces an error', function () {
|
||||
beforeEach(function () {
|
||||
this.UserDeleter.deleteUser = sinon.stub().yields(new Error('woops'))
|
||||
})
|
||||
|
||||
it('should call next with an error', function(done) {
|
||||
it('should call next with an error', function (done) {
|
||||
this.next = err => {
|
||||
expect(err).to.not.equal(null)
|
||||
expect(err).to.be.instanceof(Error)
|
||||
@@ -240,14 +240,14 @@ describe('UserController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when deleteUser produces a known error', function() {
|
||||
beforeEach(function() {
|
||||
describe('when deleteUser produces a known error', function () {
|
||||
beforeEach(function () {
|
||||
this.UserDeleter.deleteUser = sinon
|
||||
.stub()
|
||||
.yields(new Errors.SubscriptionAdminDeletionError())
|
||||
})
|
||||
|
||||
it('should return a HTTP Unprocessable Entity error', function(done) {
|
||||
it('should return a HTTP Unprocessable Entity error', function (done) {
|
||||
this.HttpErrorHandler.unprocessableEntity = sinon.spy(
|
||||
(req, res, message, info) => {
|
||||
expect(req).to.exist
|
||||
@@ -263,14 +263,14 @@ describe('UserController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when session.destroy produces an error', function() {
|
||||
beforeEach(function() {
|
||||
describe('when session.destroy produces an error', function () {
|
||||
beforeEach(function () {
|
||||
this.req.session.destroy = sinon
|
||||
.stub()
|
||||
.callsArgWith(0, new Error('woops'))
|
||||
})
|
||||
|
||||
it('should call next with an error', function(done) {
|
||||
it('should call next with an error', function (done) {
|
||||
this.next = err => {
|
||||
expect(err).to.not.equal(null)
|
||||
expect(err).to.be.instanceof(Error)
|
||||
@@ -281,8 +281,8 @@ describe('UserController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('unsubscribe', function() {
|
||||
it('should send the user to unsubscribe', function(done) {
|
||||
describe('unsubscribe', function () {
|
||||
it('should send the user to unsubscribe', function (done) {
|
||||
this.res.sendStatus = () => {
|
||||
this.NewsLetterManager.unsubscribe
|
||||
.calledWith(this.user)
|
||||
@@ -293,14 +293,14 @@ describe('UserController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('updateUserSettings', function() {
|
||||
beforeEach(function() {
|
||||
describe('updateUserSettings', function () {
|
||||
beforeEach(function () {
|
||||
this.auditLog = { initiatorId: this.user_id, ipAddress: this.req.ip }
|
||||
this.newEmail = 'hello@world.com'
|
||||
this.req.externalAuthenticationSystemUsed = sinon.stub().returns(false)
|
||||
})
|
||||
|
||||
it('should call save', function(done) {
|
||||
it('should call save', function (done) {
|
||||
this.req.body = {}
|
||||
this.res.sendStatus = code => {
|
||||
this.user.save.called.should.equal(true)
|
||||
@@ -309,7 +309,7 @@ describe('UserController', function() {
|
||||
this.UserController.updateUserSettings(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should set the first name', function(done) {
|
||||
it('should set the first name', function (done) {
|
||||
this.req.body = { first_name: 'bobby ' }
|
||||
this.res.sendStatus = code => {
|
||||
this.user.first_name.should.equal('bobby')
|
||||
@@ -318,7 +318,7 @@ describe('UserController', function() {
|
||||
this.UserController.updateUserSettings(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should set the role', function(done) {
|
||||
it('should set the role', function (done) {
|
||||
this.req.body = { role: 'student' }
|
||||
this.res.sendStatus = code => {
|
||||
this.user.role.should.equal('student')
|
||||
@@ -327,7 +327,7 @@ describe('UserController', function() {
|
||||
this.UserController.updateUserSettings(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should set the institution', function(done) {
|
||||
it('should set the institution', function (done) {
|
||||
this.req.body = { institution: 'MIT' }
|
||||
this.res.sendStatus = code => {
|
||||
this.user.institution.should.equal('MIT')
|
||||
@@ -336,7 +336,7 @@ describe('UserController', function() {
|
||||
this.UserController.updateUserSettings(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should set some props on ace', function(done) {
|
||||
it('should set some props on ace', function (done) {
|
||||
this.req.body = { editorTheme: 'something' }
|
||||
this.res.sendStatus = code => {
|
||||
this.user.ace.theme.should.equal('something')
|
||||
@@ -345,7 +345,7 @@ describe('UserController', function() {
|
||||
this.UserController.updateUserSettings(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should set the overall theme', function(done) {
|
||||
it('should set the overall theme', function (done) {
|
||||
this.req.body = { overallTheme: 'green-ish' }
|
||||
this.res.sendStatus = code => {
|
||||
this.user.ace.overallTheme.should.equal('green-ish')
|
||||
@@ -354,25 +354,25 @@ describe('UserController', function() {
|
||||
this.UserController.updateUserSettings(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should send an error if the email is 0 len', function(done) {
|
||||
it('should send an error if the email is 0 len', function (done) {
|
||||
this.req.body.email = ''
|
||||
this.res.sendStatus = function(code) {
|
||||
this.res.sendStatus = function (code) {
|
||||
code.should.equal(400)
|
||||
done()
|
||||
}
|
||||
this.UserController.updateUserSettings(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should send an error if the email does not contain an @', function(done) {
|
||||
it('should send an error if the email does not contain an @', function (done) {
|
||||
this.req.body.email = 'bob at something dot com'
|
||||
this.res.sendStatus = function(code) {
|
||||
this.res.sendStatus = function (code) {
|
||||
code.should.equal(400)
|
||||
done()
|
||||
}
|
||||
this.UserController.updateUserSettings(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should call the user updater with the new email and user _id', function(done) {
|
||||
it('should call the user updater with the new email and user _id', function (done) {
|
||||
this.req.body.email = this.newEmail.toUpperCase()
|
||||
this.UserUpdater.changeEmailAddress.callsArgWith(3)
|
||||
this.res.sendStatus = code => {
|
||||
@@ -385,7 +385,7 @@ describe('UserController', function() {
|
||||
this.UserController.updateUserSettings(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should update the email on the session', function(done) {
|
||||
it('should update the email on the session', function (done) {
|
||||
this.req.body.email = this.newEmail.toUpperCase()
|
||||
this.UserUpdater.changeEmailAddress.callsArgWith(3)
|
||||
let callcount = 0
|
||||
@@ -409,7 +409,7 @@ describe('UserController', function() {
|
||||
this.UserController.updateUserSettings(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should call populateTeamInvites', function(done) {
|
||||
it('should call populateTeamInvites', function (done) {
|
||||
this.req.body.email = this.newEmail.toUpperCase()
|
||||
this.UserUpdater.changeEmailAddress.callsArgWith(3)
|
||||
this.res.sendStatus = code => {
|
||||
@@ -422,8 +422,8 @@ describe('UserController', function() {
|
||||
this.UserController.updateUserSettings(this.req, this.res)
|
||||
})
|
||||
|
||||
describe('when changeEmailAddress yields an error', function() {
|
||||
it('should pass on an error and not send a success status', function(done) {
|
||||
describe('when changeEmailAddress yields an error', function () {
|
||||
it('should pass on an error and not send a success status', function (done) {
|
||||
this.req.body.email = this.newEmail.toUpperCase()
|
||||
this.UserUpdater.changeEmailAddress.callsArgWith(3, new OError())
|
||||
this.HttpErrorHandler.legacyInternal = sinon.spy(
|
||||
@@ -438,7 +438,7 @@ describe('UserController', function() {
|
||||
this.UserController.updateUserSettings(this.req, this.res, this.next)
|
||||
})
|
||||
|
||||
it('should call the HTTP conflict error handler when the email already exists', function(done) {
|
||||
it('should call the HTTP conflict error handler when the email already exists', function (done) {
|
||||
this.HttpErrorHandler.conflict = sinon.spy((req, res, message) => {
|
||||
expect(req).to.exist
|
||||
expect(req).to.exist
|
||||
@@ -454,14 +454,14 @@ describe('UserController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when using an external auth source', function() {
|
||||
beforeEach(function() {
|
||||
describe('when using an external auth source', function () {
|
||||
beforeEach(function () {
|
||||
this.UserUpdater.changeEmailAddress.callsArgWith(2)
|
||||
this.newEmail = 'someone23@example.com'
|
||||
this.req.externalAuthenticationSystemUsed = sinon.stub().returns(true)
|
||||
})
|
||||
|
||||
it('should not set a new email', function(done) {
|
||||
it('should not set a new email', function (done) {
|
||||
this.req.body.email = this.newEmail
|
||||
this.res.sendStatus = code => {
|
||||
code.should.equal(200)
|
||||
@@ -475,8 +475,8 @@ describe('UserController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('logout', function() {
|
||||
it('should destroy the session', function(done) {
|
||||
describe('logout', function () {
|
||||
it('should destroy the session', function (done) {
|
||||
this.req.session.destroy = sinon.stub().callsArgWith(0)
|
||||
this.res.redirect = url => {
|
||||
url.should.equal('/login')
|
||||
@@ -487,7 +487,7 @@ describe('UserController', function() {
|
||||
this.UserController.logout(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should untrack session', function(done) {
|
||||
it('should untrack session', function (done) {
|
||||
this.req.session.destroy = sinon.stub().callsArgWith(0)
|
||||
this.res.redirect = url => {
|
||||
url.should.equal('/login')
|
||||
@@ -501,7 +501,7 @@ describe('UserController', function() {
|
||||
this.UserController.logout(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should redirect after logout', function(done) {
|
||||
it('should redirect after logout', function (done) {
|
||||
this.req.body.redirect = '/institutional-login'
|
||||
this.req.session.destroy = sinon.stub().callsArgWith(0)
|
||||
this.res.redirect = url => {
|
||||
@@ -511,7 +511,7 @@ describe('UserController', function() {
|
||||
this.UserController.logout(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should redirect after logout, but not to evil.com', function(done) {
|
||||
it('should redirect after logout, but not to evil.com', function (done) {
|
||||
this.req.body.redirect = 'https://evil.com'
|
||||
this.req.session.destroy = sinon.stub().callsArgWith(0)
|
||||
this.res.redirect = url => {
|
||||
@@ -521,7 +521,7 @@ describe('UserController', function() {
|
||||
this.UserController.logout(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should redirect to login after logout when no redirect set', function(done) {
|
||||
it('should redirect to login after logout when no redirect set', function (done) {
|
||||
this.req.session.destroy = sinon.stub().callsArgWith(0)
|
||||
this.res.redirect = url => {
|
||||
url.should.equal('/login')
|
||||
@@ -531,8 +531,8 @@ describe('UserController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('register', function() {
|
||||
beforeEach(function() {
|
||||
describe('register', function () {
|
||||
beforeEach(function () {
|
||||
this.UserRegistrationHandler.registerNewUserAndSendActivationEmail = sinon
|
||||
.stub()
|
||||
.callsArgWith(1, null, this.user, (this.url = 'mock/url'))
|
||||
@@ -540,13 +540,13 @@ describe('UserController', function() {
|
||||
this.UserController.register(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should register the user and send them an email', function() {
|
||||
it('should register the user and send them an email', function () {
|
||||
this.UserRegistrationHandler.registerNewUserAndSendActivationEmail
|
||||
.calledWith(this.email)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should return the user and activation url', function() {
|
||||
it('should return the user and activation url', function () {
|
||||
this.res.json
|
||||
.calledWith({
|
||||
email: this.email,
|
||||
@@ -556,9 +556,9 @@ describe('UserController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('clearSessions', function() {
|
||||
describe('success', function() {
|
||||
it('should call revokeAllUserSessions', function(done) {
|
||||
describe('clearSessions', function () {
|
||||
describe('success', function () {
|
||||
it('should call revokeAllUserSessions', function (done) {
|
||||
this.res.sendStatus.callsFake(() => {
|
||||
this.UserSessionsManager.promises.revokeAllUserSessions.callCount.should.equal(
|
||||
1
|
||||
@@ -568,7 +568,7 @@ describe('UserController', function() {
|
||||
this.UserController.clearSessions(this.req, this.res)
|
||||
})
|
||||
|
||||
it('send a 201 response', function(done) {
|
||||
it('send a 201 response', function (done) {
|
||||
this.res.sendStatus.callsFake(status => {
|
||||
status.should.equal(201)
|
||||
done()
|
||||
@@ -577,7 +577,7 @@ describe('UserController', function() {
|
||||
this.UserController.clearSessions(this.req, this.res)
|
||||
})
|
||||
|
||||
it('sends a security alert email', function(done) {
|
||||
it('sends a security alert email', function (done) {
|
||||
this.res.sendStatus.callsFake(status => {
|
||||
this.EmailHandler.promises.sendEmail.callCount.should.equal(1)
|
||||
const expectedArg = {
|
||||
@@ -595,9 +595,9 @@ describe('UserController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('errors', function() {
|
||||
describe('when getAllUserSessions produces an error', function() {
|
||||
it('should return an error', function(done) {
|
||||
describe('errors', function () {
|
||||
describe('when getAllUserSessions produces an error', function () {
|
||||
it('should return an error', function (done) {
|
||||
this.UserSessionsManager.promises.getAllUserSessions.rejects(
|
||||
new Error('woops')
|
||||
)
|
||||
@@ -608,8 +608,8 @@ describe('UserController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when audit log addEntry produces an error', function() {
|
||||
it('should call next with an error', function(done) {
|
||||
describe('when audit log addEntry produces an error', function () {
|
||||
it('should call next with an error', function (done) {
|
||||
this.UserAuditLogHandler.promises.addEntry.rejects(new Error('woops'))
|
||||
this.UserController.clearSessions(this.req, this.res, error => {
|
||||
expect(error).to.be.instanceof(Error)
|
||||
@@ -618,8 +618,8 @@ describe('UserController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when revokeAllUserSessions produces an error', function() {
|
||||
it('should call next with an error', function(done) {
|
||||
describe('when revokeAllUserSessions produces an error', function () {
|
||||
it('should call next with an error', function (done) {
|
||||
this.UserSessionsManager.promises.revokeAllUserSessions.rejects(
|
||||
new Error('woops')
|
||||
)
|
||||
@@ -630,9 +630,9 @@ describe('UserController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when EmailHandler produces an error', function() {
|
||||
describe('when EmailHandler produces an error', function () {
|
||||
const anError = new Error('oops')
|
||||
it('send a 201 response but log error', function(done) {
|
||||
it('send a 201 response but log error', function (done) {
|
||||
this.EmailHandler.promises.sendEmail.rejects(anError)
|
||||
this.res.sendStatus.callsFake(status => {
|
||||
status.should.equal(201)
|
||||
@@ -653,9 +653,9 @@ describe('UserController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('changePassword', function() {
|
||||
describe('success', function() {
|
||||
beforeEach(function() {
|
||||
describe('changePassword', function () {
|
||||
describe('success', function () {
|
||||
beforeEach(function () {
|
||||
this.AuthenticationManager.promises.authenticate.resolves(this.user)
|
||||
this.AuthenticationManager.promises.setUserPassword.resolves()
|
||||
this.req.body = {
|
||||
@@ -663,7 +663,7 @@ describe('UserController', function() {
|
||||
newPassword2: 'newpass'
|
||||
}
|
||||
})
|
||||
it('should set the new password if they do match', function(done) {
|
||||
it('should set the new password if they do match', function (done) {
|
||||
this.res.json.callsFake(() => {
|
||||
this.AuthenticationManager.promises.setUserPassword.should.have.been.calledWith(
|
||||
this.user,
|
||||
@@ -674,7 +674,7 @@ describe('UserController', function() {
|
||||
this.UserController.changePassword(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should log the update', function(done) {
|
||||
it('should log the update', function (done) {
|
||||
this.res.json.callsFake(() => {
|
||||
this.UserAuditLogHandler.promises.addEntry.should.have.been.calledWith(
|
||||
this.user._id,
|
||||
@@ -690,7 +690,7 @@ describe('UserController', function() {
|
||||
this.UserController.changePassword(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should send security alert email', function(done) {
|
||||
it('should send security alert email', function (done) {
|
||||
this.res.json.callsFake(() => {
|
||||
const expectedArg = {
|
||||
to: this.user.email,
|
||||
@@ -706,8 +706,8 @@ describe('UserController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('errors', function() {
|
||||
it('should check the old password is the current one at the moment', function(done) {
|
||||
describe('errors', function () {
|
||||
it('should check the old password is the current one at the moment', function (done) {
|
||||
this.AuthenticationManager.promises.authenticate.resolves()
|
||||
this.req.body = { currentPassword: 'oldpasshere' }
|
||||
this.HttpErrorHandler.badRequest.callsFake(() => {
|
||||
@@ -728,7 +728,7 @@ describe('UserController', function() {
|
||||
this.UserController.changePassword(this.req, this.res)
|
||||
})
|
||||
|
||||
it('it should not set the new password if they do not match', function(done) {
|
||||
it('it should not set the new password if they do not match', function (done) {
|
||||
this.AuthenticationManager.promises.authenticate.resolves({})
|
||||
this.req.body = {
|
||||
newPassword1: '1',
|
||||
@@ -748,7 +748,7 @@ describe('UserController', function() {
|
||||
this.UserController.changePassword(this.req, this.res)
|
||||
})
|
||||
|
||||
it('it should not set the new password if it is invalid', function(done) {
|
||||
it('it should not set the new password if it is invalid', function (done) {
|
||||
// this.AuthenticationManager.validatePassword = sinon
|
||||
// .stub()
|
||||
// .returns({ message: 'validation-error' })
|
||||
@@ -774,8 +774,8 @@ describe('UserController', function() {
|
||||
this.UserController.changePassword(this.req, this.res)
|
||||
})
|
||||
|
||||
describe('UserAuditLogHandler error', function() {
|
||||
it('should return error and not update password', function(done) {
|
||||
describe('UserAuditLogHandler error', function () {
|
||||
it('should return error and not update password', function (done) {
|
||||
this.UserAuditLogHandler.promises.addEntry.rejects(new Error('oops'))
|
||||
this.AuthenticationManager.promises.authenticate.resolves(this.user)
|
||||
this.AuthenticationManager.promises.setUserPassword.resolves()
|
||||
@@ -794,9 +794,9 @@ describe('UserController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('EmailHandler error', function() {
|
||||
describe('EmailHandler error', function () {
|
||||
const anError = new Error('oops')
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
this.AuthenticationManager.promises.authenticate.resolves(this.user)
|
||||
this.AuthenticationManager.promises.setUserPassword.resolves()
|
||||
this.req.body = {
|
||||
@@ -805,7 +805,7 @@ describe('UserController', function() {
|
||||
}
|
||||
this.EmailHandler.sendEmail.yields(anError)
|
||||
})
|
||||
it('should not return error but should log it', function(done) {
|
||||
it('should not return error but should log it', function (done) {
|
||||
this.res.json.callsFake(result => {
|
||||
expect(result.message.type).to.equal('success')
|
||||
this.logger.error.callCount.should.equal(1)
|
||||
@@ -824,27 +824,27 @@ describe('UserController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('ensureAffiliationMiddleware', function() {
|
||||
describe('without affiliations feature', function() {
|
||||
beforeEach(async function() {
|
||||
describe('ensureAffiliationMiddleware', function () {
|
||||
describe('without affiliations feature', function () {
|
||||
beforeEach(async function () {
|
||||
await this.UserController.promises.ensureAffiliationMiddleware(
|
||||
this.req,
|
||||
this.res,
|
||||
this.next
|
||||
)
|
||||
})
|
||||
it('should not run affiliation check', function() {
|
||||
it('should not run affiliation check', function () {
|
||||
expect(this.UserGetter.promises.getUser).to.not.have.been.called
|
||||
expect(this.UserUpdater.promises.confirmEmail).to.not.have.been.called
|
||||
expect(this.UserUpdater.promises.addAffiliationForNewUser).to.not.have
|
||||
.been.called
|
||||
})
|
||||
it('should not return an error', function() {
|
||||
it('should not return an error', function () {
|
||||
expect(this.next).to.be.calledWith()
|
||||
})
|
||||
})
|
||||
describe('without ensureAffiliation query parameter', function() {
|
||||
beforeEach(async function() {
|
||||
describe('without ensureAffiliation query parameter', function () {
|
||||
beforeEach(async function () {
|
||||
this.Features.hasFeature.withArgs('affiliations').returns(true)
|
||||
await this.UserController.promises.ensureAffiliationMiddleware(
|
||||
this.req,
|
||||
@@ -852,18 +852,18 @@ describe('UserController', function() {
|
||||
this.next
|
||||
)
|
||||
})
|
||||
it('should not run middleware', function() {
|
||||
it('should not run middleware', function () {
|
||||
expect(this.UserGetter.promises.getUser).to.not.have.been.called
|
||||
expect(this.UserUpdater.promises.confirmEmail).to.not.have.been.called
|
||||
expect(this.UserUpdater.promises.addAffiliationForNewUser).to.not.have
|
||||
.been.called
|
||||
})
|
||||
it('should not return an error', function() {
|
||||
it('should not return an error', function () {
|
||||
expect(this.next).to.be.calledWith()
|
||||
})
|
||||
})
|
||||
describe('no flagged email', function() {
|
||||
beforeEach(async function() {
|
||||
describe('no flagged email', function () {
|
||||
beforeEach(async function () {
|
||||
const email = 'unit-test@overleaf.com'
|
||||
this.user.email = email
|
||||
this.user.emails = [
|
||||
@@ -879,22 +879,22 @@ describe('UserController', function() {
|
||||
this.next
|
||||
)
|
||||
})
|
||||
it('should get the user', function() {
|
||||
it('should get the user', function () {
|
||||
expect(this.UserGetter.promises.getUser).to.have.been.calledWith(
|
||||
this.user._id
|
||||
)
|
||||
})
|
||||
it('should not try to add affiliation or update user', function() {
|
||||
it('should not try to add affiliation or update user', function () {
|
||||
expect(this.UserUpdater.promises.addAffiliationForNewUser).to.not.have
|
||||
.been.called
|
||||
})
|
||||
it('should not return an error', function() {
|
||||
it('should not return an error', function () {
|
||||
expect(this.next).to.be.calledWith()
|
||||
})
|
||||
})
|
||||
describe('flagged non-SSO email', function() {
|
||||
describe('flagged non-SSO email', function () {
|
||||
let emailFlagged
|
||||
beforeEach(async function() {
|
||||
beforeEach(async function () {
|
||||
emailFlagged = 'flagged@overleaf.com'
|
||||
this.user.email = emailFlagged
|
||||
this.user.emails = [
|
||||
@@ -911,7 +911,7 @@ describe('UserController', function() {
|
||||
this.next
|
||||
)
|
||||
})
|
||||
it('should unflag the emails but not confirm', function() {
|
||||
it('should unflag the emails but not confirm', function () {
|
||||
expect(
|
||||
this.UserUpdater.promises.addAffiliationForNewUser
|
||||
).to.have.been.calledWith(this.user._id, emailFlagged)
|
||||
@@ -919,13 +919,13 @@ describe('UserController', function() {
|
||||
this.UserUpdater.promises.confirmEmail
|
||||
).to.not.have.been.calledWith(this.user._id, emailFlagged)
|
||||
})
|
||||
it('should not return an error', function() {
|
||||
it('should not return an error', function () {
|
||||
expect(this.next).to.be.calledWith()
|
||||
})
|
||||
})
|
||||
describe('flagged SSO email', function() {
|
||||
describe('flagged SSO email', function () {
|
||||
let emailFlagged
|
||||
beforeEach(async function() {
|
||||
beforeEach(async function () {
|
||||
emailFlagged = 'flagged@overleaf.com'
|
||||
this.user.email = emailFlagged
|
||||
this.user.emails = [
|
||||
@@ -943,7 +943,7 @@ describe('UserController', function() {
|
||||
this.next
|
||||
)
|
||||
})
|
||||
it('should add affiliation to v1, unflag and confirm on v2', function() {
|
||||
it('should add affiliation to v1, unflag and confirm on v2', function () {
|
||||
expect(this.UserUpdater.promises.addAffiliationForNewUser).to.have.not
|
||||
.been.called
|
||||
expect(this.UserUpdater.promises.confirmEmail).to.have.been.calledWith(
|
||||
@@ -951,13 +951,13 @@ describe('UserController', function() {
|
||||
emailFlagged
|
||||
)
|
||||
})
|
||||
it('should not return an error', function() {
|
||||
it('should not return an error', function () {
|
||||
expect(this.next).to.be.calledWith()
|
||||
})
|
||||
})
|
||||
describe('when v1 returns an error', function() {
|
||||
describe('when v1 returns an error', function () {
|
||||
let emailFlagged
|
||||
beforeEach(async function() {
|
||||
beforeEach(async function () {
|
||||
this.UserUpdater.promises.addAffiliationForNewUser.rejects()
|
||||
emailFlagged = 'flagged@overleaf.com'
|
||||
this.user.email = emailFlagged
|
||||
@@ -975,7 +975,7 @@ describe('UserController', function() {
|
||||
this.next
|
||||
)
|
||||
})
|
||||
it('should return the error', function() {
|
||||
it('should return the error', function () {
|
||||
expect(this.next).to.be.calledWith(sinon.match.instanceOf(Error))
|
||||
})
|
||||
})
|
||||
|
||||
@@ -4,8 +4,8 @@ const { assert } = require('chai')
|
||||
|
||||
const modulePath = '../../../../app/src/Features/User/UserCreator.js'
|
||||
|
||||
describe('UserCreator', function() {
|
||||
beforeEach(function() {
|
||||
describe('UserCreator', function () {
|
||||
beforeEach(function () {
|
||||
const self = this
|
||||
this.user = { _id: '12390i', ace: {} }
|
||||
this.user.save = sinon.stub().resolves(self.user)
|
||||
@@ -53,9 +53,9 @@ describe('UserCreator', function() {
|
||||
this.email = 'bob.oswald@gmail.com'
|
||||
})
|
||||
|
||||
describe('createNewUser', function() {
|
||||
describe('with callbacks', function() {
|
||||
it('should take the opts and put them in the model', async function() {
|
||||
describe('createNewUser', function () {
|
||||
describe('with callbacks', function () {
|
||||
it('should take the opts and put them in the model', async function () {
|
||||
const user = await this.UserCreator.promises.createNewUser({
|
||||
email: this.email,
|
||||
holdingAccount: true
|
||||
@@ -65,7 +65,7 @@ describe('UserCreator', function() {
|
||||
assert.equal(user.first_name, 'bob.oswald')
|
||||
})
|
||||
|
||||
it('should use the start of the email if the first name is empty string', async function() {
|
||||
it('should use the start of the email if the first name is empty string', async function () {
|
||||
const user = await this.UserCreator.promises.createNewUser({
|
||||
email: this.email,
|
||||
holdingAccount: true,
|
||||
@@ -76,7 +76,7 @@ describe('UserCreator', function() {
|
||||
assert.equal(user.first_name, 'bob.oswald')
|
||||
})
|
||||
|
||||
it('should use the first name if passed', async function() {
|
||||
it('should use the first name if passed', async function () {
|
||||
const user = await this.UserCreator.promises.createNewUser({
|
||||
email: this.email,
|
||||
holdingAccount: true,
|
||||
@@ -87,7 +87,7 @@ describe('UserCreator', function() {
|
||||
assert.equal(user.first_name, 'fiiirstname')
|
||||
})
|
||||
|
||||
it('should use the last name if passed', async function() {
|
||||
it('should use the last name if passed', async function () {
|
||||
const user = await this.UserCreator.promises.createNewUser({
|
||||
email: this.email,
|
||||
holdingAccount: true,
|
||||
@@ -98,7 +98,7 @@ describe('UserCreator', function() {
|
||||
assert.equal(user.last_name, 'lastNammmmeee')
|
||||
})
|
||||
|
||||
it('should set emails attribute', async function() {
|
||||
it('should set emails attribute', async function () {
|
||||
const user = await this.UserCreator.promises.createNewUser({
|
||||
email: this.email
|
||||
})
|
||||
@@ -109,9 +109,9 @@ describe('UserCreator', function() {
|
||||
user.emails[0].reversedHostname.should.equal('moc.liamg')
|
||||
})
|
||||
|
||||
describe('with affiliations feature', function() {
|
||||
describe('with affiliations feature', function () {
|
||||
let attributes, user
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
attributes = { email: this.email }
|
||||
this.Features.hasFeature = sinon
|
||||
.stub()
|
||||
@@ -119,16 +119,16 @@ describe('UserCreator', function() {
|
||||
.returns(true)
|
||||
})
|
||||
|
||||
describe('when v1 affiliations API does not return an error', function() {
|
||||
beforeEach(async function() {
|
||||
describe('when v1 affiliations API does not return an error', function () {
|
||||
beforeEach(async function () {
|
||||
user = await this.UserCreator.promises.createNewUser(attributes)
|
||||
})
|
||||
|
||||
it('should flag that affiliation is unchecked', function() {
|
||||
it('should flag that affiliation is unchecked', function () {
|
||||
user.emails[0].affiliationUnchecked.should.equal(true)
|
||||
})
|
||||
|
||||
it('should try to add affiliation to v1', function() {
|
||||
it('should try to add affiliation to v1', function () {
|
||||
sinon.assert.calledOnce(
|
||||
this.UserUpdater.promises.addAffiliationForNewUser
|
||||
)
|
||||
@@ -139,22 +139,22 @@ describe('UserCreator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should query for updated user data', function() {
|
||||
it('should query for updated user data', function () {
|
||||
sinon.assert.calledOnce(this.UserGetter.promises.getUser)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when v1 affiliations API does return an error', function() {
|
||||
beforeEach(async function() {
|
||||
describe('when v1 affiliations API does return an error', function () {
|
||||
beforeEach(async function () {
|
||||
this.UserUpdater.promises.addAffiliationForNewUser.rejects()
|
||||
user = await this.UserCreator.promises.createNewUser(attributes)
|
||||
})
|
||||
|
||||
it('should flag that affiliation is unchecked', function() {
|
||||
it('should flag that affiliation is unchecked', function () {
|
||||
user.emails[0].affiliationUnchecked.should.equal(true)
|
||||
})
|
||||
|
||||
it('should try to add affiliation to v1', function() {
|
||||
it('should try to add affiliation to v1', function () {
|
||||
sinon.assert.calledOnce(
|
||||
this.UserUpdater.promises.addAffiliationForNewUser
|
||||
)
|
||||
@@ -165,26 +165,26 @@ describe('UserCreator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should not query for updated user data', function() {
|
||||
it('should not query for updated user data', function () {
|
||||
sinon.assert.notCalled(this.UserGetter.promises.getUser)
|
||||
})
|
||||
|
||||
it('should log error', function() {
|
||||
it('should log error', function () {
|
||||
sinon.assert.calledOnce(this.logger.error)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when v1 affiliations API returns an error and requireAffiliation=true', function() {
|
||||
beforeEach(async function() {
|
||||
describe('when v1 affiliations API returns an error and requireAffiliation=true', function () {
|
||||
beforeEach(async function () {
|
||||
this.UserUpdater.promises.addAffiliationForNewUser.rejects()
|
||||
user = await this.UserCreator.promises.createNewUser(attributes)
|
||||
})
|
||||
|
||||
it('should flag that affiliation is unchecked', function() {
|
||||
it('should flag that affiliation is unchecked', function () {
|
||||
user.emails[0].affiliationUnchecked.should.equal(true)
|
||||
})
|
||||
|
||||
it('should try to add affiliation to v1', function() {
|
||||
it('should try to add affiliation to v1', function () {
|
||||
sinon.assert.calledOnce(
|
||||
this.UserUpdater.promises.addAffiliationForNewUser
|
||||
)
|
||||
@@ -195,17 +195,17 @@ describe('UserCreator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should not query for updated user data', function() {
|
||||
it('should not query for updated user data', function () {
|
||||
sinon.assert.notCalled(this.UserGetter.promises.getUser)
|
||||
})
|
||||
|
||||
it('should log error', function() {
|
||||
it('should log error', function () {
|
||||
sinon.assert.calledOnce(this.logger.error)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('should not add affiliation when without affiliation feature', async function() {
|
||||
it('should not add affiliation when without affiliation feature', async function () {
|
||||
const attributes = { email: this.email }
|
||||
await this.UserCreator.promises.createNewUser(attributes)
|
||||
sinon.assert.notCalled(
|
||||
@@ -214,8 +214,8 @@ describe('UserCreator', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('with promises', function() {
|
||||
it('should take the opts and put them in the model', async function() {
|
||||
describe('with promises', function () {
|
||||
it('should take the opts and put them in the model', async function () {
|
||||
const opts = {
|
||||
email: this.email,
|
||||
holdingAccount: true
|
||||
@@ -226,7 +226,7 @@ describe('UserCreator', function() {
|
||||
assert.equal(user.first_name, 'bob.oswald')
|
||||
})
|
||||
|
||||
it('should add affiliation when with affiliation feature', async function() {
|
||||
it('should add affiliation when with affiliation feature', async function () {
|
||||
this.Features.hasFeature = sinon
|
||||
.stub()
|
||||
.withArgs('affiliations')
|
||||
@@ -243,7 +243,7 @@ describe('UserCreator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should not add affiliation when without affiliation feature', async function() {
|
||||
it('should not add affiliation when without affiliation feature', async function () {
|
||||
this.Features.hasFeature = sinon.stub().returns(false)
|
||||
const attributes = { email: this.email }
|
||||
await this.UserCreator.promises.createNewUser(attributes)
|
||||
@@ -252,7 +252,7 @@ describe('UserCreator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should include SAML provider ID with email', async function() {
|
||||
it('should include SAML provider ID with email', async function () {
|
||||
const attributes = {
|
||||
email: this.email,
|
||||
samlIdentifiers: [{ email: this.email, providerId: '1' }]
|
||||
@@ -261,7 +261,7 @@ describe('UserCreator', function() {
|
||||
assert.equal(user.emails[0].samlProviderId, '1')
|
||||
})
|
||||
|
||||
it('should fire an analytics event on registration', async function() {
|
||||
it('should fire an analytics event on registration', async function () {
|
||||
const user = await this.UserCreator.promises.createNewUser({
|
||||
email: this.email
|
||||
})
|
||||
@@ -273,7 +273,7 @@ describe('UserCreator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should schedule an onboarding email on registration', async function() {
|
||||
it('should schedule an onboarding email on registration', async function () {
|
||||
const user = await this.UserCreator.promises.createNewUser({
|
||||
email: this.email
|
||||
})
|
||||
|
||||
@@ -10,8 +10,8 @@ const { DeletedUser } = require('../helpers/models/DeletedUser')
|
||||
|
||||
const modulePath = '../../../../app/src/Features/User/UserDeleter.js'
|
||||
|
||||
describe('UserDeleter', function() {
|
||||
beforeEach(function() {
|
||||
describe('UserDeleter', function () {
|
||||
beforeEach(function () {
|
||||
tk.freeze(Date.now())
|
||||
|
||||
this.userId = ObjectId()
|
||||
@@ -100,22 +100,22 @@ describe('UserDeleter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
this.DeletedUserMock.restore()
|
||||
this.UserMock.restore()
|
||||
this.mockedUser.restore()
|
||||
})
|
||||
|
||||
describe('deleteUser', function() {
|
||||
beforeEach(function() {
|
||||
describe('deleteUser', function () {
|
||||
beforeEach(function () {
|
||||
this.UserMock.expects('findById')
|
||||
.withArgs(this.userId)
|
||||
.chain('exec')
|
||||
.resolves(this.user)
|
||||
})
|
||||
|
||||
describe('when the user can be deleted', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the user can be deleted', function () {
|
||||
beforeEach(function () {
|
||||
this.deletedUser = {
|
||||
user: this.user,
|
||||
deleterData: {
|
||||
@@ -134,8 +134,8 @@ describe('UserDeleter', function() {
|
||||
}
|
||||
})
|
||||
|
||||
describe('when no options are passed', function() {
|
||||
beforeEach(function() {
|
||||
describe('when no options are passed', function () {
|
||||
beforeEach(function () {
|
||||
this.DeletedUserMock.expects('updateOne')
|
||||
.withArgs(
|
||||
{ 'deleterData.deletedUserId': this.userId },
|
||||
@@ -146,69 +146,69 @@ describe('UserDeleter', function() {
|
||||
.resolves()
|
||||
})
|
||||
|
||||
describe('when unsubscribing in Mailchimp succeeds', function() {
|
||||
beforeEach(function() {
|
||||
describe('when unsubscribing in Mailchimp succeeds', function () {
|
||||
beforeEach(function () {
|
||||
this.UserMock.expects('deleteOne')
|
||||
.withArgs({ _id: this.userId })
|
||||
.chain('exec')
|
||||
.resolves()
|
||||
})
|
||||
|
||||
it('should find and the user in mongo by its id', async function() {
|
||||
it('should find and the user in mongo by its id', async function () {
|
||||
await this.UserDeleter.promises.deleteUser(this.userId)
|
||||
this.UserMock.verify()
|
||||
})
|
||||
|
||||
it('should delete the user from mailchimp', async function() {
|
||||
it('should delete the user from mailchimp', async function () {
|
||||
await this.UserDeleter.promises.deleteUser(this.userId)
|
||||
expect(
|
||||
this.NewsletterManager.promises.unsubscribe
|
||||
).to.have.been.calledWith(this.user, { delete: true })
|
||||
})
|
||||
|
||||
it('should delete all the projects of a user', async function() {
|
||||
it('should delete all the projects of a user', async function () {
|
||||
await this.UserDeleter.promises.deleteUser(this.userId)
|
||||
expect(
|
||||
this.ProjectDeleter.promises.deleteUsersProjects
|
||||
).to.have.been.calledWith(this.userId)
|
||||
})
|
||||
|
||||
it("should cancel the user's subscription", async function() {
|
||||
it("should cancel the user's subscription", async function () {
|
||||
await this.UserDeleter.promises.deleteUser(this.userId)
|
||||
expect(
|
||||
this.SubscriptionHandler.promises.cancelSubscription
|
||||
).to.have.been.calledWith(this.user)
|
||||
})
|
||||
|
||||
it('should delete user affiliations', async function() {
|
||||
it('should delete user affiliations', async function () {
|
||||
await this.UserDeleter.promises.deleteUser(this.userId)
|
||||
expect(
|
||||
this.InstitutionsApi.promises.deleteAffiliations
|
||||
).to.have.been.calledWith(this.userId)
|
||||
})
|
||||
|
||||
it('should stop the user sessions', async function() {
|
||||
it('should stop the user sessions', async function () {
|
||||
await this.UserDeleter.promises.deleteUser(this.userId)
|
||||
expect(
|
||||
this.UserSessionsManager.promises.revokeAllUserSessions
|
||||
).to.have.been.calledWith(this.userId, [])
|
||||
})
|
||||
|
||||
it('should remove user from group subscriptions', async function() {
|
||||
it('should remove user from group subscriptions', async function () {
|
||||
await this.UserDeleter.promises.deleteUser(this.userId)
|
||||
expect(
|
||||
this.SubscriptionUpdater.promises.removeUserFromAllGroups
|
||||
).to.have.been.calledWith(this.userId)
|
||||
})
|
||||
|
||||
it('should remove user memberships', async function() {
|
||||
it('should remove user memberships', async function () {
|
||||
await this.UserDeleter.promises.deleteUser(this.userId)
|
||||
expect(
|
||||
this.UserMembershipsHandler.promises.removeUserFromAllEntities
|
||||
).to.have.been.calledWith(this.userId)
|
||||
})
|
||||
|
||||
it('rejects if the user is a subscription admin', async function() {
|
||||
it('rejects if the user is a subscription admin', async function () {
|
||||
this.SubscriptionLocator.promises.getUsersSubscription.rejects({
|
||||
_id: 'some-subscription'
|
||||
})
|
||||
@@ -216,35 +216,35 @@ describe('UserDeleter', function() {
|
||||
.be.rejected
|
||||
})
|
||||
|
||||
it('should create a deletedUser', async function() {
|
||||
it('should create a deletedUser', async function () {
|
||||
await this.UserDeleter.promises.deleteUser(this.userId)
|
||||
this.DeletedUserMock.verify()
|
||||
})
|
||||
})
|
||||
|
||||
describe('when unsubscribing from mailchimp fails', function() {
|
||||
beforeEach(function() {
|
||||
describe('when unsubscribing from mailchimp fails', function () {
|
||||
beforeEach(function () {
|
||||
this.NewsletterManager.promises.unsubscribe.rejects(
|
||||
new Error('something went wrong')
|
||||
)
|
||||
})
|
||||
|
||||
it('should return an error and not delete the user', async function() {
|
||||
it('should return an error and not delete the user', async function () {
|
||||
await expect(this.UserDeleter.promises.deleteUser(this.userId)).to
|
||||
.be.rejected
|
||||
this.UserMock.verify()
|
||||
})
|
||||
})
|
||||
|
||||
describe('when called as a callback', function() {
|
||||
beforeEach(function() {
|
||||
describe('when called as a callback', function () {
|
||||
beforeEach(function () {
|
||||
this.UserMock.expects('deleteOne')
|
||||
.withArgs({ _id: this.userId })
|
||||
.chain('exec')
|
||||
.resolves()
|
||||
})
|
||||
|
||||
it('should delete the user', function(done) {
|
||||
it('should delete the user', function (done) {
|
||||
this.UserDeleter.deleteUser(this.userId, err => {
|
||||
expect(err).not.to.exist
|
||||
this.UserMock.verify()
|
||||
@@ -255,8 +255,8 @@ describe('UserDeleter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when a user and IP address are specified', function() {
|
||||
beforeEach(function() {
|
||||
describe('when a user and IP address are specified', function () {
|
||||
beforeEach(function () {
|
||||
this.ipAddress = '1.2.3.4'
|
||||
this.deleterId = ObjectId()
|
||||
|
||||
@@ -277,7 +277,7 @@ describe('UserDeleter', function() {
|
||||
.resolves()
|
||||
})
|
||||
|
||||
it('should add the deleted user id and ip address to the deletedUser', async function() {
|
||||
it('should add the deleted user id and ip address to the deletedUser', async function () {
|
||||
await this.UserDeleter.promises.deleteUser(this.userId, {
|
||||
deleterUser: { _id: this.deleterId },
|
||||
ipAddress: this.ipAddress
|
||||
@@ -285,8 +285,8 @@ describe('UserDeleter', function() {
|
||||
this.DeletedUserMock.verify()
|
||||
})
|
||||
|
||||
describe('when called as a callback', function() {
|
||||
it('should delete the user', function(done) {
|
||||
describe('when called as a callback', function () {
|
||||
it('should delete the user', function (done) {
|
||||
this.UserDeleter.deleteUser(
|
||||
this.userId,
|
||||
{
|
||||
@@ -305,26 +305,26 @@ describe('UserDeleter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the user cannot be deleted because they are a subscription admin', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the user cannot be deleted because they are a subscription admin', function () {
|
||||
beforeEach(function () {
|
||||
this.SubscriptionLocator.promises.getUsersSubscription.resolves({
|
||||
_id: 'some-subscription'
|
||||
})
|
||||
})
|
||||
|
||||
it('fails with a SubscriptionAdminDeletionError', async function() {
|
||||
it('fails with a SubscriptionAdminDeletionError', async function () {
|
||||
await expect(
|
||||
this.UserDeleter.promises.deleteUser(this.userId)
|
||||
).to.be.rejectedWith(Errors.SubscriptionAdminDeletionError)
|
||||
})
|
||||
|
||||
it('should not create a deletedUser', async function() {
|
||||
it('should not create a deletedUser', async function () {
|
||||
await expect(this.UserDeleter.promises.deleteUser(this.userId)).to.be
|
||||
.rejected
|
||||
this.DeletedUserMock.verify()
|
||||
})
|
||||
|
||||
it('should not remove the user from mongo', async function() {
|
||||
it('should not remove the user from mongo', async function () {
|
||||
await expect(this.UserDeleter.promises.deleteUser(this.userId)).to.be
|
||||
.rejected
|
||||
this.UserMock.verify()
|
||||
@@ -332,8 +332,8 @@ describe('UserDeleter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('ensureCanDeleteUser', function() {
|
||||
it('should not return error when user can be deleted', async function() {
|
||||
describe('ensureCanDeleteUser', function () {
|
||||
it('should not return error when user can be deleted', async function () {
|
||||
this.SubscriptionLocator.promises.getUsersSubscription.resolves(null)
|
||||
let error
|
||||
try {
|
||||
@@ -345,7 +345,7 @@ describe('UserDeleter', function() {
|
||||
}
|
||||
})
|
||||
|
||||
it('should return custom error when user is group admin', async function() {
|
||||
it('should return custom error when user is group admin', async function () {
|
||||
this.SubscriptionLocator.promises.getUsersSubscription.resolves({
|
||||
_id: '123abc'
|
||||
})
|
||||
@@ -359,7 +359,7 @@ describe('UserDeleter', function() {
|
||||
}
|
||||
})
|
||||
|
||||
it('propagates errors', async function() {
|
||||
it('propagates errors', async function () {
|
||||
this.SubscriptionLocator.promises.getUsersSubscription.rejects(
|
||||
new Error('Some error')
|
||||
)
|
||||
@@ -374,11 +374,11 @@ describe('UserDeleter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('expireDeletedUsersAfterDuration', function() {
|
||||
describe('expireDeletedUsersAfterDuration', function () {
|
||||
const userId1 = new ObjectId()
|
||||
const userId2 = new ObjectId()
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
this.deletedUsers = [
|
||||
{
|
||||
user: { _id: userId1 },
|
||||
@@ -413,7 +413,7 @@ describe('UserDeleter', function() {
|
||||
}
|
||||
})
|
||||
|
||||
it('clears data from all deleted users', async function() {
|
||||
it('clears data from all deleted users', async function () {
|
||||
await this.UserDeleter.promises.expireDeletedUsersAfterDuration()
|
||||
for (const deletedUser of this.deletedUsers) {
|
||||
expect(deletedUser.user).to.be.undefined
|
||||
@@ -422,8 +422,8 @@ describe('UserDeleter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('expireDeletedUser', function() {
|
||||
beforeEach(function() {
|
||||
describe('expireDeletedUser', function () {
|
||||
beforeEach(function () {
|
||||
this.mockedDeletedUser = sinon.mock(
|
||||
new DeletedUser({
|
||||
user: this.user,
|
||||
@@ -443,37 +443,37 @@ describe('UserDeleter', function() {
|
||||
.resolves(this.deletedUser)
|
||||
})
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
this.mockedDeletedUser.restore()
|
||||
})
|
||||
|
||||
it('should find the user by user ID', async function() {
|
||||
it('should find the user by user ID', async function () {
|
||||
await this.UserDeleter.promises.expireDeletedUser('giraffe')
|
||||
this.DeletedUserMock.verify()
|
||||
})
|
||||
|
||||
it('should remove the user data from mongo', async function() {
|
||||
it('should remove the user data from mongo', async function () {
|
||||
await this.UserDeleter.promises.expireDeletedUser('giraffe')
|
||||
expect(this.deletedUser.user).not.to.exist
|
||||
})
|
||||
|
||||
it('should remove the IP address from mongo', async function() {
|
||||
it('should remove the IP address from mongo', async function () {
|
||||
await this.UserDeleter.promises.expireDeletedUser('giraffe')
|
||||
expect(this.deletedUser.deleterData.ipAddress).not.to.exist
|
||||
})
|
||||
|
||||
it('should not delete other deleterData fields', async function() {
|
||||
it('should not delete other deleterData fields', async function () {
|
||||
await this.UserDeleter.promises.expireDeletedUser('giraffe')
|
||||
expect(this.deletedUser.deleterData.deletedUserId).to.equal(this.userId)
|
||||
})
|
||||
|
||||
it('should save the record to mongo', async function() {
|
||||
it('should save the record to mongo', async function () {
|
||||
await this.UserDeleter.promises.expireDeletedUser('giraffe')
|
||||
this.mockedDeletedUser.verify()
|
||||
})
|
||||
|
||||
describe('when called as a callback', function() {
|
||||
it('should expire the user', function(done) {
|
||||
describe('when called as a callback', function () {
|
||||
it('should expire the user', function (done) {
|
||||
this.UserDeleter.expireDeletedUser('giraffe', err => {
|
||||
expect(err).not.to.exist
|
||||
this.DeletedUserMock.verify()
|
||||
|
||||
@@ -22,8 +22,8 @@ const { expect } = require('chai')
|
||||
const Errors = require('../../../../app/src/Features/Errors/Errors')
|
||||
const EmailHelper = require('../../../../app/src/Features/Helpers/EmailHelper')
|
||||
|
||||
describe('UserEmailsConfirmationHandler', function() {
|
||||
beforeEach(function() {
|
||||
describe('UserEmailsConfirmationHandler', function () {
|
||||
beforeEach(function () {
|
||||
this.UserEmailsConfirmationHandler = SandboxedModule.require(modulePath, {
|
||||
requires: {
|
||||
'settings-sharelatex': (this.settings = {
|
||||
@@ -48,16 +48,16 @@ describe('UserEmailsConfirmationHandler', function() {
|
||||
return (this.callback = sinon.stub())
|
||||
})
|
||||
|
||||
describe('sendConfirmationEmail', function() {
|
||||
beforeEach(function() {
|
||||
describe('sendConfirmationEmail', function () {
|
||||
beforeEach(function () {
|
||||
this.OneTimeTokenHandler.getNewToken = sinon
|
||||
.stub()
|
||||
.yields(null, (this.token = 'new-token'))
|
||||
return (this.EmailHandler.sendEmail = sinon.stub().yields())
|
||||
})
|
||||
|
||||
describe('successfully', function() {
|
||||
beforeEach(function() {
|
||||
describe('successfully', function () {
|
||||
beforeEach(function () {
|
||||
return this.UserEmailsConfirmationHandler.sendConfirmationEmail(
|
||||
this.user_id,
|
||||
this.email,
|
||||
@@ -65,7 +65,7 @@ describe('UserEmailsConfirmationHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should generate a token for the user which references their id and email', function() {
|
||||
it('should generate a token for the user which references their id and email', function () {
|
||||
return this.OneTimeTokenHandler.getNewToken
|
||||
.calledWith(
|
||||
'email_confirmation',
|
||||
@@ -75,7 +75,7 @@ describe('UserEmailsConfirmationHandler', function() {
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should send an email to the user', function() {
|
||||
it('should send an email to the user', function () {
|
||||
return this.EmailHandler.sendEmail
|
||||
.calledWith('confirmEmail', {
|
||||
to: this.email,
|
||||
@@ -86,13 +86,13 @@ describe('UserEmailsConfirmationHandler', function() {
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should call the callback', function() {
|
||||
it('should call the callback', function () {
|
||||
return this.callback.called.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with invalid email', function() {
|
||||
beforeEach(function() {
|
||||
describe('with invalid email', function () {
|
||||
beforeEach(function () {
|
||||
return this.UserEmailsConfirmationHandler.sendConfirmationEmail(
|
||||
this.user_id,
|
||||
'!"£$%^&*()',
|
||||
@@ -100,15 +100,15 @@ describe('UserEmailsConfirmationHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should return an error', function() {
|
||||
it('should return an error', function () {
|
||||
return this.callback
|
||||
.calledWith(sinon.match.instanceOf(Error))
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('a custom template', function() {
|
||||
beforeEach(function() {
|
||||
describe('a custom template', function () {
|
||||
beforeEach(function () {
|
||||
return this.UserEmailsConfirmationHandler.sendConfirmationEmail(
|
||||
this.user_id,
|
||||
this.email,
|
||||
@@ -117,7 +117,7 @@ describe('UserEmailsConfirmationHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should send an email with the given template', function() {
|
||||
it('should send an email with the given template', function () {
|
||||
return this.EmailHandler.sendEmail
|
||||
.calledWith('myCustomTemplate')
|
||||
.should.equal(true)
|
||||
@@ -125,41 +125,41 @@ describe('UserEmailsConfirmationHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('confirmEmailFromToken', function() {
|
||||
beforeEach(function() {
|
||||
describe('confirmEmailFromToken', function () {
|
||||
beforeEach(function () {
|
||||
this.OneTimeTokenHandler.getValueFromTokenAndExpire = sinon
|
||||
.stub()
|
||||
.yields(null, { user_id: this.user_id, email: this.email })
|
||||
return (this.UserUpdater.confirmEmail = sinon.stub().yields())
|
||||
})
|
||||
|
||||
describe('successfully', function() {
|
||||
beforeEach(function() {
|
||||
describe('successfully', function () {
|
||||
beforeEach(function () {
|
||||
return this.UserEmailsConfirmationHandler.confirmEmailFromToken(
|
||||
(this.token = 'mock-token'),
|
||||
this.callback
|
||||
)
|
||||
})
|
||||
|
||||
it('should call getValueFromTokenAndExpire', function() {
|
||||
it('should call getValueFromTokenAndExpire', function () {
|
||||
return this.OneTimeTokenHandler.getValueFromTokenAndExpire
|
||||
.calledWith('email_confirmation', this.token)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should confirm the email of the user_id', function() {
|
||||
it('should confirm the email of the user_id', function () {
|
||||
return this.UserUpdater.confirmEmail
|
||||
.calledWith(this.user_id, this.email)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should call the callback', function() {
|
||||
it('should call the callback', function () {
|
||||
return this.callback.called.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with an expired token', function() {
|
||||
beforeEach(function() {
|
||||
describe('with an expired token', function () {
|
||||
beforeEach(function () {
|
||||
this.OneTimeTokenHandler.getValueFromTokenAndExpire = sinon
|
||||
.stub()
|
||||
.yields(null, null)
|
||||
@@ -169,15 +169,15 @@ describe('UserEmailsConfirmationHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should call the callback with a NotFoundError', function() {
|
||||
it('should call the callback with a NotFoundError', function () {
|
||||
return this.callback
|
||||
.calledWith(sinon.match.instanceOf(Errors.NotFoundError))
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with no user_id in the token', function() {
|
||||
beforeEach(function() {
|
||||
describe('with no user_id in the token', function () {
|
||||
beforeEach(function () {
|
||||
this.OneTimeTokenHandler.getValueFromTokenAndExpire = sinon
|
||||
.stub()
|
||||
.yields(null, { email: this.email })
|
||||
@@ -187,15 +187,15 @@ describe('UserEmailsConfirmationHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should call the callback with a NotFoundError', function() {
|
||||
it('should call the callback with a NotFoundError', function () {
|
||||
return this.callback
|
||||
.calledWith(sinon.match.instanceOf(Errors.NotFoundError))
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with no email in the token', function() {
|
||||
beforeEach(function() {
|
||||
describe('with no email in the token', function () {
|
||||
beforeEach(function () {
|
||||
this.OneTimeTokenHandler.getValueFromTokenAndExpire = sinon
|
||||
.stub()
|
||||
.yields(null, { user_id: this.user_id })
|
||||
@@ -205,15 +205,15 @@ describe('UserEmailsConfirmationHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should call the callback with a NotFoundError', function() {
|
||||
it('should call the callback with a NotFoundError', function () {
|
||||
return this.callback
|
||||
.calledWith(sinon.match.instanceOf(Errors.NotFoundError))
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with no user found', function() {
|
||||
beforeEach(function() {
|
||||
describe('with no user found', function () {
|
||||
beforeEach(function () {
|
||||
this.UserGetter.getUser.yields(null, null)
|
||||
return this.UserEmailsConfirmationHandler.confirmEmailFromToken(
|
||||
(this.token = 'mock-token'),
|
||||
@@ -221,15 +221,15 @@ describe('UserEmailsConfirmationHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should call the callback with a NotFoundError', function() {
|
||||
it('should call the callback with a NotFoundError', function () {
|
||||
return this.callback
|
||||
.calledWith(sinon.match.instanceOf(Errors.NotFoundError))
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with secondary email missing on user', function() {
|
||||
beforeEach(function() {
|
||||
describe('with secondary email missing on user', function () {
|
||||
beforeEach(function () {
|
||||
this.OneTimeTokenHandler.getValueFromTokenAndExpire = sinon
|
||||
.stub()
|
||||
.yields(null, { user_id: this.user_id, email: 'deleted@email.com' })
|
||||
@@ -239,7 +239,7 @@ describe('UserEmailsConfirmationHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should call the callback with a NotFoundError', function() {
|
||||
it('should call the callback with a NotFoundError', function () {
|
||||
return this.callback
|
||||
.calledWith(sinon.match.instanceOf(Errors.NotFoundError))
|
||||
.should.equal(true)
|
||||
|
||||
@@ -8,8 +8,8 @@ const MockRequest = require('../helpers/MockRequest')
|
||||
const MockResponse = require('../helpers/MockResponse')
|
||||
const Errors = require('../../../../app/src/Features/Errors/Errors')
|
||||
|
||||
describe('UserEmailsController', function() {
|
||||
beforeEach(function() {
|
||||
describe('UserEmailsController', function () {
|
||||
beforeEach(function () {
|
||||
this.req = new MockRequest()
|
||||
this.req.sessionID = Math.random().toString()
|
||||
this.res = new MockResponse()
|
||||
@@ -79,10 +79,10 @@ describe('UserEmailsController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('List', function() {
|
||||
beforeEach(function() {})
|
||||
describe('List', function () {
|
||||
beforeEach(function () {})
|
||||
|
||||
it('lists emails', function(done) {
|
||||
it('lists emails', function (done) {
|
||||
const fullEmails = [{ some: 'data' }]
|
||||
this.UserGetter.getUserFullEmails.callsArgWith(1, null, fullEmails)
|
||||
|
||||
@@ -96,8 +96,8 @@ describe('UserEmailsController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('Add', function() {
|
||||
beforeEach(function() {
|
||||
describe('Add', function () {
|
||||
beforeEach(function () {
|
||||
this.newEmail = 'new_email@baz.com'
|
||||
this.req.body = {
|
||||
email: this.newEmail,
|
||||
@@ -111,7 +111,7 @@ describe('UserEmailsController', function() {
|
||||
.yields()
|
||||
})
|
||||
|
||||
it('passed audit log to addEmailAddress', function(done) {
|
||||
it('passed audit log to addEmailAddress', function (done) {
|
||||
this.res.sendStatus = sinon.stub()
|
||||
this.res.sendStatus.callsFake(() => {
|
||||
const addCall = this.UserUpdater.promises.addEmailAddress.lastCall
|
||||
@@ -124,7 +124,7 @@ describe('UserEmailsController', function() {
|
||||
this.UserEmailsController.add(this.req, this.res)
|
||||
})
|
||||
|
||||
it('adds new email', function(done) {
|
||||
it('adds new email', function (done) {
|
||||
this.UserEmailsController.add(
|
||||
this.req,
|
||||
{
|
||||
@@ -151,7 +151,7 @@ describe('UserEmailsController', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('sends a security alert email', function(done) {
|
||||
it('sends a security alert email', function (done) {
|
||||
this.res.sendStatus = sinon.stub()
|
||||
this.res.sendStatus.callsFake(() => {
|
||||
const emailCall = this.EmailHandler.promises.sendEmail.getCall(0)
|
||||
@@ -168,7 +168,7 @@ describe('UserEmailsController', function() {
|
||||
this.UserEmailsController.add(this.req, this.res)
|
||||
})
|
||||
|
||||
it('sends an email confirmation', function(done) {
|
||||
it('sends an email confirmation', function (done) {
|
||||
this.UserEmailsController.add(
|
||||
this.req,
|
||||
{
|
||||
@@ -186,7 +186,7 @@ describe('UserEmailsController', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('handles email parse error', function(done) {
|
||||
it('handles email parse error', function (done) {
|
||||
this.EmailHelper.parseEmail.returns(null)
|
||||
this.UserEmailsController.add(
|
||||
this.req,
|
||||
@@ -201,7 +201,7 @@ describe('UserEmailsController', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should pass the error to the next handler when adding the email fails', function(done) {
|
||||
it('should pass the error to the next handler when adding the email fails', function (done) {
|
||||
this.UserUpdater.promises.addEmailAddress.rejects(new Error())
|
||||
this.UserEmailsController.add(this.req, this.res, error => {
|
||||
expect(error).to.be.instanceof(Error)
|
||||
@@ -209,7 +209,7 @@ describe('UserEmailsController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should call the HTTP conflict handler when the email already exists', function(done) {
|
||||
it('should call the HTTP conflict handler when the email already exists', function (done) {
|
||||
this.UserUpdater.promises.addEmailAddress.rejects(
|
||||
new Errors.EmailExistsError()
|
||||
)
|
||||
@@ -222,7 +222,7 @@ describe('UserEmailsController', function() {
|
||||
this.UserEmailsController.add(this.req, this.res, this.next)
|
||||
})
|
||||
|
||||
it("should call the HTTP conflict handler when there's a domain matching error", function(done) {
|
||||
it("should call the HTTP conflict handler when there's a domain matching error", function (done) {
|
||||
this.UserUpdater.promises.addEmailAddress.rejects(
|
||||
new Error('422: Email does not belong to university')
|
||||
)
|
||||
@@ -236,14 +236,14 @@ describe('UserEmailsController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('remove', function() {
|
||||
beforeEach(function() {
|
||||
describe('remove', function () {
|
||||
beforeEach(function () {
|
||||
this.email = 'email_to_remove@bar.com'
|
||||
this.req.body.email = 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.UserEmailsController.remove(this.req, {
|
||||
@@ -260,7 +260,7 @@ describe('UserEmailsController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('handles email parse error', function(done) {
|
||||
it('handles email parse error', function (done) {
|
||||
this.EmailHelper.parseEmail.returns(null)
|
||||
|
||||
this.UserEmailsController.remove(this.req, {
|
||||
@@ -273,15 +273,15 @@ describe('UserEmailsController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('setDefault', function() {
|
||||
beforeEach(function() {
|
||||
describe('setDefault', function () {
|
||||
beforeEach(function () {
|
||||
this.email = 'email_to_set_default@bar.com'
|
||||
this.req.body.email = this.email
|
||||
this.EmailHelper.parseEmail.returns(this.email)
|
||||
this.AuthenticationController.setInSessionUser.returns(null)
|
||||
})
|
||||
|
||||
it('sets default email', function(done) {
|
||||
it('sets default email', function (done) {
|
||||
this.UserUpdater.setDefaultEmailAddress.yields()
|
||||
|
||||
this.UserEmailsController.setDefault(this.req, {
|
||||
@@ -303,7 +303,7 @@ describe('UserEmailsController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('handles email parse error', function(done) {
|
||||
it('handles email parse error', function (done) {
|
||||
this.EmailHelper.parseEmail.returns(null)
|
||||
|
||||
this.UserEmailsController.setDefault(this.req, {
|
||||
@@ -315,7 +315,7 @@ describe('UserEmailsController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should reset the users other sessions', function(done) {
|
||||
it('should reset the users other sessions', function (done) {
|
||||
this.UserUpdater.setDefaultEmailAddress.yields()
|
||||
|
||||
this.res.callback = () => {
|
||||
@@ -328,7 +328,7 @@ describe('UserEmailsController', function() {
|
||||
this.UserEmailsController.setDefault(this.req, this.res, done)
|
||||
})
|
||||
|
||||
it('handles error from revoking sessions and returns 200', function(done) {
|
||||
it('handles error from revoking sessions and returns 200', function (done) {
|
||||
this.UserUpdater.setDefaultEmailAddress.yields()
|
||||
const redisError = new Error('redis error')
|
||||
this.UserSessionsManager.revokeAllUserSessions = sinon
|
||||
@@ -352,14 +352,14 @@ describe('UserEmailsController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('endorse', function() {
|
||||
beforeEach(function() {
|
||||
describe('endorse', function () {
|
||||
beforeEach(function () {
|
||||
this.email = 'email_to_endorse@bar.com'
|
||||
this.req.body.email = 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.department = 'Department'
|
||||
|
||||
@@ -379,8 +379,8 @@ describe('UserEmailsController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('confirm', function() {
|
||||
beforeEach(function() {
|
||||
describe('confirm', function () {
|
||||
beforeEach(function () {
|
||||
this.UserEmailsConfirmationHandler.confirmEmailFromToken = sinon
|
||||
.stub()
|
||||
.yields()
|
||||
@@ -394,42 +394,42 @@ describe('UserEmailsController', function() {
|
||||
this.req.body = { token: this.token }
|
||||
})
|
||||
|
||||
describe('successfully', function() {
|
||||
beforeEach(function() {
|
||||
describe('successfully', function () {
|
||||
beforeEach(function () {
|
||||
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 () {
|
||||
this.UserEmailsConfirmationHandler.confirmEmailFromToken
|
||||
.calledWith(this.token)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should return a 200 status', function() {
|
||||
it('should return a 200 status', function () {
|
||||
this.res.sendStatus.calledWith(200).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('without a token', function() {
|
||||
beforeEach(function() {
|
||||
describe('without a token', function () {
|
||||
beforeEach(function () {
|
||||
this.req.body.token = null
|
||||
this.UserEmailsController.confirm(this.req, this.res, this.next)
|
||||
})
|
||||
|
||||
it('should return a 422 status', function() {
|
||||
it('should return a 422 status', function () {
|
||||
this.res.status.calledWith(422).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when confirming fails', function() {
|
||||
beforeEach(function() {
|
||||
describe('when confirming fails', function () {
|
||||
beforeEach(function () {
|
||||
this.UserEmailsConfirmationHandler.confirmEmailFromToken = sinon
|
||||
.stub()
|
||||
.yields(new Errors.NotFoundError('not found'))
|
||||
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.json
|
||||
.calledWith({
|
||||
@@ -439,8 +439,8 @@ describe('UserEmailsController', function() {
|
||||
})
|
||||
})
|
||||
})
|
||||
describe('resendConfirmation', function() {
|
||||
beforeEach(function() {
|
||||
describe('resendConfirmation', function () {
|
||||
beforeEach(function () {
|
||||
this.req = {
|
||||
body: {}
|
||||
}
|
||||
@@ -452,15 +452,15 @@ describe('UserEmailsController', function() {
|
||||
.stub()
|
||||
.yields()
|
||||
})
|
||||
describe('when institution SSO is released', function() {
|
||||
beforeEach(function() {
|
||||
describe('when institution SSO is released', function () {
|
||||
beforeEach(function () {
|
||||
this.Features.hasFeature.withArgs('saml').returns(true)
|
||||
})
|
||||
describe('for an institution SSO email', function() {
|
||||
beforeEach(function() {
|
||||
describe('for an institution SSO email', function () {
|
||||
beforeEach(function () {
|
||||
this.req.body.email = 'with-sso@overleaf.com'
|
||||
})
|
||||
it('should not send the email', function() {
|
||||
it('should not send the email', function () {
|
||||
this.UserEmailsController.resendConfirmation(
|
||||
this.req,
|
||||
this.res,
|
||||
@@ -471,11 +471,11 @@ describe('UserEmailsController', function() {
|
||||
)
|
||||
})
|
||||
})
|
||||
describe('for a non-institution SSO email', function() {
|
||||
beforeEach(function() {
|
||||
describe('for a non-institution SSO email', function () {
|
||||
beforeEach(function () {
|
||||
this.req.body.email = 'without-sso@example.com'
|
||||
})
|
||||
it('should send the email', function() {
|
||||
it('should send the email', function () {
|
||||
this.UserEmailsController.resendConfirmation(
|
||||
this.req,
|
||||
this.res,
|
||||
@@ -487,15 +487,15 @@ describe('UserEmailsController', function() {
|
||||
})
|
||||
})
|
||||
})
|
||||
describe('when institution SSO is not released', function() {
|
||||
beforeEach(function() {
|
||||
describe('when institution SSO is not released', function () {
|
||||
beforeEach(function () {
|
||||
this.Features.hasFeature.withArgs('saml').returns(false)
|
||||
})
|
||||
describe('for an institution SSO email', function() {
|
||||
beforeEach(function() {
|
||||
describe('for an institution SSO email', function () {
|
||||
beforeEach(function () {
|
||||
this.req.body.email = 'with-sso@overleaf.com'
|
||||
})
|
||||
it('should send the email', function() {
|
||||
it('should send the email', function () {
|
||||
this.UserEmailsController.resendConfirmation(
|
||||
this.req,
|
||||
this.res,
|
||||
@@ -506,11 +506,11 @@ describe('UserEmailsController', function() {
|
||||
)
|
||||
})
|
||||
})
|
||||
describe('for a non-institution SSO email', function() {
|
||||
beforeEach(function() {
|
||||
describe('for a non-institution SSO email', function () {
|
||||
beforeEach(function () {
|
||||
this.req.body.email = 'without-sso@example.com'
|
||||
})
|
||||
it('should send the email', function() {
|
||||
it('should send the email', function () {
|
||||
this.UserEmailsController.resendConfirmation(
|
||||
this.req,
|
||||
this.res,
|
||||
|
||||
@@ -15,8 +15,8 @@ const {
|
||||
normalizeMultiQuery
|
||||
} = require('../../../../app/src/Features/Helpers/Mongo')
|
||||
|
||||
describe('UserGetter', function() {
|
||||
beforeEach(function() {
|
||||
describe('UserGetter', function () {
|
||||
beforeEach(function () {
|
||||
this.fakeUser = {
|
||||
_id: '12390i',
|
||||
email: 'email2@foo.bar',
|
||||
@@ -65,8 +65,8 @@ describe('UserGetter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('getUser', function() {
|
||||
it('should get user', function(done) {
|
||||
describe('getUser', function () {
|
||||
it('should get user', function (done) {
|
||||
const query = { _id: '000000000000000000000000' }
|
||||
const projection = { email: 1 }
|
||||
this.UserGetter.getUser(query, projection, (error, user) => {
|
||||
@@ -78,7 +78,7 @@ describe('UserGetter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should not allow null query', function(done) {
|
||||
it('should not allow null query', function (done) {
|
||||
this.UserGetter.getUser(null, {}, error => {
|
||||
error.should.exist
|
||||
error.message.should.equal('no query provided')
|
||||
@@ -87,8 +87,8 @@ describe('UserGetter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('getUsers', function() {
|
||||
it('should get users with array of userIds', function(done) {
|
||||
describe('getUsers', function () {
|
||||
it('should get users with array of userIds', function (done) {
|
||||
const query = [new ObjectId()]
|
||||
const projection = { email: 1 }
|
||||
this.UserGetter.getUsers(query, projection, (error, users) => {
|
||||
@@ -102,7 +102,7 @@ describe('UserGetter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should not allow null query', function(done) {
|
||||
it('should not allow null query', function (done) {
|
||||
this.UserGetter.getUser(null, {}, error => {
|
||||
error.should.exist
|
||||
error.message.should.equal('no query provided')
|
||||
@@ -111,8 +111,8 @@ describe('UserGetter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('getUserFullEmails', function() {
|
||||
it('should get user', function(done) {
|
||||
describe('getUserFullEmails', function () {
|
||||
it('should get user', function (done) {
|
||||
this.UserGetter.promises.getUser = sinon.stub().resolves(this.fakeUser)
|
||||
const projection = { email: 1, emails: 1, samlIdentifiers: 1 }
|
||||
this.UserGetter.getUserFullEmails(
|
||||
@@ -128,7 +128,7 @@ describe('UserGetter', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should fetch emails data', function(done) {
|
||||
it('should fetch emails data', function (done) {
|
||||
this.UserGetter.promises.getUser = sinon.stub().resolves(this.fakeUser)
|
||||
this.UserGetter.getUserFullEmails(
|
||||
this.fakeUser._id,
|
||||
@@ -154,7 +154,7 @@ describe('UserGetter', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should merge affiliation data', function(done) {
|
||||
it('should merge affiliation data', function (done) {
|
||||
this.UserGetter.promises.getUser = sinon.stub().resolves(this.fakeUser)
|
||||
const affiliationsData = [
|
||||
{
|
||||
@@ -207,7 +207,7 @@ describe('UserGetter', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should merge SAML identifier', function(done) {
|
||||
it('should merge SAML identifier', function (done) {
|
||||
const fakeSamlIdentifiers = [
|
||||
{ providerId: 'saml_id', exteranlUserId: 'whatever' }
|
||||
]
|
||||
@@ -242,7 +242,7 @@ describe('UserGetter', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should get user when it has no emails field', function(done) {
|
||||
it('should get user when it has no emails field', function (done) {
|
||||
this.fakeUser = {
|
||||
_id: '12390i',
|
||||
email: 'email2@foo.bar'
|
||||
@@ -263,7 +263,7 @@ describe('UserGetter', function() {
|
||||
)
|
||||
})
|
||||
|
||||
describe('affiliation reconfirmation', function() {
|
||||
describe('affiliation reconfirmation', function () {
|
||||
const institutionNonSSO = {
|
||||
id: 1,
|
||||
name: 'University Name',
|
||||
@@ -283,7 +283,7 @@ describe('UserGetter', function() {
|
||||
ssoEnabled: true,
|
||||
maxConfirmationMonths: 12
|
||||
}
|
||||
describe('non-SSO institutions', function() {
|
||||
describe('non-SSO institutions', function () {
|
||||
const email1 = 'leonard@example-affiliation.com'
|
||||
const email2 = 'mccoy@example-affiliation.com'
|
||||
const affiliationsData = [
|
||||
@@ -304,7 +304,7 @@ describe('UserGetter', function() {
|
||||
institution: institutionNonSSO
|
||||
}
|
||||
]
|
||||
it('should flag inReconfirmNotificationPeriod for all affiliations in period', function(done) {
|
||||
it('should flag inReconfirmNotificationPeriod for all affiliations in period', function (done) {
|
||||
const user = {
|
||||
_id: '12390i',
|
||||
email: email1,
|
||||
@@ -348,7 +348,7 @@ describe('UserGetter', function() {
|
||||
}
|
||||
)
|
||||
})
|
||||
it('should not flag affiliations outside of notification period', function(done) {
|
||||
it('should not flag affiliations outside of notification period', function (done) {
|
||||
const aboutToBeWithinPeriod = moment()
|
||||
.subtract(institutionNonSSO.maxConfirmationMonths, 'months')
|
||||
.add(15, 'days')
|
||||
@@ -388,8 +388,8 @@ describe('UserGetter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('SSO institutions', function() {
|
||||
it('should flag only linked email, if in notification period', function(done) {
|
||||
describe('SSO institutions', function () {
|
||||
it('should flag only linked email, if in notification period', function (done) {
|
||||
const email1 = 'email1@sso.bar'
|
||||
const email2 = 'email2@sso.bar'
|
||||
const email3 = 'email3@sso.bar'
|
||||
@@ -474,8 +474,8 @@ describe('UserGetter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('multiple institution affiliations', function() {
|
||||
it('should flag each institution', function(done) {
|
||||
describe('multiple institution affiliations', function () {
|
||||
it('should flag each institution', function (done) {
|
||||
const email1 = 'email1@sso.bar'
|
||||
const email2 = 'email2@sso.bar'
|
||||
const email3 = 'email3@foo.bar'
|
||||
@@ -573,8 +573,8 @@ describe('UserGetter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('reconfirmedAt', function() {
|
||||
it('only use confirmedAt when no reconfirmedAt', function(done) {
|
||||
describe('reconfirmedAt', function () {
|
||||
it('only use confirmedAt when no reconfirmedAt', function (done) {
|
||||
const email1 = 'email1@foo.bar'
|
||||
const email2 = 'email2@foo.bar'
|
||||
const email3 = 'email3@foo.bar'
|
||||
@@ -669,9 +669,9 @@ describe('UserGetter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('before reconfirmation period expires and within reconfirmation notification period', function() {
|
||||
describe('before reconfirmation period expires and within reconfirmation notification period', function () {
|
||||
const email = 'leonard@example-affiliation.com'
|
||||
it('should flag the email', function(done) {
|
||||
it('should flag the email', function (done) {
|
||||
const confirmedAt = moment()
|
||||
.subtract(institutionNonSSO.maxConfirmationMonths, 'months')
|
||||
.subtract(14, 'days')
|
||||
@@ -712,8 +712,8 @@ describe('UserGetter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when no Settings.reconfirmNotificationDays', function() {
|
||||
it('should always return inReconfirmNotificationPeriod:false', function(done) {
|
||||
describe('when no Settings.reconfirmNotificationDays', function () {
|
||||
it('should always return inReconfirmNotificationPeriod:false', function (done) {
|
||||
const email1 = 'email1@sso.bar'
|
||||
const email2 = 'email2@foo.bar'
|
||||
const email3 = 'email3@foo.bar'
|
||||
@@ -786,8 +786,8 @@ describe('UserGetter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('getUserbyMainEmail', function() {
|
||||
it('query user by main email', function(done) {
|
||||
describe('getUserbyMainEmail', function () {
|
||||
it('query user by main email', function (done) {
|
||||
const email = 'hello@world.com'
|
||||
const projection = { emails: 1 }
|
||||
this.UserGetter.getUserByMainEmail(email, projection, (error, user) => {
|
||||
@@ -798,7 +798,7 @@ describe('UserGetter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('return user if found', function(done) {
|
||||
it('return user if found', function (done) {
|
||||
const email = 'hello@world.com'
|
||||
this.UserGetter.getUserByMainEmail(email, (error, user) => {
|
||||
expect(error).to.not.exist
|
||||
@@ -807,7 +807,7 @@ describe('UserGetter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('trim email', function(done) {
|
||||
it('trim email', function (done) {
|
||||
const email = 'hello@world.com'
|
||||
this.UserGetter.getUserByMainEmail(` ${email} `, (error, user) => {
|
||||
expect(error).to.not.exist
|
||||
@@ -818,8 +818,8 @@ describe('UserGetter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('getUserByAnyEmail', function() {
|
||||
it('query user for any email', function(done) {
|
||||
describe('getUserByAnyEmail', function () {
|
||||
it('query user for any email', function (done) {
|
||||
const email = 'hello@world.com'
|
||||
const expectedQuery = {
|
||||
emails: { $exists: true },
|
||||
@@ -840,7 +840,7 @@ describe('UserGetter', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('query contains $exists:true so partial index is used', function(done) {
|
||||
it('query contains $exists:true so partial index is used', function (done) {
|
||||
const expectedQuery = {
|
||||
emails: { $exists: true },
|
||||
'emails.email': ''
|
||||
@@ -854,7 +854,7 @@ describe('UserGetter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('checks main email as well', function(done) {
|
||||
it('checks main email as well', function (done) {
|
||||
this.findOne.callsArgWith(2, null, null)
|
||||
const email = 'hello@world.com'
|
||||
const projection = { emails: 1 }
|
||||
@@ -871,15 +871,12 @@ describe('UserGetter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('getUsersByHostname', function() {
|
||||
it('should find user by hostname', function(done) {
|
||||
describe('getUsersByHostname', function () {
|
||||
it('should find user by hostname', function (done) {
|
||||
const hostname = 'bar.foo'
|
||||
const expectedQuery = {
|
||||
emails: { $exists: true },
|
||||
'emails.reversedHostname': hostname
|
||||
.split('')
|
||||
.reverse()
|
||||
.join('')
|
||||
'emails.reversedHostname': hostname.split('').reverse().join('')
|
||||
}
|
||||
const projection = { emails: 1 }
|
||||
this.UserGetter.getUsersByHostname(
|
||||
@@ -895,8 +892,8 @@ describe('UserGetter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('getUsersByAnyConfirmedEmail', function() {
|
||||
it('should find users by confirmed email', function(done) {
|
||||
describe('getUsersByAnyConfirmedEmail', function () {
|
||||
it('should find users by confirmed email', function (done) {
|
||||
const emails = ['confirmed@example.com']
|
||||
|
||||
this.UserGetter.getUsersByAnyConfirmedEmail(emails, (error, users) => {
|
||||
@@ -919,8 +916,8 @@ describe('UserGetter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('getUsersByV1Id', function() {
|
||||
it('should find users by list of v1 ids', function(done) {
|
||||
describe('getUsersByV1Id', function () {
|
||||
it('should find users by list of v1 ids', function (done) {
|
||||
const v1Ids = [501]
|
||||
const expectedQuery = {
|
||||
'overleaf.id': { $in: v1Ids }
|
||||
@@ -935,12 +932,12 @@ describe('UserGetter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('ensureUniqueEmailAddress', function() {
|
||||
beforeEach(function() {
|
||||
describe('ensureUniqueEmailAddress', function () {
|
||||
beforeEach(function () {
|
||||
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.ensureUniqueEmailAddress(this.newEmail, err => {
|
||||
expect(err).to.exist
|
||||
@@ -949,7 +946,7 @@ describe('UserGetter', function() {
|
||||
})
|
||||
})
|
||||
|
||||
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.ensureUniqueEmailAddress(this.newEmail, err => {
|
||||
expect(err).not.to.exist
|
||||
|
||||
@@ -2,8 +2,8 @@ const sinon = require('sinon')
|
||||
const modulePath = '../../../../app/src/Features/User/UserHandler.js'
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
|
||||
describe('UserHandler', function() {
|
||||
beforeEach(function() {
|
||||
describe('UserHandler', function () {
|
||||
beforeEach(function () {
|
||||
this.user = {
|
||||
_id: '12390i',
|
||||
email: 'bob@bob.com',
|
||||
@@ -21,12 +21,12 @@ describe('UserHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('populateTeamInvites', function() {
|
||||
beforeEach(function(done) {
|
||||
describe('populateTeamInvites', function () {
|
||||
beforeEach(function (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 () {
|
||||
this.TeamInvitesHandler.createTeamInvitesForLegacyInvitedEmail
|
||||
.calledWith(this.user.email)
|
||||
.should.eq(true)
|
||||
|
||||
@@ -19,8 +19,8 @@ const MockResponse = require('../helpers/MockResponse')
|
||||
const MockRequest = require('../helpers/MockRequest')
|
||||
const { ObjectId } = require('mongodb')
|
||||
|
||||
describe('UserInfoController', function() {
|
||||
beforeEach(function() {
|
||||
describe('UserInfoController', function () {
|
||||
beforeEach(function () {
|
||||
this.UserDeleter = { deleteUser: sinon.stub().callsArgWith(1) }
|
||||
this.UserUpdater = { updatePersonalInfo: sinon.stub() }
|
||||
this.sanitizer = {
|
||||
@@ -49,8 +49,8 @@ describe('UserInfoController', function() {
|
||||
return (this.next = sinon.stub())
|
||||
})
|
||||
|
||||
describe('getLoggedInUsersPersonalInfo', function() {
|
||||
beforeEach(function() {
|
||||
describe('getLoggedInUsersPersonalInfo', function () {
|
||||
beforeEach(function () {
|
||||
this.user = { _id: ObjectId() }
|
||||
this.req.user = this.user
|
||||
this.req.session.user = this.user
|
||||
@@ -66,16 +66,16 @@ describe('UserInfoController', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should call sendFormattedPersonalInfo', function() {
|
||||
it('should call sendFormattedPersonalInfo', function () {
|
||||
return this.UserInfoController.sendFormattedPersonalInfo
|
||||
.calledWith(this.user, this.res, this.next)
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('getPersonalInfo', function() {
|
||||
describe('when the user exists with sharelatex id', function() {
|
||||
beforeEach(function() {
|
||||
describe('getPersonalInfo', function () {
|
||||
describe('when the user exists with sharelatex id', function () {
|
||||
beforeEach(function () {
|
||||
this.user_id = ObjectId().toString()
|
||||
this.user = { _id: ObjectId(this.user_id) }
|
||||
this.req.params = { user_id: this.user_id }
|
||||
@@ -88,7 +88,7 @@ describe('UserInfoController', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should look up the user in the database', function() {
|
||||
it('should look up the user in the database', function () {
|
||||
return this.UserGetter.getUser
|
||||
.calledWith(
|
||||
{ _id: ObjectId(this.user_id) },
|
||||
@@ -97,15 +97,15 @@ describe('UserInfoController', function() {
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should send the formatted details back to the client', function() {
|
||||
it('should send the formatted details back to the client', function () {
|
||||
return this.UserInfoController.sendFormattedPersonalInfo
|
||||
.calledWith(this.user, this.res, this.next)
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the user exists with overleaf id', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the user exists with overleaf id', function () {
|
||||
beforeEach(function () {
|
||||
this.user_id = 12345
|
||||
this.user = {
|
||||
_id: ObjectId(),
|
||||
@@ -123,7 +123,7 @@ describe('UserInfoController', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should look up the user in the database', function() {
|
||||
it('should look up the user in the database', function () {
|
||||
return this.UserGetter.getUser
|
||||
.calledWith(
|
||||
{ 'overleaf.id': this.user_id },
|
||||
@@ -132,15 +132,15 @@ describe('UserInfoController', function() {
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should send the formatted details back to the client', function() {
|
||||
it('should send the formatted details back to the client', function () {
|
||||
return this.UserInfoController.sendFormattedPersonalInfo
|
||||
.calledWith(this.user, this.res, this.next)
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the user does not exist', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the user does not exist', function () {
|
||||
beforeEach(function () {
|
||||
this.user_id = ObjectId().toString()
|
||||
this.req.params = { user_id: this.user_id }
|
||||
this.UserGetter.getUser = sinon.stub().callsArgWith(2, null, null)
|
||||
@@ -151,13 +151,13 @@ describe('UserInfoController', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should return 404 to the client', function() {
|
||||
it('should return 404 to the client', function () {
|
||||
return this.res.statusCode.should.equal(404)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the user id is invalid', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the user id is invalid', function () {
|
||||
beforeEach(function () {
|
||||
this.user_id = 'invalid'
|
||||
this.req.params = { user_id: this.user_id }
|
||||
this.UserGetter.getUser = sinon.stub().callsArgWith(2, null, null)
|
||||
@@ -168,14 +168,14 @@ describe('UserInfoController', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should return 400 to the client', function() {
|
||||
it('should return 400 to the client', function () {
|
||||
return this.res.statusCode.should.equal(400)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('sendFormattedPersonalInfo', function() {
|
||||
beforeEach(function() {
|
||||
describe('sendFormattedPersonalInfo', function () {
|
||||
beforeEach(function () {
|
||||
this.user = {
|
||||
_id: ObjectId(),
|
||||
first_name: 'Douglas',
|
||||
@@ -197,19 +197,19 @@ describe('UserInfoController', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should format the user details for the response', function() {
|
||||
it('should format the user details for the response', function () {
|
||||
return this.UserInfoController.formatPersonalInfo
|
||||
.calledWith(this.user)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should send the formatted details back to the client', function() {
|
||||
it('should send the formatted details back to the client', function () {
|
||||
return this.res.body.should.equal(JSON.stringify(this.formattedInfo))
|
||||
})
|
||||
})
|
||||
|
||||
describe('formatPersonalInfo', function() {
|
||||
it('should return the correctly formatted data', function() {
|
||||
describe('formatPersonalInfo', function () {
|
||||
it('should return the correctly formatted data', function () {
|
||||
this.user = {
|
||||
_id: ObjectId(),
|
||||
first_name: 'Douglas',
|
||||
|
||||
@@ -7,8 +7,8 @@ const MODULE_PATH = path.join(
|
||||
'../../../../app/src/Features/User/UserOnboardingEmailManager'
|
||||
)
|
||||
|
||||
describe('UserOnboardingEmailManager', function() {
|
||||
beforeEach(function() {
|
||||
describe('UserOnboardingEmailManager', function () {
|
||||
beforeEach(function () {
|
||||
this.fakeUserId = '123abc'
|
||||
this.fakeUserEmail = 'frog@overleaf.com'
|
||||
this.onboardingEmailsQueue = {
|
||||
@@ -55,8 +55,8 @@ describe('UserOnboardingEmailManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('schedule email', function() {
|
||||
it('should schedule delayed job on queue', function() {
|
||||
describe('schedule email', function () {
|
||||
it('should schedule delayed job on queue', function () {
|
||||
this.UserOnboardingEmailManager.scheduleOnboardingEmail({
|
||||
_id: this.fakeUserId
|
||||
})
|
||||
@@ -67,7 +67,7 @@ describe('UserOnboardingEmailManager', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('queue process callback should send onboarding email and update user', async function() {
|
||||
it('queue process callback should send onboarding email and update user', async function () {
|
||||
await this.queueProcessFunction({ data: { userId: this.fakeUserId } })
|
||||
sinon.assert.calledWith(
|
||||
this.UserGetter.promises.getUser,
|
||||
@@ -90,7 +90,7 @@ describe('UserOnboardingEmailManager', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('queue process callback should stop if user is not found', async function() {
|
||||
it('queue process callback should stop if user is not found', async function () {
|
||||
this.UserGetter.promises.getUser = sinon.stub().resolves()
|
||||
await this.queueProcessFunction({ data: { userId: 'deleted-user' } })
|
||||
sinon.assert.calledWith(
|
||||
|
||||
@@ -20,8 +20,8 @@ const modulePath = path.join(
|
||||
)
|
||||
const { expect } = require('chai')
|
||||
|
||||
describe('UserPagesController', function() {
|
||||
beforeEach(function() {
|
||||
describe('UserPagesController', function () {
|
||||
beforeEach(function () {
|
||||
this.settings = {
|
||||
apis: {
|
||||
v1: {
|
||||
@@ -73,8 +73,8 @@ describe('UserPagesController', function() {
|
||||
return (this.res = {})
|
||||
})
|
||||
|
||||
describe('registerPage', function() {
|
||||
it('should render the register page', function(done) {
|
||||
describe('registerPage', function () {
|
||||
it('should render the register page', function (done) {
|
||||
this.res.render = page => {
|
||||
page.should.equal('user/register')
|
||||
return done()
|
||||
@@ -82,7 +82,7 @@ describe('UserPagesController', function() {
|
||||
return this.UserPagesController.registerPage(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should set sharedProjectData', function(done) {
|
||||
it('should set sharedProjectData', function (done) {
|
||||
this.req.query.project_name = 'myProject'
|
||||
this.req.query.user_first_name = 'user_first_name_here'
|
||||
|
||||
@@ -96,7 +96,7 @@ describe('UserPagesController', function() {
|
||||
return this.UserPagesController.registerPage(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should set newTemplateData', function(done) {
|
||||
it('should set newTemplateData', function (done) {
|
||||
this.req.session.templateData = { templateName: 'templateName' }
|
||||
|
||||
this.res.render = (page, opts) => {
|
||||
@@ -106,7 +106,7 @@ describe('UserPagesController', function() {
|
||||
return this.UserPagesController.registerPage(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should not set the newTemplateData if there is nothing in the session', function(done) {
|
||||
it('should not set the newTemplateData if there is nothing in the session', function (done) {
|
||||
this.res.render = (page, opts) => {
|
||||
assert.equal(opts.newTemplateData.templateName, undefined)
|
||||
return done()
|
||||
@@ -115,8 +115,8 @@ describe('UserPagesController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('loginForm', function() {
|
||||
it('should render the login page', function(done) {
|
||||
describe('loginForm', function () {
|
||||
it('should render the login page', function (done) {
|
||||
this.res.render = page => {
|
||||
page.should.equal('user/login')
|
||||
return done()
|
||||
@@ -124,8 +124,8 @@ describe('UserPagesController', function() {
|
||||
return this.UserPagesController.loginPage(this.req, this.res)
|
||||
})
|
||||
|
||||
describe('when an explicit redirect is set via query string', function() {
|
||||
beforeEach(function() {
|
||||
describe('when an explicit redirect is set via query string', function () {
|
||||
beforeEach(function () {
|
||||
this.AuthenticationController._getRedirectFromSession = sinon
|
||||
.stub()
|
||||
.returns(null)
|
||||
@@ -133,7 +133,7 @@ describe('UserPagesController', function() {
|
||||
return (this.req.query.redir = '/somewhere/in/particular')
|
||||
})
|
||||
|
||||
it('should set a redirect', function(done) {
|
||||
it('should set a redirect', function (done) {
|
||||
this.res.render = page => {
|
||||
this.AuthenticationController.setRedirectInSession.callCount.should.equal(
|
||||
1
|
||||
@@ -148,8 +148,8 @@ describe('UserPagesController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('sessionsPage', function() {
|
||||
beforeEach(function() {
|
||||
describe('sessionsPage', function () {
|
||||
beforeEach(function () {
|
||||
return this.UserSessionsManager.getAllUserSessions.callsArgWith(
|
||||
2,
|
||||
null,
|
||||
@@ -157,15 +157,15 @@ describe('UserPagesController', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should render user/sessions', function(done) {
|
||||
this.res.render = function(page) {
|
||||
it('should render user/sessions', function (done) {
|
||||
this.res.render = function (page) {
|
||||
page.should.equal('user/sessions')
|
||||
return done()
|
||||
}
|
||||
return this.UserPagesController.sessionsPage(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should have called getAllUserSessions', function(done) {
|
||||
it('should have called getAllUserSessions', function (done) {
|
||||
this.res.render = page => {
|
||||
this.UserSessionsManager.getAllUserSessions.callCount.should.equal(1)
|
||||
return done()
|
||||
@@ -173,15 +173,15 @@ describe('UserPagesController', function() {
|
||||
return this.UserPagesController.sessionsPage(this.req, this.res)
|
||||
})
|
||||
|
||||
describe('when getAllUserSessions produces an error', function() {
|
||||
beforeEach(function() {
|
||||
describe('when getAllUserSessions produces an error', function () {
|
||||
beforeEach(function () {
|
||||
return this.UserSessionsManager.getAllUserSessions.callsArgWith(
|
||||
2,
|
||||
new Error('woops')
|
||||
)
|
||||
})
|
||||
|
||||
it('should call next with an error', function(done) {
|
||||
it('should call next with an error', function (done) {
|
||||
this.next = err => {
|
||||
assert(err !== null)
|
||||
assert(err instanceof Error)
|
||||
@@ -196,8 +196,8 @@ describe('UserPagesController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('settingsPage', function() {
|
||||
beforeEach(function() {
|
||||
describe('settingsPage', function () {
|
||||
beforeEach(function () {
|
||||
this.request.get = sinon
|
||||
.stub()
|
||||
.callsArgWith(1, null, { statusCode: 200 }, { has_password: true })
|
||||
@@ -206,15 +206,15 @@ describe('UserPagesController', function() {
|
||||
.callsArgWith(1, null, this.user))
|
||||
})
|
||||
|
||||
it('should render user/settings', function(done) {
|
||||
this.res.render = function(page) {
|
||||
it('should render user/settings', function (done) {
|
||||
this.res.render = function (page) {
|
||||
page.should.equal('user/settings')
|
||||
return done()
|
||||
}
|
||||
return this.UserPagesController.settingsPage(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should send user', function(done) {
|
||||
it('should send user', function (done) {
|
||||
this.res.render = (page, opts) => {
|
||||
opts.user.should.equal(this.user)
|
||||
return done()
|
||||
@@ -222,7 +222,7 @@ describe('UserPagesController', function() {
|
||||
return this.UserPagesController.settingsPage(this.req, this.res)
|
||||
})
|
||||
|
||||
it("should set 'shouldAllowEditingDetails' to true", function(done) {
|
||||
it("should set 'shouldAllowEditingDetails' to true", function (done) {
|
||||
this.res.render = (page, opts) => {
|
||||
opts.shouldAllowEditingDetails.should.equal(true)
|
||||
return done()
|
||||
@@ -230,7 +230,7 @@ describe('UserPagesController', function() {
|
||||
return this.UserPagesController.settingsPage(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should restructure thirdPartyIdentifiers data for template use', function(done) {
|
||||
it('should restructure thirdPartyIdentifiers data for template use', function (done) {
|
||||
const expectedResult = {
|
||||
google: 'testId'
|
||||
}
|
||||
@@ -241,16 +241,16 @@ describe('UserPagesController', function() {
|
||||
return this.UserPagesController.settingsPage(this.req, this.res)
|
||||
})
|
||||
|
||||
describe('when ldap.updateUserDetailsOnLogin is true', function() {
|
||||
beforeEach(function() {
|
||||
describe('when ldap.updateUserDetailsOnLogin is true', function () {
|
||||
beforeEach(function () {
|
||||
return (this.settings.ldap = { updateUserDetailsOnLogin: true })
|
||||
})
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
return delete this.settings.ldap
|
||||
})
|
||||
|
||||
it('should set "shouldAllowEditingDetails" to false', function(done) {
|
||||
it('should set "shouldAllowEditingDetails" to false', function (done) {
|
||||
this.res.render = (page, opts) => {
|
||||
opts.shouldAllowEditingDetails.should.equal(false)
|
||||
return done()
|
||||
@@ -259,16 +259,16 @@ describe('UserPagesController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when saml.updateUserDetailsOnLogin is true', function() {
|
||||
beforeEach(function() {
|
||||
describe('when saml.updateUserDetailsOnLogin is true', function () {
|
||||
beforeEach(function () {
|
||||
return (this.settings.saml = { updateUserDetailsOnLogin: true })
|
||||
})
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
return delete this.settings.saml
|
||||
})
|
||||
|
||||
it('should set "shouldAllowEditingDetails" to false', function(done) {
|
||||
it('should set "shouldAllowEditingDetails" to false', function (done) {
|
||||
this.res.render = (page, opts) => {
|
||||
opts.shouldAllowEditingDetails.should.equal(false)
|
||||
return done()
|
||||
|
||||
@@ -22,8 +22,8 @@ const sinon = require('sinon')
|
||||
const { expect } = require('chai')
|
||||
const EmailHelper = require('../../../../app/src/Features/Helpers/EmailHelper')
|
||||
|
||||
describe('UserRegistrationHandler', function() {
|
||||
beforeEach(function() {
|
||||
describe('UserRegistrationHandler', function () {
|
||||
beforeEach(function () {
|
||||
this.user = { _id: (this.user_id = '31j2lk21kjl') }
|
||||
this.User = { updateOne: sinon.stub().callsArgWith(2) }
|
||||
this.UserGetter = { getUserByAnyEmail: sinon.stub() }
|
||||
@@ -64,22 +64,22 @@ describe('UserRegistrationHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('validate Register Request', function() {
|
||||
it('allows passing validation through', function() {
|
||||
describe('validate Register Request', function () {
|
||||
it('allows passing validation through', function () {
|
||||
const result = this.handler._registrationRequestIsValid(
|
||||
this.passingRequest
|
||||
)
|
||||
return result.should.equal(true)
|
||||
})
|
||||
|
||||
describe('failing email validation', function() {
|
||||
beforeEach(function() {
|
||||
describe('failing email validation', function () {
|
||||
beforeEach(function () {
|
||||
return this.AuthenticationManager.validateEmail.returns({
|
||||
message: 'email not set'
|
||||
})
|
||||
})
|
||||
|
||||
it('does not allow through', function() {
|
||||
it('does not allow through', function () {
|
||||
const result = this.handler._registrationRequestIsValid(
|
||||
this.passingRequest
|
||||
)
|
||||
@@ -87,14 +87,14 @@ describe('UserRegistrationHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('failing password validation', function() {
|
||||
beforeEach(function() {
|
||||
describe('failing password validation', function () {
|
||||
beforeEach(function () {
|
||||
return this.AuthenticationManager.validatePassword.returns({
|
||||
message: 'password is too short'
|
||||
})
|
||||
})
|
||||
|
||||
it('does not allow through', function() {
|
||||
it('does not allow through', function () {
|
||||
const result = this.handler._registrationRequestIsValid(
|
||||
this.passingRequest
|
||||
)
|
||||
@@ -103,9 +103,9 @@ describe('UserRegistrationHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('registerNewUser', function() {
|
||||
describe('holdingAccount', function(done) {
|
||||
beforeEach(function() {
|
||||
describe('registerNewUser', function () {
|
||||
describe('holdingAccount', function (done) {
|
||||
beforeEach(function () {
|
||||
this.user.holdingAccount = true
|
||||
this.handler._registrationRequestIsValid = sinon.stub().returns(true)
|
||||
return this.UserGetter.getUserByAnyEmail.callsArgWith(
|
||||
@@ -115,14 +115,14 @@ describe('UserRegistrationHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should not create a new user if there is a holding account there', function(done) {
|
||||
it('should not create a new user if there is a holding account there', function (done) {
|
||||
return this.handler.registerNewUser(this.passingRequest, err => {
|
||||
this.UserCreator.createNewUser.called.should.equal(false)
|
||||
return done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should set holding account to false', function(done) {
|
||||
it('should set holding account to false', function (done) {
|
||||
return this.handler.registerNewUser(this.passingRequest, err => {
|
||||
const update = this.User.updateOne.args[0]
|
||||
assert.deepEqual(update[0], { _id: this.user._id })
|
||||
@@ -132,8 +132,8 @@ describe('UserRegistrationHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('invalidRequest', function() {
|
||||
it('should not create a new user if the the request is not valid', function(done) {
|
||||
describe('invalidRequest', function () {
|
||||
it('should not create a new user if the the request is not valid', function (done) {
|
||||
this.handler._registrationRequestIsValid = sinon.stub().returns(false)
|
||||
return this.handler.registerNewUser(this.passingRequest, err => {
|
||||
expect(err).to.exist
|
||||
@@ -142,7 +142,7 @@ describe('UserRegistrationHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should return email registered in the error if there is a non holdingAccount there', function(done) {
|
||||
it('should return email registered in the error if there is a non holdingAccount there', function (done) {
|
||||
this.UserGetter.getUserByAnyEmail.callsArgWith(
|
||||
1,
|
||||
null,
|
||||
@@ -160,13 +160,13 @@ describe('UserRegistrationHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('validRequest', function() {
|
||||
beforeEach(function() {
|
||||
describe('validRequest', function () {
|
||||
beforeEach(function () {
|
||||
this.handler._registrationRequestIsValid = sinon.stub().returns(true)
|
||||
return this.UserGetter.getUserByAnyEmail.callsArgWith(1)
|
||||
})
|
||||
|
||||
it('should create a new user', function(done) {
|
||||
it('should create a new user', function (done) {
|
||||
return this.handler.registerNewUser(this.passingRequest, err => {
|
||||
this.UserCreator.createNewUser
|
||||
.calledWith({
|
||||
@@ -180,7 +180,7 @@ describe('UserRegistrationHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('lower case email', function(done) {
|
||||
it('lower case email', function (done) {
|
||||
this.passingRequest.email = 'soMe@eMail.cOm'
|
||||
return this.handler.registerNewUser(this.passingRequest, err => {
|
||||
this.UserCreator.createNewUser.args[0][0].email.should.equal(
|
||||
@@ -190,7 +190,7 @@ describe('UserRegistrationHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('trim white space from email', function(done) {
|
||||
it('trim white space from email', function (done) {
|
||||
this.passingRequest.email = ' some@email.com '
|
||||
return this.handler.registerNewUser(this.passingRequest, err => {
|
||||
this.UserCreator.createNewUser.args[0][0].email.should.equal(
|
||||
@@ -200,7 +200,7 @@ describe('UserRegistrationHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should set the password', function(done) {
|
||||
it('should set the password', function (done) {
|
||||
return this.handler.registerNewUser(this.passingRequest, err => {
|
||||
this.AuthenticationManager.setUserPassword
|
||||
.calledWith(this.user, this.passingRequest.password)
|
||||
@@ -209,7 +209,7 @@ describe('UserRegistrationHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should add the user to the newsletter if accepted terms', function(done) {
|
||||
it('should add the user to the newsletter if accepted terms', function (done) {
|
||||
this.passingRequest.subscribeToNewsletter = 'true'
|
||||
return this.handler.registerNewUser(this.passingRequest, err => {
|
||||
this.NewsLetterManager.subscribe
|
||||
@@ -219,7 +219,7 @@ describe('UserRegistrationHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should not add the user to the newsletter if not accepted terms', function(done) {
|
||||
it('should not add the user to the newsletter if not accepted terms', function (done) {
|
||||
return this.handler.registerNewUser(this.passingRequest, err => {
|
||||
this.NewsLetterManager.subscribe
|
||||
.calledWith(this.user)
|
||||
@@ -228,7 +228,7 @@ describe('UserRegistrationHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should track the registration event', function(done) {
|
||||
it('should track the registration event', function (done) {
|
||||
return this.handler.registerNewUser(this.passingRequest, err => {
|
||||
this.AnalyticsManager.recordEvent
|
||||
.calledWith(this.user._id, 'user-registered')
|
||||
@@ -238,13 +238,13 @@ describe('UserRegistrationHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should call the ReferalAllocator', function(done) {
|
||||
it('should call the ReferalAllocator', function (done) {
|
||||
return done()
|
||||
})
|
||||
})
|
||||
|
||||
describe('registerNewUserAndSendActivationEmail', function() {
|
||||
beforeEach(function() {
|
||||
describe('registerNewUserAndSendActivationEmail', function () {
|
||||
beforeEach(function () {
|
||||
this.email = 'Email@example.com'
|
||||
this.crypto.randomBytes = sinon.stub().returns({
|
||||
toString: () => {
|
||||
@@ -259,8 +259,8 @@ describe('UserRegistrationHandler', function() {
|
||||
return (this.callback = sinon.stub())
|
||||
})
|
||||
|
||||
describe('with a new user', function() {
|
||||
beforeEach(function() {
|
||||
describe('with a new user', function () {
|
||||
beforeEach(function () {
|
||||
this.user.email = this.email.toLowerCase()
|
||||
this.handler.registerNewUser.callsArgWith(1, null, this.user)
|
||||
return this.handler.registerNewUserAndSendActivationEmail(
|
||||
@@ -269,7 +269,7 @@ describe('UserRegistrationHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should ask the UserRegistrationHandler to register user', function() {
|
||||
it('should ask the UserRegistrationHandler to register user', function () {
|
||||
return this.handler.registerNewUser
|
||||
.calledWith({
|
||||
email: this.email,
|
||||
@@ -278,7 +278,7 @@ describe('UserRegistrationHandler', function() {
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should generate a new password reset token', function() {
|
||||
it('should generate a new password reset token', function () {
|
||||
const data = {
|
||||
user_id: this.user._id.toString(),
|
||||
email: this.user.email
|
||||
@@ -288,7 +288,7 @@ describe('UserRegistrationHandler', function() {
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should send a registered email', function() {
|
||||
it('should send a registered email', function () {
|
||||
return this.EmailHandler.sendEmail
|
||||
.calledWith('registered', {
|
||||
to: this.user.email,
|
||||
@@ -297,7 +297,7 @@ describe('UserRegistrationHandler', function() {
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should return the user', function() {
|
||||
it('should return the user', function () {
|
||||
return this.callback
|
||||
.calledWith(
|
||||
null,
|
||||
@@ -308,8 +308,8 @@ describe('UserRegistrationHandler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a user that already exists', function() {
|
||||
beforeEach(function() {
|
||||
describe('with a user that already exists', function () {
|
||||
beforeEach(function () {
|
||||
this.handler.registerNewUser.callsArgWith(
|
||||
1,
|
||||
new Error('EmailAlreadyRegistered'),
|
||||
@@ -321,7 +321,7 @@ describe('UserRegistrationHandler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should still generate a new password token and email', function() {
|
||||
it('should still generate a new password token and email', function () {
|
||||
this.OneTimeTokenHandler.getNewToken.called.should.equal(true)
|
||||
return this.EmailHandler.sendEmail.called.should.equal(true)
|
||||
})
|
||||
|
||||
@@ -16,8 +16,8 @@ const { expect } = require('chai')
|
||||
const modulePath = '../../../../app/src/Features/User/UserSessionsManager.js'
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
|
||||
describe('UserSessionsManager', function() {
|
||||
beforeEach(function() {
|
||||
describe('UserSessionsManager', function () {
|
||||
beforeEach(function () {
|
||||
this.user = {
|
||||
_id: 'abcd',
|
||||
email: 'user@example.com'
|
||||
@@ -61,15 +61,15 @@ describe('UserSessionsManager', function() {
|
||||
}))
|
||||
})
|
||||
|
||||
describe('_sessionKey', function() {
|
||||
it('should build the correct key', function() {
|
||||
describe('_sessionKey', function () {
|
||||
it('should build the correct key', function () {
|
||||
const result = this.UserSessionsManager._sessionKey(this.sessionId)
|
||||
return result.should.equal('sess:some_session_id')
|
||||
})
|
||||
})
|
||||
|
||||
describe('trackSession', function() {
|
||||
beforeEach(function() {
|
||||
describe('trackSession', function () {
|
||||
beforeEach(function () {
|
||||
this.call = callback => {
|
||||
return this.UserSessionsManager.trackSession(
|
||||
this.user,
|
||||
@@ -83,18 +83,18 @@ describe('UserSessionsManager', function() {
|
||||
.returns(null))
|
||||
})
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
return this._checkSessions.restore()
|
||||
})
|
||||
|
||||
it('should not produce an error', function(done) {
|
||||
it('should not produce an error', function (done) {
|
||||
return this.call(err => {
|
||||
expect(err).to.not.be.instanceof(Error)
|
||||
return done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should call the appropriate redis methods', function(done) {
|
||||
it('should call the appropriate redis methods', function (done) {
|
||||
return this.call(err => {
|
||||
this.rclient.multi.callCount.should.equal(1)
|
||||
this.rclient.sadd.callCount.should.equal(1)
|
||||
@@ -104,26 +104,26 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should call _checkSessions', function(done) {
|
||||
it('should call _checkSessions', function (done) {
|
||||
return this.call(err => {
|
||||
this._checkSessions.callCount.should.equal(1)
|
||||
return done()
|
||||
})
|
||||
})
|
||||
|
||||
describe('when rclient produces an error', function() {
|
||||
beforeEach(function() {
|
||||
describe('when rclient produces an error', function () {
|
||||
beforeEach(function () {
|
||||
return this.rclient.exec.callsArgWith(0, new Error('woops'))
|
||||
})
|
||||
|
||||
it('should produce an error', function(done) {
|
||||
it('should produce an error', function (done) {
|
||||
return this.call(err => {
|
||||
expect(err).to.be.instanceof(Error)
|
||||
return done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should not call _checkSessions', function(done) {
|
||||
it('should not call _checkSessions', function (done) {
|
||||
return this.call(err => {
|
||||
this._checkSessions.callCount.should.equal(0)
|
||||
return done()
|
||||
@@ -131,8 +131,8 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when no user is supplied', function() {
|
||||
beforeEach(function() {
|
||||
describe('when no user is supplied', function () {
|
||||
beforeEach(function () {
|
||||
return (this.call = callback => {
|
||||
return this.UserSessionsManager.trackSession(
|
||||
null,
|
||||
@@ -142,7 +142,7 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should not produce an error', function(done) {
|
||||
it('should not produce an error', function (done) {
|
||||
return this.call(err => {
|
||||
expect(err).to.not.be.instanceof(Error)
|
||||
expect(err).to.equal(null)
|
||||
@@ -150,7 +150,7 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should not call the appropriate redis methods', function(done) {
|
||||
it('should not call the appropriate redis methods', function (done) {
|
||||
return this.call(err => {
|
||||
this.rclient.multi.callCount.should.equal(0)
|
||||
this.rclient.sadd.callCount.should.equal(0)
|
||||
@@ -160,7 +160,7 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should not call _checkSessions', function(done) {
|
||||
it('should not call _checkSessions', function (done) {
|
||||
return this.call(err => {
|
||||
this._checkSessions.callCount.should.equal(0)
|
||||
return done()
|
||||
@@ -168,8 +168,8 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when no sessionId is supplied', function() {
|
||||
beforeEach(function() {
|
||||
describe('when no sessionId is supplied', function () {
|
||||
beforeEach(function () {
|
||||
return (this.call = callback => {
|
||||
return this.UserSessionsManager.trackSession(
|
||||
this.user,
|
||||
@@ -179,7 +179,7 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should not produce an error', function(done) {
|
||||
it('should not produce an error', function (done) {
|
||||
return this.call(err => {
|
||||
expect(err).to.not.be.instanceof(Error)
|
||||
expect(err).to.equal(null)
|
||||
@@ -187,7 +187,7 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should not call the appropriate redis methods', function(done) {
|
||||
it('should not call the appropriate redis methods', function (done) {
|
||||
return this.call(err => {
|
||||
this.rclient.multi.callCount.should.equal(0)
|
||||
this.rclient.sadd.callCount.should.equal(0)
|
||||
@@ -197,7 +197,7 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should not call _checkSessions', function(done) {
|
||||
it('should not call _checkSessions', function (done) {
|
||||
return this.call(err => {
|
||||
this._checkSessions.callCount.should.equal(0)
|
||||
return done()
|
||||
@@ -206,8 +206,8 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('untrackSession', function() {
|
||||
beforeEach(function() {
|
||||
describe('untrackSession', function () {
|
||||
beforeEach(function () {
|
||||
this.call = callback => {
|
||||
return this.UserSessionsManager.untrackSession(
|
||||
this.user,
|
||||
@@ -221,11 +221,11 @@ describe('UserSessionsManager', function() {
|
||||
.returns(null))
|
||||
})
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
return this._checkSessions.restore()
|
||||
})
|
||||
|
||||
it('should not produce an error', function(done) {
|
||||
it('should not produce an error', function (done) {
|
||||
return this.call(err => {
|
||||
expect(err).to.not.be.instanceof(Error)
|
||||
expect(err).to.equal(undefined)
|
||||
@@ -233,7 +233,7 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should call the appropriate redis methods', function(done) {
|
||||
it('should call the appropriate redis methods', function (done) {
|
||||
return this.call(err => {
|
||||
this.rclient.multi.callCount.should.equal(1)
|
||||
this.rclient.srem.callCount.should.equal(1)
|
||||
@@ -243,26 +243,26 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should call _checkSessions', function(done) {
|
||||
it('should call _checkSessions', function (done) {
|
||||
return this.call(err => {
|
||||
this._checkSessions.callCount.should.equal(1)
|
||||
return done()
|
||||
})
|
||||
})
|
||||
|
||||
describe('when rclient produces an error', function() {
|
||||
beforeEach(function() {
|
||||
describe('when rclient produces an error', function () {
|
||||
beforeEach(function () {
|
||||
return this.rclient.exec.callsArgWith(0, new Error('woops'))
|
||||
})
|
||||
|
||||
it('should produce an error', function(done) {
|
||||
it('should produce an error', function (done) {
|
||||
return this.call(err => {
|
||||
expect(err).to.be.instanceof(Error)
|
||||
return done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should not call _checkSessions', function(done) {
|
||||
it('should not call _checkSessions', function (done) {
|
||||
return this.call(err => {
|
||||
this._checkSessions.callCount.should.equal(0)
|
||||
return done()
|
||||
@@ -270,8 +270,8 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when no user is supplied', function() {
|
||||
beforeEach(function() {
|
||||
describe('when no user is supplied', function () {
|
||||
beforeEach(function () {
|
||||
return (this.call = callback => {
|
||||
return this.UserSessionsManager.untrackSession(
|
||||
null,
|
||||
@@ -281,7 +281,7 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should not produce an error', function(done) {
|
||||
it('should not produce an error', function (done) {
|
||||
return this.call(err => {
|
||||
expect(err).to.not.be.instanceof(Error)
|
||||
expect(err).to.equal(null)
|
||||
@@ -289,7 +289,7 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should not call the appropriate redis methods', function(done) {
|
||||
it('should not call the appropriate redis methods', function (done) {
|
||||
return this.call(err => {
|
||||
this.rclient.multi.callCount.should.equal(0)
|
||||
this.rclient.srem.callCount.should.equal(0)
|
||||
@@ -299,7 +299,7 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should not call _checkSessions', function(done) {
|
||||
it('should not call _checkSessions', function (done) {
|
||||
return this.call(err => {
|
||||
this._checkSessions.callCount.should.equal(0)
|
||||
return done()
|
||||
@@ -307,8 +307,8 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when no sessionId is supplied', function() {
|
||||
beforeEach(function() {
|
||||
describe('when no sessionId is supplied', function () {
|
||||
beforeEach(function () {
|
||||
return (this.call = callback => {
|
||||
return this.UserSessionsManager.untrackSession(
|
||||
this.user,
|
||||
@@ -318,7 +318,7 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should not produce an error', function(done) {
|
||||
it('should not produce an error', function (done) {
|
||||
return this.call(err => {
|
||||
expect(err).to.not.be.instanceof(Error)
|
||||
expect(err).to.equal(null)
|
||||
@@ -326,7 +326,7 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should not call the appropriate redis methods', function(done) {
|
||||
it('should not call the appropriate redis methods', function (done) {
|
||||
return this.call(err => {
|
||||
this.rclient.multi.callCount.should.equal(0)
|
||||
this.rclient.srem.callCount.should.equal(0)
|
||||
@@ -336,7 +336,7 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should not call _checkSessions', function(done) {
|
||||
it('should not call _checkSessions', function (done) {
|
||||
return this.call(err => {
|
||||
this._checkSessions.callCount.should.equal(0)
|
||||
return done()
|
||||
@@ -345,8 +345,8 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('revokeAllUserSessions', function() {
|
||||
beforeEach(function() {
|
||||
describe('revokeAllUserSessions', function () {
|
||||
beforeEach(function () {
|
||||
this.sessionKeys = ['sess:one', 'sess:two']
|
||||
this.retain = []
|
||||
this.rclient.smembers.callsArgWith(1, null, this.sessionKeys)
|
||||
@@ -361,7 +361,7 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should not produce an error', function(done) {
|
||||
it('should not produce an error', function (done) {
|
||||
return this.call(err => {
|
||||
expect(err).to.not.be.instanceof(Error)
|
||||
expect(err).to.equal(null)
|
||||
@@ -369,7 +369,7 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should call the appropriate redis methods', function(done) {
|
||||
it('should call the appropriate redis methods', function (done) {
|
||||
return this.call(err => {
|
||||
this.rclient.smembers.callCount.should.equal(1)
|
||||
|
||||
@@ -390,8 +390,8 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when a session is retained', function() {
|
||||
beforeEach(function() {
|
||||
describe('when a session is retained', function () {
|
||||
beforeEach(function () {
|
||||
this.sessionKeys = ['sess:one', 'sess:two', 'sess:three', 'sess:four']
|
||||
this.retain = ['two']
|
||||
this.rclient.smembers.callsArgWith(1, null, this.sessionKeys)
|
||||
@@ -405,7 +405,7 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should not produce an error', function(done) {
|
||||
it('should not produce an error', function (done) {
|
||||
return this.call(err => {
|
||||
expect(err).to.not.be.instanceof(Error)
|
||||
expect(err).to.equal(null)
|
||||
@@ -413,7 +413,7 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should call the appropriate redis methods', function(done) {
|
||||
it('should call the appropriate redis methods', function (done) {
|
||||
return this.call(err => {
|
||||
this.rclient.smembers.callCount.should.equal(1)
|
||||
this.rclient.del.callCount.should.equal(this.sessionKeys.length - 1)
|
||||
@@ -422,7 +422,7 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should remove all sessions except for the retained one', function(done) {
|
||||
it('should remove all sessions except for the retained one', function (done) {
|
||||
return this.call(err => {
|
||||
expect(this.rclient.del.firstCall.args[0]).to.deep.equal('sess:one')
|
||||
expect(this.rclient.del.secondCall.args[0]).to.deep.equal(
|
||||
@@ -439,21 +439,21 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when rclient produces an error', function() {
|
||||
beforeEach(function() {
|
||||
describe('when rclient produces an error', function () {
|
||||
beforeEach(function () {
|
||||
return (this.rclient.del = sinon
|
||||
.stub()
|
||||
.callsArgWith(1, new Error('woops')))
|
||||
})
|
||||
|
||||
it('should produce an error', function(done) {
|
||||
it('should produce an error', function (done) {
|
||||
return this.call(err => {
|
||||
expect(err).to.be.instanceof(Error)
|
||||
return done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should not call rclient.srem', function(done) {
|
||||
it('should not call rclient.srem', function (done) {
|
||||
return this.call(err => {
|
||||
this.rclient.srem.callCount.should.equal(0)
|
||||
return done()
|
||||
@@ -461,8 +461,8 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when no user is supplied', function() {
|
||||
beforeEach(function() {
|
||||
describe('when no user is supplied', function () {
|
||||
beforeEach(function () {
|
||||
return (this.call = callback => {
|
||||
return this.UserSessionsManager.revokeAllUserSessions(
|
||||
null,
|
||||
@@ -472,7 +472,7 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should not produce an error', function(done) {
|
||||
it('should not produce an error', function (done) {
|
||||
return this.call(err => {
|
||||
expect(err).to.not.be.instanceof(Error)
|
||||
expect(err).to.equal(null)
|
||||
@@ -480,7 +480,7 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should not call the appropriate redis methods', function(done) {
|
||||
it('should not call the appropriate redis methods', function (done) {
|
||||
return this.call(err => {
|
||||
this.rclient.smembers.callCount.should.equal(0)
|
||||
this.rclient.del.callCount.should.equal(0)
|
||||
@@ -490,12 +490,12 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when there are no keys to delete', function() {
|
||||
beforeEach(function() {
|
||||
describe('when there are no keys to delete', function () {
|
||||
beforeEach(function () {
|
||||
return this.rclient.smembers.callsArgWith(1, null, [])
|
||||
})
|
||||
|
||||
it('should not produce an error', function(done) {
|
||||
it('should not produce an error', function (done) {
|
||||
return this.call(err => {
|
||||
expect(err).to.not.be.instanceof(Error)
|
||||
expect(err).to.equal(null)
|
||||
@@ -503,7 +503,7 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should not do the delete operation', function(done) {
|
||||
it('should not do the delete operation', function (done) {
|
||||
return this.call(err => {
|
||||
this.rclient.smembers.callCount.should.equal(1)
|
||||
this.rclient.del.callCount.should.equal(0)
|
||||
@@ -514,15 +514,15 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('touch', function() {
|
||||
beforeEach(function() {
|
||||
describe('touch', function () {
|
||||
beforeEach(function () {
|
||||
this.rclient.pexpire.callsArgWith(2, null)
|
||||
return (this.call = callback => {
|
||||
return this.UserSessionsManager.touch(this.user, callback)
|
||||
})
|
||||
})
|
||||
|
||||
it('should not produce an error', function(done) {
|
||||
it('should not produce an error', function (done) {
|
||||
return this.call(err => {
|
||||
expect(err).to.not.be.instanceof(Error)
|
||||
expect(err).to.equal(null)
|
||||
@@ -530,19 +530,19 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should call rclient.pexpire', function(done) {
|
||||
it('should call rclient.pexpire', function (done) {
|
||||
return this.call(err => {
|
||||
this.rclient.pexpire.callCount.should.equal(1)
|
||||
return done()
|
||||
})
|
||||
})
|
||||
|
||||
describe('when rclient produces an error', function() {
|
||||
beforeEach(function() {
|
||||
describe('when rclient produces an error', function () {
|
||||
beforeEach(function () {
|
||||
return this.rclient.pexpire.callsArgWith(2, new Error('woops'))
|
||||
})
|
||||
|
||||
it('should produce an error', function(done) {
|
||||
it('should produce an error', function (done) {
|
||||
return this.call(err => {
|
||||
expect(err).to.be.instanceof(Error)
|
||||
return done()
|
||||
@@ -550,14 +550,14 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when no user is supplied', function() {
|
||||
beforeEach(function() {
|
||||
describe('when no user is supplied', function () {
|
||||
beforeEach(function () {
|
||||
return (this.call = callback => {
|
||||
return this.UserSessionsManager.touch(null, callback)
|
||||
})
|
||||
})
|
||||
|
||||
it('should not produce an error', function(done) {
|
||||
it('should not produce an error', function (done) {
|
||||
return this.call(err => {
|
||||
expect(err).to.not.be.instanceof(Error)
|
||||
expect(err).to.equal(null)
|
||||
@@ -565,7 +565,7 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should not call pexpire', function(done) {
|
||||
it('should not call pexpire', function (done) {
|
||||
return this.call(err => {
|
||||
this.rclient.pexpire.callCount.should.equal(0)
|
||||
return done()
|
||||
@@ -574,8 +574,8 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('getAllUserSessions', function() {
|
||||
beforeEach(function() {
|
||||
describe('getAllUserSessions', function () {
|
||||
beforeEach(function () {
|
||||
this.sessionKeys = ['sess:one', 'sess:two', 'sess:three']
|
||||
this.sessions = [
|
||||
'{"user": {"ip_address": "a", "session_created": "b"}}',
|
||||
@@ -596,14 +596,14 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should not produce an error', function(done) {
|
||||
it('should not produce an error', function (done) {
|
||||
return this.call((err, sessions) => {
|
||||
expect(err).to.equal(null)
|
||||
return done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should get sessions', function(done) {
|
||||
it('should get sessions', function (done) {
|
||||
return this.call((err, sessions) => {
|
||||
expect(sessions).to.deep.equal([
|
||||
{ ip_address: 'a', session_created: 'b' },
|
||||
@@ -613,48 +613,48 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should have called rclient.smembers', function(done) {
|
||||
it('should have called rclient.smembers', function (done) {
|
||||
return this.call((err, sessions) => {
|
||||
this.rclient.smembers.callCount.should.equal(1)
|
||||
return done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should have called rclient.get', function(done) {
|
||||
it('should have called rclient.get', function (done) {
|
||||
return this.call((err, sessions) => {
|
||||
this.rclient.get.callCount.should.equal(this.sessionKeys.length - 1)
|
||||
return done()
|
||||
})
|
||||
})
|
||||
|
||||
describe('when there are no other sessions', function() {
|
||||
beforeEach(function() {
|
||||
describe('when there are no other sessions', function () {
|
||||
beforeEach(function () {
|
||||
this.sessionKeys = ['sess:two']
|
||||
return this.rclient.smembers.callsArgWith(1, null, this.sessionKeys)
|
||||
})
|
||||
|
||||
it('should not produce an error', function(done) {
|
||||
it('should not produce an error', function (done) {
|
||||
return this.call((err, sessions) => {
|
||||
expect(err).to.equal(null)
|
||||
return done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should produce an empty list of sessions', function(done) {
|
||||
it('should produce an empty list of sessions', function (done) {
|
||||
return this.call((err, sessions) => {
|
||||
expect(sessions).to.deep.equal([])
|
||||
return done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should have called rclient.smembers', function(done) {
|
||||
it('should have called rclient.smembers', function (done) {
|
||||
return this.call((err, sessions) => {
|
||||
this.rclient.smembers.callCount.should.equal(1)
|
||||
return done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should not have called rclient.mget', function(done) {
|
||||
it('should not have called rclient.mget', function (done) {
|
||||
return this.call((err, sessions) => {
|
||||
this.rclient.mget.callCount.should.equal(0)
|
||||
return done()
|
||||
@@ -662,12 +662,12 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when smembers produces an error', function() {
|
||||
beforeEach(function() {
|
||||
describe('when smembers produces an error', function () {
|
||||
beforeEach(function () {
|
||||
return this.rclient.smembers.callsArgWith(1, new Error('woops'))
|
||||
})
|
||||
|
||||
it('should produce an error', function(done) {
|
||||
it('should produce an error', function (done) {
|
||||
return this.call((err, sessions) => {
|
||||
expect(err).to.not.equal(null)
|
||||
expect(err).to.be.instanceof(Error)
|
||||
@@ -675,7 +675,7 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should not have called rclient.mget', function(done) {
|
||||
it('should not have called rclient.mget', function (done) {
|
||||
return this.call((err, sessions) => {
|
||||
this.rclient.mget.callCount.should.equal(0)
|
||||
return done()
|
||||
@@ -683,14 +683,14 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when get produces an error', function() {
|
||||
beforeEach(function() {
|
||||
describe('when get produces an error', function () {
|
||||
beforeEach(function () {
|
||||
return (this.rclient.get = sinon
|
||||
.stub()
|
||||
.callsArgWith(1, new Error('woops')))
|
||||
})
|
||||
|
||||
it('should produce an error', function(done) {
|
||||
it('should produce an error', function (done) {
|
||||
return this.call((err, sessions) => {
|
||||
expect(err).to.not.equal(null)
|
||||
expect(err).to.be.instanceof(Error)
|
||||
@@ -700,8 +700,8 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('_checkSessions', function() {
|
||||
beforeEach(function() {
|
||||
describe('_checkSessions', function () {
|
||||
beforeEach(function () {
|
||||
this.call = callback => {
|
||||
return this.UserSessionsManager._checkSessions(this.user, callback)
|
||||
}
|
||||
@@ -711,7 +711,7 @@ describe('UserSessionsManager', function() {
|
||||
return this.rclient.srem.callsArgWith(2, null, {})
|
||||
})
|
||||
|
||||
it('should not produce an error', function(done) {
|
||||
it('should not produce an error', function (done) {
|
||||
return this.call(err => {
|
||||
expect(err).to.not.be.instanceof(Error)
|
||||
expect(err).to.equal(undefined)
|
||||
@@ -719,7 +719,7 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should call the appropriate redis methods', function(done) {
|
||||
it('should call the appropriate redis methods', function (done) {
|
||||
return this.call(err => {
|
||||
this.rclient.smembers.callCount.should.equal(1)
|
||||
this.rclient.get.callCount.should.equal(2)
|
||||
@@ -728,13 +728,13 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when one of the keys is not present in redis', function() {
|
||||
beforeEach(function() {
|
||||
describe('when one of the keys is not present in redis', function () {
|
||||
beforeEach(function () {
|
||||
this.rclient.get.onCall(0).callsArgWith(1, null, 'some-val')
|
||||
return this.rclient.get.onCall(1).callsArgWith(1, null, null)
|
||||
})
|
||||
|
||||
it('should not produce an error', function(done) {
|
||||
it('should not produce an error', function (done) {
|
||||
return this.call(err => {
|
||||
expect(err).to.not.be.instanceof(Error)
|
||||
expect(err).to.equal(undefined)
|
||||
@@ -742,7 +742,7 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should remove that key from the set', function(done) {
|
||||
it('should remove that key from the set', function (done) {
|
||||
return this.call(err => {
|
||||
this.rclient.smembers.callCount.should.equal(1)
|
||||
this.rclient.get.callCount.should.equal(2)
|
||||
@@ -753,14 +753,14 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when no user is supplied', function() {
|
||||
beforeEach(function() {
|
||||
describe('when no user is supplied', function () {
|
||||
beforeEach(function () {
|
||||
return (this.call = callback => {
|
||||
return this.UserSessionsManager._checkSessions(null, callback)
|
||||
})
|
||||
})
|
||||
|
||||
it('should not produce an error', function(done) {
|
||||
it('should not produce an error', function (done) {
|
||||
return this.call(err => {
|
||||
expect(err).to.not.be.instanceof(Error)
|
||||
expect(err).to.equal(null)
|
||||
@@ -768,7 +768,7 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should not call redis methods', function(done) {
|
||||
it('should not call redis methods', function (done) {
|
||||
return this.call(err => {
|
||||
this.rclient.smembers.callCount.should.equal(0)
|
||||
this.rclient.get.callCount.should.equal(0)
|
||||
@@ -777,20 +777,20 @@ describe('UserSessionsManager', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when one of the get operations produces an error', function() {
|
||||
beforeEach(function() {
|
||||
describe('when one of the get operations produces an error', function () {
|
||||
beforeEach(function () {
|
||||
this.rclient.get.onCall(0).callsArgWith(1, new Error('woops'), null)
|
||||
return this.rclient.get.onCall(1).callsArgWith(1, null, null)
|
||||
})
|
||||
|
||||
it('should produce an error', function(done) {
|
||||
it('should produce an error', function (done) {
|
||||
return this.call(err => {
|
||||
expect(err).to.be.instanceof(Error)
|
||||
return done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should call the right redis methods, bailing out early', function(done) {
|
||||
it('should call the right redis methods, bailing out early', function (done) {
|
||||
return this.call(err => {
|
||||
this.rclient.smembers.callCount.should.equal(1)
|
||||
this.rclient.get.callCount.should.equal(1)
|
||||
|
||||
@@ -9,8 +9,8 @@ const tk = require('timekeeper')
|
||||
const { expect } = require('chai')
|
||||
const { normalizeQuery } = require('../../../../app/src/Features/Helpers/Mongo')
|
||||
|
||||
describe('UserUpdater', function() {
|
||||
beforeEach(function() {
|
||||
describe('UserUpdater', function () {
|
||||
beforeEach(function () {
|
||||
tk.freeze(Date.now())
|
||||
this.mongodb = {
|
||||
db: {},
|
||||
@@ -95,17 +95,17 @@ describe('UserUpdater', function() {
|
||||
this.callback = sinon.stub()
|
||||
})
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
return tk.reset()
|
||||
})
|
||||
|
||||
describe('addAffiliationForNewUser', function(done) {
|
||||
beforeEach(function() {
|
||||
describe('addAffiliationForNewUser', function (done) {
|
||||
beforeEach(function () {
|
||||
this.UserUpdater.updateUser = sinon
|
||||
.stub()
|
||||
.callsArgWith(2, null, { n: 1, nModified: 1, ok: 1 })
|
||||
})
|
||||
it('should not remove affiliationUnchecked flag if v1 returns an error', function(done) {
|
||||
it('should not remove affiliationUnchecked flag if v1 returns an error', function (done) {
|
||||
this.addAffiliation.yields(true)
|
||||
this.UserUpdater.addAffiliationForNewUser(
|
||||
this.stubbedUser._id,
|
||||
@@ -118,7 +118,7 @@ describe('UserUpdater', function() {
|
||||
}
|
||||
)
|
||||
})
|
||||
it('should remove affiliationUnchecked flag if v1 does not return an error', function(done) {
|
||||
it('should remove affiliationUnchecked flag if v1 does not return an error', function (done) {
|
||||
this.addAffiliation.yields()
|
||||
this.UserUpdater.addAffiliationForNewUser(
|
||||
this.stubbedUser._id,
|
||||
@@ -137,8 +137,8 @@ describe('UserUpdater', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('changeEmailAddress', function() {
|
||||
beforeEach(function() {
|
||||
describe('changeEmailAddress', function () {
|
||||
beforeEach(function () {
|
||||
this.auditLog = {
|
||||
initiatorId: 'abc123',
|
||||
ipAddress: '0:0:0:0'
|
||||
@@ -149,7 +149,7 @@ describe('UserUpdater', function() {
|
||||
this.UserUpdater.removeEmailAddress = sinon.stub().callsArgWith(2)
|
||||
})
|
||||
|
||||
it('change email', function(done) {
|
||||
it('change email', function (done) {
|
||||
this.UserUpdater.changeEmailAddress(
|
||||
this.stubbedUser._id,
|
||||
this.newEmail,
|
||||
@@ -176,7 +176,7 @@ describe('UserUpdater', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('validates email', function(done) {
|
||||
it('validates email', function (done) {
|
||||
this.UserUpdater.changeEmailAddress(
|
||||
this.stubbedUser._id,
|
||||
'foo',
|
||||
@@ -188,7 +188,7 @@ describe('UserUpdater', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('handle error', function(done) {
|
||||
it('handle error', function (done) {
|
||||
this.UserUpdater.removeEmailAddress.callsArgWith(2, new Error('nope'))
|
||||
this.UserUpdater.changeEmailAddress(
|
||||
this.stubbedUser._id,
|
||||
@@ -202,15 +202,15 @@ describe('UserUpdater', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('addEmailAddress', function() {
|
||||
beforeEach(function() {
|
||||
describe('addEmailAddress', function () {
|
||||
beforeEach(function () {
|
||||
this.UserGetter.promises.ensureUniqueEmailAddress = sinon
|
||||
.stub()
|
||||
.resolves()
|
||||
this.UserUpdater.promises.updateUser = sinon.stub().resolves()
|
||||
})
|
||||
|
||||
it('add email', function(done) {
|
||||
it('add email', function (done) {
|
||||
this.UserUpdater.addEmailAddress(
|
||||
this.stubbedUser._id,
|
||||
this.newEmail,
|
||||
@@ -242,7 +242,7 @@ describe('UserUpdater', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('add affiliation', function(done) {
|
||||
it('add affiliation', function (done) {
|
||||
const affiliationOptions = {
|
||||
university: { id: 1 },
|
||||
role: 'Prof',
|
||||
@@ -267,7 +267,7 @@ describe('UserUpdater', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('handle affiliation error', function(done) {
|
||||
it('handle affiliation error', function (done) {
|
||||
this.InstitutionsAPI.promises.addAffiliation.rejects(new Error('nope'))
|
||||
this.UserUpdater.addEmailAddress(
|
||||
this.stubbedUser._id,
|
||||
@@ -282,7 +282,7 @@ describe('UserUpdater', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('validates email', function(done) {
|
||||
it('validates email', function (done) {
|
||||
this.UserUpdater.addEmailAddress(
|
||||
this.stubbedUser._id,
|
||||
'bar',
|
||||
@@ -295,7 +295,7 @@ describe('UserUpdater', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('updates the audit log', function(done) {
|
||||
it('updates the audit log', function (done) {
|
||||
this.ip = '127:0:0:0'
|
||||
this.UserUpdater.addEmailAddress(
|
||||
this.stubbedUser._id,
|
||||
@@ -320,13 +320,13 @@ describe('UserUpdater', function() {
|
||||
)
|
||||
})
|
||||
|
||||
describe('errors', function() {
|
||||
describe('via UserAuditLogHandler', function() {
|
||||
describe('errors', function () {
|
||||
describe('via UserAuditLogHandler', function () {
|
||||
const anError = new Error('oops')
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
this.UserAuditLogHandler.promises.addEntry.throws(anError)
|
||||
})
|
||||
it('should not add email and should return error', function(done) {
|
||||
it('should not add email and should return error', function (done) {
|
||||
this.UserUpdater.addEmailAddress(
|
||||
this.stubbedUser._id,
|
||||
this.newEmail,
|
||||
@@ -345,14 +345,14 @@ describe('UserUpdater', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('removeEmailAddress', function() {
|
||||
beforeEach(function() {
|
||||
describe('removeEmailAddress', function () {
|
||||
beforeEach(function () {
|
||||
this.UserUpdater.updateUser = sinon
|
||||
.stub()
|
||||
.callsArgWith(2, null, { nMatched: 1 })
|
||||
})
|
||||
|
||||
it('remove email', function(done) {
|
||||
it('remove email', function (done) {
|
||||
this.UserUpdater.removeEmailAddress(
|
||||
this.stubbedUser._id,
|
||||
this.newEmail,
|
||||
@@ -369,7 +369,7 @@ describe('UserUpdater', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('remove affiliation', function(done) {
|
||||
it('remove affiliation', function (done) {
|
||||
this.UserUpdater.removeEmailAddress(
|
||||
this.stubbedUser._id,
|
||||
this.newEmail,
|
||||
@@ -384,7 +384,7 @@ describe('UserUpdater', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('refresh features', function(done) {
|
||||
it('refresh features', function (done) {
|
||||
this.UserUpdater.removeEmailAddress(
|
||||
this.stubbedUser._id,
|
||||
this.newEmail,
|
||||
@@ -396,7 +396,7 @@ describe('UserUpdater', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('handle error', function(done) {
|
||||
it('handle error', function (done) {
|
||||
this.UserUpdater.updateUser = sinon
|
||||
.stub()
|
||||
.callsArgWith(2, new Error('nope'))
|
||||
@@ -411,7 +411,7 @@ describe('UserUpdater', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('handle missed update', function(done) {
|
||||
it('handle missed update', function (done) {
|
||||
this.UserUpdater.updateUser = sinon.stub().callsArgWith(2, null, { n: 0 })
|
||||
|
||||
this.UserUpdater.removeEmailAddress(
|
||||
@@ -424,7 +424,7 @@ describe('UserUpdater', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('handle affiliation error', function(done) {
|
||||
it('handle affiliation error', function (done) {
|
||||
this.removeAffiliation.callsArgWith(2, new Error('nope'))
|
||||
this.UserUpdater.removeEmailAddress(
|
||||
this.stubbedUser._id,
|
||||
@@ -437,7 +437,7 @@ describe('UserUpdater', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('validates email', function(done) {
|
||||
it('validates email', function (done) {
|
||||
this.UserUpdater.removeEmailAddress(this.stubbedUser._id, 'baz', err => {
|
||||
expect(err).to.exist
|
||||
done()
|
||||
@@ -445,8 +445,8 @@ describe('UserUpdater', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('setDefaultEmailAddress', function() {
|
||||
beforeEach(function() {
|
||||
describe('setDefaultEmailAddress', function () {
|
||||
beforeEach(function () {
|
||||
this.auditLog = {
|
||||
initiatorId: this.stubbedUser,
|
||||
ipAddress: '0:0:0:0'
|
||||
@@ -462,7 +462,7 @@ describe('UserUpdater', function() {
|
||||
this.RecurlyWrapper.promises.updateAccountEmailAddress.resolves()
|
||||
})
|
||||
|
||||
it('set default', function(done) {
|
||||
it('set default', function (done) {
|
||||
this.UserUpdater.promises.updateUser = sinon.stub().resolves({ n: 1 })
|
||||
|
||||
this.UserUpdater.setDefaultEmailAddress(
|
||||
@@ -483,7 +483,7 @@ describe('UserUpdater', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('set changed the email in newsletter', function(done) {
|
||||
it('set changed the email in newsletter', function (done) {
|
||||
this.UserUpdater.promises.updateUser = sinon.stub().resolves({ n: 1 })
|
||||
|
||||
this.UserUpdater.setDefaultEmailAddress(
|
||||
@@ -504,7 +504,7 @@ describe('UserUpdater', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('handle error', function(done) {
|
||||
it('handle error', function (done) {
|
||||
this.UserUpdater.promises.updateUser = sinon.stub().rejects(Error('nope'))
|
||||
|
||||
this.UserUpdater.setDefaultEmailAddress(
|
||||
@@ -519,7 +519,7 @@ describe('UserUpdater', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('handle missed update', function(done) {
|
||||
it('handle missed update', function (done) {
|
||||
this.UserUpdater.promises.updateUser = sinon.stub().resolves({ n: 0 })
|
||||
|
||||
this.UserUpdater.setDefaultEmailAddress(
|
||||
@@ -534,7 +534,7 @@ describe('UserUpdater', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('validates email', function(done) {
|
||||
it('validates email', function (done) {
|
||||
this.UserUpdater.setDefaultEmailAddress(
|
||||
this.stubbedUser._id,
|
||||
'.edu',
|
||||
@@ -547,7 +547,7 @@ describe('UserUpdater', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('updates audit log', function(done) {
|
||||
it('updates audit log', function (done) {
|
||||
this.UserUpdater.promises.updateUser = sinon.stub().resolves({ n: 1 })
|
||||
|
||||
this.UserUpdater.setDefaultEmailAddress(
|
||||
@@ -574,7 +574,7 @@ describe('UserUpdater', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('blocks email update if audit log returns an error', function(done) {
|
||||
it('blocks email update if audit log returns an error', function (done) {
|
||||
this.UserUpdater.promises.updateUser = sinon.stub()
|
||||
this.UserAuditLogHandler.promises.addEntry.rejects(new Error('oops'))
|
||||
this.UserUpdater.setDefaultEmailAddress(
|
||||
@@ -590,8 +590,8 @@ describe('UserUpdater', function() {
|
||||
)
|
||||
})
|
||||
|
||||
describe('when email not confirmed', function() {
|
||||
beforeEach(function() {
|
||||
describe('when email not confirmed', function () {
|
||||
beforeEach(function () {
|
||||
this.stubbedUser.emails = [
|
||||
{
|
||||
email: this.newEmail,
|
||||
@@ -601,7 +601,7 @@ describe('UserUpdater', function() {
|
||||
this.UserUpdater.promises.updateUser = sinon.stub()
|
||||
})
|
||||
|
||||
it('should callback with error', function() {
|
||||
it('should callback with error', function () {
|
||||
this.UserUpdater.setDefaultEmailAddress(
|
||||
this.stubbedUser._id,
|
||||
this.newEmail,
|
||||
@@ -619,14 +619,14 @@ describe('UserUpdater', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when email does not belong to user', function() {
|
||||
beforeEach(function() {
|
||||
describe('when email does not belong to user', function () {
|
||||
beforeEach(function () {
|
||||
this.stubbedUser.emails = []
|
||||
this.UserGetter.promises.getUser.resolves(this.stubbedUser)
|
||||
this.UserUpdater.promises.updateUser = sinon.stub()
|
||||
})
|
||||
|
||||
it('should callback with error', function() {
|
||||
it('should callback with error', function () {
|
||||
this.UserUpdater.setDefaultEmailAddress(
|
||||
this.stubbedUser._id,
|
||||
this.newEmail,
|
||||
@@ -644,8 +644,8 @@ describe('UserUpdater', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('security alert', function() {
|
||||
it('should be sent to old and new email when sendSecurityAlert=true', function(done) {
|
||||
describe('security alert', function () {
|
||||
it('should be sent to old and new email when sendSecurityAlert=true', function (done) {
|
||||
// this.UserGetter.promises.getUser.resolves(this.stubbedUser)
|
||||
this.UserUpdater.promises.updateUser = sinon.stub().resolves({ n: 1 })
|
||||
|
||||
@@ -670,16 +670,16 @@ describe('UserUpdater', function() {
|
||||
}
|
||||
)
|
||||
})
|
||||
describe('errors', function() {
|
||||
describe('errors', function () {
|
||||
const anError = new Error('oops')
|
||||
describe('EmailHandler', function() {
|
||||
beforeEach(function() {
|
||||
describe('EmailHandler', function () {
|
||||
beforeEach(function () {
|
||||
this.EmailHandler.promises.sendEmail.rejects(anError)
|
||||
this.UserUpdater.promises.updateUser = sinon
|
||||
.stub()
|
||||
.resolves({ n: 1 })
|
||||
})
|
||||
it('should log but not pass back the error', function(done) {
|
||||
it('should log but not pass back the error', function (done) {
|
||||
this.UserUpdater.setDefaultEmailAddress(
|
||||
this.stubbedUser._id,
|
||||
this.newEmail,
|
||||
@@ -705,12 +705,12 @@ describe('UserUpdater', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('confirmEmail', function() {
|
||||
beforeEach(function() {
|
||||
describe('confirmEmail', function () {
|
||||
beforeEach(function () {
|
||||
this.UserUpdater.promises.updateUser = sinon.stub().resolves({ n: 1 })
|
||||
})
|
||||
|
||||
it('should update the email record', function(done) {
|
||||
it('should update the email record', function (done) {
|
||||
this.UserUpdater.confirmEmail(
|
||||
this.stubbedUser._id,
|
||||
this.stubbedUserEmail,
|
||||
@@ -737,7 +737,7 @@ describe('UserUpdater', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('add affiliation', function(done) {
|
||||
it('add affiliation', function (done) {
|
||||
this.UserUpdater.confirmEmail(
|
||||
this.stubbedUser._id,
|
||||
this.newEmail,
|
||||
@@ -757,7 +757,7 @@ describe('UserUpdater', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('handle error', function(done) {
|
||||
it('handle error', function (done) {
|
||||
this.UserUpdater.promises.updateUser = sinon
|
||||
.stub()
|
||||
.throws(new Error('nope'))
|
||||
@@ -772,7 +772,7 @@ describe('UserUpdater', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('handle missed update', function(done) {
|
||||
it('handle missed update', function (done) {
|
||||
this.UserUpdater.promises.updateUser = sinon.stub().resolves({ n: 0 })
|
||||
|
||||
this.UserUpdater.confirmEmail(
|
||||
@@ -785,14 +785,14 @@ describe('UserUpdater', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('validates email', function(done) {
|
||||
it('validates email', function (done) {
|
||||
this.UserUpdater.confirmEmail(this.stubbedUser._id, '@', err => {
|
||||
expect(err).to.exist
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('handle affiliation error', function(done) {
|
||||
it('handle affiliation error', function (done) {
|
||||
this.InstitutionsAPI.promises.addAffiliation.throws(Error('nope'))
|
||||
this.UserUpdater.confirmEmail(
|
||||
this.stubbedUser._id,
|
||||
@@ -805,7 +805,7 @@ describe('UserUpdater', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('refresh features', function(done) {
|
||||
it('refresh features', function (done) {
|
||||
this.UserUpdater.confirmEmail(
|
||||
this.stubbedUser._id,
|
||||
this.newEmail,
|
||||
|
||||
Reference in New Issue
Block a user