# FieldOps Cloud Test Plan Blueprint

Claude should use this blueprint to produce the final detailed test plan.

## 1. Test Strategy

Use layered testing:

1. Static checks
   - Composer validate
   - PHP lint
   - Route/action inventory
   - Documentation consistency checks

2. Unit/service tests
   - Validators
   - Calculators
   - RBAC
   - CSRF
   - Auth
   - Tenant subscription access
   - Import validation
   - AI assistant generation/redaction
   - Calendar/accounting/LLM provider registries

3. Repository/database tests
   - Tenant isolation
   - CRUD
   - Line item persistence
   - Audit log writes
   - Import created ids and undo
   - Payment fields

4. Controller/HTTP integration tests
   - Route status
   - Permission enforcement
   - CSRF enforcement
   - Redirects
   - Validation error rendering
   - JSON response contract

5. Browser E2E tests
   - Core user journeys by role
   - Mobile/tablet/desktop rendering
   - Form interactions
   - Calendar slot clicking
   - AI assistant generate click
   - Support login-as and return

6. Security tests
   - Auth and session hardening
   - RBAC negative tests
   - Tenant isolation
   - CSRF
   - XSS escaping
   - CSV injection
   - Secrets redaction
   - Support impersonation audit
   - Token tampering

7. Nonfunctional tests
   - Accessibility
   - Responsive layout
   - Performance baseline
   - Reliability under failed dependencies
   - Data backup/recovery plan

## 2. Test Data Strategy

Use at least four data sets:

1. Seed/demo happy path
   - Current `OperationsDemoData`
   - Known quote/invoice/job/client/team records

2. Tenant isolation data
   - Two tenants
   - Users in each tenant
   - Same client/quote/invoice names across tenants
   - Cross-tenant id attempts

3. Malicious/negative data
   - XSS strings: `<script>alert(1)</script>`
   - CSV formula strings: `=HYPERLINK(...)`, `+SUM(1,1)`, `@cmd`
   - Oversized strings
   - Invalid dates/times
   - Bad money values
   - Invalid emails
   - API-key-looking strings for AI assistant redaction

4. Boundary data
   - Zero and max tax rates
   - Large allowed line item quantity and unit price
   - Trial expiry today/yesterday/tomorrow
   - Overlapping bookings at exact start/end boundaries
   - Partial payment exactly one cent short of full payment

## 3. P0 Test Areas

P0 tests should block release:

- Auth/session production behavior
- RBAC tenant/platform isolation
- CSRF on non-API POST routes
- Quote and invoice financial calculation correctness
- Invoice payment and overdue state
- Tenant isolation in repositories
- Platform admin support login-as and return
- Platform billing override correctness
- Import commit/undo safety
- Export CSV injection protection
- Customer portal token validation
- Offline sync assigned-job scope
- AI assistant redaction and no external call/no mutation behavior

## 4. P1 Test Areas

- Job create/edit/detail/search/filter
- Schedule calendar booking and conflict detection
- Client create/edit/view/search
- Team create/edit/view and role validation
- Recurring job generation/pause/resume
- Dispatch technician/crew assignment
- Quote-to-invoice conversion
- Accounting provider registry and sandbox validation
- Calendar provider registry and sync strategy
- LLM settings validation
- Pricing admin multi-currency/discount/trial controls
- Demo management explicit reset

## 5. P2 Test Areas

- Dashboard/report count accuracy
- Mobile/PWA installability and visual polish
- Platform health/security/mobile status placeholders
- Accessibility labels and keyboard navigation
- Empty states
- Browser console cleanliness

## 6. Functional E2E Journeys

Claude should convert these to executable test cases:

1. Owner full operations journey
   - Sign in or demo company admin
   - Create client
   - Create job for client
   - Book schedule appointment
   - Create quote
   - Approve or convert quote to invoice
   - Record partial and full payment
   - Export data

2. Supervisor operations journey
   - View dashboard
   - Create job
   - Dispatch technician
   - Book schedule
   - Create quote
   - Confirm invoice creation is denied if role lacks permission

3. Team member field journey
   - View assigned job
   - Update assigned job
   - Use offline mode
   - Save offline update
   - Sync
   - Confirm unassigned job is inaccessible

4. Trainee restricted journey
   - Dashboard/jobs/clients visible
   - Schedule/quotes/invoices/team/import/export/AI denied
   - No hidden links should permit server access

5. Platform admin journey
   - Open `/platform-admin`
   - View tenants
   - View tenant detail
   - Start support login-as with reason
   - Work as tenant admin
   - Return to platform admin
   - Verify audit/history

6. Platform billing journey
   - View billing ledger
   - Override next invoice with valid amount/reason
   - Attempt invalid override
   - Resume automatic invoicing
   - Link platform accounting sandbox provider

