Merge pull request #2178 from automatisch/aut-1350-login

test(user): write tests for login
This commit is contained in:
Ömer Faruk Aydın
2024-11-12 12:04:55 +01:00
committed by GitHub
2 changed files with 16 additions and 2 deletions

View File

@@ -223,8 +223,8 @@ class User extends Base {
} }
} }
login(password) { async login(password) {
return bcrypt.compare(password, this.password); return await bcrypt.compare(password, this.password);
} }
async generateResetPasswordToken() { async generateResetPasswordToken() {

View File

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