Files
Oxicloud/tests/api/README.md
T

72 lines
2.5 KiB
Markdown
Raw Normal View History

2026-05-11 00:50:39 +02:00
# API functional tests
Tests are written using [Hurl](https://hurl.dev) — a plain-text, CLI-first HTTP testing tool.
## Prerequisites
- [Hurl](https://hurl.dev/docs/installation.html) ≥ 4.0
Install: `cargo install hurl` or via your package manager
## Configuration
2026-05-11 09:54:35 +02:00
Edit `test.env` to match your local instance. This file is the single source of
2026-05-11 00:50:39 +02:00
truth: `run.sh` sources it for shell variables and passes it to Hurl as
`--variables-file`.
```
base_url=http://localhost:8087
username=admin
email=admin@example.com
password=TestPassword1!
```
## Running the tests
```bash
# First-time setup (run once on a fresh instance)
2026-05-11 09:54:35 +02:00
hurl --variables-file tests/api/test.env --test tests/api/setup.hurl
2026-05-11 00:50:39 +02:00
# Contacts CRUD scenario
2026-05-11 09:54:35 +02:00
hurl --variables-file tests/api/test.env --test tests/api/contacts.hurl
2026-05-11 00:50:39 +02:00
# All scenarios at once
2026-05-11 09:54:35 +02:00
hurl --variables-file tests/api/test.env --test tests/api/setup.hurl tests/api/contacts.hurl
2026-05-11 00:50:39 +02:00
# With full request/response output
2026-05-11 09:54:35 +02:00
hurl --variables-file tests/api/test.env --test --verbose tests/api/contacts.hurl
2026-05-11 00:50:39 +02:00
# Generate an HTML report
2026-05-11 09:54:35 +02:00
hurl --variables-file tests/api/test.env --test --report-html /tmp/hurl-report tests/api/contacts.hurl
2026-05-11 00:50:39 +02:00
```
## Test files
| File | Description |
|---|---|
| `setup.hurl` | One-time admin account creation; also asserts the endpoint is locked afterwards |
| `contacts.hurl` | Full contacts CRUD scenario (13 steps, see below) |
2026-05-11 09:54:35 +02:00
| `test.env` | Variables: `base_url`, `username`, `email`, `password` — used by both Hurl and `run.sh` |
2026-05-11 00:50:39 +02:00
## Scenario: `contacts.hurl`
| Step | Description |
|---|---|
| 1 | Login – capture JWT token |
| 2 | List address books – assert system book is present and read-only |
| 3 | Create personal address book – capture `book_id` |
| 4 | List contacts in new book – assert empty |
| 5 | Create contact John Doe – capture `contact_id` |
| 6 | List contacts – assert exactly 1 result with John Doe's id |
| 7 | Get John Doe – assert all fields, capture `ETag` |
| 8 | Update John Doe (nickname, org, notes) with `If-Match` – assert new values, capture refreshed `ETag` |
| 9 | Delete John Doe with `If-Match` |
| 10 | List contacts – assert empty again |
| 11 | Delete personal address book |
| 12 | List address books – assert `book_id` no longer present |
| 13 | List system address book – assert non-empty collection of OxiCloud users |
## Legacy bash tests
`test.sh` and `common.sh` are the original curl/bash scripts kept for reference.
Run them with `bash tests/api/test.sh` from the repo root (requires `jq`).