File tree Expand file tree Collapse file tree 5 files changed +64
-15
lines changed Expand file tree Collapse file tree 5 files changed +64
-15
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,31 @@ import { MemoryRouter } from "react-router-dom";
8
8
9
9
jest . mock ( "axios" ) ;
10
10
11
+ jest . mock ( "../../utils/api" , ( ) => ( {
12
+ getUserUrl : jest . fn ( ) . mockReturnValue ( "http://localhost:3001/api" ) ,
13
+ getQuestionsUrl : jest
14
+ . fn ( )
15
+ . mockReturnValue ( "http://localhost:3000/api/questions" ) ,
16
+ getCodeExecutionUrl : jest
17
+ . fn ( )
18
+ . mockReturnValue ( "http://localhost:3004/api/run" ) ,
19
+ getQnHistoriesUrl : jest
20
+ . fn ( )
21
+ . mockReturnValue ( "http://localhost:3006/api/qnhistories" ) ,
22
+ } ) ) ;
23
+
24
+ jest . mock ( "../../utils/matchSocket" , ( ) => ( {
25
+ getMatchSocketUrl : jest . fn ( ) . mockReturnValue ( "http://localhost:3002" ) ,
26
+ } ) ) ;
27
+
28
+ jest . mock ( "../../utils/collabSocket" , ( ) => ( {
29
+ getCollabSocketUrl : jest . fn ( ) . mockReturnValue ( "http://localhost:3003" ) ,
30
+ } ) ) ;
31
+
32
+ jest . mock ( "../../utils/communicationSocket" , ( ) => ( {
33
+ getCommunicationSocketUrl : jest . fn ( ) . mockReturnValue ( "http://localhost:3005" ) ,
34
+ } ) ) ;
35
+
11
36
const mockedAxios = axios as jest . Mocked < typeof axios > ;
12
37
13
38
const mockUseNavigate = jest . fn ( ) ;
Original file line number Diff line number Diff line change 1
1
import axios from "axios" ;
2
2
3
- const usersUrl =
4
- import . meta. env . VITE_USER_SERVICE_URL ?? "http://localhost:3001/api" ;
5
- const questionsUrl =
6
- import . meta. env . VITE_QN_SERVICE_URL ?? "http://localhost:3000/api/questions" ;
7
- const codeExecutionUrl =
8
- import . meta. env . VITE_CODE_EXEC_SERVICE_URL ?? "http://localhost:3004/api/run" ;
9
- const qnHistoriesUrl =
10
- import . meta. env . VITE_QN_HIST_SERVICE_URL ??
11
- "http://localhost:3006/api/qnhistories" ;
3
+ const getUserUrl = ( ) => {
4
+ return import . meta. env . SOME_ENV_VAR_HERE ?? "http://localhost:3001/api" ;
5
+ } ;
6
+
7
+ const getQuestionsUrl = ( ) => {
8
+ return (
9
+ import . meta. env . SOME_ENV_VAR_HERE ?? "http://localhost:3000/api/questions"
10
+ ) ;
11
+ } ;
12
+
13
+ const getCodeExecutionUrl = ( ) => {
14
+ return import . meta. env . SOME_ENV_VAR_HERE ?? "http://localhost:3004/api/run" ;
15
+ } ;
16
+
17
+ const getQnHistoriesUrl = ( ) => {
18
+ return (
19
+ import . meta. env . SOME_ENV_VAR_HERE ?? "http://localhost:3006/api/qnhistories"
20
+ ) ;
21
+ } ;
22
+
23
+ const usersUrl = getUserUrl ( ) ;
24
+ const questionsUrl = getQuestionsUrl ( ) ;
25
+ const codeExecutionUrl = getCodeExecutionUrl ( ) ;
26
+ const qnHistoriesUrl = getQnHistoriesUrl ( ) ;
12
27
13
28
export const questionClient = axios . create ( {
14
29
baseURL : questionsUrl ,
Original file line number Diff line number Diff line change @@ -38,8 +38,11 @@ export type CollabSessionData = {
38
38
awareness : Awareness ;
39
39
} ;
40
40
41
- const COLLAB_SOCKET_URL =
42
- import . meta. env . VITE_COLLAB_SERVICE_URL ?? "http://localhost:3003" ;
41
+ const getCollabSocketUrl = ( ) => {
42
+ return import . meta. env . VITE_COLLAB_SERVICE_URL ?? "http://localhost:3003" ;
43
+ } ;
44
+
45
+ const COLLAB_SOCKET_URL = getCollabSocketUrl ( ) ;
43
46
44
47
export const collabSocket = io ( COLLAB_SOCKET_URL , {
45
48
reconnectionAttempts : 5 ,
Original file line number Diff line number Diff line change @@ -16,8 +16,11 @@ export enum CommunicationEvents {
16
16
DISCONNECTED = "disconnected" ,
17
17
}
18
18
19
- const COMMUNICATION_SOCKET_URL =
20
- import . meta. env . VITE_COMM_SERVICE_URL ?? "http://localhost:3005" ;
19
+ const getCommunicationSocketUrl = ( ) => {
20
+ return import . meta. env . VITE_COMM_SERVICE_URL ?? "http://localhost:3005" ;
21
+ } ;
22
+
23
+ const COMMUNICATION_SOCKET_URL = getCommunicationSocketUrl ( ) ;
21
24
22
25
export const communicationSocket = io ( COMMUNICATION_SOCKET_URL , {
23
26
reconnectionAttempts : 3 ,
Original file line number Diff line number Diff line change 1
1
import { io } from "socket.io-client" ;
2
2
import { getToken } from "./token" ;
3
3
4
- const MATCH_SOCKET_URL =
5
- import . meta. env . VITE_MATCH_SERVICE_URL ?? "http://localhost:3002" ;
4
+ const getMatchSocketUrl = ( ) => {
5
+ return import . meta. env . VITE_MATCH_SERVICE_URL ?? "http://localhost:3002" ;
6
+ } ;
7
+
8
+ const MATCH_SOCKET_URL = getMatchSocketUrl ( ) ;
6
9
7
10
export const matchSocket = io ( MATCH_SOCKET_URL , {
8
11
reconnectionAttempts : 3 ,
You can’t perform that action at this time.
0 commit comments