feat: add tests for import polling, login page, money utilities, and query keys
- Implemented tests for import polling functionality, ensuring correct behavior for active and terminal import statuses. - Created tests for the login page, validating user interactions and error handling. - Added unit tests for money utility functions, covering parsing, formatting, and summation of monetary values. - Developed tests for query keys, ensuring proper scoping and invalidation roots. chore: setup testing environment and configuration - Added setup file for testing with Vitest and Testing Library. - Configured TypeScript and Vite for the frontend project. - Created Docker and Nginx configurations for local development and production environments. - Established a PostgreSQL initialization script for setting up application roles. docs: add README and environment configuration for infra - Included README for the infra directory, detailing local development setup and service descriptions. - Created an example environment configuration file for local development with placeholders for sensitive information.
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
import { apiClient } from './client'
|
||||
import type {
|
||||
AcceptInvitePayload,
|
||||
Account,
|
||||
BalancesReport,
|
||||
BudgetCategory,
|
||||
BudgetSummary,
|
||||
CashFlowMonth,
|
||||
CategorySpendItem,
|
||||
ConfirmImportPayload,
|
||||
CreateAccountPayload,
|
||||
CreateOperationPayload,
|
||||
ExportInfo,
|
||||
ImportDetail,
|
||||
ImportSummary,
|
||||
LoginPayload,
|
||||
Operation,
|
||||
OperationFilters,
|
||||
Page,
|
||||
PlanFactReport,
|
||||
PasswordResetPayload,
|
||||
SaveRowDecisionPayload,
|
||||
SpaceDeletionStatus,
|
||||
User,
|
||||
} from './types'
|
||||
|
||||
export const api = {
|
||||
auth: {
|
||||
me: () => apiClient.get<User>('/auth/me'),
|
||||
login: (payload: LoginPayload) => apiClient.post<User>('/auth/login', { json: payload }),
|
||||
logout: () => apiClient.post<void>('/auth/logout'),
|
||||
acceptInvite: (payload: AcceptInvitePayload) =>
|
||||
apiClient.post<User>('/auth/invitations/accept', { json: payload }),
|
||||
requestPasswordReset: (email: string) =>
|
||||
apiClient.post<{ accepted: boolean }>('/auth/password-reset', { json: { email } }),
|
||||
confirmPasswordReset: (payload: PasswordResetPayload) =>
|
||||
apiClient.post<User>('/auth/password-reset/confirm', { json: payload }),
|
||||
},
|
||||
accounts: {
|
||||
list: () => apiClient.get<Account[]>('/accounts'),
|
||||
create: (payload: CreateAccountPayload) =>
|
||||
apiClient.post<Account>('/accounts', { json: payload }),
|
||||
archive: (id: string) =>
|
||||
apiClient.patch<Account>(`/accounts/${id}`, { json: { status: 'archived' } }),
|
||||
},
|
||||
operations: {
|
||||
list: (filters: OperationFilters) =>
|
||||
apiClient.get<Page<Operation>>('/operations', { query: { ...filters } }),
|
||||
create: (payload: CreateOperationPayload) =>
|
||||
apiClient.post<Operation>('/operations', { json: payload }),
|
||||
void: (id: string, reason: string) =>
|
||||
apiClient.post<Operation>(`/operations/${id}/void`, { json: { reason } }),
|
||||
categorize: (id: string, categoryId: string) =>
|
||||
apiClient.patch<Operation>(`/operations/${id}`, { json: { categoryId } }),
|
||||
},
|
||||
budget: {
|
||||
summary: (month: string) =>
|
||||
apiClient.get<BudgetSummary>('/budget/summary', { query: { month } }),
|
||||
categories: (month: string) =>
|
||||
apiClient.get<BudgetCategory[]>('/budget/categories', { query: { month } }),
|
||||
updatePlan: (categoryId: string, month: string, plannedKopecks: number) =>
|
||||
apiClient.patch<BudgetCategory>(`/budget/categories/${categoryId}`, {
|
||||
json: { month, plannedKopecks },
|
||||
}),
|
||||
fund: (categoryId: string, month: string, amountKopecks: number) =>
|
||||
apiClient.post<BudgetCategory>(`/budget/categories/${categoryId}/fund`, {
|
||||
json: { month, amountKopecks },
|
||||
}),
|
||||
close: (month: string) => apiClient.post<BudgetSummary>('/budget/close', { json: { month } }),
|
||||
reopen: (month: string) => apiClient.post<BudgetSummary>('/budget/reopen', { json: { month } }),
|
||||
copyPrevious: (month: string) =>
|
||||
apiClient.post<BudgetSummary>('/budget/copy-previous', { json: { month } }),
|
||||
},
|
||||
imports: {
|
||||
list: () => apiClient.get<ImportSummary[]>('/imports'),
|
||||
get: (id: string) => apiClient.get<ImportDetail>(`/imports/${id}`),
|
||||
upload: (file: File, accountId: string) => {
|
||||
const formData = new FormData()
|
||||
formData.append('file', file)
|
||||
formData.append('accountId', accountId)
|
||||
return apiClient.post<ImportSummary>('/imports', { formData })
|
||||
},
|
||||
saveRowDecision: (id: string, rowId: string, payload: SaveRowDecisionPayload) =>
|
||||
apiClient.patch<ImportDetail>(`/imports/${id}/rows/${rowId}`, { json: payload }),
|
||||
confirm: (id: string, payload: ConfirmImportPayload) =>
|
||||
apiClient.post<ImportDetail>(`/imports/${id}/confirm`, { json: payload }),
|
||||
reparse: (id: string) => apiClient.post<ImportDetail>(`/imports/${id}/reparse`),
|
||||
revert: (id: string) => apiClient.post<ImportDetail>(`/imports/${id}/revert`),
|
||||
},
|
||||
analytics: {
|
||||
categorySpend: (from: string, to: string) =>
|
||||
apiClient.get<CategorySpendItem[]>('/analytics/category-spend', { query: { from, to } }),
|
||||
planFact: (month: string) =>
|
||||
apiClient.get<PlanFactReport>('/analytics/plan-fact', { query: { month } }),
|
||||
cashFlow: (from: string, to: string) =>
|
||||
apiClient.get<CashFlowMonth[]>('/analytics/cash-flow', { query: { from, to } }),
|
||||
balances: () => apiClient.get<BalancesReport>('/analytics/balances'),
|
||||
},
|
||||
exports: {
|
||||
request: () => apiClient.post<ExportInfo>('/exports'),
|
||||
get: (id: string) => apiClient.get<ExportInfo>(`/exports/${id}`),
|
||||
},
|
||||
spaces: {
|
||||
deletionStatus: () => apiClient.get<SpaceDeletionStatus>('/spaces/current/deletion'),
|
||||
requestDeletion: (confirmationPhrase: string) =>
|
||||
apiClient.post<SpaceDeletionStatus>('/spaces/current/deletion', {
|
||||
json: { confirmationPhrase },
|
||||
}),
|
||||
cancelDeletion: () => apiClient.delete<SpaceDeletionStatus>('/spaces/current/deletion'),
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user