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

This commit is contained in:
Ilia Mashkov
2026-03-17 10:08:38 +03:00
parent 701dc981d2
commit 2f863bc5ba
6 changed files with 76 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
import { http, HttpResponse } from "msw";
import type { AuthData } from "../../../model/types/service";
import { BASE_URL } from "shared/config";
import { REGISTER_API_ROUTE, MOCK_EMAIL, MOCK_TOKEN } from "./constants";
const REGISTER_URL = `${BASE_URL}/${REGISTER_API_ROUTE}`;
/**
* Msw interceptor. Mocks the register endpoint response.
*/
export const registerMock = http.post(REGISTER_URL, async ({ request }) => {
const { email } = (await request.json()) as AuthData;
if (email === MOCK_EMAIL) {
return HttpResponse.json(
{ message: "User already exists" },
{ status: 409 },
);
}
return HttpResponse.json({
accessToken: MOCK_TOKEN,
user: { id: "2", email },
});
});