Skip to main content

openlark_workflow/common/
mod.rs

1/// 通用模块
2///
3/// 提供openlark-workflow项目中通用的工具、宏和类型定义。
4pub mod api_endpoints;
5/// 工作流 API 通用辅助函数。
6pub mod api_utils;
7/// Board v1 新增端点。
8pub mod board_v1_endpoints;
9/// Task v2 新增端点。
10pub mod task_v2_endpoints;
11
12// 重新导出API端点枚举
13pub use api_endpoints::TaskApiV2;
14pub use board_v1_endpoints::BoardV1Endpoint;
15pub use task_v2_endpoints::TaskV2Endpoint;
16
17/// 通用常量定义
18pub mod constants {
19    /// 默认分页大小
20    pub const DEFAULT_PAGE_SIZE: i32 = 20;
21    /// 最大分页大小
22    pub const MAX_PAGE_SIZE: i32 = 100;
23}
24
25/// 通用类型别名
26pub mod types {
27    /// 任务 GUID
28    pub type TaskGuid = String;
29    /// 任务清单 GUID
30    pub type TasklistGuid = String;
31    /// 分组 GUID
32    pub type SectionGuid = String;
33    /// 自定义字段 GUID
34    pub type CustomFieldGuid = String;
35    /// 评论 GUID
36    pub type CommentGuid = String;
37    /// 附件 GUID
38    pub type AttachmentGuid = String;
39}
40
41#[cfg(test)]
42#[allow(unused_imports)]
43mod tests {
44    use super::constants;
45    use super::types;
46    use super::{board_v1_endpoints::BoardV1Endpoint, task_v2_endpoints::TaskV2Endpoint};
47
48    #[test]
49    fn test_default_page_size() {
50        assert_eq!(constants::DEFAULT_PAGE_SIZE, 20);
51    }
52
53    #[test]
54    fn test_max_page_size() {
55        assert_eq!(constants::MAX_PAGE_SIZE, 100);
56    }
57
58    #[test]
59    fn test_task_guid_type() {
60        let guid: types::TaskGuid = "test_guid".to_string();
61        assert_eq!(guid, "test_guid");
62    }
63
64    #[test]
65    fn test_tasklist_guid_type() {
66        let guid: types::TasklistGuid = "test_tasklist".to_string();
67        assert_eq!(guid, "test_tasklist");
68    }
69
70    #[test]
71    fn test_section_guid_type() {
72        let guid: types::SectionGuid = "test_section".to_string();
73        assert_eq!(guid, "test_section");
74    }
75
76    #[test]
77    fn test_custom_field_guid_type() {
78        let guid: types::CustomFieldGuid = "test_field".to_string();
79        assert_eq!(guid, "test_field");
80    }
81
82    #[test]
83    fn test_comment_guid_type() {
84        let guid: types::CommentGuid = "test_comment".to_string();
85        assert_eq!(guid, "test_comment");
86    }
87
88    #[test]
89    fn test_attachment_guid_type() {
90        let guid: types::AttachmentGuid = "test_attachment".to_string();
91        assert_eq!(guid, "test_attachment");
92    }
93
94    #[test]
95    fn issue_194_split_endpoint_paths() {
96        assert_eq!(
97            BoardV1Endpoint::WhiteboardNodeBatchDelete("board_123".to_string()).to_url(),
98            "/open-apis/board/v1/whiteboards/board_123/nodes/batch_delete"
99        );
100        assert_eq!(
101            TaskV2Endpoint::TaskSetAncestorTask("task_123".to_string()).to_url(),
102            "/open-apis/task/v2/tasks/task_123/set_ancestor_task"
103        );
104        assert_eq!(
105            TaskV2Endpoint::ListRelatedTask.to_url(),
106            "/open-apis/task/v2/task_v2/list_related_task"
107        );
108        assert_eq!(
109            TaskV2Endpoint::TaskSubscription.to_url(),
110            "/open-apis/task/v2/task_v2/task_subscription"
111        );
112    }
113}