# Room Allocation v2 – Test Cases (curl)

**Base URL:** `http://localhost:5000` (or set `BASE_URL`)  
**API prefix:** `/api/ems/room-bookings`

Use admin token for protected routes (if applicable). Replace placeholders with real IDs from your DB.

---

## Prerequisites

- Backend running: `npm run start:server` (or from `dashboard/`: `node server.js`)
- Get a **room_unit_id**: from GET /api/ems/room-units?room_id=ROOM_ID
- Get a **person_id** (participant): from GET /api/ems/participants (use `person_id._id` for participant_id in booking)
- **date**: LA date key `YYYY-MM-DD` (e.g. `2026-03-20`), must be today or future

---

## Test 1: GET list (no auth required if backend allows)

**Expect:** 200, JSON array of bookings (possibly empty).

```bash
curl -s -w "\nHTTP %{http_code}\n" "http://localhost:5000/api/ems/room-bookings?room_id=ROOM_ID&from_date=2026-03-01&to_date=2026-03-31"
```

---

## Test 2: POST create – participant only (guest_count=0, is_guest_only=false)

**Expect:** 201, created booking with `guest_count: 0`, `is_guest_only: false`. Occupancy = 1.

```bash
curl -s -w "\nHTTP %{http_code}\n" -X POST "http://localhost:5000/api/ems/room-bookings" \
  -H "Content-Type: application/json" \
  -d '{
    "room_unit_id": "ROOM_UNIT_ID",
    "date": "2026-03-20",
    "participant_id": "PERSON_ID",
    "guest_count": 0,
    "allocation_type": "required"
  }'
```

---

## Test 3: POST create – participant + 1 guest (guest_count=1, is_guest_only=false)

**Expect:** 201. Occupancy = 2. Fails if room bed_count is 1.

```bash
curl -s -w "\nHTTP %{http_code}\n" -X POST "http://localhost:5000/api/ems/room-bookings" \
  -H "Content-Type: application/json" \
  -d '{
    "room_unit_id": "ROOM_UNIT_ID",
    "date": "2026-03-20",
    "participant_id": "PERSON_ID",
    "guest_count": 1,
    "allocation_type": "required"
  }'
```

---

## Test 4: POST create – guest only (is_guest_only=true, guest_count=1)

**Expect:** 201. Occupancy = 1 (no +1 for participant). Same participant_id, different semantic.

```bash
curl -s -w "\nHTTP %{http_code}\n" -X POST "http://localhost:5000/api/ems/room-bookings" \
  -H "Content-Type: application/json" \
  -d '{
    "room_unit_id": "ROOM_UNIT_ID",
    "date": "2026-03-20",
    "participant_id": "PERSON_ID",
    "guest_count": 1,
    "is_guest_only": true,
    "allocation_type": "required"
  }'
```

---

## Test 5: POST – missing required fields

**Expect:** 400, message about required fields.

```bash
curl -s -w "\nHTTP %{http_code}\n" -X POST "http://localhost:5000/api/ems/room-bookings" \
  -H "Content-Type: application/json" \
  -d '{"date": "2026-03-20"}'
```

---

## Test 6: POST – invalid date format

**Expect:** 400, date validation message.

```bash
curl -s -w "\nHTTP %{http_code}\n" -X POST "http://localhost:5000/api/ems/room-bookings" \
  -H "Content-Type: application/json" \
  -d '{
    "room_unit_id": "ROOM_UNIT_ID",
    "date": "03-20-2026",
    "participant_id": "PERSON_ID",
    "allocation_type": "required"
  }'
```

---

## Test 7: POST – bed limit exceeded

**Expect:** 400, "Bed limit exceeded". (Use a room with bed_count=1 and create two bookings for same unit+date.)

```bash
# First booking OK (1 person). Second booking (participant + 0 guests) would be 2nd person in same room/date on a 1-bed room → 400.
```

---

## Test 8: PATCH – update guest_count and is_guest_only

**Expect:** 200, updated booking.

```bash
curl -s -w "\nHTTP %{http_code}\n" -X PATCH "http://localhost:5000/api/ems/room-bookings/BOOKING_ID" \
  -H "Content-Type: application/json" \
  -d '{"guest_count": 1, "is_guest_only": false}'
```

---

## Test 9: GET list – response includes is_guest_only

**Expect:** 200, each booking has `is_guest_only` (boolean) and `guest_count` (number).

```bash
curl -s "http://localhost:5000/api/ems/room-bookings?room_id=ROOM_ID&from_date=2026-03-01&to_date=2026-03-31" | head -c 500
```

---

## Test 10: DELETE booking

**Expect:** 200, message "Booking cancelled successfully".

```bash
curl -s -w "\nHTTP %{http_code}\n" -X DELETE "http://localhost:5000/api/ems/room-bookings/BOOKING_ID"
```

---

## Summary checklist

| # | Test | Expected |
|---|------|----------|
| 1 | GET list | 200, array |
| 2 | POST participant only (guest_count=0) | 201 |
| 3 | POST participant + guest | 201 (if bed_count ≥ 2) |
| 4 | POST guest only (is_guest_only=true) | 201 |
| 5 | POST missing fields | 400 |
| 6 | POST invalid date | 400 |
| 7 | POST bed limit exceeded | 400 |
| 8 | PATCH guest_count / is_guest_only | 200 |
| 9 | GET returns is_guest_only | 200, field present |
| 10 | DELETE | 200 |
