Skip to content

Commit 2de220a

Browse files
fixed failing test cases
1 parent bbac4f6 commit 2de220a

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

src/App.spec.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const MOCKS = [
6363
result: {
6464
data: {
6565
verifyRole: {
66-
isAuthorized: false,
66+
isAuthorized: true,
6767
role: 'user',
6868
},
6969
},
@@ -80,8 +80,8 @@ const link2 = new StaticMockLink(
8080
},
8181
{
8282
request: { query: VERIFY_ROLE },
83-
result: { data: { verifyRole: null } }, // Ensure verifyRole exists, even if null
84-
},
83+
result: { data: { verifyRole: { isAuthorized: false, role: '' } } },
84+
}, // Ensure verifyRole exists, even if null
8585
],
8686
true,
8787
);

src/components/SecuredRoute/SecuredRoute.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ const SecuredRoute = (): JSX.Element => {
4747
} else if (error) {
4848
return <div>Error During Routing ...</div>;
4949
} else {
50+
console.log('Mocked Data:', data);
51+
if (!data || !data.verifyRole) {
52+
return <div>Error During Routing ...</div>;
53+
}
5054
const { isAuthorized = false, role = '' } = (data as VerifyRoleResponse)
5155
.verifyRole;
5256
const restrictedRoutesForAdmin = ['/member', '/users', '/communityProfile'];

src/screens/PageNotFound/PageNotFound.spec.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { render, screen } from '@testing-library/react';
33
import { Provider } from 'react-redux';
44
import { BrowserRouter } from 'react-router-dom';
55
import { I18nextProvider } from 'react-i18next';
6-
76
import { store } from 'state/store';
87
import PageNotFound from './PageNotFound';
98
import i18nForTest from 'utils/i18nForTest';
@@ -16,23 +15,24 @@ import {
1615
ApolloProvider,
1716
InMemoryCache,
1817
} from '@apollo/client';
18+
1919
const { setItem } = useLocalStorage();
2020

21-
const link = new ApolloLink((operation, forward) => {
22-
return forward(operation);
23-
});
21+
const link = ApolloLink.from([
22+
new ApolloLink((operation, forward) => {
23+
return forward ? forward(operation) : null; // ✅ Fix the issue
24+
}),
25+
]);
2426

2527
const client: ApolloClient<NormalizedCacheObject> = new ApolloClient({
2628
cache: new InMemoryCache(),
27-
link: ApolloLink.from([link]),
29+
link: link,
2830
});
2931

3032
describe('Testing Page not found component', () => {
3133
it('should render component properly for User', () => {
3234
render(
3335
<ApolloProvider client={client}>
34-
{' '}
35-
{/* ✅ Add ApolloProvider */}
3636
<BrowserRouter>
3737
<Provider store={store}>
3838
<I18nextProvider i18n={i18nForTest}>

0 commit comments

Comments
 (0)