diff --git a/README.md b/README.md index 920c104..b5dcdae 100644 --- a/README.md +++ b/README.md @@ -5,20 +5,16 @@ This template provides a minimal setup to get React working in Vite with HMR and ## Setup Guide This project was set up with NodeJS v20.11.0 LTS with yarn. - -1. Change directory to - ```shell - cd atlas-3-frontend - ``` -2. Install packages +1. Install packages ```shell yarn ``` -3. Create a file `.env.development.local` in root folder with the following information +2. Create a file `.env.development.local` in root folder with the following information ```text VITE_IGNORE_MSW=false ``` If you would like to ignore mock service worker, set it to `true`. +3. Create another file `.env.test.local` in root folder with same content as above 4. Run the development server ```shell yarn dev diff --git a/src/api/authentication.ts b/src/api/authentication.ts index ceaa294..9ebe34f 100644 --- a/src/api/authentication.ts +++ b/src/api/authentication.ts @@ -1,10 +1,10 @@ -import resolveURL, { apiURL } from "./fetch"; +import resolveURL from "./fetch"; -const BASE_URL = resolveURL(apiURL); -const LOGIN_URL = `${BASE_URL}/auth/login`; -const LOGOUT_URL = `${BASE_URL}/auth/logout`; +const LOGIN_URL = resolveURL('/auth/login'); +const LOGOUT_URL = resolveURL('/auth/logout'); +const GET_CSRF_URL = resolveURL('/auth/csrf'); -export const signIn = async (username: string, password: string): Promise => { +export const signIn = async (username: string, password: string) => { const response = await fetch(LOGIN_URL, { method: 'POST', headers: { @@ -45,7 +45,7 @@ export const signOut = async (): Promise => { }; export const getCSRF = async (): Promise => { - const response = await fetch(BASE_URL, { + const response = await fetch(GET_CSRF_URL, { method: "POST", credentials: "include", headers: { diff --git a/src/api/fetch.ts b/src/api/fetch.ts index 084600e..250dd63 100644 --- a/src/api/fetch.ts +++ b/src/api/fetch.ts @@ -1,3 +1,4 @@ + const setApiURL = () => { if (import.meta.env.DEV) { return import.meta.env.VITE_IGNORE_MSW.toLowerCase() === "true" ? "http://localhost:8000" : "http://localhost:5173" diff --git a/tests/authentication/auth.test.tsx b/tests/authentication/auth.test.tsx index 7bb4628..14037ec 100644 --- a/tests/authentication/auth.test.tsx +++ b/tests/authentication/auth.test.tsx @@ -6,9 +6,8 @@ describe("authentication helper functions", () => { test("should get csrf token", async () => { const response: Response = await getCSRF() - expect(response.headers).toBe({ - 'Set-Cookie': mockCSRFToken - }) + expect(response.headers.has('Set-Cookie')) + expect(response.headers.get('Set-Cookie')).toBe(mockCSRFToken) }) test("should be able to sign in", async () => {