26 lines
715 B
TypeScript
26 lines
715 B
TypeScript
|
|
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 },
|
||
|
|
});
|
||
|
|
});
|