Skip to content

Commit

Permalink
Revert "Replace all hard coded localhosts with env constant variables" (
Browse files Browse the repository at this point in the history
  • Loading branch information
palisadoes authored Jan 30, 2024
1 parent 751bcbe commit 41c8190
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ REACT_APP_BACKEND_WEBSOCKET_URL=ws://localhost:4000/graphql

# If you want to logs Compiletime and Runtime error , warning and info write YES or if u want to
# keep the console clean leave it blank
ALLOW_LOGS=
ALLOW_LOGS=
1 change: 0 additions & 1 deletion src/Constant/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ export const AUTH_TOKEN = '';
export const BACKEND_URL = process.env.REACT_APP_TALAWA_URL;
export const RECAPTCHA_SITE_KEY = process.env.REACT_APP_RECAPTCHA_SITE_KEY;
export const REACT_APP_USE_RECAPTCHA = process.env.REACT_APP_USE_RECAPTCHA;
export const REACT_APP_CUSTOM_PORT = process.env.PORT;
export const REACT_APP_BACKEND_WEBSOCKET_URL: string =
process.env.REACT_APP_BACKEND_WEBSOCKET_URL || '';
4 changes: 1 addition & 3 deletions src/screens/EventDashboard/EventDashboard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
queryMockWithTime,
queryMockWithoutTime,
} from './EventDashboard.mocks';
import { REACT_APP_CUSTOM_PORT } from 'Constant/constant';

// We want to disable all forms of caching so that we do not need to define a custom merge function in testing for the network requests
const defaultOptions: DefaultOptions = {
Expand Down Expand Up @@ -45,11 +44,10 @@ async function wait(ms = 500): Promise<void> {

describe('Testing Event Dashboard Screen', () => {
beforeEach(() => {
const url = `http://localhost:${REACT_APP_CUSTOM_PORT}/event/event123`;
global.window = Object.create(window);
Object.defineProperty(window, 'location', {
value: {
href: url,
href: `http://localhost:${process.env.PORT}/event/event123`,
},
writable: true,
});
Expand Down
5 changes: 2 additions & 3 deletions src/screens/LoginPage/LoginPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,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 @@ -124,7 +123,7 @@ describe('Talawa-API server fetch check', () => {
);
});

expect(fetch).toHaveBeenCalledWith(BACKEND_URL);
expect(fetch).toHaveBeenCalledWith('http://localhost:4000/graphql/');
});

test('displays warning message when resource loading fails', async () => {
Expand All @@ -145,7 +144,7 @@ describe('Talawa-API server fetch check', () => {
);
});

expect(fetch).toHaveBeenCalledWith(BACKEND_URL);
expect(fetch).toHaveBeenCalledWith('http://localhost:4000/graphql/');
});
});

Expand Down
9 changes: 3 additions & 6 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,7 +129,8 @@ function loginPage(): JSX.Element {
useEffect(() => {
async function loadResource(): Promise<void> {
try {
await fetch(BACKEND_URL as string);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const response = await fetch('http://localhost:4000/graphql/');
} catch (error: any) {
/* istanbul ignore next */
errorHandler(t, error);
Expand Down
3 changes: 1 addition & 2 deletions src/screens/UserPortal/Home/Home.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import * as getOrganizationId from 'utils/getOrganizationId';
import { CREATE_POST_MUTATION } from 'GraphQl/Mutations/mutations';
import { toast } from 'react-toastify';
import dayjs from 'dayjs';
import { REACT_APP_CUSTOM_PORT } from 'Constant/constant';

jest.mock('react-toastify', () => ({
toast: {
Expand Down Expand Up @@ -216,7 +215,7 @@ async function wait(ms = 100): Promise<void> {
}

beforeEach(() => {
const url = `http://localhost:${REACT_APP_CUSTOM_PORT}/user/organization/id=orgId`;
const url = `http://localhost:${process.env.PORT}/user/organization/id=orgId`;
Object.defineProperty(window, 'location', {
value: {
href: url,
Expand Down
5 changes: 2 additions & 3 deletions src/screens/UserPortal/UserLoginPage/UserLoginPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,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 @@ -124,7 +123,7 @@ describe('Talawa-API server fetch check', () => {
);
});

expect(fetch).toHaveBeenCalledWith(BACKEND_URL);
expect(fetch).toHaveBeenCalledWith('http://localhost:4000/graphql/');
});

test('displays warning message when resource loading fails', async () => {
Expand All @@ -145,7 +144,7 @@ describe('Talawa-API server fetch check', () => {
);
});

expect(fetch).toHaveBeenCalledWith(BACKEND_URL);
expect(fetch).toHaveBeenCalledWith('http://localhost:4000/graphql/');
});
});

Expand Down
9 changes: 3 additions & 6 deletions src/screens/UserPortal/UserLoginPage/UserLoginPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,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 @@ -87,7 +83,8 @@ function loginPage(): JSX.Element {
useEffect(() => {
async function loadResource(): Promise<void> {
try {
await fetch(BACKEND_URL as string);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const response = await fetch('http://localhost:4000/graphql/');
} catch (error: any) {
/* istanbul ignore next */
errorHandler(t, error);
Expand Down

0 comments on commit 41c8190

Please sign in to comment.