# HydraBooks Testbook

## Test: Health Endpoint

1. Run: `curl http://localhost:8080/api/v1/health`
2. Expect: JSON with `"status":"ok"`. If sync is enabled, also includes `"sync"` object with `enabled`, `last_sync`, `source_count`, and `error_count` fields.
3. Status code: 200

## Test: Push a Book

1. Run:
   ```bash
   curl -X POST \
     -H "Authorization: Bearer <token>" \
     -H "Content-Type: text/markdown" \
     --data-binary @docs/runbooks/runbook.md \
     http://localhost:8080/api/v1/books/hydrabooks/runbooks/runbook.md
   ```
2. Expect: 200 with JSON containing project, type, filename, meta
3. Verify file exists at `~/.hydrabooks/books/hydrabooks/runbooks/runbook.md`

## Test: List Books

1. Run: `curl http://localhost:8080/api/v1/books`
2. Expect: JSON array with the pushed book summary

## Test: Get Book

1. Run: `curl http://localhost:8080/api/v1/books/hydrabooks/runbooks/runbook.md`
2. Expect: Raw markdown content

## Test: Get Book as HTML

1. Run: `curl http://localhost:8080/api/v1/books/hydrabooks/runbooks/runbook.md?format=html`
2. Expect: HTML rendered from markdown

## Test: Search

1. Run: `curl http://localhost:8080/api/v1/search?q=deploy`
2. Expect: JSON array with search results containing "deploy" keyword

## Test: Delete Book

1. Run:
   ```bash
   curl -X DELETE \
     -H "Authorization: Bearer <token>" \
     http://localhost:8080/api/v1/books/hydrabooks/runbooks/runbook.md
   ```
2. Expect: `{"status":"deleted"}`
3. Verify book no longer appears in list

## Test: Web UI

1. Open `http://localhost:8080/` — dashboard shows project cards
2. Click a project — shows runbooks and testbooks
3. Click a book — renders markdown as HTML
4. Use search form — returns matching results

## Test: Push CLI

1. Run:
   ```bash
   ./bin/hydrabooks push \
     --server http://localhost:8080 \
     --token <token> \
     --project testproject \
     --type runbooks \
     docs/runbooks/runbook.md
   ```
2. Expect: `pushed testproject/runbooks/runbook.md`

## Test: Add Expert Review

1. Run:
   ```bash
   curl -X POST \
     -H "Authorization: Bearer <token>" \
     -H "Content-Type: application/json" \
     -d '{"reviewer_name":"Koenraad Van Cleempoel","affiliation":"Universiteit Hasselt","expert":true,"rating":5,"comment":"Excellent coverage of deployment procedures."}' \
     http://localhost:8080/api/v1/books/hydrabooks/runbooks/runbook.md/reviews
   ```
2. Expect: 201 with JSON containing generated `id`, `reviewer_name`, `expert: true`, `created_at`

## Test: Add Regular Review

1. Run:
   ```bash
   curl -X POST \
     -H "Authorization: Bearer <token>" \
     -H "Content-Type: application/json" \
     -d '{"reviewer_name":"John Doe","comment":"Helpful runbook."}' \
     http://localhost:8080/api/v1/books/hydrabooks/runbooks/runbook.md/reviews
   ```
2. Expect: 201 with JSON containing `expert: false`

## Test: List Reviews

1. Run: `curl http://localhost:8080/api/v1/books/hydrabooks/runbooks/runbook.md/reviews`
2. Expect: JSON array with expert reviews listed first, then regular reviews
3. Verify sidecar file exists at `~/.hydrabooks/books/hydrabooks/runbooks/runbook.md.reviews.yaml`

## Test: Delete Review

1. Get a review ID from the list reviews response
2. Run:
   ```bash
   curl -X DELETE \
     -H "Authorization: Bearer <token>" \
     http://localhost:8080/api/v1/books/hydrabooks/runbooks/runbook.md/reviews/<id>
   ```
3. Expect: `{"status":"deleted"}`
4. Verify review no longer appears in list

## Test: Review Web UI

1. Open a book view page that has reviews
2. Verify reviews section appears below the markdown content
3. Expert reviews should have an indigo "Expert" badge and highlighted border
4. Reviews show reviewer name, affiliation, star rating, comment, and timestamp

## Test: Size Limit

1. Create a file larger than 1MB
2. Push it via API
3. Expect: 413 Request Entity Too Large
