|
@@ -17,15 +17,26 @@ describe('UserActivateController', function () {
|
|
|
email: 'joe@example.com',
|
|
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.ErrorController = { notFound: sinon.stub() }
|
|
|
|
|
+ this.SplitTestHandler = {
|
|
|
|
|
+ promises: {
|
|
|
|
|
+ getAssignment: sinon.stub().resolves({ variant: 'default' }),
|
|
|
|
|
+ },
|
|
|
|
|
+ }
|
|
|
this.UserActivateController = await esmock(MODULE_PATH, {
|
|
this.UserActivateController = await esmock(MODULE_PATH, {
|
|
|
'../../../../../app/src/Features/User/UserGetter.js': this.UserGetter,
|
|
'../../../../../app/src/Features/User/UserGetter.js': this.UserGetter,
|
|
|
'../../../../../app/src/Features/User/UserRegistrationHandler.js':
|
|
'../../../../../app/src/Features/User/UserRegistrationHandler.js':
|
|
|
this.UserRegistrationHandler,
|
|
this.UserRegistrationHandler,
|
|
|
'../../../../../app/src/Features/Errors/ErrorController.js':
|
|
'../../../../../app/src/Features/Errors/ErrorController.js':
|
|
|
this.ErrorController,
|
|
this.ErrorController,
|
|
|
|
|
+ '../../../../../app/src/Features/SplitTests/SplitTestHandler':
|
|
|
|
|
+ this.SplitTestHandler,
|
|
|
})
|
|
})
|
|
|
this.req = {
|
|
this.req = {
|
|
|
body: {},
|
|
body: {},
|
|
@@ -41,12 +52,12 @@ describe('UserActivateController', function () {
|
|
|
|
|
|
|
|
describe('activateAccountPage', function () {
|
|
describe('activateAccountPage', function () {
|
|
|
beforeEach(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.user_id = this.user_id
|
|
|
this.req.query.token = this.token = 'mock-token-123'
|
|
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
|
|
delete this.req.query.user_id
|
|
|
this.ErrorController.notFound = () => done()
|
|
this.ErrorController.notFound = () => done()
|
|
|
this.UserActivateController.activateAccountPage(this.req, this.res)
|
|
this.UserActivateController.activateAccountPage(this.req, this.res)
|
|
@@ -59,7 +70,7 @@ describe('UserActivateController', function () {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should 404 without a valid user_id', function (done) {
|
|
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.ErrorController.notFound = () => done()
|
|
|
this.UserActivateController.activateAccountPage(this.req, this.res)
|
|
this.UserActivateController.activateAccountPage(this.req, this.res)
|
|
|
})
|
|
})
|
|
@@ -73,7 +84,7 @@ describe('UserActivateController', function () {
|
|
|
it('should redirect activated users to login', function (done) {
|
|
it('should redirect activated users to login', function (done) {
|
|
|
this.user.loginCount = 1
|
|
this.user.loginCount = 1
|
|
|
this.res.redirect = url => {
|
|
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')
|
|
url.should.equal('/login')
|
|
|
return done()
|
|
return done()
|
|
|
}
|
|
}
|
|
@@ -93,17 +104,20 @@ describe('UserActivateController', function () {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
describe('register', 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.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 () {
|
|
it('should register the user and send them an email', function () {
|
|
|
sinon.assert.calledWith(
|
|
sinon.assert.calledWith(
|
|
|
- this.UserRegistrationHandler.registerNewUserAndSendActivationEmail,
|
|
|
|
|
|
|
+ this.UserRegistrationHandler.promises
|
|
|
|
|
+ .registerNewUserAndSendActivationEmail,
|
|
|
this.email
|
|
this.email
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|