mod common; use axum::http::StatusCode; use sqlx::PgPool; use tower::ServiceExt; #[sqlx::test(migrations = "./migrations")] async fn lists_seeded_genres(pool: PgPool) { let h = common::harness(pool); let resp = h .app .oneshot(common::get("/api/v1/genres")) .await .unwrap(); assert_eq!(resp.status(), StatusCode::OK); let body = common::body_json(resp).await; let items = body.as_array().expect("genres returned as a flat array"); let names: Vec<&str> = items .iter() .map(|g| g["name"].as_str().unwrap()) .collect(); // The migration seeds a curated vocabulary; spot-check a few // common ones so accidental removals fail loudly. for expected in ["Action", "Comedy", "Romance", "Sci-Fi"] { assert!( names.contains(&expected), "expected seeded genre {expected:?} in {names:?}" ); } // Every genre must carry an id so the create/patch endpoints have // something to reference. for g in items { assert!(g["id"].as_str().is_some()); } }