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:
@@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -26,6 +26,14 @@ interface Props {
|
||||
ariaLabel?: string;
|
||||
/** اگر label قابلمشاهدهای وجود دارد، id آن را بده (بر ariaLabel اولویت دارد). */
|
||||
ariaLabelledBy?: string;
|
||||
/**
|
||||
* جستجوی سمت سرور: با هر تایپ صدا زده میشود تا مصرفکننده `options` تازه بدهد.
|
||||
*
|
||||
* وقتی داده میشود، فیلترِ داخلی react-select خاموش میشود؛ وگرنه نتیجهٔ سرور
|
||||
* دوباره روی متنِ تایپشده فیلتر میشد و گزینههایی که سرور با معیارِ دیگری
|
||||
* (مثلاً شمارهٔ موبایل) پیدا کرده بود ناپدید میشدند.
|
||||
*/
|
||||
onInputChange?: (input: string) => void;
|
||||
}
|
||||
|
||||
export default function SearchableSelect({
|
||||
@@ -41,6 +49,7 @@ export default function SearchableSelect({
|
||||
height = 42,
|
||||
ariaLabel,
|
||||
ariaLabelledBy,
|
||||
onInputChange,
|
||||
}: Props) {
|
||||
const darkMode = useUiStore((s) => s.darkMode);
|
||||
|
||||
@@ -121,6 +130,12 @@ export default function SearchableSelect({
|
||||
isLoading={isLoading}
|
||||
isDisabled={isDisabled}
|
||||
isClearable={isClearable}
|
||||
onInputChange={onInputChange ? (input, meta) => {
|
||||
// react-select ورودی را هنگام بستن منو و blur هم «تغییر» میداند؛ آن دو را
|
||||
// رد نکنیم، هر بار بستنِ منو لیست را به حالت خالی برمیگرداند.
|
||||
if (meta.action === 'input-change') { onInputChange(input); }
|
||||
} : undefined}
|
||||
filterOption={onInputChange ? null : undefined}
|
||||
styles={styles}
|
||||
isRtl
|
||||
menuPortalTarget={typeof document !== 'undefined' ? document.body : undefined}
|
||||
|
||||
Reference in New Issue
Block a user