> ## Documentation Index
> Fetch the complete documentation index at: https://docs.getlurk.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Test your integration

> A fake client with no network, a Staging project for the real thing, and a clock you can move.

Three levels, from cheap to thorough. Use as many as you like.

## 1. A fake client, for your unit tests

Your code should not need the internet to be tested. The TypeScript SDK ships a real client whose network is replaced by answers you give it, and a list of what it was asked.

```typescript theme={null}
import { createFakeLurk } from "@getlurk/sdk/testing";

const { lurk, calls } = createFakeLurk({
  "events.send": { activity: "act_1", event: "evt_1", user: "u", receipts: [], skipped: [] },
});

await lurk.events.send({ event: "checkin.scanned", user: "maya@example.com" });

console.log(calls[0]?.operation); // "events.send"
console.log(calls[0]?.input); // what your code sent
console.log(calls[0]?.idempotencyKey); // the key it made; the same on every retry
```

* It is the real client, so your code gets real idempotency keys, real parsing and the same errors.
* The answers are typed: a wrong shape is a compile error.
* An operation you gave no answer for fails with a message that says what to add, instead of quietly returning nothing.
* An answer can be a function of the request, and an error answer lets you test your retry and failure paths.

Your tests then check what your code did, not what Lurk did: that it sent `checkin.scanned` for the right user, once, with a stable key.

> [!NOTE]
>
> Python: the client takes a `transport`, a function that makes the HTTP call. Give it one that answers from a list, as below.

```python theme={null}
import json

from getlurk import Lurk, Response


def fake_transport(method, url, headers, body, timeout):
    calls.append((method, url, json.loads(body) if body else None))
    return Response(200, {"content-type": "application/json"}, json.dumps({"receipts": [], "skipped": []}).encode())


calls = []
lurk = Lurk("lurk_sk_test_key", transport=fake_transport)
lurk.events.send(event="checkin.scanned", user="maya@example.com")
assert calls[0][1] == "https://api.getlurk.com/v1/events"
```

## 2. A Staging project, for the real thing

For a test that talks to Lurk itself, use a **Staging** project and its key. It is a project of its own: its people, units, rules and receipts are separate from Production's, and nothing in it reaches your real users.

```bash theme={null}
export LURK_KEY=lurk_sk_…   # a Staging project's key
node test-against-lurk.mjs
```

* Use a recognisable user, such as `ci-test-user@example.com`, and a new idempotency key for each run, so a test does not collide with the last one.
* Rules must be live to run. A person takes a Staging rule live in the dashboard, once.
* Nothing is ever deleted from a ledger: a test run leaves receipts. That is by design and costs nothing; use a fresh test user if you want clean balances.

## 3. A clock you can move

Rules that depend on time (a streak of days, "once a week", a unit that expires in 30 days) are tested by moving the **Staging project's clock**, not by waiting.

```bash theme={null}
# Where is the clock?
curl https://api.getlurk.com/v1/clock -H "Authorization: Bearer $LURK_KEY"

# Move it forward three days: the next event happens "three days later"
curl -X POST https://api.getlurk.com/v1/clock/advance \
  -H "Authorization: Bearer $LURK_KEY" -H "Content-Type: application/json" \
  -H "Idempotency-Key: advance-3d-1" -d '{ "days": 3 }'

# Back to real time
curl -X POST https://api.getlurk.com/v1/clock/reset -H "Authorization: Bearer $LURK_KEY" -H "Idempotency-Key: reset-1"
```

The clock exists only in Staging projects. Production's is always real time. The change moves forward only for what happens after it: it does not rewrite receipts already written. Reset it when you are done, so the next person's tests see the real time.

## What to test

* That your code sends the event once per real thing, with a key built from something stable (an order ID).
* That a retry after a timeout does not give twice: send the same event and key again and look at the answer.
* That your code copes with an empty `receipts` list, and with an error: pass a fake that fails.
* That your webhook endpoint rejects a bad signature and answers `2xx` quickly. [Webhooks](https://docs.getlurk.com/webhooks.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.