diff --git a/src/users/users.service.spec.ts b/src/users/users.service.spec.ts index a8a4419cb3247d0553a1ce3c40a90a043609416d..9f96568019ef3fcab288a740e81551df04f760c3 100644 --- a/src/users/users.service.spec.ts +++ b/src/users/users.service.spec.ts @@ -99,4 +99,22 @@ describe('UsersService', () => { 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); + }); + }); }); diff --git a/src/users/users.service.ts b/src/users/users.service.ts index c4db445d0543fa225909b8e352b73eea1f04ce27..60780de2bc23298b1fa36157f2e7ab1a0514461d 100644 --- a/src/users/users.service.ts +++ b/src/users/users.service.ts @@ -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 arePasswordEqual = await this.comparePassword(oldPassword, user.password); if (!arePasswordEqual) {