feat: Implement resource-based appointment booking flow
- Updated DoctorPage component to accept bookingResources prop for appointment list. - Added serviceQuery function to serialize service item UUIDs for API requests. - Introduced new API endpoints for fetching booking resources and resource slots. - Enhanced tests for new resource-based booking functionality, including resource selection and service availability. - Created ResourceSelect component for selecting appointment types, including doctor and resource options. - Updated appointment submission logic to include resource_uuid in payload when applicable. - Ensured UI reflects changes in booking flow without disrupting existing doctor-centric experience.
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
|
||||
vi.mock('@/services/response', () => ({
|
||||
request: {
|
||||
postAppointment: vi.fn(() => Promise.resolve({ data: { data: { uuid: 'a1' } } })),
|
||||
patchUserProfile: vi.fn(() => Promise.resolve({})),
|
||||
postUserProfile: vi.fn(() => Promise.resolve({})),
|
||||
},
|
||||
}));
|
||||
vi.mock('@/context/ProvinceProvider', () => ({ useProvince: () => ({ cityId: 7 }) }));
|
||||
vi.mock('js-cookie', () => ({ default: { get: () => undefined, set: vi.fn() } }));
|
||||
vi.mock('@/lib/tokenStore', () => ({ setAccessToken: vi.fn() }));
|
||||
vi.mock('../paying/ButtonFixed', () => ({ default: ({ children }) => <div>{children}</div> }));
|
||||
vi.mock('@/components/icons/ArrowLeftB', () => ({ default: () => null }));
|
||||
|
||||
import { request } from '@/services/response';
|
||||
import SubmitData from './SubmitData';
|
||||
|
||||
const VALID = {
|
||||
uuid: 'p1',
|
||||
phone: { value: '09120000000' },
|
||||
national_code: { value: '0012345678' },
|
||||
name: { value: 'علی' },
|
||||
family: { value: 'رضایی' },
|
||||
gender: { value: 'male' },
|
||||
basic_insurance: { value: { id: 3 } },
|
||||
};
|
||||
|
||||
const props = (over = {}) => ({
|
||||
setStep: vi.fn(),
|
||||
data: VALID,
|
||||
prevData: VALID,
|
||||
setErrors: vi.fn(),
|
||||
doctor: { uuid: 'doc-1' },
|
||||
isForAnother: false,
|
||||
selectedSlot: { start: 1786339800, end: 1786341000 },
|
||||
selectedDate: 1786339800,
|
||||
setAppointmentId: vi.fn(),
|
||||
setAppointmentExpiresAt: vi.fn(),
|
||||
selectedServiceUuids: ['s1'],
|
||||
clinicUuid: null,
|
||||
...over,
|
||||
});
|
||||
|
||||
const submit = async (over) => {
|
||||
render(<SubmitData {...props(over)} />);
|
||||
await userEvent.click(screen.getByText('ثبت اطلاعات'));
|
||||
return request.postAppointment.mock.calls[0]?.[0];
|
||||
};
|
||||
|
||||
describe('payload ثبت نوبت', () => {
|
||||
beforeEach(() => vi.clearAllMocks());
|
||||
|
||||
it('نوبت با پزشک → بدون resource_uuid', async () => {
|
||||
const payload = await submit();
|
||||
|
||||
expect(payload).toBeDefined();
|
||||
expect(payload).not.toHaveProperty('resource_uuid');
|
||||
expect(payload.service_item_uuids).toEqual(['s1']);
|
||||
});
|
||||
|
||||
it('نوبت منبعمحور → resource_uuid فرستاده میشود', async () => {
|
||||
const payload = await submit({ resourceUuid: 'r1' });
|
||||
|
||||
expect(payload.resource_uuid).toBe('r1');
|
||||
expect(payload.doctor_uuid).toBe('doc-1');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user