]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/e2e/src/suites-local/signup.e2e-spec.ts
Fix local e2e tests
[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 () => {
a41b9443 246 const key = browser.options.baseUrl + '-emailPort'
5bdfa604 247 // FIXME: typings are wrong, get returns a promise
a41b9443
C
248 // FIXME: use * because the key is not properly escaped by the shared store when using get(key)
249 emailPort = (await (browser.sharedStore.get('*') as unknown as Promise<number>))[key]
5bdfa604 250
5b94394a 251 await MockSMTPServer.Instance.collectEmails(emailPort, emails)
1db86422
C
252 })
253
5bdfa604
C
254 describe('Direct registration', function () {
255
256 it('Should enable signup without approval', async () => {
257 await prepareSignup({ enabled: true, requiresApproval: false, requiresEmailVerification: true })
258
259 await signupPage.getRegisterMenuButton().waitForDisplayed()
260 })
261
262 it('Should go on signup page', async function () {
263 await signupPage.clickOnRegisterInMenu()
264 })
265
266 it('Should validate the first step (about page)', async function () {
267 await signupPage.validateStep()
268 })
269
270 it('Should validate the second step (terms)', async function () {
271 await signupPage.checkTerms()
272 await signupPage.validateStep()
273 })
274
275 it('Should validate the third step (account)', async function () {
276 await signupPage.fillAccountStep({ username: 'user_3', displayName: 'user_3 display name', email: 'user_3@example.com' })
277
278 await signupPage.validateStep()
279 })
280
281 it('Should validate the third step (channel)', async function () {
282 await signupPage.fillChannelStep({ name: 'user_3_channel' })
283
284 await signupPage.validateStep()
285 })
286
287 it('Should have a valid end message', async function () {
288 const message = await signupPage.getEndMessage()
289
290 checkEndMessage({
291 message,
292 requiresEmailVerification: true,
293 requiresApproval: false,
294 afterEmailVerification: false
295 })
296
1ec4835d 297 await browser.saveScreenshot(getScreenshotPath('direct-with-email.png'))
5bdfa604
C
298 })
299
300 it('Should validate the email', async function () {
301 let email: { text: string }
302
303 while (!(email = findEmailTo(emails, 'user_3@example.com'))) {
304 await browserSleep(100)
305 }
306
307 await go(getVerificationLink(email))
308
309 const message = await signupPage.getEndMessage()
310
311 checkEndMessage({
312 message,
313 requiresEmailVerification: false,
314 requiresApproval: false,
315 afterEmailVerification: true
316 })
1db86422 317
1ec4835d 318 await browser.saveScreenshot(getScreenshotPath('direct-after-email.png'))
5bdfa604
C
319 })
320 })
321
322 describe('Registration with approval', function () {
323
324 it('Should enable signup without approval', async () => {
325 await prepareSignup({ enabled: true, requiresApproval: true, requiresEmailVerification: true })
326
327 await signupPage.getRegisterMenuButton().waitForDisplayed()
328 })
329
330 it('Should go on signup page', async function () {
331 await signupPage.clickOnRegisterInMenu()
332 })
333
334 it('Should validate the first step (about page)', async function () {
335 await signupPage.validateStep()
336 })
337
338 it('Should validate the second step (terms)', async function () {
339 await signupPage.checkTerms()
340 await signupPage.fillRegistrationReason('my super reason 2')
341 await signupPage.validateStep()
342 })
343
344 it('Should validate the third step (account)', async function () {
345 await signupPage.fillAccountStep({
346 username: 'user_4',
347 displayName: 'user_4 display name',
348 email: 'user_4@example.com',
349 password: 'password'
350 })
351 await signupPage.validateStep()
352 })
353
354 it('Should validate the third step (channel)', async function () {
355 await signupPage.fillChannelStep({ name: 'user_4_channel' })
356 await signupPage.validateStep()
357 })
358
359 it('Should have a valid end message', async function () {
360 const message = await signupPage.getEndMessage()
361
362 checkEndMessage({
363 message,
364 requiresEmailVerification: true,
365 requiresApproval: true,
366 afterEmailVerification: false
367 })
368
1ec4835d 369 await browser.saveScreenshot(getScreenshotPath('request-with-email.png'))
5bdfa604
C
370 })
371
372 it('Should display a message when trying to login with this account', async function () {
373 const error = await loginPage.getLoginError('user_4', 'password')
374
375 expect(error).toContain('awaiting approval')
376 })
377
378 it('Should accept the registration', async function () {
379 await loginPage.loginAsRootUser()
380
381 await adminRegistrationPage.navigateToRegistratonsList()
382 await adminRegistrationPage.accept('user_4', 'moderation response 2')
383
384 await loginPage.logout()
385 })
386
387 it('Should validate the email', async function () {
388 let email: { text: string }
389
390 while (!(email = findEmailTo(emails, 'user_4@example.com'))) {
391 await browserSleep(100)
392 }
393
394 await go(getVerificationLink(email))
395
396 const message = await signupPage.getEndMessage()
397
398 checkEndMessage({
399 message,
400 requiresEmailVerification: false,
401 requiresApproval: true,
402 afterEmailVerification: true
403 })
404
1ec4835d 405 await browser.saveScreenshot(getScreenshotPath('request-after-email.png'))
5bdfa604
C
406 })
407 })
408
5b94394a 409 after(() => {
5bdfa604
C
410 MockSMTPServer.Instance.kill()
411 })
1db86422
C
412 })
413})