Skip to content

Commit c87399c

Browse files
authored
Merge pull request #1 from jure/user_controller_tests
User controller tests
2 parents f6fd93f + dd34760 commit c87399c

File tree

3 files changed

+66
-3
lines changed

3 files changed

+66
-3
lines changed

spec/UserController.spec.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
var UserController = require('../src/Controllers/UserController').UserController;
2+
var emailAdapter = require('./MockEmailAdapter')
3+
var AppCache = require('../src/cache').AppCache;
4+
5+
describe('UserController', () => {
6+
var user = {
7+
_email_verify_token: 'testToken',
8+
username: 'testUser',
9+
10+
}
11+
12+
describe('sendVerificationEmail', () => {
13+
describe('parseFrameURL not provided', () => {
14+
it('uses publicServerURL', (done) => {
15+
16+
AppCache.put(defaultConfiguration.appId, Object.assign(defaultConfiguration, {
17+
publicServerURL: 'http://www.example.com',
18+
customPages: {
19+
parseFrameURL: undefined
20+
}
21+
}))
22+
23+
emailAdapter.sendVerificationEmail = (options) => {
24+
expect(options.link).toEqual('http://www.example.com/apps/test/verify_email?token=testToken&username=testUser')
25+
done()
26+
}
27+
28+
var userController = new UserController(emailAdapter, 'test', {
29+
verifyUserEmails: true
30+
})
31+
32+
userController.sendVerificationEmail(user)
33+
})
34+
})
35+
36+
describe('parseFrameURL provided', () => {
37+
it('uses parseFrameURL and includes the destination in the link parameter', (done) => {
38+
39+
AppCache.put(defaultConfiguration.appId, Object.assign(defaultConfiguration, {
40+
publicServerURL: 'http://www.example.com',
41+
customPages: {
42+
parseFrameURL: 'http://someother.example.com/handle-parse-iframe'
43+
}
44+
}))
45+
46+
emailAdapter.sendVerificationEmail = (options) => {
47+
expect(options.link).toEqual('http://someother.example.com/handle-parse-iframe?link=%2Fapps%2Ftest%2Fverify_email&token=testToken&username=testUser')
48+
done()
49+
}
50+
51+
var userController = new UserController(emailAdapter, 'test', {
52+
verifyUserEmails: true
53+
})
54+
55+
userController.sendVerificationEmail(user)
56+
})
57+
})
58+
})
59+
});

spec/ValidationAndPasswordsReset.spec.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ describe("Custom Pages, Email Verification, Password Reset", () => {
1212
invalidLink: "myInvalidLink",
1313
verifyEmailSuccess: "myVerifyEmailSuccess",
1414
choosePassword: "myChoosePassword",
15-
passwordResetSuccess: "myPasswordResetSuccess"
15+
passwordResetSuccess: "myPasswordResetSuccess",
16+
parseFrameURL: "http://example.com/handle-parse-iframe"
1617
},
1718
publicServerURL: "https://my.public.server.com/1"
1819
})
@@ -22,6 +23,7 @@ describe("Custom Pages, Email Verification, Password Reset", () => {
2223
expect(config.verifyEmailSuccessURL).toEqual("myVerifyEmailSuccess");
2324
expect(config.choosePasswordURL).toEqual("myChoosePassword");
2425
expect(config.passwordResetSuccessURL).toEqual("myPasswordResetSuccess");
26+
expect(config.parseFrameURL).toEqual("http://example.com/handle-parse-iframe");
2527
expect(config.verifyEmailURL).toEqual("https://my.public.server.com/1/apps/test/verify_email");
2628
expect(config.requestResetPasswordURL).toEqual("https://my.public.server.com/1/apps/test/request_password_reset");
2729
done();

src/Controllers/UserController.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ export class UserController extends AdaptableController {
119119
// We may need to fetch the user in case of update email
120120
this.getUserIfNeeded(user).then((user) => {
121121
const username = encodeURIComponent(user.username);
122+
122123
const link = buildEmailLink(this.config.verifyEmailURL, username, token, this.config);
123124
const options = {
124125
appName: this.config.appName,
@@ -216,10 +217,11 @@ function updateUserPassword(userId, password, config) {
216217
}
217218

218219
function buildEmailLink(destination, username, token, config) {
219-
let usernameAndToken = `token=${token}&username=${username}`
220+
const usernameAndToken = `token=${token}&username=${username}`
220221

221222
if (config.parseFrameURL) {
222-
let destinationWithoutHost = destination.replace(config.publicServerURL, '');
223+
const destinationWithoutHost = destination.replace(config.publicServerURL, '');
224+
223225
return `${config.parseFrameURL}?link=${encodeURIComponent(destinationWithoutHost)}&${usernameAndToken}`;
224226
} else {
225227
return `${destination}?${usernameAndToken}`;

0 commit comments

Comments
 (0)