mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-03-14 04:00:42 -04:00
test: check reporting user sends an email (#55166)
This commit is contained in:
committed by
GitHub
parent
eb84dce6ca
commit
0916d1bb49
3
.github/workflows/e2e-playwright.yml
vendored
3
.github/workflows/e2e-playwright.yml
vendored
@@ -89,7 +89,8 @@ jobs:
|
||||
mailhog:
|
||||
image: mailhog/mailhog
|
||||
ports:
|
||||
- 1025:1025
|
||||
- 1025:1025 # SMTP server (listens for emails)
|
||||
- 8025:8025 # HTTP server (so we can make requests to the api)
|
||||
|
||||
steps:
|
||||
- name: Set Action Environment Variables
|
||||
|
||||
@@ -769,7 +769,7 @@ describe('userRoutes', () => {
|
||||
from: 'team@freecodecamp.org',
|
||||
to: 'support@freecodecamp.org',
|
||||
cc: 'foo@bar.com',
|
||||
subject: "Abuse Report: Reporting darth-vader's profile",
|
||||
subject: "Abuse Report : Reporting darth-vader's profile.",
|
||||
text: `
|
||||
Hello Team,
|
||||
|
||||
|
||||
@@ -250,7 +250,7 @@ export const userRoutes: FastifyPluginCallbackTypebox = (
|
||||
from: 'team@freecodecamp.org',
|
||||
to: 'support@freecodecamp.org',
|
||||
cc: user.email,
|
||||
subject: `Abuse Report: Reporting ${username}'s profile`,
|
||||
subject: `Abuse Report : Reporting ${username}'s profile.`,
|
||||
text: generateReportEmail(user, username, report)
|
||||
});
|
||||
|
||||
|
||||
@@ -1,9 +1,19 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
import {
|
||||
deleteAllEmails,
|
||||
getAllEmails,
|
||||
getFirstEmail,
|
||||
getSubject
|
||||
} from './utils/mailhog';
|
||||
test.use({ storageState: 'playwright/.auth/certified-user.json' });
|
||||
|
||||
// To run this test you will need to run the email server.
|
||||
// To do this: https://contribute.freecodecamp.org/#/how-to-catch-outgoing-emails-locally?id=using-mailhog
|
||||
|
||||
test.beforeEach(async () => {
|
||||
await deleteAllEmails();
|
||||
});
|
||||
|
||||
test('should be possible to report a user from their profile page', async ({
|
||||
page
|
||||
}) => {
|
||||
@@ -28,4 +38,12 @@ test('should be possible to report a user from their profile page', async ({
|
||||
await expect(page.getByTestId('flash-message')).toContainText(
|
||||
'A report was sent to the team with foo@bar.com in copy'
|
||||
);
|
||||
|
||||
await expect(async () => {
|
||||
const emails = await getAllEmails();
|
||||
expect(emails.items).toHaveLength(1);
|
||||
expect(getSubject(getFirstEmail(emails))).toBe(
|
||||
"Abuse Report : Reporting twaha's profile."
|
||||
);
|
||||
}).toPass();
|
||||
});
|
||||
|
||||
30
e2e/utils/mailhog.ts
Normal file
30
e2e/utils/mailhog.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
type Email = {
|
||||
Content: { Headers: { Subject: string[] } };
|
||||
};
|
||||
|
||||
type AllEmails = {
|
||||
items: Email[];
|
||||
};
|
||||
|
||||
const host = process.env.MAILHOG_HOST || 'localhost';
|
||||
|
||||
export const getAllEmails = async (): Promise<AllEmails> => {
|
||||
const res = await fetch(`http://${host}:8025/api/v2/messages`);
|
||||
return res.json() as Promise<AllEmails>;
|
||||
};
|
||||
|
||||
export const getFirstEmail = (allEmails: { items: Email[] }) => {
|
||||
return allEmails.items[0];
|
||||
};
|
||||
|
||||
export const getSubject = (email: {
|
||||
Content: { Headers: { Subject: string[] } };
|
||||
}) => {
|
||||
return email.Content.Headers.Subject[0];
|
||||
};
|
||||
|
||||
export const deleteAllEmails = async () => {
|
||||
await fetch(`http://${host}:8025/api/v1/messages`, {
|
||||
method: 'DELETE'
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user