-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(logout): add logout button and logic with error handling
- Added a logout button in the header. - added `useLogoutService` to call the `/logout` endpoint. - Added error handling with `useErrorToast` to display error messages on logout failure. - Redirects user to the home page on successful logout. - adds unit tests RISDEV-5806
- Loading branch information
Showing
4 changed files
with
108 additions
and
3 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
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { describe, it, expect, vi, beforeEach } from "vitest" | ||
|
||
describe("logoutService", () => { | ||
beforeEach(() => { | ||
vi.resetModules() | ||
vi.resetAllMocks() | ||
}) | ||
|
||
it("calls the /logout endpoint with POST method", async () => { | ||
const useFetchMock = { | ||
error: { value: null }, | ||
isFetching: { value: false }, | ||
} | ||
|
||
vi.doMock("@/services/apiService", () => ({ | ||
useApiFetch: vi.fn().mockReturnValue(useFetchMock), | ||
})) | ||
|
||
const { useLogoutService } = await import("@/services/logoutService") | ||
|
||
const result = useLogoutService() | ||
|
||
expect(result.error.value).toBe(null) | ||
expect(result.isFetching.value).toBe(false) | ||
|
||
const { useApiFetch } = await import("@/services/apiService") | ||
expect(useApiFetch).toHaveBeenCalledWith("/logout", { | ||
method: "POST", | ||
}) | ||
}) | ||
}) |
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,13 @@ | ||
import { UseFetchReturn } from "@vueuse/core" | ||
import { useApiFetch } from "@/services/apiService" | ||
|
||
/** | ||
* Service to log out the user. | ||
* | ||
* Calls the backend `/logout` endpoint. | ||
*/ | ||
export function useLogoutService(): UseFetchReturn<void> { | ||
return useApiFetch("/logout", { | ||
method: "POST", | ||
}) | ||
} |