Testing your integration
Run the stack locally, send test alerts without waking anyone, and test your webhook receiver.
There is no hosted sandbox yet, so you test against your own copy. It takes two commands.
#Run it locally
docker compose up -d --wait # Postgres
npm run migrate # schema
npm run seed # a development org: people, a team, a schedule, a policy
CARRIER_MODE=simulate npm run dev # the API on :3100 (and `npm run worker` for escalation timers)CARRIER_MODE=simulate sends nothing: pushes, texts and calls are faked, with receipts, so the whole pipeline runs without waking a person or spending money. Never use it in production (the server refuses to start in production with it on).
Then get keys for the examples and the CLI:
eval "$(npm run -s example:env)" # exports TREASON_API_URL, TREASON_API_KEY, TREASON_ADMIN_KEY, TREASON_TEAM_ID
treason alert create "Hello from my laptop" --priority P2#Acknowledge in a test
Production acknowledges come from a phone. In tests, do it from code: it is the same state change.
const { alert } = await treason.alerts.create({ message: "test", alias: "t1" });
await treason.alerts.ack(alert!.id, { user: "test" });
const done = await treason.alerts.waitFor(alert!.id, { timeoutMs: 1000 });
expect(done.reached).toBe(true);The examples are tested exactly this way: a test plays "the person on call" by acknowledging after a short delay, and the code under test waits for it.
#Make your code testable
- Take the client as a parameter (
Treason) instead of importing a global, so tests can pass one aimed at a local server, or a fakefetch:
const treason = new Treason({ apiKey: "k", baseUrl: "http://x.test", fetch: fakeFetch, maxRetries: 0 });- Use a distinct
aliasper test so de-duplication does not merge them. - Set
maxRetries: 0in tests that assert on failures.
#Testing a webhook receiver
Sign a payload with the SDK's helper (see Webhooks) and post it to your handler. Test the three cases that matter: a valid signature, a wrong signature (expect 400), and an old timestamp (expect 400).
#Heartbeats in tests
You cannot wait a day. Use the minimum interval (10 seconds) with no grace, or in an integration test create the heartbeat and then PUT it with a tiny interval and ping nothing; the monitor opens the alert within about 15 seconds of the deadline.