# Test mode and the test postcodes

Test mode runs everything a live letter does (the address check, the render, the checks, the price, the rules, approvals, webhooks, a test record) and prints, posts and charges nothing. Test credits are not money.

A test key starts `as_test_`; a live key `as_live_`. A key is one mode. `get_account` says which (`mode.name`), and every quote says `"test": true`.

## Moving a test letter along

[`advance_test_letter`](reference/advance_test_letter.md) moves a test letter one stage, as the print room would: queued, printing, printed, posted, on record. Each step sends the webhook events a live letter would. A live key gets `test_mode_only`.

## Rehearsing what goes wrong

Address a test letter to one of these postcodes and it takes that path. Any other test letter takes the happy path. A test postcode is refused with a live key (`test_postcode_in_live`).

| Postcode | What happens |
|---|---|
| `TEST 01` | Approved and posted, simulated. Follows the agent's approval mode, is printed, becomes a test record. |
| `TEST 02` | Declined. Waits for approval in any mode, then a sample person declines it with a sample reason. Held test credits come back. |
| `TEST 03` | Quote lapsed. Waits for approval and nobody answers. Nothing sent, held credits released. |
| `TEST 04` | Address not found. quote_letter returns address_not_found with two sample close matches. Nothing charged. |
| `TEST 05` | Held by Atomside. A sample reviewer question appears on the letter with a box to reply. Reply with anything and it goes ahead. |
| `TEST 06` | Declined by Atomside. Held, then declined by our reviewer with a sample reason. Held test credits come back. |
| `TEST 07` | Marked as returned. Goes on record, then comes back to sender one stage later. |
| `TEST 08` | Held as a possible duplicate of a sample earlier letter, even on autopilot. Discard, send anyway or stop asking, as in live. The real check runs too: send the same letter twice to any address. |
| `TEST 09` | Daily limit reached. send_letter answers as if the daily limit were used up, whatever is left of it. As in live: refused with over_daily_limit on autopilot, otherwise it waits for approval (needs_approval). |
| `TEST 10` | Sending paused. The agent is paused as if a safeguard tripped. Every send is refused: paused by a safeguard, nothing charged, do not retry. Resume it from the banner, as in live. |
| `TEST 11` | Posting day moved. Sent with any post_on, it is scheduled, then moved to the next posting day as if we were away. |
| `TEST 12` | Day full. quote_letter with any post_on returns post_on_not_available, why day_full, with sample days either side. |
| `TEST 13` | Missed its day. Sent with any post_on, it is scheduled, then held as if sending was stopped on the day. Pick a new day on the letter, or let it lapse. |

The postcode can be written `TEST 01` or `test01`. Use any street and town.

In a list of recipients, each line takes its own postcode's path: a `TEST 04` line is left out of the quote as `address_not_found` while the rest are quoted. Test mode takes lists of up to 50 from the start.

## Posting on a later day

`post_on` is checked against the real calendar in test mode, so your agent's date handling is tested for real, but test letters never fill a day. A scheduled test letter does not wait for its day: it shows as "Scheduled, simulated" and moves on at the speed set for test letters, or with `advance_test_letter`. `TEST 11`, `TEST 12` and `TEST 13` rehearse a moved day, a full day and a missed day; without `post_on` they take the happy path.

## What to rehearse before going live

- Your agent shows the approval link and waits (`TEST 01` with "every letter").
- It handles a decline without resending (`TEST 02`) and a lapse by quoting once more (`TEST 03`).
- It does not pick a close match unless it is clearly the same place (`TEST 04`).
- It stops and tells its person when it is paused (`TEST 10`) or over a limit (`TEST 09`).
- With `post_on`, it reads `letter.posting_moved` (`TEST 11`), asks its person before taking another day when one is full (`TEST 12`), and tells its person when a letter missed its day (`TEST 13`).
