# 12 - Factory QA Tools for BigOrders

**Status: PARTIALLY IMPLEMENTED (UI with Basic Workflow)**

## Summary

A page in Arda that runs full end-to-end tests of the order workflow using production systems with test-flagged data. Verifies the entire order-to-shipment pipeline without affecting real customer orders.

## Current State

An experimental UI page exists at `/experimental/qa-tools` with:
- Test configuration form (product type, customer email, IPD, priority, country)
- Test options checkboxes (create scan, simulate manufacturing, auto-pick, generate label, Shopify fulfillment)
- Step-by-step test runner with visual progress indicators
- Real-time logs panel
- Test results table showing pass/fail for each step
- Links to created test orders and shipments

**Existing files:**
- `webapps/src/components/Experimental/FactoryQATools.jsx` - Main QA tools page
- `webapps/src/components/Experimental/ExperimentalWrapper.jsx` - Navigation wrapper
- `webapps/src/components/Experimental/ExperimentalHome.jsx` - Home page
- `webapps/arda/app/App.jsx` - Route at `/experimental/qa-tools`

**Implemented test steps:**
1. Create Test Order (`POST /api/admin/shop/test_order`)
2. Verify Order Created (validates `origin: TestData`)
3. Send Scan Request (order action `SendScanRequest`)
4. Simulate Scan Completion (marks scan `ReadyForFabricator`)
5. Check Inventory
6. Create Shipment (`POST /api/admin/shipper/shipment`)
7. Pick Inventory Items (`PickInventoryItem` action)
8. Generate Shipping Label (`GenerateShippingLabel` action)
9. Verify Final State

**Existing test infrastructure:**
- `POST /api/admin/shop/test_order` creates orders with `origin: TestData`
- `tests/fabricator/004.AddTestOrders.ts` and `tests/fabricator/005.BigOrderFlow.ts` have reference implementations

## Requirements

1. Backend API for orchestrated test sequences (currently runs client-side)
2. Test cleanup functionality (delete test orders after testing)
3. More comprehensive validation at each step
4. Historical test run logging
5. Optionally move from experimental to main QA section in Arda

## Files to Create

| File | Purpose |
|------|---------|
| `webapps/src/components/QA/QATestRunner.jsx` | Component that executes and displays test progress |
| `webapps/src/components/QA/QATestStep.jsx` | Individual test step display with pass/fail |
| `webapps/src/components/QA/QATestReport.jsx` | Summary report after test completion |
| `api/src/fabricator/QAToolsApi.ts` | Backend API for running QA test sequences |

## Files to Modify

| File | Change |
|------|--------|
| `webapps/app/ArdaWrapper.jsx` | Add QA Tools navigation link (optional) |
| `apps/admin_api/admin_api.ts` | Register QA tools API routes |
| `api/src/fabricator/FabricatorAdminApi.ts` | Potentially add batch action execution endpoint |

## API Endpoints

| Method | Endpoint | Purpose |
|--------|----------|---------|
| POST | `/api/admin/qa/test-order` | Create test order with full configuration |
| POST | `/api/admin/qa/run-step` | Execute a single test step |
| POST | `/api/admin/qa/run-full-test` | Execute complete test sequence |
| GET | `/api/admin/qa/test-status/:id` | Get current test run status |
| DELETE | `/api/admin/qa/cleanup/:orderId` | Clean up test order and related data |

## Implementation Notes

- All test orders MUST have `origin: TestData`
- Shipping label generation should use Shippo's test mode to avoid charges
- Consider "dry run" mode that validates without making changes
- Add rate limiting to prevent accidental mass test creation
- Test results should be logged for historical tracking
