diff --git a/src/features/auth/api/calls/index.ts b/src/features/auth/api/calls/index.ts index b6bf91f..ce51756 100644 --- a/src/features/auth/api/calls/index.ts +++ b/src/features/auth/api/calls/index.ts @@ -1,2 +1,3 @@ export * from "./login"; export * from "./register"; +export * from "./logout"; diff --git a/src/features/auth/api/calls/logout/constants.ts b/src/features/auth/api/calls/logout/constants.ts new file mode 100644 index 0000000..24ee95e --- /dev/null +++ b/src/features/auth/api/calls/logout/constants.ts @@ -0,0 +1 @@ +export const LOGOUT_API_ROUTE = "auth/logout"; diff --git a/src/features/auth/api/calls/logout/index.ts b/src/features/auth/api/calls/logout/index.ts new file mode 100644 index 0000000..a81b5b9 --- /dev/null +++ b/src/features/auth/api/calls/logout/index.ts @@ -0,0 +1,2 @@ +export { logout } from "./logout"; +export { LOGOUT_API_ROUTE } from "./constants"; diff --git a/src/features/auth/api/calls/logout/logout.mock.ts b/src/features/auth/api/calls/logout/logout.mock.ts new file mode 100644 index 0000000..1515d04 --- /dev/null +++ b/src/features/auth/api/calls/logout/logout.mock.ts @@ -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 }); +}); diff --git a/src/features/auth/api/calls/logout/logout.spec.ts b/src/features/auth/api/calls/logout/logout.spec.ts new file mode 100644 index 0000000..eb28c4d --- /dev/null +++ b/src/features/auth/api/calls/logout/logout.spec.ts @@ -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(); + }); + }); +}); diff --git a/src/features/auth/api/calls/logout/logout.ts b/src/features/auth/api/calls/logout/logout.ts new file mode 100644 index 0000000..f418d80 --- /dev/null +++ b/src/features/auth/api/calls/logout/logout.ts @@ -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 { + await api.post(LOGOUT_API_ROUTE); +}