refs #5472 test(changePassword): back
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alex Moreno 2023-05-23 15:12:28 +02:00
parent ddab59a10c
commit c35e2e155f
4 changed files with 21 additions and 14 deletions

View File

@ -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');
}
};

View File

@ -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"
},

View File

@ -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);
};
};

View File

@ -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() => {