From f871392ce4b34ec4a84939ffbb428c04bd6431eb Mon Sep 17 00:00:00 2001 From: Guan Quan <76832850+guanquann@users.noreply.github.com> Date: Wed, 13 Nov 2024 16:14:12 +0800 Subject: [PATCH 1/3] Update test --- .../code-execution-service/tests/codeExecutionRoutes.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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, From 7d2f7fe26c3810c115b56d028495e6bf571079fd Mon Sep 17 00:00:00 2001 From: Guan Quan <76832850+guanquann@users.noreply.github.com> Date: Wed, 13 Nov 2024 16:53:20 +0800 Subject: [PATCH 2/3] Fix test --- .../src/components/Navbar/Navbar.test.tsx | 25 ++++++++++++++ frontend/src/utils/api.ts | 33 ++++++++++++++----- frontend/src/utils/collabSocket.ts | 7 ++-- frontend/src/utils/communicationSocket.ts | 7 ++-- frontend/src/utils/matchSocket.ts | 7 ++-- 5 files changed, 64 insertions(+), 15 deletions(-) diff --git a/frontend/src/components/Navbar/Navbar.test.tsx b/frontend/src/components/Navbar/Navbar.test.tsx index 454b1d0315..c556bf53bb 100644 --- a/frontend/src/components/Navbar/Navbar.test.tsx +++ b/frontend/src/components/Navbar/Navbar.test.tsx @@ -8,6 +8,31 @@ 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"), +})); + 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..73322406d8 100644 --- a/frontend/src/utils/api.ts +++ b/frontend/src/utils/api.ts @@ -1,14 +1,29 @@ 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.SOME_ENV_VAR_HERE ?? "http://localhost:3001/api"; +}; + +const getQuestionsUrl = () => { + return ( + import.meta.env.SOME_ENV_VAR_HERE ?? "http://localhost:3000/api/questions" + ); +}; + +const getCodeExecutionUrl = () => { + return import.meta.env.SOME_ENV_VAR_HERE ?? "http://localhost:3004/api/run"; +}; + +const getQnHistoriesUrl = () => { + return ( + import.meta.env.SOME_ENV_VAR_HERE ?? "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 7d6461c201..3c1be72be7 100644 --- a/frontend/src/utils/collabSocket.ts +++ b/frontend/src/utils/collabSocket.ts @@ -38,8 +38,11 @@ export type CollabSessionData = { awareness: Awareness; }; -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 collabSocket = io(COLLAB_SOCKET_URL, { reconnectionAttempts: 5, diff --git a/frontend/src/utils/communicationSocket.ts b/frontend/src/utils/communicationSocket.ts index 8356102b48..395ad6541a 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 communicationSocket = io(COMMUNICATION_SOCKET_URL, { reconnectionAttempts: 3, diff --git a/frontend/src/utils/matchSocket.ts b/frontend/src/utils/matchSocket.ts index 754c96157c..0951e6e877 100644 --- a/frontend/src/utils/matchSocket.ts +++ b/frontend/src/utils/matchSocket.ts @@ -1,8 +1,11 @@ import { io } from "socket.io-client"; import { getToken } from "./token"; -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 matchSocket = io(MATCH_SOCKET_URL, { reconnectionAttempts: 3, From 30db5ca66b0d7b8cbf27b8c2bedd73f725311f08 Mon Sep 17 00:00:00 2001 From: Guan Quan <76832850+guanquann@users.noreply.github.com> Date: Wed, 13 Nov 2024 17:07:40 +0800 Subject: [PATCH 3/3] Update api --- frontend/src/utils/api.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/frontend/src/utils/api.ts b/frontend/src/utils/api.ts index 73322406d8..f00e249098 100644 --- a/frontend/src/utils/api.ts +++ b/frontend/src/utils/api.ts @@ -1,22 +1,26 @@ import axios from "axios"; const getUserUrl = () => { - return import.meta.env.SOME_ENV_VAR_HERE ?? "http://localhost:3001/api"; + return import.meta.env.VITE_USER_SERVICE_URL ?? "http://localhost:3001/api"; }; const getQuestionsUrl = () => { return ( - import.meta.env.SOME_ENV_VAR_HERE ?? "http://localhost:3000/api/questions" + import.meta.env.VITE_QN_SERVICE_URL ?? "http://localhost:3000/api/questions" ); }; const getCodeExecutionUrl = () => { - return import.meta.env.SOME_ENV_VAR_HERE ?? "http://localhost:3004/api/run"; + return ( + import.meta.env.VITE_CODE_EXEC_SERVICE_URL ?? + "http://localhost:3004/api/run" + ); }; const getQnHistoriesUrl = () => { return ( - import.meta.env.SOME_ENV_VAR_HERE ?? "http://localhost:3006/api/qnhistories" + import.meta.env.VITE_QN_HIST_SERVICE_URL ?? + "http://localhost:3006/api/qnhistories" ); };