Merge pull request #23763 from overleaf/td-bs5-user-activation

Migrate user activation page to BS5

GitOrigin-RevId: 3f4c9173cf480aafc5d874bfe81bbc8503a2e5be
This commit is contained in:
Tim Down
2025-03-05 09:04:58 +00:00
committed by Copybot
parent 69896f4c8b
commit 1f339b37bd
3 changed files with 153 additions and 135 deletions
@@ -17,15 +17,26 @@ describe('UserActivateController', function () {
email: 'joe@example.com',
}
this.UserGetter = { getUser: sinon.stub() }
this.UserRegistrationHandler = {}
this.UserGetter = {
promises: {
getUser: sinon.stub(),
},
}
this.UserRegistrationHandler = { promises: {} }
this.ErrorController = { notFound: sinon.stub() }
this.SplitTestHandler = {
promises: {
getAssignment: sinon.stub().resolves({ variant: 'default' }),
},
}
this.UserActivateController = await esmock(MODULE_PATH, {
'../../../../../app/src/Features/User/UserGetter.js': this.UserGetter,
'../../../../../app/src/Features/User/UserRegistrationHandler.js':
this.UserRegistrationHandler,
'../../../../../app/src/Features/Errors/ErrorController.js':
this.ErrorController,
'../../../../../app/src/Features/SplitTests/SplitTestHandler':
this.SplitTestHandler,
})
this.req = {
body: {},
@@ -41,12 +52,12 @@ describe('UserActivateController', function () {
describe('activateAccountPage', function () {
beforeEach(function () {
this.UserGetter.getUser = sinon.stub().callsArgWith(2, null, this.user)
this.UserGetter.promises.getUser = sinon.stub().resolves(this.user)
this.req.query.user_id = this.user_id
this.req.query.token = this.token = 'mock-token-123'
})
it('should 404 without a user_id', function (done) {
it('should 404 without a user_id', async function (done) {
delete this.req.query.user_id
this.ErrorController.notFound = () => done()
this.UserActivateController.activateAccountPage(this.req, this.res)
@@ -59,7 +70,7 @@ describe('UserActivateController', function () {
})
it('should 404 without a valid user_id', function (done) {
this.UserGetter.getUser = sinon.stub().callsArgWith(2, null, null)
this.UserGetter.promises.getUser = sinon.stub().resolves(null)
this.ErrorController.notFound = () => done()
this.UserActivateController.activateAccountPage(this.req, this.res)
})
@@ -73,7 +84,7 @@ describe('UserActivateController', function () {
it('should redirect activated users to login', function (done) {
this.user.loginCount = 1
this.res.redirect = url => {
this.UserGetter.getUser.calledWith(this.user_id).should.equal(true)
sinon.assert.calledWith(this.UserGetter.promises.getUser, this.user_id)
url.should.equal('/login')
return done()
}
@@ -93,17 +104,20 @@ describe('UserActivateController', function () {
})
describe('register', function () {
beforeEach(function () {
this.UserRegistrationHandler.registerNewUserAndSendActivationEmail = sinon
.stub()
.callsArgWith(1, null, this.user, (this.url = 'mock/url'))
beforeEach(async function () {
this.UserRegistrationHandler.promises.registerNewUserAndSendActivationEmail =
sinon.stub().resolves({
user: this.user,
setNewPasswordUrl: (this.url = 'mock/url'),
})
this.req.body.email = this.user.email = this.email = 'email@example.com'
this.UserActivateController.register(this.req, this.res)
await this.UserActivateController.register(this.req, this.res)
})
it('should register the user and send them an email', function () {
sinon.assert.calledWith(
this.UserRegistrationHandler.registerNewUserAndSendActivationEmail,
this.UserRegistrationHandler.promises
.registerNewUserAndSendActivationEmail,
this.email
)
})