aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/e2e/src/utils/email.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/e2e/src/utils/email.ts')
-rw-r--r--client/e2e/src/utils/email.ts31
1 files changed, 31 insertions, 0 deletions
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}