7. Import/export journey
   - Select each import type
   - Validate valid CSV
   - Validate invalid CSV
   - Commit valid preview
   - Undo
   - Export all datasets

8. AI assistant journey
   - Open `/ai-assistant`
   - Generate quote response
   - Generate schedule response
   - Include fake secrets and verify redaction
   - Confirm no operational record changes

9. Customer portal journey
   - Open signed quote portal
   - Approve quote
   - Decline quote
   - Open invoice portal
   - Open job status portal
   - Tamper token and verify denial

10. Mobile/PWA/offline journey
   - Open mobile viewport
   - Confirm sidebar/nav usable
   - Load offline route
   - Save offline change
   - Sync assigned job
   - Verify unassigned job rejection

## 7. Module Test Case Seeds

### Auth/RBAC

- AUTH-001: valid login creates session.
- AUTH-002: invalid login fails without session.
- AUTH-003: logout clears session.
- AUTH-004: signup creates owner session.
- AUTH-005: production-like env disables demo auto-login.
- RBAC-001: owner denied platform admin.
- RBAC-002: platform admin denied tenant jobs without support session.
- RBAC-003: trainee denied AI assistant.
- RBAC-004: demo_user denied platform admin.
- RBAC-005: support impersonation restores original platform admin.

### CSRF

- CSRF-001: every non-API POST without token returns 403.
- CSRF-002: every non-API POST with tampered token returns 403.
- CSRF-003: valid token permits route execution.
- CSRF-004: API routes are separately validated.

### Financial

- MONEY-001: quote line item totals with tax.
- MONEY-002: invoice line item totals with tax.
- MONEY-003: large valid values.
- MONEY-004: invalid negative unit price.
- MONEY-005: invalid zero quantity.
- MONEY-006: decimal rounding stable.
- MONEY-007: quote-to-invoice preserves totals.

### Schedule

- SCH-001: week starts Monday.
- SCH-002: previous/current/next navigation.
- SCH-003: click slot fills date/time.
- SCH-004: existing client booking.
- SCH-005: potential client booking.
- SCH-006: invalid potential email.
- SCH-007: conflict same technician id.
- SCH-008: conflict same technician name.
- SCH-009: adjacent bookings do not conflict.

### Import/Export

- IMP-001: each type required fields.
- IMP-002: aliases normalise.
- IMP-003: invalid preview blocks commit.
- IMP-004: commit stores records.
- IMP-005: undo removes records.
- EXP-001: Basic live export blocked.
- EXP-002: Pro trial live export allowed.
- EXP-003: formula injection escaped.

### AI

- AI-001: quote mode response.
- AI-002: schedule mode response.
- AI-003: general mode response.
- AI-004: invalid mode returns 422.
- AI-005: trainee denied.
- AI-006: CSRF required.
- AI-007: secrets redacted.
- AI-008: no data mutation.

### Platform Admin

- PA-001: platform admin loads.
- PA-002: tenant roles denied.
- PA-003: tenant detail tabs visible.
- PA-004: suspend tenant requires confirmation and audit.
- PA-005: resume tenant requires confirmation and audit.
- PA-006: start/extend/end trial.
- PA-007: change plan.
- PA-008: billing override valid.
- PA-009: billing override invalid.
- PA-010: support login reason required.
- PA-011: support session expiry.
- PA-012: return to platform admin.
- PA-013: demo reset explicit only.

## 8. Automation Recommendations

Short term:

- Expand `tests/run.php` into grouped test files or PHPUnit suites.
- Keep `composer check` as quick local gate.
- Keep `tools/qa-inventory.php`.
- Expand Playwright coverage in `tools/browser-smoke.cjs` and `tools/role-walkthrough.cjs`.

Medium term:

- Add database fixture setup/teardown script.
- Add repository isolation tests for every entity.
- Add API contract tests for current API routes.
- Add accessibility checks with axe or equivalent.
- Add CI workflow that runs composer validate, install, test, check, browser smoke.

Long term:

- Add production-like environment smoke with demo disabled.
- Add provider sandbox contract tests when OAuth credentials exist.
- Add LLM live-provider tests only after encrypted keys and audit logging are implemented.
- Add mobile app build and store-readiness pipeline after native requirements are complete.

## 9. Release Gate Recommendation

Do not approve production until:

- Production auth and demo disablement are verified.
- Tenant isolation tests exist for all repositories.
- P0 financial tests are complete.
- Platform support impersonation audit is complete.
- Import/export safety tests are complete.
- Customer portal token tests are complete.
- Security review passes.
- Live integrations are either implemented and tested or clearly disabled.
- Public API docs match active routes.
- Backup/restore and deployment runbooks exist.

