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

This commit is contained in:
Ilia Mashkov
2026-03-17 10:00:51 +03:00
parent a36922e1c7
commit 9302013632
7 changed files with 89 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
import { http, HttpResponse } from "msw";
import type { AuthData } from "../../../model/types/service";
import { BASE_URL } from "shared/config";
import {
LOGIN_API_ROUTE,
MOCK_EMAIL,
MOCK_PASSWORD,
MOCK_TOKEN,
} from "./constants";
const LOGIN_URL = `${BASE_URL}/${LOGIN_API_ROUTE}`;
/**
* Msw interceptor. Mocks the login endpoint response.
*/
export const loginMock = http.post(LOGIN_URL, async ({ request }) => {
const { email, password } = (await request.json()) as AuthData;
if (email === MOCK_EMAIL && password === MOCK_PASSWORD) {
return HttpResponse.json({
accessToken: MOCK_TOKEN,
user: { id: "1", email },
});
}
return HttpResponse.json({ message: "Invalid credentials" }, { status: 401 });
});