Some checks failed
95 tests across 22 files covering all frontend modules: - API layer: client, auth - Components: BondDetails, Layout, PriceChart, ProtectedRoute, SearchBar, StockDetails - Context: AuthContext - Hooks: useAuth, useBond, useBondCandles, useSearch, useStock, useStockCandles, useStockDividends - Pages: BondPage, HomePage, LoginPage, ProfilePage, RegisterPage, StockPage Infrastructure: - vitest + @testing-library/react + MSW v2 with 13 API handlers - Co-located test files alongside source files - Test utilities: setup, server, factories, test-utils - BrowserRouter future flags for MemoryRouter test compatibility - Root test:frontend script for workspace-wide execution
53 lines
1.4 KiB
TypeScript
53 lines
1.4 KiB
TypeScript
import { request, setAccessToken } from './client';
|
|
import type { AuthResponse, UserResponse } from './responses';
|
|
|
|
export async function login(email: string, password: string) {
|
|
const result = await request<AuthResponse>('/api/v1/auth/login', undefined, {
|
|
method: 'POST',
|
|
body: { email, password },
|
|
skipAuth: true,
|
|
});
|
|
setAccessToken(result.data.accessToken);
|
|
return result.data;
|
|
}
|
|
|
|
export async function register(email: string, password: string, name?: string) {
|
|
const result = await request<AuthResponse>('/api/v1/auth/register', undefined, {
|
|
method: 'POST',
|
|
body: { email, password, name },
|
|
skipAuth: true,
|
|
});
|
|
setAccessToken(result.data.accessToken);
|
|
return result.data;
|
|
}
|
|
|
|
export async function refresh() {
|
|
const result = await request<AuthResponse>('/api/v1/auth/refresh', undefined, {
|
|
method: 'POST',
|
|
skipAuth: true,
|
|
});
|
|
setAccessToken(result.data.accessToken);
|
|
return result.data;
|
|
}
|
|
|
|
export async function logout() {
|
|
const result = await request<{ message: string }>('/api/v1/auth/logout', undefined, {
|
|
method: 'POST',
|
|
});
|
|
setAccessToken(null);
|
|
return result.data;
|
|
}
|
|
|
|
export async function getMe() {
|
|
const result = await request<UserResponse>('/api/v1/auth/me');
|
|
return result.data;
|
|
}
|
|
|
|
export async function updateProfile(data: { name?: string }) {
|
|
const result = await request<UserResponse>('/api/v1/auth/me', undefined, {
|
|
method: 'PATCH',
|
|
body: data,
|
|
});
|
|
return result.data;
|
|
}
|