feat(auth): create login api call with basic test coverage and msw mock
This commit is contained in:
27
src/features/auth/api/calls/login/login.mock.ts
Normal file
27
src/features/auth/api/calls/login/login.mock.ts
Normal 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 });
|
||||
});
|
||||
Reference in New Issue
Block a user