From 89c25c07b6d4a9e880cc7a43ea97481226ab4aa2 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 28 Jun 2023 09:59:55 +0200 Subject: [PATCH] refs #5475 fix e2e and back test --- back/methods/vn-user/specs/sign-in.spec.js | 14 ++++++++------ e2e/helpers/puppeteer.js | 2 +- e2e/paths/01-salix/05_changePassword.spec.js | 12 +++++++++++- .../02_alias_create_and_basic_data.spec.js | 2 +- front/salix/components/change-password/index.js | 4 ---- .../account/back/methods/account/set-password.js | 4 ++-- .../methods/account/specs/set-password.spec.js | 14 ++++++++++++-- 7 files changed, 35 insertions(+), 17 deletions(-) diff --git a/back/methods/vn-user/specs/sign-in.spec.js b/back/methods/vn-user/specs/sign-in.spec.js index c3ff2d7db..710320d09 100644 --- a/back/methods/vn-user/specs/sign-in.spec.js +++ b/back/methods/vn-user/specs/sign-in.spec.js @@ -1,6 +1,6 @@ const {models} = require('vn-loopback/server/server'); -fdescribe('VnUser Sign-in()', () => { +describe('VnUser Sign-in()', () => { const employeeId = 1; const unauthCtx = { req: { @@ -76,24 +76,26 @@ fdescribe('VnUser Sign-in()', () => { describe('when passExpired', () => { it('should throw a passExpired error', async() => { - let error; + const tx = await VnUser.beginTransaction({}); const employee = await VnUser.findById(employeeId); const yesterday = Date.vnNew(); yesterday.setDate(yesterday.getDate() - 1); + let error; try { - await employee.updateAttribute('passExpired', yesterday); + const options = {transaction: tx}; + await employee.updateAttribute('passExpired', yesterday, options); - await VnUser.signin(unauthCtx, 'employee', 'nightmare'); + await VnUser.signin(unauthCtx, 'employee', 'nightmare', options); + await tx.rollback(); } catch (e) { + await tx.rollback(); error = e; } expect(error).toBeDefined(); expect(error.statusCode).toBe(400); expect(error.message).toBe('Pass expired'); - - await employee.updateAttribute('passExpired', null); }); }); }); diff --git a/e2e/helpers/puppeteer.js b/e2e/helpers/puppeteer.js index ac4f6cc02..bd20346a3 100644 --- a/e2e/helpers/puppeteer.js +++ b/e2e/helpers/puppeteer.js @@ -28,7 +28,7 @@ export async function getBrowser() { args, defaultViewport: null, headless: headless, - slowMo: 1, // slow down by ms + slowMo: 20, // slow down by ms // ignoreDefaultArgs: ['--disable-extensions'], // executablePath: '/usr/bin/google-chrome-stable', // executablePath: '/usr/bin/firefox-developer-edition', diff --git a/e2e/paths/01-salix/05_changePassword.spec.js b/e2e/paths/01-salix/05_changePassword.spec.js index 6e4cfb7f3..950f773dd 100644 --- a/e2e/paths/01-salix/05_changePassword.spec.js +++ b/e2e/paths/01-salix/05_changePassword.spec.js @@ -16,6 +16,7 @@ describe('ChangePassword path', async() => { await browser.close(); }); + const badPassword = 'badpass'; const oldPassword = 'nightmare'; const newPassword = 'newPass.1234'; describe('Bad login', async() => { @@ -37,13 +38,22 @@ describe('ChangePassword path', async() => { expect(message.text).toContain('Invalid current password'); // Bad attempt: password not meet requirements + message = await page.sendForm($.form, { + oldPassword: oldPassword, + newPassword: badPassword, + repeatPassword: badPassword + }); + + expect(message.text).toContain('Password does not meet requirements'); + + // Bad attempt: same password message = await page.sendForm($.form, { oldPassword: oldPassword, newPassword: oldPassword, repeatPassword: oldPassword }); - expect(message.text).toContain('Password does not meet requirements'); + expect(message.text).toContain('You can not use the same password'); // Correct attempt: change password message = await page.sendForm($.form, { diff --git a/e2e/paths/14-account/02_alias_create_and_basic_data.spec.js b/e2e/paths/14-account/02_alias_create_and_basic_data.spec.js index dd35dd740..78a17d353 100644 --- a/e2e/paths/14-account/02_alias_create_and_basic_data.spec.js +++ b/e2e/paths/14-account/02_alias_create_and_basic_data.spec.js @@ -1,7 +1,7 @@ import selectors from '../../helpers/selectors.js'; import getBrowser from '../../helpers/puppeteer'; -describe('Account Alias create and basic data path', () => { +fdescribe('Account Alias create and basic data path', () => { let browser; let page; diff --git a/front/salix/components/change-password/index.js b/front/salix/components/change-password/index.js index c8b0a2efb..80784e5d0 100644 --- a/front/salix/components/change-password/index.js +++ b/front/salix/components/change-password/index.js @@ -15,10 +15,6 @@ export default class Controller { } $onInit() { - this.oldPassword = 'nightmare'; - this.repeatPassword = 'test.1234'; - this.newPassword = 'test.1234'; - this.verificationCode = '1234'; if (!this.$state.params.id) this.$state.go('login'); diff --git a/modules/account/back/methods/account/set-password.js b/modules/account/back/methods/account/set-password.js index 010197e0d..f6c820af9 100644 --- a/modules/account/back/methods/account/set-password.js +++ b/modules/account/back/methods/account/set-password.js @@ -21,7 +21,7 @@ module.exports = Self => { } }); - Self.setPassword = async function(id, newPassword) { - await Self.app.models.VnUser.setPassword(id, newPassword); + Self.setPassword = async function(id, newPassword, options) { + await Self.app.models.VnUser.setPassword(id, newPassword, options); }; }; diff --git a/modules/account/back/methods/account/specs/set-password.spec.js b/modules/account/back/methods/account/specs/set-password.spec.js index 5de2a7bad..48cfa595a 100644 --- a/modules/account/back/methods/account/specs/set-password.spec.js +++ b/modules/account/back/methods/account/specs/set-password.spec.js @@ -8,8 +8,18 @@ describe('Account setPassword()', () => { }); it('should update password when it passes requirements', async() => { - let req = models.Account.setPassword(1, 'Very$ecurePa22.'); + const tx = await models.Account.beginTransaction({}); - await expectAsync(req).toBeResolved(); + let error; + try { + const options = {transaction: tx}; + await models.Account.setPassword(1, 'Very$ecurePa22.', options); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + error = e; + } + + expect(error).not.toBeDefined(); }); });