test: validate email sending (#58889)

Co-authored-by: Mrugesh Mohapatra <1884376+raisedadead@users.noreply.github.com>
This commit is contained in:
John A Maloney
2025-03-26 07:50:30 -05:00
committed by GitHub
parent 4a64be5b29
commit d1b4a9b89f
4 changed files with 79 additions and 4 deletions
+36 -1
View File
@@ -1,7 +1,42 @@
import { execSync } from 'child_process';
import { test, expect, Page } from '@playwright/test';
import translations from '../client/i18n/locales/english/translations.json';
import { alertToBeVisible } from './utils/alerts';
import {
deleteAllEmails,
getAllEmails,
getFirstEmail,
getSubject
} from './utils/mailhog';
test.describe('Claim a certification - almost certified user', () => {
test.beforeEach(async () => {
await deleteAllEmails();
execSync('node ./tools/scripts/seed/seed-demo-user --unclaimed-user');
});
test.afterAll(() => {
execSync('node ./tools/scripts/seed/seed-demo-user --certified-user');
});
test.use({ storageState: 'playwright/.auth/certified-user.json' });
test('User receives a congratulations email on completing all certs', async ({
page
}) => {
await page.goto('/settings#cert-front-end-development-libraries');
await page
.getByRole('button', { name: 'Claim Certification Front End' })
.click();
// verify that an email is sent
await expect(async () => {
const emails = await getAllEmails();
expect(emails.items).toHaveLength(1);
expect(getSubject(getFirstEmail(emails))).toBe(
'Congratulations on completing all of the freeCodeCamp certifications!'
);
}).toPass();
});
});
test.describe('Certification page - Non Microsoft', () => {
test.beforeEach(async ({ page }) => {
+28
View File
@@ -1,6 +1,16 @@
import { test, expect } from '@playwright/test';
import translations from '../client/i18n/locales/english/translations.json';
import { allowTrailingSlash } from './utils/url';
import {
deleteAllEmails,
getAllEmails,
getFirstEmail,
getSubject
} from './utils/mailhog';
test.beforeEach(async () => {
await deleteAllEmails();
});
test.describe('The update-email page when the user is signed in', () => {
test.beforeEach(async ({ page }) => {
@@ -47,6 +57,24 @@ test.describe('The update-email page when the user is signed in', () => {
await emailInput.fill('123@gmail.com');
await expect(submitButton).toBeEnabled();
});
test('actually sends an email', async ({ page }) => {
const emailInput = page.getByLabel(translations.misc.email);
const submitButton = page.getByRole('button', { name: 'Update my Email' });
await expect(submitButton).toBeDisabled();
await emailInput.fill('123');
await expect(submitButton).toBeDisabled();
await emailInput.fill('123@gmail.com');
await submitButton.click();
await expect(async () => {
const emails = await getAllEmails();
expect(emails.items).toHaveLength(1);
expect(getSubject(getFirstEmail(emails))).toBe(
'Please confirm your updated email address for freeCodeCamp.org'
);
}).toPass();
});
});
test.describe('The update-email page when the user is not signed in', () => {
+6 -2
View File
@@ -11,7 +11,8 @@ const {
publicUser,
fullyCertifiedUser,
userIds,
almostFullyCertifiedUser
almostFullyCertifiedUser,
unclaimedUser
} = require('./user-data');
const options = {
@@ -20,7 +21,8 @@ const options = {
'set-false': { type: 'string', multiple: true },
'seed-trophy-challenges': { type: 'boolean' },
'certified-user': { type: 'boolean' },
'almost-certified-user': { type: 'boolean' }
'almost-certified-user': { type: 'boolean' },
'unclaimed-user': { type: 'boolean' }
};
const { values: argValues } = parseArgs({ options });
@@ -127,6 +129,8 @@ const run = async () => {
await user.insertOne(fullyCertifiedUser);
} else if (argValues['almost-certified-user']) {
await user.insertOne(almostFullyCertifiedUser);
} else if (argValues['unclaimed-user']) {
await user.insertOne(unclaimedUser);
} else {
await user.insertOne(demoUser);
}
+9 -1
View File
@@ -5,13 +5,15 @@ const publicUserId = new ObjectId('663b839b24a8b29f57728b13');
const demoUserId = new ObjectId('5bd30e0f1caf6ac3ddddddb5');
const fullyCertifiedUserId = new ObjectId('5fa2db00a25c1c1fa49ce067');
const almostFullyCertifiedUserId = new ObjectId('5bd30e0f1caf6ac3ddddddb9');
const unclaimedUserId = new ObjectId('5bd30e0f1caf6ac3ddddddb1');
const userIds = [
blankUserId,
publicUserId,
demoUserId,
fullyCertifiedUserId,
almostFullyCertifiedUserId
almostFullyCertifiedUserId,
unclaimedUserId
];
module.exports.blankUser = {
@@ -12293,6 +12295,12 @@ module.exports.fullyCertifiedUser = {
unsubscribeId: 'tBX8stC5jiustPBteF2mV'
};
module.exports.unclaimedUser = {
...module.exports.fullyCertifiedUser,
id: unclaimedUserId,
isFrontEndLibsCert: false
};
module.exports.almostFullyCertifiedUser = {
...module.exports.fullyCertifiedUser,
id: almostFullyCertifiedUserId,