-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Configure test workflow for client (#12)
* Configure test workflow for client Verified that the test file naming conventions are followed, allowing for proper detection of test cases across the project. * Resolve test issues by mocking useUserStore and removing updatedAt property - Added a mock for `useUserStore` to resolve test failures and ensure consistent behavior during testing. - Removed the `updatedAt` property from the `UserDTO` as it is currently not needed, simplifying the data model and improving test reliability. - Updated related test cases to reflect these changes and maintain coverage.
- Loading branch information
1 parent
0b42037
commit 4a4e836
Showing
6 changed files
with
70 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Client Test Workflow | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
test: | ||
name: Run Client Tests | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 18 | ||
|
||
- name: Install dependencies | ||
run: | | ||
cd client | ||
npm install | ||
- name: Run vitest | ||
run: | | ||
cd client | ||
npm run test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import { render } from "@testing-library/react"; | |
import "@testing-library/jest-dom"; | ||
|
||
import { useAuthStore } from "@/lib/stores/auth-store"; | ||
import { useUserStore } from "@/lib/stores/user-store"; | ||
import { AppRoutes } from "@/constants/routes"; | ||
|
||
import PrivateGuard from "./private-guard"; | ||
|
@@ -20,11 +21,27 @@ vi.mock("@/lib/stores/auth-store", () => ({ | |
}), | ||
})); | ||
|
||
vi.mock("@/lib/stores/user-store", () => ({ | ||
useUserStore: vi.fn().mockReturnValueOnce({ | ||
setUser: vi.fn(), | ||
}), | ||
})); | ||
|
||
vi.mock("@tanstack/react-query", () => ({ | ||
useQuery: vi.fn().mockReturnValueOnce({ | ||
isLoading: false, | ||
isError: false, | ||
isSuccess: false, | ||
data: { | ||
user: { | ||
id: "abc123", | ||
username: "Test", | ||
email_address: "[email protected]", | ||
last_signed_in: new Date(), | ||
is_verified: false, | ||
created_at: new Date(), | ||
}, | ||
}, | ||
}), | ||
})); | ||
|
||
|
@@ -60,6 +77,10 @@ describe("Private Guard", () => { | |
initialEntries: [AppRoutes.Root], | ||
}); | ||
|
||
(useUserStore as unknown as Mock).mockRejectedValueOnce({ | ||
setUser: vi.fn(), | ||
}); | ||
|
||
(useAuthStore as unknown as Mock).mockReturnValueOnce({ | ||
authenticated: true, | ||
setAuthorized: vi.fn(), | ||
|
@@ -69,6 +90,9 @@ describe("Private Guard", () => { | |
isError: true, | ||
isLoading: false, | ||
isSuccess: false, | ||
data: { | ||
user: undefined, | ||
}, | ||
}); | ||
|
||
render(<RouterProvider router={router} />); | ||
|
@@ -81,6 +105,10 @@ describe("Private Guard", () => { | |
initialEntries: [AppRoutes.Root], | ||
}); | ||
|
||
(useUserStore as unknown as Mock).mockReturnValueOnce({ | ||
setUser: vi.fn(), | ||
}); | ||
|
||
(useAuthStore as unknown as Mock).mockReturnValueOnce({ | ||
authorized: true, | ||
setAuthorized: vi.fn(), | ||
|
@@ -90,6 +118,9 @@ describe("Private Guard", () => { | |
isError: false, | ||
isLoading: false, | ||
isSuccess: true, | ||
data: { | ||
user: undefined, | ||
}, | ||
}); | ||
|
||
render(<RouterProvider router={router} />); | ||
|
@@ -102,6 +133,10 @@ describe("Private Guard", () => { | |
initialEntries: [AppRoutes.Root], | ||
}); | ||
|
||
(useUserStore as unknown as Mock).mockRejectedValueOnce({ | ||
useUser: vi.fn(), | ||
}); | ||
|
||
(useAuthStore as unknown as Mock).mockReturnValueOnce({ | ||
authorized: true, | ||
setAuthorized: vi.fn(), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,4 @@ export type UserDTO = { | |
last_signed_in: Date; | ||
is_verified: boolean; | ||
created_at: Date; | ||
updated_at: Date; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters