Integration-Tests für die gesamte API #28

Open
opened 2026-06-21 23:03:47 +02:00 by Radixura · 0 comments
Owner

Ziel

Schreibe Integration-Tests, die den Axum-Router mit einer Test-Datenbank starten und alle Endpunkte via HTTP-Requests testen.

Beschreibung

Integration-Tests testen das Zusammenspiel aller Komponenten: Router, Handler, DB, Auth, Cache. Sie nutzen axum_test oder direkt reqwest gegen einen Test-Router.

Akzeptanzkriterien

  • Test-Harness: tests/integration_test.rs
    • Startet Router mit In-Memory-Test-DB
    • Erstellt einen Test-API-Key
    • Bietet Helper: test_client()reqwest::Client oder axum_test::TestServer

Auth Tests

  • test_unauthenticated_write_returns_401 — POST ohne X-API-Key → 401
  • test_invalid_api_key_returns_401 — POST mit falschem Key → 401
  • test_revoked_key_returns_401 — Revokter Key → 401
  • test_write_only_key_cannot_read_private — Key ohne can_read_private → 403

Feed CRUD Tests

  • test_create_feed — POST /api/v1/feeds → 201 + Response
  • test_create_duplicate_feed_slug → 409 Conflict
  • test_create_feed_invalid_slug — "Bitcoin News!" → 400
  • test_list_feeds — GET /api/v1/feeds → 200 + Array
  • test_get_feed_by_slug — GET /api/v1/feeds/bitcoin → 200
  • test_get_nonexistent_feed → 404
  • test_update_feed — PATCH /api/v1/feeds/bitcoin → 200
  • test_delete_feed — DELETE /api/v1/feeds/bitcoin → 204

Post Tests

  • test_create_post — POST /api/v1/posts → 201 + UUID
  • test_create_post_multi_feed — Post in 3 Feeds → 201, Response hat feeds: [3 slugs]
  • test_create_post_nonexistent_feed → 400 "Feed not found"
  • test_create_post_empty_feeds → 400 "At least one feed"
  • test_get_post_by_uuid → 200
  • test_get_nonexistent_post_uuid → 404
  • test_list_posts → 200 + Array
  • test_list_posts_by_feed → 200 + nur Posts dieses Feeds

Feed-XML Tests

  • test_get_rss_feed — GET /feeds/bitcoin/rss.xml → 200, Content-Type: application/rss+xml
  • test_get_atom_feed — GET /feeds/bitcoin/atom.xml → 200, Content-Type: application/atom+xml
  • test_private_feed_without_token_returns_403 → 403
  • test_private_feed_with_valid_token_returns_200 → 200
  • test_private_feed_with_invalid_token_returns_403 → 403
  • test_xml_cache_hit — Zweiter Request hat X-Cache: HIT

Admin Tests

  • test_create_api_key → 201 mit Klartext-Key
  • test_list_api_keys → 200, KEINE Klartext-Keys
  • test_revoke_api_key → 200, danach Auth → 401
  • test_delete_api_key → 204

Technische Hinweise

  • axum_test Crate (falls erwünscht) oder reqwest mit tokio::test
  • Test-DB ist In-Memory (sqlite::memory:), keine Datei — Tests sind isoliert
  • Alle Tests mit #[tokio::test] annotieren
  • cargo test --test integration_test zum gezielten Ausführen
## Ziel Schreibe Integration-Tests, die den Axum-Router mit einer Test-Datenbank starten und alle Endpunkte via HTTP-Requests testen. ## Beschreibung Integration-Tests testen das Zusammenspiel aller Komponenten: Router, Handler, DB, Auth, Cache. Sie nutzen `axum_test` oder direkt `reqwest` gegen einen Test-Router. ## Akzeptanzkriterien - [ ] Test-Harness: `tests/integration_test.rs` - Startet Router mit In-Memory-Test-DB - Erstellt einen Test-API-Key - Bietet Helper: `test_client()` → `reqwest::Client` oder `axum_test::TestServer` ### Auth Tests - [ ] `test_unauthenticated_write_returns_401` — POST ohne X-API-Key → 401 - [ ] `test_invalid_api_key_returns_401` — POST mit falschem Key → 401 - [ ] `test_revoked_key_returns_401` — Revokter Key → 401 - [ ] `test_write_only_key_cannot_read_private` — Key ohne `can_read_private` → 403 ### Feed CRUD Tests - [ ] `test_create_feed` — POST /api/v1/feeds → 201 + Response - [ ] `test_create_duplicate_feed_slug` → 409 Conflict - [ ] `test_create_feed_invalid_slug` — "Bitcoin News!" → 400 - [ ] `test_list_feeds` — GET /api/v1/feeds → 200 + Array - [ ] `test_get_feed_by_slug` — GET /api/v1/feeds/bitcoin → 200 - [ ] `test_get_nonexistent_feed` → 404 - [ ] `test_update_feed` — PATCH /api/v1/feeds/bitcoin → 200 - [ ] `test_delete_feed` — DELETE /api/v1/feeds/bitcoin → 204 ### Post Tests - [ ] `test_create_post` — POST /api/v1/posts → 201 + UUID - [ ] `test_create_post_multi_feed` — Post in 3 Feeds → 201, Response hat `feeds: [3 slugs]` - [ ] `test_create_post_nonexistent_feed` → 400 "Feed not found" - [ ] `test_create_post_empty_feeds` → 400 "At least one feed" - [ ] `test_get_post_by_uuid` → 200 - [ ] `test_get_nonexistent_post_uuid` → 404 - [ ] `test_list_posts` → 200 + Array - [ ] `test_list_posts_by_feed` → 200 + nur Posts dieses Feeds ### Feed-XML Tests - [ ] `test_get_rss_feed` — GET /feeds/bitcoin/rss.xml → 200, Content-Type: application/rss+xml - [ ] `test_get_atom_feed` — GET /feeds/bitcoin/atom.xml → 200, Content-Type: application/atom+xml - [ ] `test_private_feed_without_token_returns_403` → 403 - [ ] `test_private_feed_with_valid_token_returns_200` → 200 - [ ] `test_private_feed_with_invalid_token_returns_403` → 403 - [ ] `test_xml_cache_hit` — Zweiter Request hat X-Cache: HIT ### Admin Tests - [ ] `test_create_api_key` → 201 mit Klartext-Key - [ ] `test_list_api_keys` → 200, KEINE Klartext-Keys - [ ] `test_revoke_api_key` → 200, danach Auth → 401 - [ ] `test_delete_api_key` → 204 ## Technische Hinweise - `axum_test` Crate (falls erwünscht) oder `reqwest` mit `tokio::test` - Test-DB ist In-Memory (`sqlite::memory:`), keine Datei — Tests sind isoliert - Alle Tests mit `#[tokio::test]` annotieren - `cargo test --test integration_test` zum gezielten Ausführen
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Radixura/rss-atom-backend#28
No description provided.