mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-25 11:16:31 -05:00
Update error types for checkLocalPassword and updateLocalPassword to InvalidCredentialsError and NoLocalIdentityError in tests
Signed-off-by: Yannick Bungers <git@innay.de>
This commit is contained in:
parent
b562a5dac7
commit
030e40ccf0
1 changed files with 19 additions and 10 deletions
|
@ -10,7 +10,10 @@ import { Repository } from 'typeorm';
|
||||||
|
|
||||||
import appConfigMock from '../config/mock/app.config.mock';
|
import appConfigMock from '../config/mock/app.config.mock';
|
||||||
import authConfigMock from '../config/mock/auth.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 { LoggerModule } from '../logger/logger.module';
|
||||||
import { User } from '../users/user.entity';
|
import { User } from '../users/user.entity';
|
||||||
import { checkPassword, hashPassword } from '../utils/password';
|
import { checkPassword, hashPassword } from '../utils/password';
|
||||||
|
@ -88,7 +91,7 @@ describe('IdentityService', () => {
|
||||||
it('fails, when user has no local identity', async () => {
|
it('fails, when user has no local identity', async () => {
|
||||||
user.identities = Promise.resolve([]);
|
user.identities = Promise.resolve([]);
|
||||||
await expect(service.updateLocalPassword(user, password)).rejects.toThrow(
|
await expect(service.updateLocalPassword(user, password)).rejects.toThrow(
|
||||||
NotInDBError,
|
NoLocalIdentityError,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -107,17 +110,23 @@ describe('IdentityService', () => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
describe('fails', () => {
|
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 () => {
|
it('when user has no local identity', async () => {
|
||||||
user.identities = Promise.resolve([]);
|
user.identities = Promise.resolve([]);
|
||||||
await expect(
|
await expect(
|
||||||
service.updateLocalPassword(user, password),
|
service.checkLocalPassword(user, password),
|
||||||
).rejects.toThrow(NotInDBError);
|
).rejects.toThrow(NoLocalIdentityError);
|
||||||
});
|
|
||||||
it('when the password is wrong', async () => {
|
|
||||||
user.identities = Promise.resolve([]);
|
|
||||||
await expect(
|
|
||||||
service.updateLocalPassword(user, 'wrong_password'),
|
|
||||||
).rejects.toThrow(NotInDBError);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue