2020-10-25 15:06:58 -05:00
|
|
|
const UserController = require('../lib/Controllers/UserController').UserController;
|
2018-09-01 13:58:06 -04:00
|
|
|
const emailAdapter = require('./MockEmailAdapter');
|
2018-07-02 23:30:14 -04:00
|
|
|
const AppCache = require('../lib/cache').AppCache;
|
2017-01-08 19:56:57 +01:00
|
|
|
|
|
|
|
|
describe('UserController', () => {
|
2018-02-17 09:55:30 -05:00
|
|
|
const user = {
|
2017-01-08 19:56:57 +01:00
|
|
|
_email_verify_token: 'testToken',
|
|
|
|
|
username: 'testUser',
|
2018-09-01 13:58:06 -04:00
|
|
|
email: 'test@example.com',
|
|
|
|
|
};
|
2017-01-08 19:56:57 +01:00
|
|
|
|
|
|
|
|
describe('sendVerificationEmail', () => {
|
|
|
|
|
describe('parseFrameURL not provided', () => {
|
2018-09-01 13:58:06 -04:00
|
|
|
it('uses publicServerURL', done => {
|
|
|
|
|
AppCache.put(
|
|
|
|
|
defaultConfiguration.appId,
|
|
|
|
|
Object.assign({}, defaultConfiguration, {
|
|
|
|
|
publicServerURL: 'http://www.example.com',
|
|
|
|
|
customPages: {
|
|
|
|
|
parseFrameURL: undefined,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
);
|
2017-01-08 19:56:57 +01:00
|
|
|
|
2018-09-01 13:58:06 -04:00
|
|
|
emailAdapter.sendVerificationEmail = options => {
|
|
|
|
|
expect(options.link).toEqual(
|
|
|
|
|
'http://www.example.com/apps/test/verify_email?token=testToken&username=testUser'
|
|
|
|
|
);
|
|
|
|
|
done();
|
|
|
|
|
};
|
2017-01-08 19:56:57 +01:00
|
|
|
|
2018-02-17 09:55:30 -05:00
|
|
|
const userController = new UserController(emailAdapter, 'test', {
|
2018-09-01 13:58:06 -04:00
|
|
|
verifyUserEmails: true,
|
|
|
|
|
});
|
2017-01-08 19:56:57 +01:00
|
|
|
|
2018-09-01 13:58:06 -04:00
|
|
|
userController.sendVerificationEmail(user);
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-01-08 19:56:57 +01:00
|
|
|
|
|
|
|
|
describe('parseFrameURL provided', () => {
|
2018-09-01 13:58:06 -04:00
|
|
|
it('uses parseFrameURL and includes the destination in the link parameter', done => {
|
|
|
|
|
AppCache.put(
|
|
|
|
|
defaultConfiguration.appId,
|
|
|
|
|
Object.assign({}, defaultConfiguration, {
|
|
|
|
|
publicServerURL: 'http://www.example.com',
|
|
|
|
|
customPages: {
|
|
|
|
|
parseFrameURL: 'http://someother.example.com/handle-parse-iframe',
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
);
|
2017-01-08 19:56:57 +01:00
|
|
|
|
2018-09-01 13:58:06 -04:00
|
|
|
emailAdapter.sendVerificationEmail = options => {
|
|
|
|
|
expect(options.link).toEqual(
|
|
|
|
|
'http://someother.example.com/handle-parse-iframe?link=%2Fapps%2Ftest%2Fverify_email&token=testToken&username=testUser'
|
|
|
|
|
);
|
|
|
|
|
done();
|
|
|
|
|
};
|
2017-01-08 19:56:57 +01:00
|
|
|
|
2018-02-17 09:55:30 -05:00
|
|
|
const userController = new UserController(emailAdapter, 'test', {
|
2018-09-01 13:58:06 -04:00
|
|
|
verifyUserEmails: true,
|
|
|
|
|
});
|
2017-01-08 19:56:57 +01:00
|
|
|
|
2018-09-01 13:58:06 -04:00
|
|
|
userController.sendVerificationEmail(user);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-01-08 19:56:57 +01:00
|
|
|
});
|