# End-to-end test

import script from "../../scripts/nexa-e2e.mjs?raw";

The script at the bottom of this page calls every endpoint in the order the
real flow uses them, prints what it sent and what came back, and explains
each step as it goes. Run it once and you have seen the entire integration
without reading a line of spec.

It is **one file with no dependencies**: no repository, no package install,
no build step. Copy it, save it as `nexa-e2e.mjs`, run it.

```sh
node nexa-e2e.mjs
```

Node 20 or newer. Bun and Deno (`deno run --allow-net`) work too. To point
it at your own implementation instead of the Tesser stub host, pass a base
URL:

```sh
node nexa-e2e.mjs https://your-host
```

## The seven steps it walks

| | Step | |
| --- | --- | --- |
| 1 | Tesser asks Nexa for a quote | <N /> |
| 2 | Tesser accepts the quote | <N /> |
| 3 | Tesser reports the USDC arriving at custody | <N /> |
| 4 | Nexa decides to credit (`quote.credit.sent`) | <T /> |
| 5 | Nexa confirms the GTQ landed (`quote.credit.confirmed`) | <T /> |
| 6 | Tesser instructs the GTQ payout and gets the result back in the response | <N /> |
| 7 | Nexa checks its USDC balance | <T /> |

Steps 1, 2, 3 and 6 are API calls into [Nexa's endpoints](/api-nexa). Steps
4 and 5 are webhooks into
[Tesser's receiver](/api-tesser/webhooks#receive-nexa-webhook-op-4), which
the script posts on Nexa's behalf so you can see the envelopes. Step 7 is
Nexa calling [Tesser's core API](/api-tesser/accounts#get-an-account-by-id).

The payout in step 6 is **synchronous**, so the walk ends there: there is no
progress event to wait for. Nexa sends a `payment.status.changed` event only
if the payout later fails, which the script does not simulate because it is
the exception rather than the flow. See
[4 · GTQ payout](/flow-nexa/gtq-payout).

Step 4 is the branch point: Nexa could instead send
`quote.additional_funds_requested` or `quote.rejected`. Both are described
on [3 · Credit decision](/flow-nexa/credit-decision).

<Callout type="note" title="These are stubs">

The endpoints answer with the example from the API reference whatever you
send them, and they keep no state between calls. So the run shows you the
real shapes, field names and order of play, but it is not checking that
sequencing rules are enforced: nothing is enforcing them yet. Point the
script at a real implementation when you want that.

</Callout>

If a call comes back with something other than a success status the script
says so and exits non-zero, which is enough to drop it into CI if you want
a smoke test. Otherwise read the output and ignore the exit code.

## The script

<SyntaxHighlight language="js" code={script} title="nexa-e2e.mjs" showLanguageIndicator />
