#![allow(clippy::unwrap_used)] #![allow(clippy::cast_precision_loss)] #![allow(clippy::cast_sign_loss)] #![allow(clippy::cast_possible_truncation)] #![allow(clippy::cast_possible_wrap)] #![allow(clippy::cast_lossless)] #![allow(clippy::missing_panics_doc)] #![allow(clippy::missing_errors_doc)] #![allow(missing_docs)] #![allow(clippy::items_after_statements)] #![allow(clippy::used_underscore_binding)] #![allow(clippy::needless_pass_by_value)]
mod common;
use common::test_app::{api_router, get_json, get_text, make_populated_test_state};
use http::StatusCode;
#[tokio::test]
async fn schema_graphql_endpoint_returns_sdl_text() {
let router = api_router(make_populated_test_state());
let (status, sdl) = get_text(&router, "/api/v1/schema.graphql").await;
assert_eq!(status, StatusCode::OK);
assert!(sdl.contains("type Query"), "SDL should contain type Query, got: {sdl}");
}
#[tokio::test]
async fn schema_graphql_sdl_contains_types_and_mutations() {
let router = api_router(make_populated_test_state());
let (_, sdl) = get_text(&router, "/api/v1/schema.graphql").await;
assert!(sdl.contains("type User"), "SDL should contain User type");
assert!(sdl.contains("type Mutation"), "SDL should contain Mutation type");
}
#[tokio::test]
async fn schema_json_endpoint_returns_structured_schema() {
let router = api_router(make_populated_test_state());
let (status, json) = get_json(&router, "/api/v1/schema.json").await;
assert_eq!(status, StatusCode::OK);
assert_eq!(json["status"], "success");
assert!(json["data"]["schema"]["types"].is_array());
assert!(json["data"]["schema"]["queries"].is_array());
}
#[tokio::test]
async fn schema_json_types_have_fields() {
let router = api_router(make_populated_test_state());
let (_, json) = get_json(&router, "/api/v1/schema.json").await;
let types = json["data"]["schema"]["types"].as_array().unwrap();
assert!(!types.is_empty());
let user_type = types.iter().find(|t| t["name"] == "User");
assert!(user_type.is_some(), "Should have a User type");
assert!(user_type.unwrap()["fields"].is_array());
}