-
+
diff --git a/public/login/santaLogin.js b/public/login/santaLogin.js
index 57b9866..5515b02 100644
--- a/public/login/santaLogin.js
+++ b/public/login/santaLogin.js
@@ -39,7 +39,7 @@ $(async function () {
$('#santa-email-form').on('submit', function () {
$.post(
'api/email',
- { email: $('#santa-email').val() },
+ { email: $('#forgot-email').val() },
function (result) {
$('#forgot-password-dialog').modal('hide');
showAlert(result);
diff --git a/routers/session-router.js b/routers/session-router.js
index 40db2dd..6fa2480 100644
--- a/routers/session-router.js
+++ b/routers/session-router.js
@@ -82,7 +82,7 @@ sessionRouter.post('/api/email', async (req, res) => {
const data = fs.readFileSync('./templates/forgot-password-email.html');
emailText = data
.toString()
- .replace(/{{name}}/, user.name)
+ .replace(/{{email}}/, user.email)
.replace(/{{password}}/, user.password);
} else {
const data = fs.readFileSync('./templates/unknown-user-email.html');
@@ -98,11 +98,13 @@ sessionRouter.post('/api/email', async (req, res) => {
const emailStatus = await sendEmail(emailTemplate);
- if (emailStatus.success) {
- res.send({ success: `Email successfully sent to ${emailTemplate.to}` });
- } else {
- res.send({ error: `Error sending email: ${emailStatus.error}` });
+ if (emailStatus.success !== true) {
+ return res.send({ error: `Error sending email: ${emailStatus.error}` });
}
+ return res.send({
+ success: `Email successfully sent to ${emailTemplate.to}`,
+ emailUrl: emailStatus.emailUrl,
+ });
});
passport.use(
diff --git a/templates/forgot-password-email.html b/templates/forgot-password-email.html
index 5dee36b..839727b 100644
--- a/templates/forgot-password-email.html
+++ b/templates/forgot-password-email.html
@@ -45,11 +45,13 @@
Email: |
- {{name}} |
+ {{email}} |
Password: |
- {{password}} |
+
+ {{password}}
+ |
diff --git a/tests/chat.spec.js b/tests/chat.spec.js
index bc969a4..aea1020 100644
--- a/tests/chat.spec.js
+++ b/tests/chat.spec.js
@@ -9,10 +9,10 @@ test.describe('chat tests', () => {
let groupData;
let page;
- test.beforeAll('setup', async ({ browser })=> {
+ test.beforeAll('setup', async ({ browser }) => {
page = await browser.newPage();
groupData = await createNewGroup(page.request);
- })
+ });
test('user can send a message', async ({ page }) => {
await login(
@@ -53,8 +53,14 @@ test.describe('chat tests', () => {
);
await page.goto('/chat');
- await expect(page.locator('[data-name="chatTo"]')).toContainText(groupData.users.user2.name);
- await expect(page.locator('[data-name="chatMessage"]')).toHaveText(message.message);
- await expect(page.locator('[data-name="chatFrom"]')).toHaveText('From: Anonymous');
+ await expect(page.locator('[data-name="chatTo"]')).toContainText(
+ groupData.users.user2.name
+ );
+ await expect(page.locator('[data-name="chatMessage"]')).toHaveText(
+ message.message
+ );
+ await expect(page.locator('[data-name="chatFrom"]')).toHaveText(
+ 'From: Anonymous'
+ );
});
});
diff --git a/tests/email.spec.js b/tests/email.spec.js
index 32dd802..8443a57 100644
--- a/tests/email.spec.js
+++ b/tests/email.spec.js
@@ -1,14 +1,38 @@
// @ts-check
import { test, expect } from '@playwright/test';
import { faker } from '@faker-js/faker';
-import { login, registerUser } from './helpers/login.js';
+import { forgotPassword, login, registerUser } from './helpers/login.js';
import { inviteUserToGroup, updateGroup } from './helpers/admin.js';
import { createDraftedGroup, createNewGroup } from './helpers/setup.js';
import { sendMessage } from './helpers/chat.js';
test.describe('email tests', () => {
-
test.describe('admin tests', () => {
+ test('user should receive an email when forgot password is triggered', async ({
+ page,
+ }) => {
+ const user = {
+ email: faker.internet.email(),
+ password: faker.internet.password(),
+ };
+ await registerUser(page.request, user);
+ const response = await forgotPassword(page.request, user.email);
+ const responseJson = await response.json();
+ await expect(responseJson).toHaveProperty('emailUrl');
+ await page.goto(responseJson.emailUrl);
+
+ await expect(page).toHaveScreenshot('forgot-password-email.png', {
+ mask: [
+ page.locator('.mp_address_group').nth(1),
+ page.locator('.datestring'),
+ // Message-ID
+ page.locator('#message-header div').nth(4).locator('span'),
+ page.frameLocator('[style]').locator('#email-placeholder'),
+ page.frameLocator('[style]').locator('#password-placeholder'),
+ ],
+ fullPage: true,
+ });
+ });
test('new user receives an email when invited to the group', async ({
page,
@@ -44,7 +68,6 @@ test.describe('email tests', () => {
await page.goto(bodyWithUrl.emailUrl);
await expect(page).toHaveScreenshot('invite-email.png', {
- maxDiffPixelRatio: 0.05,
mask: [
page.locator('.mp_address_group').nth(1),
page.locator('.datestring'),
@@ -53,6 +76,7 @@ test.describe('email tests', () => {
page.frameLocator('[style]').locator('#group-placeholder'),
page.frameLocator('[style]').locator('#password-placeholder'),
],
+ fullPage: true,
});
});
@@ -88,7 +112,6 @@ test.describe('email tests', () => {
await page.goto(bodyWithUrl.emailUrl);
await expect(page).toHaveScreenshot('invite-email.png', {
- maxDiffPixelRatio: 0.05,
mask: [
page.locator('.mp_address_group').nth(1),
page.locator('.datestring'),
@@ -97,12 +120,12 @@ test.describe('email tests', () => {
page.frameLocator('[style]').locator('#group-placeholder'),
page.frameLocator('[style]').locator('#password-placeholder'),
],
+ fullPage: true,
});
});
- })
+ });
test.describe('chat tests', () => {
-
test('user should receive a chat email', async ({ page }) => {
const groupData = await createDraftedGroup(page.request);
const updatedGroupData = {
@@ -131,7 +154,9 @@ test.describe('email tests', () => {
await expect(page.locator('#message-header')).toContainText(
''
);
- await expect(page.locator('#message-header')).toContainText(message.email);
+ await expect(page.locator('#message-header')).toContainText(
+ message.email
+ );
await expect(
page.frameLocator('#message iframe').locator('body')
).toContainText(message.message);
@@ -152,5 +177,5 @@ test.describe('email tests', () => {
const messageData = await sendMessage(page.request, message);
await expect(messageData).not.toHaveProperty('emailUrl');
});
- })
+ });
});
diff --git a/tests/email.spec.js-snapshots/forgot-password-email-chromium-win32.png b/tests/email.spec.js-snapshots/forgot-password-email-chromium-win32.png
new file mode 100644
index 0000000..47fec1b
Binary files /dev/null and b/tests/email.spec.js-snapshots/forgot-password-email-chromium-win32.png differ
diff --git a/tests/email.spec.js-snapshots/invite-email-chromium-linux.png b/tests/email.spec.js-snapshots/invite-email-chromium-linux.png
deleted file mode 100644
index 8b8af2b..0000000
Binary files a/tests/email.spec.js-snapshots/invite-email-chromium-linux.png and /dev/null differ
diff --git a/tests/email.spec.js-snapshots/invite-email-chromium-win32.png b/tests/email.spec.js-snapshots/invite-email-chromium-win32.png
index 3f8e25e..a8fafdc 100644
Binary files a/tests/email.spec.js-snapshots/invite-email-chromium-win32.png and b/tests/email.spec.js-snapshots/invite-email-chromium-win32.png differ
diff --git a/tests/helpers/login.js b/tests/helpers/login.js
index 3775815..adbf3ee 100644
--- a/tests/helpers/login.js
+++ b/tests/helpers/login.js
@@ -13,3 +13,9 @@ export function login(request, email, password) {
data: { username: email, password },
});
}
+
+export function forgotPassword(request, email) {
+ return request.post('session/api/email', {
+ data: { email },
+ });
+}
diff --git a/tests/session.spec.js b/tests/session.spec.js
index d49f22c..107a06d 100644
--- a/tests/session.spec.js
+++ b/tests/session.spec.js
@@ -33,12 +33,36 @@ test.describe('session tests', () => {
await page.goto('/');
await page.getByLabel('Santa email').fill(user.email);
- await page.getByLabel('Santa password').fill(user.password);
+ await page.getByLabel('Santa password').fill(faker.internet.password());
+
+ await page.getByRole('button', { name: 'Login' }).click();
+ await expect(page.locator('#footerAlert')).toHaveText(
+ 'Email or password wrong'
+ );
+ await page.getByLabel('Santa password').fill(user.password);
await page.getByRole('button', { name: 'Login' }).click();
await expect(page.locator('#footerAlert')).toHaveText('No active group');
await expect(page).toHaveTitle(/Secret Santa/);
await expect(page.locator('#unavailableImage')).toBeVisible();
});
+
+ test('user can request password', async ({ request, page }) => {
+ const user = {
+ email: faker.internet.email(),
+ password: faker.internet.password(),
+ };
+ await registerUser(request, user);
+
+ await page.goto('/');
+
+ await page.getByText('Forgot password').click();
+ await page.getByLabel('Enter your email address').fill(user.email);
+ await page.getByRole('button', { name: 'Email' }).click();
+
+ await expect(page.locator('#footerAlert')).toHaveText(
+ `Email successfully sent to ${user.email}`
+ );
+ });
});
|