1# Chapter 20¾: jev-http/tests — the whole client, over real TLS
2
3One file, [mock.rs](mock.rs): an integration test. Cargo builds each file in
4a crate's `tests/` folder as a separate program that can use only the
5crate's public API, the way an outside caller would. (The nearest JavaScript
6equivalent is an end-to-end test that imports the package by name rather
7than reaching into its source.)
8
9Every test starts `jev_mock::MockJev` on loopback, points a `Jev` at it
10with `Endpoint::parse(&mock.endpoint()).trusting(mock.ca_file())`, and gives
11it a ledger in a fresh temp directory. Nothing reaches the real API and
12nothing touches the real ledger.
13
14```mermaid
15flowchart LR
16  T["test"] --> J["Jev::ask"]
17  J --> L[("sandbox ledger")]
18  J -->|"HTTP/2 over TLS, throwaway CA"| M["MockJev on 127.0.0.1"]
19  M -->|"Reply from the test's closure"| J
20```
21
22| Test | Shows |
23| --- | --- |
24| `answers_over_one_kept_connection_and_books_the_cost` | Three asks, three requests, one TLS connection; every hold settled. |
25| `the_ledger_refuses_before_anything_is_sent` | With a bucket of one, the second ask is `Failure::Throttled` and the mock sees one request. |
26| `out_of_credit_stops_every_later_ask` | A `402` is `OutOfCredit` after one attempt, the next ask is `Failure::Budget` without a request, and the refused hold was released. |
27| `a_plain_http_endpoint_is_refused` | `Endpoint::parse` refuses `http://`. |
28
29## Try it
30
31```
32cargo test -p jev-http --test mock
33```
34
35## For the people who maintain it
36
37### In this folder
38
39| File | What |
40| --- | --- |
41| [mock.rs](mock.rs) | The four tests above, and the `client` and `one_noul` helpers. |
42| [CLAUDE.md](CLAUDE.md) | Invariants for agents. |
43
44← Previous: [Chapter 20½: inside jev-http/src](../src/) · Up: [jev-http](../) · Next: [Chapter 21: jev-mock](../../jev-mock/) →