# Testing

## Automated tests included
Local runs use PHP's built-in server with SQLite (`WACLOUD_TEST_DB`) — no MySQL needed.

```bash
export WACLOUD_TEST_DB=$PWD/storage/dev.sqlite
php database/install.php "Test Admin" admin@waclouds.com 'AdminPass123!'
php -S 127.0.0.1:8099 -t public_html tests/router.php &
python3 tests/e2e.py                       # 71 checks
# integration (mock WHMCS + MTN MoMo):
php -S 127.0.0.1:8098 tests/mock_apis.php &
#   create app/config.php with whmcs.url & mtn.base_url = http://127.0.0.1:8098, identifier 'mockid', both enabled
python3 tests/integration.py               # 19 checks
```

Results at hand-over: **e2e 71/71 passed, integration 19/19 passed.**

`e2e.py` covers: enquiry submission + validation + honeypot; ERP quotation request; solution finder; consultation booking, meeting link and manage page; guest order → registration → order resumed → invoice with separate setup and recurring fees; bank transfer stays pending; finance verification requires statement confirmation; subscription activation; automatic project and website tracker creation; receipt; prorated upgrade invoice; coupon validation; ticket creation and staff reply; lead pipeline; milestone client approval; every admin and portal page renders; client blocked from admin (403); another client cannot open someone else's invoice (404); CSRF enforced (419); AI training cohort, participants and completion report.

`integration.py` covers: live domain search via WHMCS `DomainWhois`, registered-domain detection, suggestions, cart and 2-year period, checkout creating a WHMCS order, WACLOUD domain price written to the WHMCS invoice, MTN MoMo request-to-pay, status verification, `AddInvoicePayment` to WHMCS, "Processing" until registrar confirms, cron sync to "Registered", OTP step-up required before nameserver change, nameserver update at registrar.

## Pre-launch acceptance checklist (with live credentials)
Run these on the production domain with real sandbox/live accounts. Tick each one:

- [ ] New customer registration (WHMCS client auto-created)
- [ ] Login, logout and password recovery email
- [ ] Contact form → reference number email, sales notification, lead in CRM with assignee
- [ ] Service subscription → invoice → MTN MoMo payment (small amount) → automatic confirmation & receipt
- [ ] Airtel Money payment → confirmation
- [ ] Card payment through Pesapal → confirmation
- [ ] Bank transfer → pending → Finance verification → paid
- [ ] Hosting order (WHMCS-mapped package) → WHMCS invoice paid → cPanel account provisioned
- [ ] Domain search, register a cheap .com, pay → registrar confirmation → appears as Registered
- [ ] Domain transfer with EPP code
- [ ] Renewal invoice generated (set a test subscription's next due date to within 7 days and run cron)
- [ ] Support ticket created, staff reply, email + SMS received
- [ ] Consultation booking → Zoom/Meet/Teams link, calendar invite, consultant email, 24 h & 1 h reminders
- [ ] Reschedule and cancel from email link
- [ ] Email, SMS and WhatsApp delivery (check *Communications* log for failures)
- [ ] Each staff role sees only its permitted areas
- [ ] Mobile and tablet check on Android Chrome and iPhone Safari
- [ ] Google Search Console sitemap submitted; GA4 receiving traffic
- [ ] Backup downloaded and test-restored
