diff --git a/backend/code-execution-service/tests/codeExecutionRoutes.spec.ts b/backend/code-execution-service/tests/codeExecutionRoutes.spec.ts index 81996aef95..3bbe293041 100644 --- a/backend/code-execution-service/tests/codeExecutionRoutes.spec.ts +++ b/backend/code-execution-service/tests/codeExecutionRoutes.spec.ts @@ -1,5 +1,5 @@ import supertest from "supertest"; -import app from "../app"; +import app from "../src/app"; import { ERROR_MISSING_REQUIRED_FIELDS_MESSAGE, ERROR_UNSUPPORTED_LANGUAGE_MESSAGE, diff --git a/frontend/src/components/Navbar/Navbar.test.tsx b/frontend/src/components/Navbar/Navbar.test.tsx index 0f4203d4d4..3f6ee8b21e 100644 --- a/frontend/src/components/Navbar/Navbar.test.tsx +++ b/frontend/src/components/Navbar/Navbar.test.tsx @@ -8,6 +8,37 @@ import { MemoryRouter } from "react-router-dom"; jest.mock("axios"); +jest.mock("../../utils/api", () => ({ + getUserUrl: jest.fn().mockReturnValue("http://localhost:3001/api"), + getQuestionsUrl: jest + .fn() + .mockReturnValue("http://localhost:3000/api/questions"), + getCodeExecutionUrl: jest + .fn() + .mockReturnValue("http://localhost:3004/api/run"), + getQnHistoriesUrl: jest + .fn() + .mockReturnValue("http://localhost:3006/api/qnhistories"), +})); + +jest.mock("../../utils/matchSocket", () => ({ + getMatchSocketUrl: jest.fn().mockReturnValue("http://localhost:3002"), +})); + +jest.mock("../../utils/collabSocket", () => ({ + getCollabSocketUrl: jest.fn().mockReturnValue("http://localhost:3003"), +})); + +jest.mock("../../utils/communicationSocket", () => ({ + getCommunicationSocketUrl: jest.fn().mockReturnValue("http://localhost:3005"), +})); + +jest.mock("y-protocols/awareness.js", () => { + return { + Awareness: jest.fn(), + }; +}); + const mockedAxios = axios as jest.Mocked; const mockUseNavigate = jest.fn(); diff --git a/frontend/src/utils/api.ts b/frontend/src/utils/api.ts index 410f668de7..f00e249098 100644 --- a/frontend/src/utils/api.ts +++ b/frontend/src/utils/api.ts @@ -1,14 +1,33 @@ import axios from "axios"; -const usersUrl = - import.meta.env.VITE_USER_SERVICE_URL ?? "http://localhost:3001/api"; -const questionsUrl = - import.meta.env.VITE_QN_SERVICE_URL ?? "http://localhost:3000/api/questions"; -const codeExecutionUrl = - import.meta.env.VITE_CODE_EXEC_SERVICE_URL ?? "http://localhost:3004/api/run"; -const qnHistoriesUrl = - import.meta.env.VITE_QN_HIST_SERVICE_URL ?? - "http://localhost:3006/api/qnhistories"; +const getUserUrl = () => { + return import.meta.env.VITE_USER_SERVICE_URL ?? "http://localhost:3001/api"; +}; + +const getQuestionsUrl = () => { + return ( + import.meta.env.VITE_QN_SERVICE_URL ?? "http://localhost:3000/api/questions" + ); +}; + +const getCodeExecutionUrl = () => { + return ( + import.meta.env.VITE_CODE_EXEC_SERVICE_URL ?? + "http://localhost:3004/api/run" + ); +}; + +const getQnHistoriesUrl = () => { + return ( + import.meta.env.VITE_QN_HIST_SERVICE_URL ?? + "http://localhost:3006/api/qnhistories" + ); +}; + +const usersUrl = getUserUrl(); +const questionsUrl = getQuestionsUrl(); +const codeExecutionUrl = getCodeExecutionUrl(); +const qnHistoriesUrl = getQnHistoriesUrl(); export const questionClient = axios.create({ baseURL: questionsUrl, diff --git a/frontend/src/utils/collabSocket.ts b/frontend/src/utils/collabSocket.ts index a3bdf58f13..f58f9ceeb0 100644 --- a/frontend/src/utils/collabSocket.ts +++ b/frontend/src/utils/collabSocket.ts @@ -27,8 +27,11 @@ export enum CollabEvents { SOCKET_RECONNECT_FAILED = "reconnect_failed", } -const COLLAB_SOCKET_URL = - import.meta.env.VITE_COLLAB_SERVICE_URL ?? "http://localhost:3003"; +const getCollabSocketUrl = () => { + return import.meta.env.VITE_COLLAB_SERVICE_URL ?? "http://localhost:3003"; +}; + +const COLLAB_SOCKET_URL = getCollabSocketUrl(); export const createCollabSocket = () => io(COLLAB_SOCKET_URL, { diff --git a/frontend/src/utils/communicationSocket.ts b/frontend/src/utils/communicationSocket.ts index e1ef0dbf8b..00c955c1ba 100644 --- a/frontend/src/utils/communicationSocket.ts +++ b/frontend/src/utils/communicationSocket.ts @@ -16,8 +16,11 @@ export enum CommunicationEvents { DISCONNECTED = "disconnected", } -const COMMUNICATION_SOCKET_URL = - import.meta.env.VITE_COMM_SERVICE_URL ?? "http://localhost:3005"; +const getCommunicationSocketUrl = () => { + return import.meta.env.VITE_COMM_SERVICE_URL ?? "http://localhost:3005"; +}; + +const COMMUNICATION_SOCKET_URL = getCommunicationSocketUrl(); export const createCommunicationSocket = () => io(COMMUNICATION_SOCKET_URL, { diff --git a/frontend/src/utils/matchSocket.ts b/frontend/src/utils/matchSocket.ts index 1322283342..ab28c43bae 100644 --- a/frontend/src/utils/matchSocket.ts +++ b/frontend/src/utils/matchSocket.ts @@ -27,8 +27,11 @@ export enum MatchEvents { SOCKET_RECONNECT_FAILED = "reconnect_failed", } -const MATCH_SOCKET_URL = - import.meta.env.VITE_MATCH_SERVICE_URL ?? "http://localhost:3002"; +const getMatchSocketUrl = () => { + return import.meta.env.VITE_MATCH_SERVICE_URL ?? "http://localhost:3002"; +}; + +const MATCH_SOCKET_URL = getMatchSocketUrl(); export const createMatchSocket = () => io(MATCH_SOCKET_URL, {