mirror of
https://github.com/SomboChea/ui
synced 2024-12-24 21:24:26 +07:00
chore: added typings (#157)
This commit is contained in:
parent
f84fd79c5b
commit
61a400fbd8
@ -15,6 +15,11 @@ export function generateTokenWithTimeRange(limit = 0) {
|
||||
|
||||
export function generateTokenWithExpirationAsString() {
|
||||
const payload = { username: 'verdaccio', exp: 'I am not a number' };
|
||||
return `xxxxxx.${Base64.encode(JSON.stringify(payload))}.xxxxxx`;
|
||||
}
|
||||
|
||||
export function generateInvalidToken() {
|
||||
const payload = `invalidtoken`;
|
||||
return `xxxxxx.${Base64.encode(payload)}.xxxxxx`;
|
||||
}
|
||||
|
||||
|
@ -19,8 +19,10 @@
|
||||
"@material-ui/icons": "4.4.3",
|
||||
"@octokit/rest": "16.28.7",
|
||||
"@testing-library/react": "9.2.0",
|
||||
"@types/autosuggest-highlight": "3.1.0",
|
||||
"@types/enzyme": "3.10.3",
|
||||
"@types/jest": "24.0.18",
|
||||
"@types/js-base64": "2.3.1",
|
||||
"@types/lodash": "4.14.141",
|
||||
"@types/node": "12.7.8",
|
||||
"@types/react": "16.9.2",
|
||||
|
@ -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__');
|
||||
|
5
types/custom.d.ts
vendored
5
types/custom.d.ts
vendored
@ -5,3 +5,8 @@ declare module '*.svg' {
|
||||
}
|
||||
|
||||
declare module '*.png';
|
||||
|
||||
declare module 'localstorage-memory' {
|
||||
const memoryStorage: Storage;
|
||||
export default memoryStorage;
|
||||
}
|
||||
|
10
yarn.lock
10
yarn.lock
@ -1498,6 +1498,11 @@
|
||||
"@testing-library/dom" "^6.3.0"
|
||||
"@types/testing-library__react" "^9.1.0"
|
||||
|
||||
"@types/autosuggest-highlight@3.1.0":
|
||||
version "3.1.0"
|
||||
resolved "https://registry.yarnpkg.com/@types/autosuggest-highlight/-/autosuggest-highlight-3.1.0.tgz#62045417c2f6d841f9f12e715336218e4db0fcb1"
|
||||
integrity sha512-rJWvrDFKf2NkB3CkeJPcnX3oD0XAQriJOhYC5DUwiK6X/KTM96e1rW+1/PgI0U4tL6GQ2K7dvoiYFhMnAaNLUw==
|
||||
|
||||
"@types/babel__core@^7.1.0":
|
||||
version "7.1.3"
|
||||
resolved "https://registry.verdaccio.org/@types%2fbabel__core/-/babel__core-7.1.3.tgz#e441ea7df63cd080dfcd02ab199e6d16a735fc30"
|
||||
@ -1607,6 +1612,11 @@
|
||||
resolved "https://registry.verdaccio.org/@types%2fjest/-/jest-23.3.14.tgz#37daaf78069e7948520474c87b80092ea912520a"
|
||||
integrity sha512-Q5hTcfdudEL2yOmluA1zaSyPbzWPmJ3XfSWeP3RyoYvS9hnje1ZyagrZOuQ6+1nQC1Gw+7gap3pLNL3xL6UBug==
|
||||
|
||||
"@types/js-base64@2.3.1":
|
||||
version "2.3.1"
|
||||
resolved "https://registry.yarnpkg.com/@types/js-base64/-/js-base64-2.3.1.tgz#c39f14f129408a3d96a1105a650d8b2b6eeb4168"
|
||||
integrity sha512-4RKbhIDGC87s4EBy2Cp2/5S2O6kmCRcZnD5KRCq1q9z2GhBte1+BdsfVKCpG8yKpDGNyEE2G6IqFIh6W2YwWPA==
|
||||
|
||||
"@types/json-schema@^7.0.3":
|
||||
version "7.0.3"
|
||||
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.3.tgz#bdfd69d61e464dcc81b25159c270d75a73c1a636"
|
||||
|
Loading…
Reference in New Issue
Block a user