Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Revert "Replace all hard coded localhosts with env constant variables"" #1521

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: 1 addition & 0 deletions src/Constant/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ 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: 3 additions & 1 deletion src/screens/EventDashboard/EventDashboard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ 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 @@ -44,10 +45,11 @@ 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: `http://localhost:${process.env.PORT}/event/event123`,
href: url,
},
writable: true,
});
Expand Down
5 changes: 3 additions & 2 deletions src/screens/LoginPage/LoginPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ 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 @@ -123,7 +124,7 @@ describe('Talawa-API server fetch check', () => {
);
});

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

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

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

Expand Down
9 changes: 6 additions & 3 deletions src/screens/LoginPage/LoginPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ import {
YoutubeLogo,
} from 'assets/svgs/social-icons';

import { REACT_APP_USE_RECAPTCHA, RECAPTCHA_SITE_KEY } from 'Constant/constant';
import {
REACT_APP_USE_RECAPTCHA,
RECAPTCHA_SITE_KEY,
BACKEND_URL,
} from 'Constant/constant';
import {
LOGIN_MUTATION,
RECAPTCHA_MUTATION,
Expand Down Expand Up @@ -129,8 +133,7 @@ function loginPage(): JSX.Element {
useEffect(() => {
async function loadResource(): Promise<void> {
try {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const response = await fetch('http://localhost:4000/graphql/');
await fetch(BACKEND_URL as string);
} catch (error: any) {
/* istanbul ignore next */
errorHandler(t, error);
Expand Down
3 changes: 2 additions & 1 deletion src/screens/UserPortal/Home/Home.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ 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 @@ -215,7 +216,7 @@ async function wait(ms = 100): Promise<void> {
}

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

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

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

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

Expand Down
9 changes: 6 additions & 3 deletions src/screens/UserPortal/UserLoginPage/UserLoginPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ import {
YoutubeLogo,
} from 'assets/svgs/social-icons';

import { REACT_APP_USE_RECAPTCHA, RECAPTCHA_SITE_KEY } from 'Constant/constant';
import {
REACT_APP_USE_RECAPTCHA,
RECAPTCHA_SITE_KEY,
BACKEND_URL,
} from 'Constant/constant';
import {
LOGIN_MUTATION,
RECAPTCHA_MUTATION,
Expand Down Expand Up @@ -83,8 +87,7 @@ function loginPage(): JSX.Element {
useEffect(() => {
async function loadResource(): Promise<void> {
try {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const response = await fetch('http://localhost:4000/graphql/');
await fetch(BACKEND_URL as string);
} catch (error: any) {
/* istanbul ignore next */
errorHandler(t, error);
Expand Down
Loading