# Testing your integration

> How to test code that calls the API without calling the API, and what to check before you go live.

Type: Guide. Updated 2 December 2026. Page: https://www.colossium.cloud/docs/testing

## Do not test against your real organisation

There is no test mode. Requests made with a token are real requests: they are reviewed, and approved ones create real services that can cost money. So:

- **Unit and contract tests** use a stand-in for the API that you control. This is where most of your testing belongs.
- **An end-to-end check** uses a separate organisation made for testing, on the Free plan, with its own token. Never point automated tests at the organisation that runs your business.
- **Cancel** what you made, and remove test resources, afterwards.

## A stand-in for the API

The reference clients are tested with a small server that speaks the API's contract: the same paths, headers, statuses and error shape. You can do the same in a few lines. This is the pattern used by this documentation's own tests:

```typescript
import { createServer } from "node:http"

const server = createServer((req, res) => {
  const send = (status: number, body: unknown, headers = {}) => {
    res.writeHead(status, { "content-type": "application/json", "x-request-id": "req_test", "x-ratelimit-limit": "120", "x-ratelimit-remaining": "100", "x-ratelimit-reset": "1", ...headers })
    res.end(JSON.stringify(body))
  }
  if (req.headers.authorization !== `Bearer ${TOKEN}`) return send(401, { error: { code: "invalid_token", message: "The token is not valid.", request_id: "req_test", doc_url: "https://docs.colossium.cloud/errors#invalid_token" } })
  if (req.url === "/v1/token/verify") return send(200, { id: "...", name: "test", status: "active", scopes: ["resource.read", "resource.write"] })
  // ...the endpoints your code uses
})
server.listen(0)
// new Colossium({ token: TOKEN, baseUrl: `http://127.0.0.1:${port}/v1`, sleep: async () => {} })
```

Pass `sleep: async () => {}` to the client in tests so retries do not slow the suite.

## What to test

| Case | What you are checking |
| --- | --- |
| The token is rejected (401) | You stop and alert, and do not retry in a loop. |
| A 429 with `Retry-After` | You wait, then succeed. |
| A 503 on a GET, and on a POST with a key | You retry and make one thing, not two. |
| A repeated idempotency key | You treat `200` with `Idempotent-Replayed: true` as success, and as the same request. |
| A 400 with `details.problems` | You surface the problems and do not retry. |
| A request that stays `awaiting_approval` | You wait without timing out, up to your limit, then report clearly. |
| A request that ends `failed` | You report `failure` and exit non-zero. |
| A list with several pages | You read all of them. |
| Your logs | Search them for the token. It must not be there. |

## Check against the OpenAPI file

The API's description is at `/v1/openapi.json`. Fetch it in a test and check that every path and method your code uses exists, so that you find out about a removed endpoint in your tests and not in production. [Using the OpenAPI file](/docs/openapi).

```bash
curl -s https://api.colossium.cloud/v1/openapi.json | jq -r '.paths | to_entries[] | .key as $p | .value | keys[] | "\(. | ascii_upcase) \($p)"'
```

## Before you go live

1. The token has the **fewest scopes** that work, a **project limit** if possible, and an **expiry**.
2. The token is in a **secrets manager**, and appears nowhere in your repository history (search it).
3. Your code **retries only what is safe**, with backoff, and respects `Retry-After`.
4. Every POST of a request has an **idempotency key** that is built from the intent and holds no personal data.
5. Logs hold the **request id and error code**, and no tokens, headers or personal data.
6. You know **who to tell and what to do** if the token leaks: [the runbook](/docs/security#leaked).
7. You have read [Data protection for builders](/docs/data-protection) and recorded what your integration does with personal data.
