freeCodeCamp/e2e/utils/mailhog.ts
Mrugesh Mohapatra 3cbe2ab8b1
Some checks failed
i18n - Build Validation / Validate i18n Builds (22) (push) Has been cancelled
CI - Node.js / Lint (22) (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
CD - Docker - DOCR Cleanup Container Images / Delete Old Images (learn-api, dev) (push) Has been cancelled
CD - Docker - DOCR Cleanup Container Images / Delete Old Images (learn-api, org) (push) Has been cancelled
i18n - Download Client UI / Client (push) Has been cancelled
i18n - Upload Client UI / Client (push) Has been cancelled
i18n - Upload Curriculum / Learn (push) Has been cancelled
fix(tools): consolidate docker compose setup (#62525)
2025-10-07 10:49:41 +05:30

39 lines
1.0 KiB
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;
};
// TODO: Remove MAILHOG_HOST in a few months
// We renamed MailHog to MailPit, but kept the same port and API
// This is to keep backward compatibility with existing setups
// that might still use MAILHOG_HOST environment variable
const host =
process.env.MAILPIT_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'
});
};