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,29 @@
import { setupServer } from "msw/node";
import { login } from "./login";
import { loginMock } from "./login.mock";
import { MOCK_EMAIL, MOCK_PASSWORD } from "./constants";
const server = setupServer(loginMock);
describe("login", () => {
beforeAll(() => server.listen({ onUnhandledRequest: "error" }));
afterEach(() => server.resetHandlers());
afterAll(() => server.close());
describe("happy path", () => {
it("returns access token and user on valid credentials", async () => {
const result = await login({ email: MOCK_EMAIL, password: MOCK_PASSWORD });
expect(result.accessToken).toBe("mock.access.token");
expect(result.user).toEqual({ id: "1", email: MOCK_EMAIL });
});
});
describe("error cases", () => {
it("throws on invalid credentials", async () => {
await expect(
login({ email: "wrong@test.com", password: "wrong" }),
).rejects.toThrow();
});
});
});