aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/e2e/src/utils/email.ts
blob: 2ad12033340a2bb3c81484a908166d185d6ebb92 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
function getVerificationLink (email: { text: string }) {
  const { text } = email

  const regexp = /\[(?<link>http:\/\/[^\]]+)\]/g
  const matched = text.matchAll(regexp)

  if (!matched) throw new Error('Could not find verification link in email')

  for (const match of matched) {
    const link = match.groups.link

    if (link.includes('/verify-account/')) return link
  }

  throw new Error('Could not find /verify-account/ link')
}

function findEmailTo (emails: { text: string, to: { address: string }[] }[], to: string) {
  for (const email of emails) {
    for (const { address } of email.to) {
      if (address === to) return email
    }
  }

  return undefined
}

export {
  getVerificationLink,
  findEmailTo
}