# Automated Testing & Quality Assurance Guide

This document details the test suites, execution procedures, assertion metrics, and CI/CD pipelines governing the Eniceberny Bakery and Culinary Hub platform.

---

## 1. Test Architecture & Standards

Quality assurance is enforced through comprehensive automated testing using **PHPUnit** and Laravel's HTTP test utilities:

- **Isolated In-Memory Database**: All test suites execute against high-speed in-memory SQLite instances (`:memory:`), guaranteeing complete test isolation without residual side-effects.
- **Automated Seeding Integration**: Test classes leverage the `RefreshDatabase` trait with `protected bool $seed = true;`, ensuring authentic catalog categories, menu delicacies, and role permissions are present during every test run.
- **Zero-Mock Financial Verification**: Payment callbacks, cart additions, discount deductions, and order conversions are executed against real Eloquent database models.

---

## 2. Comprehensive Test Suite Inventory (82 Tests, 378 Assertions)

The platform test suite contains **82 automated tests** across six specialized feature test classes:

| Test Suite Class | File Path | Tests | Key Focus Areas |
| :--- | :--- | :---: | :--- |
| **`AdminTest`** | `tests/Feature/AdminTest.php` | 13 | Access control, live dashboard metrics, order status updates, POS transactions, modular settings, brand logo uploads, security file rejections. |
| **`CmsAndBroadcastTest`** | `tests/Feature/CmsAndBroadcastTest.php` | 6 | Marketing copy updates, testimonials CRUD, CMS pages, email broadcast center, customer permission boundaries. |
| **`Phase25ErpAndGhanaComplianceTest`** | `tests/Feature/Phase25ErpAndGhanaComplianceTest.php` | 10 | Ghana Act 843 compliance, terms of service, granular staff permissions, public invoice lookups, catering conversion to orders, takeaway/dine-in POS modes. |
| **`Phase2CommerceTest`** | `tests/Feature/Phase2CommerceTest.php` | 20 | Customer account profiles, delivery address management, order history, Paystack webhooks, POS sales, coupon code validation, sliding cart drawer data. |
| **`Phase3OperationsAndCmsTest`** | `tests/Feature/Phase3OperationsAndCmsTest.php` | 10 | Admin navigation architecture, product variants and options, homepage sections, catering services/quotes, customer addresses ledger, audit log redaction, sitemaps. |
| **`StorefrontTest`** | `tests/Feature/StorefrontTest.php` | 14 | Cinematic landing page sections, shop catalog filters, end-to-end checkout flow, printable receipts, OTP verification, back-to-storefront auth buttons. |
| **`ExampleTest`** | `tests/Feature/ExampleTest.php` | 1 | Basic HTTP 200 health verification. |

---

## 3. Running Tests Locally

### 3.1 Run Complete Test Suite
Execute the entire test suite from the repository root:

```bash
php artisan test
```

Expected output:
```text
  PASS  Tests\Feature\AdminTest
  PASS  Tests\Feature\CmsAndBroadcastTest
  PASS  Tests\Feature\ExampleTest
  PASS  Tests\Feature\Phase25ErpAndGhanaComplianceTest
  PASS  Tests\Feature\Phase2CommerceTest
  PASS  Tests\Feature\Phase3OperationsAndCmsTest
  PASS  Tests\Feature\StorefrontTest

  Tests:    82 passed (378 assertions)
  Duration: ~15s
```

### 3.2 Run Specific Test Classes or Filters
Target individual feature areas during local development:

```bash
# Run only Admin tests
php artisan test --filter AdminTest

# Run only Storefront & Checkout tests
php artisan test --filter StorefrontTest

# Run Ghana compliance and ERP tests
php artisan test --filter Phase25ErpAndGhanaComplianceTest

# Run a specific single test method
php artisan test --filter test_catering_inquiry_can_be_converted_to_official_order
```

---

## 4. Continuous Integration Pipeline (GitHub Actions)

Every pull request and push to the `main` branch automatically triggers the automated CI/CD pipeline defined in `.github/workflows/ci.yml`:

```mermaid
graph TD
    A[Push / PR to main] --> B[GitHub Actions Runner: ubuntu-latest]
    B --> C[Setup PHP 8.4 with required extensions]
    B --> D[Setup Node.js 20 with npm cache]
    C --> E[composer install --prefer-dist --optimize-autoloader]
    D --> F[npm ci && npm run build]
    E --> G[Copy .env.example & Generate Key]
    F --> G
    G --> H[php artisan test --colors=always]
    H -->|All 82 Tests Pass| I[Production Render Deployment Trigger]
    H -->|Any Failure| J[Halt & Reject Deployment]
```

### CI Requirements:
- **PHP Version**: `8.4` (matching production runtime and Symfony 8.1 dependencies).
- **PHP Extensions**: `mbstring`, `xml`, `ctype`, `iconv`, `intl`, `pdo`, `pdo_sqlite`, `pdo_pgsql`, `bcmath`, `gd`, `zip`.
- **Node.js**: `20.x` compiling Tailwind v3 and Vite bundles.
- **Coverage**: Fast execution without xdebug overhead (`coverage: none`).
