feat: port payment management tab from tauri to admin dashboard
Add per-clinic payment methods (bank accounts + POS/card-reader devices)
under the "مدیریت پرداخت" settings tab at /admin/my-financial, ported from
clinic-pro-tauri's mock-only PaymentManagement tab into a real persisted
feature. These records are referenceable (by uuid) from patient invoices to
record which method a service payment was made with.
Backend (new src/PaymentMethod domain):
- BankAccount + Pos entities, repositories, PaymentMethodService (validation,
ownership scoping, create/update/toggle logic).
- Thin PaymentMethodController exposing /api/v1/my/payment-methods/{bank-accounts,pos}
(GET/POST/PUT + PATCH .../status), guarded to clinic/doctor/secretary/admin.
- Migration for bank_accounts + pos_devices tables.
- Functional tests (success + validation/404/403 + empty boundaries).
- docs/api/payment-method.md.
Frontend:
- Replace MyFinancialPage content with the payment-management UI (two tabs,
tables, add/edit modals, status toggle) using the admin design system.
- usePaymentMethods hook (TanStack Query) + presentational components.
- Update page test to cover tabs, data, empty state and the add modal.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
||||
import { screen } from '@testing-library/react';
|
||||
import { screen, fireEvent, within } from '@testing-library/react';
|
||||
import { renderWithProviders } from '../test/utils';
|
||||
|
||||
vi.mock('sonner', () => ({ toast: { success: vi.fn(), error: vi.fn() } }));
|
||||
@@ -13,20 +13,70 @@ import MyFinancialPage from './MyFinancialPage';
|
||||
|
||||
const get = api.get as ReturnType<typeof vi.fn>;
|
||||
|
||||
const bankRow = {
|
||||
uuid: 'bank-1', bank_name: 'ملی', card_number: '6037991234567890',
|
||||
account_number: '0101234567890', shaba_number: null, is_active: true, created_at: 1,
|
||||
};
|
||||
const posRow = {
|
||||
uuid: 'pos-1', bank_name: 'ملت', serial_number: 'SN-98765',
|
||||
terminal_number: '123456', account_number: null, is_active: false, created_at: 1,
|
||||
};
|
||||
|
||||
function mockData({ banks = [bankRow], pos = [posRow] } = {}) {
|
||||
get.mockImplementation((url: string) => {
|
||||
if (url.includes('/bank-accounts')) return Promise.resolve({ success: true, data: banks });
|
||||
if (url.includes('/pos')) return Promise.resolve({ success: true, data: pos });
|
||||
return Promise.resolve({ success: true, data: [] });
|
||||
});
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
get.mockReset();
|
||||
get.mockResolvedValue({ success: true, data: {
|
||||
total_paid: 0, total_pending: 0, monthly_chart: [],
|
||||
} });
|
||||
mockData();
|
||||
});
|
||||
|
||||
describe('MyFinancialPage inside the settings shell', () => {
|
||||
it('renders the settings sub-nav around the page content', async () => {
|
||||
describe('MyFinancialPage — payment methods', () => {
|
||||
it('renders the settings shell and the payment management header', async () => {
|
||||
renderWithProviders(<MyFinancialPage />, { route: '/admin/my-financial' });
|
||||
// settings shell menu
|
||||
expect(await screen.findByText('خرید اشتراک')).toBeInTheDocument();
|
||||
expect(screen.getByText('خدمات')).toBeInTheDocument();
|
||||
// page's own content
|
||||
expect(screen.getByText('گزارش مالی')).toBeInTheDocument();
|
||||
expect(await screen.findByText('خرید اشتراک')).toBeInTheDocument(); // settings sub-nav
|
||||
expect(screen.getByText('مدیریت پرداختها')).toBeInTheDocument(); // page header
|
||||
expect(screen.getByRole('tab', { name: 'حساب بانکی' })).toBeInTheDocument();
|
||||
expect(screen.getByRole('tab', { name: 'کارت خوان' })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows bank accounts by default', async () => {
|
||||
renderWithProviders(<MyFinancialPage />, { route: '/admin/my-financial' });
|
||||
expect(await screen.findByText('0101234567890')).toBeInTheDocument();
|
||||
expect(screen.getByText('6037991234567890')).toBeInTheDocument();
|
||||
expect(screen.getByText('مدیریت و اضافه کردن حساب های بانکی کلینیک')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('switches to the POS tab and lists devices', async () => {
|
||||
renderWithProviders(<MyFinancialPage />, { route: '/admin/my-financial' });
|
||||
await screen.findByText('0101234567890');
|
||||
|
||||
fireEvent.click(screen.getByRole('tab', { name: 'کارت خوان' }));
|
||||
|
||||
expect(await screen.findByText('SN-98765')).toBeInTheDocument();
|
||||
expect(screen.getByText('123456')).toBeInTheDocument();
|
||||
expect(screen.getByText('مدیریت و اضافه کردن دستگاه های کارت خوان موجود')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders an empty state when there are no bank accounts', async () => {
|
||||
mockData({ banks: [] });
|
||||
renderWithProviders(<MyFinancialPage />, { route: '/admin/my-financial' });
|
||||
expect(await screen.findByText('هنوز حساب بانکی ثبت نشده است')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('opens the add bank account modal from the header button', async () => {
|
||||
renderWithProviders(<MyFinancialPage />, { route: '/admin/my-financial' });
|
||||
await screen.findByText('0101234567890');
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: /افزودن حساب بانکی/ }));
|
||||
|
||||
const dialog = await screen.findByText('افزودن حساب بانکی', { selector: 'h2' });
|
||||
expect(dialog).toBeInTheDocument();
|
||||
const modal = dialog.closest('.modal') as HTMLElement;
|
||||
expect(within(modal).getByText('شبا')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user