Fix tests

This commit is contained in:
Convly 2022-08-25 16:27:18 +02:00
parent 87520328bd
commit d834bf6f48
2 changed files with 7 additions and 5 deletions

View File

@ -86,7 +86,7 @@ describe('API Token Auth Strategy', () => {
}); });
test('Expired token throws on authorize', async () => { test('Expired token throws on authorize', async () => {
const pastDate = Date.now() - 1; const pastDate = new Date(Date.now() - 1).toISOString();
const getBy = jest.fn(() => { const getBy = jest.fn(() => {
return { return {
@ -109,9 +109,11 @@ describe('API Token Auth Strategy', () => {
}, },
}; };
expect(async () => { const { authenticated, error } = await apiTokenStrategy.authenticate(ctx);
await apiTokenStrategy.authenticate(ctx);
}).rejects.toThrow(new UnauthorizedError('Token expired')); expect(authenticated).toBe(false);
expect(error).toBeInstanceOf(UnauthorizedError);
expect(error.message).toBe('Token expired');
expect(getBy).toHaveBeenCalledWith({ accessKey: 'api-token_tests-hashed-access-key' }); expect(getBy).toHaveBeenCalledWith({ accessKey: 'api-token_tests-hashed-access-key' });
}); });

View File

@ -47,7 +47,7 @@ const authenticate = async (ctx) => {
// token has expired // token has expired
if (expirationDate < currentDate) { if (expirationDate < currentDate) {
throw new UnauthorizedError('Token expired'); return { authenticated: false, error: new UnauthorizedError('Token expired') };
} }
// update lastUsedAt // update lastUsedAt