From aef41e4bf83aaad6eddd6666a44fac119e63035f Mon Sep 17 00:00:00 2001 From: Jakub Wilk Date: Mon, 4 Nov 2024 13:38:53 +0100 Subject: [PATCH] test: update test config --- apps/web/app/api/api-client.ts | 4 +++- apps/web/app/utils/mocks/handlers/auth.ts | 6 ++++++ apps/web/app/utils/mocks/handlers/course.ts | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/apps/web/app/api/api-client.ts b/apps/web/app/api/api-client.ts index 290d7c91..6db78717 100644 --- a/apps/web/app/api/api-client.ts +++ b/apps/web/app/api/api-client.ts @@ -1,6 +1,8 @@ import { useAuthStore } from "~/modules/Auth/authStore"; import { API } from "./generated-api"; +const isTestEnv = process.env.NODE_ENV === "test"; + export const ApiClient = new API({ baseURL: import.meta.env.VITE_API_URL, secure: true, @@ -13,7 +15,7 @@ ApiClient.instance.interceptors.request.use((config) => { config.url?.includes("/refresh") || config.url?.includes("/register"); - if (!isAuthEndpoint && !useAuthStore.getState().isLoggedIn) { + if (!isTestEnv && !isAuthEndpoint && !useAuthStore.getState().isLoggedIn) { const controller = new AbortController(); controller.abort(); config.signal = controller.signal; diff --git a/apps/web/app/utils/mocks/handlers/auth.ts b/apps/web/app/utils/mocks/handlers/auth.ts index 51b1f134..2fad02c2 100644 --- a/apps/web/app/utils/mocks/handlers/auth.ts +++ b/apps/web/app/utils/mocks/handlers/auth.ts @@ -34,4 +34,10 @@ export const handlers = [ http.get("/api/auth/current-user", () => { return HttpResponse.json(currentUser); }), + http.post("/api/auth/refresh", () => { + return HttpResponse.json({ + accessToken: "mock-access-token", + refreshToken: "mock-refresh-token", + }); + }), ]; diff --git a/apps/web/app/utils/mocks/handlers/course.ts b/apps/web/app/utils/mocks/handlers/course.ts index ec318966..8ad96b27 100644 --- a/apps/web/app/utils/mocks/handlers/course.ts +++ b/apps/web/app/utils/mocks/handlers/course.ts @@ -57,6 +57,7 @@ const availableCoursesHandler = withSearchParams( ); export const handlers = [ + http.get("/api/courses", availableCoursesHandler), http.get("/api/courses/available-courses", availableCoursesHandler), http.get("/api/courses/get-student-courses", () => { return HttpResponse.json(studentCourses);