feat(auth): create logout api call with basic test coverage and msw mock

This commit is contained in:
Ilia Mashkov
2026-03-17 10:14:57 +03:00
parent 2f863bc5ba
commit 638e198d02
6 changed files with 47 additions and 0 deletions

View File

@@ -1,2 +1,3 @@
export * from "./login"; export * from "./login";
export * from "./register"; export * from "./register";
export * from "./logout";

View File

@@ -0,0 +1 @@
export const LOGOUT_API_ROUTE = "auth/logout";

View File

@@ -0,0 +1,2 @@
export { logout } from "./logout";
export { LOGOUT_API_ROUTE } from "./constants";

View File

@@ -0,0 +1,12 @@
import { http, HttpResponse } from "msw";
import { BASE_URL } from "shared/config";
import { LOGOUT_API_ROUTE } from "./constants";
const LOGOUT_URL = `${BASE_URL}/${LOGOUT_API_ROUTE}`;
/**
* Msw interceptor. Mocks the logout endpoint response.
*/
export const logoutMock = http.post(LOGOUT_URL, () => {
return new HttpResponse(null, { status: 204 });
});

View File

@@ -0,0 +1,19 @@
import { setupServer } from "msw/node";
import { logout } from "./logout";
import { logoutMock } from "./logout.mock";
const server = setupServer(logoutMock);
describe("logout", () => {
beforeAll(() => server.listen({ onUnhandledRequest: "error" }));
afterEach(() => server.resetHandlers());
afterAll(() => server.close());
describe("happy path", () => {
it("resolves without a value", async () => {
const result = await logout();
expect(result).toBeUndefined();
});
});
});

View File

@@ -0,0 +1,12 @@
import { api } from "../../../api";
import { LOGOUT_API_ROUTE } from "./constants";
/**
* Logs out the currently authenticated user.
* async/await is used here intentionally to discard the ky Response and return void.
*
* @returns A promise that resolves when the session is terminated.
*/
export async function logout(): Promise<void> {
await api.post(LOGOUT_API_ROUTE);
}