feat(invoice): implement recorder identity resolution for payments and update related tests
This commit is contained in:
@@ -8,6 +8,7 @@ vi.mock('../lib/api', () => ({
|
||||
}));
|
||||
|
||||
import { api } from '../lib/api';
|
||||
import { useAuthStore } from '../stores/authStore';
|
||||
import InvoiceSummaryModal from './InvoiceSummaryModal';
|
||||
|
||||
const get = api.get as ReturnType<typeof vi.fn>;
|
||||
@@ -121,6 +122,61 @@ describe('InvoiceSummaryModal', () => {
|
||||
expect(screen.getByText('بیمه ایران')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
/**
|
||||
* ستون «ثبتکننده»: نامِ حلشدهٔ سرور، و لینک فقط وقتی بیننده صفحهٔ آن پروفایل را
|
||||
* میتواند باز کند. عکسِ لحظهٔ ثبت (`created_by_name`) فقط fallback است.
|
||||
*/
|
||||
describe('ثبتکنندهٔ پرداخت', () => {
|
||||
const withRecorder = (recorder: object | null) => ({
|
||||
...baseInvoice,
|
||||
session: {
|
||||
...fullSession,
|
||||
payments: [{
|
||||
uuid: 'p1', method: 'wallet', amount_rials: 1_500_000, paid_at: 1700100000,
|
||||
created_by_name: '09120000000', created_by: recorder,
|
||||
}],
|
||||
},
|
||||
});
|
||||
|
||||
it('پزشکِ ثبتکننده به پروفایل پزشک لینک میشود', async () => {
|
||||
useAuthStore.setState({ primaryRole: 'clinic' } as any);
|
||||
mockInvoice(withRecorder({ user_uuid: 'u1', name: 'دکتر رضایی', role: 'doctor', doctor_uuid: 'doc-9' }));
|
||||
renderWithProviders(<InvoiceSummaryModal invoiceUuid="iv1" onClose={() => {}} />);
|
||||
|
||||
const link = await screen.findByRole('link', { name: 'دکتر رضایی' });
|
||||
expect(link).toHaveAttribute('href', '/admin/doctors/doc-9');
|
||||
// نامِ زنده جای شمارهٔ ذخیرهشده مینشیند.
|
||||
expect(screen.queryByText('09120000000')).toBeNull();
|
||||
});
|
||||
|
||||
it('منشیِ ثبتکننده برای کلینیک به فهرست منشیهای خودش لینک میشود', async () => {
|
||||
useAuthStore.setState({ primaryRole: 'clinic' } as any);
|
||||
mockInvoice(withRecorder({ user_uuid: 'u2', name: 'منشی مدیسا', role: 'secretary', doctor_uuid: null }));
|
||||
renderWithProviders(<InvoiceSummaryModal invoiceUuid="iv1" onClose={() => {}} />);
|
||||
|
||||
const link = await screen.findByRole('link', { name: 'منشی مدیسا' });
|
||||
expect(link).toHaveAttribute('href', '/admin/my-secretaries');
|
||||
});
|
||||
|
||||
it('بینندهای که آن صفحه را ندارد، فقط نام میبیند نه لینک', async () => {
|
||||
useAuthStore.setState({ primaryRole: 'secretary' } as any);
|
||||
mockInvoice(withRecorder({ user_uuid: 'u2', name: 'منشی مدیسا', role: 'secretary', doctor_uuid: null }));
|
||||
renderWithProviders(<InvoiceSummaryModal invoiceUuid="iv1" onClose={() => {}} />);
|
||||
|
||||
expect(await screen.findByText('منشی مدیسا')).toBeInTheDocument();
|
||||
expect(screen.queryByRole('link', { name: 'منشی مدیسا' })).toBeNull();
|
||||
});
|
||||
|
||||
it('بدون created_by (کاربر حذفشده): همان عکسِ ذخیرهشده، بدون لینک', async () => {
|
||||
useAuthStore.setState({ primaryRole: 'clinic' } as any);
|
||||
mockInvoice(withRecorder(null));
|
||||
renderWithProviders(<InvoiceSummaryModal invoiceUuid="iv1" onClose={() => {}} />);
|
||||
|
||||
expect(await screen.findByText('09120000000')).toBeInTheDocument();
|
||||
expect(screen.queryByRole('link', { name: '09120000000' })).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
it('فاکتور بدون بیمه، جدول بیمه ندارد', async () => {
|
||||
mockInvoice(baseInvoice);
|
||||
renderWithProviders(<InvoiceSummaryModal invoiceUuid="iv1" onClose={() => {}} />);
|
||||
|
||||
Reference in New Issue
Block a user