@mamund/tram 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,115 @@
1
+ # Tasks API tutorial
2
+
3
+ This tutorial uses the local Tasks API included in the [TRAM source repository](https://github.com/mamund/tram). It builds on the [public API quick start](quick-start.md) by testing a service that supports both retrieval and state-changing requests.
4
+
5
+ **What you'll learn:** run a local API, execute a multi-test manifest, inspect passing and failing assertions, use runtime data, and review HTTP evidence.
6
+
7
+ ## Prerequisites
8
+
9
+ - Node.js 18 or later and npm.
10
+ - TRAM installed from npm (`npm install -g @mamund/tram@beta` after publication), or linked from a source checkout with `npm link`.
11
+ - A local checkout of the repository, because the Tasks API and its manifest are not included in the npm package.
12
+
13
+ ```bash
14
+ git clone https://github.com/mamund/tram.git
15
+ cd tram
16
+ ```
17
+
18
+ If you already have a checkout, use it rather than cloning again. The sample is in `api-samples/tasks/`.
19
+
20
+ ## 1. Start the Tasks API
21
+
22
+ From the repository root:
23
+
24
+ ```bash
25
+ cd api-samples/tasks
26
+ npm install
27
+ npm start
28
+ ```
29
+
30
+ Keep this terminal open. The server listens at `http://localhost:3000`. In a second terminal, check it:
31
+
32
+ ```bash
33
+ curl http://localhost:3000/
34
+ ```
35
+
36
+ The root response includes `_links` with `taskList` and `createTask` affordances. If port 3000 is occupied, stop the conflicting service; the sample currently uses a fixed port.
37
+
38
+ ## 2. Inspect the supplied manifest
39
+
40
+ From the repository root, the manifest is `api-samples/tasks/api-tests.json`. It declares `manifestVersion: "0.1"` and a `config.baseUrl` of `http://localhost:3000`.
41
+
42
+ The `tests` array covers these behaviors:
43
+
44
+ | Test ID | Expected behavior |
45
+ | --- | --- |
46
+ | `root-get` | API root exposes navigational links |
47
+ | `tasks-list` | Task collection has the expected shape |
48
+ | `task-get-single` | A known task can be retrieved |
49
+ | `task-get-missing` | Unknown task returns HTTP 404 |
50
+ | `task-create-valid` | Valid task creation returns HTTP 201 |
51
+ | `task-create-missing-title` | Missing title returns HTTP 400 |
52
+ | `task-create-invalid-status` | Missing status returns HTTP 400 |
53
+ | `task-update-status` | Updating a task's status succeeds |
54
+ | `task-filter-active` | Active tasks can be filtered |
55
+ | `task-filter-completed` | Completed tasks can be filtered |
56
+
57
+ The `task-create-invalid-status` identifier is historical: the payload actually omits `status`, and the server checks for a missing required field. The sample does **not** currently enforce an enumeration of permitted status values.
58
+
59
+ ## 3. Validate the manifest
60
+
61
+ Open another terminal at the repository root:
62
+
63
+ ```bash
64
+ tram api-samples/tasks/api-tests.json --validate
65
+ ```
66
+
67
+ Validation checks the manifest's structure without contacting the API. This is useful even when the sample server is stopped.
68
+
69
+ ## 4. Execute the tests and collect evidence
70
+
71
+ ```bash
72
+ tram api-samples/tasks/api-tests.json \
73
+ --report tasks-results.json \
74
+ --transcript tasks-transcript.http
75
+ ```
76
+
77
+ With a fresh sample server, the expected summary is **10 passed, 0 failed, 0 skipped**. TRAM writes the JSON report and HTTP transcript into the current working directory. A failed test causes a nonzero exit code.
78
+
79
+ The sample changes server state. Restart the server to restore its initial in-memory task collection before repeating the full suite. Repeated runs without a restart can add duplicate sample tasks and affect collection-based assertions.
80
+
81
+ ## 5. Read an assertion
82
+
83
+ The `root-get` test requests `GET /`. Its assertions check HTTP 200, a JSON content type, and the presence and structure of `_links`. This tests an observable contract: clients can discover the available operations from the API root.
84
+
85
+ The `task-get-missing` test expects HTTP **404**. A passing test here means the API correctly rejected the lookup. TRAM's pass/fail result describes whether the **observed response matched the expectation**, rather than whether the HTTP status was in the 2xx range.
86
+
87
+ ## 6. Understand runtime data
88
+
89
+ In the manifest's `data` section, the entry `stable.guid` contains the known identifier of an initial task. The test `task-get-single` uses it in its path:
90
+
91
+ ```json
92
+ "path": "/tasks/${data.stable.guid}"
93
+ ```
94
+
95
+ The `task-create-valid` test uses a data reference as its request body:
96
+
97
+ ```json
98
+ "body": "$data.task.valid"
99
+ ```
100
+
101
+ This keeps example values in one place and allows TRAM to interpolate them when requests are constructed. The sample also uses `${randomId}` to generate identifiers.
102
+
103
+ ## 7. Inspect the evidence
104
+
105
+ Open `tasks-results.json` to examine the suite summary, individual test results, and assertion outcomes. Open `tasks-transcript.http` to inspect the requests and responses. The transcript is evidence of what the API returned during this particular run.
106
+
107
+ Try changing the `task-get-missing` test's expected HTTP status from `404` to `200`. Run the suite again against a restarted server. The assertion should fail and the report should record the observed status. Restore `404` afterward.
108
+
109
+ ## 8. Where to go next
110
+
111
+ The sample manifest uses format `0.1`. TRAM also supports manifest `0.2`, which adds **response capture**: a test can extract a value from a response and use it in a later request. This existing Tasks API manifest does not exercise capture. See the [manifest specification](manifest-spec.md) for capture syntax and the [beta status](beta-status.md) for current limitations.
112
+
113
+ For a useful follow-on exercise, add a `0.2` test that creates a task, captures its returned `id`, and uses that value in a subsequent `GET /tasks/{id}` request. Keep that experiment separate from the baseline suite until its assertions are verified.
114
+
115
+ **Security:** Reports and transcripts can contain request and response data. TRAM redacts selected sensitive HTTP headers, but does not automatically remove secrets from URLs, bodies, or all assertion evidence. Review artifacts before sharing them.