mirror of
https://github.com/strapi/strapi.git
synced 2025-11-02 02:44:55 +00:00
Fix tests
This commit is contained in:
parent
87520328bd
commit
d834bf6f48
@ -86,7 +86,7 @@ describe('API Token Auth Strategy', () => {
|
||||
});
|
||||
|
||||
test('Expired token throws on authorize', async () => {
|
||||
const pastDate = Date.now() - 1;
|
||||
const pastDate = new Date(Date.now() - 1).toISOString();
|
||||
|
||||
const getBy = jest.fn(() => {
|
||||
return {
|
||||
@ -109,9 +109,11 @@ describe('API Token Auth Strategy', () => {
|
||||
},
|
||||
};
|
||||
|
||||
expect(async () => {
|
||||
await apiTokenStrategy.authenticate(ctx);
|
||||
}).rejects.toThrow(new UnauthorizedError('Token expired'));
|
||||
const { authenticated, error } = await apiTokenStrategy.authenticate(ctx);
|
||||
|
||||
expect(authenticated).toBe(false);
|
||||
expect(error).toBeInstanceOf(UnauthorizedError);
|
||||
expect(error.message).toBe('Token expired');
|
||||
|
||||
expect(getBy).toHaveBeenCalledWith({ accessKey: 'api-token_tests-hashed-access-key' });
|
||||
});
|
||||
|
||||
@ -47,7 +47,7 @@ const authenticate = async (ctx) => {
|
||||
|
||||
// token has expired
|
||||
if (expirationDate < currentDate) {
|
||||
throw new UnauthorizedError('Token expired');
|
||||
return { authenticated: false, error: new UnauthorizedError('Token expired') };
|
||||
}
|
||||
|
||||
// update lastUsedAt
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user