Skip to content

Commit

Permalink
avoid 400 badrequest error in login page
Browse files Browse the repository at this point in the history
  • Loading branch information
Nay Oo Lwin committed Feb 12, 2024
1 parent 558c475 commit da2bd02
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 64 deletions.
94 changes: 47 additions & 47 deletions src/screens/LoginPage/LoginPage.test.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable jest/no-commented-out-tests */
import React from 'react';
import { MockedProvider } from '@apollo/react-testing';
import { act, render, screen } from '@testing-library/react';
Expand All @@ -16,7 +17,6 @@ import {
} from 'GraphQl/Mutations/mutations';
import { store } from 'state/store';
import i18nForTest from 'utils/i18nForTest';
import { BACKEND_URL } from 'Constant/constant';

const MOCKS = [
{
Expand Down Expand Up @@ -102,52 +102,52 @@ jest.mock('Constant/constant.ts', () => ({
RECAPTCHA_SITE_KEY: 'xxx',
}));

describe('Talawa-API server fetch check', () => {
beforeEach(() => {
jest.clearAllMocks();
});

test('Checks if Talawa-API resource is loaded successfully', async () => {
global.fetch = jest.fn(() => Promise.resolve({} as unknown as Response));

await act(async () => {
render(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
<Provider store={store}>
<I18nextProvider i18n={i18nForTest}>
<LoginPage />
</I18nextProvider>
</Provider>
</BrowserRouter>
</MockedProvider>
);
});

expect(fetch).toHaveBeenCalledWith(BACKEND_URL);
});

test('displays warning message when resource loading fails', async () => {
const mockError = new Error('Network error');
global.fetch = jest.fn(() => Promise.reject(mockError));

await act(async () => {
render(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
<Provider store={store}>
<I18nextProvider i18n={i18nForTest}>
<LoginPage />
</I18nextProvider>
</Provider>
</BrowserRouter>
</MockedProvider>
);
});

expect(fetch).toHaveBeenCalledWith(BACKEND_URL);
});
});
// describe('Talawa-API server fetch check', () => {
// beforeEach(() => {
// jest.clearAllMocks();
// });

// test('Checks if Talawa-API resource is loaded successfully', async () => {
// global.fetch = jest.fn(() => Promise.resolve({} as unknown as Response));

// await act(async () => {
// render(
// <MockedProvider addTypename={false} link={link}>
// <BrowserRouter>
// <Provider store={store}>
// <I18nextProvider i18n={i18nForTest}>
// <LoginPage />
// </I18nextProvider>
// </Provider>
// </BrowserRouter>
// </MockedProvider>
// );
// });

// expect(fetch).toHaveBeenCalledWith(BACKEND_URL);
// });

// test('displays warning message when resource loading fails', async () => {
// const mockError = new Error('Network error');
// global.fetch = jest.fn(() => Promise.reject(mockError));

// await act(async () => {
// render(
// <MockedProvider addTypename={false} link={link}>
// <BrowserRouter>
// <Provider store={store}>
// <I18nextProvider i18n={i18nForTest}>
// <LoginPage />
// </I18nextProvider>
// </Provider>
// </BrowserRouter>
// </MockedProvider>
// );
// });

// expect(fetch).toHaveBeenCalledWith(BACKEND_URL);
// });
// });

describe('Testing Login Page Screen', () => {
test('Component Should be rendered properly', async () => {
Expand Down
30 changes: 13 additions & 17 deletions src/screens/LoginPage/LoginPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ import {
YoutubeLogo,
} from 'assets/svgs/social-icons';

import {
REACT_APP_USE_RECAPTCHA,
RECAPTCHA_SITE_KEY,
BACKEND_URL,
} from 'Constant/constant';
import { REACT_APP_USE_RECAPTCHA, RECAPTCHA_SITE_KEY } from 'Constant/constant';
import {
LOGIN_MUTATION,
RECAPTCHA_MUTATION,
Expand Down Expand Up @@ -133,18 +129,18 @@ function loginPage(): JSX.Element {
const [recaptcha, { loading: recaptchaLoading }] =
useMutation(RECAPTCHA_MUTATION);

useEffect(() => {
async function loadResource(): Promise<void> {
try {
await fetch(BACKEND_URL as string);
} catch (error: any) {
/* istanbul ignore next */
errorHandler(t, error);
}
}

loadResource();
}, []);
// useEffect(() => {
// async function loadResource(): Promise<void> {
// try {
// await fetch(BACKEND_URL as string);
// } catch (error: any) {
// /* istanbul ignore next */
// errorHandler(t, error);
// }
// }

// loadResource();
// }, []);

const verifyRecaptcha = async (
recaptchaToken: any
Expand Down

0 comments on commit da2bd02

Please sign in to comment.