From ef610dd36c1ce2ef429d0e9d513ccb0a957212e4 Mon Sep 17 00:00:00 2001 From: Mrugesh Mohapatra <1884376+raisedadead@users.noreply.github.com> Date: Sat, 4 Oct 2025 01:55:33 +0530 Subject: [PATCH] fix(tools): s/MailHog/Mailpit/g (#62481) --- .github/workflows/e2e-third-party.yml | 4 ++-- .gitpod.yml | 4 ++-- api/src/plugins/mail-providers/nodemailer.ts | 4 ++-- api/src/utils/env.ts | 2 +- docker-compose.yml | 10 +++++----- e2e/certification.spec.ts | 2 +- e2e/report-user.spec.ts | 2 +- e2e/update-email.spec.ts | 2 +- e2e/utils/mailhog.ts | 21 +++++++++++--------- playwright.config.ts | 4 ++-- 10 files changed, 29 insertions(+), 26 deletions(-) diff --git a/.github/workflows/e2e-third-party.yml b/.github/workflows/e2e-third-party.yml index 28ebb9a0e03..7a4a33be269 100644 --- a/.github/workflows/e2e-third-party.yml +++ b/.github/workflows/e2e-third-party.yml @@ -99,8 +99,8 @@ jobs: image: mongo:8.0 ports: - 27017:27017 - mailhog: - image: mailhog/mailhog + mailpit: + image: axllent/mailpit ports: - 1025:1025 steps: diff --git a/.gitpod.yml b/.gitpod.yml index 085d5e4af35..8bc673b170a 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -18,10 +18,10 @@ ports: visibility: public - port: 3300 # challenge editor client visibility: public - - port: 8025 # MailHog + - port: 8025 # Mailpit visibility: public onOpen: ignore - - port: 1025 # MailHog + - port: 1025 # Mailpit onOpen: ignore - port: 9323 # Playwright visibility: public diff --git a/api/src/plugins/mail-providers/nodemailer.ts b/api/src/plugins/mail-providers/nodemailer.ts index 24ce9e82102..7adf31b04f3 100644 --- a/api/src/plugins/mail-providers/nodemailer.ts +++ b/api/src/plugins/mail-providers/nodemailer.ts @@ -11,8 +11,8 @@ export class NodemailerProvider implements MailProvider { private transporter: Transporter; /** - * Sets up nodemailer, with hardcodeded configuration. This is intended for - * use in development. + * Sets up nodemailer, with hardcoded configuration. This is intended for + * use in development with Mailpit. */ constructor() { this.transporter = nodemailer.createTransport({ diff --git a/api/src/utils/env.ts b/api/src/utils/env.ts index c089b4077a3..0876dc13329 100644 --- a/api/src/utils/env.ts +++ b/api/src/utils/env.ts @@ -157,7 +157,7 @@ if (process.env.FREECODECAMP_NODE_ENV !== 'development') { } 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. export const MAILHOG_HOST = process.env.MAILHOG_HOST ?? 'localhost'; export const MONGOHQ_URL = diff --git a/docker-compose.yml b/docker-compose.yml index 9fc91e930e9..402f38e46f9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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) 'mongosh --host mongo:27017 --eval ''try {rs.initiate();} catch (err) { if(err.codeName !== "AlreadyInitialized") throw err };''' ] - mailhog: + mailpit: restart: unless-stopped - image: mailhog/mailhog + image: axllent/mailpit ports: - '1025:1025' - '8025:8025' @@ -25,15 +25,15 @@ services: restart: unless-stopped depends_on: - mongo - - mailhog + - mailpit image: fcc-api env_file: - .env 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. - MONGOHQ_URL=mongodb://mongo:27017/freecodecamp?directConnection=true - - MAILHOG_HOST=mailhog + - MAILHOG_HOST=mailpit - HOST=0.0.0.0 ports: - '3000:3000' diff --git a/e2e/certification.spec.ts b/e2e/certification.spec.ts index 150ab9ffd30..47fd215ed3d 100644 --- a/e2e/certification.spec.ts +++ b/e2e/certification.spec.ts @@ -30,7 +30,7 @@ test.describe('Claim a certification - almost certified user', () => { // verify that an email is sent await expect(async () => { const emails = await getAllEmails(); - expect(emails.items).toHaveLength(1); + expect(emails.messages).toHaveLength(1); expect(getSubject(getFirstEmail(emails))).toBe( 'Congratulations on completing all of the freeCodeCamp certifications!' ); diff --git a/e2e/report-user.spec.ts b/e2e/report-user.spec.ts index 0b6e02eca0b..63fb341e1a0 100644 --- a/e2e/report-user.spec.ts +++ b/e2e/report-user.spec.ts @@ -39,7 +39,7 @@ test('should be possible to report a user from their profile page', async ({ await expect(async () => { const emails = await getAllEmails(); - expect(emails.items).toHaveLength(1); + expect(emails.messages).toHaveLength(1); expect(getSubject(getFirstEmail(emails))).toBe( "Abuse Report : Reporting twaha's profile." ); diff --git a/e2e/update-email.spec.ts b/e2e/update-email.spec.ts index ac031b5a4a0..22f787cbc40 100644 --- a/e2e/update-email.spec.ts +++ b/e2e/update-email.spec.ts @@ -69,7 +69,7 @@ test.describe('The update-email page when the user is signed in', () => { await submitButton.click(); await expect(async () => { const emails = await getAllEmails(); - expect(emails.items).toHaveLength(1); + expect(emails.messages).toHaveLength(1); expect(getSubject(getFirstEmail(emails))).toBe( 'Please confirm your updated email address for freeCodeCamp.org' ); diff --git a/e2e/utils/mailhog.ts b/e2e/utils/mailhog.ts index e9365d04c0a..9c3d0f0a042 100644 --- a/e2e/utils/mailhog.ts +++ b/e2e/utils/mailhog.ts @@ -1,26 +1,29 @@ type Email = { - Content: { Headers: { Subject: string[] } }; + Subject: string; + ID: string; + From: { Address: string; Name: string }; + To: Array<{ Address: string; Name: string }>; }; type AllEmails = { - items: Email[]; + messages: Email[]; + total: number; + count: number; }; const host = process.env.MAILHOG_HOST || 'localhost'; export const getAllEmails = async (): Promise => { - 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; }; -export const getFirstEmail = (allEmails: { items: Email[] }) => { - return allEmails.items[0]; +export const getFirstEmail = (allEmails: { messages: Email[] }) => { + return allEmails.messages[0]; }; -export const getSubject = (email: { - Content: { Headers: { Subject: string[] } }; -}) => { - return email.Content.Headers.Subject[0]; +export const getSubject = (email: { Subject: string }) => { + return email.Subject; }; export const deleteAllEmails = async () => { diff --git a/playwright.config.ts b/playwright.config.ts index 3eed81b7316..9967d0ca9ae 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -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: { - 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, reuseExistingServer: true, timeout: 180000