Skip to content

Commit

Permalink
Merge pull request #131 from guanquann/readme
Browse files Browse the repository at this point in the history
Fix frontend test
  • Loading branch information
nicolelim02 authored Nov 13, 2024
2 parents bb20400 + eac5b8f commit d37b252
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
31 changes: 31 additions & 0 deletions frontend/src/components/Navbar/Navbar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof axios>;

const mockUseNavigate = jest.fn();
Expand Down
37 changes: 28 additions & 9 deletions frontend/src/utils/api.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
7 changes: 5 additions & 2 deletions frontend/src/utils/collabSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
7 changes: 5 additions & 2 deletions frontend/src/utils/communicationSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
7 changes: 5 additions & 2 deletions frontend/src/utils/matchSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down

0 comments on commit d37b252

Please sign in to comment.