# Fixtures & Test Data

Mock API responses for predictable verification.

## Overview

Fixtures provide predictable test data during verification. Instead of hitting real APIs (which may vary, require auth, or be rate-limited), fixtures return consistent mock responses.

## When to Use Fixtures

- **Data-dependent pages**: Dashboards, profiles, listings
- **Third-party APIs**: Stripe, analytics, CMS
- **Edge cases**: Empty states, errors, large datasets

## Fixture Sources

### 1. Local Files

```json
{
  "fixtures": [
    { "pattern": "/api/user", "source": "file://fixtures/user.json" },
    { "pattern": "/api/products", "source": "file://fixtures/products.json" }
  ]
}
```

### 2. Staging URLs

```json
{
  "fixtures": [
    { "pattern": "/api/dashboard", "source": "https://staging.example.com/api/dashboard" }
  ]
}
```

### 3. S3 Buckets

```json
{
  "fixtures": [
    { "pattern": "/api/analytics", "source": "s3://my-bucket/fixtures/analytics.json" }
  ]
}
```

### 4. Passthrough

```json
{
  "fixtures": [
    { "pattern": "/api/public/*", "source": "passthrough" }
  ]
}
```

## Pattern Matching

| Pattern | Matches | Example |
|---------|---------|---------|
| `/api/user` | Exact path | /api/user |
| `/api/users/*` | Single segment | /api/users/123 |
| `/api/**` | Multi-segment | /api/users/123/posts |
| `/api/users/:id` | Named param | /api/users/abc-123 |

## Recording Fixtures

```bash
npx -y @haystackeditor/cli@latest record-fixture \
  --url "https://staging.example.com/api/dashboard" \
  --output "fixtures/dashboard.json"
```

## Fixture Variants

Different data for different scenarios:

```json
{
  "fixtures": [{
    "pattern": "/api/products",
    "source": "file://fixtures/products.json",
    "variants": {
      "empty": "file://fixtures/products-empty.json",
      "large": "file://fixtures/products-large.json"
    }
  }],
  "flows": [{
    "name": "Empty products page",
    "fixture_variant": "empty",
    "steps": [...]
  }]
}
```
