diff options
author | Chocobozzz <me@florianbigard.com> | 2023-01-19 09:30:05 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2023-01-19 13:53:40 +0100 |
commit | 5bdfa604f102a5e51b5152457cd1a16d79177e26 (patch) | |
tree | 878c04cbd3c452c7b45aa39e19abd38bfe691063 /client/e2e/src/utils/mock-smtp.ts | |
parent | 9589907c89d29a6c0acd52c8cb789af9f93ce9af (diff) | |
download | PeerTube-5bdfa604f102a5e51b5152457cd1a16d79177e26.tar.gz PeerTube-5bdfa604f102a5e51b5152457cd1a16d79177e26.tar.zst PeerTube-5bdfa604f102a5e51b5152457cd1a16d79177e26.zip |
Add E2E client tests for signup approval
Diffstat (limited to 'client/e2e/src/utils/mock-smtp.ts')
-rw-r--r-- | client/e2e/src/utils/mock-smtp.ts | 58 |
1 files changed, 58 insertions, 0 deletions
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 @@ | |||
1 | import { ChildProcess } from 'child_process' | ||
2 | import MailDev from '@peertube/maildev' | ||
3 | |||
4 | class 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 | |||
56 | export { | ||
57 | MockSMTPServer | ||
58 | } | ||