# Task 27 — System Tests

## Goal
Build the system-wide testing phase for ERPdash after the main modules are implemented.
This task is intentionally separated from feature development to keep implementation flow lightweight.

---

## Scope

This task covers:
- feature tests for implemented modules
- permission tests
- integration tests for key business flows
- smoke tests for dashboard and reports

This task does NOT cover:
- browser automation
- load testing
- external API contract testing

---

## Testing Strategy

Testing is divided into:

1. Core tests
2. Finance tests
3. Inventory tests
4. Sales tests
5. HR tests
6. System tests

---

## Core Tests

Modules:
- Branches
- Number Sequences
- Settings
- Fiscal Years
- Fiscal Periods
- Cost Centers

Examples:
- CRUD permissions work
- translated fields save correctly
- branch-scoped settings override system settings
- number sequences increment correctly
- fiscal periods close correctly

---

## Finance Tests

Modules:
- Accounts
- Journals
- Journal Entries
- Posting Engine
- Trial Balance
- General Ledger
- Income Statement

Examples:
- account hierarchy saves correctly
- journal entries save with lines
- posting rejects unbalanced entries
- posting rejects closed periods
- posting updates balances correctly
- trial balance query returns expected totals
- general ledger only shows posted entries
- income statement calculates net result correctly

---

## Inventory Tests

Modules:
- Warehouses
- Items
- Stock Movements
- Stock Report

Examples:
- warehouse and item CRUD permissions
- stock movement only allows stock items
- stock report totals are correct

---

## Sales Tests

Modules:
- Customers
- Sales Orders
- Invoices
- Sales Reports

Examples:
- customer CRUD permissions
- sales order saves with lines
- invoice totals calculate correctly
- sales report filters work correctly

---

## HR Tests

Modules:
- Employees
- Payroll
- Payroll Summary

Examples:
- employee CRUD permissions
- payroll net salary calculation
- payroll summary totals

---

## System Tests

Modules:
- Notifications
- Audit Logs
- Dashboard Analytics

Examples:
- notifications list is accessible with permission
- audit logs view permission works
- dashboard KPIs load without crashing

---

## Files

Suggested test locations:
- tests/Feature/Core/
- tests/Feature/Finance/
- tests/Feature/Inventory/
- tests/Feature/Sales/
- tests/Feature/HR/
- tests/Feature/System/

Optional support files:
- factories
- seeders
- test helpers

---

## Permissions Validation

Every secured route should have permission coverage where applicable.

Examples:
- 403 for unauthorized user
- 200/302 for authorized user based on screen flow

---

## Suggested Order

### Step 1
Audit existing tests and missing coverage.

### Step 2
Create/complete Core tests.

### Step 3
Create/complete Finance tests.

### Step 4
Create/complete Inventory tests.

### Step 5
Create/complete Sales tests.

### Step 6
Create/complete HR tests.

### Step 7
Create/complete System tests.

### Step 8
Run full test suite and summarize results.

---

## Notes for AI

- Follow docs/ai/AI_MASTER_PROJECT.md
- Follow docs/ai/ARCHITECTURE_RULES.md
- Follow docs/ai/AI_EXECUTION_RULES.md
- Execute one test group at a time
- Do not rewrite implemented modules unless a failing test proves a bug
- Wait for confirmation after each step

