diff --git a/packages/backend/src/models/user.js b/packages/backend/src/models/user.js index 5f165273..61e6048c 100644 --- a/packages/backend/src/models/user.js +++ b/packages/backend/src/models/user.js @@ -223,8 +223,8 @@ class User extends Base { } } - login(password) { - return bcrypt.compare(password, this.password); + async login(password) { + return await bcrypt.compare(password, this.password); } async generateResetPasswordToken() { diff --git a/packages/backend/src/models/user.test.js b/packages/backend/src/models/user.test.js index b7183ffb..472e36f2 100644 --- a/packages/backend/src/models/user.test.js +++ b/packages/backend/src/models/user.test.js @@ -493,4 +493,18 @@ describe('User model', () => { ); }); }); + + describe('login', () => { + it('should return true when the given password matches with the user password', async () => { + const user = await createUser({ password: 'sample-password' }); + + expect(await user.login('sample-password')).toBe(true); + }); + + it('should return false when the given password does not match with the user password', async () => { + const user = await createUser({ password: 'sample-password' }); + + expect(await user.login('wrong-password')).toBe(false); + }); + }); });