feat: Enhance appointment management by decoupling online booking toggle for admin context

- Introduced management mode for appointment slots, allowing doctors, admins, and clinic managers to view and book slots regardless of the online booking status.
- Updated SlotCalculatorService to accept a management context parameter, bypassing online booking restrictions.
- Modified appointment-related endpoints to handle management context and ensure proper authorization checks.
- Added tests to verify that management users can access slots even when online booking is disabled, while public users are still restricted.
- Improved documentation for API endpoints to reflect new management parameters and behaviors.
This commit is contained in:
hamed
2026-07-22 16:43:56 +03:30
parent 5507b42fd8
commit ed516c81a8
16 changed files with 658 additions and 83 deletions
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach, vi } from 'vitest';
import { screen } from '@testing-library/react';
import { screen, waitFor } from '@testing-library/react';
import { renderWithProviders } from '../test/utils';
vi.mock('sonner', () => ({ toast: { success: vi.fn(), error: vi.fn() } }));
@@ -43,4 +43,43 @@ describe('AppointmentSettingsPage', () => {
expect(await screen.findByText('قیمت ویزیت آزاد')).toBeInTheDocument();
expect(screen.getByText('این بخش فقط برای پزشک در دسترس است.')).toBeInTheDocument();
});
it('پزشک عضو کلینیک بدون مطب شخصی: پیش‌فرض روی کلینیک، بدون پیام «ابتدا آدرس مطب»', async () => {
get.mockImplementation((url: string) => {
if (url === '/api/v1/doctor/doc-1')
return Promise.resolve({ success: true, data: { data: { uuid: 'doc-1', clinics: [{ uuid: 'clinicX', name: 'کلینیک الف' }] } } });
// مطب شخصی مکانی ندارد → پیش‌فرض باید کلینیک شود
if (url === '/api/v1/appointment-settings/available-locations/doc-1')
return Promise.resolve({ success: true, data: { data: [] } });
if (url.includes('available-locations/doc-1?clinic_uuid=clinicX'))
return Promise.resolve({ success: true, data: { data: [{ id: '5', uuid: 'addr5', type: 'clinic', clinic_id: '9', clinic_name: 'کلینیک الف' }] } });
if (url.includes('/weekly-schedule')) return Promise.resolve({ success: true, data: { data: null } });
return Promise.resolve({ success: true, data: {} });
});
renderWithProviders(<AppointmentSettingsPage />, { route: '/admin/appointment-settings' });
expect(await screen.findByText('محیط نوبت‌دهی')).toBeInTheDocument();
await waitFor(() =>
expect(get).toHaveBeenCalledWith(expect.stringContaining('available-locations/doc-1?clinic_uuid=clinicX')),
);
expect(screen.queryByText('ابتدا آدرس مطب را ثبت کنید')).not.toBeInTheDocument();
});
it('پزشک بدون کلینیک: انتخابگر محیط نمایش داده نمی‌شود', async () => {
get.mockImplementation((url: string) => {
if (url === '/api/v1/doctor/doc-1')
return Promise.resolve({ success: true, data: { data: { uuid: 'doc-1', clinics: [] } } });
if (url === '/api/v1/appointment-settings/available-locations/doc-1')
return Promise.resolve({ success: true, data: { data: [] } });
if (url.includes('/weekly-schedule')) return Promise.resolve({ success: true, data: { data: null } });
return Promise.resolve({ success: true, data: {} });
});
renderWithProviders(<AppointmentSettingsPage />, { route: '/admin/appointment-settings' });
await screen.findByText('قیمت ویزیت آزاد');
await waitFor(() => expect(get).toHaveBeenCalledWith('/api/v1/doctor/doc-1'));
expect(screen.queryByText('محیط نوبت‌دهی')).not.toBeInTheDocument();
});
});