You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.7 KiB
Markdown

+++
title = "Write unit tests in api/src/tests.rs covering all handlers, auth logic, and pagination"
priority = 6
status = "todo"
ticket_type = "task"
dependencies = ["f3dc74", "2ce22e", "5dbb7d", "886bfd", "05f8ae", "5d9f5a", "b20b5a", "28e7d9"]
+++
<context>
The `quotesdb` API is built with Axum + Tokio, targeting Cloudflare Workers via `workers-rs`. It serves JSON at `/api/*` endpoints and persists data to Cloudflare D1 (production) or a local SQLite file via Turso (development). Source lives in `src/bin/api/`.
Shared types and utilities are in `src/lib.rs` — code placed there must compile for both the host target and `wasm32-unknown-unknown`.
</context>
<goal>
Write unit tests in `src/bin/api/tests.rs` (or a `#[cfg(test)]` module) covering all API handlers, the auth logic, and pagination calculations. Unit tests should test handler logic in isolation using mock or in-memory databases where possible.
</goal>
<constraints>
- Unit tests must run with `cargo test` on the host target — no WASM or browser context required.
- Test auth code matching logic (correct code → pass, wrong code → 403).
- Test pagination edge cases: page 1, last page, out-of-range page (empty array).
- Test tag insertion and replacement (correct rows added/removed).
- Aim for 80%+ code coverage of the API handler module.
</constraints>
<skills>
Use `superpowers:test-driven-development` throughout implementation — unit tests should already exist from prior tickets.
Use `superpowers:verification-before-completion` before closing.
</skills>
<validation>
Run in order from the `quotesdb/` directory:
```sh
cargo fmt
cargo check
cargo clippy
cargo test
```
</validation>
<commit>
`test(quotesdb): add unit tests for api handlers, auth logic, and pagination`
</commit>