Skip to content

Commit

Permalink
[INJIWEB-977]: Fix storage.ts & Add comment in reduxMockUtils
Browse files Browse the repository at this point in the history
Signed-off-by: Kamlesh Singh Bisht <[email protected]>
  • Loading branch information
kamlesh012 committed Oct 21, 2024
1 parent f36ad03 commit afc1fc8
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
7 changes: 7 additions & 0 deletions inji-web/src/test-utils/mockUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ import { Provider } from 'react-redux';
import { BrowserRouter as Router } from 'react-router-dom';
import { reduxStore } from '../redux/reduxStore';

// Mock react-redux hooks
jest.mock('react-redux', () => ({
...jest.requireActual('react-redux'),
useSelector: (selector: any) => selector(mockReduxState),
useDispatch: () => jest.fn()
}));

// Mock for storage module
export const mockStorageModule = () => {
jest.mock('../utils/storage.ts', () => ({
Expand Down
3 changes: 2 additions & 1 deletion inji-web/src/test-utils/reduxMockUtils.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// reduxMockUtils.ts
//TO DO: Move everything from this file to mockUtils.tsx
// Currently if doing this, then storage mock is not being recognized by some test cases for i18n.test.tsx;
let mockReduxState: any = {};

export const setReduxState = (state: any) => {
Expand Down
4 changes: 2 additions & 2 deletions inji-web/src/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export class api {
// static mimotoHost = window.location.origin + "/v1/mimoto";
static mimotoHost="https://api.collab.mossip.net" + "/v1/mimoto";

static authorizationRedirectionUrl = window.location.origin + "/redirect";

// static authorizationRedirectionUrl = window.location.origin + "/redirect";
static authorizationRedirectionUrl = "https://api.collab.mossip.net" + "/redirect";

static fetchIssuers: ApiRequest = {
url: () => (api.mimotoHost + "/issuers"),
Expand Down
2 changes: 1 addition & 1 deletion inji-web/src/utils/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const getTokenRequestBody = (code: string, codeVerifier: string, issuerId
return {
'grant_type': 'authorization_code',
'code': code,
'redirect_uri': 'https://api.collab.mossip.net/redirect',
'redirect_uri': api.authorizationRedirectionUrl,
'code_verifier': codeVerifier,
'issuer': issuerId,
'credential': credentialType,
Expand Down
23 changes: 8 additions & 15 deletions inji-web/src/utils/storage.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@

export class storage {
static SESSION_INFO = "download_session";
static SELECTED_LANGUAGE = "selected_language";

static setItem = (key: string, value: string | null | undefined) => {
if (value !== null && value !== undefined) {
static SESSION_INFO = "download_session"
static SELECTED_LANGUAGE = "selected_language"
static setItem = (key: string, value: string) => {
if (value) {
localStorage.setItem(key, JSON.stringify(value));
}
}

static getItem = (key: string): string | null => {
const data = localStorage.getItem(key);
static getItem = (key: string) => {
let data = localStorage.getItem(key);
if (data) {
try {
return JSON.parse(data);
} catch (error) {
return null;
}

data = JSON.parse(data);
}
return null;
return data;
}
}

0 comments on commit afc1fc8

Please sign in to comment.