beeper_desktop_api/models/
app.rs1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct FocusAppInput {
8 #[serde(skip_serializing_if = "Option::is_none")]
10 #[serde(rename = "chatID")]
11 pub chat_id: Option<String>,
12 #[serde(skip_serializing_if = "Option::is_none")]
14 #[serde(rename = "messageID")]
15 pub message_id: Option<String>,
16 #[serde(skip_serializing_if = "Option::is_none")]
18 pub draft: Option<String>,
19}
20
21#[derive(Debug, Clone, Serialize, Deserialize)]
23pub struct FocusAppOutput {
24 pub success: bool,
26}
27
28#[derive(Debug, Clone, Serialize, Deserialize)]
30pub struct DownloadAssetInput {
31 pub url: String,
33}
34
35#[derive(Debug, Clone, Serialize, Deserialize)]
37pub struct DownloadAssetOutput {
38 #[serde(rename = "localURL")]
40 pub local_url: String,
41}
42
43#[cfg(test)]
44mod tests {
45 use super::*;
46
47 #[test]
48 fn test_focus_app_input_minimal() {
49 let input = FocusAppInput {
50 chat_id: None,
51 message_id: None,
52 draft: None,
53 };
54 assert!(input.chat_id.is_none());
55 assert!(input.message_id.is_none());
56 assert!(input.draft.is_none());
57 }
58
59 #[test]
60 fn test_focus_app_input_with_chat() {
61 let input = FocusAppInput {
62 chat_id: Some("chat-1".to_string()),
63 message_id: None,
64 draft: None,
65 };
66 assert_eq!(input.chat_id, Some("chat-1".to_string()));
67 assert!(input.message_id.is_none());
68 }
69
70 #[test]
71 fn test_focus_app_input_with_message() {
72 let input = FocusAppInput {
73 chat_id: Some("chat-1".to_string()),
74 message_id: Some("msg-123".to_string()),
75 draft: None,
76 };
77 assert_eq!(input.chat_id, Some("chat-1".to_string()));
78 assert_eq!(input.message_id, Some("msg-123".to_string()));
79 }
80
81 #[test]
82 fn test_focus_app_input_with_draft() {
83 let input = FocusAppInput {
84 chat_id: Some("chat-1".to_string()),
85 message_id: None,
86 draft: Some("Hello, world!".to_string()),
87 };
88 assert_eq!(input.draft, Some("Hello, world!".to_string()));
89 }
90
91 #[test]
92 fn test_focus_app_output_success() {
93 let output = FocusAppOutput { success: true };
94 assert!(output.success);
95 }
96
97 #[test]
98 fn test_focus_app_output_failure() {
99 let output = FocusAppOutput { success: false };
100 assert!(!output.success);
101 }
102
103 #[test]
104 fn test_download_asset_input() {
105 let input = DownloadAssetInput {
106 url: "https://example.com/file.png".to_string(),
107 };
108 assert_eq!(input.url, "https://example.com/file.png");
109 }
110
111 #[test]
112 fn test_download_asset_output() {
113 let output = DownloadAssetOutput {
114 local_url: "file:///home/user/.beeper/cache/file.png".to_string(),
115 };
116 assert!(output.local_url.contains("file://"));
117 }
118
119 #[test]
120 fn test_focus_app_input_serialization() {
121 let input = FocusAppInput {
122 chat_id: Some("chat-1".to_string()),
123 message_id: Some("msg-1".to_string()),
124 draft: Some("Test draft".to_string()),
125 };
126 let json = serde_json::to_string(&input).expect("Failed to serialize");
127 assert!(json.contains("\"chatID\""));
128 assert!(json.contains("\"messageID\""));
129 }
130
131 #[test]
132 fn test_download_asset_input_serialization() {
133 let input = DownloadAssetInput {
134 url: "https://example.com/asset.jpg".to_string(),
135 };
136 let json = serde_json::to_string(&input).expect("Failed to serialize");
137 assert!(json.contains("https://example.com/asset.jpg"));
138 }
139}