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.- 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.
checkin.scanned for the right user, once, with a stable key.
Python: the client takes a
transport, a function that makes the HTTP call. Give it one that answers from a list, as below.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.- 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.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
receiptslist, and with an error: pass a fake that fails. - That your webhook endpoint rejects a bad signature and answers
2xxquickly. Webhooks.