feat(auth): create logout api call with basic test coverage and msw mock
This commit is contained in:
@@ -1,2 +1,3 @@
|
|||||||
export * from "./login";
|
export * from "./login";
|
||||||
export * from "./register";
|
export * from "./register";
|
||||||
|
export * from "./logout";
|
||||||
|
|||||||
1
src/features/auth/api/calls/logout/constants.ts
Normal file
1
src/features/auth/api/calls/logout/constants.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export const LOGOUT_API_ROUTE = "auth/logout";
|
||||||
2
src/features/auth/api/calls/logout/index.ts
Normal file
2
src/features/auth/api/calls/logout/index.ts
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
export { logout } from "./logout";
|
||||||
|
export { LOGOUT_API_ROUTE } from "./constants";
|
||||||
12
src/features/auth/api/calls/logout/logout.mock.ts
Normal file
12
src/features/auth/api/calls/logout/logout.mock.ts
Normal 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 });
|
||||||
|
});
|
||||||
19
src/features/auth/api/calls/logout/logout.spec.ts
Normal file
19
src/features/auth/api/calls/logout/logout.spec.ts
Normal 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();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
12
src/features/auth/api/calls/logout/logout.ts
Normal file
12
src/features/auth/api/calls/logout/logout.ts
Normal 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);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user