# 8. Verification & Testing

## Pre-requisites

- VisoAdmin running at `http://localhost:8002`
- Logged in as admin user
- At least one RM request exists with `record_type` not yet linked to an event
- Database has active records in: `countries`, `states`, `cities`, `services`, `categories`

## Test Scenarios

### Scenario 1: Navigate to Create Event Form

1. Go to `/rm/rm-requests`
2. Click "View Details" on an RM request that has **no event linked**
3. Verify the "Create Event" button is visible (top-right)
4. Click "Create Event"
5. **Expected:** Redirects to `/rm/create-event/{rmUuid}` with the form page

### Scenario 2: Verify Pre-filled Data

On the create event form, verify:
- [ ] Client info card shows correct name, phone, email from the RM request's client
- [ ] Budget is shown if present on RM request
- [ ] Country dropdown is pre-selected from RM `country_id`
- [ ] State dropdown is pre-selected from RM `state_id`
- [ ] City dropdown is pre-selected from RM `city_id` and populated with cities for that state
- [ ] Category dropdown is pre-selected from RM `category`
- [ ] Event Type is pre-selected based on category's type (personal/corporate)

### Scenario 3: Cascading Dropdowns

1. Change the **State** dropdown to a different state
2. **Expected:** City dropdown clears and reloads with cities for the new state
3. Change the **Event Type** dropdown
4. **Expected:** Category options filter to show only matching type

### Scenario 4: Dynamic Service Rows

1. Click "Add Service" button
2. **Expected:** A new service row appears (dropdown + budget input + remove button)
3. All service dropdowns show active services ordered alphabetically
4. Click "Remove" on a row
5. **Expected:** Row is removed
6. When only 1 row remains, "Remove" button is hidden
7. Verify service dropdown options match `services` table (active records only)

### Scenario 5: Form Validation

1. Try to submit with empty Event Name → **Expected:** SweetAlert2 error
2. Try to submit with no date → **Expected:** SweetAlert2 error
3. Try to submit with no city selected → **Expected:** SweetAlert2 error
4. Try to submit with no service selected → **Expected:** SweetAlert2 error
5. Fill all fields correctly and submit → **Expected:** SweetAlert2 confirmation dialog

### Scenario 6: Successful Event Creation

1. Fill all fields correctly and confirm submission
2. **Expected:**
   - Redirect to `/rm/rm-request-details/{rmUuid}`
   - Green success flash message: "Event created successfully"
   - Event details now display in the card (name, human_usable_id, guest count)
   - "Create Event" button is **no longer visible**
   - RM status shows "Event Created" (orange)

### Scenario 7: Verify Database Records

After successful creation, check:

```sql
-- 1. New event row
SELECT * FROM events ORDER BY id DESC LIMIT 1;
-- Verify: uuid, human_usable_id (EVN prefix), client_id, type, category,
--         country_id, state_id, cities_id, event_name, event_date, etc.

-- 2. Event services rows
SELECT * FROM event_services WHERE event_id = <new_event_id>;
-- Verify: one row per selected service, correct service_id (integer),
--         expected_event_date and expected_start_time match event

-- 3. Updated RM request
SELECT * FROM client_rm_requests WHERE uuid = '<rm_uuid>';
-- Verify: status=2, record_id=<event_uuid>, event_id=<event_uuid>, record_type='event'
```

### Scenario 8: Event Appears in Event List

1. Navigate to `/event/list`
2. **Expected:** The newly created event appears in the DataTable
3. Click on the event to see details
4. **Expected:** All fields display correctly (name, date, location, host details)

### Scenario 9: Guard Against Duplicate Event

1. Go to an RM request that **already has** an event linked
2. **Expected:** "Create Event" button is **not shown** on the details page
3. Try to manually navigate to `/rm/create-event/{rmUuid}` for this request
4. **Expected:** Redirect back to RM details with warning: "Event already exists for this RM request"

### Scenario 10: Error Handling

1. Simulate a DB failure (e.g., invalid client_id)
2. **Expected:** Transaction rolls back, no partial data, error flash message shown
3. Check Laravel log (`storage/logs/`) for error details

## Checklist

- [ ] Routes registered and accessible
- [ ] Controller methods handle happy path and edge cases
- [ ] Form pre-fills correctly from RM request data
- [ ] Cascading dropdowns work (state → city)
- [ ] Category filtering by event type works
- [ ] Dynamic service rows add/remove correctly
- [ ] Client-side validation catches all required fields
- [ ] Server-side validation rejects invalid data
- [ ] Event created with correct data in all 3 tables
- [ ] RM request status updated to "Event Created" (2)
- [ ] Event visible in `/event/list` and `/event/details/{id}`
- [ ] "Create Event" button hidden when event already exists
- [ ] Guard redirect works for duplicate attempts
- [ ] Error handling with rollback works
