Files
clinicpro/assets/admin/components/resources/ResourceFormModal.test.tsx
T
hamedandClaude Opus 5 dd284ec622 refactor(branch): remove the branch domain, keep the address
Branches and rooms are not part of the resource-first product: a room is a
resource like any other, and the only thing the branch pages still managed —
opening hours — duplicated the resource's own shift.

What could not go is the address. Every appointment carries address_id (75 of
75 rows), the public booking site reads /clinic-pro/doctor-address/{id}, and a
resource derives its tenant pair from the address it belongs to. So
DoctorAddress stays as an invisible anchor with no page and no menu entry, and
GET /api/v1/addresses replaces GET /api/v1/branches for the forms that still
need to say "where".

BranchResolver was likewise not a branch feature. doctor_addresses is a global
table, so TenantFilter does not cover it and eight callers across booking,
availability, pricing and the catalog went through this resolver to avoid
leaking another clinic's address. It moved to Doctor\Service\AddressResolver
rather than dying with the domain.

The availability engine loses one layer: a resource's real hours were the
branch hours intersected with its shift, and are now the shift alone. That is
the single behavioural change, and the three tests that asserted the old
contract are replaced by one that states the new one.

Rooms already had a resource row each; the migration drops only the bridge
back to `rooms`, and drops it before the table — that foreign key is ON DELETE
CASCADE and the other order would take the resources, and their appointments,
with it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-02 15:25:32 +03:30

68 lines
2.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { renderWithProviders } from '../../test/utils';
vi.mock('../../lib/api', () => ({
api: { get: vi.fn(), post: vi.fn(), patch: vi.fn(), put: vi.fn(), delete: vi.fn() },
ApiError: class extends Error {},
}));
vi.mock('sonner', () => ({ toast: { success: vi.fn(), error: vi.fn() } }));
import { api } from '../../lib/api';
import ResourceFormModal from './ResourceFormModal';
const get = api.get as ReturnType<typeof vi.fn>;
const resource = {
uuid: 'r-1',
name: 'لیزر ۱',
address_uuid: 'b-1',
type_uuid: 't-1',
capacity: 1,
is_active: true,
attributes: {},
};
const props = {
open: true,
resource: resource as never,
addresses: [{ uuid: 'b-1', name: 'محل نوبت‌دهی' }] as never,
types: [{ uuid: 't-1', name: 'دستگاه', code: 'device' }] as never,
saving: false,
onClose: () => {},
onSave: () => {},
};
describe('ResourceFormModal — هشدار غیرفعال‌سازی', () => {
beforeEach(() => vi.clearAllMocks());
/** ⭐ غیرفعال‌کردن نوبت‌ها را لغو نمی‌کند؛ اپراتور باید بداند چند بیمار درگیرند. */
it('warns with the upcoming count only once the resource is switched off', async () => {
get.mockResolvedValue({ data: { ...resource, upcoming_appointments: 4 } });
const user = userEvent.setup();
renderWithProviders(<ResourceFormModal {...props} />);
await waitFor(() => expect(get).toHaveBeenCalledWith('/api/v1/resource/r-1'));
expect(screen.queryByText(/نوبت آیندهٔ فعال دارد/)).toBeNull();
await user.click(screen.getByLabelText('منبع فعال است'));
expect(await screen.findByText(/۴ نوبت آیندهٔ فعال دارد/)).toBeInTheDocument();
});
it('stays quiet when nothing is booked on the resource', async () => {
get.mockResolvedValue({ data: { ...resource, upcoming_appointments: 0 } });
const user = userEvent.setup();
renderWithProviders(<ResourceFormModal {...props} />);
await waitFor(() => expect(get).toHaveBeenCalled());
await user.click(screen.getByLabelText('منبع فعال است'));
expect(screen.queryByText(/نوبت آیندهٔ فعال دارد/)).toBeNull();
});
});