# Test mode

Test mode simulates a delivery through the same v2 API and base URL used for live deliveries.

## Setup

In [Automated Ordering](https://business.armadadelivery.com/automated-ordering), use a separate key for testing. New keys start with **Test mode on** and all permissions enabled. Keep Test mode on, clear unneeded permissions and click **Save changes** before creating a delivery. Confirm `test_mode: true` in the response. Changing the key setting affects new orders only.

Use an existing branch and contacts you control. Test deliveries appear in your order history with `test_mode: true`.

## Lifecycle

Allow up to 90 seconds for the simulated lifecycle:

| Stage        | Scheduled delay                         |
| ------------ | --------------------------------------- |
| `dispatched` | Bot driver assigned after creation      |
| `accepted`   | 30 seconds after dispatch; trip created |
| `en_route`   | Another 30 seconds                      |
| `completed`  | Another 30 seconds                      |

Configured status callbacks use `order.updated`. The bot is removed after the simulation; the order and trip records remain.

## Test cancellation

Enable `delivery:cancel` and `delivery:read` on the test key and save it. Create a fresh test delivery, then send `POST /v2/deliveries/{code}/cancel` during `dispatched`, `accepted` or `en_route`.

The body is optional:

```json
{ "reason": "Integration test" }
```

Expect `200` with `status: "canceled"` and `test_mode: true`. Cancellation stops the simulation without adding cancellation fees or debiting the wallet. Repeating the cancel request keeps the first cancellation reason. A completed delivery returns `400`; a `409` means the delivery changed during cancellation, so read its state before retrying.

For a callback, save your **Order update webhook** URL with **Canceled** selected. Expect topic `order.updated` and `status: "canceled"`. **Send delivery test** only sends a fixed connectivity sample; it does not run or cancel a delivery. See [Webhooks](https://docs.armadadelivery.com/v2/webhooks.md).

## Checking results

Retrieve the delivery using its `code` to check the current status. After a timeout, read its state before retrying a request. Use `test_mode` to filter test deliveries in your reports.

See the [quickstart](https://docs.armadadelivery.com/v2/quickstart.md) for SDK creation and cancellation examples.

## Going live

Use a separate production key. Configure its permissions and callbacks, turn **Test mode off** and click **Save changes** before sending live traffic. Confirm `test_mode: false` on the first intended live delivery. Existing test deliveries remain test deliveries.
