diff options
Diffstat (limited to 'client/e2e/src/suites-local/signup.e2e-spec.ts')
-rw-r--r-- | client/e2e/src/suites-local/signup.e2e-spec.ts | 403 |
1 files changed, 359 insertions, 44 deletions
diff --git a/client/e2e/src/suites-local/signup.e2e-spec.ts b/client/e2e/src/suites-local/signup.e2e-spec.ts index 4eed3eefe..b6f7ad1a7 100644 --- a/client/e2e/src/suites-local/signup.e2e-spec.ts +++ b/client/e2e/src/suites-local/signup.e2e-spec.ts | |||
@@ -1,12 +1,89 @@ | |||
1 | import { AdminConfigPage } from '../po/admin-config.po' | 1 | import { AdminConfigPage } from '../po/admin-config.po' |
2 | import { AdminRegistrationPage } from '../po/admin-registration.po' | ||
2 | import { LoginPage } from '../po/login.po' | 3 | import { LoginPage } from '../po/login.po' |
3 | import { SignupPage } from '../po/signup.po' | 4 | import { SignupPage } from '../po/signup.po' |
4 | import { isMobileDevice, waitServerUp } from '../utils' | 5 | import { browserSleep, getVerificationLink, go, findEmailTo, isMobileDevice, MockSMTPServer, waitServerUp } from '../utils' |
6 | |||
7 | function checkEndMessage (options: { | ||
8 | message: string | ||
9 | requiresEmailVerification: boolean | ||
10 | requiresApproval: boolean | ||
11 | afterEmailVerification: boolean | ||
12 | }) { | ||
13 | const { message, requiresApproval, requiresEmailVerification, afterEmailVerification } = options | ||
14 | |||
15 | { | ||
16 | const created = 'account has been created' | ||
17 | const request = 'account request has been sent' | ||
18 | |||
19 | if (requiresApproval) { | ||
20 | expect(message).toContain(request) | ||
21 | expect(message).not.toContain(created) | ||
22 | } else { | ||
23 | expect(message).not.toContain(request) | ||
24 | expect(message).toContain(created) | ||
25 | } | ||
26 | } | ||
27 | |||
28 | { | ||
29 | const checkEmail = 'Check your emails' | ||
30 | |||
31 | if (requiresEmailVerification) { | ||
32 | expect(message).toContain(checkEmail) | ||
33 | } else { | ||
34 | expect(message).not.toContain(checkEmail) | ||
35 | |||
36 | const moderatorsApproval = 'moderator will check your registration request' | ||
37 | if (requiresApproval) { | ||
38 | expect(message).toContain(moderatorsApproval) | ||
39 | } else { | ||
40 | expect(message).not.toContain(moderatorsApproval) | ||
41 | } | ||
42 | } | ||
43 | } | ||
44 | |||
45 | { | ||
46 | const emailVerified = 'email has been verified' | ||
47 | |||
48 | if (afterEmailVerification) { | ||
49 | expect(message).toContain(emailVerified) | ||
50 | } else { | ||
51 | expect(message).not.toContain(emailVerified) | ||
52 | } | ||
53 | } | ||
54 | } | ||
5 | 55 | ||
6 | describe('Signup', () => { | 56 | describe('Signup', () => { |
7 | let loginPage: LoginPage | 57 | let loginPage: LoginPage |
8 | let adminConfigPage: AdminConfigPage | 58 | let adminConfigPage: AdminConfigPage |
9 | let signupPage: SignupPage | 59 | let signupPage: SignupPage |
60 | let adminRegistrationPage: AdminRegistrationPage | ||
61 | |||
62 | async function prepareSignup (options: { | ||
63 | enabled: boolean | ||
64 | requiresApproval?: boolean | ||
65 | requiresEmailVerification?: boolean | ||
66 | }) { | ||
67 | await loginPage.loginAsRootUser() | ||
68 | |||
69 | await adminConfigPage.navigateTo('basic-configuration') | ||
70 | await adminConfigPage.toggleSignup(options.enabled) | ||
71 | |||
72 | if (options.enabled) { | ||
73 | if (options.requiresApproval !== undefined) { | ||
74 | await adminConfigPage.toggleSignupApproval(options.requiresApproval) | ||
75 | } | ||
76 | |||
77 | if (options.requiresEmailVerification !== undefined) { | ||
78 | await adminConfigPage.toggleSignupEmailVerification(options.requiresEmailVerification) | ||
79 | } | ||
80 | } | ||
81 | |||
82 | await adminConfigPage.save() | ||
83 | |||
84 | await loginPage.logout() | ||
85 | await browser.refresh() | ||
86 | } | ||
10 | 87 | ||
11 | before(async () => { | 88 | before(async () => { |
12 | await waitServerUp() | 89 | await waitServerUp() |
@@ -16,72 +93,310 @@ describe('Signup', () => { | |||
16 | loginPage = new LoginPage(isMobileDevice()) | 93 | loginPage = new LoginPage(isMobileDevice()) |
17 | adminConfigPage = new AdminConfigPage() | 94 | adminConfigPage = new AdminConfigPage() |
18 | signupPage = new SignupPage() | 95 | signupPage = new SignupPage() |
96 | adminRegistrationPage = new AdminRegistrationPage() | ||
19 | 97 | ||
20 | await browser.maximizeWindow() | 98 | await browser.maximizeWindow() |
21 | }) | 99 | }) |
22 | 100 | ||
23 | it('Should disable signup', async () => { | 101 | describe('Signup disabled', function () { |
24 | await loginPage.loginAsRootUser() | 102 | it('Should disable signup', async () => { |
103 | await prepareSignup({ enabled: false }) | ||
25 | 104 | ||
26 | await adminConfigPage.navigateTo('basic-configuration') | 105 | await expect(signupPage.getRegisterMenuButton()).not.toBeDisplayed() |
27 | await adminConfigPage.toggleSignup() | 106 | }) |
107 | }) | ||
28 | 108 | ||
29 | await adminConfigPage.save() | 109 | describe('Email verification disabled', function () { |
30 | 110 | ||
31 | await loginPage.logout() | 111 | describe('Direct registration', function () { |
32 | await browser.refresh() | ||
33 | 112 | ||
34 | expect(signupPage.getRegisterMenuButton()).not.toBeDisplayed() | 113 | it('Should enable signup without approval', async () => { |
35 | }) | 114 | await prepareSignup({ enabled: true, requiresApproval: false, requiresEmailVerification: false }) |
36 | 115 | ||
37 | it('Should enable signup', async () => { | 116 | await signupPage.getRegisterMenuButton().waitForDisplayed() |
38 | await loginPage.loginAsRootUser() | 117 | }) |
39 | 118 | ||
40 | await adminConfigPage.navigateTo('basic-configuration') | 119 | it('Should go on signup page', async function () { |
41 | await adminConfigPage.toggleSignup() | 120 | await signupPage.clickOnRegisterInMenu() |
121 | }) | ||
42 | 122 | ||
43 | await adminConfigPage.save() | 123 | it('Should validate the first step (about page)', async function () { |
124 | await signupPage.validateStep() | ||
125 | }) | ||
44 | 126 | ||
45 | await loginPage.logout() | 127 | it('Should validate the second step (terms)', async function () { |
46 | await browser.refresh() | 128 | await signupPage.checkTerms() |
129 | await signupPage.validateStep() | ||
130 | }) | ||
47 | 131 | ||
48 | expect(signupPage.getRegisterMenuButton()).toBeDisplayed() | 132 | it('Should validate the third step (account)', async function () { |
49 | }) | 133 | await signupPage.fillAccountStep({ username: 'user_1', displayName: 'user_1_dn' }) |
50 | 134 | ||
51 | it('Should go on signup page', async function () { | 135 | await signupPage.validateStep() |
52 | await signupPage.clickOnRegisterInMenu() | 136 | }) |
53 | }) | ||
54 | 137 | ||
55 | it('Should validate the first step (about page)', async function () { | 138 | it('Should validate the third step (channel)', async function () { |
56 | await signupPage.validateStep() | 139 | await signupPage.fillChannelStep({ name: 'user_1_channel' }) |
57 | }) | ||
58 | 140 | ||
59 | it('Should validate the second step (terms)', async function () { | 141 | await signupPage.validateStep() |
60 | await signupPage.checkTerms() | 142 | }) |
61 | await signupPage.validateStep() | 143 | |
62 | }) | 144 | it('Should be logged in', async function () { |
145 | await loginPage.ensureIsLoggedInAs('user_1_dn') | ||
146 | }) | ||
147 | |||
148 | it('Should have a valid end message', async function () { | ||
149 | const message = await signupPage.getEndMessage() | ||
150 | |||
151 | checkEndMessage({ | ||
152 | message, | ||
153 | requiresEmailVerification: false, | ||
154 | requiresApproval: false, | ||
155 | afterEmailVerification: false | ||
156 | }) | ||
63 | 157 | ||
64 | it('Should validate the third step (account)', async function () { | 158 | await browser.saveScreenshot('./screenshots/direct-without-email.png') |
65 | await signupPage.fillAccountStep({ | 159 | |
66 | displayName: 'user 1', | 160 | await loginPage.logout() |
67 | username: 'user_1', | 161 | }) |
68 | email: 'user_1@example.com', | ||
69 | password: 'my_super_password' | ||
70 | }) | 162 | }) |
71 | 163 | ||
72 | await signupPage.validateStep() | 164 | describe('Registration with approval', function () { |
165 | |||
166 | it('Should enable signup with approval', async () => { | ||
167 | await prepareSignup({ enabled: true, requiresApproval: true, requiresEmailVerification: false }) | ||
168 | |||
169 | await signupPage.getRegisterMenuButton().waitForDisplayed() | ||
170 | }) | ||
171 | |||
172 | it('Should go on signup page', async function () { | ||
173 | await signupPage.clickOnRegisterInMenu() | ||
174 | }) | ||
175 | |||
176 | it('Should validate the first step (about page)', async function () { | ||
177 | await signupPage.validateStep() | ||
178 | }) | ||
179 | |||
180 | it('Should validate the second step (terms)', async function () { | ||
181 | await signupPage.checkTerms() | ||
182 | await signupPage.fillRegistrationReason('my super reason') | ||
183 | await signupPage.validateStep() | ||
184 | }) | ||
185 | |||
186 | it('Should validate the third step (account)', async function () { | ||
187 | await signupPage.fillAccountStep({ username: 'user_2', displayName: 'user_2 display name', password: 'password' }) | ||
188 | await signupPage.validateStep() | ||
189 | }) | ||
190 | |||
191 | it('Should validate the third step (channel)', async function () { | ||
192 | await signupPage.fillChannelStep({ name: 'user_2_channel' }) | ||
193 | await signupPage.validateStep() | ||
194 | }) | ||
195 | |||
196 | it('Should have a valid end message', async function () { | ||
197 | const message = await signupPage.getEndMessage() | ||
198 | |||
199 | checkEndMessage({ | ||
200 | message, | ||
201 | requiresEmailVerification: false, | ||
202 | requiresApproval: true, | ||
203 | afterEmailVerification: false | ||
204 | }) | ||
205 | |||
206 | await browser.saveScreenshot('./screenshots/request-without-email.png') | ||
207 | }) | ||
208 | |||
209 | it('Should display a message when trying to login with this account', async function () { | ||
210 | const error = await loginPage.getLoginError('user_2', 'password') | ||
211 | |||
212 | expect(error).toContain('awaiting approval') | ||
213 | }) | ||
214 | |||
215 | it('Should accept the registration', async function () { | ||
216 | await loginPage.loginAsRootUser() | ||
217 | |||
218 | await adminRegistrationPage.navigateToRegistratonsList() | ||
219 | await adminRegistrationPage.accept('user_2', 'moderation response') | ||
220 | |||
221 | await loginPage.logout() | ||
222 | }) | ||
223 | |||
224 | it('Should be able to login with this new account', async function () { | ||
225 | await loginPage.login({ username: 'user_2', password: 'password', displayName: 'user_2 display name' }) | ||
226 | |||
227 | await loginPage.logout() | ||
228 | }) | ||
229 | }) | ||
73 | }) | 230 | }) |
74 | 231 | ||
75 | it('Should validate the third step (channel)', async function () { | 232 | describe('Email verification enabled', function () { |
76 | await signupPage.fillChannelStep({ | 233 | const emails: any[] = [] |
77 | displayName: 'user 1 channel', | 234 | let emailPort: number |
78 | name: 'user_1_channel' | 235 | |
236 | before(async () => { | ||
237 | // FIXME: typings are wrong, get returns a promise | ||
238 | emailPort = await browser.sharedStore.get('emailPort') as unknown as number | ||
239 | |||
240 | MockSMTPServer.Instance.collectEmails(emailPort, emails) | ||
79 | }) | 241 | }) |
80 | 242 | ||
81 | await signupPage.validateStep() | 243 | describe('Direct registration', function () { |
82 | }) | 244 | |
245 | it('Should enable signup without approval', async () => { | ||
246 | await prepareSignup({ enabled: true, requiresApproval: false, requiresEmailVerification: true }) | ||
247 | |||
248 | await signupPage.getRegisterMenuButton().waitForDisplayed() | ||
249 | }) | ||
250 | |||
251 | it('Should go on signup page', async function () { | ||
252 | await signupPage.clickOnRegisterInMenu() | ||
253 | }) | ||
254 | |||
255 | it('Should validate the first step (about page)', async function () { | ||
256 | await signupPage.validateStep() | ||
257 | }) | ||
258 | |||
259 | it('Should validate the second step (terms)', async function () { | ||
260 | await signupPage.checkTerms() | ||
261 | await signupPage.validateStep() | ||
262 | }) | ||
263 | |||
264 | it('Should validate the third step (account)', async function () { | ||
265 | await signupPage.fillAccountStep({ username: 'user_3', displayName: 'user_3 display name', email: 'user_3@example.com' }) | ||
266 | |||
267 | await signupPage.validateStep() | ||
268 | }) | ||
269 | |||
270 | it('Should validate the third step (channel)', async function () { | ||
271 | await signupPage.fillChannelStep({ name: 'user_3_channel' }) | ||
272 | |||
273 | await signupPage.validateStep() | ||
274 | }) | ||
275 | |||
276 | it('Should have a valid end message', async function () { | ||
277 | const message = await signupPage.getEndMessage() | ||
278 | |||
279 | checkEndMessage({ | ||
280 | message, | ||
281 | requiresEmailVerification: true, | ||
282 | requiresApproval: false, | ||
283 | afterEmailVerification: false | ||
284 | }) | ||
285 | |||
286 | await browser.saveScreenshot('./screenshots/direct-with-email.png') | ||
287 | }) | ||
288 | |||
289 | it('Should validate the email', async function () { | ||
290 | let email: { text: string } | ||
291 | |||
292 | while (!(email = findEmailTo(emails, 'user_3@example.com'))) { | ||
293 | await browserSleep(100) | ||
294 | } | ||
295 | |||
296 | await go(getVerificationLink(email)) | ||
297 | |||
298 | const message = await signupPage.getEndMessage() | ||
299 | |||
300 | checkEndMessage({ | ||
301 | message, | ||
302 | requiresEmailVerification: false, | ||
303 | requiresApproval: false, | ||
304 | afterEmailVerification: true | ||
305 | }) | ||
83 | 306 | ||
84 | it('Should be logged in', async function () { | 307 | await browser.saveScreenshot('./screenshots/direct-after-email.png') |
85 | await loginPage.ensureIsLoggedInAs('user 1') | 308 | }) |
309 | }) | ||
310 | |||
311 | describe('Registration with approval', function () { | ||
312 | |||
313 | it('Should enable signup without approval', async () => { | ||
314 | await prepareSignup({ enabled: true, requiresApproval: true, requiresEmailVerification: true }) | ||
315 | |||
316 | await signupPage.getRegisterMenuButton().waitForDisplayed() | ||
317 | }) | ||
318 | |||
319 | it('Should go on signup page', async function () { | ||
320 | await signupPage.clickOnRegisterInMenu() | ||
321 | }) | ||
322 | |||
323 | it('Should validate the first step (about page)', async function () { | ||
324 | await signupPage.validateStep() | ||
325 | }) | ||
326 | |||
327 | it('Should validate the second step (terms)', async function () { | ||
328 | await signupPage.checkTerms() | ||
329 | await signupPage.fillRegistrationReason('my super reason 2') | ||
330 | await signupPage.validateStep() | ||
331 | }) | ||
332 | |||
333 | it('Should validate the third step (account)', async function () { | ||
334 | await signupPage.fillAccountStep({ | ||
335 | username: 'user_4', | ||
336 | displayName: 'user_4 display name', | ||
337 | email: 'user_4@example.com', | ||
338 | password: 'password' | ||
339 | }) | ||
340 | await signupPage.validateStep() | ||
341 | }) | ||
342 | |||
343 | it('Should validate the third step (channel)', async function () { | ||
344 | await signupPage.fillChannelStep({ name: 'user_4_channel' }) | ||
345 | await signupPage.validateStep() | ||
346 | }) | ||
347 | |||
348 | it('Should have a valid end message', async function () { | ||
349 | const message = await signupPage.getEndMessage() | ||
350 | |||
351 | checkEndMessage({ | ||
352 | message, | ||
353 | requiresEmailVerification: true, | ||
354 | requiresApproval: true, | ||
355 | afterEmailVerification: false | ||
356 | }) | ||
357 | |||
358 | await browser.saveScreenshot('./screenshots/request-with-email.png') | ||
359 | }) | ||
360 | |||
361 | it('Should display a message when trying to login with this account', async function () { | ||
362 | const error = await loginPage.getLoginError('user_4', 'password') | ||
363 | |||
364 | expect(error).toContain('awaiting approval') | ||
365 | }) | ||
366 | |||
367 | it('Should accept the registration', async function () { | ||
368 | await loginPage.loginAsRootUser() | ||
369 | |||
370 | await adminRegistrationPage.navigateToRegistratonsList() | ||
371 | await adminRegistrationPage.accept('user_4', 'moderation response 2') | ||
372 | |||
373 | await loginPage.logout() | ||
374 | }) | ||
375 | |||
376 | it('Should validate the email', async function () { | ||
377 | let email: { text: string } | ||
378 | |||
379 | while (!(email = findEmailTo(emails, 'user_4@example.com'))) { | ||
380 | await browserSleep(100) | ||
381 | } | ||
382 | |||
383 | await go(getVerificationLink(email)) | ||
384 | |||
385 | const message = await signupPage.getEndMessage() | ||
386 | |||
387 | checkEndMessage({ | ||
388 | message, | ||
389 | requiresEmailVerification: false, | ||
390 | requiresApproval: true, | ||
391 | afterEmailVerification: true | ||
392 | }) | ||
393 | |||
394 | await browser.saveScreenshot('./screenshots/request-after-email.png') | ||
395 | }) | ||
396 | }) | ||
397 | |||
398 | before(() => { | ||
399 | MockSMTPServer.Instance.kill() | ||
400 | }) | ||
86 | }) | 401 | }) |
87 | }) | 402 | }) |