Skip to main content

fastapi_output/testing/
fixtures.rs

1//! Test fixtures for common output scenarios.
2
3/// Sample route metadata for output component tests.
4#[derive(Debug, Clone)]
5pub struct FixtureRoute {
6    /// HTTP method.
7    pub method: &'static str,
8    /// Route path.
9    pub path: &'static str,
10    /// Optional handler name.
11    pub handler_name: Option<&'static str>,
12}
13
14/// Create a sample set of routes for testing.
15#[must_use]
16pub fn sample_routes() -> Vec<FixtureRoute> {
17    vec![
18        FixtureRoute {
19            method: "GET",
20            path: "/users",
21            handler_name: Some("list_users"),
22        },
23        FixtureRoute {
24            method: "POST",
25            path: "/users",
26            handler_name: Some("create_user"),
27        },
28        FixtureRoute {
29            method: "GET",
30            path: "/users/{id}",
31            handler_name: Some("get_user"),
32        },
33    ]
34}
35
36/// Sample validation error fixture.
37#[derive(Debug, Clone)]
38pub struct FixtureValidationError {
39    /// Path segments to the invalid field.
40    pub path: Vec<&'static str>,
41    /// Error message.
42    pub message: &'static str,
43    /// Error code.
44    pub code: &'static str,
45    /// Expected value description.
46    pub expected: Option<&'static str>,
47    /// Received value description.
48    pub received: Option<&'static str>,
49}
50
51/// Create sample validation errors.
52#[must_use]
53pub fn sample_validation_errors() -> Vec<FixtureValidationError> {
54    vec![FixtureValidationError {
55        path: vec!["email"],
56        message: "Invalid email format",
57        code: "email",
58        expected: Some("valid email address"),
59        received: Some("not-an-email"),
60    }]
61}
62
63/// Sample middleware metadata for output tests.
64#[derive(Debug, Clone)]
65pub struct FixtureMiddlewareInfo {
66    /// Middleware name.
67    pub name: &'static str,
68    /// Type name for display.
69    pub type_name: &'static str,
70    /// Registration order.
71    pub order: usize,
72    /// Whether it can short-circuit.
73    pub can_short_circuit: bool,
74    /// Optional configuration summary.
75    pub config_summary: Option<&'static str>,
76}
77
78/// Create sample middleware stack.
79#[must_use]
80pub fn sample_middleware() -> Vec<FixtureMiddlewareInfo> {
81    vec![
82        FixtureMiddlewareInfo {
83            name: "RequestLogger",
84            type_name: "fastapi::middleware::RequestLogger",
85            order: 0,
86            can_short_circuit: false,
87            config_summary: Some("level=INFO"),
88        },
89        FixtureMiddlewareInfo {
90            name: "Auth",
91            type_name: "fastapi::middleware::Auth",
92            order: 1,
93            can_short_circuit: true,
94            config_summary: Some("scheme=Bearer"),
95        },
96    ]
97}