freeCodeCamp/e2e/utils/mailhog.ts
Mrugesh Mohapatra ef610dd36c
Some checks failed
i18n - Build Validation / Validate i18n Builds (22) (push) Has been cancelled
CI - Node.js / Lint (22) (push) Has been cancelled
CI - E2E - 3rd party donation tests / Build Client (22) (push) Has been cancelled
CI - E2E - 3rd party donation tests / Build API (Container) (push) Has been cancelled
CI - Node.js / Build (22) (push) Has been cancelled
CI - Node.js / Test (22) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (22) (push) Has been cancelled
CI - E2E - 3rd party donation tests / Run Playwright 3rd Party Donation Tests (chromium, 22) (push) Has been cancelled
fix(tools): s/MailHog/Mailpit/g (#62481)
2025-10-03 13:25:33 -07:00

34 lines
774 B
TypeScript

type Email = {
Subject: string;
ID: string;
From: { Address: string; Name: string };
To: Array<{ Address: string; Name: string }>;
};
type AllEmails = {
messages: Email[];
total: number;
count: number;
};
const host = process.env.MAILHOG_HOST || 'localhost';
export const getAllEmails = async (): Promise<AllEmails> => {
const res = await fetch(`http://${host}:8025/api/v1/messages`);
return res.json() as Promise<AllEmails>;
};
export const getFirstEmail = (allEmails: { messages: Email[] }) => {
return allEmails.messages[0];
};
export const getSubject = (email: { Subject: string }) => {
return email.Subject;
};
export const deleteAllEmails = async () => {
await fetch(`http://${host}:8025/api/v1/messages`, {
method: 'DELETE'
});
};