From f3899f3afdd6f60de0d5f40acec8f950fcac49ef Mon Sep 17 00:00:00 2001 From: Yannick Bungers Date: Thu, 6 Jan 2022 22:01:39 +0100 Subject: [PATCH] Update error types for checkLocalPassword and updateLocalPassword to InvalidCredentialsError and NoLocalIdentityError in tests Signed-off-by: Yannick Bungers --- src/identity/identity.service.spec.ts | 29 ++++++++++++++++++--------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/identity/identity.service.spec.ts b/src/identity/identity.service.spec.ts index 91b3d3d96..356670d36 100644 --- a/src/identity/identity.service.spec.ts +++ b/src/identity/identity.service.spec.ts @@ -10,7 +10,10 @@ import { Repository } from 'typeorm'; import appConfigMock from '../config/mock/app.config.mock'; import authConfigMock from '../config/mock/auth.config.mock'; -import { NotInDBError } from '../errors/errors'; +import { + InvalidCredentialsError, + NoLocalIdentityError, +} from '../errors/errors'; import { LoggerModule } from '../logger/logger.module'; import { User } from '../users/user.entity'; import { checkPassword, hashPassword } from '../utils/password'; @@ -88,7 +91,7 @@ describe('IdentityService', () => { it('fails, when user has no local identity', async () => { user.identities = Promise.resolve([]); await expect(service.updateLocalPassword(user, password)).rejects.toThrow( - NotInDBError, + NoLocalIdentityError, ); }); }); @@ -107,17 +110,23 @@ describe('IdentityService', () => { ); }); describe('fails', () => { + it('when the password is wrong', async () => { + const identity = Identity.create( + user, + ProviderType.LOCAL, + false, + ) as Identity; + identity.passwordHash = await hashPassword(password); + user.identities = Promise.resolve([identity]); + await expect( + service.checkLocalPassword(user, 'wrong_password'), + ).rejects.toThrow(InvalidCredentialsError); + }); it('when user has no local identity', async () => { user.identities = Promise.resolve([]); await expect( - service.updateLocalPassword(user, password), - ).rejects.toThrow(NotInDBError); - }); - it('when the password is wrong', async () => { - user.identities = Promise.resolve([]); - await expect( - service.updateLocalPassword(user, 'wrong_password'), - ).rejects.toThrow(NotInDBError); + service.checkLocalPassword(user, password), + ).rejects.toThrow(NoLocalIdentityError); }); }); });