24 lines
664 B
TypeScript
24 lines
664 B
TypeScript
import { isExpired, sessionFrom } from './session';
|
|
|
|
describe('session', () => {
|
|
it('computes the expiry from expires_in', () => {
|
|
const session = sessionFrom(
|
|
{ accessToken: 't', refreshToken: 'r', expiresIn: 3600 },
|
|
1_000,
|
|
);
|
|
expect(session).toEqual({
|
|
accessToken: 't',
|
|
refreshToken: 'r',
|
|
expiresAt: 3_601_000,
|
|
});
|
|
});
|
|
|
|
it('treats tokens about to expire as expired', () => {
|
|
const session = sessionFrom({ accessToken: 't', expiresIn: 30 }, 0);
|
|
expect(isExpired(session, 0)).toBe(true);
|
|
expect(
|
|
isExpired(sessionFrom({ accessToken: 't', expiresIn: 3600 }, 0), 0),
|
|
).toBe(false);
|
|
});
|
|
});
|