From 5d6eaca6b847cd0c7f73ca7907957835bc71244c Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 5 Jun 2023 15:20:07 +0200 Subject: [PATCH] refs #5472 test(changePassword): e2e --- db/dump/fixtures.sql | 4 + e2e/paths/01-salix/05_changePassword.spec.js | 80 +++++++++++++++++++ e2e/paths/06-claim/05_summary.spec.js | 6 +- .../components/change-password/index.html | 3 + loopback/locale/en.json | 2 +- 5 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 e2e/paths/01-salix/05_changePassword.spec.js diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 15fa96a792..67b8b718ac 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -113,6 +113,10 @@ INSERT INTO `account`.`user`(`id`,`name`,`nickname`, `bcryptPassword`, `password (1111, 'Missing', 'Missing', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 'ac754a330530832ba1bf7687f577da91', 2, 0, NULL, 'en', NULL), (1112, 'Trash', 'Trash', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 'ac754a330530832ba1bf7687f577da91', 2, 0, NULL, 'en', NULL); +UPDATE account.`user` + SET passExpired = DATE_SUB(util.VN_CURDATE(), INTERVAL 1 YEAR) + WHERE name = 'maintenance'; + INSERT INTO `account`.`mailAlias`(`id`, `alias`, `description`, `isPublic`) VALUES (1, 'general', 'General mailing list', FALSE), diff --git a/e2e/paths/01-salix/05_changePassword.spec.js b/e2e/paths/01-salix/05_changePassword.spec.js new file mode 100644 index 0000000000..969360cc4d --- /dev/null +++ b/e2e/paths/01-salix/05_changePassword.spec.js @@ -0,0 +1,80 @@ +import getBrowser from '../../helpers/puppeteer'; + +const $ = { + form: 'vn-out-layout form' +}; + +fdescribe('ChangePassword path', async() => { + let browser; + let page; + beforeAll(async() => { + browser = await getBrowser(); + page = browser.page; + }); + + afterAll(async() => { + await browser.close(); + }); + + const toExpects = []; + async function saveExpets(message, expectMessage, expectState) { + console.log(message); + if (!message) message = await page.waitForSnackbar(); + if (expectState) + toExpects.push({value: await page.getState(), expected: toExpects.length + expectState}); + if (expectMessage) + toExpects.push({value: message.text, expected: toExpects.length + expectMessage}); + } + + function expects() { + for (let toExpect of toExpects) + expect(toExpect.expected).toContain(toExpect.value); // eslint-disable-line + } + + const oldPassword = 'nightmare'; + const newPassword = 'newPass.1234'; + describe('Bad login', async() => { + it('should receive an error when the password is expired', async() => { + // 0 Expired login + await saveExpets(await page.doLogin( + 'maintenance', + oldPassword + ), 'The password has expired, change it from Salix', 'change-password'); + + // 1 Bad attempt: incorrect current password + await saveExpets(await page.sendForm($.form, { + oldPassword: newPassword, + newPassword: oldPassword, + repeatPassword: oldPassword + }), 'Invalid current password'); + + // 2 Bad attempt: password not meet requirements + await saveExpets(await page.sendForm($.form, { + oldPassword: oldPassword, + newPassword: oldPassword, + repeatPassword: oldPassword + }), 'Password does not meet requirements'); + + // 3 Correct attempt: change password + await saveExpets(await page.sendForm($.form, { + oldPassword: oldPassword, + newPassword: newPassword, + repeatPassword: newPassword + }), 'Password updated!', 'login'); + + // 4 Bad login, old password + await saveExpets(await page.doLogin( + 'maintenance', + oldPassword + ), 'The password has expired, change it from Salix'); + + // 5 Correct login, new password + await saveExpets(await page.doLogin( + 'maintenance', + newPassword + ), null, 'change-password'); + + expects(); + }); + }); +}); diff --git a/e2e/paths/06-claim/05_summary.spec.js b/e2e/paths/06-claim/05_summary.spec.js index 9656ea656d..46c208723b 100644 --- a/e2e/paths/06-claim/05_summary.spec.js +++ b/e2e/paths/06-claim/05_summary.spec.js @@ -49,7 +49,11 @@ describe('Claim summary path', () => { }); it(`should click on the first sale ID making the item descriptor visible`, async() => { - await page.waitToClick(selectors.claimSummary.firstSaleItemId); + const firstItem = selectors.claimSummary.firstSaleItemId; + await page.evaluate(selectors => { + document.querySelector(selectors).scrollIntoView(); + }, firstItem); + await page.waitToClick(firstItem, true); await page.waitImgLoad(selectors.claimSummary.firstSaleDescriptorImage); const visible = await page.isVisible(selectors.claimSummary.itemDescriptorPopover); diff --git a/front/salix/components/change-password/index.html b/front/salix/components/change-password/index.html index 5ea5ced971..8d338d4118 100644 --- a/front/salix/components/change-password/index.html +++ b/front/salix/components/change-password/index.html @@ -2,12 +2,14 @@ @@ -15,6 +17,7 @@ diff --git a/loopback/locale/en.json b/loopback/locale/en.json index d8cbee3962..8bc9d40563 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -172,7 +172,7 @@ "Comment added to client": "Comment added to client", "This ticket is already a refund": "This ticket is already a refund", "A claim with that sale already exists": "A claim with that sale already exists", - "Pass expired": "The password has expired, change it from Salix", + "Pass expired": "The password has expired, change it from Salix", "Can't transfer claimed sales": "Can't transfer claimed sales", "Invalid quantity": "Invalid quantity" }