# Testing Execution Guide
# mockupAWS v1.0.0

This guide provides step-by-step instructions for executing all QA tests for mockupAWS v1.0.0.

## Prerequisites

### Required Tools
- Node.js 20+
- Python 3.11+
- Docker & Docker Compose
- k6 (for performance testing)
- Trivy (for container scanning)
- GitLeaks (for secrets scanning)

### Optional Tools
- Snyk CLI (for dependency scanning)
- SonarScanner (for SAST)
- OWASP ZAP (for DAST)

## Quick Start

```bash
# 1. Start the application
docker-compose up -d

# 2. Wait for services to be ready
sleep 30

# 3. Run all tests
./testing/run-all-tests.sh
```

## Individual Test Suites

### 1. Performance Tests

```bash
cd testing/performance

# Run smoke test
k6 run scripts/smoke-test.js

# Run load tests (100, 500, 1000 users)
k6 run scripts/load-test.js

# Run stress test
k6 run scripts/stress-test.js

# Run benchmark test
k6 run scripts/benchmark-test.js

# Or use the test runner
./scripts/run-tests.sh all
```

### 2. E2E Tests

```bash
cd frontend

# Install dependencies
npm install

# Run all E2E tests
npm run test:e2e:ci

# Run with specific browsers
npx playwright test --project=chromium
npx playwright test --project=firefox
npx playwright test --project=webkit

# Run visual regression tests
npx playwright test --config=playwright.v100.config.ts --project=visual-regression

# Run with UI mode for debugging
npm run test:e2e:ui
```

### 3. Security Tests

```bash
cd testing/security

# Run all security scans
./scripts/run-security-tests.sh

# Individual scans:

# Snyk (requires SNYK_TOKEN)
snyk test --file=../../pyproject.toml
snyk test --file=../../frontend/package.json

# Trivy
trivy fs --severity HIGH,CRITICAL ../../
trivy config ../../Dockerfile

# GitLeaks
gitleaks detect --source ../../ --verbose

# OWASP ZAP (requires running application)
docker run -t ghcr.io/zaproxy/zaproxy:stable zap-baseline.py -t http://host.docker.internal:8000
```

### 4. Unit & Integration Tests

```bash
# Backend tests
cd /home/google/Sources/LucaSacchiNet/mockupAWS
uv run pytest -v

# Frontend tests
cd frontend
npm test
```

## Test Environments

### Local Development
```bash
# Use local URLs
export TEST_BASE_URL=http://localhost:5173
export API_BASE_URL=http://localhost:8000
```

### Staging
```bash
export TEST_BASE_URL=https://staging.mockupaws.com
export API_BASE_URL=https://api-staging.mockupaws.com
```

### Production
```bash
export TEST_BASE_URL=https://app.mockupaws.com
export API_BASE_URL=https://api.mockupaws.com
```

## Test Reports

After running tests, reports are generated in:

- **Performance:** `testing/performance/reports/`
- **E2E:** `frontend/e2e-v100-report/`
- **Security:** `testing/security/reports/`

## CI/CD Integration

### GitHub Actions

```yaml
name: QA Tests
on: [push, pull_request]

jobs:
  performance:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Run Performance Tests
        run: |
          docker-compose up -d
          sleep 30
          cd testing/performance
          ./scripts/run-tests.sh smoke

  e2e:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Run E2E Tests
        run: |
          cd frontend
          npm ci
          npx playwright install
          npm run test:e2e:ci

  security:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Run Security Tests
        run: |
          cd testing/security
          ./scripts/run-security-tests.sh
```

## Troubleshooting

### Performance Tests
- **Issue:** Connection refused
  - Solution: Ensure application is running on port 8000
  
- **Issue:** High memory usage
  - Solution: Reduce VUs or run tests sequentially

### E2E Tests
- **Issue:** Tests timeout
  - Solution: Increase timeout in playwright config
  
- **Issue:** Flaky tests
  - Solution: Use retry logic, improve selectors

### Security Tests
- **Issue:** Tool not found
  - Solution: Install tool or use Docker version
  
- **Issue:** Permission denied
  - Solution: Make scripts executable with `chmod +x`

## Test Data Management

Test data is automatically created and cleaned up during E2E tests. To manually manage:

```bash
# Clean all test data
./testing/scripts/cleanup-test-data.sh

# Seed test data
./testing/scripts/seed-test-data.sh
```

## Support

For issues or questions:
- Performance tests: QA Team
- E2E tests: QA Team  
- Security tests: Security Team
- General: DevOps Team

---

**Document Version:** 1.0.0  
**Last Updated:** 2026-04-07
