# FieldOps Cloud Testing Strategy

## Goal

Validate FieldOps Cloud as a SaaS platform for trades and field-service businesses across tenant workflows, platform-admin workflows, billing foundations, import/export, integrations, mobile/PWA/offline readiness, and production release gates.

## Test Layers

| Layer | Purpose | Current Command Or Evidence |
| --- | --- | --- |
| Dependency checks | Ensure installable and no known vulnerable packages. | `composer install`, `composer validate`, `composer audit` |
| Service/regression tests | Validate business logic and previously fixed defects. | `composer test` |
| PHP lint | Catch syntax errors across application code. | `composer check` via `tools/lint-php.php` |
| Static route/action inventory | Catch dead links, form targets, anchors, and unhooked buttons. | `php tools\qa-inventory.php` |
| API contract harness | Verify active API route truth, JSON boundary errors, disabled webhook behavior, planned REST route absence, and API docs alignment. | `composer api-contract-harness` |
| Browser smoke | Validate routed pages, role scenarios, responsiveness, and console/page errors. | `tools/browser-smoke.cjs` against XAMPP |
| Role/RBAC browser walkthrough | Validate explicit role sessions, allowed/forbidden routes, sidebar visibility, and support login-as return. | `tools/role-walkthrough.cjs` against XAMPP |
| High-risk role interaction smoke | Validate selected click/form interactions across sensitive owner and restricted-role flows. | `tools/role-interaction-smoke.cjs` against XAMPP |
| Production auth/security smoke | Validate production-mode auth with demo disabled, CSP/security headers, session cookie policy, invalid login, signup, DB-backed role logins, and platform-admin isolation. | `tools/auth-production-smoke.cjs` |
| Database import | Validate schema and seed can load into MySQL. | Disposable XAMPP database import |
| Manual QA | Validate full workflows, UX, accessibility, and provider setup. | `docs/MANUAL_QA_SCRIPT.md` plus this strategy |

Browser automation intentionally blocks service workers and serves empty jsDelivr CSS/JS test stubs. This keeps local QA focused on FieldOps routes, RBAC, responsive behaviour, and console/page errors rather than PWA cache state or third-party CDN availability.

## Priority Coverage

1. Critical business flows:
   - Client create/view/edit.
   - Job create/view/edit/status/schedule.
   - Quote create/view/edit/approve/convert to invoice.
   - Invoice view/edit/payment state.
   - Customer portal token flow.
   - Import preview/validation/commit/undo.
   - Export gating by plan.
2. Money, data, and security paths:
   - Tenant isolation.
   - RBAC by role.
   - CSRF on mutating forms.
   - Billing plan/trial/grace-period actions.
   - Platform admin support login and tenant actions.
   - Audit log creation for sensitive actions.
   - CSV formula injection protection.
3. Integration boundaries:
   - Accounting provider settings for Xero, QuickBooks Online, Sage Accounting, Zoho Books, MYOB, FreeAgent, Reckon, SMEPlus, FreshBooks, and Wave.
   - Google Calendar and Outlook Calendar two-way sync settings.
   - LLM provider configuration without secret exposure.
4. Mobile and offline:
   - PWA manifest/service worker.
   - Mobile responsive layouts.
   - Offline technician queue.
   - Offline sync endpoint validation.
   - Capacitor Android/iOS project readiness.

## Required Permission Tests

Run route and workflow tests as:

- Public unauthenticated user.
- Trainee.
- Team Member.
- Supervisor.
- Manager.
- Director/Owner.
- Platform Admin.
- Platform Admin using support login as tenant admin.

For each role, verify:

- Allowed pages load.
- Forbidden pages return a controlled 403.
- Hidden UI actions are also blocked server-side.
- Tenant-scoped records cannot be accessed across tenants.

## Required Failure-Mode Tests

- Invalid login credentials.
- Expired/invalid portal token.
- Missing CSRF token.
- Invalid tenant support-login reason.
- Suspended tenant access.
- Expired trial and Basic plan export restriction.
- Duplicate client/team records where uniqueness applies.
- Invalid CSV headers and missing mandatory import fields.
- Malformed offline sync payload.
- Provider disconnected/expired integration token placeholders.

## Current Automated Status

Latest evidence is in `docs/PRODUCTION_READINESS_QA_REPORT.md`.

Current automated checks pass locally and in the XAMPP served copy, including:

