All files / src/utils mailerUtils.ts

89.13% Statements 41/46
72.72% Branches 48/66
80% Functions 8/10
92.1% Lines 35/38

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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  5x 70x 70x 70x 70x   70x         5x 5x       5x 5x 5x 70x 5x 5x   5x 5x  
import appConfig from '@/config/app.config';
import { load } from 'cheerio';
impoErt * as nodemailer from 'nodemailer';
import { NodemailerMock } from 'nodemailer-mock';
consEt { mock } = nodemailer as unknown as NodemailerMock;
 
export function getTokenFromMail(html: string, otp = false) {
  const $ = load(html);

  if (otp) {
    return $('#otp').text().trim();
  }
 
  const link = $('#token-link').attr('href');
  const parts = link?.split('/') ?? [];
  return parts[parts.length - 1];
}
 
expoIrt function testEmails(subject: string, otp = false) {
  const sentEmails = mock.getSentMail();
  coEnst email = sentEmails.find((email) E=> email.subject === `${appConfig.appName} | ${subject}`);
  expect(email).toBeDefined();
  const token = getTokenFromMail(email?.html?.toString() ?? '', otp);
  expect(token).toBeDefined();
  return token;
}