Align /admin/my-payments with the tauri /payments source (per user): the list
is now a flat, newest-first list of the tenant's recorded invoices — one row
per invoice — instead of the per-patient aggregation built from Figma.
Backend:
- replace InvoiceRepository::patientPaymentSummary aggregation with
tenantInvoices/countTenantInvoices (flat, joins patient name/national code).
- InvoiceService::patientPaymentList → tenantInvoiceList.
- BillingController: GET /api/v1/my/billing/patient-payments →
GET /api/v1/my/billing/payments returning
{ invoice_uuid, patient_uuid, patient_name, national_code, issued_at,
amount_rials, status } rows.
- node-2 patient invoices endpoint unchanged.
Frontend:
- useMyPayments: usePatientPayments → usePayments (flat PaymentRow).
- MyPaymentsPage columns match tauri DetailT: row #, avatar+name, national
code, date-time, amount paid, مشاهده (no status column); 'اضافه کردن بیمار'
links to /admin/patients/new. Filters (national code / status / Jalali date
range) kept.
Tests + docs/api/billing.md updated. Intentionally omitted tauri extras:
mobile Cards view and the advanced ModalFilter.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
59 lines
2.8 KiB
TypeScript
59 lines
2.8 KiB
TypeScript
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
import { screen, fireEvent, waitFor } from '@testing-library/react';
|
|
import { renderWithProviders } from '../test/utils';
|
|
|
|
const navigate = vi.fn();
|
|
vi.mock('react-router-dom', async (orig) => ({
|
|
...(await orig<typeof import('react-router-dom')>()),
|
|
useNavigate: () => navigate,
|
|
}));
|
|
vi.mock('../lib/api', () => ({ api: { get: vi.fn() }, ApiError: class extends Error {} }));
|
|
|
|
import { api } from '../lib/api';
|
|
import MyPaymentsPage from './MyPaymentsPage';
|
|
|
|
const get = api.get as ReturnType<typeof vi.fn>;
|
|
|
|
const ROWS = [
|
|
{ invoice_uuid: 'iv1', patient_uuid: 'p1', patient_name: 'دنیا خلیلی', national_code: '1744023654',
|
|
issued_at: 1717000000, amount_rials: 2350000, status: 'paid' },
|
|
{ invoice_uuid: 'iv2', patient_uuid: 'p2', patient_name: 'علی بدیعی', national_code: '2200112233',
|
|
issued_at: 1718000000, amount_rials: 6000000, status: 'unsettled' },
|
|
];
|
|
|
|
beforeEach(() => {
|
|
navigate.mockReset();
|
|
get.mockReset();
|
|
get.mockResolvedValue({ success: true, data: ROWS, meta: { totalRecords: 2, totalPages: 1, currentPage: 1 } });
|
|
});
|
|
|
|
describe('MyPaymentsPage (لیست پرداختها)', () => {
|
|
it('renders a flat row per invoice with patient name and national code', async () => {
|
|
renderWithProviders(<MyPaymentsPage />, { route: '/admin/my-payments' });
|
|
expect(await screen.findByText('دنیا خلیلی')).toBeInTheDocument();
|
|
expect(screen.getByText('علی بدیعی')).toBeInTheDocument();
|
|
expect(screen.getByText('1744023654')).toBeInTheDocument();
|
|
expect(screen.getByText('2200112233')).toBeInTheDocument();
|
|
});
|
|
|
|
it('navigates to the patient detail on مشاهده', async () => {
|
|
renderWithProviders(<MyPaymentsPage />, { route: '/admin/my-payments' });
|
|
await screen.findByText('دنیا خلیلی');
|
|
fireEvent.click(screen.getAllByRole('button', { name: /مشاهده/ })[0]);
|
|
expect(navigate).toHaveBeenCalledWith('/admin/my-payments/p1');
|
|
});
|
|
|
|
it('shows an empty state when there are no payments', async () => {
|
|
get.mockResolvedValue({ success: true, data: [], meta: { totalRecords: 0, totalPages: 0, currentPage: 1 } });
|
|
renderWithProviders(<MyPaymentsPage />, { route: '/admin/my-payments' });
|
|
expect(await screen.findByText('پرداختی یافت نشد')).toBeInTheDocument();
|
|
});
|
|
|
|
it('sends the national_code filter to the API', async () => {
|
|
renderWithProviders(<MyPaymentsPage />, { route: '/admin/my-payments' });
|
|
await screen.findByText('دنیا خلیلی');
|
|
fireEvent.change(screen.getByPlaceholderText('کد ملی بیمار را وارد کنید...'), { target: { value: '1744' } });
|
|
await waitFor(() => expect(get.mock.calls.some(([u]) => String(u).includes('national_code=1744'))).toBe(true));
|
|
});
|
|
});
|