- Composer install/validate/audit/test/check.
- Static route/action inventory with zero findings.
- Browser smoke across public, tenant-owner, and platform-admin scenarios on mobile/tablet/desktop.
- Role/RBAC browser walkthrough for Owner, Manager, Supervisor, Team Member, Trainee, Demo User, Platform Admin, and support login-as return flow.
- Gate 20 role interaction smoke for owner schedule booking, quote billing-point add/delete UI, restricted create-route denial, and import validation blocking.
- Gate 21 import payload replay foundation tests for bounded payload storage, delayed queue/claim, completion, failure metadata, expiry rejection, invalid-validation rejection, dashboard non-disclosure, and tenant-scoped lookup.
- Gate 22 API contract truth tests for JSON response envelopes, JSON `/api/*` 404/403 errors, API POST CSRF boundary behavior, disabled billing webhook JSON errors, active API-style route registration, planned REST route absence, and documentation truth markers.
- Gate 23 reports durability tests for tenant-backed job status, quote funnel, invoice revenue, technician workload, and unassigned backlog summaries.
- Gate 24 dashboard durability tests for tenant-backed job KPI totals, pending quote filtering, invoice follow-up counts, collected revenue, and removal of static dashboard trend placeholders.
- Gate 25 period-scoped summary tests for custom-range invoice revenue scoping and rendered `/reports` plus `/dashboard` period behavior.
- Gate 26 previous-period trend tests for comparable range calculation and rendered `/reports` plus `/dashboard` trend/comparison text.
- Gate 27 advanced report summary tests for productivity, first-time-fix proxy, quote conversion, engineer productivity, customer performance, profitability-readiness calculations, and rendered `/reports` advanced sections.
- Gate 28 saved report preset tests for validation, tenant-scoped session/database persistence, `/reports` open/save/delete rendering, and create/delete audit events.
- Gate 29 scheduled report delivery foundation tests for `manage_reports` RBAC, tenant-scoped queue persistence, duplicate prevention, `/reports` delivery queue rendering, route registration, and queue audit events.
- Gate 30 material-cost-backed profitability tests for linked invoice/job inventory movements, costed revenue, captured material cost, gross profit, margin, cost coverage, Reports UI rendering, and schema index presence.
- Gate 31 direct job cost capture tests for cost validation, tenant-scoped persistence, `manage_job_costs` RBAC, audit logging, job detail ledger rendering, demo reset coverage, direct cost report rollups, and MySQL lookup indexes.
- Gate 32 contract profitability tests for maintenance-agreement/job/invoice/billing-schedule/cost rollups, `/reports` Contract Profitability rendering, and exclusion of unlinked same-customer invoices.
- Gate 33 purchase-order accrual tests for committed/received PO line costs, draft/cancelled exclusion, tenant-scoped database reads, cross-tenant line isolation, demo reset coverage, and `/reports` Purchase-order accrual rendering.
- Gate 34 supplier-invoice matching tests for approved/posted supplier invoice actual costs, draft exclusion, matched purchase-order accrual replacement, tenant-scoped database reads, cross-tenant line isolation, demo reset coverage, and `/reports` Supplier invoice cost rendering.
- Gate 35 payroll/time-sheet import tests for mandatory payroll costing fields, row validation, tenant-scoped time-sheet database reads/writes, import commit/undo, draft payroll exclusion, demo reset coverage, and `/reports` Timesheet labour cost rendering.
- Gate 36 production workflow browser smoke for customer portal quote approval, invoice payment validation/sandbox recording, booking requests, DB-backed role matrices, support login-as/return, and XAMPP portal base-path form rendering.
- Production auth/security smoke with demo disabled, CSP/security headers, session cookie policy, DB-backed role login, invalid-login handling, signup, and platform-admin isolation.
- MySQL schema/seed disposable import.

## Production Release Gaps

The product is not production-ready until these remaining gates pass:

- Public REST API implementation and security tests if external API access becomes launch scope.
- Additional production-mode DB-backed browser interactions for high-risk non-owner workflows, building on the passing production role route matrix, Gate 20 XAMPP role interaction smoke, and Gate 36 production workflow smoke.
- Live report provider delivery, hosted worker execution, live payroll/provider sync, live accounting-provider cost imports, hosted-scale report rollups, and hosted report performance evidence.
- Live accounting/calendar OAuth, webhooks, sync workers, encrypted token storage, and provider activation tests.
- Live payment gateway capture, subscription-state mutation, reconciliation, and provider activation tests.
- Manual assistive-technology/WCAG accessibility audit beyond the automated Gate 8 smoke.
- Hosted import worker runner proof and hosted-scale import/export/performance tests.
- Native Android/iOS build, signing, store metadata, and physical-device QA.
