# Restaurant Manager — Comprehensive Test Plan

## Overview

All tests use **Pest 2.6** framework, located in `tests/Feature/Controllers/RestaurantManager/` and `tests/Unit/Enums/`.

**Estimated total: ~210 tests**

---

## 1. Authorization Tests (10 tests)

**File:** `tests/Feature/Controllers/RestaurantManager/RestaurantManagerAuthorizationTest.php`

| # | Test | Expected |
|---|---|---|
| 1 | Restaurant manager can access restaurant routes | 200 |
| 2 | Regular employee without role gets | 403 |
| 3 | Customer user gets | 403 |
| 4 | Coach user gets | 403 |
| 5 | Unauthenticated gets | 401 |
| 6 | Manager at Place A cannot access Place B restaurant | 403 |
| 7 | Manager cannot access restaurant of different place | 403 |
| 8 | Manager with inactive employee status gets | 403 |
| 9 | All model factories create valid records | pass |
| 10 | Morph map resolves correctly for all new types | pass |

---

## 2. Menu System Tests (30 tests)

**File:** `tests/Feature/Controllers/RestaurantManager/MenuSystemTest.php`

### Categories (8)
| # | Test |
|---|---|
| 1 | List categories returns paginated results |
| 2 | List categories filtered by type (food/drink) |
| 3 | Create category with parent hierarchy |
| 4 | Create category with invalid type returns 422 |
| 5 | Update category changes name and type |
| 6 | Delete category with no items works |
| 7 | Delete category with active items fails |
| 8 | Category sort_order respected in listing |

### Menu Items (14)
| # | Test |
|---|---|
| 9 | List items returns paginated results |
| 10 | List items filtered by category |
| 11 | List items filtered by allergen |
| 12 | List items filtered by dietary label |
| 13 | List items with search query |
| 14 | Create item with all fields and image |
| 15 | Create item without required fields returns 422 |
| 16 | Create item validates allergen enum values |
| 17 | Update item changes values correctly |
| 18 | Toggle item active/inactive |
| 19 | Delete item soft deletes |
| 20 | Show item returns full detail |
| 21 | Item image URL included in response |
| 22 | Inactive items excluded unless include_inactive=true |

### Menus (8)
| # | Test |
|---|---|
| 23 | List menus filtered by date |
| 24 | List menus filtered by service period |
| 25 | Create menu with sections and items |
| 26 | Today's menu returns current service period menu |
| 27 | Today's menu returns empty when no menu for today |
| 28 | Update menu replaces sections |
| 29 | Duplicate menu creates deep copy with new date |
| 30 | Delete menu soft deletes |

---

## 3. Tables Tests (18 tests)

**File:** `tests/Feature/Controllers/RestaurantManager/TablesTest.php`

| # | Test |
|---|---|
| 1 | List tables returns all with status |
| 2 | List tables filtered by zone |
| 3 | List tables filtered by status |
| 4 | Create table with valid data |
| 5 | Create table with duplicate number returns 422 |
| 6 | Update table changes fields |
| 7 | Update table status via PATCH |
| 8 | Delete table without reservations works |
| 9 | Delete table with future reservations fails |
| 10 | Tables status returns live data |
| 11 | Tables status shows reservation info on reserved tables |
| 12 | Tables status shows order info on occupied tables |
| 13 | Get restaurant hours returns structure |
| 14 | Update restaurant hours persists |
| 15 | Create exceptional closure works |
| 16 | Delete exceptional closure works |
| 17 | Availability service respects closures |
| 18 | Availability service respects opening hours |

---

## 4. Reservation Tests (28 tests)

**File:** `tests/Feature/Controllers/RestaurantManager/ReservationsTest.php`

### Manager API (12)
| # | Test |
|---|---|
| 1 | List reservations for date |
| 2 | List reservations filtered by status |
| 3 | Show reservation returns full detail |
| 4 | Create reservation with tables |
| 5 | Create walk-in reservation without customer |
| 6 | Status: PENDING → CONFIRMED works |
| 7 | Status: CONFIRMED → SEATED updates table status to OCCUPIED |
| 8 | Status: SEATED → COMPLETED frees tables to AVAILABLE |
| 9 | Status: CONFIRMED → NO_SHOW frees tables |
| 10 | Invalid status transition returns 422 |
| 11 | Assign tables validates availability |
| 12 | Assign tables warns if seats < party_size |

