From c35e2e155fc01cfee887c25b35f03ce6c2469f1d Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 23 May 2023 15:12:28 +0200 Subject: [PATCH] refs #5472 test(changePassword): back --- back/models/vn-user.js | 8 ++++---- back/models/vn-user.json | 7 +++++++ .../back/methods/account/change-password.js | 3 +-- .../account/specs/change-password.spec.js | 17 +++++++++-------- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/back/models/vn-user.js b/back/models/vn-user.js index d90b75882..867dce31b 100644 --- a/back/models/vn-user.js +++ b/back/models/vn-user.js @@ -125,14 +125,14 @@ module.exports = function(Self) { try { await Self.rawSql(`CALL account.user_setPassword(?, ?)`, [id, newPassword], options); - await _setPassword.call(this, id, newPassword, options, options); + await _setPassword.call(this, id, newPassword, options, cb); const user = await Self.findById(id, null, options); await user.updateAttribute('passExpired', null, options); if (tx) await tx.commit(); return; } catch (e) { if (tx) await tx.rollback(); - console.error('Error changing password, contact with informatica', e); + // console.error('Error changing password, contact with informatica', e); throw new UserError(e); } }; @@ -154,14 +154,14 @@ module.exports = function(Self) { try { await Self.rawSql(`CALL account.user_changePassword(?, ?, ?)`, [id, oldPassword, newPassword], options); - await _changePassword.call(this, id, oldPassword, newPassword, options); + await _changePassword.call(this, id, oldPassword, newPassword, options, cb); const user = await Self.findById(id, null, options); await user.updateAttribute('passExpired', null, options); if (tx) await tx.commit(); return; } catch (error) { if (tx) await tx.rollback(); - console.error('Error changing password, contact with informatica', error); + // console.error('Error changing password, contact with informatica', error); throw new UserError(error.sqlMessage || 'Error changing password, contact with informatica'); } }; diff --git a/back/models/vn-user.json b/back/models/vn-user.json index d9668903a..e23b7daa9 100644 --- a/back/models/vn-user.json +++ b/back/models/vn-user.json @@ -13,6 +13,10 @@ "type": "number", "id": true }, + "name": { + "type": "string", + "required": true + }, "username": { "type": "string", "mysql": { @@ -38,6 +42,9 @@ "lang": { "type": "string" }, + "bcryptPassword": { + "type": "string" + }, "active": { "type": "boolean" }, diff --git a/modules/account/back/methods/account/change-password.js b/modules/account/back/methods/account/change-password.js index ee1b2fd3a..c6f08a232 100644 --- a/modules/account/back/methods/account/change-password.js +++ b/modules/account/back/methods/account/change-password.js @@ -28,7 +28,6 @@ module.exports = Self => { }); Self.changePassword = async function(id, oldPassword, newPassword) { - const response = await Self.app.models.VnUser.changePassword(id, oldPassword, newPassword); - console.log(response); + await Self.app.models.VnUser.changePassword(id, oldPassword, newPassword); }; }; diff --git a/modules/account/back/methods/account/specs/change-password.spec.js b/modules/account/back/methods/account/specs/change-password.spec.js index 1b599f430..0667336f3 100644 --- a/modules/account/back/methods/account/specs/change-password.spec.js +++ b/modules/account/back/methods/account/specs/change-password.spec.js @@ -1,14 +1,15 @@ const {models} = require('vn-loopback/server/server'); -fdescribe('account changePassword()', () => { - fit('should throw an error when old password is wrong', async() => { - let err; - await models.Account.changePassword(1, 'wrongPassword2', 'nightmare.9999') - .catch(error => { - err = error.sqlMessage; - }); +describe('account changePassword()', () => { + it('should throw an error when old password is wrong', async() => { + let error; + try { + await models.Account.changePassword(1, 'wrongPassword', 'nightmare.9999'); + } catch (e) { + error = e.message; + } - expect(err).toEqual('Invalid password'); + expect(error).toContain('Invalid password'); }); it('should change password', async() => {