feat: add admin subscription granting feature

- Implemented the ability for admins to grant subscriptions to doctors and clinics without payment.
- Added new API endpoint `/api/v1/admin/subscription/grant` for granting subscriptions.
- Updated the subscription model to track the admin who granted the subscription.
- Enhanced the subscription report to include details about granted subscriptions.
- Introduced a new `is_granted` field to indicate if a subscription was granted by an admin.
- Updated the database schema to support the new functionality with a migration.
- Added tests to ensure the correct behavior of the subscription granting process.
This commit is contained in:
hamed
2026-08-09 13:43:30 +03:30
parent 60ccd5cc1d
commit a6a965a2aa
10 changed files with 874 additions and 29 deletions
@@ -1,5 +1,5 @@
import { describe, it, expect, vi } from 'vitest';
import { render, screen } from '@testing-library/react';
import { render, screen, fireEvent } from '@testing-library/react';
import SearchableSelect from './SearchableSelect';
vi.mock('../../stores/uiStore', () => ({ useUiStore: () => false }));
@@ -53,3 +53,44 @@ describe('SearchableSelect — نام دسترس‌پذیر', () => {
expect(screen.getByRole('combobox', { name: 'شهر' })).toBeInTheDocument();
});
});
describe('SearchableSelect — جستجوی سمت سرور', () => {
it('با تایپ، onInputChange صدا زده می‌شود', () => {
const onInputChange = vi.fn();
render(<SearchableSelect options={[]} onChange={() => {}} inputId="srv" onInputChange={onInputChange} />);
fireEvent.change(document.getElementById('srv') as HTMLInputElement, { target: { value: 'رضا' } });
expect(onInputChange).toHaveBeenCalledWith('رضا');
});
/** نتیجهٔ سرور نباید دوباره روی متنِ تایپ‌شده فیلتر شود. */
it('در حالت سرور، گزینه‌ای که با متن تایپ‌شده نمی‌خواند هم می‌ماند', () => {
render(
<SearchableSelect
options={[{ value: 'd1', label: 'دکتر رضایی' }]}
onChange={() => {}}
inputId="srv2"
onInputChange={() => {}}
/>,
);
const input = document.getElementById('srv2') as HTMLInputElement;
fireEvent.focus(input);
fireEvent.keyDown(input, { key: 'ArrowDown' });
fireEvent.change(input, { target: { value: '0912' } });
expect(screen.getByText('دکتر رضایی')).toBeInTheDocument();
});
it('بدون onInputChange، فیلتر داخلی سر جایش می‌ماند', () => {
render(<SearchableSelect options={[{ value: 'd1', label: 'دکتر رضایی' }]} onChange={() => {}} inputId="srv3" />);
const input = document.getElementById('srv3') as HTMLInputElement;
fireEvent.focus(input);
fireEvent.keyDown(input, { key: 'ArrowDown' });
fireEvent.change(input, { target: { value: '0912' } });
expect(screen.queryByText('دکتر رضایی')).not.toBeInTheDocument();
});
});