# Testing & Quality Assurance

## Test Strategy

### Unit Tests
- Financial calculation functions (margins, taxes)
- Webhook signature validation
- Data transformation functions
- Required: 90% coverage on core automation logic

### Integration Tests
- Stripe webhook handling (payment success, failed, refunded)
- Calendly booking → Pipedrive → Notion flow
- Typeform → Pipedrive → Dashboard update
- Required: All critical paths covered

### Manual Testing
- Booking flow end-to-end
- Invoice generation and payment
- Dashboard data accuracy
- Mobile responsiveness

## Quality Gates

1. **Code Review**: All workflow changes require peer review
2. **Staging**: Test all changes in staging environment first
3. **Monitoring**: Enable webhook logging and alerting
4. **Backups**: Daily database dumps, weekly full backups

## Testing Tools

- **Jest**: Unit tests for utility functions
- **Playwright**: E2E tests for website and booking flow
- **Postman**: API testing for Stripe, Pipedrive, Calendly
- **cURL**: Manual webhook testing

## Test Data

### Stripe Test Cards
- Success: `4242 4242 4242 4242`
- Decline: `4000 0000 0000 0002`
- Refund: `4000 0000 0000 0005`

### Pipedrive Test Leads
- Create test lead before each integration test
- Clean up test data after test completion

### Webhook Test Events
- Use Stripe CLI: `stripe trigger payment_intent.succeeded`
- Use ngrok for local webhook testing

## Monitoring & Alerting

### Critical Alerts (immediate response)
- Webhook processor down
- Payment processing failure
- Capacity limit reached (>95%)

### Daily Checks (end of day review)
- Revenue reconciliation
- Failed workflow count
- Booking conversion rate

### Weekly Reviews
- Conversion funnel analysis
- Client satisfaction scores
- System performance metrics

## Deployment Checklist

Before any production deployment:
- [ ] All tests passing (unit + integration)
- [ ] Staging environment verified
- [ ] Backup taken
- [ ] Monitoring alerts configured
- [ ] Rollback plan documented