### Customer API (10)
| # | Test |
|---|---|
| 13 | Get available slots returns correct windows |
| 14 | Available slots respects closures |
| 15 | Available slots respects existing reservations |
| 16 | Available slots respects party size vs table capacity |
| 17 | Create reservation with auto-confirm → status CONFIRMED |
| 18 | Create reservation without auto-confirm → status PENDING |
| 19 | Create reservation for fully booked slot returns 422 |
| 20 | List my reservations shows only own |
| 21 | Cancel PENDING reservation works |
| 22 | Cancel SEATED reservation fails |

### Multi-table & Payment (6)
| # | Test |
|---|---|
| 23 | Assign 2 tables to large party |
| 24 | Multi-table total seats computed correctly |
| 25 | Cancel other user's reservation fails |
| 26 | Paid reservation creates order item via Orderable |
| 27 | RestaurantMustBeAvailable constraint works |
| 28 | Reservation auto-calculates end_at |

---

## 5. Cart & Checkout Tests (30 tests)

**File:** `tests/Feature/Controllers/RestaurantManager/CartCheckoutTest.php`

### Cart CRUD (12)
| # | Test |
|---|---|
| 1 | Create cart with table assignment |
| 2 | Create cart without customer (walk-in) |
| 3 | List carts returns only this manager's carts |
| 4 | Show cart returns items and totals |
| 5 | Add menu item creates correct OrderItem |
| 6 | Add menu item computes correct price |
| 7 | Update item quantity recalculates |
| 8 | Remove item from cart |
| 9 | Full cart update replaces items |
| 10 | Change cart customer |
| 11 | Assign tables to cart sets OCCUPIED |
| 12 | Delete cart frees tables |

### Payments (10)
| # | Test |
|---|---|
| 13 | Pay via wallet deducts balance |
| 14 | Pay via wallet with insufficient balance fails |
| 15 | Pay via POS stores receipt photo |
| 16 | Pay via cash validates change calculation |
| 17 | Pay via cash stores cash photo |
| 18 | Pay via Stripe creates payment intent |
| 19 | Payment marks order as PAID |
| 20 | Payment frees assigned tables |
| 21 | Invoice generated after payment (queued) |
| 22 | Order total includes all items |

### Tips & Orders (8)
| # | Test |
|---|---|
| 23 | Add tip stores amount on order |
| 24 | Tip separate from order total |
| 25 | Update tip overwrites previous |
| 26 | List orders returns PAID restaurant orders |
| 27 | Order detail includes tip info |
| 28 | Order detail includes table info |
| 29 | Download invoice returns PDF |
| 30 | Send invoice to email works |

---

## 6. Customer API Tests (22 tests)

**File:** `tests/Feature/Controllers/RestaurantManager/CustomerApiTest.php`

### Restaurant & Menu (6)
| # | Test |
|---|---|
| 1 | List restaurants returns active only |
| 2 | Show restaurant returns full detail |
| 3 | Get menu returns today's active menu |
| 4 | Menu items include allergens and dietary labels |
| 5 | Member sees member pricing |
| 6 | Non-member sees standard pricing |

### Pre-order (10)
| # | Test |
|---|---|
| 7 | Create pre-order links to reservation |
| 8 | Pre-order fails if accepts_preorders=false |
| 9 | Pre-order fails for other user's reservation |
| 10 | Pre-order fails for cancelled reservation |
| 11 | Pre-order validates menu items are active |
| 12 | Pre-order validates items available for date's service period |
| 13 | View pre-order returns items and totals |
| 14 | Pay pre-order via wallet works |
| 15 | Pay pre-order via Stripe works |
| 16 | POS/Cash not available for customer pre-orders |

### Search & Create Customer (6)
| # | Test |
|---|---|
| 17 | Search customers by name |
| 18 | Search customers returns empty for no match |
| 19 | Create quick customer with email |
| 20 | Create quick customer without email |
| 21 | Create customer with existing email fails |
| 22 | Customer search respects place context |

---

## 7. Dashboard Tests (24 tests)

**File:** `tests/Feature/Controllers/RestaurantManager/DashboardTest.php`

### Real-time (8)
| # | Test |
|---|---|
| 1 | Live status returns correct table counts |
| 2 | Live status returns current covers |
| 3 | Live status detects current service period |
| 4 | Today summary calculates revenue |
| 5 | Today summary compares with yesterday |
| 6 | Service snapshot returns current period data |
| 7 | Upcoming reservations returns chronological |
| 8 | Upcoming reservations excludes cancelled |

