# Testing & Mock Server

## Testing & Mock Server

### Mock Server Overview

The mock server is a **full drop-in replacement** for the ChainGPT API. It provides:

* Realistic responses matching the live API schema
* Simulated latency for real-world behavior
* Credit tracking (no actual charges)
* Zero cost for unlimited testing

No API key is required to use the mock server.

***

### Setup

```bash
cd mock-server
npm install
npm run dev
```

The mock server starts on **localhost:3001**.

Point your environment at the mock server:

```bash
export CHAINGPT_BASE_URL=http://localhost:3001
```

All MCP server tools will automatically route requests to the mock server instead of the live API.

***

### Test Suite

The plugin includes **79 passing tests** across two test suites:

| Suite                      | Tests | Coverage                                       |
| -------------------------- | ----- | ---------------------------------------------- |
| MCP server unit tests      | 53    | All 12 tools, error handling, input validation |
| Mock server endpoint tests | 26    | All endpoints, response schemas, edge cases    |

#### Running Tests

```bash
# Run all tests
npm test

# Run MCP server tests only
npm run test:mcp

# Run mock server tests only
npm run test:mock

# Run with coverage
npm run test:coverage
```

***

### Validation Script

A structural validation script checks the entire plugin for correctness:

```bash
bash scripts/validate.sh
```

This runs **118 structural checks** including:

* File existence and naming conventions
* JSON schema validation for plugin.json and .mcp.json
* Markdown structure and link integrity
* Template completeness
* Reference doc cross-references

***

### CI Workflow

All tests run automatically on every push and pull request. The CI workflow:

1. Installs dependencies
2. Starts the mock server
3. Runs the full test suite (79 tests)
4. Executes the validation script (118 checks)
5. Reports results

***

### Using the Mock Server in Development

The mock server mirrors every endpoint of the live ChainGPT API:

```bash
# LLM Chat
curl http://localhost:3001/chat -X POST -H "Content-Type: application/json" \
  -d '{"question": "What is Ethereum?"}'

# NFT Generation
curl http://localhost:3001/nft/generate -X POST -H "Content-Type: application/json" \
  -d '{"prompt": "cyberpunk city"}'

# Contract Audit
curl http://localhost:3001/contract/audit -X POST -H "Content-Type: application/json" \
  -d '{"code": "pragma solidity ^0.8.0; contract Test {}"}'

# Check credit balance (simulated)
curl http://localhost:3001/credits/balance
```

Responses include the same fields, status codes, and error formats as the production API, making it safe to build and test integrations before going live.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.chaingpt.org/dev-docs-b2b-saas-api-and-sdk/chaingpt-claude-skill-and-plugin/resources/testing-and-mock-server.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
