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