From d99be63877c98b2190350b3d161feb7ef4e6cd76 Mon Sep 17 00:00:00 2001 From: June Kelly Date: Thu, 21 Jul 2022 13:26:54 +0100 Subject: [PATCH] Merge pull request #8945 from overleaf/jel-decaf-cleanup [web] decaf cleanup a test file GitOrigin-RevId: 55b1d8df2d6f22204712360bb30b5548abd0d933 --- .../src/User/UserRegistrationHandlerTests.js | 101 +++++++----------- 1 file changed, 39 insertions(+), 62 deletions(-) diff --git a/services/web/test/unit/src/User/UserRegistrationHandlerTests.js b/services/web/test/unit/src/User/UserRegistrationHandlerTests.js index 1755854a35..5d9ded3f41 100644 --- a/services/web/test/unit/src/User/UserRegistrationHandlerTests.js +++ b/services/web/test/unit/src/User/UserRegistrationHandlerTests.js @@ -1,16 +1,3 @@ -/* eslint-disable - n/handle-callback-err, - max-len, - no-return-assign, - no-unused-vars, -*/ -// TODO: This file was created by bulk-decaffeinate. -// Fix any style issues and re-enable lint. -/* - * decaffeinate suggestions: - * DS102: Remove unnecessary code created because of implicit returns - * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md - */ const SandboxedModule = require('sandboxed-module') const assert = require('assert') const path = require('path') @@ -76,12 +63,12 @@ describe('UserRegistrationHandler', function () { const result = this.handler._registrationRequestIsValid( this.passingRequest ) - return result.should.equal(true) + result.should.equal(true) }) describe('failing email validation', function () { beforeEach(function () { - return this.AuthenticationManager.validateEmail.returns({ + this.AuthenticationManager.validateEmail.returns({ message: 'email not set', }) }) @@ -96,7 +83,7 @@ describe('UserRegistrationHandler', function () { describe('failing password validation', function () { beforeEach(function () { - return this.AuthenticationManager.validatePassword.returns({ + this.AuthenticationManager.validatePassword.returns({ message: 'password is too short', }) }) @@ -105,7 +92,7 @@ describe('UserRegistrationHandler', function () { const result = this.handler._registrationRequestIsValid( this.passingRequest ) - return result.should.equal(false) + result.should.equal(false) }) }) }) @@ -115,26 +102,22 @@ describe('UserRegistrationHandler', function () { beforeEach(function () { this.user.holdingAccount = true this.handler._registrationRequestIsValid = sinon.stub().returns(true) - return this.UserGetter.getUserByAnyEmail.callsArgWith( - 1, - null, - this.user - ) + this.UserGetter.getUserByAnyEmail.callsArgWith(1, null, this.user) }) it('should not create a new user if there is a holding account there', function (done) { - return this.handler.registerNewUser(this.passingRequest, err => { + this.handler.registerNewUser(this.passingRequest, error => { this.UserCreator.createNewUser.called.should.equal(false) - return done() + done(error) }) }) it('should set holding account to false', function (done) { - return this.handler.registerNewUser(this.passingRequest, err => { + this.handler.registerNewUser(this.passingRequest, error => { const update = this.User.updateOne.args[0] assert.deepEqual(update[0], { _id: this.user._id }) assert.deepEqual(update[1], { $set: { holdingAccount: false } }) - return done() + done(error) }) }) }) @@ -142,10 +125,11 @@ describe('UserRegistrationHandler', function () { 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 + this.handler.registerNewUser(this.passingRequest, error => { + expect(error).to.be.instanceOf(Error) + this.UserCreator.createNewUser.called.should.equal(false) - return done() + done() }) }) @@ -155,26 +139,23 @@ describe('UserRegistrationHandler', function () { null, (this.user = { holdingAccount: false }) ) - return this.handler.registerNewUser( - this.passingRequest, - (err, user) => { - expect(err).to.be.instanceOf(Error) - expect(err).to.have.property('message', 'EmailAlreadyRegistered') - user.should.deep.equal(this.user) - return done() - } - ) + this.handler.registerNewUser(this.passingRequest, (err, user) => { + expect(err).to.be.instanceOf(Error) + expect(err).to.have.property('message', 'EmailAlreadyRegistered') + user.should.deep.equal(this.user) + done() + }) }) }) describe('validRequest', function () { beforeEach(function () { this.handler._registrationRequestIsValid = sinon.stub().returns(true) - return this.UserGetter.getUserByAnyEmail.callsArgWith(1) + this.UserGetter.getUserByAnyEmail.callsArgWith(1) }) it('should create a new user', function (done) { - this.handler.registerNewUser(this.passingRequest, err => { + this.handler.registerNewUser(this.passingRequest, error => { sinon.assert.calledWith(this.UserCreator.createNewUser, { email: this.passingRequest.email, holdingAccount: false, @@ -182,62 +163,58 @@ describe('UserRegistrationHandler', function () { last_name: this.passingRequest.last_name, analyticsId: this.user.analyticsId, }) - done() + done(error) }) }) it('lower case email', function (done) { this.passingRequest.email = 'soMe@eMail.cOm' - return this.handler.registerNewUser(this.passingRequest, err => { + this.handler.registerNewUser(this.passingRequest, error => { this.UserCreator.createNewUser.args[0][0].email.should.equal( 'some@email.com' ) - return done() + done(error) }) }) it('trim white space from email', function (done) { this.passingRequest.email = ' some@email.com ' - return this.handler.registerNewUser(this.passingRequest, err => { + this.handler.registerNewUser(this.passingRequest, error => { this.UserCreator.createNewUser.args[0][0].email.should.equal( 'some@email.com' ) - return done() + done(error) }) }) it('should set the password', function (done) { - return this.handler.registerNewUser(this.passingRequest, err => { + this.handler.registerNewUser(this.passingRequest, error => { this.AuthenticationManager.setUserPassword .calledWith(this.user, this.passingRequest.password) .should.equal(true) - return done() + done(error) }) }) 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.handler.registerNewUser(this.passingRequest, error => { this.NewsLetterManager.subscribe .calledWith(this.user) .should.equal(true) - return done() + done(error) }) }) it('should not add the user to the newsletter if not accepted terms', function (done) { - return this.handler.registerNewUser(this.passingRequest, err => { + this.handler.registerNewUser(this.passingRequest, error => { this.NewsLetterManager.subscribe .calledWith(this.user) .should.equal(false) - return done() + done(error) }) }) }) - - it('should call the ReferalAllocator', function (done) { - return done() - }) }) describe('registerNewUserAndSendActivationEmail', function () { @@ -253,14 +230,14 @@ describe('UserRegistrationHandler', function () { (this.token = 'mock-token') ) this.handler.registerNewUser = sinon.stub() - return (this.callback = sinon.stub()) + this.callback = sinon.stub() }) 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( + this.handler.registerNewUserAndSendActivationEmail( this.email, this.callback ) @@ -278,13 +255,13 @@ describe('UserRegistrationHandler', function () { user_id: this.user._id.toString(), email: this.user.email, } - return this.OneTimeTokenHandler.getNewToken + this.OneTimeTokenHandler.getNewToken .calledWith('password', data, { expiresIn: 7 * 24 * 60 * 60 }) .should.equal(true) }) it('should send a registered email', function () { - return this.EmailHandler.sendEmail + this.EmailHandler.sendEmail .calledWith('registered', { to: this.user.email, setNewPasswordUrl: `${this.settings.siteUrl}/user/activate?token=${this.token}&user_id=${this.user_id}`, @@ -293,7 +270,7 @@ describe('UserRegistrationHandler', function () { }) it('should return the user', function () { - return this.callback + this.callback .calledWith( null, this.user, @@ -310,7 +287,7 @@ describe('UserRegistrationHandler', function () { new Error('EmailAlreadyRegistered'), this.user ) - return this.handler.registerNewUserAndSendActivationEmail( + this.handler.registerNewUserAndSendActivationEmail( this.email, this.callback ) @@ -318,7 +295,7 @@ describe('UserRegistrationHandler', 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) + this.EmailHandler.sendEmail.called.should.equal(true) }) }) })