Skip to content
Snippets Groups Projects
Commit c3eb184b authored by Hugo SUBTIL's avatar Hugo SUBTIL
Browse files

feat: add tu for password change

parent cead66ea
No related branches found
No related tags found
3 merge requests!27Recette,!26Dev,!6Feat/change password
...@@ -99,4 +99,22 @@ describe('UsersService', () => { ...@@ -99,4 +99,22 @@ describe('UsersService', () => {
expect(await service.validateUser('add3d', 'qdqdqdqd185')).toBe(result); expect(await service.validateUser('add3d', 'qdqdqdqd185')).toBe(result);
}); });
}); });
describe('changeUserPassword', () => {
it('should not change password', async () => {
const result = new HttpException('Invalid token', HttpStatus.UNAUTHORIZED);
jest.spyOn(service, 'changeUserPassword').mockImplementation(async (): Promise<HttpException> => result);
expect(await service.changeUserPassword('add3d', 'azertyU1', 'azertyU1!d')).toBe(result);
});
it('should not change password', async () => {
const result = new HttpException('Invalid token', HttpStatus.UNPROCESSABLE_ENTITY);
jest.spyOn(service, 'changeUserPassword').mockImplementation(async (): Promise<HttpException> => result);
expect(await service.changeUserPassword('add3d', 'azertyU1!d', 'a')).toBe(result);
});
it('should not change password', async () => {
const result = new HttpException('Invalid token', HttpStatus.CREATED);
jest.spyOn(service, 'changeUserPassword').mockImplementation(async (): Promise<HttpException> => result);
expect(await service.changeUserPassword('add3d', 'azertyU1!d', 'azertyU1!d')).toBe(result);
});
});
}); });
...@@ -134,7 +134,7 @@ export class UsersService { ...@@ -134,7 +134,7 @@ export class UsersService {
} }
} }
public async changeUserPassword(userId: string, oldPassword: string, newPassword: string) { public async changeUserPassword(userId: string, oldPassword: string, newPassword: string): Promise<any> {
const user = await this.findById(userId, true); const user = await this.findById(userId, true);
const arePasswordEqual = await this.comparePassword(oldPassword, user.password); const arePasswordEqual = await this.comparePassword(oldPassword, user.password);
if (!arePasswordEqual) { if (!arePasswordEqual) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment