fix(tools): s/MailHog/Mailpit/g (#62481)

This commit is contained in:
Mrugesh Mohapatra
2025-10-04 01:55:33 +05:30
committed by GitHub
parent 034d6b1569
commit ef610dd36c
10 changed files with 29 additions and 26 deletions

View File

@@ -99,8 +99,8 @@ jobs:
image: mongo:8.0 image: mongo:8.0
ports: ports:
- 27017:27017 - 27017:27017
mailhog: mailpit:
image: mailhog/mailhog image: axllent/mailpit
ports: ports:
- 1025:1025 - 1025:1025
steps: steps:

View File

@@ -18,10 +18,10 @@ ports:
visibility: public visibility: public
- port: 3300 # challenge editor client - port: 3300 # challenge editor client
visibility: public visibility: public
- port: 8025 # MailHog - port: 8025 # Mailpit
visibility: public visibility: public
onOpen: ignore onOpen: ignore
- port: 1025 # MailHog - port: 1025 # Mailpit
onOpen: ignore onOpen: ignore
- port: 9323 # Playwright - port: 9323 # Playwright
visibility: public visibility: public

View File

@@ -11,8 +11,8 @@ export class NodemailerProvider implements MailProvider {
private transporter: Transporter; private transporter: Transporter;
/** /**
* Sets up nodemailer, with hardcodeded configuration. This is intended for * Sets up nodemailer, with hardcoded configuration. This is intended for
* use in development. * use in development with Mailpit.
*/ */
constructor() { constructor() {
this.transporter = nodemailer.createTransport({ this.transporter = nodemailer.createTransport({

View File

@@ -157,7 +157,7 @@ if (process.env.FREECODECAMP_NODE_ENV !== 'development') {
} }
export const HOME_LOCATION = process.env.HOME_LOCATION; export const HOME_LOCATION = process.env.HOME_LOCATION;
// Mailhog is used in development and test environments, hence the localhost // Mailpit is used in development and test environments, hence the localhost
// default. // default.
export const MAILHOG_HOST = process.env.MAILHOG_HOST ?? 'localhost'; export const MAILHOG_HOST = process.env.MAILHOG_HOST ?? 'localhost';
export const MONGOHQ_URL = export const MONGOHQ_URL =

View File

@@ -15,9 +15,9 @@ services:
# This will try to initiate the replica set, until it succeeds twice (i.e. until the replica set is already initialized) # This will try to initiate the replica set, until it succeeds twice (i.e. until the replica set is already initialized)
'mongosh --host mongo:27017 --eval ''try {rs.initiate();} catch (err) { if(err.codeName !== "AlreadyInitialized") throw err };''' 'mongosh --host mongo:27017 --eval ''try {rs.initiate();} catch (err) { if(err.codeName !== "AlreadyInitialized") throw err };'''
] ]
mailhog: mailpit:
restart: unless-stopped restart: unless-stopped
image: mailhog/mailhog image: axllent/mailpit
ports: ports:
- '1025:1025' - '1025:1025'
- '8025:8025' - '8025:8025'
@@ -25,15 +25,15 @@ services:
restart: unless-stopped restart: unless-stopped
depends_on: depends_on:
- mongo - mongo
- mailhog - mailpit
image: fcc-api image: fcc-api
env_file: env_file:
- .env - .env
environment: environment:
# The api cannot connect to mongodb or mailhog via localhost from inside the # The api cannot connect to mongodb or mailpit via localhost from inside the
# container, so we have to override these variables. # container, so we have to override these variables.
- MONGOHQ_URL=mongodb://mongo:27017/freecodecamp?directConnection=true - MONGOHQ_URL=mongodb://mongo:27017/freecodecamp?directConnection=true
- MAILHOG_HOST=mailhog - MAILHOG_HOST=mailpit
- HOST=0.0.0.0 - HOST=0.0.0.0
ports: ports:
- '3000:3000' - '3000:3000'

View File

@@ -30,7 +30,7 @@ test.describe('Claim a certification - almost certified user', () => {
// verify that an email is sent // verify that an email is sent
await expect(async () => { await expect(async () => {
const emails = await getAllEmails(); const emails = await getAllEmails();
expect(emails.items).toHaveLength(1); expect(emails.messages).toHaveLength(1);
expect(getSubject(getFirstEmail(emails))).toBe( expect(getSubject(getFirstEmail(emails))).toBe(
'Congratulations on completing all of the freeCodeCamp certifications!' 'Congratulations on completing all of the freeCodeCamp certifications!'
); );

View File

@@ -39,7 +39,7 @@ test('should be possible to report a user from their profile page', async ({
await expect(async () => { await expect(async () => {
const emails = await getAllEmails(); const emails = await getAllEmails();
expect(emails.items).toHaveLength(1); expect(emails.messages).toHaveLength(1);
expect(getSubject(getFirstEmail(emails))).toBe( expect(getSubject(getFirstEmail(emails))).toBe(
"Abuse Report : Reporting twaha's profile." "Abuse Report : Reporting twaha's profile."
); );

View File

@@ -69,7 +69,7 @@ test.describe('The update-email page when the user is signed in', () => {
await submitButton.click(); await submitButton.click();
await expect(async () => { await expect(async () => {
const emails = await getAllEmails(); const emails = await getAllEmails();
expect(emails.items).toHaveLength(1); expect(emails.messages).toHaveLength(1);
expect(getSubject(getFirstEmail(emails))).toBe( expect(getSubject(getFirstEmail(emails))).toBe(
'Please confirm your updated email address for freeCodeCamp.org' 'Please confirm your updated email address for freeCodeCamp.org'
); );

View File

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

View File

@@ -87,9 +87,9 @@ export default defineConfig({
// } // }
], ],
/* Some tests make the api send emails, so we need mailhog to catch them */ /* Some tests make the api send emails, so we need mailpit to catch them */
webServer: { webServer: {
command: 'docker run -d -p 1025:1025 -p 8025:8025 mailhog/mailhog', command: 'docker run --rm -p 1025:1025 -p 8025:8025 axllent/mailpit',
port: 1025, port: 1025,
reuseExistingServer: true, reuseExistingServer: true,
timeout: 180000 timeout: 180000