# Test Utilities

Shared test patterns from `@modyo/mcp-shared`.

## Quick Start

```typescript
import {
  test,
  expect, describe, it,
  setupToolTest,
  parseResultJSON,
  STANDARD_PAGINATION_CASES,
} from "@modyo/mcp-shared";
```

## Test Fixtures

Use `test` for automatic fixture injection:

```typescript
test("should register tool", async ({ server, organizations, logger }) => {
  MyTool.registerTool(server, organizations, logger);
  expect(server.registerTool).toHaveBeenCalled();
});

test("should handle request", async ({ testSetup }) => {
  const handler = testSetup.extractHandler();
  const result = await handler({ action: "list" });
  expect(result).toBeDefined();
});
```

## Mock Creators

| Function | Purpose |
|----------|---------|
| `createMockServer()` | Mock MCP server |
| `createMockOrganizations(orgs?)` | Mock platform map |
| `createMockLogger()` | Mock logger |
| `setupToolTest()` | Complete setup |

## Parametrized Cases

```typescript
import { STANDARD_PAGINATION_CASES } from "@modyo/mcp-shared";

it.each(STANDARD_PAGINATION_CASES)(
  "should handle $description",
  async ({ params }) => {
    await handler({ ...params });
  }
);
```

Available constants:
- `STANDARD_PAGINATION_CASES`
- `STANDARD_ID_CASES`
- `STANDARD_QUERY_CASES`
- `STANDARD_LIST_CASES`

## Result Helpers

| Function | Purpose |
|----------|---------|
| `parseResultJSON<T>(result)` | Parse JSON from result |
| `extractResultText(result)` | Extract text content |
| `isCallToolResult(result)` | Type guard |

## Coverage Thresholds

| Metric | Threshold |
|--------|-----------|
| Lines | 80% |
| Statements | 80% |
| Functions | 80% |
| Branches | 75% |

## Running Tests

```bash
npm run test:run                # All tests
npm run test:coverage           # With coverage
npm test -- --run src/file      # Single file
```