### Analytics (16)
| # | Test |
|---|---|
| 9 | Revenue analytics total correct |
| 10 | Revenue percentage change correct |
| 11 | Revenue chart has one entry per day |
| 12 | Covers analytics groups by date |
| 13 | Covers by service period correct |
| 14 | Affluence groups by hour |
| 15 | Affluence identifies peak hour |
| 16 | Popular items returns top sellers |
| 17 | Popular items filtered by food/drink |
| 18 | Average ticket calculation correct |
| 19 | Average ticket by service period |
| 20 | Average ticket by payment method |
| 21 | Reservation stats rates correct |
| 22 | All period filters work (today, 7d, 14d, 30d) |
| 23 | Custom date range works |
| 24 | Empty data returns zeros, not errors |

---

## 8. Cross-cutting Tests (16 tests)

**File:** `tests/Feature/Controllers/RestaurantManager/CrossCuttingTest.php`

| # | Test |
|---|---|
| 1 | Reservation confirmation notification sent |
| 2 | Reservation cancellation notification sent |
| 3 | Pre-order confirmed notification sent |
| 4 | New reservation notification to manager |
| 5 | Pusher event on table status change |
| 6 | Pusher event on new reservation |
| 7 | Pusher event on order paid |
| 8 | Cart cleanup expires carts after 4h |
| 9 | Cart cleanup frees tables |
| 10 | Cart cleanup ignores non-restaurant carts |
| 11 | Reservation reminder sent 2h before |
| 12 | Reservation reminder not duplicated |
| 13 | Daily summary compiled |
| 14 | Dashboard cache warm job runs |
| 15 | All translations exist (en, es, fr, zh) |
| 16 | Observer fires events on status change |

---

## 9. Seeder Tests (10 tests)

**File:** `tests/Feature/Seeders/RestaurantSeederTest.php`

| # | Test |
|---|---|
| 1 | Seeder runs without errors |
| 2 | 2 restaurants created |
| 3 | Correct table counts per restaurant |
| 4 | Menu categories with hierarchy |
| 5 | Menu items with allergens and images |
| 6 | Daily menus for 7 days |
| 7 | Reservations with mixed statuses |
| 8 | Paid orders with items |
| 9 | Restaurant manager employees created |
| 10 | Seeder idempotent (no duplicates on re-run) |

---

## 10. Unit Tests — Enums (22 tests)

**File:** `tests/Unit/Enums/RestaurantEnumsTest.php`

| # | Test |
|---|---|
| 1 | Allergen enum has exactly 14 values |
| 2 | All Allergen values have labels |
| 3 | DietaryLabel enum has 10 values |
| 4 | All DietaryLabel values have labels |
| 5 | RestaurantServicePeriod has 6 values |
| 6 | All RestaurantServicePeriod values have labels |
| 7 | RestaurantReservationStatus has 6 values |
| 8 | All RestaurantReservationStatus values have labels |
| 9 | RestaurantTableZone has 6 values |
| 10 | All RestaurantTableZone values have labels |
| 11 | RestaurantTableStatus has 4 values |
| 12 | All RestaurantTableStatus values have labels |
| 13 | RestaurantMenuCategoryType has 2 values |
| 14 | All RestaurantMenuCategoryType values have labels |
| 15 | OrderableType includes RESTAURANT_MENU_ITEM |
| 16 | OrderableType includes RESTAURANT_RESERVATION |
| 17 | AdminRole includes RESTAURANT_MANAGER |
| 18 | AdminRole RESTAURANT_MANAGER has label |
| 19 | RestaurantMenuItem implements Orderable |
| 20 | RestaurantReservation implements Orderable |
| 21 | RestaurantMenuItem morph key resolves |
| 22 | RestaurantReservation morph key resolves |

---

## Summary

| Test Group | File | Count |
|---|---|---|
| Authorization | `RestaurantManagerAuthorizationTest.php` | 10 |
| Menu System | `MenuSystemTest.php` | 30 |
| Tables | `TablesTest.php` | 18 |
| Reservations | `ReservationsTest.php` | 28 |
| Cart & Checkout | `CartCheckoutTest.php` | 30 |
| Customer API | `CustomerApiTest.php` | 22 |
| Dashboards | `DashboardTest.php` | 24 |
| Cross-cutting | `CrossCuttingTest.php` | 16 |
| Seeder | `RestaurantSeederTest.php` | 10 |
| Unit — Enums | `RestaurantEnumsTest.php` | 22 |
| **Total** | | **~210** |
