Skip to main content

llm_optimizer_api_tests/
fixtures.rs

1//! Test fixtures and mock data
2
3use serde::{Deserialize, Serialize};
4use uuid::Uuid;
5
6/// Mock API key for testing
7pub const MOCK_API_KEY: &str = "test_api_key_12345";
8
9/// Mock JWT secret for testing
10pub const MOCK_JWT_SECRET: &str = "test_jwt_secret_super_secure";
11
12/// Mock user for testing
13#[derive(Debug, Clone, Serialize, Deserialize)]
14pub struct MockUser {
15    pub id: Uuid,
16    pub username: String,
17    pub email: String,
18    pub role: UserRole,
19}
20
21#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
22pub enum UserRole {
23    Admin,
24    User,
25    ReadOnly,
26}
27
28impl MockUser {
29    pub fn admin() -> Self {
30        Self {
31            id: Uuid::new_v4(),
32            username: "admin".to_string(),
33            email: "admin@example.com".to_string(),
34            role: UserRole::Admin,
35        }
36    }
37
38    pub fn user() -> Self {
39        Self {
40            id: Uuid::new_v4(),
41            username: "user".to_string(),
42            email: "user@example.com".to_string(),
43            role: UserRole::User,
44        }
45    }
46
47    pub fn readonly() -> Self {
48        Self {
49            id: Uuid::new_v4(),
50            username: "readonly".to_string(),
51            email: "readonly@example.com".to_string(),
52            role: UserRole::ReadOnly,
53        }
54    }
55}
56
57/// Mock request data
58#[derive(Debug, Clone, Serialize, Deserialize)]
59pub struct MockRequest {
60    pub id: Uuid,
61    pub data: String,
62}
63
64impl MockRequest {
65    pub fn new(data: impl Into<String>) -> Self {
66        Self {
67            id: Uuid::new_v4(),
68            data: data.into(),
69        }
70    }
71}
72
73/// Mock response data
74#[derive(Debug, Clone, Serialize, Deserialize)]
75pub struct MockResponse {
76    pub id: Uuid,
77    pub status: String,
78    pub data: String,
79}
80
81impl MockResponse {
82    pub fn success(data: impl Into<String>) -> Self {
83        Self {
84            id: Uuid::new_v4(),
85            status: "success".to_string(),
86            data: data.into(),
87        }
88    }
89
90    pub fn error(message: impl Into<String>) -> Self {
91        Self {
92            id: Uuid::new_v4(),
93            status: "error".to_string(),
94            data: message.into(),
95        }
96    }
97}
98
99#[cfg(test)]
100mod tests {
101    use super::*;
102
103    #[test]
104    fn test_mock_users() {
105        let admin = MockUser::admin();
106        assert_eq!(admin.role, UserRole::Admin);
107
108        let user = MockUser::user();
109        assert_eq!(user.role, UserRole::User);
110
111        let readonly = MockUser::readonly();
112        assert_eq!(readonly.role, UserRole::ReadOnly);
113    }
114
115    #[test]
116    fn test_mock_request() {
117        let req = MockRequest::new("test data");
118        assert_eq!(req.data, "test data");
119    }
120
121    #[test]
122    fn test_mock_response() {
123        let success = MockResponse::success("done");
124        assert_eq!(success.status, "success");
125
126        let error = MockResponse::error("failed");
127        assert_eq!(error.status, "error");
128    }
129}