# API Tests

This directory contains integration and contract tests for the eMoney Token Factory API.

## Test Structure

```
test/api/
├── integration/          # Integration tests
│   ├── rest-api.test.ts
│   └── graphql.test.ts
└── contract/             # Contract validation tests
    ├── openapi-validation.test.ts
    └── event-schema-validation.test.ts
```

## Running Tests

```bash
# Run all tests
pnpm test

# Run only integration tests
pnpm run test:integration

# Run only contract tests
pnpm run test:contract

# Watch mode
pnpm run test:watch
```

## Test Types

### Integration Tests

Test actual API endpoints against running services:
- REST API operations
- GraphQL queries and mutations
- End-to-end flows

### Contract Tests

Validate that implementations conform to specifications:
- OpenAPI schema validation
- AsyncAPI event schema validation
- Request/response format validation

## Mock Servers

Use mock servers for testing without requiring full infrastructure:

```bash
# Start all mock servers
cd api/tools/mock-server
pnpm run start:all

# Or start individually
pnpm run start:rest      # REST API mock (port 4010)
pnpm run start:graphql   # GraphQL mock (port 4020)
```

## Test Environment

Set environment variables:

```bash
export API_URL=http://localhost:3000
export GRAPHQL_URL=http://localhost:4000/graphql
export ACCESS_TOKEN=your-test-token
```

