mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-21 18:55:19 -04:00
AuthService: Throw NotInDBError on empty DB result
This adds error handling to various functions, so they throw a NotInDBError instead of a TypeError Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
52f6310e91
commit
ef8b8d985e
2 changed files with 18 additions and 0 deletions
|
@ -168,6 +168,12 @@ describe('AuthService', () => {
|
|||
);
|
||||
await service.setLastUsedToken(authToken.keyId);
|
||||
});
|
||||
it('throws if the token is not in the database', async () => {
|
||||
jest.spyOn(authTokenRepo, 'findOne').mockResolvedValueOnce(undefined);
|
||||
await expect(service.setLastUsedToken(authToken.keyId)).rejects.toThrow(
|
||||
NotInDBError,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('validateToken', () => {
|
||||
|
@ -227,6 +233,12 @@ describe('AuthService', () => {
|
|||
);
|
||||
await service.removeToken(authToken.keyId);
|
||||
});
|
||||
it('throws if the token is not in the database', async () => {
|
||||
jest.spyOn(authTokenRepo, 'findOne').mockResolvedValueOnce(undefined);
|
||||
await expect(service.removeToken(authToken.keyId)).rejects.toThrow(
|
||||
NotInDBError,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('createTokenForUser', () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue