28 lines
748 B
TypeScript
28 lines
748 B
TypeScript
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 });
|
|
});
|