forked from sombochea/verdaccio-ui
chore: added typings (#157)
This commit is contained in:
committed by
Priscila Oliveira
parent
f84fd79c5b
commit
61a400fbd8
@@ -1,6 +1,11 @@
|
||||
import { isTokenExpire, makeLogin } from './login';
|
||||
|
||||
import { generateTokenWithTimeRange, generateTokenWithExpirationAsString, generateTokenWithOutExpiration } from '../../jest/unit/components/__mocks__/token';
|
||||
import {
|
||||
generateTokenWithTimeRange,
|
||||
generateTokenWithExpirationAsString,
|
||||
generateTokenWithOutExpiration,
|
||||
generateInvalidToken,
|
||||
} from '../../jest/unit/components/__mocks__/token';
|
||||
/* eslint-disable no-console */
|
||||
console.error = jest.fn();
|
||||
|
||||
@@ -9,10 +14,6 @@ jest.mock('./api', () => ({
|
||||
}));
|
||||
|
||||
describe('isTokenExpire', (): void => {
|
||||
test('isTokenExpire - token is not present', () => {
|
||||
expect(isTokenExpire()).toBeTruthy();
|
||||
});
|
||||
|
||||
test('isTokenExpire - token is not a valid payload', (): void => {
|
||||
expect(isTokenExpire('not_a_valid_token')).toBeTruthy();
|
||||
});
|
||||
@@ -33,11 +34,16 @@ describe('isTokenExpire', (): void => {
|
||||
});
|
||||
|
||||
test('isTokenExpire - token is not a valid json token', (): void => {
|
||||
const token = generateTokenWithExpirationAsString();
|
||||
const result = ['Invalid token:', new SyntaxError('Unexpected token o in JSON at position 1'), 'xxxxxx.W29iamVjdCBPYmplY3Rd.xxxxxx'];
|
||||
const token = generateInvalidToken();
|
||||
const result = ['Invalid token:', new SyntaxError('Unexpected token i in JSON at position 0'), 'xxxxxx.aW52YWxpZHRva2Vu.xxxxxx'];
|
||||
expect(isTokenExpire(token)).toBeTruthy();
|
||||
expect(console.error).toHaveBeenCalledWith(...result);
|
||||
});
|
||||
|
||||
test('isTokenExpire - token expiration is not a number', (): void => {
|
||||
const token = generateTokenWithExpirationAsString();
|
||||
expect(isTokenExpire(token)).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('makeLogin', (): void => {
|
||||
|
||||
@@ -9,7 +9,7 @@ interface PayloadInterface {
|
||||
exp: number;
|
||||
}
|
||||
|
||||
export function isTokenExpire(token?: string): boolean {
|
||||
export function isTokenExpire(token: string | null): boolean {
|
||||
if (!isString(token)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import memoryStorage from 'localstorage-memory';
|
||||
|
||||
let storage;
|
||||
let storage: Storage;
|
||||
try {
|
||||
localStorage.setItem('__TEST__', '');
|
||||
localStorage.removeItem('__TEST__');
|
||||
|
||||
Reference in New Issue
Block a user