1 import { AdminConfigPage } from '../po/admin-config.po'
2 import { AdminRegistrationPage } from '../po/admin-registration.po'
3 import { LoginPage } from '../po/login.po'
4 import { SignupPage } from '../po/signup.po'
16 function checkEndMessage (options: {
18 requiresEmailVerification: boolean
19 requiresApproval: boolean
20 afterEmailVerification: boolean
22 const { message, requiresApproval, requiresEmailVerification, afterEmailVerification } = options
25 const created = 'account has been created'
26 const request = 'account request has been sent'
28 if (requiresApproval) {
29 expect(message).toContain(request)
30 expect(message).not.toContain(created)
32 expect(message).not.toContain(request)
33 expect(message).toContain(created)
38 const checkEmail = 'Check your emails'
40 if (requiresEmailVerification) {
41 expect(message).toContain(checkEmail)
43 expect(message).not.toContain(checkEmail)
45 const moderatorsApproval = 'moderator will check your registration request'
46 if (requiresApproval) {
47 expect(message).toContain(moderatorsApproval)
49 expect(message).not.toContain(moderatorsApproval)
55 const emailVerified = 'email has been verified'
57 if (afterEmailVerification) {
58 expect(message).toContain(emailVerified)
60 expect(message).not.toContain(emailVerified)
65 describe('Signup', () => {
66 let loginPage: LoginPage
67 let adminConfigPage: AdminConfigPage
68 let signupPage: SignupPage
69 let adminRegistrationPage: AdminRegistrationPage
71 async function prepareSignup (options: {
73 requiresApproval?: boolean
74 requiresEmailVerification?: boolean
76 await loginPage.loginAsRootUser()
78 await adminConfigPage.navigateTo('basic-configuration')
79 await adminConfigPage.toggleSignup(options.enabled)
81 if (options.enabled) {
82 if (options.requiresApproval !== undefined) {
83 await adminConfigPage.toggleSignupApproval(options.requiresApproval)
86 if (options.requiresEmailVerification !== undefined) {
87 await adminConfigPage.toggleSignupEmailVerification(options.requiresEmailVerification)
91 await adminConfigPage.save()
93 await loginPage.logout()
94 await browser.refresh()
101 beforeEach(async () => {
102 loginPage = new LoginPage(isMobileDevice())
103 adminConfigPage = new AdminConfigPage()
104 signupPage = new SignupPage()
105 adminRegistrationPage = new AdminRegistrationPage()
107 await browser.maximizeWindow()
110 describe('Signup disabled', function () {
111 it('Should disable signup', async () => {
112 await prepareSignup({ enabled: false })
114 await expect(signupPage.getRegisterMenuButton()).not.toBeDisplayed()
118 describe('Email verification disabled', function () {
120 describe('Direct registration', function () {
122 it('Should enable signup without approval', async () => {
123 await prepareSignup({ enabled: true, requiresApproval: false, requiresEmailVerification: false })
125 await signupPage.getRegisterMenuButton().waitForDisplayed()
128 it('Should go on signup page', async function () {
129 await signupPage.clickOnRegisterInMenu()
132 it('Should validate the first step (about page)', async function () {
133 await signupPage.validateStep()
136 it('Should validate the second step (terms)', async function () {
137 await signupPage.checkTerms()
138 await signupPage.validateStep()
141 it('Should validate the third step (account)', async function () {
142 await signupPage.fillAccountStep({ username: 'user_1', displayName: 'user_1_dn' })
144 await signupPage.validateStep()
147 it('Should validate the third step (channel)', async function () {
148 await signupPage.fillChannelStep({ name: 'user_1_channel' })
150 await signupPage.validateStep()
153 it('Should be logged in', async function () {
154 await loginPage.ensureIsLoggedInAs('user_1_dn')
157 it('Should have a valid end message', async function () {
158 const message = await signupPage.getEndMessage()
162 requiresEmailVerification: false,
163 requiresApproval: false,
164 afterEmailVerification: false
167 await browser.saveScreenshot(getScreenshotPath('direct-without-email.png'))
169 await loginPage.logout()
173 describe('Registration with approval', function () {
175 it('Should enable signup with approval', async () => {
176 await prepareSignup({ enabled: true, requiresApproval: true, requiresEmailVerification: false })
178 await signupPage.getRegisterMenuButton().waitForDisplayed()
181 it('Should go on signup page', async function () {
182 await signupPage.clickOnRegisterInMenu()
185 it('Should validate the first step (about page)', async function () {
186 await signupPage.validateStep()
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()
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()
200 it('Should validate the third step (channel)', async function () {
201 await signupPage.fillChannelStep({ name: 'user_2_channel' })
202 await signupPage.validateStep()
205 it('Should have a valid end message', async function () {
206 const message = await signupPage.getEndMessage()
210 requiresEmailVerification: false,
211 requiresApproval: true,
212 afterEmailVerification: false
215 await browser.saveScreenshot(getScreenshotPath('request-without-email.png'))
218 it('Should display a message when trying to login with this account', async function () {
219 const error = await loginPage.getLoginError('user_2', 'password')
221 expect(error).toContain('awaiting approval')
224 it('Should accept the registration', async function () {
225 await loginPage.loginAsRootUser()
227 await adminRegistrationPage.navigateToRegistratonsList()
228 await adminRegistrationPage.accept('user_2', 'moderation response')
230 await loginPage.logout()
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' })
236 await loginPage.logout()
241 describe('Email verification enabled', function () {
242 const emails: any[] = []
243 let emailPort: number
246 const key = browser.options.baseUrl + '-emailPort'
247 // FIXME: typings are wrong, get returns a promise
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]
251 await MockSMTPServer.Instance.collectEmails(emailPort, emails)
254 describe('Direct registration', function () {
256 it('Should enable signup without approval', async () => {
257 await prepareSignup({ enabled: true, requiresApproval: false, requiresEmailVerification: true })
259 await signupPage.getRegisterMenuButton().waitForDisplayed()
262 it('Should go on signup page', async function () {
263 await signupPage.clickOnRegisterInMenu()
266 it('Should validate the first step (about page)', async function () {
267 await signupPage.validateStep()
270 it('Should validate the second step (terms)', async function () {
271 await signupPage.checkTerms()
272 await signupPage.validateStep()
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' })
278 await signupPage.validateStep()
281 it('Should validate the third step (channel)', async function () {
282 await signupPage.fillChannelStep({ name: 'user_3_channel' })
284 await signupPage.validateStep()
287 it('Should have a valid end message', async function () {
288 const message = await signupPage.getEndMessage()
292 requiresEmailVerification: true,
293 requiresApproval: false,
294 afterEmailVerification: false
297 await browser.saveScreenshot(getScreenshotPath('direct-with-email.png'))
300 it('Should validate the email', async function () {
301 let email: { text: string }
303 while (!(email = findEmailTo(emails, 'user_3@example.com'))) {
304 await browserSleep(100)
307 await go(getVerificationLink(email))
309 const message = await signupPage.getEndMessage()
313 requiresEmailVerification: false,
314 requiresApproval: false,
315 afterEmailVerification: true
318 await browser.saveScreenshot(getScreenshotPath('direct-after-email.png'))
322 describe('Registration with approval', function () {
324 it('Should enable signup without approval', async () => {
325 await prepareSignup({ enabled: true, requiresApproval: true, requiresEmailVerification: true })
327 await signupPage.getRegisterMenuButton().waitForDisplayed()
330 it('Should go on signup page', async function () {
331 await signupPage.clickOnRegisterInMenu()
334 it('Should validate the first step (about page)', async function () {
335 await signupPage.validateStep()
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()
344 it('Should validate the third step (account)', async function () {
345 await signupPage.fillAccountStep({
347 displayName: 'user_4 display name',
348 email: 'user_4@example.com',
351 await signupPage.validateStep()
354 it('Should validate the third step (channel)', async function () {
355 await signupPage.fillChannelStep({ name: 'user_4_channel' })
356 await signupPage.validateStep()
359 it('Should have a valid end message', async function () {
360 const message = await signupPage.getEndMessage()
364 requiresEmailVerification: true,
365 requiresApproval: true,
366 afterEmailVerification: false
369 await browser.saveScreenshot(getScreenshotPath('request-with-email.png'))
372 it('Should display a message when trying to login with this account', async function () {
373 const error = await loginPage.getLoginError('user_4', 'password')
375 expect(error).toContain('awaiting approval')
378 it('Should accept the registration', async function () {
379 await loginPage.loginAsRootUser()
381 await adminRegistrationPage.navigateToRegistratonsList()
382 await adminRegistrationPage.accept('user_4', 'moderation response 2')
384 await loginPage.logout()
387 it('Should validate the email', async function () {
388 let email: { text: string }
390 while (!(email = findEmailTo(emails, 'user_4@example.com'))) {
391 await browserSleep(100)
394 await go(getVerificationLink(email))
396 const message = await signupPage.getEndMessage()
400 requiresEmailVerification: false,
401 requiresApproval: true,
402 afterEmailVerification: true
405 await browser.saveScreenshot(getScreenshotPath('request-after-email.png'))
410 MockSMTPServer.Instance.kill()