aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/e2e/src/utils
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-01-19 09:30:05 +0100
committerChocobozzz <chocobozzz@cpy.re>2023-01-19 13:53:40 +0100
commit5bdfa604f102a5e51b5152457cd1a16d79177e26 (patch)
tree878c04cbd3c452c7b45aa39e19abd38bfe691063 /client/e2e/src/utils
parent9589907c89d29a6c0acd52c8cb789af9f93ce9af (diff)
downloadPeerTube-5bdfa604f102a5e51b5152457cd1a16d79177e26.tar.gz
PeerTube-5bdfa604f102a5e51b5152457cd1a16d79177e26.tar.zst
PeerTube-5bdfa604f102a5e51b5152457cd1a16d79177e26.zip
Add E2E client tests for signup approval
Diffstat (limited to 'client/e2e/src/utils')
-rw-r--r--client/e2e/src/utils/elements.ts17
-rw-r--r--client/e2e/src/utils/email.ts31
-rw-r--r--client/e2e/src/utils/hooks.ts24
-rw-r--r--client/e2e/src/utils/index.ts2
-rw-r--r--client/e2e/src/utils/mock-smtp.ts58
-rw-r--r--client/e2e/src/utils/server.ts4
6 files changed, 128 insertions, 8 deletions
diff --git a/client/e2e/src/utils/elements.ts b/client/e2e/src/utils/elements.ts
index b0ddd5a65..d9435e520 100644
--- a/client/e2e/src/utils/elements.ts
+++ b/client/e2e/src/utils/elements.ts
@@ -5,6 +5,10 @@ async function getCheckbox (name: string) {
5 return input.parentElement() 5 return input.parentElement()
6} 6}
7 7
8function isCheckboxSelected (name: string) {
9 return $(`input[id=${name}]`).isSelected()
10}
11
8async function selectCustomSelect (id: string, valueLabel: string) { 12async function selectCustomSelect (id: string, valueLabel: string) {
9 const wrapper = $(`[formcontrolname=${id}] .ng-arrow-wrapper`) 13 const wrapper = $(`[formcontrolname=${id}] .ng-arrow-wrapper`)
10 14
@@ -22,7 +26,18 @@ async function selectCustomSelect (id: string, valueLabel: string) {
22 return option.click() 26 return option.click()
23} 27}
24 28
29async function findParentElement (
30 el: WebdriverIO.Element,
31 finder: (el: WebdriverIO.Element) => Promise<boolean>
32) {
33 if (await finder(el) === true) return el
34
35 return findParentElement(await el.parentElement(), finder)
36}
37
25export { 38export {
26 getCheckbox, 39 getCheckbox,
27 selectCustomSelect 40 isCheckboxSelected,
41 selectCustomSelect,
42 findParentElement
28} 43}
diff --git a/client/e2e/src/utils/email.ts b/client/e2e/src/utils/email.ts
new file mode 100644
index 000000000..2ad120333
--- /dev/null
+++ b/client/e2e/src/utils/email.ts
@@ -0,0 +1,31 @@
1function getVerificationLink (email: { text: string }) {
2 const { text } = email
3
4 const regexp = /\[(?<link>http:\/\/[^\]]+)\]/g
5 const matched = text.matchAll(regexp)
6
7 if (!matched) throw new Error('Could not find verification link in email')
8
9 for (const match of matched) {
10 const link = match.groups.link
11
12 if (link.includes('/verify-account/')) return link
13 }
14
15 throw new Error('Could not find /verify-account/ link')
16}
17
18function findEmailTo (emails: { text: string, to: { address: string }[] }[], to: string) {
19 for (const email of emails) {
20 for (const { address } of email.to) {
21 if (address === to) return email
22 }
23 }
24
25 return undefined
26}
27
28export {
29 getVerificationLink,
30 findEmailTo
31}
diff --git a/client/e2e/src/utils/hooks.ts b/client/e2e/src/utils/hooks.ts
index 889cf1d86..7fe247681 100644
--- a/client/e2e/src/utils/hooks.ts
+++ b/client/e2e/src/utils/hooks.ts
@@ -1,10 +1,13 @@
1import { ChildProcessWithoutNullStreams } from 'child_process' 1import { ChildProcessWithoutNullStreams } from 'child_process'
2import { basename } from 'path' 2import { basename } from 'path'
3import { runCommand, runServer } from './server' 3import { runCommand, runServer } from './server'
4import { setValue } from '@wdio/shared-store-service'
4 5
5let appInstance: string 6let appInstance: number
6let app: ChildProcessWithoutNullStreams 7let app: ChildProcessWithoutNullStreams
7 8
9let emailPort: number
10
8async function beforeLocalSuite (suite: any) { 11async function beforeLocalSuite (suite: any) {
9 const config = buildConfig(suite.file) 12 const config = buildConfig(suite.file)
10 13
@@ -17,13 +20,20 @@ function afterLocalSuite () {
17 app = undefined 20 app = undefined
18} 21}
19 22
20function beforeLocalSession (config: { baseUrl: string }, capabilities: { browserName: string }) { 23async function beforeLocalSession (config: { baseUrl: string }, capabilities: { browserName: string }) {
21 appInstance = capabilities['browserName'] === 'chrome' ? '1' : '2' 24 appInstance = capabilities['browserName'] === 'chrome'
25 ? 1
26 : 2
27
28 emailPort = 1025 + appInstance
29
22 config.baseUrl = 'http://localhost:900' + appInstance 30 config.baseUrl = 'http://localhost:900' + appInstance
31
32 await setValue('emailPort', emailPort)
23} 33}
24 34
25async function onBrowserStackPrepare () { 35async function onBrowserStackPrepare () {
26 const appInstance = '1' 36 const appInstance = 1
27 37
28 await runCommand('npm run clean:server:test -- ' + appInstance) 38 await runCommand('npm run clean:server:test -- ' + appInstance)
29 app = runServer(appInstance) 39 app = runServer(appInstance)
@@ -71,7 +81,11 @@ function buildConfig (suiteFile: string = undefined) {
71 if (filename === 'signup.e2e-spec.ts') { 81 if (filename === 'signup.e2e-spec.ts') {
72 return { 82 return {
73 signup: { 83 signup: {
74 enabled: true 84 limit: -1
85 },
86 smtp: {
87 hostname: '127.0.0.1',
88 port: emailPort
75 } 89 }
76 } 90 }
77 } 91 }
diff --git a/client/e2e/src/utils/index.ts b/client/e2e/src/utils/index.ts
index 354352ee2..420fd239e 100644
--- a/client/e2e/src/utils/index.ts
+++ b/client/e2e/src/utils/index.ts
@@ -1,5 +1,7 @@
1export * from './common' 1export * from './common'
2export * from './elements' 2export * from './elements'
3export * from './email'
3export * from './hooks' 4export * from './hooks'
5export * from './mock-smtp'
4export * from './server' 6export * from './server'
5export * from './urls' 7export * from './urls'
diff --git a/client/e2e/src/utils/mock-smtp.ts b/client/e2e/src/utils/mock-smtp.ts
new file mode 100644
index 000000000..614477d7d
--- /dev/null
+++ b/client/e2e/src/utils/mock-smtp.ts
@@ -0,0 +1,58 @@
1import { ChildProcess } from 'child_process'
2import MailDev from '@peertube/maildev'
3
4class MockSMTPServer {
5
6 private static instance: MockSMTPServer
7 private started = false
8 private emailChildProcess: ChildProcess
9 private emails: object[]
10
11 collectEmails (port: number, emailsCollection: object[]) {
12 return new Promise<number>((res, rej) => {
13 this.emails = emailsCollection
14
15 if (this.started) {
16 return res(undefined)
17 }
18
19 const maildev = new MailDev({
20 ip: '127.0.0.1',
21 smtp: port,
22 disableWeb: true,
23 silent: true
24 })
25
26 maildev.on('new', email => {
27 this.emails.push(email)
28 })
29
30 maildev.listen(err => {
31 if (err) return rej(err)
32
33 this.started = true
34
35 return res(port)
36 })
37 })
38 }
39
40 kill () {
41 if (!this.emailChildProcess) return
42
43 process.kill(this.emailChildProcess.pid)
44
45 this.emailChildProcess = null
46 MockSMTPServer.instance = null
47 }
48
49 static get Instance () {
50 return this.instance || (this.instance = new this())
51 }
52}
53
54// ---------------------------------------------------------------------------
55
56export {
57 MockSMTPServer
58}
diff --git a/client/e2e/src/utils/server.ts b/client/e2e/src/utils/server.ts
index 140054794..227f4aea6 100644
--- a/client/e2e/src/utils/server.ts
+++ b/client/e2e/src/utils/server.ts
@@ -1,10 +1,10 @@
1import { exec, spawn } from 'child_process' 1import { exec, spawn } from 'child_process'
2import { join, resolve } from 'path' 2import { join, resolve } from 'path'
3 3
4function runServer (appInstance: string, config: any = {}) { 4function runServer (appInstance: number, config: any = {}) {
5 const env = Object.create(process.env) 5 const env = Object.create(process.env)
6 env['NODE_ENV'] = 'test' 6 env['NODE_ENV'] = 'test'
7 env['NODE_APP_INSTANCE'] = appInstance 7 env['NODE_APP_INSTANCE'] = appInstance + ''
8 8
9 env['NODE_CONFIG'] = JSON.stringify({ 9 env['NODE_CONFIG'] = JSON.stringify({
10 rates_limit: { 10 rates_limit: {